summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2013-08-02 23:49:34 -0500
committerDan Williams <dcbw@redhat.com>2013-08-03 00:14:19 -0500
commit7570832b20e6fb5ff6cad89e870a28dc998d26fc (patch)
treeaa47c9aa2dc2c650fd0669da6ffd8fdfcc6ae321
parentc936f61a4308496957fa5323023ccefea8df126e (diff)
downloadNetworkManager-7570832b20e6fb5ff6cad89e870a28dc998d26fc.tar.gz
platform: simplify getting routes and ignoring the default route
Most places except the tests don't want the default route when asking the platform for all routes, so make that simpler by just adding a parameter for including the default route or not.
-rw-r--r--src/nm-ip4-config.c8
-rw-r--r--src/nm-ip6-config.c8
-rw-r--r--src/platform/nm-fake-platform.c16
-rw-r--r--src/platform/nm-linux-platform.c10
-rw-r--r--src/platform/nm-platform.c20
-rw-r--r--src/platform/nm-platform.h8
-rw-r--r--src/platform/tests/dump.c4
-rw-r--r--src/platform/tests/platform.c4
-rw-r--r--src/platform/tests/test-cleanup.c8
-rw-r--r--src/platform/tests/test-route.c4
10 files changed, 38 insertions, 52 deletions
diff --git a/src/nm-ip4-config.c b/src/nm-ip4-config.c
index 7e76e0ddee..1647d35800 100644
--- a/src/nm-ip4-config.c
+++ b/src/nm-ip4-config.c
@@ -123,15 +123,9 @@ nm_ip4_config_capture (int ifindex)
return NULL;
}
- routes_array = nm_platform_ip4_route_get_all (ifindex);
+ routes_array = nm_platform_ip4_route_get_all (ifindex, FALSE);
routes = (NMPlatformIP4Route *)routes_array->data;
for (i = 0; i < routes_array->len; i++) {
- /* Default route ignored; it's handled internally by NM and not
- * tracked in the device's IP config.
- */
- if (routes[i].plen == 0)
- continue;
-
route = nm_ip4_route_new ();
nm_ip4_route_set_dest (route, routes[i].network);
nm_ip4_route_set_prefix (route, routes[i].plen);
diff --git a/src/nm-ip6-config.c b/src/nm-ip6-config.c
index a4b6a4ecac..1fddb6438d 100644
--- a/src/nm-ip6-config.c
+++ b/src/nm-ip6-config.c
@@ -125,15 +125,9 @@ nm_ip6_config_capture (int ifindex)
return NULL;
}
- routes_array = nm_platform_ip6_route_get_all (ifindex);
+ routes_array = nm_platform_ip6_route_get_all (ifindex, FALSE);
routes = (NMPlatformIP6Route *)routes_array->data;
for (i = 0; i < routes_array->len; i++) {
- /* Default route ignored; it's handled internally by NM and not
- * tracked in the device's IP config.
- */
- if (routes[i].plen == 0)
- continue;
-
route = nm_ip6_route_new ();
nm_ip6_route_set_dest (route, &routes[i].network);
nm_ip6_route_set_prefix (route, routes[i].plen);
diff --git a/src/platform/nm-fake-platform.c b/src/platform/nm-fake-platform.c
index 390ccc6249..dd421c7a21 100644
--- a/src/platform/nm-fake-platform.c
+++ b/src/platform/nm-fake-platform.c
@@ -882,7 +882,7 @@ ip6_address_exists (NMPlatform *platform, int ifindex, struct in6_addr addr, int
/******************************************************************/
static GArray *
-ip4_route_get_all (NMPlatform *platform, int ifindex)
+ip4_route_get_all (NMPlatform *platform, int ifindex, gboolean include_default)
{
NMFakePlatformPrivate *priv = NM_FAKE_PLATFORM_GET_PRIVATE (platform);
GArray *routes;
@@ -901,15 +901,17 @@ ip4_route_get_all (NMPlatform *platform, int ifindex)
/* Fill routes */
for (i = 0; i < priv->ip4_routes->len; i++) {
route = &g_array_index (priv->ip4_routes, NMPlatformIP4Route, i);
- if (route && route->ifindex == ifindex)
- g_array_append_val (routes, *route);
+ if (route && route->ifindex == ifindex) {
+ if (route->plen != 0 || include_default)
+ g_array_append_val (routes, *route);
+ }
}
return routes;
}
static GArray *
-ip6_route_get_all (NMPlatform *platform, int ifindex)
+ip6_route_get_all (NMPlatform *platform, int ifindex, gboolean include_default)
{
NMFakePlatformPrivate *priv = NM_FAKE_PLATFORM_GET_PRIVATE (platform);
GArray *routes;
@@ -928,8 +930,10 @@ ip6_route_get_all (NMPlatform *platform, int ifindex)
/* Fill routes */
for (i = 0; i < priv->ip6_routes->len; i++) {
route = &g_array_index (priv->ip6_routes, NMPlatformIP6Route, i);
- if (route && route->ifindex == ifindex)
- g_array_append_val (routes, *route);
+ if (route && route->ifindex == ifindex) {
+ if (route->plen != 0 || include_default)
+ g_array_append_val (routes, *route);
+ }
}
return routes;
diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c
index e572ee9ece..022bd5002c 100644
--- a/src/platform/nm-linux-platform.c
+++ b/src/platform/nm-linux-platform.c
@@ -2155,7 +2155,7 @@ ip_route_mark_all (NMPlatform *platform, int family, int ifindex)
}
static GArray *
-ip4_route_get_all (NMPlatform *platform, int ifindex)
+ip4_route_get_all (NMPlatform *platform, int ifindex, gboolean include_default)
{
NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform);
GArray *routes;
@@ -2169,7 +2169,8 @@ ip4_route_get_all (NMPlatform *platform, int ifindex)
for (object = nl_cache_get_first (priv->route_cache); object; object = nl_cache_get_next (object)) {
if (nl_object_is_marked (object)) {
init_ip4_route (&route, (struct rtnl_route *) object);
- g_array_append_val (routes, route);
+ if (route.plen != 0 || include_default)
+ g_array_append_val (routes, route);
nl_object_unmark (object);
}
}
@@ -2178,7 +2179,7 @@ ip4_route_get_all (NMPlatform *platform, int ifindex)
}
static GArray *
-ip6_route_get_all (NMPlatform *platform, int ifindex)
+ip6_route_get_all (NMPlatform *platform, int ifindex, gboolean include_default)
{
NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform);
GArray *routes;
@@ -2192,7 +2193,8 @@ ip6_route_get_all (NMPlatform *platform, int ifindex)
for (object = nl_cache_get_first (priv->route_cache); object; object = nl_cache_get_next (object)) {
if (nl_object_is_marked (object)) {
init_ip6_route (&route, (struct rtnl_route *) object);
- g_array_append_val (routes, route);
+ if (route.plen != 0 || include_default)
+ g_array_append_val (routes, route);
nl_object_unmark (object);
}
}
diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c
index 7ac929e6cc..78feeb98bc 100644
--- a/src/platform/nm-platform.c
+++ b/src/platform/nm-platform.c
@@ -1326,25 +1326,25 @@ nm_platform_address_flush (int ifindex)
/******************************************************************/
GArray *
-nm_platform_ip4_route_get_all (int ifindex)
+nm_platform_ip4_route_get_all (int ifindex, gboolean include_default)
{
reset_error ();
g_return_val_if_fail (ifindex > 0, NULL);
g_return_val_if_fail (klass->ip4_route_get_all, NULL);
- return klass->ip4_route_get_all (platform, ifindex);
+ return klass->ip4_route_get_all (platform, ifindex, include_default);
}
GArray *
-nm_platform_ip6_route_get_all (int ifindex)
+nm_platform_ip6_route_get_all (int ifindex, gboolean include_default)
{
reset_error ();
g_return_val_if_fail (ifindex > 0, NULL);
g_return_val_if_fail (klass->ip6_route_get_all, NULL);
- return klass->ip6_route_get_all (platform, ifindex);
+ return klass->ip6_route_get_all (platform, ifindex, include_default);
}
gboolean
@@ -1485,15 +1485,11 @@ nm_platform_ip4_route_sync (int ifindex, const GArray *known_routes)
int i;
/* Delete unknown routes */
- routes = nm_platform_ip4_route_get_all (ifindex);
+ routes = nm_platform_ip4_route_get_all (ifindex, FALSE);
for (i = 0; i < routes->len; i++) {
route = &g_array_index (routes, NMPlatformIP4Route, i);
route->ifindex = 0;
- /* Ignore default route */
- if (!route->plen)
- continue;
-
if (!array_contains_ip4_route (known_routes, route))
nm_platform_ip4_route_delete (ifindex, route->network, route->plen, route->metric);
}
@@ -1535,15 +1531,11 @@ nm_platform_ip6_route_sync (int ifindex, const GArray *known_routes)
int i;
/* Delete unknown routes */
- routes = nm_platform_ip6_route_get_all (ifindex);
+ routes = nm_platform_ip6_route_get_all (ifindex, FALSE);
for (i = 0; i < routes->len; i++) {
route = &g_array_index (routes, NMPlatformIP6Route, i);
route->ifindex = 0;
- /* Ignore default route */
- if (!route->plen)
- continue;
-
if (!array_contains_ip6_route (known_routes, route))
nm_platform_ip6_route_delete (ifindex, route->network, route->plen, route->metric);
}
diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h
index 0aec812105..5ca2b22c61 100644
--- a/src/platform/nm-platform.h
+++ b/src/platform/nm-platform.h
@@ -282,8 +282,8 @@ typedef struct {
gboolean (*ip4_address_exists) (NMPlatform *, int ifindex, in_addr_t address, int plen);
gboolean (*ip6_address_exists) (NMPlatform *, int ifindex, struct in6_addr address, int plen);
- GArray * (*ip4_route_get_all) (NMPlatform *, int ifindex);
- GArray * (*ip6_route_get_all) (NMPlatform *, int ifindex);
+ GArray * (*ip4_route_get_all) (NMPlatform *, int ifindex, gboolean include_default);
+ GArray * (*ip6_route_get_all) (NMPlatform *, int ifindex, gboolean include_default);
gboolean (*ip4_route_add) (NMPlatform *, int ifindex,
in_addr_t network, int plen, in_addr_t gateway, int prio, int mss);
gboolean (*ip6_route_add) (NMPlatform *, int ifindex,
@@ -404,8 +404,8 @@ gboolean nm_platform_ip4_address_sync (int ifindex, const GArray *known_addresse
gboolean nm_platform_ip6_address_sync (int ifindex, const GArray *known_addresses);
gboolean nm_platform_address_flush (int ifindex);
-GArray *nm_platform_ip4_route_get_all (int ifindex);
-GArray *nm_platform_ip6_route_get_all (int ifindex);
+GArray *nm_platform_ip4_route_get_all (int ifindex, gboolean include_default);
+GArray *nm_platform_ip6_route_get_all (int ifindex, gboolean include_default);
gboolean nm_platform_route_set_metric (int ifindex, int metric);
gboolean nm_platform_ip4_route_add (int ifindex,
in_addr_t network, int plen, in_addr_t gateway, int metric, int mss);
diff --git a/src/platform/tests/dump.c b/src/platform/tests/dump.c
index 5a7f6ee8fb..038082afec 100644
--- a/src/platform/tests/dump.c
+++ b/src/platform/tests/dump.c
@@ -85,8 +85,8 @@ dump_interface (NMPlatformLink *link)
g_array_unref (ip4_addresses);
g_array_unref (ip6_addresses);
- ip4_routes = nm_platform_ip4_route_get_all (link->ifindex);
- ip6_routes = nm_platform_ip6_route_get_all (link->ifindex);
+ ip4_routes = nm_platform_ip4_route_get_all (link->ifindex, TRUE);
+ ip6_routes = nm_platform_ip6_route_get_all (link->ifindex, TRUE);
g_assert (ip4_routes);
g_assert (ip6_routes);
diff --git a/src/platform/tests/platform.c b/src/platform/tests/platform.c
index 8bb8ce35a5..cd274cdad7 100644
--- a/src/platform/tests/platform.c
+++ b/src/platform/tests/platform.c
@@ -578,7 +578,7 @@ do_ip4_route_get_all (char **argv)
int i;
if (ifindex) {
- routes = nm_platform_ip4_route_get_all (ifindex);
+ routes = nm_platform_ip4_route_get_all (ifindex, TRUE);
for (i = 0; i < routes->len; i++) {
route = &g_array_index (routes, NMPlatformIP4Route, i);
inet_ntop (AF_INET, &route->network, networkstr, sizeof (networkstr));
@@ -602,7 +602,7 @@ do_ip6_route_get_all (char **argv)
int i;
if (ifindex) {
- routes = nm_platform_ip6_route_get_all (ifindex);
+ routes = nm_platform_ip6_route_get_all (ifindex, TRUE);
for (i = 0; i < routes->len; i++) {
route = &g_array_index (routes, NMPlatformIP6Route, i);
inet_ntop (AF_INET6, &route->network, networkstr, sizeof (networkstr));
diff --git a/src/platform/tests/test-cleanup.c b/src/platform/tests/test-cleanup.c
index 095cef253b..cbfebe71c7 100644
--- a/src/platform/tests/test-cleanup.c
+++ b/src/platform/tests/test-cleanup.c
@@ -51,8 +51,8 @@ test_cleanup_internal ()
addresses4 = nm_platform_ip4_address_get_all (ifindex);
addresses6 = nm_platform_ip6_address_get_all (ifindex);
- routes4 = nm_platform_ip4_route_get_all (ifindex);
- routes6 = nm_platform_ip6_route_get_all (ifindex);
+ routes4 = nm_platform_ip4_route_get_all (ifindex, TRUE);
+ routes6 = nm_platform_ip6_route_get_all (ifindex, TRUE);
g_assert_cmpint (addresses4->len, ==, 1);
g_assert_cmpint (addresses6->len, ==, 1);
@@ -69,8 +69,8 @@ test_cleanup_internal ()
addresses4 = nm_platform_ip4_address_get_all (ifindex);
addresses6 = nm_platform_ip6_address_get_all (ifindex);
- routes4 = nm_platform_ip4_route_get_all (ifindex);
- routes6 = nm_platform_ip6_route_get_all (ifindex);
+ routes4 = nm_platform_ip4_route_get_all (ifindex, TRUE);
+ routes6 = nm_platform_ip6_route_get_all (ifindex, TRUE);
g_assert_cmpint (addresses4->len, ==, 0);
g_assert_cmpint (addresses6->len, ==, 0);
diff --git a/src/platform/tests/test-route.c b/src/platform/tests/test-route.c
index b042d992ac..6c764ad3c3 100644
--- a/src/platform/tests/test-route.c
+++ b/src/platform/tests/test-route.c
@@ -83,7 +83,7 @@ test_ip4_route ()
accept_signal (route_changed);
/* Test route listing */
- routes = nm_platform_ip4_route_get_all (ifindex);
+ routes = nm_platform_ip4_route_get_all (ifindex, TRUE);
memset (rts, 0, sizeof (rts));
rts[0].network = gateway;
rts[0].plen = 32;
@@ -166,7 +166,7 @@ test_ip6_route ()
accept_signal (route_changed);
/* Test route listing */
- routes = nm_platform_ip6_route_get_all (ifindex);
+ routes = nm_platform_ip6_route_get_all (ifindex, TRUE);
memset (rts, 0, sizeof (rts));
rts[0].network = gateway;
rts[0].plen = 128;