File: netns.c

package info (click to toggle)
criu 4.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 11,584 kB
  • sloc: ansic: 139,280; python: 7,484; sh: 3,824; java: 2,799; makefile: 2,659; asm: 1,137; perl: 206; xml: 117; exp: 45
file content (55 lines) | stat: -rw-r--r-- 1,180 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <string.h>
#include <unistd.h>
#include <stdlib.h>

#include "zdtmtst.h"

const char *test_doc = "Check that network environment (links, addresses and routes) are preserved";
const char *test_author = "Pavel Emelianov <xemul@parallels.com>";

int main(int argc, char **argv)
{
	test_init(argc, argv);

	if (system("ip link set lo up")) {
		fail("Can't set lo up");
		return -1;
	}

	if (system("ip addr add 1.2.3.4 dev lo")) {
		fail("Can't add addr on lo");
		return -1;
	}

	if (system("ip route add 1.2.3.5 dev lo")) {
		fail("Can't add route via lo");
		return -1;
	}

	if (system("ip route add 1.2.3.6 via 1.2.3.5")) {
		fail("Can't add route via lo (2)");
		return -1;
	}

	if (system("ip link > netns.dump.test && ip addr >> netns.dump.test && ip route >> netns.dump.test")) {
		sleep(1000);
		fail("Can't save net config");
		return -1;
	}

	test_daemon();
	test_waitsig();

	if (system("ip link > netns.rst.test && ip addr >> netns.rst.test && ip route >> netns.rst.test")) {
		fail("Can't get net config");
		return -1;
	}

	if (system("diff netns.rst.test netns.dump.test")) {
		fail("Net config differs after restore");
		return -1;
	}

	pass();
	return 0;
}