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);