diff options
author | Viacheslav <v.gletenko@vyos.io> | 2021-10-17 17:09:24 +0000 |
---|---|---|
committer | Viacheslav <v.gletenko@vyos.io> | 2021-10-17 17:09:24 +0000 |
commit | e54d3526aeec2ebcda5eafa4a363bf824c3c1c85 (patch) | |
tree | 70ca4b8f7782ee03709b421493b89d6db2f3ef12 /src/conf_mode/syslog.py | |
parent | 5dd06565d9f3ed71577fe76d08aa9306b84cb3bf (diff) | |
download | vyos-1x-e54d3526aeec2ebcda5eafa4a363bf824c3c1c85.tar.gz vyos-1x-e54d3526aeec2ebcda5eafa4a363bf824c3c1c85.zip |
syslog: T3396: Allow remote IPv6 host
Diffstat (limited to 'src/conf_mode/syslog.py')
-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'): |