[CRIU] [PATCH v2 3/3] test: add bind() test to bridge
Tycho Andersen
tycho.andersen at canonical.com
Tue Nov 24 13:28:18 PST 2015
This tests c/r of the link-local scope-id argument to bind().
v2: sort the interfaces so diff works
Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
---
test/zdtm/live/static/bridge.c | 33 +++++++++++++++++++++++++++++++--
test/zdtm/live/static/bridge.desc | 2 +-
2 files changed, 32 insertions(+), 3 deletions(-)
diff --git a/test/zdtm/live/static/bridge.c b/test/zdtm/live/static/bridge.c
index 0aca514..983c262 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,6 +25,10 @@ int add_bridge(void)
if (system("ip addr add 10.0.55.55/32 dev " BRIDGE_NAME))
return -1;
+ /* 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"))
return -1;
@@ -43,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.
@@ -55,7 +84,7 @@ int main(int argc, char **argv)
* (I got this race with zdtm.py, but not with zdtm.sh; not quite sure
* what the environment difference is/was.)
*/
- if (system("ip addr list dev " BRIDGE_NAME " | grep inet > bridge.dump.test")) {
+ if (system("ip addr list dev " BRIDGE_NAME " | grep inet | sort > bridge.dump.test")) {
pr_perror("can't save net config");
fail("Can't save net config");
goto out;
@@ -64,7 +93,7 @@ int main(int argc, char **argv)
test_daemon();
test_waitsig();
- if (system("ip addr list dev " BRIDGE_NAME " | grep inet > bridge.rst.test")) {
+ if (system("ip addr list dev " BRIDGE_NAME " | grep inet | sort > bridge.rst.test")) {
fail("Can't get net config");
goto out;
}
diff --git a/test/zdtm/live/static/bridge.desc b/test/zdtm/live/static/bridge.desc
index bfbd0d9..8af1df7 100644
--- a/test/zdtm/live/static/bridge.desc
+++ b/test/zdtm/live/static/bridge.desc
@@ -1 +1 @@
-{'flavor': 'ns uns', 'deps': [ '/bin/sh', '/bin/grep', '/sbin/ip', '/usr/bin/diff'], 'flags': 'suid'}
+{'flavor': 'ns uns', 'deps': [ '/bin/sh', '/usr/bin/sort', '/bin/grep', '/sbin/ip', '/usr/bin/diff'], 'flags': 'suid'}
--
2.6.2
More information about the CRIU
mailing list