fake-platform: reject adding routes without the gateway on the same interface

This mimics Linux behavior.

(cherry picked from commit 4d097829f0)
This commit is contained in:
Lubomir Rintel 2015-01-27 13:54:16 +01:00 committed by Thomas Haller
parent 7e5981a894
commit 63611cb46f

View file

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