summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2016-07-07 15:45:58 +0200
committerThomas Haller <thaller@redhat.com>2016-07-08 12:35:14 +0200
commit0e07bbf9687c920f2a065d68b839c9ad3ce69576 (patch)
treeaada973a2434514f2097128b846e9e70c63c9a79
parent15b486700fb5db66a8acc801507dbc473ae18bea (diff)
downloadNetworkManager-0e07bbf9687c920f2a065d68b839c9ad3ce69576.tar.gz
rdisc: tighten up type and range of NMRDiscRoute.plen
-rw-r--r--src/devices/nm-device.c26
-rw-r--r--src/nm-iface-helper.c26
-rw-r--r--src/rdisc/nm-fake-rdisc.c2
-rw-r--r--src/rdisc/nm-rdisc.c14
-rw-r--r--src/rdisc/nm-rdisc.h2
-rw-r--r--src/rdisc/tests/test-rdisc-fake.c3
6 files changed, 34 insertions, 39 deletions
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index a5b5ced087..f98ab0ec73 100644
--- a/src/devices/nm-device.c
+++ b/src/devices/nm-device.c
@@ -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;
-
- /* 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);
- }
+ 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),
+ };
+
+ nm_ip6_config_add_route (priv->ac_ip6_config, &route);
}
}
diff --git a/src/nm-iface-helper.c b/src/nm-iface-helper.c
index 0801ca40d5..49672cf565 100644
--- a/src/nm-iface-helper.c
+++ b/src/nm-iface-helper.c
@@ -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;
-
- /* 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);
- }
+ 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,
+ };
+
+ nm_ip6_config_add_route (rdisc_config, &route);
}
}
diff --git a/src/rdisc/nm-fake-rdisc.c b/src/rdisc/nm-fake-rdisc.c
index 3636f64e17..043986277f 100644
--- a/src/rdisc/nm-fake-rdisc.c
+++ b/src/rdisc/nm-fake-rdisc.c
@@ -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;
diff --git a/src/rdisc/nm-rdisc.c b/src/rdisc/nm-rdisc.c
index aba4320205..cf993bc311 100644
--- a/src/rdisc/nm-rdisc.c
+++ b/src/rdisc/nm-rdisc.c
@@ -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));
}
diff --git a/src/rdisc/nm-rdisc.h b/src/rdisc/nm-rdisc.h
index 69c8973d68..9e5e9349bc 100644
--- a/src/rdisc/nm-rdisc.h
+++ b/src/rdisc/nm-rdisc.h
@@ -78,7 +78,7 @@ typedef struct {
typedef struct {
struct in6_addr network;
- int plen;
+ guint8 plen;
struct in6_addr gateway;
guint32 timestamp;
guint32 lifetime;
diff --git a/src/rdisc/tests/test-rdisc-fake.c b/src/rdisc/tests/test-rdisc-fake.c
index ffcaf893bb..02ffb5100e 100644
--- a/src/rdisc/tests/test-rdisc-fake.c
+++ b/src/rdisc/tests/test-rdisc-fake.c
@@ -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);