summary refs log tree commit diff
path: root/src/platform/tests/test-common.c
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2018-05-11 22:08:45 +0200
committerMichael Biebl <biebl@debian.org>2018-05-11 22:08:45 +0200
commitee9c73a923909e23a649407be77e25235d769e25 (patch)
treee21c923621fa278e737da693df9eb60ea31a6067 /src/platform/tests/test-common.c
parentf60117b41d5433be1b4a96d82cd11d0c3dce9b63 (diff)
New upstream version 1.10.8 upstream/1.10.8
Diffstat (limited to 'src/platform/tests/test-common.c')
-rw-r--r--src/platform/tests/test-common.c116
1 files changed, 23 insertions, 93 deletions
diff --git a/src/platform/tests/test-common.c b/src/platform/tests/test-common.c
index 7885c083..d56e681e 100644
--- a/src/platform/tests/test-common.c
+++ b/src/platform/tests/test-common.c
@@ -1,5 +1,6 @@
 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
-/*
+/* NetworkManager audit support
+ *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
@@ -23,7 +24,6 @@
 #include <sched.h>
 #include <sys/wait.h>
 #include <fcntl.h>
-#include <linux/if_tun.h>
 
 #include "test-common.h"
 
@@ -628,10 +628,7 @@ 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)
 {
-	return nmtstp_wait_for_link_until (platform, ifname, expected_link_type,
-	                                   timeout_ms
-	                                     ? nm_utils_get_monotonic_timestamp_ms () + timeout_ms
-	                                     : 0);
+	return nmtstp_wait_for_link_until (platform, ifname, expected_link_type, nm_utils_get_monotonic_timestamp_ms () + timeout_ms);
 }
 
 const NMPlatformLink *
@@ -639,7 +636,6 @@ nmtstp_wait_for_link_until (NMPlatform *platform, const char *ifname, NMLinkType
 {
 	const NMPlatformLink *plink;
 	gint64 now;
-	gboolean waited_once = FALSE;
 
 	_init_platform (&platform, FALSE);
 
@@ -651,24 +647,29 @@ nmtstp_wait_for_link_until (NMPlatform *platform, const char *ifname, NMLinkType
 		    && (expected_link_type == NM_LINK_TYPE_NONE || plink->type == expected_link_type))
 			return plink;
 
-		if (until_ms == 0) {
-			/* don't wait, don't even poll the socket. */
-			return NULL;
-		}
-
-		if (   waited_once
-		    && until_ms < now) {
-			/* timeout reached (+ we already waited for a signal at least once). */
+		if (until_ms < now)
 			return NULL;
-		}
 
-		waited_once = TRUE;
-		/* regardless of whether timeout is already reached, we poll the netlink
-		 * socket a bit. */
 		nmtstp_wait_for_signal (platform, until_ms - now);
 	}
 }
 
