[CRIU] [PATCH 5/5] test: add bind() test to bridge

Tycho Andersen tycho.andersen at canonical.com
Mon Nov 23 12:55:28 PST 2015


This tests c/r of the link-local scope-id argument to bind().

Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
---
 test/zdtm/live/static/bridge.c | 30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/test/zdtm/live/static/bridge.c b/test/zdtm/live/static/bridge.c
index 6e9d5a0..2fc8aa3 100644
--- a/test/zdtm/live/static/bridge.c
+++ b/test/zdtm/live/static/bridge.c
@@ -8,6 +8,8 @@
 #include <sys/mount.h>
 #include <linux/limits.h>
 #include <signal.h>
+#include <arpa/inet.h>
+#include <net/if.h>
 #include "zdtmtst.h"
 
 const char *test_doc	= "check that empty bridges are c/r'd correctly";
@@ -23,7 +25,8 @@ int add_bridge(void)
 	if (system("ip addr add 10.0.55.55/32 dev " BRIDGE_NAME))
 		return -1;
 
-	if (system("ip addr add 1234:4567::1/64 nodad dev " BRIDGE_NAME))
+	/* use a link local address so we can test scope_id change */
+	if (system("ip addr add fe80:4567::1/64 nodad dev " BRIDGE_NAME))
 		return -1;
 
 	if (system("ip link set " BRIDGE_NAME " up"))
@@ -46,11 +49,34 @@ int del_bridge(void)
 int main(int argc, char **argv)
 {
 	int ret = 1;
+	struct sockaddr_in6 addr;
+	int sk;
+
 	test_init(argc, argv);
 
 	if (add_bridge() < 0)
 		return 1;
 
+	sk = socket(AF_INET6, SOCK_DGRAM, 0);
+	if (sk < 0) {
+		fail("can't get socket");
+		goto out;
+	}
+
+	memset(&addr, 0, sizeof(addr));
+	addr.sin6_port = htons(0);
+	addr.sin6_family = AF_INET6;
+	if (inet_pton(AF_INET6, "fe80:4567::1", &addr.sin6_addr) < 0) {
+		fail("can't convert inet6 addr");
+		goto out;
+	}
+	addr.sin6_scope_id = if_nametoindex(BRIDGE_NAME);
+
+	if (bind(sk, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
+		fail("can't bind");
+		goto out;
+	}
+
 	/* Here, we grep for inet because some of the IPV6 DAD stuff can be
 	 * racy, and all we really care about is that the bridge got restored
 	 * with the right MAC, since we know DAD will succeed eventually.
@@ -68,6 +94,8 @@ int main(int argc, char **argv)
 		goto out;
 	}
 
+
+
 	test_daemon();
 	test_waitsig();
 
-- 
2.6.2



More information about the CRIU mailing list