8e10d11ed064b331725ff12ce46490899aea5011
[tinc] / test / ns-ping.test
1 #!/bin/sh
2
3 . ./testlib.sh
4
5 require_root "$0" "$@"
6 test -e /dev/net/tun || exit $EXIT_SKIP_TEST
7 ip netns list || exit $EXIT_SKIP_TEST
8
9 ip_foo=192.168.1.1
10 ip_bar=192.168.1.2
11 mask=24
12
13 echo [STEP] Create network namespaces
14
15 ip netns add ping.test1
16 ip netns add ping.test2
17
18 cleanup_hook() {
19   ip netns del ping.test1
20   ip netns del ping.test2
21 }
22
23 echo [STEP] Initialize two nodes
24
25 tinc foo <<EOF
26 init foo
27 set Subnet $ip_foo
28 set Interface ping.test1
29 set Port 30090
30 set Address localhost
31 set AutoConnect no
32 EOF
33
34 # shellcheck disable=SC2016
35 create_script foo tinc-up "
36   ip link set dev \$INTERFACE netns ping.test1
37   ip netns exec ping.test1 ip addr add $ip_foo/$mask dev \$INTERFACE
38   ip netns exec ping.test1 ip link set \$INTERFACE up
39 "
40
41 tinc bar <<EOF
42 init bar
43 set Subnet $ip_bar
44 set Interface ping.test2
45 set Port 30091
46 set AutoConnect no
47 EOF
48
49 # shellcheck disable=SC2016
50 create_script bar tinc-up "
51   ip link set dev \$INTERFACE netns ping.test2
52   ip netns exec ping.test2 ip addr add $ip_bar/$mask dev \$INTERFACE
53   ip netns exec ping.test2 ip link set \$INTERFACE up
54 "
55
56 echo [STEP] Exchange configuration files
57
58 tinc foo export | tinc bar exchange | tinc foo import
59
60 echo [STEP] Start tinc
61
62 start_tinc foo
63 start_tinc bar
64
65 wait_script foo tinc-up
66 wait_script bar tinc-up
67
68 echo [STEP] The nodes should not be able to ping each other if there is no connection
69
70 must_fail ip netns exec ping.test1 ping -W1 -c3 $ip_bar
71
72 echo [STEP] After connecting they should be
73
74 create_script bar hosts/foo-up
75
76 tinc bar add ConnectTo foo
77 wait_script bar hosts/foo-up
78
79 ip netns exec ping.test1 ping -W1 -c3 $ip_bar