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