From d5b58517f88358c686e6c8ea039a7a9a64d6c6ee Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Mon, 25 May 2020 21:02:35 +0200 Subject: dhcpv6-pd: pppoe: T2506: restructure CLI Rename the CLI nodes for prefix delegation from "dhcpv6-options delegate " to "dhcpv6-options prefix-delegation interface ". The change is required to add the possibility to request for specific prefix sized via the CLI. That option was not possible with the old configuration tree. --- src/conf_mode/interfaces-pppoe.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src/conf_mode/interfaces-pppoe.py') diff --git a/src/conf_mode/interfaces-pppoe.py b/src/conf_mode/interfaces-pppoe.py index 6cde850c9..e8aeb810f 100755 --- a/src/conf_mode/interfaces-pppoe.py +++ b/src/conf_mode/interfaces-pppoe.py @@ -36,7 +36,7 @@ default_config_data = { 'deleted': False, 'description': '\0', 'disable': False, - 'dhcpv6_pd': [], + 'dhcpv6_pd_interfaces': [], 'intf': '', 'idle_timeout': '', 'ipv6_autoconf': False, @@ -137,15 +137,19 @@ def get_config(): if conf.exists('vrf'): pppoe['vrf'] = conf.return_value(['vrf']) - if conf.exists(['dhcpv6-options', 'delegate']): - for interface in conf.list_nodes(['dhcpv6-options', 'delegate']): + if conf.exists(['dhcpv6-options', 'prefix-delegation']): + dhcpv6_pd_path = base_path + [pppoe['intf'], + 'dhcpv6-options', 'prefix-delegation'] + conf.set_level(dhcpv6_pd_path) + + for interface in conf.list_nodes(['interface']): + conf.set_level(dhcpv6_pd_path + ['interface', interface]) pd = { 'ifname': interface, 'sla_id': '', 'sla_len': '', 'if_id': '' } - conf.set_level(base_path + [pppoe['intf'], 'dhcpv6-options', 'delegate', interface]) if conf.exists(['sla-id']): pd['sla_id'] = conf.return_value(['sla-id']) @@ -153,10 +157,10 @@ def get_config(): if conf.exists(['sla-len']): pd['sla_len'] = conf.return_value(['sla-len']) - if conf.exists(['interface-id']): - pd['if_id'] = conf.return_value(['interface-id']) + if conf.exists(['address']): + pd['if_id'] = conf.return_value(['address']) - pppoe['dhcpv6_pd'].append(pd) + pppoe['dhcpv6_pd_interfaces'].append(pd) return pppoe @@ -223,7 +227,7 @@ def generate(pppoe): render(script_pppoe_ipv6_up, 'pppoe/ipv6-up.script.tmpl', pppoe, trim_blocks=True, permission=0o755) - if len(pppoe['dhcpv6_pd']) > 0: + if len(pppoe['dhcpv6_pd_interfaces']) > 0: # ipv6.tmpl relies on ifname - this should be made consitent in the # future better then double key-ing the same value pppoe['ifname'] = intf -- cgit v1.2.3 From 7dddfa338800303335673df637a05d8aaaccdaa2 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Mon, 25 May 2020 21:11:43 +0200 Subject: dhcpv6-pd: T2506: add option to request specific prefix length Some ISPs (e.g. Comcast) only delegate a /64 by default. You have to explicitly "ask" for a bigger (e.g. /60) prefix. This commit adds a CLI node to request a specific prefix length in the range 32 - 64. dhcpv6-options { prefix-delegation { length 60 } } --- data/templates/dhcp-client/ipv6.tmpl | 3 +++ python/vyos/configdict.py | 1 + python/vyos/ifconfig_vlan.py | 3 +++ src/conf_mode/interfaces-bonding.py | 3 +++ src/conf_mode/interfaces-bridge.py | 3 +++ src/conf_mode/interfaces-ethernet.py | 3 +++ src/conf_mode/interfaces-pppoe.py | 6 ++++++ src/conf_mode/interfaces-pseudo-ethernet.py | 3 +++ src/conf_mode/interfaces-wireless.py | 3 +++ 9 files changed, 28 insertions(+) (limited to 'src/conf_mode/interfaces-pppoe.py') diff --git a/data/templates/dhcp-client/ipv6.tmpl b/data/templates/dhcp-client/ipv6.tmpl index 8957516e2..490f14726 100644 --- a/data/templates/dhcp-client/ipv6.tmpl +++ b/data/templates/dhcp-client/ipv6.tmpl @@ -23,6 +23,9 @@ id-assoc na 1 { {% if dhcpv6_pd_interfaces %} id-assoc pd 2 { +{% if dhcpv6_pd_length %} + prefix ::/{{ dhcpv6_pd_length }} infinity; +{% endif %} {% for intf in dhcpv6_pd_interfaces %} prefix-interface {{ intf.ifname }} { {% if intf.sla_id %} diff --git a/python/vyos/configdict.py b/python/vyos/configdict.py index 6afc78039..3e1f22d09 100644 --- a/python/vyos/configdict.py +++ b/python/vyos/configdict.py @@ -112,6 +112,7 @@ interface_default_data = { 'dhcp_vendor_class_id': '', 'dhcpv6_prm_only': False, 'dhcpv6_temporary': False, + 'dhcpv6_pd_length': '', 'dhcpv6_pd_interfaces': [], 'disable': False, 'disable_link_detect': 1, diff --git a/python/vyos/ifconfig_vlan.py b/python/vyos/ifconfig_vlan.py index ec4d1da42..53a77c651 100644 --- a/python/vyos/ifconfig_vlan.py +++ b/python/vyos/ifconfig_vlan.py @@ -87,6 +87,9 @@ def apply_vlan_config(vlan, config): if config['dhcpv6_temporary']: vlan.dhcp.v6.options['dhcpv6_temporary'] = True + if config['dhcpv6_pd_length']: + vlan.dhcp.v6.options['dhcpv6_pd_length'] = config['dhcpv6_pd_length'] + if config['dhcpv6_pd_interfaces']: vlan.dhcp.v6.options['dhcpv6_pd_interfaces'] = config['dhcpv6_pd_interfaces'] diff --git a/src/conf_mode/interfaces-bonding.py b/src/conf_mode/interfaces-bonding.py index b531e97fc..ed9b754c3 100755 --- a/src/conf_mode/interfaces-bonding.py +++ b/src/conf_mode/interfaces-bonding.py @@ -299,6 +299,9 @@ def apply(bond): if bond['dhcpv6_temporary']: b.dhcp.v6.options['dhcpv6_temporary'] = True + if bond['dhcpv6_pd_length']: + b.dhcp.v6.options['dhcpv6_pd_length'] = bond['dhcpv6_pd_length'] + if bond['dhcpv6_pd_interfaces']: b.dhcp.v6.options['dhcpv6_pd_interfaces'] = bond['dhcpv6_pd_interfaces'] diff --git a/src/conf_mode/interfaces-bridge.py b/src/conf_mode/interfaces-bridge.py index 865d8a999..adfa81c74 100755 --- a/src/conf_mode/interfaces-bridge.py +++ b/src/conf_mode/interfaces-bridge.py @@ -321,6 +321,9 @@ def apply(bridge): if bridge['dhcpv6_temporary']: br.dhcp.v6.options['dhcpv6_temporary'] = True + if bridge['dhcpv6_pd_length']: + br.dhcp.v6.options['dhcpv6_pd_length'] = br['dhcpv6_pd_length'] + if bridge['dhcpv6_pd_interfaces']: br.dhcp.v6.options['dhcpv6_pd_interfaces'] = br['dhcpv6_pd_interfaces'] diff --git a/src/conf_mode/interfaces-ethernet.py b/src/conf_mode/interfaces-ethernet.py index 8ffefc7cf..e9cab4be7 100755 --- a/src/conf_mode/interfaces-ethernet.py +++ b/src/conf_mode/interfaces-ethernet.py @@ -201,6 +201,9 @@ def apply(eth): if eth['dhcpv6_temporary']: e.dhcp.v6.options['dhcpv6_temporary'] = True + if eth['dhcpv6_pd_length']: + e.dhcp.v6.options['dhcpv6_pd_length'] = eth['dhcpv6_pd_length'] + if eth['dhcpv6_pd_interfaces']: e.dhcp.v6.options['dhcpv6_pd_interfaces'] = eth['dhcpv6_pd_interfaces'] diff --git a/src/conf_mode/interfaces-pppoe.py b/src/conf_mode/interfaces-pppoe.py index e8aeb810f..eaa61cdb6 100755 --- a/src/conf_mode/interfaces-pppoe.py +++ b/src/conf_mode/interfaces-pppoe.py @@ -36,6 +36,7 @@ default_config_data = { 'deleted': False, 'description': '\0', 'disable': False, + 'dhcpv6_pd_length': '', 'dhcpv6_pd_interfaces': [], 'intf': '', 'idle_timeout': '', @@ -142,6 +143,11 @@ def get_config(): 'dhcpv6-options', 'prefix-delegation'] conf.set_level(dhcpv6_pd_path) + # retriebe DHCPv6-PD prefix helper length as some ISPs only hand out a + # /64 by default (https://phabricator.vyos.net/T2506) + if conf.exists(['length']): + pppoe['dhcpv6_pd_length'] = conf.return_value(['length']) + for interface in conf.list_nodes(['interface']): conf.set_level(dhcpv6_pd_path + ['interface', interface]) pd = { diff --git a/src/conf_mode/interfaces-pseudo-ethernet.py b/src/conf_mode/interfaces-pseudo-ethernet.py index c1f52d42c..c09df15e8 100755 --- a/src/conf_mode/interfaces-pseudo-ethernet.py +++ b/src/conf_mode/interfaces-pseudo-ethernet.py @@ -171,6 +171,9 @@ def apply(peth): if peth['dhcpv6_temporary']: p.dhcp.v6.options['dhcpv6_temporary'] = True + if peth['dhcpv6_pd_length']: + p.dhcp.v6.options['dhcpv6_pd_length'] = peth['dhcpv6_pd_length'] + if peth['dhcpv6_pd_interfaces']: p.dhcp.v6.options['dhcpv6_pd_interfaces'] = peth['dhcpv6_pd_interfaces'] diff --git a/src/conf_mode/interfaces-wireless.py b/src/conf_mode/interfaces-wireless.py index 54420acd1..8a2736a66 100755 --- a/src/conf_mode/interfaces-wireless.py +++ b/src/conf_mode/interfaces-wireless.py @@ -591,6 +591,9 @@ def apply(wifi): if wifi['dhcpv6_temporary']: w.dhcp.v6.options['dhcpv6_temporary'] = True + if wifi['dhcpv6_pd_length']: + w.dhcp.v6.options['dhcpv6_pd_length'] = wifi['dhcpv6_pd_length'] + if wifi['dhcpv6_pd_interfaces']: w.dhcp.v6.options['dhcpv6_pd_interfaces'] = wifi['dhcpv6_pd_interfaces'] -- cgit v1.2.3 From 8ff6d2ed6025fb113a180e3c23be83dac7169658 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Mon, 25 May 2020 21:15:38 +0200 Subject: dhcpv6-pd: T2506: use common dictionary definition for config parameters --- python/vyos/configdict.py | 16 ++++++++++------ src/conf_mode/interfaces-pppoe.py | 6 +++--- 2 files changed, 13 insertions(+), 9 deletions(-) (limited to 'src/conf_mode/interfaces-pppoe.py') diff --git a/python/vyos/configdict.py b/python/vyos/configdict.py index 3e1f22d09..c89447163 100644 --- a/python/vyos/configdict.py +++ b/python/vyos/configdict.py @@ -103,17 +103,21 @@ def get_ethertype(ethertype_val): else: raise ConfigError('invalid ethertype "{}"'.format(ethertype_val)) +dhcpv6_pd_default_data = { + 'dhcpv6_prm_only': False, + 'dhcpv6_temporary': False, + 'dhcpv6_pd_length': '', + 'dhcpv6_pd_interfaces': [] +} + interface_default_data = { + **dhcpv6_pd_default_data, 'address': [], 'address_remove': [], 'description': '', 'dhcp_client_id': '', 'dhcp_hostname': '', 'dhcp_vendor_class_id': '', - 'dhcpv6_prm_only': False, - 'dhcpv6_temporary': False, - 'dhcpv6_pd_length': '', - 'dhcpv6_pd_interfaces': [], 'disable': False, 'disable_link_detect': 1, 'ip_disable_arp_filter': 1, @@ -246,8 +250,8 @@ def intf_to_dict(conf, default): if conf.exists(['sla-len']): pd['sla_len'] = conf.return_value(['sla-len']) - if conf.exists(['interface-id']): - pd['if_id'] = conf.return_value(['interface-id']) + if conf.exists(['address']): + pd['if_id'] = conf.return_value(['address']) intf['dhcpv6_pd_interfaces'].append(pd) diff --git a/src/conf_mode/interfaces-pppoe.py b/src/conf_mode/interfaces-pppoe.py index eaa61cdb6..08c129bf0 100755 --- a/src/conf_mode/interfaces-pppoe.py +++ b/src/conf_mode/interfaces-pppoe.py @@ -21,13 +21,15 @@ from copy import deepcopy from netifaces import interfaces from vyos.config import Config +from vyos.configdict import dhcpv6_pd_default_data from vyos.ifconfig import Interface +from vyos.template import render from vyos.util import chown, chmod_755, call from vyos import ConfigError -from vyos.template import render default_config_data = { + **dhcpv6_pd_default_data, 'access_concentrator': '', 'auth_username': '', 'auth_password': '', @@ -36,8 +38,6 @@ default_config_data = { 'deleted': False, 'description': '\0', 'disable': False, - 'dhcpv6_pd_length': '', - 'dhcpv6_pd_interfaces': [], 'intf': '', 'idle_timeout': '', 'ipv6_autoconf': False, -- cgit v1.2.3