mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-01 01:20:12 +01:00
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:
parent
7e5981a894
commit
63611cb46f
1 changed files with 36 additions and 0 deletions
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue