From 63611cb46f51147fb123950578d08cd74fec6a2c Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Tue, 27 Jan 2015 13:54:16 +0100 Subject: [PATCH] fake-platform: reject adding routes without the gateway on the same interface This mimics Linux behavior. (cherry picked from commit 4d097829f0e70200c4f4589dfacd1f6de6a37e1d) --- src/platform/nm-fake-platform.c | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/platform/nm-fake-platform.c b/src/platform/nm-fake-platform.c index a8d437dc05..71a4e9f8f1 100644 --- a/src/platform/nm-fake-platform.c +++ b/src/platform/nm-fake-platform.c @@ -1124,6 +1124,23 @@ ip4_route_add (NMPlatform *platform, int ifindex, NMIPConfigSource source, route.metric = metric; route.mss = mss; + if (gateway) { + for (i = 0; i < priv->ip4_routes->len; i++) { + NMPlatformIP4Route *item = &g_array_index (priv->ip4_routes, + NMPlatformIP4Route, i); + guint32 gate = ntohl (item->network) >> (32 - item->plen); + guint32 host = ntohl (gateway) >> (32 - item->plen); + + if (ifindex == item->ifindex && gate == host) + break; + } + if (i == priv->ip4_routes->len) { + g_warning ("Fake platform: error adding %s: Network Unreachable", + nm_platform_ip4_route_to_string (&route)); + return FALSE; + } + } + for (i = 0; i < priv->ip4_routes->len; i++) { NMPlatformIP4Route *item = &g_array_index (priv->ip4_routes, NMPlatformIP4Route, i); @@ -1172,6 +1189,25 @@ ip6_route_add (NMPlatform *platform, int ifindex, NMIPConfigSource source, route.metric = metric; route.mss = mss; + if (!IN6_IS_ADDR_UNSPECIFIED(&gateway)) { + for (i = 0; i < priv->ip6_routes->len; i++) { + NMPlatformIP6Route *item = &g_array_index (priv->ip6_routes, + NMPlatformIP6Route, i); + guint8 gate_bits = gateway.s6_addr[item->plen / 8] >> (8 - item->plen % 8); + guint8 host_bits = item->network.s6_addr[item->plen / 8] >> (8 - item->plen % 8); + + if ( ifindex == item->ifindex + && memcmp (&gateway, &item->network, item->plen / 8) == 0 + && gate_bits == host_bits) + break; + } + if (i == priv->ip6_routes->len) { + g_warning ("Fake platform: error adding %s: Network Unreachable", + nm_platform_ip6_route_to_string (&route)); + return FALSE; + } + } + for (i = 0; i < priv->ip6_routes->len; i++) { NMPlatformIP6Route *item = &g_array_index (priv->ip6_routes, NMPlatformIP6Route, i);