From 8701282fbcb5972c874900105ec6c8ec0a2d4919 Mon Sep 17 00:00:00 2001 From: Indrajit Raychaudhuri Date: Sat, 23 Sep 2023 23:44:08 -0500 Subject: mdns: T5615: Allow controlling IP version to use for mDNS repeater This commit adds a new configuration option to the mDNS repeater service to allow controlling which IP version to use for mDNS repeater. Additionally, publishing AAAA record over IPv4 and A record over IPv6 is disabled as suggested. See: - https://github.com/lathiat/avahi/issues/117#issuecomment-1651475104 - https://bugzilla.redhat.com/show_bug.cgi?id=669627#c2 (cherry picked from commit e66f7075ee12ae3107d29efaf683442c3535e8b9) --- src/conf_mode/service_mdns-repeater.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'src/conf_mode/service_mdns-repeater.py') diff --git a/src/conf_mode/service_mdns-repeater.py b/src/conf_mode/service_mdns-repeater.py index a2c90b537..d4b8ef8c4 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 -- cgit v1.2.3 From 39d30e2034d75823a958905aac7bc8427597fdac Mon Sep 17 00:00:00 2001 From: Indrajit Raychaudhuri Date: Sun, 24 Sep 2023 23:22:31 -0500 Subject: mdns: T5615: Rename avahi-daemon config file Rename avahi-daemon config file to avahi-daemon.conf.j2 to match the convention used by other config files. (cherry picked from commit 3a3123485f2ea7b253caa1c49f19c82a0eaa0b37) --- data/templates/mdns-repeater/avahi-daemon.conf.j2 | 27 +++++++++++++++++++++++ data/templates/mdns-repeater/avahi-daemon.j2 | 27 ----------------------- src/conf_mode/service_mdns-repeater.py | 2 +- 3 files changed, 28 insertions(+), 28 deletions(-) create mode 100644 data/templates/mdns-repeater/avahi-daemon.conf.j2 delete mode 100644 data/templates/mdns-repeater/avahi-daemon.j2 (limited to 'src/conf_mode/service_mdns-repeater.py') diff --git a/data/templates/mdns-repeater/avahi-daemon.conf.j2 b/data/templates/mdns-repeater/avahi-daemon.conf.j2 new file mode 100644 index 000000000..d562c048f --- /dev/null +++ b/data/templates/mdns-repeater/avahi-daemon.conf.j2 @@ -0,0 +1,27 @@ +### Autogenerated by service_mdns-repeater.py ### +[server] +use-ipv4={{ 'yes' if ip_version in ['ipv4', 'both'] else 'no' }} +use-ipv6={{ 'yes' if ip_version in ['ipv6', 'both'] else 'no' }} +allow-interfaces={{ interface | join(', ') }} +{% if browse_domain is vyos_defined and browse_domain | length %} +browse-domains={{ browse_domain | join(', ') }} +{% endif %} +disallow-other-stacks=no + +[wide-area] +enable-wide-area=yes + +[publish] +disable-publishing=yes +disable-user-service-publishing=yes +publish-addresses=no +publish-hinfo=no +publish-workstation=no +publish-aaaa-on-ipv4=no +publish-a-on-ipv6=no + +[reflector] +enable-reflector=yes +{% if allow_service is vyos_defined and allow_service | length %} +reflect-filters={{ allow_service | join(', ') }} +{% endif %} diff --git a/data/templates/mdns-repeater/avahi-daemon.j2 b/data/templates/mdns-repeater/avahi-daemon.j2 deleted file mode 100644 index d562c048f..000000000 --- a/data/templates/mdns-repeater/avahi-daemon.j2 +++ /dev/null @@ -1,27 +0,0 @@ -### Autogenerated by service_mdns-repeater.py ### -[server] -use-ipv4={{ 'yes' if ip_version in ['ipv4', 'both'] else 'no' }} -use-ipv6={{ 'yes' if ip_version in ['ipv6', 'both'] else 'no' }} -allow-interfaces={{ interface | join(', ') }} -{% if browse_domain is vyos_defined and browse_domain | length %} -browse-domains={{ browse_domain | join(', ') }} -{% endif %} -disallow-other-stacks=no - -[wide-area] -enable-wide-area=yes - -[publish] -disable-publishing=yes -disable-user-service-publishing=yes -publish-addresses=no -publish-hinfo=no -publish-workstation=no -publish-aaaa-on-ipv4=no -publish-a-on-ipv6=no - -[reflector] -enable-reflector=yes -{% if allow_service is vyos_defined and allow_service | length %} -reflect-filters={{ allow_service | join(', ') }} -{% endif %} diff --git a/src/conf_mode/service_mdns-repeater.py b/src/conf_mode/service_mdns-repeater.py index d4b8ef8c4..6909731ff 100755 --- a/src/conf_mode/service_mdns-repeater.py +++ b/src/conf_mode/service_mdns-repeater.py @@ -100,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): -- cgit v1.2.3