a7acbb
From ea83e72b335e652b080fda66a075c0d1322ed6dc Mon Sep 17 00:00:00 2001
a7acbb
From: Emanuele Giuseppe Esposito <eesposit@redhat.com>
a7acbb
Date: Tue, 7 Dec 2021 10:00:41 +0100
a7acbb
Subject: [PATCH] cloudinit/net: handle two different routes for the same ip
a7acbb
 (#1124)
a7acbb
a7acbb
RH-Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
a7acbb
RH-MergeRequest: 39: cloudinit/net: handle two different routes for the same ip (#1124)
a7acbb
RH-Commit: [1/1] 6810dc29ce786fbca96d2033386aa69c6ab65997
a7acbb
RH-Bugzilla: 2028028
a7acbb
RH-Acked-by: Mohamed Gamal Morsy <mmorsy@redhat.com>
a7acbb
RH-Acked-by: Eduardo Otubo <otubo@redhat.com>
a7acbb
a7acbb
commit 0e25076b34fa995161b83996e866c0974cee431f
a7acbb
Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
a7acbb
Date:   Mon Dec 6 18:34:26 2021 +0100
a7acbb
a7acbb
    cloudinit/net: handle two different routes for the same ip (#1124)
a7acbb
a7acbb
    If we set a dhcp server side like this:
a7acbb
    $ cat /var/tmp/cloud-init/cloud-init-dhcp-f0rie5tm/dhcp.leases
a7acbb
    lease {
a7acbb
    ...
a7acbb
    option classless-static-routes 31.169.254.169.254 0.0.0.0,31.169.254.169.254
a7acbb
        10.112.143.127,22.10.112.140 0.0.0.0,0 10.112.140.1;
a7acbb
    ...
a7acbb
    }
a7acbb
    cloud-init fails to configure the routes via 'ip route add' because to there are
a7acbb
    two different routes for 169.254.169.254:
a7acbb
a7acbb
    $ ip -4 route add 192.168.1.1/32 via 0.0.0.0 dev eth0
a7acbb
    $ ip -4 route add 192.168.1.1/32 via 10.112.140.248 dev eth0
a7acbb
a7acbb
    But NetworkManager can handle such scenario successfully as it uses "ip route append".
a7acbb
    So change cloud-init to also use "ip route append" to fix the issue:
a7acbb
a7acbb
    $ ip -4 route append 192.168.1.1/32 via 0.0.0.0 dev eth0
a7acbb
    $ ip -4 route append 192.168.1.1/32 via 10.112.140.248 dev eth0
a7acbb
a7acbb
    Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
a7acbb
a7acbb
    RHBZ: #2003231
a7acbb
a7acbb
Conflicts:
a7acbb
    cloudinit/net/tests/test_init.py: a mock call in
a7acbb
    test_ephemeral_ipv4_network_with_rfc3442_static_routes is not
a7acbb
    present downstream.
a7acbb
a7acbb
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
a7acbb
---
a7acbb
 cloudinit/net/__init__.py        | 2 +-
a7acbb
 cloudinit/net/tests/test_init.py | 4 ++--
a7acbb
 2 files changed, 3 insertions(+), 3 deletions(-)
a7acbb
a7acbb
diff --git a/cloudinit/net/__init__.py b/cloudinit/net/__init__.py
a7acbb
index 385b7bcc..003efa2a 100644
a7acbb
--- a/cloudinit/net/__init__.py
a7acbb
+++ b/cloudinit/net/__init__.py
a7acbb
@@ -1138,7 +1138,7 @@ class EphemeralIPv4Network(object):
a7acbb
             if gateway != "0.0.0.0/0":
a7acbb
                 via_arg = ['via', gateway]
a7acbb
             subp.subp(
a7acbb
-                ['ip', '-4', 'route', 'add', net_address] + via_arg +
a7acbb
+                ['ip', '-4', 'route', 'append', net_address] + via_arg +
a7acbb
                 ['dev', self.interface], capture=True)
a7acbb
             self.cleanup_cmds.insert(
a7acbb
                 0, ['ip', '-4', 'route', 'del', net_address] + via_arg +
a7acbb
diff --git a/cloudinit/net/tests/test_init.py b/cloudinit/net/tests/test_init.py
a7acbb
index 946f8ee2..2350837b 100644
a7acbb
--- a/cloudinit/net/tests/test_init.py
a7acbb
+++ b/cloudinit/net/tests/test_init.py
a7acbb
@@ -719,10 +719,10 @@ class TestEphemeralIPV4Network(CiTestCase):
a7acbb
                 ['ip', '-family', 'inet', 'link', 'set', 'dev', 'eth0', 'up'],
a7acbb
                 capture=True),
a7acbb
             mock.call(
a7acbb
-                ['ip', '-4', 'route', 'add', '169.254.169.254/32',
a7acbb
+                ['ip', '-4', 'route', 'append', '169.254.169.254/32',
a7acbb
                  'via', '192.168.2.1', 'dev', 'eth0'], capture=True),
a7acbb
             mock.call(
a7acbb
-                ['ip', '-4', 'route', 'add', '0.0.0.0/0',
a7acbb
+                ['ip', '-4', 'route', 'append', '0.0.0.0/0',
a7acbb
                  'via', '192.168.2.1', 'dev', 'eth0'], capture=True)]
a7acbb
         expected_teardown_calls = [
a7acbb
             mock.call(
a7acbb
-- 
a7acbb
2.27.0
a7acbb