summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2014-11-07 10:56:21 +0100
committerThomas Haller <thaller@redhat.com>2014-11-07 15:23:11 +0100
commit0c355ea5a0a59f688dcb2f07910a4a4be87ae843 (patch)
treea2333f2ac5fd8e95d59bc41d40244fbcfb4b8f57
parent3ef807c6ae48cac04df7195c0a03dd8c5de13fc5 (diff)
downloadNetworkManager-0c355ea5a0a59f688dcb2f07910a4a4be87ae843.tar.gz
platform: support route_get_all() to return route for every ifindex
By passing an ifindex of 0, the search is not limited to a certain ifindex. Signed-off-by: Thomas Haller <thaller@redhat.com>
-rw-r--r--src/platform/nm-fake-platform.c26
-rw-r--r--src/platform/nm-platform.c4
2 files changed, 8 insertions, 22 deletions
diff --git a/src/platform/nm-fake-platform.c b/src/platform/nm-fake-platform.c
index f397f5b731..17304544be 100644
--- a/src/platform/nm-fake-platform.c
+++ b/src/platform/nm-fake-platform.c
@@ -988,23 +988,16 @@ ip4_route_get_all (NMPlatform *platform, int ifindex, NMPlatformGetRouteMode mod
NMFakePlatformPrivate *priv = NM_FAKE_PLATFORM_GET_PRIVATE (platform);
GArray *routes;
NMPlatformIP4Route *route;
- int count = 0, i;
+ guint i;
g_return_val_if_fail (NM_IN_SET (mode, NM_PLATFORM_GET_ROUTE_MODE_ALL, NM_PLATFORM_GET_ROUTE_MODE_NO_DEFAULT, NM_PLATFORM_GET_ROUTE_MODE_ONLY_DEFAULT), NULL);
- /* Count routes */
- for (i = 0; i < priv->ip4_routes->len; i++) {
- route = &g_array_index (priv->ip4_routes, NMPlatformIP4Route, i);
- if (route && route->ifindex == ifindex)
- count++;
- }
-
- routes = g_array_sized_new (TRUE, TRUE, sizeof (NMPlatformIP4Route), count);
+ routes = g_array_new (TRUE, TRUE, sizeof (NMPlatformIP4Route));
/* 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) {
+ if (route && (!ifindex || route->ifindex == ifindex)) {
if (NM_PLATFORM_IP_ROUTE_IS_DEFAULT (route)) {
if (mode != NM_PLATFORM_GET_ROUTE_MODE_NO_DEFAULT)
g_array_append_val (routes, *route);
@@ -1024,23 +1017,16 @@ ip6_route_get_all (NMPlatform *platform, int ifindex, NMPlatformGetRouteMode mod
NMFakePlatformPrivate *priv = NM_FAKE_PLATFORM_GET_PRIVATE (platform);
GArray *routes;
NMPlatformIP6Route *route;
- int count = 0, i;
+ guint i;
g_return_val_if_fail (NM_IN_SET (mode, NM_PLATFORM_GET_ROUTE_MODE_ALL, NM_PLATFORM_GET_ROUTE_MODE_NO_DEFAULT, NM_PLATFORM_GET_ROUTE_MODE_ONLY_DEFAULT), NULL);
- /* Count routes */
- for (i = 0; i < priv->ip6_routes->len; i++) {
- route = &g_array_index (priv->ip6_routes, NMPlatformIP6Route, i);
- if (route && route->ifindex == ifindex)
- count++;
- }
-
- routes = g_array_sized_new (TRUE, TRUE, sizeof (NMPlatformIP6Route), count);
+ routes = g_array_new (TRUE, TRUE, sizeof (NMPlatformIP6Route));
/* 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) {
+ if (route && (!ifindex || route->ifindex == ifindex)) {
if (NM_PLATFORM_IP_ROUTE_IS_DEFAULT (route)) {
if (mode != NM_PLATFORM_GET_ROUTE_MODE_NO_DEFAULT)
g_array_append_val (routes, *route);
diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c
index 70395ca3cf..07e9979692 100644
--- a/src/platform/nm-platform.c
+++ b/src/platform/nm-platform.c
@@ -1841,7 +1841,7 @@ nm_platform_ip4_route_get_all (int ifindex, NMPlatformGetRouteMode mode)
{
reset_error ();
- g_return_val_if_fail (ifindex > 0, NULL);
+ 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, mode);
@@ -1852,7 +1852,7 @@ nm_platform_ip6_route_get_all (int ifindex, NMPlatformGetRouteMode mode)
{
reset_error ();
- g_return_val_if_fail (ifindex > 0, NULL);
+ 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, mode);