From f996a7b46878f543ecf775380529af10fe87b8cb Mon Sep 17 00:00:00 2001 From: "Alexey I. Froloff" Date: Tue, 30 Sep 2014 16:37:19 +0400 Subject: [PATCH] Specify prefix length for IPv6 subnets If Network contains dhcpv6-stateful Subnet with prefix other than /64, dnsmasq refuses to start if prefix-len is not specified in dhcp-range option. From dnsmasq(8) manpage: For IPv6, the parameters are slightly different: instead of netmask and broadcast address, there is an optional prefix length which must be equal to or larger then the prefix length on the local interface. If not given, this defaults to 64. Unlike the IPv4 case, the prefix length is not automatically derived from the interface configuration. The mimimum size of the prefix length is 64. It is safe to always specify prefix length, so dnsmasq will use correct configuration. Change-Id: Ibef1f55926585016f0054accd7f7ef5a022e3fe1 Closes-Bug: #1372883 --- neutron/agent/linux/dhcp.py | 12 +++++++++--- neutron/tests/unit/test_linux_dhcp.py | 11 +++++++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/neutron/agent/linux/dhcp.py b/neutron/agent/linux/dhcp.py index 534d27969..2dfd7faeb 100644 --- a/neutron/agent/linux/dhcp.py +++ b/neutron/agent/linux/dhcp.py @@ -405,9 +405,15 @@ class Dnsmasq(DhcpLocalProcess): # mode is optional and is not set - skip it if mode: - cmd.append('--dhcp-range=%s%s,%s,%s,%s' % - ('set:', self._TAG_PREFIX % i, - cidr.network, mode, lease)) + if subnet.ip_version == 4: + cmd.append('--dhcp-range=%s%s,%s,%s,%s' % + ('set:', self._TAG_PREFIX % i, + cidr.network, mode, lease)) + else: + cmd.append('--dhcp-range=%s%s,%s,%s,%d,%s' % + ('set:', self._TAG_PREFIX % i, + cidr.network, mode, + cidr.prefixlen, lease)) possible_leases += cidr.size # Cap the limit because creating lots of subnets can inflate diff --git a/neutron/tests/unit/test_linux_dhcp.py b/neutron/tests/unit/test_linux_dhcp.py index 98b5beaab..e5cbdb8be 100644 --- a/neutron/tests/unit/test_linux_dhcp.py +++ b/neutron/tests/unit/test_linux_dhcp.py @@ -791,14 +791,21 @@ class TestDnsmasq(TestBase): seconds = 's' if has_static: prefix = '--dhcp-range=set:tag%d,%s,static,%s%s' + prefix6 = '--dhcp-range=set:tag%d,%s,static,%s,%s%s' else: prefix = '--dhcp-range=set:tag%d,%s,%s%s' + prefix6 = '--dhcp-range=set:tag%d,%s,%s,%s%s' possible_leases = 0 for i, s in enumerate(network.subnets): if (s.ip_version != 6 or s.ipv6_address_mode == constants.DHCPV6_STATEFUL): - expected.extend([prefix % ( - i, s.cidr.split('/')[0], lease_duration, seconds)]) + if s.ip_version == 4: + expected.extend([prefix % ( + i, s.cidr.split('/')[0], lease_duration, seconds)]) + else: + expected.extend([prefix6 % ( + i, s.cidr.split('/')[0], s.cidr.split('/')[1], + lease_duration, seconds)]) possible_leases += netaddr.IPNetwork(s.cidr).size expected.append('--dhcp-lease-max=%d' % min( -- 2.45.2