diff options
author | Christian Breunig <christian@breunig.cc> | 2023-09-28 18:22:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-28 18:22:19 +0200 |
commit | 34772d635fa5a44db8c944b6f0a84f184a704f1d (patch) | |
tree | d37d1297c5110cca0374e3b25beb6174b806b93f /src/conf_mode | |
parent | 852e9c3328e61f5d0b92a9efca376aec94533f2b (diff) | |
parent | 3a3123485f2ea7b253caa1c49f19c82a0eaa0b37 (diff) | |
download | vyos-1x-34772d635fa5a44db8c944b6f0a84f184a704f1d.tar.gz vyos-1x-34772d635fa5a44db8c944b6f0a84f184a704f1d.zip |
Merge pull request #2307 from indrajitr/mdns-ipversions
mdns: T5615: Allow controlling IP version to use for mDNS repeater
Diffstat (limited to 'src/conf_mode')
-rwxr-xr-x | src/conf_mode/service_mdns-repeater.py | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/conf_mode/service_mdns-repeater.py b/src/conf_mode/service_mdns-repeater.py index a2c90b537..6909731ff 100755 --- a/src/conf_mode/service_mdns-repeater.py +++ b/src/conf_mode/service_mdns-repeater.py @@ -18,7 +18,7 @@ import os from json import loads from sys import exit -from netifaces import ifaddresses, interfaces, AF_INET +from netifaces import ifaddresses, interfaces, AF_INET, AF_INET6 from vyos.config import Config from vyos.ifconfig.vrrp import VRRP @@ -36,18 +36,22 @@ def get_config(config=None): conf = config else: conf = Config() + base = ['service', 'mdns', 'repeater'] - mdns = conf.get_config_dict(base, key_mangling=('-', '_'), get_first_key=True) + if not conf.exists(base): + return None + + mdns = conf.get_config_dict(base, key_mangling=('-', '_'), + no_tag_node_value_mangle=True, + get_first_key=True, + with_recursive_defaults=True) if mdns: mdns['vrrp_exists'] = conf.exists('high-availability vrrp') return mdns def verify(mdns): - if not mdns: - return None - - if 'disable' in mdns: + if not mdns or 'disable' in mdns: return None # We need at least two interfaces to repeat mDNS advertisments @@ -60,10 +64,14 @@ def verify(mdns): if interface not in interfaces(): raise ConfigError(f'Interface "{interface}" does not exist!') - if AF_INET not in ifaddresses(interface): + if mdns['ip_version'] in ['ipv4', 'both'] and AF_INET not in ifaddresses(interface): raise ConfigError('mDNS repeater requires an IPv4 address to be ' f'configured on interface "{interface}"') + if mdns['ip_version'] in ['ipv6', 'both'] and AF_INET6 not in ifaddresses(interface): + raise ConfigError('mDNS repeater requires an IPv6 address to be ' + f'configured on interface "{interface}"') + return None # Get VRRP states from interfaces, returns only interfaces where state is MASTER @@ -92,7 +100,7 @@ def generate(mdns): if len(mdns['interface']) < 2: return None - render(config_file, 'mdns-repeater/avahi-daemon.j2', mdns) + render(config_file, 'mdns-repeater/avahi-daemon.conf.j2', mdns) return None def apply(mdns): |