From 0c355ea5a0a59f688dcb2f07910a4a4be87ae843 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 7 Nov 2014 10:56:21 +0100 Subject: 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 --- src/platform/nm-fake-platform.c | 26 ++++++-------------------- src/platform/nm-platform.c | 4 ++-- 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); -- cgit v1.2.1