]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Subnets with prefix length 0 are invalid
authorSalvatore Orlando <salv.orlando@gmail.com>
Thu, 28 Aug 2014 21:54:18 +0000 (14:54 -0700)
committerSalvatore Orlando <salv.orlando@gmail.com>
Fri, 29 Aug 2014 19:16:05 +0000 (12:16 -0700)
This patch changes the API behaviour to return a 400 error
when a subnet with /0 prefix length is specified.

This kind of subnet hardly make any sense, and also cannot
possibly work when DHCP is enabled.

Change-Id: I8f822f14b91475dcf86ea44ee607013e61cbb6f7
Closes-Bug: #1362651

neutron/db/db_base_plugin_v2.py
neutron/tests/unit/test_db_plugin.py

index 9f8d7bf3fbf286f317ef8fd902bddd95dfad4e78..fa5cd3a425773f30871b92e8c9c74165d64463b0 100644 (file)
@@ -564,6 +564,16 @@ class NeutronDbPluginV2(neutron_plugin_base_v2.NeutronPluginBaseV2,
         CIDR if overlapping IPs are disabled.
         """
         new_subnet_ipset = netaddr.IPSet([new_subnet_cidr])
+        # Disallow subnets with prefix length 0 as they will lead to
+        # dnsmasq failures (see bug 1362651).
+        # This is not a discrimination against /0 subnets.
+        # A /0 subnet is conceptually possible but hardly a practical
+        # scenario for neutron's use cases.
+        for cidr in new_subnet_ipset.iter_cidrs():
+            if cidr.prefixlen == 0:
+                err_msg = _("0 is not allowed as CIDR prefix length")
+                raise n_exc.InvalidInput(error_message=err_msg)
+
         if cfg.CONF.allow_overlapping_ips:
             subnet_list = network.subnets
         else:
index 720d10948c7c5452b5dc9963183a935e5dee95d7..69c9451bdc9af2a090f21f61a3678c14c6dd6b24 100644 (file)
@@ -2357,6 +2357,17 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase):
             res = subnet_req.get_response(self.api)
             self.assertEqual(res.status_int, webob.exc.HTTPClientError.code)
 
+    def test_create_subnet_bad_V4_cidr_prefix_len(self):
+        with self.network() as network:
+            data = {'subnet': {'network_id': network['network']['id'],
+                    'cidr': '0.0.0.0/0',
+                    'ip_version': '4',
+                    'tenant_id': network['network']['tenant_id'],
+                    'gateway_ip': '0.0.0.1'}}
+            subnet_req = self.new_create_request('subnets', data)
+            res = subnet_req.get_response(self.api)
+            self.assertEqual(res.status_int, webob.exc.HTTPClientError.code)
+
     def test_create_subnet_bad_V6_cidr(self):
         with self.network() as network:
             data = {'subnet': {'network_id': network['network']['id'],