summaryrefslogtreecommitdiff
path: root/src/platform/tests/test-route.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/platform/tests/test-route.c')
-rw-r--r--src/platform/tests/test-route.c200
1 files changed, 139 insertions, 61 deletions
diff --git a/src/platform/tests/test-route.c b/src/platform/tests/test-route.c
index 360404e944..781d6d922b 100644
--- a/src/platform/tests/test-route.c
+++ b/src/platform/tests/test-route.c
@@ -76,56 +76,70 @@ test_ip4_route_metric0 (void)
SignalData *route_added = add_signal (NM_PLATFORM_SIGNAL_IP4_ROUTE_CHANGED, NM_PLATFORM_SIGNAL_ADDED, ip4_route_callback);
SignalData *route_changed = add_signal (NM_PLATFORM_SIGNAL_IP4_ROUTE_CHANGED, NM_PLATFORM_SIGNAL_CHANGED, ip4_route_callback);
SignalData *route_removed = add_signal (NM_PLATFORM_SIGNAL_IP4_ROUTE_CHANGED, NM_PLATFORM_SIGNAL_REMOVED, ip4_route_callback);
- in_addr_t network = nmtst_inet4_from_string ("192.0.2.5"); /* from 192.0.2.0/24 (TEST-NET-1) (rfc5737) */
+ const char *const NETWORK = "192.0.2.5"; /* from 192.0.2.0/24 (TEST-NET-1) (rfc5737) */
+ const guint32 network = nmtst_inet4_from_string (NETWORK);
int plen = 32;
int metric = 22987;
int mss = 1000;
+ NMPlatformIP4Route r = {
+ .ifindex = ifindex,
+ .network = network,
+ .plen = plen,
+ .rt_source = NM_IP_CONFIG_SOURCE_USER,
+ .metric = metric,
+ .mss = mss,
+ };
+ NMPlatformIP4Route r_metric0;
+
+ r_metric0 = r;
+ r_metric0.metric = 0;
/* No routes initially */
- nmtstp_assert_ip4_route_exists (NULL, FALSE, DEVICE_NAME, network, plen, 0);
- nmtstp_assert_ip4_route_exists (NULL, FALSE, DEVICE_NAME, network, plen, metric);
+ nmtstp_assert_ip4_route_exists (NULL, FALSE, DEVICE_NAME, network, plen, 0, NULL);
+ nmtstp_assert_ip4_route_exists (NULL, FALSE, DEVICE_NAME, network, plen, metric, NULL);
/* add the first route */
- g_assert (nm_platform_ip4_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, network, plen, INADDR_ANY, 0, metric, mss));
+
+ g_assert (nm_platform_ip4_route_add (NM_PLATFORM_GET, &r));
accept_signal (route_added);
- nmtstp_assert_ip4_route_exists (NULL, FALSE, DEVICE_NAME, network, plen, 0);
- nmtstp_assert_ip4_route_exists (NULL, TRUE, DEVICE_NAME, network, plen, metric);
+ nmtstp_assert_ip4_route_exists (NULL, FALSE, DEVICE_NAME, network, plen, 0, NULL);
+ nmtstp_assert_ip4_route_exists (NULL, TRUE, DEVICE_NAME, network, plen, metric, NULL);
/* Deleting route with metric 0 does nothing */
- g_assert (nm_platform_ip4_route_delete (NM_PLATFORM_GET, ifindex, network, plen, 0));
+ g_assert (nm_platform_ip4_route_delete (NM_PLATFORM_GET, &r_metric0));
ensure_no_signal (route_removed);
- nmtstp_assert_ip4_route_exists (NULL, FALSE, DEVICE_NAME, network, plen, 0);
- nmtstp_assert_ip4_route_exists (NULL, TRUE, DEVICE_NAME, network, plen, metric);
+ nmtstp_assert_ip4_route_exists (NULL, FALSE, DEVICE_NAME, network, plen, 0, NULL);
+ nmtstp_assert_ip4_route_exists (NULL, TRUE, DEVICE_NAME, network, plen, metric, NULL);
/* add the second route */
- g_assert (nm_platform_ip4_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, network, plen, INADDR_ANY, 0, 0, mss));
+ g_assert (nm_platform_ip4_route_add (NM_PLATFORM_GET, &r_metric0));
accept_signal (route_added);
- nmtstp_assert_ip4_route_exists (NULL, TRUE, DEVICE_NAME, network, plen, 0);
- nmtstp_assert_ip4_route_exists (NULL, TRUE, DEVICE_NAME, network, plen, metric);
+ nmtstp_assert_ip4_route_exists (NULL, TRUE, DEVICE_NAME, network, plen, 0, NULL);
+ nmtstp_assert_ip4_route_exists (NULL, TRUE, DEVICE_NAME, network, plen, metric, NULL);
/* Delete route with metric 0 */
- g_assert (nm_platform_ip4_route_delete (NM_PLATFORM_GET, ifindex, network, plen, 0));
+ g_assert (nm_platform_ip4_route_delete (NM_PLATFORM_GET, &r_metric0));
accept_signal (route_removed);
- nmtstp_assert_ip4_route_exists (NULL, FALSE, DEVICE_NAME, network, plen, 0);
- nmtstp_assert_ip4_route_exists (NULL, TRUE, DEVICE_NAME, network, plen, metric);
+ nmtstp_assert_ip4_route_exists (NULL, FALSE, DEVICE_NAME, network, plen, 0, NULL);
+ nmtstp_assert_ip4_route_exists (NULL, TRUE, DEVICE_NAME, network, plen, metric, NULL);
/* Delete route with metric 0 again (we expect nothing to happen) */
- g_assert (nm_platform_ip4_route_delete (NM_PLATFORM_GET, ifindex, network, plen, 0));
+ g_assert (nm_platform_ip4_route_delete (NM_PLATFORM_GET, &r_metric0));
ensure_no_signal (route_removed);
- nmtstp_assert_ip4_route_exists (NULL, FALSE, DEVICE_NAME, network, plen, 0);
- nmtstp_assert_ip4_route_exists (NULL, TRUE, DEVICE_NAME, network, plen, metric);
+ nmtstp_assert_ip4_route_exists (NULL, FALSE, DEVICE_NAME, network, plen, 0, NULL);
+ nmtstp_assert_ip4_route_exists (NULL, TRUE, DEVICE_NAME, network, plen, metric, NULL);
/* Delete the other route */
- g_assert (nm_platform_ip4_route_delete (NM_PLATFORM_GET, ifindex, network, plen, metric));
+ g_assert (nm_platform_ip4_route_delete (NM_PLATFORM_GET, &r));
accept_signal (route_removed);
- nmtstp_assert_ip4_route_exists (NULL, FALSE, DEVICE_NAME, network, plen, 0);
- nmtstp_assert_ip4_route_exists (NULL, FALSE, DEVICE_NAME, network, plen, metric);
+ nmtstp_assert_ip4_route_exists (NULL, FALSE, DEVICE_NAME, network, plen, 0, NULL);
+ nmtstp_assert_ip4_route_exists (NULL, FALSE, DEVICE_NAME, network, plen, metric, NULL);
free_signal (route_added);
free_signal (route_changed);
@@ -141,38 +155,61 @@ test_ip4_route (void)
SignalData *route_removed = add_signal (NM_PLATFORM_SIGNAL_IP4_ROUTE_CHANGED, NM_PLATFORM_SIGNAL_REMOVED, ip4_route_callback);
GArray *routes;
NMPlatformIP4Route rts[3];
- in_addr_t network;
guint8 plen = 24;
- in_addr_t gateway;
/* Choose a high metric so that we hopefully don't conflict. */
int metric = 22986;
int mss = 1000;
-
- inet_pton (AF_INET, "192.0.3.0", &network);
- inet_pton (AF_INET, "198.51.100.1", &gateway);
+ const char *const NETWORK = "192.0.3.0";
+ const char *const GATEWAY = "198.51.100.1";
+ const guint32 network = nmtst_inet4_from_string (NETWORK);
+ const guint32 gateway = nmtst_inet4_from_string (GATEWAY);
+ NMPlatformIP4Route r = {
+ .ifindex = ifindex,
+ .network = network,
+ .plen = plen,
+ .gateway = gateway,
+ .metric = metric,
+ .mss = mss,
+ .rt_source = NM_IP_CONFIG_SOURCE_USER,
+ };
+ NMPlatformIP4Route r_gateway = {
+ .ifindex = ifindex,
+ .network = gateway,
+ .plen = 32,
+ .metric = metric,
+ .mss = mss,
+ .rt_source = NM_IP_CONFIG_SOURCE_USER,
+ };
+ NMPlatformIP4Route r_default = {
+ .ifindex = ifindex,
+ .gateway = gateway,
+ .metric = metric,
+ .mss = mss,
+ .rt_source = NM_IP_CONFIG_SOURCE_USER,
+ };
/* Add route to gateway */
- g_assert (nm_platform_ip4_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, gateway, 32, INADDR_ANY, 0, metric, mss));
+ g_assert (nm_platform_ip4_route_add (NM_PLATFORM_GET, &r_gateway));
accept_signal (route_added);
/* Add route */
- nmtstp_assert_ip4_route_exists (NULL, FALSE, DEVICE_NAME, network, plen, metric);
- g_assert (nm_platform_ip4_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, network, plen, gateway, 0, metric, mss));
- nmtstp_assert_ip4_route_exists (NULL, TRUE, DEVICE_NAME, network, plen, metric);
+ nmtstp_assert_ip4_route_exists (NULL, FALSE, DEVICE_NAME, network, plen, metric, NULL);
+ g_assert (nm_platform_ip4_route_add (NM_PLATFORM_GET, &r));
+ nmtstp_assert_ip4_route_exists (NULL, TRUE, DEVICE_NAME, network, plen, metric, NULL);
accept_signal (route_added);
/* Add route again */
- g_assert (nm_platform_ip4_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, network, plen, gateway, 0, metric, mss));
+ g_assert (nm_platform_ip4_route_add (NM_PLATFORM_GET, &r));
accept_signals (route_changed, 0, 1);
/* Add default route */
- nmtstp_assert_ip4_route_exists (NULL, FALSE, DEVICE_NAME, 0, 0, metric);
- g_assert (nm_platform_ip4_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, 0, 0, gateway, 0, metric, mss));
- nmtstp_assert_ip4_route_exists (NULL, TRUE, DEVICE_NAME, 0, 0, metric);
+ nmtstp_assert_ip4_route_exists (NULL, FALSE, DEVICE_NAME, 0, 0, metric, NULL);
+ g_assert (nm_platform_ip4_route_add (NM_PLATFORM_GET, &r_default));
+ nmtstp_assert_ip4_route_exists (NULL, TRUE, DEVICE_NAME, 0, 0, metric, NULL);
accept_signal (route_added);
/* Add default route again */
- g_assert (nm_platform_ip4_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, 0, 0, gateway, 0, metric, mss));
+ g_assert (nm_platform_ip4_route_add (NM_PLATFORM_GET, &r_default));
accept_signals (route_changed, 0, 1);
/* Test route listing */
@@ -185,7 +222,8 @@ test_ip4_route (void)
rts[0].gateway = INADDR_ANY;
rts[0].metric = metric;
rts[0].mss = mss;
- rts[0].scope_inv = nm_platform_route_scope_inv (RT_SCOPE_LINK);
+ rts[0].rt_scope = RT_SCOPE_LINK;
+ rts[0].rt_scope_is_set = TRUE;
rts[1].rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER);
rts[1].network = network;
rts[1].plen = plen;
@@ -193,7 +231,8 @@ test_ip4_route (void)
rts[1].gateway = gateway;
rts[1].metric = metric;
rts[1].mss = mss;
- rts[1].scope_inv = nm_platform_route_scope_inv (RT_SCOPE_UNIVERSE);
+ rts[1].rt_scope = RT_SCOPE_UNIVERSE;
+ rts[1].rt_scope_is_set = TRUE;
rts[2].rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER);
rts[2].network = 0;
rts[2].plen = 0;
@@ -201,18 +240,19 @@ test_ip4_route (void)
rts[2].gateway = gateway;
rts[2].metric = metric;
rts[2].mss = mss;
- rts[2].scope_inv = nm_platform_route_scope_inv (RT_SCOPE_UNIVERSE);
+ rts[2].rt_scope = RT_SCOPE_UNIVERSE;
+ rts[2].rt_scope_is_set = TRUE;
g_assert_cmpint (routes->len, ==, 3);
nmtst_platform_ip4_routes_equal ((NMPlatformIP4Route *) routes->data, rts, routes->len, TRUE);
g_array_unref (routes);
/* Remove route */
- g_assert (nm_platform_ip4_route_delete (NM_PLATFORM_GET, ifindex, network, plen, metric));
- nmtstp_assert_ip4_route_exists (NULL, FALSE, DEVICE_NAME, network, plen, metric);
+ g_assert (nm_platform_ip4_route_delete (NM_PLATFORM_GET, &r));
+ nmtstp_assert_ip4_route_exists (NULL, FALSE, DEVICE_NAME, network, plen, metric, NULL);
accept_signal (route_removed);
/* Remove route again */
- g_assert (nm_platform_ip4_route_delete (NM_PLATFORM_GET, ifindex, network, plen, metric));
+ g_assert (nm_platform_ip4_route_delete (NM_PLATFORM_GET, &r));
free_signal (route_added);
free_signal (route_changed);
@@ -228,38 +268,60 @@ test_ip6_route (void)
SignalData *route_removed = add_signal (NM_PLATFORM_SIGNAL_IP6_ROUTE_CHANGED, NM_PLATFORM_SIGNAL_REMOVED, ip6_route_callback);
GArray *routes;
NMPlatformIP6Route rts[3];
- struct in6_addr network;
+ const char *const NETWORK = "2001:db8:a:b:0:0:0:0";
+ const char *const GATEWAY = "2001:db8:c:d:1:2:3:4";
+ const struct in6_addr network = *nmtst_inet6_from_string (NETWORK);
+ const struct in6_addr gateway = *nmtst_inet6_from_string (GATEWAY);
guint8 plen = 64;
- struct in6_addr gateway;
- /* Choose a high metric so that we hopefully don't conflict. */
int metric = 22987;
int mss = 1000;
-
- inet_pton (AF_INET6, "2001:db8:a:b:0:0:0:0", &network);
- inet_pton (AF_INET6, "2001:db8:c:d:1:2:3:4", &gateway);
+ NMPlatformIP6Route r = {
+ .ifindex = ifindex,
+ .network = network,
+ .plen = plen,
+ .gateway = gateway,
+ .metric = metric,
+ .mss = mss,
+ .rt_source = NM_IP_CONFIG_SOURCE_USER,
+ };
+ NMPlatformIP6Route r_gateway = {
+ .ifindex = ifindex,
+ .network = gateway,
+ .plen = 128,
+ .metric = metric,
+ .mss = mss,
+ .rt_source = NM_IP_CONFIG_SOURCE_USER,
+ };
+ NMPlatformIP6Route r_default = {
+ .ifindex = ifindex,
+ .gateway = gateway,
+ .metric = metric,
+ .mss = mss,
+ .rt_source = NM_IP_CONFIG_SOURCE_USER,
+ };
/* Add route to gateway */
- g_assert (nm_platform_ip6_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, gateway, 128, in6addr_any, metric, mss));
+ g_assert (nm_platform_ip6_route_add (NM_PLATFORM_GET, &r_gateway));
accept_signal (route_added);
/* Add route */
- g_assert (!nm_platform_ip6_route_get (NM_PLATFORM_GET, ifindex, network, plen, metric));
- g_assert (nm_platform_ip6_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, network, plen, gateway, metric, mss));
- g_assert (nm_platform_ip6_route_get (NM_PLATFORM_GET, ifindex, network, plen, metric));
+ g_assert (!nm_platform_ip6_route_get (NM_PLATFORM_GET, &r));
+ g_assert (nm_platform_ip6_route_add (NM_PLATFORM_GET, &r));
+ g_assert (nm_platform_ip6_route_get (NM_PLATFORM_GET, &r));
accept_signal (route_added);
/* Add route again */
- g_assert (nm_platform_ip6_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, network, plen, gateway, metric, mss));
+ g_assert (nm_platform_ip6_route_add (NM_PLATFORM_GET, &r));
accept_signals (route_changed, 0, 1);
/* Add default route */
- g_assert (!nm_platform_ip6_route_get (NM_PLATFORM_GET, ifindex, in6addr_any, 0, metric));
- g_assert (nm_platform_ip6_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, in6addr_any, 0, gateway, metric, mss));
- g_assert (nm_platform_ip6_route_get (NM_PLATFORM_GET, ifindex, in6addr_any, 0, metric));
+ g_assert (!nm_platform_ip6_route_get (NM_PLATFORM_GET, &r_default));
+ g_assert (nm_platform_ip6_route_add (NM_PLATFORM_GET, &r_default));
+ g_assert (nm_platform_ip6_route_get (NM_PLATFORM_GET, &r_default));
accept_signal (route_added);
/* Add default route again */
- g_assert (nm_platform_ip6_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, in6addr_any, 0, gateway, metric, mss));
+ g_assert (nm_platform_ip6_route_add (NM_PLATFORM_GET, &r_default));
accept_signals (route_changed, 0, 1);
/* Test route listing */
@@ -291,12 +353,12 @@ test_ip6_route (void)
g_array_unref (routes);
/* Remove route */
- g_assert (nm_platform_ip6_route_delete (NM_PLATFORM_GET, ifindex, network, plen, metric));
- g_assert (!nm_platform_ip6_route_get (NM_PLATFORM_GET, ifindex, network, plen, metric));
+ g_assert (nm_platform_ip6_route_delete (NM_PLATFORM_GET, &r));
+ g_assert (!nm_platform_ip6_route_get (NM_PLATFORM_GET, &r));
accept_signal (route_removed);
/* Remove route again */
- g_assert (nm_platform_ip6_route_delete (NM_PLATFORM_GET, ifindex, network, plen, metric));
+ g_assert (nm_platform_ip6_route_delete (NM_PLATFORM_GET, &r));
free_signal (route_added);
free_signal (route_changed);
@@ -309,14 +371,30 @@ static void
test_ip4_zero_gateway (void)
{
int ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, DEVICE_NAME);
+ NMPlatformIP4Route r_global = {
+ .ifindex = ifindex,
+ .network = nmtst_inet4_from_string ("1.2.3.1"),
+ .plen = 32,
+ .rt_source = NM_IP_CONFIG_SOURCE_RTPROT_BOOT,
+ .rt_scope = RT_SCOPE_UNIVERSE,
+ .rt_scope_is_set = TRUE,
+ };
+ NMPlatformIP4Route r_local = {
+ .ifindex = ifindex,
+ .network = nmtst_inet4_from_string ("1.2.3.2"),
+ .plen = 32,
+ .rt_source = NM_IP_CONFIG_SOURCE_RTPROT_BOOT,
+ .rt_scope = RT_SCOPE_LINK,
+ .rt_scope_is_set = TRUE,
+ };
nmtstp_run_command_check ("ip route add 1.2.3.1/32 via 0.0.0.0 dev %s", DEVICE_NAME);
nmtstp_run_command_check ("ip route add 1.2.3.2/32 dev %s", DEVICE_NAME);
NMTST_WAIT_ASSERT (100, {
nmtstp_wait_for_signal (NM_PLATFORM_GET, 10);
- if ( nm_platform_ip4_route_get (NM_PLATFORM_GET, ifindex, nmtst_inet4_from_string ("1.2.3.1"), 32, 0)
- && nm_platform_ip4_route_get (NM_PLATFORM_GET, ifindex, nmtst_inet4_from_string ("1.2.3.2"), 32, 0))
+ if ( nm_platform_ip4_route_get (NM_PLATFORM_GET, &r_global)
+ && nm_platform_ip4_route_get (NM_PLATFORM_GET, &r_local))
break;
});