]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Make sure dnsmasq can distinguish IPv6 address from MAC address
authorDazhao <dzyu@cn.ibm.com>
Fri, 21 Feb 2014 09:53:30 +0000 (17:53 +0800)
committerThomas Goirand <thomas@goirand.fr>
Thu, 13 Mar 2014 07:20:30 +0000 (15:20 +0800)
Currrently, due to in dnsmasq host file, the IPv6 address does
not be wrapped with '[]', dnsmasq cannot distinguish IPv6 address
from MAC address, it will cause the deployed instances cannot get
IPv6 address via dnsmasq dhcp service.

Change-Id: I023e44667a238664d11f2ac2cc484432cd301bcc
Closes-Bug: #1281916

neutron/agent/linux/dhcp.py
neutron/tests/unit/test_linux_dhcp.py

index 8850306e7b814af9a530cf69b698272be8b25cc6..e1682d8aca2a6b935e24205f72bcbf6b2a4e0d3e 100644 (file)
@@ -419,16 +419,22 @@ class Dnsmasq(DhcpLocalProcess):
                 name = 'host-%s.%s' % (r.sub('-', alloc.ip_address),
                                        self.conf.dhcp_domain)
                 set_tag = ''
+                # (dzyu) Check if it is legal ipv6 address, if so, need wrap
+                # it with '[]' to let dnsmasq to distinguish MAC address from
+                # IPv6 address.
+                ip_address = alloc.ip_address
+                if netaddr.valid_ipv6(ip_address):
+                    ip_address = '[%s]' % ip_address
                 if getattr(port, 'extra_dhcp_opts', False):
                     if self.version >= self.MINIMUM_VERSION:
                         set_tag = 'set:'
 
                     buf.write('%s,%s,%s,%s%s\n' %
-                              (port.mac_address, name, alloc.ip_address,
+                              (port.mac_address, name, ip_address,
                                set_tag, port.id))
                 else:
                     buf.write('%s,%s,%s\n' %
-                              (port.mac_address, name, alloc.ip_address))
+                              (port.mac_address, name, ip_address))
 
         name = self.get_conf_file_name('host')
         utils.replace_file(name, buf.getvalue())
index 146043341dedfd535a1e5c6678caacb3f66e1dc2..7086a7b7fee91812d087ad84c3b53c1fd7126700 100644 (file)
@@ -966,11 +966,11 @@ tag:44444444-4444-4444-4444-444444444444,option:bootfile-name,pxelinux3.0"""
         exp_host_data = ('00:00:80:aa:bb:cc,host-192-168-0-2.openstacklocal,'
                          '192.168.0.2\n'
                          '00:00:f3:aa:bb:cc,host-fdca-3ba5-a17a-4ba3--2.'
-                         'openstacklocal,fdca:3ba5:a17a:4ba3::2\n'
+                         'openstacklocal,[fdca:3ba5:a17a:4ba3::2]\n'
                          '00:00:0f:aa:bb:cc,host-192-168-0-3.openstacklocal,'
                          '192.168.0.3\n'
                          '00:00:0f:aa:bb:cc,host-fdca-3ba5-a17a-4ba3--3.'
-                         'openstacklocal,fdca:3ba5:a17a:4ba3::3\n'
+                         'openstacklocal,[fdca:3ba5:a17a:4ba3::3]\n'
                          '00:00:0f:rr:rr:rr,host-192-168-0-1.openstacklocal,'
                          '192.168.0.1\n').lstrip()
         exp_opt_name = '/dhcp/cccccccc-cccc-cccc-cccc-cccccccccccc/opts'
@@ -1015,11 +1015,11 @@ tag:tag1,249,%s,%s""".lstrip() % (fake_v6,
         exp_host_data = ('00:00:80:aa:bb:cc,host-192-168-0-2.openstacklocal,'
                          '192.168.0.2\n'
                          '00:00:f3:aa:bb:cc,host-fdca-3ba5-a17a-4ba3--2.'
-                         'openstacklocal,fdca:3ba5:a17a:4ba3::2\n'
+                         'openstacklocal,[fdca:3ba5:a17a:4ba3::2]\n'
                          '00:00:0f:aa:bb:cc,host-192-168-0-3.openstacklocal,'
                          '192.168.0.3\n'
                          '00:00:0f:aa:bb:cc,host-fdca-3ba5-a17a-4ba3--3.'
-                         'openstacklocal,fdca:3ba5:a17a:4ba3::3\n'
+                         'openstacklocal,[fdca:3ba5:a17a:4ba3::3]\n'
                          '00:00:0f:rr:rr:rr,host-192-168-0-1.openstacklocal,'
                          '192.168.0.1\n').lstrip()
         exp_host_data.replace('\n', '')