render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Blob Blame History Raw
From 83e667d206d16867cfc640b118a37e46d1ef897d Mon Sep 17 00:00:00 2001
Message-Id: <83e667d206d16867cfc640b118a37e46d1ef897d@dist-git>
From: Martin Kletzander <mkletzan@redhat.com>
Date: Thu, 6 Aug 2015 13:10:24 +0200
Subject: [PATCH] network: Add another collision check into
 networkCheckRouteCollision

The comment above that function says: "This function can be a lot more
exhaustive, ...", so let's be.

Check for collisions between routes in the system and static routes
being added explicitly from the <route/> element of the network XML.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1094205

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
(cherry picked from commit 0e3ad241f3f421c23bbe2cbe11a70f8e9184dc65)
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/network/bridge_driver_linux.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/src/network/bridge_driver_linux.c b/src/network/bridge_driver_linux.c
index e394daf..bd7508c 100644
--- a/src/network/bridge_driver_linux.c
+++ b/src/network/bridge_driver_linux.c
@@ -69,6 +69,7 @@ int networkCheckRouteCollision(virNetworkDefPtr def)
         char iface[17], dest[128], mask[128];
         unsigned int addr_val, mask_val;
         virNetworkIpDefPtr ipdef;
+        virNetworkRouteDefPtr routedef;
         int num;
         size_t i;
 
@@ -123,6 +124,34 @@ int networkCheckRouteCollision(virNetworkDefPtr def)
                 goto out;
             }
         }
+
+        for (i = 0;
+             (routedef = virNetworkDefGetRouteByIndex(def, AF_INET, i));
+             i++) {
+
+            virSocketAddr r_mask, r_addr;
+            virSocketAddrPtr tmp_addr = virNetworkRouteDefGetAddress(routedef);
+            int r_prefix = virNetworkRouteDefGetPrefix(routedef);
+
+            if (!tmp_addr ||
+                virSocketAddrMaskByPrefix(tmp_addr, r_prefix, &r_addr) < 0 ||
+                virSocketAddrPrefixToNetmask(r_prefix, &r_mask, AF_INET) < 0)
+                continue;
+
+            if ((r_addr.data.inet4.sin_addr.s_addr == addr_val) &&
+                (r_mask.data.inet4.sin_addr.s_addr == mask_val)) {
+                char *addr_str = virSocketAddrFormat(&r_addr);
+                if (!addr_str)
+                    virResetLastError();
+                virReportError(VIR_ERR_INTERNAL_ERROR,
+                               _("Route address '%s' conflicts "
+                                 "with IP address for '%s'"),
+                               NULLSTR(addr_str), iface);
+                VIR_FREE(addr_str);
+                ret = -1;
+                goto out;
+            }
+        }
     }
 
  out:
-- 
2.5.0