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-07 15:45:58 +0200
commit1d56143892adfd1a2716c3a6cf6b61e264ca9295 (patch)
tree4a78e3e36b3df79d978f327052e91289b3f26a76
parent69eedf445b4fb51bd467bd6f747075e6f21f6eb2 (diff)
downloadNetworkManager-th/rdisc-cleanup.tar.gz
rdisc: tighten up type and range of NMRDiscRoute.plenth/rdisc-cleanup
-rw-r--r--src/devices/nm-device.c25
-rw-r--r--src/nm-iface-helper.c25
-rw-r--r--src/rdisc/nm-fake-rdisc.c2
-rw-r--r--src/rdisc/nm-rdisc.c4
-rw-r--r--src/rdisc/nm-rdisc.h2
-rw-r--r--src/rdisc/tests/test-rdisc-fake.c3
6 files changed, 31 insertions, 30 deletions
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index a9bed4eae6..cf0c51afc5 100644
--- a/src/devices/nm-device.c
+++ b/src/devices/nm-device.c
@@ -6163,21 +6163,20 @@ rdisc_config_changed (NMRDisc *rdisc, const NMRDiscData *rdata, guint changed_in
const NMRDiscRoute *discovered_route = &rdata->routes[i];
NMPlatformIP6Route route;
- /* Only accept non-default routes. The router has no idea what the
+ /* 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 is quite rude and thus ignored.
+ * with a prefix length of 0 must be ignored by NMRDisc.
*/
- 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_assert (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 = 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..63da5e51ef 100644
--- a/src/nm-iface-helper.c
+++ b/src/nm-iface-helper.c
@@ -209,21 +209,20 @@ rdisc_config_changed (NMRDisc *rdisc, const NMRDiscData *rdata, guint changed_in
const NMRDiscRoute *discovered_route = &rdata->routes[i];
NMPlatformIP6Route route;
- /* Only accept non-default routes. The router has no idea what the
+ /* 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 is quite rude and thus ignored.
+ * with a prefix length of 0 must be ignored by NMRDisc.
*/
- 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_assert (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);
}
}
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 db2bb0c877..55516f194d 100644
--- a/src/rdisc/nm-rdisc.c
+++ b/src/rdisc/nm-rdisc.c
@@ -323,7 +323,7 @@ nm_rdisc_add_route (NMRDisc *rdisc, const NMRDiscRoute *new)
int i, insert_idx = -1;
if (new->plen == 0 || new->plen > 128)
- return FALSE;
+ g_return_val_if_reached (FALSE);
priv = NM_RDISC_GET_PRIVATE (rdisc);
rdata = &priv->rdata;
@@ -673,7 +673,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 c160477b91..ca400681e8 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);