From f62cfb7b95ba3e2aac8ddda957e5e6b6bc26a67d Mon Sep 17 00:00:00 2001 From: Rajendra Dendukuri Date: Sat, 6 Jul 2019 15:14:38 -0700 Subject: [PATCH 1/4] addons: dhcp: Policy to specify DUID type to use on dhcpv6 requests Add a ifupdown2 policy attribute dhcp6-duid to allow user to specify the DUID type to be used on an IPv6 enabled interface. Signed-off-by: Rajendra Dendukuri --- ifupdown2/addons/dhcp.py | 10 +++++++--- ifupdown2/ifupdownaddons/dhclient.py | 15 ++++++++++++--- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/ifupdown2/addons/dhcp.py b/ifupdown2/addons/dhcp.py index 4d87f7c..ca41988 100644 --- a/ifupdown2/addons/dhcp.py +++ b/ifupdown2/addons/dhcp.py @@ -68,6 +68,8 @@ class dhcp(moduleBase): except: timeout = 10 pass + dhcp6_duid = policymanager.policymanager_api.get_iface_default(module_name=self.__class__.__name__, \ + ifname=ifaceobj.name, attr='dhcp6-duid') vrf = ifaceobj.get_attr_value_first('vrf') if (vrf and self.vrf_exec_cmd_prefix and @@ -103,7 +105,7 @@ class dhcp(moduleBase): self.sysctl_set('net.ipv6.conf.%s' %ifaceobj.name + '.autoconf', autoconf) try: - self.dhclientcmd.stop6(ifaceobj.name) + self.dhclientcmd.stop6(ifaceobj.name, duid=dhcp6_duid) except: pass #add delay before starting IPv6 dhclient to @@ -118,7 +120,7 @@ class dhcp(moduleBase): if r: self.dhclientcmd.start6(ifaceobj.name, wait=wait, - cmd_prefix=dhclient_cmd_prefix) + cmd_prefix=dhclient_cmd_prefix, duid=dhcp6_duid) return timeout -= 1 if timeout: @@ -144,8 +146,10 @@ class dhcp(moduleBase): if (vrf and self.vrf_exec_cmd_prefix and self.ipcmd.link_exists(vrf)): dhclient_cmd_prefix = '%s %s' %(self.vrf_exec_cmd_prefix, vrf) + dhcp6_duid = policymanager.policymanager_api.get_iface_default(module_name=self.__class__.__name__, \ + ifname=ifaceobj.name, attr='dhcp6-duid') if 'inet6' in ifaceobj.addr_family: - self.dhclientcmd.release6(ifaceobj.name, dhclient_cmd_prefix) + self.dhclientcmd.release6(ifaceobj.name, dhclient_cmd_prefix, duid=dhcp6_duid) if 'inet' in ifaceobj.addr_family: self.dhclientcmd.release(ifaceobj.name, dhclient_cmd_prefix) diff --git a/ifupdown2/ifupdownaddons/dhclient.py b/ifupdown2/ifupdownaddons/dhclient.py index d8f8924..4d907f5 100644 --- a/ifupdown2/ifupdownaddons/dhclient.py +++ b/ifupdown2/ifupdownaddons/dhclient.py @@ -85,25 +85,34 @@ class dhclient(utilsBase): '%s' %ifacename] self._run_dhclient_cmd(cmd, cmd_prefix) - def start6(self, ifacename, wait=True, cmd_prefix=None): + def start6(self, ifacename, wait=True, cmd_prefix=None, duid=None): cmd = ['/sbin/dhclient', '-6', '-pf', '/run/dhclient6.%s.pid' %ifacename, '-lf', '/var/lib/dhcp/dhclient6.%s.leases' % ifacename, '%s' %ifacename] if not wait: cmd.append('-nw') + if duid is not None: + cmd.append('-D') + cmd.append(duid) self._run_dhclient_cmd(cmd, cmd_prefix) - def stop6(self, ifacename, cmd_prefix=None): + def stop6(self, ifacename, cmd_prefix=None, duid=None): cmd = ['/sbin/dhclient', '-6', '-x', '-pf', '/run/dhclient6.%s.pid' % ifacename, '-lf', '/var/lib/dhcp/dhclient6.%s.leases' % ifacename, '%s' %ifacename] + if duid is not None: + cmd.append('-D') + cmd.append(duid) self._run_dhclient_cmd(cmd, cmd_prefix) - def release6(self, ifacename, cmd_prefix=None): + def release6(self, ifacename, cmd_prefix=None, duid=None): cmd = ['/sbin/dhclient', '-6', '-r', '-pf', '/run/dhclient6.%s.pid' %ifacename, '-lf', '/var/lib/dhcp/dhclient6.%s.leases' % ifacename, '%s' %ifacename] + if duid is not None: + cmd.append('-D') + cmd.append(duid) self._run_dhclient_cmd(cmd, cmd_prefix) From 1321d5e3578c15b48aed616638cad82ac9f5bf4d Mon Sep 17 00:00:00 2001 From: Rajendra Dendukuri Date: Wed, 10 Jul 2019 22:43:28 -0700 Subject: [PATCH 2/4] addons: dhcp: Policy to specify DUID type to use on dhcpv6 requests Update module description and changelog Signed-off-by: Rajendra Dendukuri --- debian/changelog | 1 + ifupdown2/addons/dhcp.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/debian/changelog b/debian/changelog index 2247f14..47b0275 100644 --- a/debian/changelog +++ b/debian/changelog @@ -11,6 +11,7 @@ ifupdown2 (1.2.6-1) unstable; urgency=medium * New: link-down yes will also down macvlans * New: XFRM addon module * New: Add policy to wait for IPv6 link local address to be available + * New: Add policy dhcp6-duid to specify DUID type to be used for IPv6 interfaces -- Julien Fortin Sun, 23 Jun 2019 23:42:42 -1000 diff --git a/ifupdown2/addons/dhcp.py b/ifupdown2/addons/dhcp.py index ca41988..67a66ea 100644 --- a/ifupdown2/addons/dhcp.py +++ b/ifupdown2/addons/dhcp.py @@ -32,6 +32,35 @@ except ImportError: class dhcp(moduleBase): """ ifupdown2 addon module to configure dhcp on interface """ + _modinfo = { + "mhelp": "Configure dhcp", + "attrs": { + "dhcp6-duid": { + "help": "Override the default when selecting the type of DUID to use. By default, DHCPv6 dhclient " + "creates an identifier based on the link-layer address (DUID-LL) if it is running in stateless " + "mode (with -S, not requesting an address), or it creates an identifier based on the " + "link-layer address plus a timestamp (DUID-LLT) if it is running in stateful mode (without -S, " + "requesting an address). When DHCPv4 is configured to use a DUID using -i option the default " + "is to use a DUID-LLT. -D overrides these default, with a value of either LL or LLT.", + "validvals": ["LL", "LLT"], + "example": ["dhcp6-duid LL"] + }, + "dhcp-wait": { + "help": "Wait or not wait and become a daemon immediately (nowait) rather than waiting until an " + "IP address has been acquired. If not specified default value is true, that is to wait.", + "validvals": ["true", "false"], + "example": ["dhcp-wait false"] + }, + "dhcp6-ll-wait": { + "help": "Overrides the default wait time before DHCPv6 client is started. During this wait time, " + "ifupdown2 checks if the interface requesting an address has a valid link-local address. " + "If not specified default value used is 10 seconds.", + "validvals": ["whole numbers"], + "example": ["dhcp6-ll-wait 0"] + } + } + } + def __init__(self, *args, **kargs): moduleBase.__init__(self, *args, **kargs) self.dhclientcmd = dhclient(**kargs) From a6f6c8b2ada26be191b6ddec8d2facea2528431c Mon Sep 17 00:00:00 2001 From: Julien Fortin Date: Fri, 12 Jul 2019 12:22:10 +0400 Subject: [PATCH 3/4] addons: dhcp: PEP8 fixes Signed-off-by: Julien Fortin --- ifupdown2/addons/dhcp.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/ifupdown2/addons/dhcp.py b/ifupdown2/addons/dhcp.py index 67a66ea..30886b4 100644 --- a/ifupdown2/addons/dhcp.py +++ b/ifupdown2/addons/dhcp.py @@ -34,30 +34,30 @@ class dhcp(moduleBase): _modinfo = { "mhelp": "Configure dhcp", - "attrs": { + "policies": { "dhcp6-duid": { "help": "Override the default when selecting the type of DUID to use. By default, DHCPv6 dhclient " "creates an identifier based on the link-layer address (DUID-LL) if it is running in stateless " "mode (with -S, not requesting an address), or it creates an identifier based on the " - "link-layer address plus a timestamp (DUID-LLT) if it is running in stateful mode (without -S, " + "link-layer address plus a timestamp (DUID-LLT) if it is running in stateful mode (without -S, " "requesting an address). When DHCPv4 is configured to use a DUID using -i option the default " "is to use a DUID-LLT. -D overrides these default, with a value of either LL or LLT.", - "validvals": ["LL", "LLT"], + "validvals": ["LL", "LLT"], "example": ["dhcp6-duid LL"] }, - "dhcp-wait": { + "dhcp-wait": { "help": "Wait or not wait and become a daemon immediately (nowait) rather than waiting until an " - "IP address has been acquired. If not specified default value is true, that is to wait.", - "validvals": ["true", "false"], + "IP address has been acquired. If not specified default value is true, that is to wait.", + "validvals": ["true", "false"], "example": ["dhcp-wait false"] }, - "dhcp6-ll-wait": { + "dhcp6-ll-wait": { "help": "Overrides the default wait time before DHCPv6 client is started. During this wait time, " "ifupdown2 checks if the interface requesting an address has a valid link-local address. " "If not specified default value used is 10 seconds.", - "validvals": ["whole numbers"], + "validvals": ["whole numbers"], "example": ["dhcp6-ll-wait 0"] - } + } } } From 79ba6a415ae1eb5f17d7db5573d18eb9f707b6e7 Mon Sep 17 00:00:00 2001 From: Julien Fortin Date: Fri, 12 Jul 2019 12:22:36 +0400 Subject: [PATCH 4/4] debian: changelog: add new changelog entry 1.2.8-1 Signed-off-by: Julien Fortin --- debian/changelog | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index 163e5b5..9917e34 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +ifupdown2 (1.2.8-1) unstable; urgency=medium + + * New: Add policy dhcp6-duid to specify DUID type to be used for IPv6 interfaces + + -- Julien Fortin Thu, 11 Jul 2019 23:42:42 +0200 + ifupdown2 (1.2.7-1) unstable; urgency=medium * New: Add bridge-ports-condone-regex option (closes #117) @@ -17,7 +23,6 @@ ifupdown2 (1.2.6-1) unstable; urgency=medium * New: link-down yes will also down macvlans * New: XFRM addon module * New: Add policy to wait for IPv6 link local address to be available - * New: Add policy dhcp6-duid to specify DUID type to be used for IPv6 interfaces -- Julien Fortin Sun, 23 Jun 2019 23:42:42 -1000