diff options
| author | Michael Biebl <biebl@debian.org> | 2020-04-11 21:28:04 +0200 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2020-04-11 21:28:04 +0200 |
| commit | 1e5977b62f896e844b548c3007ace9e1dfa7f9ed (patch) | |
| tree | 7a7416ed410e72b6200f3d860fd315ec11cc106b /src/platform/tests/test-common.c | |
| parent | b012fa6e1d808e0736c009799c62d835cbfcc1dd (diff) | |
New upstream version 1.23.90 upstream/1.23.90
Diffstat (limited to 'src/platform/tests/test-common.c')
| -rw-r--r-- | src/platform/tests/test-common.c | 124 |
1 files changed, 82 insertions, 42 deletions
diff --git a/src/platform/tests/test-common.c b/src/platform/tests/test-common.c index f831fe94..f393ae93 100644 --- a/src/platform/tests/test-common.c +++ b/src/platform/tests/test-common.c @@ -190,7 +190,7 @@ _accept_or_wait_signal (const char *file, int line, const char *func, SignalData if (data->received_count == 0) { data->loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (data->loop); - g_clear_pointer (&data->loop, g_main_loop_unref); + nm_clear_pointer (&data->loop, g_main_loop_unref); } _accept_signal (file, line, func, data); @@ -205,7 +205,7 @@ _wait_signal (const char *file, int line, const char *func, SignalData *data) data->loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (data->loop); - g_clear_pointer (&data->loop, g_main_loop_unref); + nm_clear_pointer (&data->loop, g_main_loop_unref); _accept_signal (file, line, func, data); } @@ -356,7 +356,7 @@ _nmtstp_assert_ip4_route_exists (const char *file, g_error ("[%s:%u] %s(): The ip4 route %s/%d metric %u tos %u shall exist %u times, but platform has it %u times", file, line, func, - nm_utils_inet4_ntop (network, sbuf), + _nm_utils_inet4_ntop (network, sbuf), plen, metric, tos, @@ -467,10 +467,10 @@ _nmtstp_assert_ip6_route_exists (const char *file, g_error ("[%s:%u] %s(): The ip6 route %s/%d metric %u src %s/%d shall exist %u times, but platform has it %u times", file, line, func, - nm_utils_inet6_ntop (network, s_network), + _nm_utils_inet6_ntop (network, s_network), plen, metric, - nm_utils_inet6_ntop (src, s_src), + _nm_utils_inet6_ntop (src, s_src), src_plen, c_exists, c); @@ -553,7 +553,7 @@ _wait_for_signal_timeout (gpointer user_data) } guint -nmtstp_wait_for_signal (NMPlatform *platform, gint64 timeout_ms) +nmtstp_wait_for_signal (NMPlatform *platform, gint64 timeout_msec) { WaitForSignalData data = { 0 }; gulong id_link, id_ip4_address, id_ip6_address, id_ip4_route, id_ip6_route; @@ -568,7 +568,7 @@ nmtstp_wait_for_signal (NMPlatform *platform, gint64 timeout_ms) id_ip4_route = g_signal_connect (platform, NM_PLATFORM_SIGNAL_IP4_ROUTE_CHANGED, G_CALLBACK (_wait_for_signal_cb), &data); id_ip6_route = g_signal_connect (platform, NM_PLATFORM_SIGNAL_IP6_ROUTE_CHANGED, G_CALLBACK (_wait_for_signal_cb), &data); - /* if timeout_ms is negative, it means the wait-time already expired. + /* if timeout_msec is negative, it means the wait-time already expired. * Maybe, we should do nothing and return right away, without even * processing events from platform. However, that inconsistency (of not * processing events from mainloop) is inconvenient. @@ -578,7 +578,7 @@ nmtstp_wait_for_signal (NMPlatform *platform, gint64 timeout_ms) * a zero timeout: we check whether there are any events pending in platform, * and quite the mainloop immediately afterwards. But we always check. */ - data.id = g_timeout_add (CLAMP (timeout_ms, 0, G_MAXUINT32), + data.id = g_timeout_add (CLAMP (timeout_msec, 0, G_MAXUINT32), _wait_for_signal_timeout, &data); g_main_loop_run (data.loop); @@ -590,7 +590,7 @@ nmtstp_wait_for_signal (NMPlatform *platform, gint64 timeout_ms) g_assert (nm_clear_g_signal_handler (platform, &id_ip4_route)); g_assert (nm_clear_g_signal_handler (platform, &id_ip6_route)); - g_clear_pointer (&data.loop, g_main_loop_unref); + nm_clear_pointer (&data.loop, g_main_loop_unref); /* return the number of signals, or 0 if timeout was reached .*/ return data.signal_counts; @@ -603,7 +603,7 @@ nmtstp_wait_for_signal_until (NMPlatform *platform, gint64 until_ms) guint signal_counts; while (TRUE) { - now = nm_utils_get_monotonic_timestamp_ms (); + now = nm_utils_get_monotonic_timestamp_msec (); if (until_ms < now) return 0; @@ -615,11 +615,11 @@ nmtstp_wait_for_signal_until (NMPlatform *platform, gint64 until_ms) } const NMPlatformLink * -nmtstp_wait_for_link (NMPlatform *platform, const char *ifname, NMLinkType expected_link_type, gint64 timeout_ms) +nmtstp_wait_for_link (NMPlatform *platform, const char *ifname, NMLinkType expected_link_type, gint64 timeout_msec) { return nmtstp_wait_for_link_until (platform, ifname, expected_link_type, - timeout_ms - ? nm_utils_get_monotonic_timestamp_ms () + timeout_ms + timeout_msec + ? nm_utils_get_monotonic_timestamp_msec () + timeout_msec : 0); } @@ -633,7 +633,7 @@ nmtstp_wait_for_link_until (NMPlatform *platform, const char *ifname, NMLinkType _init_platform (&platform, FALSE); while (TRUE) { - now = nm_utils_get_monotonic_timestamp_ms (); + now = nm_utils_get_monotonic_timestamp_msec (); plink = nm_platform_link_get_by_ifname (platform, ifname); if ( plink @@ -704,7 +704,7 @@ nmtstp_ip_address_check_lifetime (const NMPlatformIPAddress *addr, g_assert (addr); if (now == -1) - now = nm_utils_get_monotonic_timestamp_s (); + now = nm_utils_get_monotonic_timestamp_sec (); g_assert (now > 0); g_assert (expected_preferred <= expected_lifetime); @@ -750,7 +750,7 @@ nmtstp_ip_address_assert_lifetime (const NMPlatformIPAddress *addr, g_assert (addr); if (now == -1) - now = nm_utils_get_monotonic_timestamp_s (); + now = nm_utils_get_monotonic_timestamp_sec (); g_assert (now > 0); g_assert (expected_preferred <= expected_lifetime); @@ -831,12 +831,12 @@ _ip_address_add (NMPlatform *platform, if ( peer_address->addr4 != address->addr4 || nmtst_get_rand_uint32 () % 2) { /* If the peer is the same as the local address, we can omit it. The result should be identical */ - nm_sprintf_buf (s_peer, " peer %s", nm_utils_inet4_ntop (peer_address->addr4, b2)); + nm_sprintf_buf (s_peer, " peer %s", _nm_utils_inet4_ntop (peer_address->addr4, b2)); } else s_peer[0] = '\0'; nmtstp_run_command_check ("ip address change %s%s/%d dev %s%s%s%s", - nm_utils_inet4_ntop (address->addr4, b1), + _nm_utils_inet4_ntop (address->addr4, b1), s_peer, plen, ifname, @@ -849,9 +849,9 @@ _ip_address_add (NMPlatform *platform, /* flags not implemented (yet) */ g_assert (flags == 0); nmtstp_run_command_check ("ip address change %s%s%s/%d dev %s%s%s%s", - nm_utils_inet6_ntop (&address->addr6, b1), + _nm_utils_inet6_ntop (&address->addr6, b1), !IN6_IS_ADDR_UNSPECIFIED (&peer_address->addr6) ? " peer " : "", - !IN6_IS_ADDR_UNSPECIFIED (&peer_address->addr6) ? nm_utils_inet6_ntop (&peer_address->addr6, b2) : "", + !IN6_IS_ADDR_UNSPECIFIED (&peer_address->addr6) ? _nm_utils_inet6_ntop (&peer_address->addr6, b2) : "", plen, ifname, s_valid ?: "", @@ -867,6 +867,7 @@ _ip_address_add (NMPlatform *platform, address->addr4, plen, peer_address->addr4, + 0u, lifetime, preferred, flags, @@ -886,7 +887,7 @@ _ip_address_add (NMPlatform *platform, } /* Let's wait until we see the address. */ - end_time = nm_utils_get_monotonic_timestamp_ms () + 500; + end_time = nm_utils_get_monotonic_timestamp_msec () + 500; do { if (external_command) @@ -1058,15 +1059,15 @@ _ip_address_del (NMPlatform *platform, if (is_v4) { success = nmtstp_run_command ("ip address delete %s%s%s/%d dev %s", - nm_utils_inet4_ntop (address->addr4, b1), + _nm_utils_inet4_ntop (address->addr4, b1), peer_address->addr4 != address->addr4 ? " peer " : "", - peer_address->addr4 != address->addr4 ? nm_utils_inet4_ntop (peer_address->addr4, b2) : "", + peer_address->addr4 != address->addr4 ? _nm_utils_inet4_ntop (peer_address->addr4, b2) : "", plen, ifname); } else { g_assert (!peer_address); success = nmtstp_run_command ("ip address delete %s/%d dev %s", - nm_utils_inet6_ntop (&address->addr6, b1), + _nm_utils_inet6_ntop (&address->addr6, b1), plen, ifname); } @@ -1091,7 +1092,7 @@ _ip_address_del (NMPlatform *platform, } /* Let's wait until we get the result */ - end_time = nm_utils_get_monotonic_timestamp_ms () + 250; + end_time = nm_utils_get_monotonic_timestamp_msec () + 250; do { if (external_command) nm_platform_process_events (platform); @@ -1257,15 +1258,15 @@ nmtstp_link_gre_add (NMPlatform *platform, name, type, dev ?: "", - nm_utils_inet4_ntop (lnk->local, b1), - nm_utils_inet4_ntop (lnk->remote, b2), + _nm_utils_inet4_ntop (lnk->local, b1), + _nm_utils_inet4_ntop (lnk->remote, b2), lnk->ttl, lnk->tos, lnk->path_mtu_discovery ? "pmtudisc" : "nopmtudisc"); if (success) pllink = nmtstp_assert_wait_for_link (platform, name, link_type, 100); } else - success = NMTST_NM_ERR_SUCCESS (nm_platform_link_gre_add (platform, name, lnk, &pllink)); + success = NMTST_NM_ERR_SUCCESS (nm_platform_link_gre_add (platform, name, NULL, 0, lnk, &pllink)); _assert_pllink (platform, success, pllink, name, link_type); @@ -1319,8 +1320,8 @@ nmtstp_link_ip6tnl_add (NMPlatform *platform, name, mode, dev, - nm_utils_inet6_ntop (&lnk->local, b1), - nm_utils_inet6_ntop (&lnk->remote, b2), + _nm_utils_inet6_ntop (&lnk->local, b1), + _nm_utils_inet6_ntop (&lnk->remote, b2), lnk->ttl, tclass_inherit ? "inherit" : nm_sprintf_buf (tclass, "%02x", lnk->tclass), encap_ignore ? "none" : nm_sprintf_buf (encap, "%u", lnk->encap_limit), @@ -1367,8 +1368,8 @@ nmtstp_link_ip6gre_add (NMPlatform *platform, name, lnk->is_tap ? "ip6gretap" : "ip6gre", dev, - nm_utils_inet6_ntop (&lnk->local, b1), - nm_utils_inet6_ntop (&lnk->remote, b2), + _nm_utils_inet6_ntop (&lnk->local, b1), + _nm_utils_inet6_ntop (&lnk->remote, b2), lnk->ttl, tclass_inherit ? "inherit" : nm_sprintf_buf (tclass, "%02x", lnk->tclass), lnk->flow_label); @@ -1412,8 +1413,8 @@ nmtstp_link_ipip_add (NMPlatform *platform, success = !nmtstp_run_command ("ip tunnel add %s mode ipip %s local %s remote %s ttl %u tos %02x %s", name, dev, - nm_utils_inet4_ntop (lnk->local, b1), - nm_utils_inet4_ntop (lnk->remote, b2), + _nm_utils_inet4_ntop (lnk->local, b1), + _nm_utils_inet4_ntop (lnk->remote, b2), lnk->ttl, lnk->tos, lnk->path_mtu_discovery ? "pmtudisc" : "nopmtudisc"); @@ -1506,8 +1507,8 @@ nmtstp_link_sit_add (NMPlatform *platform, success = !nmtstp_run_command ("ip tunnel add %s mode sit%s local %s remote %s ttl %u tos %02x %s", name, dev, - nm_utils_inet4_ntop (lnk->local, b1), - nm_utils_inet4_ntop (lnk->remote, b2), + _nm_utils_inet4_ntop (lnk->local, b1), + _nm_utils_inet4_ntop (lnk->remote, b2), lnk->ttl, lnk->tos, lnk->path_mtu_discovery ? "pmtudisc" : "nopmtudisc"); @@ -1586,6 +1587,45 @@ nmtstp_link_tun_add (NMPlatform *platform, } const NMPlatformLink * +nmtstp_link_vrf_add (NMPlatform *platform, + gboolean external_command, + const char *name, + const NMPlatformLnkVrf *lnk, + gboolean *out_not_supported) +{ + const NMPlatformLink *pllink = NULL; + int r = 0; + + g_assert (nm_utils_ifname_valid_kernel (name, NULL)); + + NM_SET_OUT (out_not_supported, FALSE); + external_command = nmtstp_run_command_check_external (external_command); + + _init_platform (&platform, external_command); + + if (external_command) { + r = nmtstp_run_command ("ip link add %s type vrf table %u", + name, + lnk->table); + + if (r == 0) + pllink = nmtstp_assert_wait_for_link (platform, name, NM_LINK_TYPE_VRF, 100); + else + _LOGI ("Adding vrf device via iproute2 failed. Assume iproute2 is not up to the task."); + } + + if (!pllink) { + r = nm_platform_link_vrf_add (platform, name, lnk, &pllink); + if (r == -EOPNOTSUPP) + NM_SET_OUT (out_not_supported, TRUE); + } + + _assert_pllink (platform, r == 0, pllink, name, NM_LINK_TYPE_VRF); + + return pllink; +} + +const NMPlatformLink * nmtstp_link_vxlan_add (NMPlatform *platform, gboolean external_command, const char *name, @@ -1610,16 +1650,16 @@ nmtstp_link_vxlan_add (NMPlatform *platform, dev = g_strdup_printf ("dev %s", nm_platform_link_get_name (platform, lnk->parent_ifindex)); if (lnk->local) - nm_utils_inet4_ntop (lnk->local, local); + _nm_utils_inet4_ntop (lnk->local, local); else if (memcmp (&lnk->local6, &in6addr_any, sizeof (in6addr_any))) - nm_utils_inet6_ntop (&lnk->local6, local); + _nm_utils_inet6_ntop (&lnk->local6, local); else local[0] = '\0'; if (lnk->group) - nm_utils_inet4_ntop (lnk->group, group); + _nm_utils_inet4_ntop (lnk->group, group); else if (memcmp (&lnk->group6, &in6addr_any, sizeof (in6addr_any))) - nm_utils_inet6_ntop (&lnk->group6, group); + _nm_utils_inet6_ntop (&lnk->group6, group); else group[0] = '\0'; @@ -1736,7 +1776,7 @@ nmtstp_link_delete (NMPlatform *platform, } /* Let's wait until we get the result */ - end_time = nm_utils_get_monotonic_timestamp_ms () + 250; + end_time = nm_utils_get_monotonic_timestamp_msec () + 250; do { if (external_command) nm_platform_process_events (platform); @@ -1785,7 +1825,7 @@ nmtstp_link_set_updown (NMPlatform *platform, } /* Let's wait until we get the result */ - end_time = nm_utils_get_monotonic_timestamp_ms () + 250; + end_time = nm_utils_get_monotonic_timestamp_msec () + 250; do { if (external_command) nm_platform_process_events (platform); |