}
gboolean
-nmtstp_wait_for_signal (guint timeout_ms)
+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;
+
data.loop = g_main_loop_new (NULL, FALSE);
- id_link = g_signal_connect (NM_PLATFORM_GET, NM_PLATFORM_SIGNAL_LINK_CHANGED, G_CALLBACK (_wait_for_signal_cb), &data);
- id_ip4_address = g_signal_connect (NM_PLATFORM_GET, NM_PLATFORM_SIGNAL_IP4_ADDRESS_CHANGED, G_CALLBACK (_wait_for_signal_cb), &data);
- id_ip6_address = g_signal_connect (NM_PLATFORM_GET, NM_PLATFORM_SIGNAL_IP6_ADDRESS_CHANGED, G_CALLBACK (_wait_for_signal_cb), &data);
- id_ip4_route = g_signal_connect (NM_PLATFORM_GET, NM_PLATFORM_SIGNAL_IP4_ROUTE_CHANGED, G_CALLBACK (_wait_for_signal_cb), &data);
- id_ip6_route = g_signal_connect (NM_PLATFORM_GET, NM_PLATFORM_SIGNAL_IP6_ROUTE_CHANGED, G_CALLBACK (_wait_for_signal_cb), &data);
+ id_link = g_signal_connect (platform, NM_PLATFORM_SIGNAL_LINK_CHANGED, G_CALLBACK (_wait_for_signal_cb), &data);
+ id_ip4_address = g_signal_connect (platform, NM_PLATFORM_SIGNAL_IP4_ADDRESS_CHANGED, G_CALLBACK (_wait_for_signal_cb), &data);
+ id_ip6_address = g_signal_connect (platform, NM_PLATFORM_SIGNAL_IP6_ADDRESS_CHANGED, G_CALLBACK (_wait_for_signal_cb), &data);
+ 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 != 0)
data.id = g_timeout_add (timeout_ms, _wait_for_signal_timeout, &data);
g_main_loop_run (data.loop);
- g_assert (nm_clear_g_signal_handler (NM_PLATFORM_GET, &id_link));
- g_assert (nm_clear_g_signal_handler (NM_PLATFORM_GET, &id_ip4_address));
- g_assert (nm_clear_g_signal_handler (NM_PLATFORM_GET, &id_ip6_address));
- g_assert (nm_clear_g_signal_handler (NM_PLATFORM_GET, &id_ip4_route));
- g_assert (nm_clear_g_signal_handler (NM_PLATFORM_GET, &id_ip6_route));
+ g_assert (nm_clear_g_signal_handler (platform, &id_link));
+ g_assert (nm_clear_g_signal_handler (platform, &id_ip4_address));
+ g_assert (nm_clear_g_signal_handler (platform, &id_ip6_address));
+ g_assert (nm_clear_g_signal_handler (platform, &id_ip4_route));
+ g_assert (nm_clear_g_signal_handler (platform, &id_ip6_route));
if (nm_clear_g_source (&data.id))
g_assert (timeout_ms != 0 && !data.timeout);
}
gboolean
-nmtstp_wait_for_signal_until (gint64 until_ms)
+nmtstp_wait_for_signal_until (NMPlatform *platform, gint64 until_ms)
{
gint64 now;
if (until_ms < now)
return FALSE;
- if (nmtstp_wait_for_signal (MAX (1, until_ms - now)))
+ if (nmtstp_wait_for_signal (platform, MAX (1, until_ms - now)))
return TRUE;
}
}
const NMPlatformLink *
-nmtstp_wait_for_link (const char *ifname, NMLinkType expected_link_type, guint timeout_ms)
+nmtstp_wait_for_link (NMPlatform *platform, const char *ifname, NMLinkType expected_link_type, guint timeout_ms)
{
- return nmtstp_wait_for_link_until (ifname, expected_link_type, nm_utils_get_monotonic_timestamp_ms () + timeout_ms);
+ return nmtstp_wait_for_link_until (platform, ifname, expected_link_type, nm_utils_get_monotonic_timestamp_ms () + timeout_ms);
}
const NMPlatformLink *
-nmtstp_wait_for_link_until (const char *ifname, NMLinkType expected_link_type, gint64 until_ms)
+nmtstp_wait_for_link_until (NMPlatform *platform, const char *ifname, NMLinkType expected_link_type, gint64 until_ms)
{
const NMPlatformLink *plink;
gint64 now;
while (TRUE) {
now = nm_utils_get_monotonic_timestamp_ms ();
- plink = nm_platform_link_get_by_ifname (NM_PLATFORM_GET, ifname);
+ plink = nm_platform_link_get_by_ifname (platform ?: NM_PLATFORM_GET, ifname);
if ( plink
&& (expected_link_type == NM_LINK_TYPE_NONE || plink->type == expected_link_type))
return plink;
if (until_ms < now)
return NULL;
- nmtstp_wait_for_signal (MAX (1, until_ms - now));
+ nmtstp_wait_for_signal (platform, MAX (1, until_ms - now));
}
}
const NMPlatformLink *
-nmtstp_assert_wait_for_link (const char *ifname, NMLinkType expected_link_type, guint timeout_ms)
+nmtstp_assert_wait_for_link (NMPlatform *platform, const char *ifname, NMLinkType expected_link_type, guint timeout_ms)
{
- return nmtstp_assert_wait_for_link_until (ifname, expected_link_type, nm_utils_get_monotonic_timestamp_ms () + timeout_ms);
+ return nmtstp_assert_wait_for_link_until (platform, ifname, expected_link_type, nm_utils_get_monotonic_timestamp_ms () + timeout_ms);
}
const NMPlatformLink *
-nmtstp_assert_wait_for_link_until (const char *ifname, NMLinkType expected_link_type, gint64 until_ms)
+nmtstp_assert_wait_for_link_until (NMPlatform *platform, const char *ifname, NMLinkType expected_link_type, gint64 until_ms)
{
const NMPlatformLink *plink;
- plink = nmtstp_wait_for_link_until (ifname, expected_link_type, until_ms);
+ plink = nmtstp_wait_for_link_until (platform, ifname, expected_link_type, until_ms);
g_assert (plink);
return plink;
}
/* for internal command, we expect not to reach this line.*/
g_assert (external_command);
- g_assert (nmtstp_wait_for_signal_until (end_time));
+ g_assert (nmtstp_wait_for_signal_until (NM_PLATFORM_GET, end_time));
} while (TRUE);
}
-#define _assert_pllink(success, pllink, name, type) \
+#define _assert_pllink(platform, success, pllink, name, type) \
G_STMT_START { \
const NMPlatformLink *_pllink = (pllink); \
\
if ((success)) { \
g_assert (_pllink); \
- g_assert (_pllink == nmtstp_link_get_typed (_pllink->ifindex, (name), (type))); \
+ g_assert (_pllink == nmtstp_link_get_typed (platform, _pllink->ifindex, (name), (type))); \
} else { \
g_assert (!_pllink); \
- g_assert (!nmtstp_link_get (0, (name))); \
+ g_assert (!nmtstp_link_get (platform, 0, (name))); \
} \
} G_STMT_END
success = !nmtstp_run_command ("ip link add %s type dummy",
name);
if (success)
- pllink = nmtstp_assert_wait_for_link (name, NM_LINK_TYPE_DUMMY, 100);
+ pllink = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, name, NM_LINK_TYPE_DUMMY, 100);
} else
success = nm_platform_link_dummy_add (NM_PLATFORM_GET, name, &pllink) == NM_PLATFORM_ERROR_SUCCESS;
g_assert (success);
- _assert_pllink (success, pllink, name, NM_LINK_TYPE_DUMMY);
+ _assert_pllink (NM_PLATFORM_GET, success, pllink, name, NM_LINK_TYPE_DUMMY);
return pllink;
}
lnk->tos,
lnk->path_mtu_discovery ? "pmtudisc" : "nopmtudisc");
if (success)
- pllink = nmtstp_assert_wait_for_link (name, NM_LINK_TYPE_GRE, 100);
+ pllink = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, name, NM_LINK_TYPE_GRE, 100);
} else
success = nm_platform_link_gre_add (NM_PLATFORM_GET, name, lnk, &pllink) == NM_PLATFORM_ERROR_SUCCESS;
- _assert_pllink (success, pllink, name, NM_LINK_TYPE_GRE);
+ _assert_pllink (NM_PLATFORM_GET, success, pllink, name, NM_LINK_TYPE_GRE);
return pllink;
}
lnk->encap_limit,
lnk->flow_label);
if (success)
- pllink = nmtstp_assert_wait_for_link (name, NM_LINK_TYPE_IP6TNL, 100);
+ pllink = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, name, NM_LINK_TYPE_IP6TNL, 100);
} else
success = nm_platform_link_ip6tnl_add (NM_PLATFORM_GET, name, lnk, &pllink) == NM_PLATFORM_ERROR_SUCCESS;
- _assert_pllink (success, pllink, name, NM_LINK_TYPE_IP6TNL);
+ _assert_pllink (NM_PLATFORM_GET, success, pllink, name, NM_LINK_TYPE_IP6TNL);
return pllink;
}
lnk->tos,
lnk->path_mtu_discovery ? "pmtudisc" : "nopmtudisc");
if (success)
- pllink = nmtstp_assert_wait_for_link (name, NM_LINK_TYPE_IPIP, 100);
+ pllink = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, name, NM_LINK_TYPE_IPIP, 100);
} else
success = nm_platform_link_ipip_add (NM_PLATFORM_GET, name, lnk, &pllink) == NM_PLATFORM_ERROR_SUCCESS;
- _assert_pllink (success, pllink, name, NM_LINK_TYPE_IPIP);
+ _assert_pllink (NM_PLATFORM_GET, success, pllink, name, NM_LINK_TYPE_IPIP);
return pllink;
}
modes[lnk->mode],
lnk->no_promisc ? "nopromisc" : "");
if (success)
- pllink = nmtstp_assert_wait_for_link (name, link_type, 100);
+ pllink = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, name, link_type, 100);
} else
success = nm_platform_link_macvlan_add (NM_PLATFORM_GET, name, parent, lnk, &pllink) == NM_PLATFORM_ERROR_SUCCESS;
- _assert_pllink (success, pllink, name, link_type);
+ _assert_pllink (NM_PLATFORM_GET, success, pllink, name, link_type);
return pllink;
}
lnk->tos,
lnk->path_mtu_discovery ? "pmtudisc" : "nopmtudisc");
if (success)
- pllink = nmtstp_assert_wait_for_link (name, NM_LINK_TYPE_SIT, 100);
+ pllink = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, name, NM_LINK_TYPE_SIT, 100);
} else
success = nm_platform_link_sit_add (NM_PLATFORM_GET, name, lnk, &pllink) == NM_PLATFORM_ERROR_SUCCESS;
- _assert_pllink (success, pllink, name, NM_LINK_TYPE_SIT);
+ _assert_pllink (NM_PLATFORM_GET, success, pllink, name, NM_LINK_TYPE_SIT);
return pllink;
}
/* 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 (name, NM_LINK_TYPE_VXLAN, 100);
+ pllink = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, name, NM_LINK_TYPE_VXLAN, 100);
else
_LOGI ("Adding vxlan device via iproute2 failed. Assume iproute2 is not up to the task.");
}
/* for internal command, we expect not to reach this line.*/
g_assert (external_command);
- g_assert (nmtstp_wait_for_signal_until (end_time));
+ g_assert (nmtstp_wait_for_signal_until (NM_PLATFORM_GET, end_time));
} while (TRUE);
}
}
const NMPlatformLink *
-nmtstp_link_get_typed (int ifindex,
+nmtstp_link_get_typed (NMPlatform *platform,
+ int ifindex,
const char *name,
NMLinkType link_type)
{
const NMPlatformLink *pllink = NULL;
+ if (!platform)
+ platform = NM_PLATFORM_GET;
+
if (ifindex > 0) {
- pllink = nm_platform_link_get (NM_PLATFORM_GET, ifindex);
+ pllink = nm_platform_link_get (platform, ifindex);
if (pllink) {
g_assert_cmpint (pllink->ifindex, ==, ifindex);
g_assert_cmpstr (name, ==, pllink->name);
} else {
if (name)
- g_assert (!nm_platform_link_get_by_ifname (NM_PLATFORM_GET, name));
+ g_assert (!nm_platform_link_get_by_ifname (platform, name));
}
} else {
g_assert (name);
- pllink = nm_platform_link_get_by_ifname (NM_PLATFORM_GET, name);
+ pllink = nm_platform_link_get_by_ifname (platform, name);
if (pllink)
g_assert_cmpstr (name, ==, pllink->name);
}
const NMPlatformLink *
-nmtstp_link_get (int ifindex,
+nmtstp_link_get (NMPlatform *platform,
+ int ifindex,
const char *name)
{
- return nmtstp_link_get_typed (ifindex, name, NM_LINK_TYPE_NONE);
+ return nmtstp_link_get_typed (platform, ifindex, name, NM_LINK_TYPE_NONE);
}
void
gboolean success;
gs_free char *name_copy = NULL;
- pllink = nmtstp_link_get (ifindex, name);
+ pllink = nmtstp_link_get (NM_PLATFORM_GET, ifindex, name);
g_assert (pllink);
/* for internal command, we expect not to reach this line.*/
g_assert (external_command);
- g_assert (nmtstp_wait_for_signal_until (end_time));
+ g_assert (nmtstp_wait_for_signal_until (NM_PLATFORM_GET, end_time));
} while (TRUE);
}
/* for internal command, we expect not to reach this line.*/
g_assert (external_command);
- g_assert (nmtstp_wait_for_signal_until (end_time));
+ g_assert (nmtstp_wait_for_signal_until (NM_PLATFORM_GET, end_time));
} while (TRUE);
}
const gboolean ext = test_data->external_command;
nmtstp_run_command_check ("ip link add %s type dummy", PARENT_NAME);
- ifindex_parent = nmtstp_assert_wait_for_link (PARENT_NAME, NM_LINK_TYPE_DUMMY, 100)->ifindex;
+ ifindex_parent = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, PARENT_NAME, NM_LINK_TYPE_DUMMY, 100)->ifindex;
switch (test_data->link_type) {
case NM_LINK_TYPE_GRE: {
g_assert_not_reached ();
}
- ifindex = nmtstp_assert_wait_for_link (DEVICE_NAME, test_data->link_type, 100)->ifindex;
+ 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);
int ifindex, ifindex_parent;
nmtstp_run_command_check ("ip link add %s type dummy", PARENT_NAME);
- ifindex_parent = nmtstp_assert_wait_for_link (PARENT_NAME, NM_LINK_TYPE_DUMMY, 100)->ifindex;
+ ifindex_parent = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, PARENT_NAME, NM_LINK_TYPE_DUMMY, 100)->ifindex;
nmtstp_run_command_check ("ip link add name %s link %s type vlan id 1245", DEVICE_NAME, PARENT_NAME);
- ifindex = nmtstp_assert_wait_for_link (DEVICE_NAME, NM_LINK_TYPE_VLAN, 100)->ifindex;
+ ifindex = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, DEVICE_NAME, NM_LINK_TYPE_VLAN, 100)->ifindex;
/* ingress-qos-map */
/* create veth pair. */
nmtstp_run_command_check ("ip link add dev %s type veth peer name %s", IFACE_VETH0, IFACE_VETH1);
- ifindex_veth0 = nmtstp_assert_wait_for_link (IFACE_VETH0, NM_LINK_TYPE_VETH, 100)->ifindex;
- ifindex_veth1 = nmtstp_assert_wait_for_link (IFACE_VETH1, NM_LINK_TYPE_VETH, 100)->ifindex;
+ ifindex_veth0 = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, IFACE_VETH0, NM_LINK_TYPE_VETH, 100)->ifindex;
+ ifindex_veth1 = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, IFACE_VETH1, NM_LINK_TYPE_VETH, 100)->ifindex;
/* assert that nm_platform_link_veth_get_properties() returns the expected peer ifindexes. */
g_assert (nm_platform_link_veth_get_properties (NM_PLATFORM_GET, ifindex_veth0, &i));
nmtstp_run_command_check ("ip link set %s netns %ld", IFACE_VETH1, (long) nmtstp_namespace_handle_get_pid (ns_handle));
NMTST_WAIT_ASSERT (100, {
- nmtstp_wait_for_signal (50);
+ nmtstp_wait_for_signal (NM_PLATFORM_GET, 50);
nm_platform_process_events (NM_PLATFORM_GET);
pllink_veth1 = nm_platform_link_get (NM_PLATFORM_GET, ifindex_veth1);
out:
nmtstp_link_del (-1, ifindex_veth0, IFACE_VETH0);
- g_assert (!nmtstp_link_get (ifindex_veth0, IFACE_VETH0));
- g_assert (!nmtstp_link_get (ifindex_veth1, IFACE_VETH1));
+ 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);
}
/* see https://bugzilla.redhat.com/show_bug.cgi?id=1285719 */
nmtstp_run_command_check ("ip link add %s type dummy", IFACE_DUMMY0);
- ifindex_dummy0 = nmtstp_assert_wait_for_link (IFACE_DUMMY0, NM_LINK_TYPE_DUMMY, 100)->ifindex;
+ ifindex_dummy0 = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, IFACE_DUMMY0, NM_LINK_TYPE_DUMMY, 100)->ifindex;
nmtstp_run_command_check ("ip link add %s type bond", IFACE_BOND0);
- ifindex_bond0 = nmtstp_assert_wait_for_link (IFACE_BOND0, NM_LINK_TYPE_BOND, 100)->ifindex;
+ 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_run_command_check ("ip link set %s master %s", IFACE_DUMMY0, IFACE_BOND0);
NMTST_WAIT_ASSERT (100, {
- nmtstp_wait_for_signal (50);
+ nmtstp_wait_for_signal (NM_PLATFORM_GET, 50);
pllink = nm_platform_link_get (NM_PLATFORM_GET, ifindex_dummy0);
g_assert (pllink);
nmtstp_run_command_check ("ip link del %s", IFACE_BOND0);
wait_for_settle = TRUE;
- nmtstp_wait_for_signal (50);
+ nmtstp_wait_for_signal (NM_PLATFORM_GET, 50);
again:
nm_platform_process_events (NM_PLATFORM_GET);
pllink = nm_platform_link_get (NM_PLATFORM_GET, ifindex_bond0);
if (wait_for_settle) {
wait_for_settle = FALSE;
- NMTST_WAIT (300, { nmtstp_wait_for_signal (50); });
+ NMTST_WAIT (300, { nmtstp_wait_for_signal (NM_PLATFORM_GET, 50); });
goto again;
}
- g_assert (!nmtstp_link_get (ifindex_bond0, IFACE_BOND0));
+ g_assert (!nmtstp_link_get (NM_PLATFORM_GET, ifindex_bond0, IFACE_BOND0));
nmtstp_link_del (-1, ifindex_dummy0, IFACE_DUMMY0);
}
/* see https://bugzilla.redhat.com/show_bug.cgi?id=1285719 */
nmtstp_run_command_check ("ip link add %s type dummy", IFACE_DUMMY0);
- ifindex_dummy0 = nmtstp_assert_wait_for_link (IFACE_DUMMY0, NM_LINK_TYPE_DUMMY, 100)->ifindex;
+ ifindex_dummy0 = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, IFACE_DUMMY0, NM_LINK_TYPE_DUMMY, 100)->ifindex;
nmtstp_run_command_check ("ip link add %s type bridge", IFACE_BRIDGE0);
- ifindex_bridge0 = nmtstp_assert_wait_for_link (IFACE_BRIDGE0, NM_LINK_TYPE_BRIDGE, 100)->ifindex;
+ 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_run_command_check ("ip link set %s master %s", IFACE_DUMMY0, IFACE_BRIDGE0);
NMTST_WAIT_ASSERT (100, {
- nmtstp_wait_for_signal (50);
+ nmtstp_wait_for_signal (NM_PLATFORM_GET, 50);
pllink = nm_platform_link_get (NM_PLATFORM_GET, ifindex_dummy0);
g_assert (pllink);
nmtstp_run_command_check ("ip link set %s nomaster", IFACE_DUMMY0);
wait_for_settle = TRUE;
- nmtstp_wait_for_signal (50);
+ nmtstp_wait_for_signal (NM_PLATFORM_GET, 50);
again:
nm_platform_process_events (NM_PLATFORM_GET);
pllink = nm_platform_link_get (NM_PLATFORM_GET, ifindex_bridge0);
if (wait_for_settle) {
wait_for_settle = FALSE;
- NMTST_WAIT (300, { nmtstp_wait_for_signal (50); });
+ NMTST_WAIT (300, { nmtstp_wait_for_signal (NM_PLATFORM_GET, 50); });
goto again;
}