+const NMPlatformLink *
+nmtstp_assert_wait_for_link (NMPlatform *platform, const char *ifname, NMLinkType expected_link_type, guint 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 (NMPlatform *platform, const char *ifname, NMLinkType expected_link_type, gint64 until_ms)
+{
+	const NMPlatformLink *plink;
+
+	plink = nmtstp_wait_for_link_until (platform, ifname, expected_link_type, until_ms);
+	g_assert (plink);
+	return plink;
+}
+
 /*****************************************************************************/
 
 int
@@ -1283,10 +1284,6 @@ nmtstp_link_ip6tnl_add (NMPlatform *platform,
 	const NMPlatformLink *pllink = NULL;
 	gboolean success;
 	char buffer[INET6_ADDRSTRLEN];
-	char encap[20];
-	char tclass[20];
-	gboolean encap_ignore;
-	gboolean tclass_inherit;
 
 	g_assert (nm_utils_is_valid_iface_name (name, NULL));
 
@@ -1312,18 +1309,15 @@ nmtstp_link_ip6tnl_add (NMPlatform *platform,
 			g_assert_not_reached ();
 		}
 
-		encap_ignore = NM_FLAGS_HAS (lnk->flags, IP6_TNL_F_IGN_ENCAP_LIMIT);
-		tclass_inherit = NM_FLAGS_HAS (lnk->flags, IP6_TNL_F_USE_ORIG_TCLASS);
-
-		success = !nmtstp_run_command ("ip -6 tunnel add %s mode %s %s local %s remote %s ttl %u tclass %s encaplimit %s flowlabel %x",
+		success = !nmtstp_run_command ("ip -6 tunnel add %s mode %s %s local %s remote %s ttl %u tclass %02x encaplimit %u flowlabel %x",
 		                                name,
 		                                mode,
 		                                dev,
 		                                nm_utils_inet6_ntop (&lnk->local, NULL),
 		                                nm_utils_inet6_ntop (&lnk->remote, buffer),
 		                                lnk->ttl,
-		                                tclass_inherit ? "inherit" : nm_sprintf_buf (tclass, "%02x", lnk->tclass),
-		                                encap_ignore ? "none" : nm_sprintf_buf (encap, "%u", lnk->encap_limit),
+		                                lnk->tclass,
+		                                lnk->encap_limit,
 		                                lnk->flow_label);
 		if (success)
 			pllink = nmtstp_assert_wait_for_link (platform, name, NM_LINK_TYPE_IP6TNL, 100);
@@ -1469,70 +1463,6 @@ nmtstp_link_sit_add (NMPlatform *platform,
 }
 
 const NMPlatformLink *
-nmtstp_link_tun_add (NMPlatform *platform,
-                     gboolean external_command,
-                     const char *name,
-                     const NMPlatformLnkTun *lnk,
-                     int *out_fd)
-{
-	const NMPlatformLink *pllink = NULL;
-	NMPlatformError plerr;
-	int err;
-
-	g_assert (nm_utils_is_valid_iface_name (name, NULL));
-	g_assert (lnk);
-	g_assert (NM_IN_SET (lnk->type, IFF_TUN, IFF_TAP));
-	g_assert (!out_fd || *out_fd == -1);
-
-	if (!lnk->persist) {
-		/* ip tuntap does not support non-persistent devices.
-		 *
-		 * Add this device only via NMPlatform. */
-		if (external_command == -1)
-			external_command = FALSE;
-	}
-
-	external_command = nmtstp_run_command_check_external (external_command);
-
-	_init_platform (&platform, external_command);
-
-	if (external_command) {
-		g_assert (lnk->persist);
-
-		err = nmtstp_run_command ("ip tuntap add"
-		                          " mode %s"
-		                          "%s" /* user */
-		                          "%s" /* group */
-		                          "%s" /* pi */
-		                          "%s" /* vnet_hdr */
-		                          "%s" /* multi_queue */
-		                          " name %s",
-		                          lnk->type == IFF_TUN ? "tun" : "tap",
-		                          lnk->owner_valid ? nm_sprintf_bufa (100, " user %u", (guint) lnk->owner) : "",
-		                          lnk->group_valid ? nm_sprintf_bufa (100, " group %u", (guint) lnk->group) : "",
-		                          lnk->pi ? " pi" : "",
-		                          lnk->vnet_hdr ? " vnet_hdr" : "",
-		                          lnk->multi_queue ? " multi_queue" : "",
-		                          name);
-		/* Older versions of iproute2 don't support adding  devices.
-		 * On failure, fallback to using platform code. */
-		if (err == 0)
-			pllink = nmtstp_assert_wait_for_link (platform, name, NM_LINK_TYPE_TUN, 100);
-		else
-			g_error ("failure to add tun/tap device via ip-route");
-	} else {
-		g_assert (lnk->persist || out_fd);
-		plerr = nm_platform_link_tun_add (platform, name, lnk, &pllink, out_fd);
-		g_assert_cmpint (plerr, ==, NM_PLATFORM_ERROR_SUCCESS);
-	}
-
-	g_assert (pllink);
-	g_assert_cmpint (pllink->type, ==, NM_LINK_TYPE_TUN);
-	g_assert_cmpstr (pllink->name, ==, name);
-	return pllink;
-}
-
-const NMPlatformLink *
 nmtstp_link_vxlan_add (NMPlatform *platform,
                        gboolean external_command,
                        const char *name,