diff options
author | Christian Poessinger <christian@poessinger.com> | 2021-10-19 06:37:31 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-19 06:37:31 +0200 |
commit | ce969f3b746b36ec3aad25bc550601acc1901c03 (patch) | |
tree | 70ca4b8f7782ee03709b421493b89d6db2f3ef12 | |
parent | 5dd06565d9f3ed71577fe76d08aa9306b84cb3bf (diff) | |
parent | e54d3526aeec2ebcda5eafa4a363bf824c3c1c85 (diff) | |
download | vyos-1x-ce969f3b746b36ec3aad25bc550601acc1901c03.tar.gz vyos-1x-ce969f3b746b36ec3aad25bc550601acc1901c03.zip |
Merge pull request #1029 from sever-sever/T3396-crux
syslog: T3396: Allow remote IPv6 host
-rwxr-xr-x | src/conf_mode/syslog.py | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/conf_mode/syslog.py b/src/conf_mode/syslog.py index b3876164c..435a318e4 100755 --- a/src/conf_mode/syslog.py +++ b/src/conf_mode/syslog.py @@ -19,6 +19,7 @@ import os import re import jinja2 from sys import exit +from jinja2.filters import FILTERS, environmentfilter from vyos.config import Config from vyos import ConfigError @@ -59,9 +60,9 @@ $outchannel {{file}},{{files[file]['log-file']}},{{files[file]['max-size']}},{{f {% endif %} {% else %} {% if hosts[host]['port'] %} -{{hosts[host]['selectors']}} @{{host}}:{{hosts[host]['port']}} +{{hosts[host]['selectors']}} @{{ host | bracketize_ipv6 }}:{{hosts[host]['port']}} {% else %} -{{hosts[host]['selectors']}} @{{host}} +{{hosts[host]['selectors']}} @{{ host | bracketize_ipv6 }} {% endif %} {% endif %} {% endfor %} @@ -90,6 +91,23 @@ logrotate_configs = ''' # config templates end +# Bracketize filters for jinja2 +def is_ipv6(text): + """ Filter IP address, return True on IPv6 address, False otherwise """ + from ipaddress import ip_interface + try: return ip_interface(text).version == 6 + except: return False + +@environmentfilter +def bracketize_ipv6(self, address): + """ Place a passed IPv6 address into [] brackets, do nothing for IPv4 """ + if is_ipv6(address): + return '[{0}]'.format(address) + return address + +FILTERS['bracketize_ipv6'] = bracketize_ipv6 +# end bracketize + def get_config(): c = Config() if not c.exists('system syslog'): |