diff options
author | Christian Poessinger <christian@poessinger.com> | 2020-11-29 20:32:22 +0100 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2020-11-29 20:32:22 +0100 |
commit | bced875d720277fa91d0da629466447fc22e83c6 (patch) | |
tree | 92a933dd97f8e4c3d240cd77579d04a1ae09529d | |
parent | ea3c4544634a9d916deff4bd6cdce1522d395a0d (diff) | |
download | vyos-1x-bced875d720277fa91d0da629466447fc22e83c6.tar.gz vyos-1x-bced875d720277fa91d0da629466447fc22e83c6.zip |
dhcpv6-relay: T3095: improve verify()
- Upstream interfaces require a DHCPv6 server to be configured
- Listen interface must have a a global unicast address assigned, else
ISC dhcrelay won't start.
-rw-r--r-- | data/templates/dhcp-relay/dhcrelay6.conf.tmpl | 6 | ||||
-rwxr-xr-x | src/conf_mode/dhcpv6_relay.py | 17 | ||||
-rw-r--r-- | src/systemd/isc-dhcp-relay6.service | 4 |
3 files changed, 24 insertions, 3 deletions
diff --git a/data/templates/dhcp-relay/dhcrelay6.conf.tmpl b/data/templates/dhcp-relay/dhcrelay6.conf.tmpl index 165216592..58c216b7c 100644 --- a/data/templates/dhcp-relay/dhcrelay6.conf.tmpl +++ b/data/templates/dhcp-relay/dhcrelay6.conf.tmpl @@ -10,7 +10,11 @@ {# listen_interface is mandatory so it's always present #} {% set listen = namespace(value='') %} {% for interface, config in listen_interface.items() %} -{% set listen.value = listen.value + '-l ' + config.address + '%' + interface + ' ' %} +{% if config.address is defined and config.address is not none %} +{% set listen.value = listen.value + '-l ' + config.address + '%' + interface + ' ' %} +{% else %} +{% set listen.value = listen.value + '-l ' + interface + ' ' %} +{% endif %} {% endfor %} OPTIONS="{{ listen.value }} {{ upstream.value }} -c {{ max_hop_count }} {{ '-I' if use_interface_id_option is defined }}" diff --git a/src/conf_mode/dhcpv6_relay.py b/src/conf_mode/dhcpv6_relay.py index 9a91ace1c..cf8a26674 100755 --- a/src/conf_mode/dhcpv6_relay.py +++ b/src/conf_mode/dhcpv6_relay.py @@ -20,9 +20,11 @@ from sys import exit from vyos.config import Config from vyos.configdict import dict_merge +from vyos.ifconfig import Interface from vyos.template import render from vyos.util import call from vyos.util import dict_search +from vyos.validate import is_ipv6_link_local from vyos.xml import defaults from vyos import ConfigError from vyos import airbag @@ -54,10 +56,25 @@ def verify(relay): if 'upstream_interface' not in relay: raise ConfigError('At least one upstream interface required!') + for interface, config in relay['upstream_interface'].items(): + if 'address' not in config: + raise ConfigError('DHCPv6 server required for upstream ' \ + f'interface {interface}!') if 'listen_interface' not in relay: raise ConfigError('At least one listen interface required!') + # DHCPv6 relay requires at least one global unicat address assigned to the + # interface + for interface in relay['listen_interface']: + has_global = False + for addr in Interface(interface).get_addr(): + if not is_ipv6_link_local(addr.split('/')[0]): + has_global = True + if not has_global: + raise ConfigError(f'Interface {interface} does not have global '\ + 'IPv6 address assigned!') + return None def generate(relay): diff --git a/src/systemd/isc-dhcp-relay6.service b/src/systemd/isc-dhcp-relay6.service index 8788d1ed6..30037e013 100644 --- a/src/systemd/isc-dhcp-relay6.service +++ b/src/systemd/isc-dhcp-relay6.service @@ -12,8 +12,8 @@ WorkingDirectory=/run/dhcp-relay RuntimeDirectory=dhcp-relay RuntimeDirectoryPreserve=yes EnvironmentFile=/run/dhcp-relay/dhcrelay6.conf -PIDFile=/run/dhcp-relay/dhcrelayv6.pid -ExecStart=/usr/sbin/dhcrelay -6 -pf /run/dhcp-relay/dhcrelayv6.pid $OPTIONS +PIDFile=/run/dhcp-relay/dhcrelay6.pid +ExecStart=/usr/sbin/dhcrelay -6 -pf /run/dhcp-relay/dhcrelay6.pid $OPTIONS Restart=always [Install] |