From 259fe2189506ebbf659d62c1d405176fb3ec7f91 Mon Sep 17 00:00:00 2001 From: Adit Sarfaty Date: Tue, 2 Jan 2018 15:03:43 +0200 Subject: [PATCH] NSX|v+v3: Prevent adding 0.0.0.0 route to router Both NSX backend does not support adding a static route with destination 0.0.0.0/#. Commit Ibb4f81a484de48f7ea65cb2bb6968e55eae087ad failed the request for destination 0.0.0.0/0, but it should be failed for any prefix size. Change-Id: Id1c299ad49ef8f34aede9b876f23fdb7ac7203e4 --- vmware_nsx/plugins/common/plugin.py | 2 +- vmware_nsx/tests/unit/nsx_v3/test_plugin.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/vmware_nsx/plugins/common/plugin.py b/vmware_nsx/plugins/common/plugin.py index d8f0ad97c5..01b2dc3bfb 100644 --- a/vmware_nsx/plugins/common/plugin.py +++ b/vmware_nsx/plugins/common/plugin.py @@ -327,7 +327,7 @@ class NsxPluginBase(db_base_plugin_v2.NeutronDbPluginV2, context, router_id, routes) # do not allow adding a default route. NSX-v/v3 don't support it for route in routes: - if route.get('destination') == '0.0.0.0/0': + if route.get('destination', '').startswith('0.0.0.0/'): msg = _("Cannot set a default route using static routes") raise n_exc.BadRequest(resource='router', msg=msg) diff --git a/vmware_nsx/tests/unit/nsx_v3/test_plugin.py b/vmware_nsx/tests/unit/nsx_v3/test_plugin.py index 637536aaaf..7b586d5a98 100644 --- a/vmware_nsx/tests/unit/nsx_v3/test_plugin.py +++ b/vmware_nsx/tests/unit/nsx_v3/test_plugin.py @@ -1750,6 +1750,22 @@ class TestL3NatTestCase(L3NatTest, az_hints = rtr['router']['availability_zone_hints'] self.assertListEqual(zone, az_hints) + def _test_route_update_illegal(self, destination): + routes = [{'destination': destination, 'nexthop': '10.0.1.3'}] + with self.router() as r: + with self.subnet(cidr='10.0.1.0/24') as s: + fixed_ip_data = [{'ip_address': '10.0.1.2'}] + with self.port(subnet=s, fixed_ips=fixed_ip_data) as p: + self._router_interface_action( + 'add', r['router']['id'], None, p['port']['id']) + self._update('routers', r['router']['id'], + {'router': {'routes': routes}}, + expected_code=400) + + def test_route_update_illegal(self): + self._test_route_update_illegal('0.0.0.0/0') + self._test_route_update_illegal('0.0.0.0/16') + class ExtGwModeTestCase(test_ext_gw_mode.ExtGwModeIntTestCase, L3NatTest):