mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-07 04:00:32 +01:00
rdisc: tighten up type and range of NMRDiscRoute.plen
This commit is contained in:
parent
15b486700f
commit
0e07bbf968
6 changed files with 32 additions and 37 deletions
|
|
@ -6169,23 +6169,15 @@ rdisc_config_changed (NMRDisc *rdisc, const NMRDiscData *rdata, guint changed_in
|
|||
|
||||
for (i = 0; i < rdata->routes_n; i++) {
|
||||
const NMRDiscRoute *discovered_route = &rdata->routes[i];
|
||||
NMPlatformIP6Route route;
|
||||
const NMPlatformIP6Route route = {
|
||||
.network = discovered_route->network,
|
||||
.plen = discovered_route->plen,
|
||||
.gateway = discovered_route->gateway,
|
||||
.rt_source = NM_IP_CONFIG_SOURCE_RDISC,
|
||||
.metric = nm_device_get_ip6_route_metric (self),
|
||||
};
|
||||
|
||||
/* Only accept non-default routes. The router has no idea what the
|
||||
* local configuration or user preferences are, so sending routes
|
||||
* with a prefix length of 0 is quite rude and thus ignored.
|
||||
*/
|
||||
if (discovered_route->plen > 0) {
|
||||
memset (&route, 0, sizeof (route));
|
||||
route.network = discovered_route->network;
|
||||
nm_assert (discovered_route->plen <= 128);
|
||||
route.plen = discovered_route->plen;
|
||||
route.gateway = discovered_route->gateway;
|
||||
route.rt_source = NM_IP_CONFIG_SOURCE_RDISC;
|
||||
route.metric = nm_device_get_ip6_route_metric (self);
|
||||
|
||||
nm_ip6_config_add_route (priv->ac_ip6_config, &route);
|
||||
}
|
||||
nm_ip6_config_add_route (priv->ac_ip6_config, &route);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -207,23 +207,15 @@ rdisc_config_changed (NMRDisc *rdisc, const NMRDiscData *rdata, guint changed_in
|
|||
|
||||
for (i = 0; i < rdata->routes_n; i++) {
|
||||
const NMRDiscRoute *discovered_route = &rdata->routes[i];
|
||||
NMPlatformIP6Route route;
|
||||
const NMPlatformIP6Route route = {
|
||||
.network = discovered_route->network,
|
||||
.plen = discovered_route->plen,
|
||||
.gateway = discovered_route->gateway,
|
||||
.rt_source = NM_IP_CONFIG_SOURCE_RDISC,
|
||||
.metric = global_opt.priority_v6,
|
||||
};
|
||||
|
||||
/* Only accept non-default routes. The router has no idea what the
|
||||
* local configuration or user preferences are, so sending routes
|
||||
* with a prefix length of 0 is quite rude and thus ignored.
|
||||
*/
|
||||
if ( discovered_route->plen > 0
|
||||
&& discovered_route->plen <= 128) {
|
||||
memset (&route, 0, sizeof (route));
|
||||
route.network = discovered_route->network;
|
||||
route.plen = discovered_route->plen;
|
||||
route.gateway = discovered_route->gateway;
|
||||
route.rt_source = NM_IP_CONFIG_SOURCE_RDISC;
|
||||
route.metric = global_opt.priority_v6;
|
||||
|
||||
nm_ip6_config_add_route (rdisc_config, &route);
|
||||
}
|
||||
nm_ip6_config_add_route (rdisc_config, &route);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -264,6 +264,8 @@ receive_ra (gpointer user_data)
|
|||
.preference = item->preference,
|
||||
};
|
||||
|
||||
g_assert (route.plen > 0 && route.plen <= 128);
|
||||
|
||||
if (nm_rdisc_add_route (rdisc, &route))
|
||||
changed |= NM_RDISC_CONFIG_ROUTES;
|
||||
|
||||
|
|
|
|||
|
|
@ -320,8 +320,16 @@ nm_rdisc_add_route (NMRDisc *rdisc, const NMRDiscRoute *new)
|
|||
NMRDiscDataInternal *rdata;
|
||||
int i, insert_idx = -1;
|
||||
|
||||
if (new->plen == 0 || new->plen > 128)
|
||||
return FALSE;
|
||||
if (new->plen == 0 || new->plen > 128) {
|
||||
/* Only expect non-default routes. The router has no idea what the
|
||||
* local configuration or user preferences are, so sending routes
|
||||
* with a prefix length of 0 must be ignored by NMRDisc.
|
||||
*
|
||||
* Also, upper layers also don't expect that NMRDisc exposes routes
|
||||
* with a plen or zero or larger then 128.
|
||||
*/
|
||||
g_return_val_if_reached (FALSE);
|
||||
}
|
||||
|
||||
priv = NM_RDISC_GET_PRIVATE (rdisc);
|
||||
rdata = &priv->rdata;
|
||||
|
|
@ -672,7 +680,7 @@ _config_changed_log (NMRDisc *rdisc, NMRDiscConfigMap changed)
|
|||
NMRDiscRoute *route = &g_array_index (rdata->routes, NMRDiscRoute, i);
|
||||
|
||||
inet_ntop (AF_INET6, &route->network, addrstr, sizeof (addrstr));
|
||||
_LOGD (" route %s/%d via %s pref %d exp %u", addrstr, route->plen,
|
||||
_LOGD (" route %s/%d via %s pref %d exp %u", addrstr, (int) route->plen,
|
||||
nm_utils_inet6_ntop (&route->gateway, NULL), route->preference,
|
||||
expiry (route));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
struct in6_addr network;
|
||||
int plen;
|
||||
guint8 plen;
|
||||
struct in6_addr gateway;
|
||||
guint32 timestamp;
|
||||
guint32 lifetime;
|
||||
|
|
|
|||
|
|
@ -90,11 +90,12 @@ match_route (const NMRDiscData *rdata, guint idx, const char *nw, int plen, cons
|
|||
g_assert (rdata);
|
||||
g_assert_cmpint (idx, <, rdata->routes_n);
|
||||
g_assert (rdata->routes);
|
||||
g_assert (plen > 0 && plen <= 128);
|
||||
|
||||
route = &rdata->routes[idx];
|
||||
|
||||
g_assert_cmpstr (inet_ntop (AF_INET6, &route->network, buf, sizeof (buf)), ==, nw);
|
||||
g_assert_cmpint (route->plen, ==, plen);
|
||||
g_assert_cmpint ((int) route->plen, ==, plen);
|
||||
g_assert_cmpstr (inet_ntop (AF_INET6, &route->gateway, buf, sizeof (buf)), ==, gw);
|
||||
g_assert_cmpint (route->timestamp, ==, ts);
|
||||
g_assert_cmpint (route->lifetime, ==, lt);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue