]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Disable port creation when invalid MAC address is provided
authorsridhargaddam <sridhar.gaddam@enovance.com>
Mon, 13 Jul 2015 14:00:20 +0000 (14:00 +0000)
committersridhargaddam <sridhar.gaddam@enovance.com>
Thu, 23 Jul 2015 09:35:28 +0000 (09:35 +0000)
When a port is manually created with an invalid mac address like
'00:00:00:00:00:00' and associated to neutron router, we see an
exception in L3-agent logs. Since we do not have any valid use-case
to have a port with a mac_address of all zeros, this patch disables
the corresponding port creation/updation request.

Along with all zeros MAC, validation aganist broadcast MAC is also
included in this patch.

DocImpact

Closes-Bug: #1472243
Change-Id: I93875716550dbc1f299aee95c45144e4904af233

neutron/api/v2/attributes.py
neutron/common/constants.py
neutron/tests/unit/api/v2/test_attributes.py

index 64a45e89105dba884a658e2073488c2a4639e545..b1a9f1a34a1615073e713acab7e1bc03aa0ded13 100644 (file)
@@ -170,6 +170,10 @@ def _validate_mac_address(data, valid_values=None):
         valid_mac = netaddr.valid_mac(_validate_no_whitespace(data))
     except Exception:
         valid_mac = False
+
+    if valid_mac:
+        valid_mac = not netaddr.EUI(data) in map(netaddr.EUI,
+                    constants.INVALID_MAC_ADDRESSES)
     # TODO(arosen): The code in this file should be refactored
     # so it catches the correct exceptions. _validate_no_whitespace
     # raises AttributeError if data is None.
index fc9c4b246332a7d778854689fffe7dbb01dcf4bd..0c4af837a965a5f679e755188a9207eb4fa5dd14 100644 (file)
@@ -72,6 +72,8 @@ IP_VERSION_6 = 6
 IPv4_BITS = 32
 IPv6_BITS = 128
 
+INVALID_MAC_ADDRESSES = ['00:00:00:00:00:00', 'FF:FF:FF:FF:FF:FF']
+
 IPv4_ANY = '0.0.0.0/0'
 IPv6_ANY = '::/0'
 IP_ANY = {IP_VERSION_4: IPv4_ANY, IP_VERSION_6: IPv6_ANY}
index 512fc3022e7e861d69709beff69eb568d83b55b0..0f0828a4c47d1a002da280654347ceef25155755 100644 (file)
@@ -19,6 +19,7 @@ import testtools
 import mock
 
 from neutron.api.v2 import attributes
+from neutron.common import constants
 from neutron.common import exceptions as n_exc
 from neutron.tests import base
 from neutron.tests import tools
@@ -187,6 +188,10 @@ class TestAttributes(base.BaseTestCase):
         err_msg = "'%s' is not a valid MAC address"
         self.assertEqual(err_msg % mac_addr, msg)
 
+        for invalid_mac_addr in constants.INVALID_MAC_ADDRESSES:
+            msg = validator(invalid_mac_addr)
+            self.assertEqual(err_msg % invalid_mac_addr, msg)
+
         mac_addr = "123"
         msg = validator(mac_addr)
         self.assertEqual(err_msg % mac_addr, msg)