]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Specify prefix length for IPv6 subnets
authorAlexey I. Froloff <raorn@raorn.name>
Tue, 30 Sep 2014 12:37:19 +0000 (16:37 +0400)
committerAlexey I. Froloff <raorn@raorn.name>
Tue, 13 Jan 2015 14:32:02 +0000 (17:32 +0300)
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
neutron/tests/unit/test_linux_dhcp.py

index 534d27969bd2f7dc74ba455d46edd61f66ba5752..2dfd7faebdcfbbe19093dbc91fad2719fbfba6a5 100644 (file)
@@ -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
index 98b5beaab8825f620a0c9b422e16e5a2f847b47f..e5cbdb8be215d40984c7311caa8b9fbb1870895c 100644 (file)
@@ -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(