diff options
author | Thomas Haller <thaller@redhat.com> | 2017-07-04 10:40:52 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2017-07-05 18:37:39 +0200 |
commit | 35f52aafc1331ee51ca16dec9a10bf8dbc62d136 (patch) | |
tree | 9a1b15828957b60a1638ae3646864ef1dd74c578 | |
parent | aeaa1b3b98d0728d9b220a8d16eaa017a2bfa8b4 (diff) | |
download | NetworkManager-35f52aafc1331ee51ca16dec9a10bf8dbc62d136.tar.gz |
platform: drop nm_platform_ip6_route_get_all()
We no longer need a full clone of routes. The only remaining uses
are in test code. Rework it.
-rw-r--r-- | src/platform/nm-platform.c | 50 | ||||
-rw-r--r-- | src/platform/nm-platform.h | 13 | ||||
-rw-r--r-- | src/platform/tests/test-route.c | 10 | ||||
-rw-r--r-- | src/tests/test-route-manager.c | 49 |
4 files changed, 23 insertions, 99 deletions
diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index de5ac3cf40..912f498437 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -3198,56 +3198,6 @@ nm_platform_address_flush (NMPlatform *self, int ifindex) /*****************************************************************************/ -static GArray * -ipx_route_get_all (NMPlatform *platform, int ifindex, NMPObjectType obj_type, NMPlatformGetRouteFlags flags) -{ - NMDedupMultiIter iter; - NMPLookup lookup; - const NMDedupMultiHeadEntry *head_entry; - GArray *array; - const NMPClass *klass; - const NMPObject *o; - gboolean with_rtprot_kernel; - - nm_assert (NM_IN_SET (obj_type, NMP_OBJECT_TYPE_IP4_ROUTE, NMP_OBJECT_TYPE_IP6_ROUTE)); - - if (!NM_FLAGS_ANY (flags, NM_PLATFORM_GET_ROUTE_FLAGS_WITH_DEFAULT | NM_PLATFORM_GET_ROUTE_FLAGS_WITH_NON_DEFAULT)) - flags |= NM_PLATFORM_GET_ROUTE_FLAGS_WITH_DEFAULT | NM_PLATFORM_GET_ROUTE_FLAGS_WITH_NON_DEFAULT; - - klass = nmp_class_from_type (obj_type); - - head_entry = nmp_cache_lookup (nm_platform_get_cache (platform), - nmp_lookup_init_route_visible (&lookup, - obj_type, - ifindex, - NM_FLAGS_HAS (flags, NM_PLATFORM_GET_ROUTE_FLAGS_WITH_DEFAULT), - NM_FLAGS_HAS (flags, NM_PLATFORM_GET_ROUTE_FLAGS_WITH_NON_DEFAULT))); - - array = g_array_sized_new (FALSE, FALSE, klass->sizeof_public, head_entry ? head_entry->len : 0); - - with_rtprot_kernel = NM_FLAGS_HAS (flags, NM_PLATFORM_GET_ROUTE_FLAGS_WITH_RTPROT_KERNEL); - - nmp_cache_iter_for_each (&iter, - head_entry, - &o) { - nm_assert (NMP_OBJECT_GET_CLASS (o) == klass); - if ( with_rtprot_kernel - || o->ip_route.rt_source != NM_IP_CONFIG_SOURCE_RTPROT_KERNEL) - g_array_append_vals (array, &o->ip_route, 1); - } - return array; -} - -GArray * -nm_platform_ip6_route_get_all (NMPlatform *self, int ifindex, NMPlatformGetRouteFlags flags) -{ - _CHECK_SELF (self, klass, NULL); - - g_return_val_if_fail (ifindex >= 0, NULL); - - return ipx_route_get_all (self, ifindex, NMP_OBJECT_TYPE_IP6_ROUTE, flags); -} - /** * nm_platform_ip4_route_add: * @self: diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index f4c499787e..4074fb8a49 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -173,18 +173,6 @@ typedef enum { NM_PLATFORM_SIGNAL_REMOVED, } NMPlatformSignalChangeType; -typedef enum { /*< skip >*/ - NM_PLATFORM_GET_ROUTE_FLAGS_NONE = 0, - - /* Whether to include default-routes/non-default-routes. Omitting - * both WITH_DEFAULT and WITH_NON_DEFAULT, is equal to specifying - * both of them. */ - NM_PLATFORM_GET_ROUTE_FLAGS_WITH_DEFAULT = (1LL << 0), - NM_PLATFORM_GET_ROUTE_FLAGS_WITH_NON_DEFAULT = (1LL << 1), - - NM_PLATFORM_GET_ROUTE_FLAGS_WITH_RTPROT_KERNEL = (1LL << 2), -} NMPlatformGetRouteFlags; - typedef struct { __NMPlatformObject_COMMON; } NMPlatformObject; @@ -980,7 +968,6 @@ gboolean nm_platform_address_flush (NMPlatform *self, int ifindex); const NMPlatformIP4Route *nm_platform_ip4_route_get (NMPlatform *self, int ifindex, in_addr_t network, guint8 plen, guint32 metric); const NMPlatformIP6Route *nm_platform_ip6_route_get (NMPlatform *self, int ifindex, struct in6_addr network, guint8 plen, guint32 metric); -GArray *nm_platform_ip6_route_get_all (NMPlatform *self, int ifindex, NMPlatformGetRouteFlags flags); gboolean nm_platform_ip4_route_add (NMPlatform *self, const NMPlatformIP4Route *route); gboolean nm_platform_ip6_route_add (NMPlatform *self, const NMPlatformIP6Route *route); gboolean nm_platform_ip4_route_delete (NMPlatform *self, int ifindex, in_addr_t network, guint8 plen, guint32 metric); diff --git a/src/platform/tests/test-route.c b/src/platform/tests/test-route.c index f4ac2a6e6c..3fe0f3128a 100644 --- a/src/platform/tests/test-route.c +++ b/src/platform/tests/test-route.c @@ -450,7 +450,7 @@ test_ip6_route_options (gconstpointer test_data) { const int TEST_IDX = GPOINTER_TO_INT (test_data); const int IFINDEX = nm_platform_link_get_ifindex (NM_PLATFORM_GET, DEVICE_NAME); - gs_unref_array GArray *routes = NULL; + GPtrArray *routes; #define RTS_MAX 1 NMPlatformIP6Route rts_add[RTS_MAX] = { }; NMPlatformIP6Route rts_cmp[RTS_MAX] = { }; @@ -519,9 +519,7 @@ test_ip6_route_options (gconstpointer test_data) for (i = 0; i < rts_n; i++) g_assert (nm_platform_ip6_route_add (NM_PLATFORM_GET, &rts_add[i])); - routes = nm_platform_ip6_route_get_all (NM_PLATFORM_GET, IFINDEX, - NM_PLATFORM_GET_ROUTE_FLAGS_WITH_DEFAULT | - NM_PLATFORM_GET_ROUTE_FLAGS_WITH_NON_DEFAULT); + routes = nmtstp_ip6_route_get_all (NM_PLATFORM_GET, IFINDEX); switch (TEST_IDX) { case 1: case 2: @@ -533,9 +531,9 @@ test_ip6_route_options (gconstpointer test_data) default: g_assert_not_reached (); } - g_assert_cmpint (routes->len, ==, rts_n); - nmtst_platform_ip6_routes_equal ((const NMPlatformIP6Route *) routes->data, rts_cmp, rts_n, TRUE); + nmtst_platform_ip6_routes_equal_aptr ((const NMPObject *const*) routes->pdata, rts_cmp, routes->len, TRUE); + g_ptr_array_unref (routes); for (i = 0; i < rts_n; i++) { g_assert (nm_platform_ip6_route_delete (NM_PLATFORM_GET, IFINDEX, diff --git a/src/tests/test-route-manager.c b/src/tests/test-route-manager.c index f647cc7494..275d898641 100644 --- a/src/tests/test-route-manager.c +++ b/src/tests/test-route-manager.c @@ -143,15 +143,20 @@ update_dev0_ip4 (int ifindex) static GArray * -ip4_routes (test_fixture *fixture) +ip_routes (test_fixture *fixture, NMPObjectType obj_type) { + const NMPClass *klass; GArray *routes; const NMDedupMultiHeadEntry *pl_head_entry; NMDedupMultiIter iter; const NMPObject *plobj = NULL; guint i; - routes = g_array_new (FALSE, FALSE, sizeof (NMPlatformIP4Route)); + g_assert (NM_IN_SET (obj_type, NMP_OBJECT_TYPE_IP4_ROUTE, NMP_OBJECT_TYPE_IP6_ROUTE)); + + klass = nmp_class_from_type (obj_type); + + routes = g_array_new (FALSE, FALSE, klass->sizeof_public); for (i = 0; i < 2; i++) { int ifindex; @@ -162,12 +167,12 @@ ip4_routes (test_fixture *fixture) ifindex = fixture->ifindex1; pl_head_entry = nm_platform_lookup_route_visible (NM_PLATFORM_GET, - NMP_OBJECT_TYPE_IP4_ROUTE, + obj_type, ifindex, FALSE, TRUE); nmp_cache_iter_for_each (&iter, pl_head_entry, &plobj) { - const NMPlatformIP4Route *r = NMP_OBJECT_CAST_IP4_ROUTE (plobj); + const NMPlatformIPRoute *r = NMP_OBJECT_CAST_IP_ROUTE (plobj); if (r->rt_source == NM_IP_CONFIG_SOURCE_RTPROT_KERNEL) continue; @@ -346,7 +351,7 @@ test_ip4 (test_fixture *fixture, gconstpointer user_data) * - 7.0.0.0/8 route, metric 21021 added * - 7.0.0.0/8 route, metric 22 added * - 8.0.0.0/8 could be added. */ - routes = ip4_routes (fixture); + routes = ip_routes (fixture, NMP_OBJECT_TYPE_IP4_ROUTE); g_assert_cmpint (routes->len, ==, G_N_ELEMENTS (state1)); nmtst_platform_ip4_routes_equal ((NMPlatformIP4Route *) routes->data, state1, routes->len, TRUE); g_array_free (routes, TRUE); @@ -357,7 +362,7 @@ test_ip4 (test_fixture *fixture, gconstpointer user_data) setup_dev0_ip4 (fixture->ifindex0, 0, 21); /* Ensure nothing changed. */ - routes = ip4_routes (fixture); + routes = ip_routes (fixture, NMP_OBJECT_TYPE_IP4_ROUTE); g_assert_cmpint (routes->len, ==, G_N_ELEMENTS (state1)); state1[0].mss = 0; state1[1].metric = 21; @@ -367,7 +372,7 @@ test_ip4 (test_fixture *fixture, gconstpointer user_data) update_dev0_ip4 (fixture->ifindex0); /* minor changes in the routes. Quite similar to state1. */ - routes = ip4_routes (fixture); + routes = ip_routes (fixture, NMP_OBJECT_TYPE_IP4_ROUTE); g_assert_cmpint (routes->len, ==, G_N_ELEMENTS (state2)); nmtst_platform_ip4_routes_equal ((NMPlatformIP4Route *) routes->data, state2, routes->len, TRUE); g_array_free (routes, TRUE); @@ -379,7 +384,7 @@ test_ip4 (test_fixture *fixture, gconstpointer user_data) * 7.0.0.0/8 gone from dev0, still present on dev1 * 8.0.0.0/8 is present on dev1 * No dev0 routes left. */ - routes = ip4_routes (fixture); + routes = ip_routes (fixture, NMP_OBJECT_TYPE_IP4_ROUTE); g_assert_cmpint (routes->len, ==, G_N_ELEMENTS (state3)); nmtst_platform_ip4_routes_equal ((NMPlatformIP4Route *) routes->data, state3, routes->len, TRUE); g_array_free (routes, TRUE); @@ -387,7 +392,7 @@ test_ip4 (test_fixture *fixture, gconstpointer user_data) nm_route_manager_route_flush (route_manager_get (), fixture->ifindex1); /* No routes left. */ - routes = ip4_routes (fixture); + routes = ip_routes (fixture, NMP_OBJECT_TYPE_IP4_ROUTE); g_assert_cmpint (routes->len, ==, 0); g_array_free (routes, TRUE); } @@ -544,22 +549,6 @@ update_dev0_ip6 (int ifindex) g_array_free (routes, TRUE); } -static GArray * -ip6_routes (test_fixture *fixture) -{ - GArray *routes = nm_platform_ip6_route_get_all (NM_PLATFORM_GET, - fixture->ifindex0, - NM_PLATFORM_GET_ROUTE_FLAGS_WITH_NON_DEFAULT); - GArray *routes1 = nm_platform_ip6_route_get_all (NM_PLATFORM_GET, - fixture->ifindex1, - NM_PLATFORM_GET_ROUTE_FLAGS_WITH_NON_DEFAULT); - - g_array_append_vals (routes, routes1->data, routes1->len); - g_array_free (routes1, TRUE); - - return routes; -} - static void test_ip6 (test_fixture *fixture, gconstpointer user_data) { @@ -762,7 +751,7 @@ test_ip6 (test_fixture *fixture, gconstpointer user_data) * 2001:db8:d34d::/64 on dev1 could not be added * 2001:db8:1337::/48 on dev0 won over 2001:db8:1337::/48 on dev1 and has metric 1024 * 2001:db8:abad:c0de::/64 routes did not clash */ - routes = ip6_routes (fixture); + routes = ip_routes (fixture, NMP_OBJECT_TYPE_IP6_ROUTE); g_assert_cmpint (routes->len, ==, G_N_ELEMENTS (state1)); nmtst_platform_ip6_routes_equal ((NMPlatformIP6Route *) routes->data, state1, routes->len, TRUE); g_array_free (routes, TRUE); @@ -773,7 +762,7 @@ test_ip6 (test_fixture *fixture, gconstpointer user_data) setup_dev0_ip6 (fixture->ifindex0); /* Ensure nothing changed. */ - routes = ip6_routes (fixture); + routes = ip_routes (fixture, NMP_OBJECT_TYPE_IP6_ROUTE); g_assert_cmpint (routes->len, ==, G_N_ELEMENTS (state1)); nmtst_platform_ip6_routes_equal ((NMPlatformIP6Route *) routes->data, state1, routes->len, TRUE); g_array_free (routes, TRUE); @@ -781,7 +770,7 @@ test_ip6 (test_fixture *fixture, gconstpointer user_data) update_dev0_ip6 (fixture->ifindex0); /* 2001:db8:abad:c0de::/64 on dev0 was updated for gateway removal*/ - routes = ip6_routes (fixture); + routes = ip_routes (fixture, NMP_OBJECT_TYPE_IP6_ROUTE); g_assert_cmpint (routes->len, ==, G_N_ELEMENTS (state2)); nmtst_platform_ip6_routes_equal ((NMPlatformIP6Route *) routes->data, state2, routes->len, TRUE); g_array_free (routes, TRUE); @@ -793,7 +782,7 @@ test_ip6 (test_fixture *fixture, gconstpointer user_data) * 2001:db8:1337::/48 is now on dev1, metric of 1024 still applies * 2001:db8:d34d::/64 is present now that 2001:db8:8086::/48 is on dev1 * No dev0 routes left. */ - routes = ip6_routes (fixture); + routes = ip_routes (fixture, NMP_OBJECT_TYPE_IP6_ROUTE); g_assert_cmpint (routes->len, ==, G_N_ELEMENTS (state3)); nmtst_platform_ip6_routes_equal ((NMPlatformIP6Route *) routes->data, state3, routes->len, TRUE); g_array_free (routes, TRUE); @@ -801,7 +790,7 @@ test_ip6 (test_fixture *fixture, gconstpointer user_data) nm_route_manager_route_flush (route_manager_get (), fixture->ifindex1); /* No routes left. */ - routes = ip6_routes (fixture); + routes = ip_routes (fixture, NMP_OBJECT_TYPE_IP6_ROUTE); g_assert_cmpint (routes->len, ==, 0); g_array_free (routes, TRUE); } |