diff options
| author | Michael Biebl <biebl@debian.org> | 2017-11-07 00:14:39 +0100 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2017-11-07 00:14:39 +0100 |
| commit | 90e8691111889a7b5f3c812f5a41f15a8a058913 (patch) | |
| tree | f101a879eca27c34a9bfa5f3da52266b22539a36 /src/tests/test-ip6-config.c | |
| parent | bdb6eeb0670658255c2a4c3c501c0a27fa8cfe55 (diff) | |
New upstream version 1.9.90 upstream/1.9.90
Diffstat (limited to 'src/tests/test-ip6-config.c')
| -rw-r--r-- | src/tests/test-ip6-config.c | 151 |
1 files changed, 111 insertions, 40 deletions
diff --git a/src/tests/test-ip6-config.c b/src/tests/test-ip6-config.c index 7e83625c..bcbeee3e 100644 --- a/src/tests/test-ip6-config.c +++ b/src/tests/test-ip6-config.c @@ -34,13 +34,13 @@ build_test_config (void) NMIP6Config *config; /* Build up the config to subtract */ - config = nm_ip6_config_new (1); + config = nmtst_ip6_config_new (1); nm_ip6_config_add_address (config, nmtst_platform_ip6_address ("abcd:1234:4321::cdde", "1:2:3:4::5", 64)); - nm_ip6_config_add_route (config, nmtst_platform_ip6_route ("abcd:1234:4321::", 24, "abcd:1234:4321:cdde::2", NULL)); - nm_ip6_config_add_route (config, nmtst_platform_ip6_route ("2001:abba::", 16, "2001:abba::2234", NULL)); + nm_ip6_config_add_route (config, nmtst_platform_ip6_route ("abcd:1200::", 24, "abcd:1234:4321:cdde::2", NULL), NULL); + nm_ip6_config_add_route (config, nmtst_platform_ip6_route ("2001::", 16, "2001:abba::2234", NULL), NULL); - nm_ip6_config_set_gateway (config, nmtst_inet6_from_string ("3001:abba::3234")); + nm_ip6_config_add_route (config, nmtst_platform_ip6_route ("::", 0, "3001:abba::3234", NULL), NULL); nm_ip6_config_add_nameserver (config, nmtst_inet6_from_string ("1:2:3:4::1")); nm_ip6_config_add_nameserver (config, nmtst_inet6_from_string ("1:2:3:4::2")); @@ -60,7 +60,7 @@ test_subtract (void) const NMPlatformIP6Route *test_route; const char *expected_addr = "1122:3344:5566::7788"; guint32 expected_addr_plen = 96; - const char *expected_route_dest = "9991:8882:7773::"; + const char *expected_route_dest = "9991:8800::"; guint32 expected_route_plen = 24; const char *expected_route_next_hop = "1119:2228:3337:4446::5555"; struct in6_addr expected_ns1; @@ -74,7 +74,7 @@ test_subtract (void) /* add a couple more things to the test config */ dst = build_test_config (); nm_ip6_config_add_address (dst, nmtst_platform_ip6_address (expected_addr, NULL, expected_addr_plen)); - nm_ip6_config_add_route (dst, nmtst_platform_ip6_route (expected_route_dest, expected_route_plen, expected_route_next_hop, NULL)); + nm_ip6_config_add_route (dst, nmtst_platform_ip6_route (expected_route_dest, expected_route_plen, expected_route_next_hop, NULL), NULL); expected_ns1 = *nmtst_inet6_from_string ("2222:3333:4444::5555"); nm_ip6_config_add_nameserver (dst, &expected_ns1); @@ -84,21 +84,21 @@ test_subtract (void) nm_ip6_config_add_domain (dst, expected_domain); nm_ip6_config_add_search (dst, expected_search); - nm_ip6_config_subtract (dst, src); + nm_ip6_config_subtract (dst, src, 0); /* ensure what's left is what we expect */ g_assert_cmpuint (nm_ip6_config_get_num_addresses (dst), ==, 1); - test_addr = nm_ip6_config_get_address (dst, 0); + test_addr = _nmtst_ip6_config_get_address (dst, 0); g_assert (test_addr != NULL); tmp = *nmtst_inet6_from_string (expected_addr); g_assert (memcmp (&test_addr->address, &tmp, sizeof (tmp)) == 0); g_assert (memcmp (&test_addr->peer_address, &in6addr_any, sizeof (tmp)) == 0); g_assert_cmpuint (test_addr->plen, ==, expected_addr_plen); - g_assert (nm_ip6_config_get_gateway (dst) == NULL); + g_assert (nm_ip6_config_best_default_route_get (dst) == NULL); g_assert_cmpuint (nm_ip6_config_get_num_routes (dst), ==, 1); - test_route = nm_ip6_config_get_route (dst, 0); + test_route = _nmtst_ip6_config_get_route (dst, 0); g_assert (test_route != NULL); tmp = *nmtst_inet6_from_string (expected_route_dest); @@ -127,8 +127,8 @@ test_compare_with_source (void) NMPlatformIP6Address addr; NMPlatformIP6Route route; - a = nm_ip6_config_new (1); - b = nm_ip6_config_new (2); + a = nmtst_ip6_config_new (1); + b = nmtst_ip6_config_new (2); /* Address */ addr = *nmtst_platform_ip6_address ("1122:3344:5566::7788", NULL, 64); @@ -139,12 +139,12 @@ test_compare_with_source (void) nm_ip6_config_add_address (b, &addr); /* Route */ - route = *nmtst_platform_ip6_route ("abcd:1234:4321::", 24, "abcd:1234:4321:cdde::2", NULL); + route = *nmtst_platform_ip6_route ("abcd:1200::", 24, "abcd:1234:4321:cdde::2", NULL); route.rt_source = NM_IP_CONFIG_SOURCE_USER; - nm_ip6_config_add_route (a, &route); + nm_ip6_config_add_route (a, &route, NULL); route.rt_source = NM_IP_CONFIG_SOURCE_VPN; - nm_ip6_config_add_route (b, &route); + nm_ip6_config_add_route (b, &route, NULL); /* Assert that the configs are basically the same, eg that the source is ignored */ g_assert (nm_ip6_config_equal (a, b)); @@ -160,34 +160,34 @@ test_add_address_with_source (void) NMPlatformIP6Address addr; const NMPlatformIP6Address *test_addr; - a = nm_ip6_config_new (1); + a = nmtst_ip6_config_new (1); /* Test that a higher priority source is not overwritten */ addr = *nmtst_platform_ip6_address ("1122:3344:5566::7788", NULL, 64); addr.addr_source = NM_IP_CONFIG_SOURCE_USER; nm_ip6_config_add_address (a, &addr); - test_addr = nm_ip6_config_get_address (a, 0); + test_addr = _nmtst_ip6_config_get_address (a, 0); g_assert_cmpint (test_addr->addr_source, ==, NM_IP_CONFIG_SOURCE_USER); addr.addr_source = NM_IP_CONFIG_SOURCE_VPN; nm_ip6_config_add_address (a, &addr); - test_addr = nm_ip6_config_get_address (a, 0); + test_addr = _nmtst_ip6_config_get_address (a, 0); g_assert_cmpint (test_addr->addr_source, ==, NM_IP_CONFIG_SOURCE_USER); /* Test that a lower priority address source is overwritten */ - nm_ip6_config_del_address (a, 0); + _nmtst_ip6_config_del_address (a, 0); addr.addr_source = NM_IP_CONFIG_SOURCE_KERNEL; nm_ip6_config_add_address (a, &addr); - test_addr = nm_ip6_config_get_address (a, 0); + test_addr = _nmtst_ip6_config_get_address (a, 0); g_assert_cmpint (test_addr->addr_source, ==, NM_IP_CONFIG_SOURCE_KERNEL); addr.addr_source = NM_IP_CONFIG_SOURCE_USER; nm_ip6_config_add_address (a, &addr); - test_addr = nm_ip6_config_get_address (a, 0); + test_addr = _nmtst_ip6_config_get_address (a, 0); g_assert_cmpint (test_addr->addr_source, ==, NM_IP_CONFIG_SOURCE_USER); g_object_unref (a); @@ -196,41 +196,45 @@ test_add_address_with_source (void) static void test_add_route_with_source (void) { - NMIP6Config *a; + gs_unref_object NMIP6Config *a = NULL; NMPlatformIP6Route route; const NMPlatformIP6Route *test_route; - a = nm_ip6_config_new (1); + a = nmtst_ip6_config_new (1); /* Test that a higher priority source is not overwritten */ - route = *nmtst_platform_ip6_route ("abcd:1234:4321::", 24, "abcd:1234:4321:cdde::2", NULL); + route = *nmtst_platform_ip6_route ("abcd:1200::", 24, "abcd:1234:4321:cdde::2", NULL); route.rt_source = NM_IP_CONFIG_SOURCE_USER; - nm_ip6_config_add_route (a, &route); + nm_ip6_config_add_route (a, &route, NULL); - test_route = nm_ip6_config_get_route (a, 0); + g_assert_cmpint (nm_ip6_config_get_num_routes (a), ==, 1); + test_route = _nmtst_ip6_config_get_route (a, 0); g_assert_cmpint (test_route->rt_source, ==, NM_IP_CONFIG_SOURCE_USER); route.rt_source = NM_IP_CONFIG_SOURCE_VPN; - nm_ip6_config_add_route (a, &route); + nm_ip6_config_add_route (a, &route, NULL); - test_route = nm_ip6_config_get_route (a, 0); + g_assert_cmpint (nm_ip6_config_get_num_routes (a), ==, 1); + test_route = _nmtst_ip6_config_get_route (a, 0); g_assert_cmpint (test_route->rt_source, ==, NM_IP_CONFIG_SOURCE_USER); + _nmtst_ip6_config_del_route (a, 0); + g_assert_cmpint (nm_ip6_config_get_num_routes (a), ==, 0); + /* Test that a lower priority address source is overwritten */ - nm_ip6_config_del_route (a, 0); route.rt_source = NM_IP_CONFIG_SOURCE_KERNEL; - nm_ip6_config_add_route (a, &route); + nm_ip6_config_add_route (a, &route, NULL); - test_route = nm_ip6_config_get_route (a, 0); + g_assert_cmpint (nm_ip6_config_get_num_routes (a), ==, 1); + test_route = _nmtst_ip6_config_get_route (a, 0); g_assert_cmpint (test_route->rt_source, ==, NM_IP_CONFIG_SOURCE_KERNEL); route.rt_source = NM_IP_CONFIG_SOURCE_USER; - nm_ip6_config_add_route (a, &route); + nm_ip6_config_add_route (a, &route, NULL); - test_route = nm_ip6_config_get_route (a, 0); + g_assert_cmpint (nm_ip6_config_get_num_routes (a), ==, 1); + test_route = _nmtst_ip6_config_get_route (a, 0); g_assert_cmpint (test_route->rt_source, ==, NM_IP_CONFIG_SOURCE_USER); - - g_object_unref (a); } static void @@ -256,18 +260,18 @@ test_nm_ip6_config_addresses_sort_check (NMIP6Config *config, NMSettingIP6Config int j = g_rand_int_range (nmtst_get_rand (), i, addr_count); NMTST_SWAP (idx[i], idx[j]); - nm_ip6_config_add_address (copy, nm_ip6_config_get_address (config, idx[i])); + nm_ip6_config_add_address (copy, _nmtst_ip6_config_get_address (config, idx[i])); } /* reorder them again */ - nm_ip6_config_addresses_sort (copy); + _nmtst_ip6_config_addresses_sort (copy); /* check equality using nm_ip6_config_equal() */ if (!nm_ip6_config_equal (copy, config)) { g_message ("%s", "SORTING yields unexpected output:"); for (i = 0; i < addr_count; i++) { - g_message (" >> [%d] = %s", i, nm_platform_ip6_address_to_string (nm_ip6_config_get_address (config, i), NULL, 0)); - g_message (" << [%d] = %s", i, nm_platform_ip6_address_to_string (nm_ip6_config_get_address (copy, i), NULL, 0)); + g_message (" >> [%d] = %s", i, nm_platform_ip6_address_to_string (_nmtst_ip6_config_get_address (config, i), NULL, 0)); + g_message (" << [%d] = %s", i, nm_platform_ip6_address_to_string (_nmtst_ip6_config_get_address (copy, i), NULL, 0)); } g_assert_not_reached (); } @@ -327,7 +331,7 @@ test_strip_search_trailing_dot (void) { NMIP6Config *config; - config = nm_ip6_config_new (1); + config = nmtst_ip6_config_new (1); nm_ip6_config_add_search (config, "."); nm_ip6_config_add_search (config, "foo"); @@ -345,6 +349,71 @@ test_strip_search_trailing_dot (void) /*****************************************************************************/ +static void +test_replace (gconstpointer user_data) +{ + nm_auto_unref_dedup_multi_index NMDedupMultiIndex *multi_idx = nm_dedup_multi_index_new (); + const int TEST_IDX = GPOINTER_TO_INT (user_data); + const int IFINDEX = 1; + gs_unref_object NMIP6Config *src_conf = NULL; + gs_unref_object NMIP6Config *dst_conf = NULL; + NMPlatformIP6Address *addr; + NMPlatformIP6Address addrs[5] = { }; + guint addrs_n = 0; + guint i; + + dst_conf = nm_ip6_config_new (multi_idx, IFINDEX); + src_conf = nm_ip6_config_new (multi_idx, IFINDEX); + + switch (TEST_IDX) { + case 1: + addr = &addrs[addrs_n++]; + addr->ifindex = IFINDEX; + addr->address = *nmtst_inet6_from_string ("fe80::78ec:7a6d:602d:20f2"); + addr->plen = 64; + addr->n_ifa_flags = IFA_F_PERMANENT; + addr->addr_source = NM_IP_CONFIG_SOURCE_KERNEL; + break; + case 2: + addr = &addrs[addrs_n++]; + addr->ifindex = IFINDEX; + addr->address = *nmtst_inet6_from_string ("fe80::78ec:7a6d:602d:20f2"); + addr->plen = 64; + addr->n_ifa_flags = IFA_F_PERMANENT; + addr->addr_source = NM_IP_CONFIG_SOURCE_KERNEL; + + addr = &addrs[addrs_n++]; + addr->ifindex = IFINDEX; + addr->address = *nmtst_inet6_from_string ("1::1"); + addr->plen = 64; + addr->addr_source = NM_IP_CONFIG_SOURCE_USER; + + nm_ip6_config_add_address (dst_conf, addr); + break; + default: + g_assert_not_reached (); + } + + g_assert (addrs_n < G_N_ELEMENTS (addrs)); + + for (i = 0; i < addrs_n; i++) + nm_ip6_config_add_address (src_conf, &addrs[i]); + + nm_ip6_config_replace (dst_conf, src_conf, NULL); + + for (i = 0; i < addrs_n; i++) { + const NMPlatformIP6Address *a = _nmtst_ip6_config_get_address (dst_conf, i); + const NMPlatformIP6Address *b = _nmtst_ip6_config_get_address (src_conf, i); + + g_assert (nm_platform_ip6_address_cmp (&addrs[i], a) == 0); + g_assert (nm_platform_ip6_address_cmp (&addrs[i], b) == 0); + } + g_assert (addrs_n == nm_ip6_config_get_num_addresses (dst_conf)); + g_assert (addrs_n == nm_ip6_config_get_num_addresses (src_conf)); +} + +/*****************************************************************************/ + NMTST_DEFINE(); int @@ -358,6 +427,8 @@ main (int argc, char **argv) g_test_add_func ("/ip6-config/add-route-with-source", test_add_route_with_source); g_test_add_func ("/ip6-config/test_nm_ip6_config_addresses_sort", test_nm_ip6_config_addresses_sort); g_test_add_func ("/ip6-config/strip-search-trailing-dot", test_strip_search_trailing_dot); + g_test_add_data_func ("/ip6-config/replace/1", GINT_TO_POINTER (1), test_replace); + g_test_add_data_func ("/ip6-config/replace/2", GINT_TO_POINTER (2), test_replace); return g_test_run (); } |