diff options
author | Petr Fedchenkov <giggsoff@gmail.com> | 2021-04-07 19:16:30 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-07 11:16:30 -0500 |
commit | 15dd3601c484e189ea82917600322b7d0e25c088 (patch) | |
tree | 4f1e6f93d52de1f99df862d9fc7d020c4e6ba423 | |
parent | fc5d541529d9f4a076998b7b4a3c90bb4be0000d (diff) | |
download | vyos-cloud-init-15dd3601c484e189ea82917600322b7d0e25c088.tar.gz vyos-cloud-init-15dd3601c484e189ea82917600322b7d0e25c088.zip |
bringup_static_routes: fix gateway check (#850)
When bringing up DHCP-provided static routes, we check for "0.0.0.0/0"
to indicate an unspecified gateway. However, when parsing the static
route in `parse_static_routes`, the gateway is never specified with
a net length, so the "/0" will never happen.
This change updates the gateway check to check only for "0.0.0.0".
-rw-r--r-- | cloudinit/net/__init__.py | 2 | ||||
-rw-r--r-- | cloudinit/net/tests/test_dhcp.py | 5 | ||||
-rw-r--r-- | cloudinit/net/tests/test_init.py | 15 | ||||
-rw-r--r-- | tools/.github-cla-signers | 1 |
4 files changed, 18 insertions, 5 deletions
diff --git a/cloudinit/net/__init__.py b/cloudinit/net/__init__.py index 385b7bcc..6b3b84f7 100644 --- a/cloudinit/net/__init__.py +++ b/cloudinit/net/__init__.py @@ -1135,7 +1135,7 @@ class EphemeralIPv4Network(object): # ("0.0.0.0/0", "130.56.240.1")] for net_address, gateway in self.static_routes: via_arg = [] - if gateway != "0.0.0.0/0": + if gateway != "0.0.0.0": via_arg = ['via', gateway] subp.subp( ['ip', '-4', 'route', 'add', net_address] + via_arg + diff --git a/cloudinit/net/tests/test_dhcp.py b/cloudinit/net/tests/test_dhcp.py index 74cf4b94..6f9a02de 100644 --- a/cloudinit/net/tests/test_dhcp.py +++ b/cloudinit/net/tests/test_dhcp.py @@ -194,6 +194,11 @@ class TestDHCPParseStaticRoutes(CiTestCase): self.assertEqual([('0.0.0.0/0', '130.56.240.1')], parse_static_routes(rfc3442)) + def test_unspecified_gateway(self): + rfc3442 = "32,169,254,169,254,0,0,0,0" + self.assertEqual([('169.254.169.254/32', '0.0.0.0')], + parse_static_routes(rfc3442)) + def test_parse_static_routes_class_c_b_a(self): class_c = "24,192,168,74,192,168,0,4" class_b = "16,172,16,172,16,0,4" diff --git a/cloudinit/net/tests/test_init.py b/cloudinit/net/tests/test_init.py index 946f8ee2..ad9c90ff 100644 --- a/cloudinit/net/tests/test_init.py +++ b/cloudinit/net/tests/test_init.py @@ -706,19 +706,23 @@ class TestEphemeralIPV4Network(CiTestCase): def test_ephemeral_ipv4_network_with_rfc3442_static_routes(self, m_subp): params = { 'interface': 'eth0', 'ip': '192.168.2.2', - 'prefix_or_mask': '255.255.255.0', 'broadcast': '192.168.2.255', - 'static_routes': [('169.254.169.254/32', '192.168.2.1'), + 'prefix_or_mask': '255.255.255.255', 'broadcast': '192.168.2.255', + 'static_routes': [('192.168.2.1/32', '0.0.0.0'), + ('169.254.169.254/32', '192.168.2.1'), ('0.0.0.0/0', '192.168.2.1')], 'router': '192.168.2.1'} expected_setup_calls = [ mock.call( - ['ip', '-family', 'inet', 'addr', 'add', '192.168.2.2/24', + ['ip', '-family', 'inet', 'addr', 'add', '192.168.2.2/32', 'broadcast', '192.168.2.255', 'dev', 'eth0'], capture=True, update_env={'LANG': 'C'}), mock.call( ['ip', '-family', 'inet', 'link', 'set', 'dev', 'eth0', 'up'], capture=True), mock.call( + ['ip', '-4', 'route', 'add', '192.168.2.1/32', + 'dev', 'eth0'], capture=True), + mock.call( ['ip', '-4', 'route', 'add', '169.254.169.254/32', 'via', '192.168.2.1', 'dev', 'eth0'], capture=True), mock.call( @@ -732,11 +736,14 @@ class TestEphemeralIPV4Network(CiTestCase): ['ip', '-4', 'route', 'del', '169.254.169.254/32', 'via', '192.168.2.1', 'dev', 'eth0'], capture=True), mock.call( + ['ip', '-4', 'route', 'del', '192.168.2.1/32', + 'dev', 'eth0'], capture=True), + mock.call( ['ip', '-family', 'inet', 'link', 'set', 'dev', 'eth0', 'down'], capture=True), mock.call( ['ip', '-family', 'inet', 'addr', 'del', - '192.168.2.2/24', 'dev', 'eth0'], capture=True) + '192.168.2.2/32', 'dev', 'eth0'], capture=True) ] with net.EphemeralIPv4Network(**params): self.assertEqual(expected_setup_calls, m_subp.call_args_list) diff --git a/tools/.github-cla-signers b/tools/.github-cla-signers index 0a573f9e..b39f4198 100644 --- a/tools/.github-cla-signers +++ b/tools/.github-cla-signers @@ -16,6 +16,7 @@ dhensby eandersson eb3095 emmanuelthome +giggsoff izzyleung johnsonshi jordimassaguerpla |