platform/tests: add @platform argument to nmtstp functions

This allows tests to use these functions on a different platform instance
then on the singleton. The change makes the argument list longer, which is
unfortunate. On the other hand, it makes those functions more useful
in general.

You can't have it all.

Also, they now follow the pattern of most functions in NM where the type
is a singleton: you always pass the singleton to the function, although
in the usual case there is only one singleton instance. This allows to
use the function also on the non-singleton instance.

(cherry picked from commit c4151ebb5b)
This commit is contained in:
Thomas Haller 2016-04-07 12:32:00 +02:00
parent df74df710e
commit a79a94fcfd
6 changed files with 233 additions and 165 deletions

View file

@ -79,7 +79,7 @@ test_arping_common (test_fixture *fixture, TestInfo *info)
g_assert (nm_arping_manager_add_address (manager, info->addresses[i]));
for (i = 0; info->peer_addresses[i]; i++) {
nmtstp_ip4_address_add (FALSE, fixture->ifindex1, info->peer_addresses[i],
nmtstp_ip4_address_add (NULL, FALSE, fixture->ifindex1, info->peer_addresses[i],
24, 0, 3600, 1800, 0, NULL);
}

View file

@ -94,12 +94,12 @@ test_ip4_address_general (void)
/* Add address */
g_assert (!nm_platform_ip4_address_get (NM_PLATFORM_GET, ifindex, addr, IP4_PLEN, addr));
nmtstp_ip4_address_add (EX, ifindex, addr, IP4_PLEN, addr, lifetime, preferred, 0, NULL);
nmtstp_ip4_address_add (NULL, EX, ifindex, addr, IP4_PLEN, addr, lifetime, preferred, 0, NULL);
g_assert (nm_platform_ip4_address_get (NM_PLATFORM_GET, ifindex, addr, IP4_PLEN, addr));
accept_signal (address_added);
/* Add address again (aka update) */
nmtstp_ip4_address_add (EX, ifindex, addr, IP4_PLEN, addr, lifetime + 100, preferred + 50, 0, NULL);
nmtstp_ip4_address_add (NULL, EX, ifindex, addr, IP4_PLEN, addr, lifetime + 100, preferred + 50, 0, NULL);
accept_signals (address_changed, 0, 1);
/* Test address listing */
@ -114,12 +114,12 @@ test_ip4_address_general (void)
g_array_unref (addresses);
/* Remove address */
nmtstp_ip4_address_del (EX, ifindex, addr, IP4_PLEN, addr);
nmtstp_ip4_address_del (NULL, EX, ifindex, addr, IP4_PLEN, addr);
g_assert (!nm_platform_ip4_address_get (NM_PLATFORM_GET, ifindex, addr, IP4_PLEN, addr));
accept_signal (address_removed);
/* Remove address again */
nmtstp_ip4_address_del (EX, ifindex, addr, IP4_PLEN, addr);
nmtstp_ip4_address_del (NULL, EX, ifindex, addr, IP4_PLEN, addr);
free_signal (address_added);
free_signal (address_changed);
@ -144,12 +144,12 @@ test_ip6_address_general (void)
/* Add address */
g_assert (!nm_platform_ip6_address_get (NM_PLATFORM_GET, ifindex, addr, IP6_PLEN));
nmtstp_ip6_address_add (EX, ifindex, addr, IP6_PLEN, in6addr_any, lifetime, preferred, flags);
nmtstp_ip6_address_add (NULL, EX, ifindex, addr, IP6_PLEN, in6addr_any, lifetime, preferred, flags);
g_assert (nm_platform_ip6_address_get (NM_PLATFORM_GET, ifindex, addr, IP6_PLEN));
accept_signal (address_added);
/* Add address again (aka update) */
nmtstp_ip6_address_add (EX, ifindex, addr, IP6_PLEN, in6addr_any, lifetime, preferred, flags);
nmtstp_ip6_address_add (NULL, EX, ifindex, addr, IP6_PLEN, in6addr_any, lifetime, preferred, flags);
accept_signals (address_changed, 0, 1);
/* Test address listing */
@ -163,12 +163,12 @@ test_ip6_address_general (void)
g_array_unref (addresses);
/* Remove address */
nmtstp_ip6_address_del (EX, ifindex, addr, IP6_PLEN);
nmtstp_ip6_address_del (NULL, EX, ifindex, addr, IP6_PLEN);
g_assert (!nm_platform_ip6_address_get (NM_PLATFORM_GET, ifindex, addr, IP6_PLEN));
accept_signal (address_removed);
/* Remove address again */
nmtstp_ip6_address_del (EX, ifindex, addr, IP6_PLEN);
nmtstp_ip6_address_del (NULL, EX, ifindex, addr, IP6_PLEN);
/* ensure not pending signal. */
accept_signals (address_changed, 0, 1);
@ -197,15 +197,15 @@ test_ip4_address_general_2 (void)
g_assert (nm_platform_link_set_up (NM_PLATFORM_GET, DEVICE_IFINDEX, NULL));
/* Add/delete notification */
nmtstp_ip4_address_add (EX, ifindex, addr, IP4_PLEN, addr, lifetime, preferred, 0, NULL);
nmtstp_ip4_address_add (NULL, EX, ifindex, addr, IP4_PLEN, addr, lifetime, preferred, 0, NULL);
accept_signal (address_added);
g_assert (nm_platform_ip4_address_get (NM_PLATFORM_GET, ifindex, addr, IP4_PLEN, addr));
nmtstp_ip4_address_del (EX, ifindex, addr, IP4_PLEN, addr);
nmtstp_ip4_address_del (NULL, EX, ifindex, addr, IP4_PLEN, addr);
accept_signal (address_removed);
g_assert (!nm_platform_ip4_address_get (NM_PLATFORM_GET, ifindex, addr, IP4_PLEN, addr));
/* Add/delete conflict */
nmtstp_ip4_address_add (EX, ifindex, addr, IP4_PLEN, addr, lifetime, preferred, 0, NULL);
nmtstp_ip4_address_add (NULL, EX, ifindex, addr, IP4_PLEN, addr, lifetime, preferred, 0, NULL);
g_assert (nm_platform_ip4_address_get (NM_PLATFORM_GET, ifindex, addr, IP4_PLEN, addr));
accept_signal (address_added);
@ -227,20 +227,20 @@ test_ip6_address_general_2 (void)
inet_pton (AF_INET6, IP6_ADDRESS, &addr);
/* Add/delete notification */
nmtstp_ip6_address_add (EX, ifindex, addr, IP6_PLEN, in6addr_any, lifetime, preferred, 0);
nmtstp_ip6_address_add (NULL, EX, ifindex, addr, IP6_PLEN, in6addr_any, lifetime, preferred, 0);
accept_signal (address_added);
g_assert (nm_platform_ip6_address_get (NM_PLATFORM_GET, ifindex, addr, IP6_PLEN));
nmtstp_ip6_address_del (EX, ifindex, addr, IP6_PLEN);
nmtstp_ip6_address_del (NULL, EX, ifindex, addr, IP6_PLEN);
accept_signal (address_removed);
g_assert (!nm_platform_ip6_address_get (NM_PLATFORM_GET, ifindex, addr, IP6_PLEN));
/* Add/delete conflict */
nmtstp_ip6_address_add (EX, ifindex, addr, IP6_PLEN, in6addr_any, lifetime, preferred, 0);
nmtstp_ip6_address_add (NULL, EX, ifindex, addr, IP6_PLEN, in6addr_any, lifetime, preferred, 0);
accept_signal (address_added);
g_assert (nm_platform_ip6_address_get (NM_PLATFORM_GET, ifindex, addr, IP6_PLEN));
nmtstp_ip6_address_add (EX, ifindex, addr, IP6_PLEN, in6addr_any, lifetime, preferred, flags);
nmtstp_ip6_address_add (NULL, EX, ifindex, addr, IP6_PLEN, in6addr_any, lifetime, preferred, flags);
ensure_no_signal (address_added);
g_assert (nm_platform_ip6_address_get (NM_PLATFORM_GET, ifindex, addr, IP6_PLEN));
@ -273,7 +273,7 @@ test_ip4_address_peer (void)
accept_signals (address_added, 0, G_MAXINT);
/* Add/delete notification */
nmtstp_ip4_address_add (EX, ifindex, addr, IP4_PLEN, addr_peer, lifetime, preferred, 0, NULL);
nmtstp_ip4_address_add (NULL, EX, ifindex, addr, IP4_PLEN, addr_peer, lifetime, preferred, 0, NULL);
accept_signal (address_added);
a = nm_platform_ip4_address_get (NM_PLATFORM_GET, ifindex, addr, IP4_PLEN, addr_peer);
g_assert (a);
@ -281,7 +281,7 @@ test_ip4_address_peer (void)
nmtstp_ip_address_assert_lifetime ((NMPlatformIPAddress *) a, -1, lifetime, preferred);
nmtstp_ip4_address_add (EX, ifindex, addr, IP4_PLEN, addr_peer2, lifetime, preferred, 0, NULL);
nmtstp_ip4_address_add (NULL, EX, ifindex, addr, IP4_PLEN, addr_peer2, lifetime, preferred, 0, NULL);
accept_signal (address_added);
g_assert (nm_platform_ip4_address_get (NM_PLATFORM_GET, ifindex, addr, IP4_PLEN, addr_peer));
a = nm_platform_ip4_address_get (NM_PLATFORM_GET, ifindex, addr, IP4_PLEN, addr_peer2);
@ -290,7 +290,7 @@ test_ip4_address_peer (void)
nmtstp_ip_address_assert_lifetime ((NMPlatformIPAddress *) a, -1, lifetime, preferred);
g_assert (addr != addr_peer);
nmtstp_ip4_address_del (EX, ifindex, addr, IP4_PLEN, addr_peer);
nmtstp_ip4_address_del (NULL, EX, ifindex, addr, IP4_PLEN, addr_peer);
accept_signal (address_removed);
g_assert (!nm_platform_ip4_address_get (NM_PLATFORM_GET, ifindex, addr, IP4_PLEN, addr_peer));
g_assert (nm_platform_ip4_address_get (NM_PLATFORM_GET, ifindex, addr, IP4_PLEN, addr_peer2));
@ -328,7 +328,7 @@ test_ip4_address_peer_zero (void)
for (i = 0; i < G_N_ELEMENTS (peers); i++) {
g_assert (!nm_platform_ip4_address_get (NM_PLATFORM_GET, ifindex, addr, plen, r_peers[i]));
nmtstp_ip4_address_add (EX, ifindex, addr, plen, r_peers[i], lifetime, preferred, 0, label);
nmtstp_ip4_address_add (NULL, EX, ifindex, addr, plen, r_peers[i], lifetime, preferred, 0, label);
addrs = nm_platform_ip4_address_get_all (NM_PLATFORM_GET, ifindex);
g_assert (addrs);
@ -343,7 +343,7 @@ test_ip4_address_peer_zero (void)
for (i = 0; i < G_N_ELEMENTS (peers); i++) {
g_assert (nm_platform_ip4_address_get (NM_PLATFORM_GET, ifindex, addr, plen, r_peers[i]));
nmtstp_ip4_address_del (EX, ifindex, addr, plen, r_peers[i]);
nmtstp_ip4_address_del (NULL, EX, ifindex, addr, plen, r_peers[i]);
addrs = nm_platform_ip4_address_get_all (NM_PLATFORM_GET, ifindex);
g_assert (addrs);

View file

@ -47,6 +47,18 @@ nmtstp_is_sysfs_writable (void)
|| (access ("/sys/devices", W_OK) == 0);
}
static void
_init_platform (NMPlatform **platform, gboolean external_command)
{
g_assert (platform);
if (!*platform)
*platform = NM_PLATFORM_GET;
g_assert (NM_IS_PLATFORM (*platform));
if (external_command)
g_assert (NM_IS_LINUX_PLATFORM (*platform));
}
/*****************************************************************************/
SignalData *
@ -209,7 +221,7 @@ nmtstp_ip4_route_exists (const char *ifname, guint32 network, int plen, guint32
g_assert (!strstr (ifname, " metric "));
g_assert (plen >= 0 && plen <= 32);
if (!NM_IS_LINUX_PLATFORM (nm_platform_get ())) {
if (!nmtstp_is_root_test ()) {
/* If we don't test against linux-platform, we don't actually configure any
* routes in the system. */
return -1;
@ -263,11 +275,13 @@ nmtstp_ip4_route_exists (const char *ifname, guint32 network, int plen, guint32
}
void
_nmtstp_assert_ip4_route_exists (const char *file, guint line, const char *func, gboolean exists, const char *ifname, guint32 network, int plen, guint32 metric)
_nmtstp_assert_ip4_route_exists (const char *file, guint line, const char *func, NMPlatform *platform, gboolean exists, const char *ifname, guint32 network, int plen, guint32 metric)
{
int ifindex;
gboolean exists_checked;
_init_platform (&platform, FALSE);
/* Check for existance of the route by spawning iproute2. Do this because platform
* code might be entirely borked, but we expect ip-route to give a correct result.
* If the ip command cannot be found, we accept this as success. */
@ -280,9 +294,9 @@ _nmtstp_assert_ip4_route_exists (const char *file, guint line, const char *func,
exists ? "doesn't" : "does");
}
ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, ifname);
ifindex = nm_platform_link_get_ifindex (platform, ifname);
g_assert (ifindex > 0);
if (!nm_platform_ip4_route_get (NM_PLATFORM_GET, ifindex, network, plen, metric) != !exists) {
if (!nm_platform_ip4_route_get (platform, ifindex, network, plen, metric) != !exists) {
g_error ("[%s:%u] %s(): The ip4 route %s/%d metric %u %s, but platform thinks %s",
file, line, func,
nm_utils_inet4_ntop (network, NULL), plen, metric,
@ -349,8 +363,7 @@ nmtstp_wait_for_signal (NMPlatform *platform, guint timeout_ms)
WaitForSignalData data = { 0 };
gulong id_link, id_ip4_address, id_ip6_address, id_ip4_route, id_ip6_route;
if (!platform)
platform = NM_PLATFORM_GET;
_init_platform (&platform, FALSE);
data.loop = g_main_loop_new (NULL, FALSE);
@ -407,10 +420,12 @@ nmtstp_wait_for_link_until (NMPlatform *platform, const char *ifname, NMLinkType
const NMPlatformLink *plink;
gint64 now;
_init_platform (&platform, FALSE);
while (TRUE) {
now = nm_utils_get_monotonic_timestamp_ms ();
plink = nm_platform_link_get_by_ifname (platform ?: NM_PLATFORM_GET, ifname);
plink = nm_platform_link_get_by_ifname (platform, ifname);
if ( plink
&& (expected_link_type == NM_LINK_TYPE_NONE || plink->type == expected_link_type))
return plink;
@ -569,7 +584,8 @@ nmtstp_ip_address_assert_lifetime (const NMPlatformIPAddress *addr,
/*****************************************************************************/
static void
_ip_address_add (gboolean external_command,
_ip_address_add (NMPlatform *platform,
gboolean external_command,
gboolean is_v4,
int ifindex,
const NMIPAddr *address,
@ -584,6 +600,8 @@ _ip_address_add (gboolean external_command,
external_command = nmtstp_run_command_check_external (external_command);
_init_platform (&platform, external_command);
if (external_command) {
const char *ifname;
gs_free char *s_valid = NULL;
@ -591,7 +609,7 @@ _ip_address_add (gboolean external_command,
gs_free char *s_label = NULL;
char b1[NM_UTILS_INET_ADDRSTRLEN], b2[NM_UTILS_INET_ADDRSTRLEN];
ifname = nm_platform_link_get_name (NM_PLATFORM_GET, ifindex);
ifname = nm_platform_link_get_name (platform, ifindex);
g_assert (ifname);
if (lifetime != NM_PLATFORM_LIFETIME_PERMANENT)
@ -640,7 +658,7 @@ _ip_address_add (gboolean external_command,
gboolean success;
if (is_v4) {
success = nm_platform_ip4_address_add (NM_PLATFORM_GET,
success = nm_platform_ip4_address_add (platform,
ifindex,
address->addr4,
plen,
@ -651,7 +669,7 @@ _ip_address_add (gboolean external_command,
label);
} else {
g_assert (label == NULL);
success = nm_platform_ip6_address_add (NM_PLATFORM_GET,
success = nm_platform_ip6_address_add (platform,
ifindex,
address->addr6,
plen,
@ -668,14 +686,14 @@ _ip_address_add (gboolean external_command,
do {
if (external_command)
nm_platform_process_events (NM_PLATFORM_GET);
nm_platform_process_events (platform);
/* let's wait until we see the address as we added it. */
if (is_v4) {
const NMPlatformIP4Address *a;
g_assert (flags == 0);
a = nm_platform_ip4_address_get (NM_PLATFORM_GET, ifindex, address->addr4, plen, peer_address->addr4);
a = nm_platform_ip4_address_get (platform, ifindex, address->addr4, plen, peer_address->addr4);
if ( a
&& a->peer_address == peer_address->addr4
&& nmtstp_ip_address_check_lifetime ((NMPlatformIPAddress*) a, -1, lifetime, preferred)
@ -687,7 +705,7 @@ _ip_address_add (gboolean external_command,
g_assert (label == NULL);
g_assert (flags == 0);
a = nm_platform_ip6_address_get (NM_PLATFORM_GET, ifindex, address->addr6, plen);
a = nm_platform_ip6_address_get (platform, ifindex, address->addr6, plen);
if ( a
&& !memcmp (nm_platform_ip6_address_get_peer (a),
(IN6_IS_ADDR_UNSPECIFIED (&peer_address->addr6) || IN6_ARE_ADDR_EQUAL (&address->addr6, &peer_address->addr6))
@ -700,12 +718,13 @@ _ip_address_add (gboolean external_command,
/* for internal command, we expect not to reach this line.*/
g_assert (external_command);
g_assert (nmtstp_wait_for_signal_until (NM_PLATFORM_GET, end_time));
g_assert (nmtstp_wait_for_signal_until (platform, end_time));
} while (TRUE);
}
void
nmtstp_ip4_address_add (gboolean external_command,
nmtstp_ip4_address_add (NMPlatform *platform,
gboolean external_command,
int ifindex,
in_addr_t address,
int plen,
@ -715,7 +734,8 @@ nmtstp_ip4_address_add (gboolean external_command,
guint32 flags,
const char *label)
{
_ip_address_add (external_command,
_ip_address_add (platform,
external_command,
TRUE,
ifindex,
(NMIPAddr *) &address,
@ -728,7 +748,8 @@ nmtstp_ip4_address_add (gboolean external_command,
}
void
nmtstp_ip6_address_add (gboolean external_command,
nmtstp_ip6_address_add (NMPlatform *platform,
gboolean external_command,
int ifindex,
struct in6_addr address,
int plen,
@ -737,7 +758,8 @@ nmtstp_ip6_address_add (gboolean external_command,
guint32 preferred,
guint32 flags)
{
_ip_address_add (external_command,
_ip_address_add (platform,
external_command,
FALSE,
ifindex,
(NMIPAddr *) &address,
@ -752,7 +774,8 @@ nmtstp_ip6_address_add (gboolean external_command,
/*****************************************************************************/
static void
_ip_address_del (gboolean external_command,
_ip_address_del (NMPlatform *platform,
gboolean external_command,
gboolean is_v4,
int ifindex,
const NMIPAddr *address,
@ -763,20 +786,22 @@ _ip_address_del (gboolean external_command,
external_command = nmtstp_run_command_check_external (external_command);
_init_platform (&platform, external_command);
if (external_command) {
const char *ifname;
char b1[NM_UTILS_INET_ADDRSTRLEN], b2[NM_UTILS_INET_ADDRSTRLEN];
int success;
gboolean had_address;
ifname = nm_platform_link_get_name (NM_PLATFORM_GET, ifindex);
ifname = nm_platform_link_get_name (platform, ifindex);
g_assert (ifname);
/* let's wait until we see the address as we added it. */
if (is_v4)
had_address = !!nm_platform_ip4_address_get (NM_PLATFORM_GET, ifindex, address->addr4, plen, peer_address->addr4);
had_address = !!nm_platform_ip4_address_get (platform, ifindex, address->addr4, plen, peer_address->addr4);
else
had_address = !!nm_platform_ip6_address_get (NM_PLATFORM_GET, ifindex, address->addr6, plen);
had_address = !!nm_platform_ip6_address_get (platform, ifindex, address->addr6, plen);
if (is_v4) {
success = nmtstp_run_command ("ip address delete %s%s%s/%d dev %s",
@ -797,14 +822,14 @@ _ip_address_del (gboolean external_command,
gboolean success;
if (is_v4) {
success = nm_platform_ip4_address_delete (NM_PLATFORM_GET,
success = nm_platform_ip4_address_delete (platform,
ifindex,
address->addr4,
plen,
peer_address->addr4);
} else {
g_assert (!peer_address);
success = nm_platform_ip6_address_delete (NM_PLATFORM_GET,
success = nm_platform_ip6_address_delete (platform,
ifindex,
address->addr6,
plen);
@ -816,19 +841,19 @@ _ip_address_del (gboolean external_command,
end_time = nm_utils_get_monotonic_timestamp_ms () + 250;
do {
if (external_command)
nm_platform_process_events (NM_PLATFORM_GET);
nm_platform_process_events (platform);
/* let's wait until we see the address as we added it. */
if (is_v4) {
const NMPlatformIP4Address *a;
a = nm_platform_ip4_address_get (NM_PLATFORM_GET, ifindex, address->addr4, plen, peer_address->addr4);
a = nm_platform_ip4_address_get (platform, ifindex, address->addr4, plen, peer_address->addr4);
if (!a)
break;
} else {
const NMPlatformIP6Address *a;
a = nm_platform_ip6_address_get (NM_PLATFORM_GET, ifindex, address->addr6, plen);
a = nm_platform_ip6_address_get (platform, ifindex, address->addr6, plen);
if (!a)
break;
}
@ -836,18 +861,20 @@ _ip_address_del (gboolean external_command,
/* for internal command, we expect not to reach this line.*/
g_assert (external_command);
g_assert (nmtstp_wait_for_signal_until (NM_PLATFORM_GET, end_time));
g_assert (nmtstp_wait_for_signal_until (platform, end_time));
} while (TRUE);
}
void
nmtstp_ip4_address_del (gboolean external_command,
nmtstp_ip4_address_del (NMPlatform *platform,
gboolean external_command,
int ifindex,
in_addr_t address,
int plen,
in_addr_t peer_address)
{
_ip_address_del (external_command,
_ip_address_del (platform,
external_command,
TRUE,
ifindex,
(NMIPAddr *) &address,
@ -856,12 +883,14 @@ nmtstp_ip4_address_del (gboolean external_command,
}
void
nmtstp_ip6_address_del (gboolean external_command,
nmtstp_ip6_address_del (NMPlatform *platform,
gboolean external_command,
int ifindex,
struct in6_addr address,
int plen)
{
_ip_address_del (external_command,
_ip_address_del (platform,
external_command,
FALSE,
ifindex,
(NMIPAddr *) &address,
@ -885,7 +914,8 @@ nmtstp_ip6_address_del (gboolean external_command,
} G_STMT_END
const NMPlatformLink *
nmtstp_link_dummy_add (gboolean external_command,
nmtstp_link_dummy_add (NMPlatform *platform,
gboolean external_command,
const char *name)
{
const NMPlatformLink *pllink = NULL;
@ -895,21 +925,24 @@ nmtstp_link_dummy_add (gboolean external_command,
external_command = nmtstp_run_command_check_external (external_command);
_init_platform (&platform, external_command);
if (external_command) {
success = !nmtstp_run_command ("ip link add %s type dummy",
name);
if (success)
pllink = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, name, NM_LINK_TYPE_DUMMY, 100);
pllink = nmtstp_assert_wait_for_link (platform, name, NM_LINK_TYPE_DUMMY, 100);
} else
success = nm_platform_link_dummy_add (NM_PLATFORM_GET, name, &pllink) == NM_PLATFORM_ERROR_SUCCESS;
success = nm_platform_link_dummy_add (platform, name, &pllink) == NM_PLATFORM_ERROR_SUCCESS;
g_assert (success);
_assert_pllink (NM_PLATFORM_GET, success, pllink, name, NM_LINK_TYPE_DUMMY);
_assert_pllink (platform, success, pllink, name, NM_LINK_TYPE_DUMMY);
return pllink;
}
const NMPlatformLink *
nmtstp_link_gre_add (gboolean external_command,
nmtstp_link_gre_add (NMPlatform *platform,
gboolean external_command,
const char *name,
const NMPlatformLnkGre *lnk)
{
@ -921,11 +954,13 @@ nmtstp_link_gre_add (gboolean external_command,
external_command = nmtstp_run_command_check_external (external_command);
_init_platform (&platform, external_command);
if (external_command) {
gs_free char *dev = NULL;
if (lnk->parent_ifindex)
dev = g_strdup_printf ("dev %s", nm_platform_link_get_name (NM_PLATFORM_GET, lnk->parent_ifindex));
dev = g_strdup_printf ("dev %s", nm_platform_link_get_name (platform, lnk->parent_ifindex));
success = !nmtstp_run_command ("ip tunnel add %s mode gre %s local %s remote %s ttl %u tos %02x %s",
name,
@ -936,17 +971,18 @@ nmtstp_link_gre_add (gboolean external_command,
lnk->tos,
lnk->path_mtu_discovery ? "pmtudisc" : "nopmtudisc");
if (success)
pllink = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, name, NM_LINK_TYPE_GRE, 100);
pllink = nmtstp_assert_wait_for_link (platform, name, NM_LINK_TYPE_GRE, 100);
} else
success = nm_platform_link_gre_add (NM_PLATFORM_GET, name, lnk, &pllink) == NM_PLATFORM_ERROR_SUCCESS;
success = nm_platform_link_gre_add (platform, name, lnk, &pllink) == NM_PLATFORM_ERROR_SUCCESS;
_assert_pllink (NM_PLATFORM_GET, success, pllink, name, NM_LINK_TYPE_GRE);
_assert_pllink (platform, success, pllink, name, NM_LINK_TYPE_GRE);
return pllink;
}
const NMPlatformLink *
nmtstp_link_ip6tnl_add (gboolean external_command,
nmtstp_link_ip6tnl_add (NMPlatform *platform,
gboolean external_command,
const char *name,
const NMPlatformLnkIp6Tnl *lnk)
{
@ -958,12 +994,14 @@ nmtstp_link_ip6tnl_add (gboolean external_command,
external_command = nmtstp_run_command_check_external (external_command);
_init_platform (&platform, external_command);
if (external_command) {
gs_free char *dev = NULL;
const char *mode;
if (lnk->parent_ifindex)
dev = g_strdup_printf ("dev %s", nm_platform_link_get_name (NM_PLATFORM_GET, lnk->parent_ifindex));
dev = g_strdup_printf ("dev %s", nm_platform_link_get_name (platform, lnk->parent_ifindex));
switch (lnk->proto) {
case IPPROTO_IPIP:
@ -987,17 +1025,18 @@ nmtstp_link_ip6tnl_add (gboolean external_command,
lnk->encap_limit,
lnk->flow_label);
if (success)
pllink = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, name, NM_LINK_TYPE_IP6TNL, 100);
pllink = nmtstp_assert_wait_for_link (platform, name, NM_LINK_TYPE_IP6TNL, 100);
} else
success = nm_platform_link_ip6tnl_add (NM_PLATFORM_GET, name, lnk, &pllink) == NM_PLATFORM_ERROR_SUCCESS;
success = nm_platform_link_ip6tnl_add (platform, name, lnk, &pllink) == NM_PLATFORM_ERROR_SUCCESS;
_assert_pllink (NM_PLATFORM_GET, success, pllink, name, NM_LINK_TYPE_IP6TNL);
_assert_pllink (platform, success, pllink, name, NM_LINK_TYPE_IP6TNL);
return pllink;
}
const NMPlatformLink *
nmtstp_link_ipip_add (gboolean external_command,
nmtstp_link_ipip_add (NMPlatform *platform,
gboolean external_command,
const char *name,
const NMPlatformLnkIpIp *lnk)
{
@ -1009,11 +1048,13 @@ nmtstp_link_ipip_add (gboolean external_command,
external_command = nmtstp_run_command_check_external (external_command);
_init_platform (&platform, external_command);
if (external_command) {
gs_free char *dev = NULL;
if (lnk->parent_ifindex)
dev = g_strdup_printf ("dev %s", nm_platform_link_get_name (NM_PLATFORM_GET, lnk->parent_ifindex));
dev = g_strdup_printf ("dev %s", nm_platform_link_get_name (platform, lnk->parent_ifindex));
success = !nmtstp_run_command ("ip tunnel add %s mode ipip %s local %s remote %s ttl %u tos %02x %s",
name,
@ -1024,17 +1065,18 @@ nmtstp_link_ipip_add (gboolean external_command,
lnk->tos,
lnk->path_mtu_discovery ? "pmtudisc" : "nopmtudisc");
if (success)
pllink = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, name, NM_LINK_TYPE_IPIP, 100);
pllink = nmtstp_assert_wait_for_link (platform, name, NM_LINK_TYPE_IPIP, 100);
} else
success = nm_platform_link_ipip_add (NM_PLATFORM_GET, name, lnk, &pllink) == NM_PLATFORM_ERROR_SUCCESS;
success = nm_platform_link_ipip_add (platform, name, lnk, &pllink) == NM_PLATFORM_ERROR_SUCCESS;
_assert_pllink (NM_PLATFORM_GET, success, pllink, name, NM_LINK_TYPE_IPIP);
_assert_pllink (platform, success, pllink, name, NM_LINK_TYPE_IPIP);
return pllink;
}
const NMPlatformLink *
nmtstp_link_macvlan_add (gboolean external_command,
nmtstp_link_macvlan_add (NMPlatform *platform,
gboolean external_command,
const char *name,
int parent,
const NMPlatformLnkMacvlan *lnk)
@ -1047,6 +1089,8 @@ nmtstp_link_macvlan_add (gboolean external_command,
external_command = nmtstp_run_command_check_external (external_command);
_init_platform (&platform, external_command);
link_type = lnk->tap ? NM_LINK_TYPE_MACVTAP : NM_LINK_TYPE_MACVLAN;
if (external_command) {
@ -1058,7 +1102,7 @@ nmtstp_link_macvlan_add (gboolean external_command,
[MACVLAN_MODE_PASSTHRU] = "passthru",
};
dev = nm_platform_link_get_name (NM_PLATFORM_GET, parent);
dev = nm_platform_link_get_name (platform, parent);
g_assert (dev);
g_assert_cmpint (lnk->mode, <, G_N_ELEMENTS (modes));
@ -1069,17 +1113,18 @@ nmtstp_link_macvlan_add (gboolean external_command,
modes[lnk->mode],
lnk->no_promisc ? "nopromisc" : "");
if (success)
pllink = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, name, link_type, 100);
pllink = nmtstp_assert_wait_for_link (platform, name, link_type, 100);
} else
success = nm_platform_link_macvlan_add (NM_PLATFORM_GET, name, parent, lnk, &pllink) == NM_PLATFORM_ERROR_SUCCESS;
success = nm_platform_link_macvlan_add (platform, name, parent, lnk, &pllink) == NM_PLATFORM_ERROR_SUCCESS;
_assert_pllink (NM_PLATFORM_GET, success, pllink, name, link_type);
_assert_pllink (platform, success, pllink, name, link_type);
return pllink;
}
const NMPlatformLink *
nmtstp_link_sit_add (gboolean external_command,
nmtstp_link_sit_add (NMPlatform *platform,
gboolean external_command,
const char *name,
const NMPlatformLnkSit *lnk)
{
@ -1091,13 +1136,15 @@ nmtstp_link_sit_add (gboolean external_command,
external_command = nmtstp_run_command_check_external (external_command);
_init_platform (&platform, external_command);
if (external_command) {
const char *dev = "";
if (lnk->parent_ifindex) {
const char *parent_name;
parent_name = nm_platform_link_get_name (NM_PLATFORM_GET, lnk->parent_ifindex);
parent_name = nm_platform_link_get_name (platform, lnk->parent_ifindex);
g_assert (parent_name);
dev = nm_sprintf_bufa (100, " dev %s", parent_name);
}
@ -1111,17 +1158,18 @@ nmtstp_link_sit_add (gboolean external_command,
lnk->tos,
lnk->path_mtu_discovery ? "pmtudisc" : "nopmtudisc");
if (success)
pllink = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, name, NM_LINK_TYPE_SIT, 100);
pllink = nmtstp_assert_wait_for_link (platform, name, NM_LINK_TYPE_SIT, 100);
} else
success = nm_platform_link_sit_add (NM_PLATFORM_GET, name, lnk, &pllink) == NM_PLATFORM_ERROR_SUCCESS;
success = nm_platform_link_sit_add (platform, name, lnk, &pllink) == NM_PLATFORM_ERROR_SUCCESS;
_assert_pllink (NM_PLATFORM_GET, success, pllink, name, NM_LINK_TYPE_SIT);
_assert_pllink (platform, success, pllink, name, NM_LINK_TYPE_SIT);
return pllink;
}
const NMPlatformLink *
nmtstp_link_vxlan_add (gboolean external_command,
nmtstp_link_vxlan_add (NMPlatform *platform,
gboolean external_command,
const char *name,
const NMPlatformLnkVxlan *lnk)
{
@ -1133,12 +1181,14 @@ nmtstp_link_vxlan_add (gboolean external_command,
external_command = nmtstp_run_command_check_external (external_command);
_init_platform (&platform, external_command);
if (external_command) {
gs_free char *dev = NULL;
gs_free char *local = NULL, *remote = NULL;
if (lnk->parent_ifindex)
dev = g_strdup_printf ("dev %s", nm_platform_link_get_name (NM_PLATFORM_GET, lnk->parent_ifindex));
dev = g_strdup_printf ("dev %s", nm_platform_link_get_name (platform, lnk->parent_ifindex));
if (lnk->local)
local = g_strdup_printf ("%s", nm_utils_inet4_ntop (lnk->local, NULL));
@ -1164,12 +1214,12 @@ nmtstp_link_vxlan_add (gboolean external_command,
/* Older versions of iproute2 don't support adding vxlan devices.
* On failure, fallback to using platform code. */
if (err == 0)
pllink = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, name, NM_LINK_TYPE_VXLAN, 100);
pllink = nmtstp_assert_wait_for_link (platform, name, NM_LINK_TYPE_VXLAN, 100);
else
_LOGI ("Adding vxlan device via iproute2 failed. Assume iproute2 is not up to the task.");
}
if (!pllink) {
plerr = nm_platform_link_vxlan_add (NM_PLATFORM_GET, name, lnk, &pllink);
plerr = nm_platform_link_vxlan_add (platform, name, lnk, &pllink);
g_assert_cmpint (plerr, ==, NM_PLATFORM_ERROR_SUCCESS);
g_assert (pllink);
}
@ -1189,8 +1239,7 @@ nmtstp_link_get_typed (NMPlatform *platform,
{
const NMPlatformLink *pllink = NULL;
if (!platform)
platform = NM_PLATFORM_GET;
_init_platform (&platform, FALSE);
if (ifindex > 0) {
pllink = nm_platform_link_get (platform, ifindex);
@ -1231,7 +1280,8 @@ nmtstp_link_get (NMPlatform *platform,
/*****************************************************************************/
void
nmtstp_link_del (gboolean external_command,
nmtstp_link_del (NMPlatform *platform,
gboolean external_command,
int ifindex,
const char *name)
{
@ -1240,19 +1290,21 @@ nmtstp_link_del (gboolean external_command,
gboolean success;
gs_free char *name_copy = NULL;
pllink = nmtstp_link_get (NM_PLATFORM_GET, ifindex, name);
external_command = nmtstp_run_command_check_external (external_command);
_init_platform (&platform, external_command);
pllink = nmtstp_link_get (platform, ifindex, name);
g_assert (pllink);
name = name_copy = g_strdup (pllink->name);
ifindex = pllink->ifindex;
external_command = nmtstp_run_command_check_external (external_command);
if (external_command) {
nmtstp_run_command_check ("ip link delete %s", name);
} else {
success = nm_platform_link_delete (NM_PLATFORM_GET, ifindex);
success = nm_platform_link_delete (platform, ifindex);
g_assert (success);
}
@ -1260,24 +1312,25 @@ nmtstp_link_del (gboolean external_command,
end_time = nm_utils_get_monotonic_timestamp_ms () + 250;
do {
if (external_command)
nm_platform_process_events (NM_PLATFORM_GET);
nm_platform_process_events (platform);
if (!nm_platform_link_get (NM_PLATFORM_GET, ifindex)) {
g_assert (!nm_platform_link_get_by_ifname (NM_PLATFORM_GET, name));
if (!nm_platform_link_get (platform, ifindex)) {
g_assert (!nm_platform_link_get_by_ifname (platform, name));
break;
}
/* for internal command, we expect not to reach this line.*/
g_assert (external_command);
g_assert (nmtstp_wait_for_signal_until (NM_PLATFORM_GET, end_time));
g_assert (nmtstp_wait_for_signal_until (platform, end_time));
} while (TRUE);
}
/*****************************************************************************/
void
nmtstp_link_set_updown (gboolean external_command,
nmtstp_link_set_updown (NMPlatform *platform,
gboolean external_command,
int ifindex,
gboolean up)
{
@ -1286,10 +1339,12 @@ nmtstp_link_set_updown (gboolean external_command,
external_command = nmtstp_run_command_check_external (external_command);
_init_platform (&platform, external_command);
if (external_command) {
const char *ifname;
ifname = nm_platform_link_get_name (NM_PLATFORM_GET, ifindex);
ifname = nm_platform_link_get_name (platform, ifindex);
g_assert (ifname);
nmtstp_run_command_check ("ip link set %s %s",
@ -1297,19 +1352,19 @@ nmtstp_link_set_updown (gboolean external_command,
up ? "up" : "down");
} else {
if (up)
g_assert (nm_platform_link_set_up (NM_PLATFORM_GET, ifindex, NULL));
g_assert (nm_platform_link_set_up (platform, ifindex, NULL));
else
g_assert (nm_platform_link_set_down (NM_PLATFORM_GET, ifindex));
g_assert (nm_platform_link_set_down (platform, ifindex));
}
/* Let's wait until we get the result */
end_time = nm_utils_get_monotonic_timestamp_ms () + 250;
do {
if (external_command)
nm_platform_process_events (NM_PLATFORM_GET);
nm_platform_process_events (platform);
/* let's wait until we see the address as we added it. */
plink = nm_platform_link_get (NM_PLATFORM_GET, ifindex);
plink = nm_platform_link_get (platform, ifindex);
g_assert (plink);
if (NM_FLAGS_HAS (plink->n_ifi_flags, IFF_UP) == !!up)
@ -1318,7 +1373,7 @@ nmtstp_link_set_updown (gboolean external_command,
/* for internal command, we expect not to reach this line.*/
g_assert (external_command);
g_assert (nmtstp_wait_for_signal_until (NM_PLATFORM_GET, end_time));
g_assert (nmtstp_wait_for_signal_until (platform, end_time));
} while (TRUE);
}

View file

@ -106,8 +106,8 @@ gboolean nmtstp_run_command_check_external (int external_command);
gboolean nmtstp_ip4_route_exists (const char *ifname, guint32 network, int plen, guint32 metric);
void _nmtstp_assert_ip4_route_exists (const char *file, guint line, const char *func, gboolean exists, const char *ifname, guint32 network, int plen, guint32 metric);
#define nmtstp_assert_ip4_route_exists(exists, ifname, network, plen, metric) _nmtstp_assert_ip4_route_exists (__FILE__, __LINE__, G_STRFUNC, exists, ifname, network, plen, metric)
void _nmtstp_assert_ip4_route_exists (const char *file, guint line, const char *func, NMPlatform *platform, gboolean exists, const char *ifname, guint32 network, int plen, guint32 metric);
#define nmtstp_assert_ip4_route_exists(platform, exists, ifname, network, plen, metric) _nmtstp_assert_ip4_route_exists (__FILE__, __LINE__, G_STRFUNC, platform, exists, ifname, network, plen, metric)
/*****************************************************************************/
@ -120,7 +120,8 @@ void nmtstp_ip_address_assert_lifetime (const NMPlatformIPAddress *addr,
guint32 expected_lifetime,
guint32 expected_preferred);
void nmtstp_ip4_address_add (gboolean external_command,
void nmtstp_ip4_address_add (NMPlatform *platform,
gboolean external_command,
int ifindex,
in_addr_t address,
int plen,
@ -129,7 +130,8 @@ void nmtstp_ip4_address_add (gboolean external_command,
guint32 preferred,
guint32 flags,
const char *label);
void nmtstp_ip6_address_add (gboolean external_command,
void nmtstp_ip6_address_add (NMPlatform *platform,
gboolean external_command,
int ifindex,
struct in6_addr address,
int plen,
@ -137,12 +139,14 @@ void nmtstp_ip6_address_add (gboolean external_command,
guint32 lifetime,
guint32 preferred,
guint32 flags);
void nmtstp_ip4_address_del (gboolean external_command,
void nmtstp_ip4_address_del (NMPlatform *platform,
gboolean external_command,
int ifindex,
in_addr_t address,
int plen,
in_addr_t peer_address);
void nmtstp_ip6_address_del (gboolean external_command,
void nmtstp_ip6_address_del (NMPlatform *platform,
gboolean external_command,
int ifindex,
struct in6_addr address,
int plen);
@ -152,33 +156,42 @@ void nmtstp_ip6_address_del (gboolean external_command,
const NMPlatformLink *nmtstp_link_get_typed (NMPlatform *platform, int ifindex, const char *name, NMLinkType link_type);
const NMPlatformLink *nmtstp_link_get (NMPlatform *platform, int ifindex, const char *name);
void nmtstp_link_set_updown (gboolean external_command,
void nmtstp_link_set_updown (NMPlatform *platform,
gboolean external_command,
int ifindex,
gboolean up);
const NMPlatformLink *nmtstp_link_dummy_add (gboolean external_command,
const NMPlatformLink *nmtstp_link_dummy_add (NMPlatform *platform,
gboolean external_command,
const char *name);
const NMPlatformLink *nmtstp_link_gre_add (gboolean external_command,
const NMPlatformLink *nmtstp_link_gre_add (NMPlatform *platform,
gboolean external_command,
const char *name,
const NMPlatformLnkGre *lnk);
const NMPlatformLink *nmtstp_link_ip6tnl_add (gboolean external_command,
const NMPlatformLink *nmtstp_link_ip6tnl_add (NMPlatform *platform,
gboolean external_command,
const char *name,
const NMPlatformLnkIp6Tnl *lnk);
const NMPlatformLink *nmtstp_link_ipip_add (gboolean external_command,
const NMPlatformLink *nmtstp_link_ipip_add (NMPlatform *platform,
gboolean external_command,
const char *name,
const NMPlatformLnkIpIp *lnk);
const NMPlatformLink *nmtstp_link_macvlan_add (gboolean external_command,
const NMPlatformLink *nmtstp_link_macvlan_add (NMPlatform *platform,
gboolean external_command,
const char *name,
int parent,
const NMPlatformLnkMacvlan *lnk);
const NMPlatformLink *nmtstp_link_sit_add (gboolean external_command,
const NMPlatformLink *nmtstp_link_sit_add (NMPlatform *platform,
gboolean external_command,
const char *name,
const NMPlatformLnkSit *lnk);
const NMPlatformLink *nmtstp_link_vxlan_add (gboolean external_command,
const NMPlatformLink *nmtstp_link_vxlan_add (NMPlatform *platform,
gboolean external_command,
const char *name,
const NMPlatformLnkVxlan *lnk);
void nmtstp_link_del (gboolean external_command,
void nmtstp_link_del (NMPlatform *platform,
gboolean external_command,
int ifindex,
const char *name);

View file

@ -343,7 +343,7 @@ test_slave (int master, int type, SignalData *master_changed)
ensure_no_signal (link_added);
ensure_no_signal (link_changed);
ensure_no_signal (link_removed);
nmtstp_link_del (-1, ifindex, NULL);
nmtstp_link_del (NULL, -1, ifindex, NULL);
accept_signals (master_changed, 0, 1);
accept_signals (link_changed, 0, 1);
accept_signal (link_removed);
@ -437,7 +437,7 @@ test_software (NMLinkType link_type, const char *link_typename)
free_signal (link_changed);
/* Delete */
nmtstp_link_del (-1, ifindex, DEVICE_NAME);
nmtstp_link_del (NULL, -1, ifindex, DEVICE_NAME);
accept_signal (link_removed);
/* Delete again */
@ -448,7 +448,7 @@ test_software (NMLinkType link_type, const char *link_typename)
if (link_type == NM_LINK_TYPE_VLAN) {
SignalData *link_removed_parent = add_signal_ifindex (NM_PLATFORM_SIGNAL_LINK_CHANGED, NM_PLATFORM_SIGNAL_REMOVED, link_callback, vlan_parent);
nmtstp_link_del (-1, vlan_parent, NULL);
nmtstp_link_del (NULL, -1, vlan_parent, NULL);
accept_signal (link_removed_parent);
free_signal (link_removed_parent);
}
@ -531,7 +531,7 @@ test_bridge_addr (void)
g_assert_cmpint (plink->addr.len, ==, sizeof (addr));
g_assert (!memcmp (plink->addr.data, addr, sizeof (addr)));
nmtstp_link_del (-1, link.ifindex, link.name);
nmtstp_link_del (NULL, -1, link.ifindex, link.name);
}
/*****************************************************************************/
@ -606,7 +606,7 @@ test_internal (void)
accept_signal (link_changed);
/* Delete device */
nmtstp_link_del (-1, ifindex, DEVICE_NAME);
nmtstp_link_del (NULL, -1, ifindex, DEVICE_NAME);
accept_signal (link_removed);
/* Try to delete again */
@ -717,7 +717,7 @@ test_software_detect (gconstpointer user_data)
gracefully_skip = nm_utils_modprobe (NULL, TRUE, "ip_gre", NULL) != 0;
}
if (!nmtstp_link_gre_add (ext, DEVICE_NAME, &lnk_gre)) {
if (!nmtstp_link_gre_add (NULL, ext, DEVICE_NAME, &lnk_gre)) {
if (gracefully_skip) {
g_test_skip ("Cannot create gre tunnel because of missing ip_gre module (modprobe ip_gre)");
goto out_delete_parent;
@ -741,7 +741,7 @@ test_software_detect (gconstpointer user_data)
lnk_ipip.tos = 32;
lnk_ipip.path_mtu_discovery = FALSE;
if (!nmtstp_link_ipip_add (ext, DEVICE_NAME, &lnk_ipip)) {
if (!nmtstp_link_ipip_add (NULL, ext, DEVICE_NAME, &lnk_ipip)) {
if (gracefully_skip) {
g_test_skip ("Cannot create ipip tunnel because of missing ipip module (modprobe ipip)");
goto out_delete_parent;
@ -767,7 +767,7 @@ test_software_detect (gconstpointer user_data)
lnk_ip6tnl.flow_label = 1337;
lnk_ip6tnl.proto = IPPROTO_IPV6;
if (!nmtstp_link_ip6tnl_add (ext, DEVICE_NAME, &lnk_ip6tnl)) {
if (!nmtstp_link_ip6tnl_add (NULL, ext, DEVICE_NAME, &lnk_ip6tnl)) {
if (gracefully_skip) {
g_test_skip ("Cannot create ip6tnl tunnel because of missing ip6_tunnel module (modprobe ip6_tunnel)");
goto out_delete_parent;
@ -783,7 +783,7 @@ test_software_detect (gconstpointer user_data)
lnk_macvlan.no_promisc = FALSE;
lnk_macvlan.tap = FALSE;
if (!nmtstp_link_macvlan_add (ext, DEVICE_NAME, ifindex_parent, &lnk_macvlan))
if (!nmtstp_link_macvlan_add (NULL, ext, DEVICE_NAME, ifindex_parent, &lnk_macvlan))
g_error ("Failed adding MACVLAN interface");
break;
}
@ -794,7 +794,7 @@ test_software_detect (gconstpointer user_data)
lnk_macvtap.no_promisc = FALSE;
lnk_macvtap.tap = TRUE;
if (!nmtstp_link_macvlan_add (ext, DEVICE_NAME, ifindex_parent, &lnk_macvtap))
if (!nmtstp_link_macvlan_add (NULL, ext, DEVICE_NAME, ifindex_parent, &lnk_macvtap))
g_error ("Failed adding MACVTAP interface");
break;
}
@ -814,7 +814,7 @@ test_software_detect (gconstpointer user_data)
gracefully_skip = nm_utils_modprobe (NULL, TRUE, "sit", NULL) != 0;
}
if (!nmtstp_link_sit_add (ext, DEVICE_NAME, &lnk_sit)) {
if (!nmtstp_link_sit_add (NULL, ext, DEVICE_NAME, &lnk_sit)) {
if (gracefully_skip) {
g_test_skip ("Cannot create sit tunnel because of missing sit module (modprobe sit)");
goto out_delete_parent;
@ -853,7 +853,7 @@ test_software_detect (gconstpointer user_data)
break;
}
g_assert (nmtstp_link_vxlan_add (ext, DEVICE_NAME, &lnk_vxlan));
g_assert (nmtstp_link_vxlan_add (NULL, ext, DEVICE_NAME, &lnk_vxlan));
break;
}
default:
@ -862,7 +862,7 @@ test_software_detect (gconstpointer user_data)
ifindex = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, DEVICE_NAME, test_data->link_type, 100)->ifindex;
nmtstp_link_set_updown (-1, ifindex_parent, TRUE);
nmtstp_link_set_updown (NULL, -1, ifindex_parent, TRUE);
for (i_step = 0; i_step < 5; i_step++) {
@ -880,7 +880,7 @@ test_software_detect (gconstpointer user_data)
* https://bugzilla.redhat.com/show_bug.cgi?id=1277131 */
g_usleep (1);
}
nmtstp_link_set_updown (-1, ifindex, set_up);
nmtstp_link_set_updown (NULL, -1, ifindex, set_up);
}
lnk = nm_platform_link_get_lnk (NM_PLATFORM_GET, ifindex, test_data->link_type, &plink);
@ -1017,9 +1017,9 @@ test_software_detect (gconstpointer user_data)
}
}
nmtstp_link_del (-1, ifindex, DEVICE_NAME);
nmtstp_link_del (NULL, -1, ifindex, DEVICE_NAME);
out_delete_parent:
nmtstp_link_del (-1, ifindex_parent, PARENT_NAME);
nmtstp_link_del (NULL, -1, ifindex_parent, PARENT_NAME);
}
static void
@ -1597,8 +1597,8 @@ test_vlan_set_xgress (void)
_assert_vlan_flags (ifindex, NM_VLAN_FLAG_REORDER_HEADERS | NM_VLAN_FLAG_GVRP);
}
nmtstp_link_del (-1, ifindex, DEVICE_NAME);
nmtstp_link_del (-1, ifindex_parent, PARENT_NAME);
nmtstp_link_del (NULL, -1, ifindex, DEVICE_NAME);
nmtstp_link_del (NULL, -1, ifindex_parent, PARENT_NAME);
}
/*****************************************************************************/
@ -1625,7 +1625,7 @@ test_create_many_links_do (guint n_devices)
* while adding all the links. */
nmtstp_run_command_check ("ip link add %s type dummy", name);
} else
nmtstp_link_dummy_add (EX, name);
nmtstp_link_dummy_add (NULL, EX, name);
}
_LOGI (">>> process events after creating devices...");
@ -1654,7 +1654,7 @@ test_create_many_links_do (guint n_devices)
if (EX == 2)
nmtstp_run_command_check ("ip link delete %s", name);
else
nmtstp_link_del (EX, g_array_index (ifindexes, int, i), name);
nmtstp_link_del (NULL, EX, g_array_index (ifindexes, int, i), name);
}
_LOGI (">>> process events after deleting devices...");
@ -1743,7 +1743,7 @@ test_nl_bugs_veth (void)
});
out:
nmtstp_link_del (-1, ifindex_veth0, IFACE_VETH0);
nmtstp_link_del (NULL, -1, ifindex_veth0, IFACE_VETH0);
g_assert (!nmtstp_link_get (NM_PLATFORM_GET, ifindex_veth0, IFACE_VETH0));
g_assert (!nmtstp_link_get (NM_PLATFORM_GET, ifindex_veth1, IFACE_VETH1));
nmtstp_namespace_handle_release (ns_handle);
@ -1768,7 +1768,7 @@ test_nl_bugs_spuroius_newlink (void)
nmtstp_run_command_check ("ip link add %s type bond", IFACE_BOND0);
ifindex_bond0 = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, IFACE_BOND0, NM_LINK_TYPE_BOND, 100)->ifindex;
nmtstp_link_set_updown (-1, ifindex_bond0, TRUE);
nmtstp_link_set_updown (NULL, -1, ifindex_bond0, TRUE);
nmtstp_run_command_check ("ip link set %s master %s", IFACE_DUMMY0, IFACE_BOND0);
NMTST_WAIT_ASSERT (100, {
@ -1796,7 +1796,7 @@ again:
}
g_assert (!nmtstp_link_get (NM_PLATFORM_GET, ifindex_bond0, IFACE_BOND0));
nmtstp_link_del (-1, ifindex_dummy0, IFACE_DUMMY0);
nmtstp_link_del (NULL, -1, ifindex_dummy0, IFACE_DUMMY0);
}
/*****************************************************************************/
@ -1818,7 +1818,7 @@ test_nl_bugs_spuroius_dellink (void)
nmtstp_run_command_check ("ip link add %s type bridge", IFACE_BRIDGE0);
ifindex_bridge0 = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, IFACE_BRIDGE0, NM_LINK_TYPE_BRIDGE, 100)->ifindex;
nmtstp_link_set_updown (-1, ifindex_bridge0, TRUE);
nmtstp_link_set_updown (NULL, -1, ifindex_bridge0, TRUE);
nmtstp_run_command_check ("ip link set %s master %s", IFACE_DUMMY0, IFACE_BRIDGE0);
NMTST_WAIT_ASSERT (100, {
@ -1850,8 +1850,8 @@ again:
goto again;
}
nmtstp_link_del (-1, ifindex_bridge0, IFACE_BRIDGE0);
nmtstp_link_del (-1, ifindex_dummy0, IFACE_DUMMY0);
nmtstp_link_del (NULL, -1, ifindex_bridge0, IFACE_BRIDGE0);
nmtstp_link_del (NULL, -1, ifindex_dummy0, IFACE_DUMMY0);
}
/******************************************************************/

View file

@ -82,50 +82,50 @@ test_ip4_route_metric0 (void)
int mss = 1000;
/* No routes initially */
nmtstp_assert_ip4_route_exists (FALSE, DEVICE_NAME, network, plen, 0);
nmtstp_assert_ip4_route_exists (FALSE, DEVICE_NAME, network, plen, metric);
nmtstp_assert_ip4_route_exists (NULL, FALSE, DEVICE_NAME, network, plen, 0);
nmtstp_assert_ip4_route_exists (NULL, FALSE, DEVICE_NAME, network, plen, metric);
/* 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));
accept_signal (route_added);
nmtstp_assert_ip4_route_exists (FALSE, DEVICE_NAME, network, plen, 0);
nmtstp_assert_ip4_route_exists (TRUE, DEVICE_NAME, network, plen, metric);
nmtstp_assert_ip4_route_exists (NULL, FALSE, DEVICE_NAME, network, plen, 0);
nmtstp_assert_ip4_route_exists (NULL, TRUE, DEVICE_NAME, network, plen, metric);
/* Deleting route with metric 0 does nothing */
g_assert (nm_platform_ip4_route_delete (NM_PLATFORM_GET, ifindex, network, plen, 0));
ensure_no_signal (route_removed);
nmtstp_assert_ip4_route_exists (FALSE, DEVICE_NAME, network, plen, 0);
nmtstp_assert_ip4_route_exists (TRUE, DEVICE_NAME, network, plen, metric);
nmtstp_assert_ip4_route_exists (NULL, FALSE, DEVICE_NAME, network, plen, 0);
nmtstp_assert_ip4_route_exists (NULL, TRUE, DEVICE_NAME, network, plen, metric);
/* 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));
accept_signal (route_added);
nmtstp_assert_ip4_route_exists (TRUE, DEVICE_NAME, network, plen, 0);
nmtstp_assert_ip4_route_exists (TRUE, DEVICE_NAME, network, plen, metric);
nmtstp_assert_ip4_route_exists (NULL, TRUE, DEVICE_NAME, network, plen, 0);
nmtstp_assert_ip4_route_exists (NULL, TRUE, DEVICE_NAME, network, plen, metric);
/* Delete route with metric 0 */
g_assert (nm_platform_ip4_route_delete (NM_PLATFORM_GET, ifindex, network, plen, 0));
accept_signal (route_removed);
nmtstp_assert_ip4_route_exists (FALSE, DEVICE_NAME, network, plen, 0);
nmtstp_assert_ip4_route_exists (TRUE, DEVICE_NAME, network, plen, metric);
nmtstp_assert_ip4_route_exists (NULL, FALSE, DEVICE_NAME, network, plen, 0);
nmtstp_assert_ip4_route_exists (NULL, TRUE, DEVICE_NAME, network, plen, metric);
/* 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));
ensure_no_signal (route_removed);
nmtstp_assert_ip4_route_exists (FALSE, DEVICE_NAME, network, plen, 0);
nmtstp_assert_ip4_route_exists (TRUE, DEVICE_NAME, network, plen, metric);
nmtstp_assert_ip4_route_exists (NULL, FALSE, DEVICE_NAME, network, plen, 0);
nmtstp_assert_ip4_route_exists (NULL, TRUE, DEVICE_NAME, network, plen, metric);
/* Delete the other route */
g_assert (nm_platform_ip4_route_delete (NM_PLATFORM_GET, ifindex, network, plen, metric));
accept_signal (route_removed);
nmtstp_assert_ip4_route_exists (FALSE, DEVICE_NAME, network, plen, 0);
nmtstp_assert_ip4_route_exists (FALSE, DEVICE_NAME, network, plen, metric);
nmtstp_assert_ip4_route_exists (NULL, FALSE, DEVICE_NAME, network, plen, 0);
nmtstp_assert_ip4_route_exists (NULL, FALSE, DEVICE_NAME, network, plen, metric);
free_signal (route_added);
free_signal (route_changed);
@ -156,9 +156,9 @@ test_ip4_route (void)
accept_signal (route_added);
/* Add route */
nmtstp_assert_ip4_route_exists (FALSE, DEVICE_NAME, network, plen, metric);
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 (TRUE, DEVICE_NAME, network, plen, metric);
nmtstp_assert_ip4_route_exists (NULL, TRUE, DEVICE_NAME, network, plen, metric);
accept_signal (route_added);
/* Add route again */
@ -166,9 +166,9 @@ test_ip4_route (void)
accept_signals (route_changed, 0, 1);
/* Add default route */
nmtstp_assert_ip4_route_exists (FALSE, DEVICE_NAME, 0, 0, metric);
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 (TRUE, DEVICE_NAME, 0, 0, metric);
nmtstp_assert_ip4_route_exists (NULL, TRUE, DEVICE_NAME, 0, 0, metric);
accept_signal (route_added);
/* Add default route again */
@ -208,7 +208,7 @@ test_ip4_route (void)
/* Remove route */
g_assert (nm_platform_ip4_route_delete (NM_PLATFORM_GET, ifindex, network, plen, metric));
nmtstp_assert_ip4_route_exists (FALSE, DEVICE_NAME, network, plen, metric);
nmtstp_assert_ip4_route_exists (NULL, FALSE, DEVICE_NAME, network, plen, metric);
accept_signal (route_removed);
/* Remove route again */