GitHub CI: update list of container images
[tinc] / test / ns-ping.test
1 #!/bin/sh
2
3 . "${0%/*}/testlib.sh"
4
5 # Skip this test if we aren't root or if "ip netns" does not exist
6
7 test "`id -u`" = "0" || exit 77
8 ip netns list || exit 77
9
10 # Initialize two nodes
11
12 $tinc $c1 <<EOF
13 init foo
14 set Subnet 192.168.1.1
15 set Interface ping.test1
16 set Port 32577
17 set Address localhost
18 set AutoConnect no
19 EOF
20
21 cat >$d1/tinc-up <<EOF
22 #!/bin/sh
23 ip netns add ping.test1
24 ip link set dev \$INTERFACE netns ping.test1
25 ip netns exec ping.test1 ip addr add 192.168.1.1/24 dev \$INTERFACE
26 ip netns exec ping.test1 ip link set \$INTERFACE up
27 EOF
28
29 $tinc $c2 <<EOF
30 init bar
31 set Subnet 192.168.1.2
32 set Interface ping.test2
33 set Port 32574
34 set AutoConnect no
35 EOF
36
37 cat >$d2/tinc-up <<EOF
38 #!/bin/sh
39 ip netns add ping.test2
40 ip link set dev \$INTERFACE netns ping.test2
41 ip netns exec ping.test2 ip addr add 192.168.1.2/24 dev \$INTERFACE
42 ip netns exec ping.test2 ip link set \$INTERFACE up
43 EOF
44
45 # Exchange configuration files
46
47 $tinc $c1 export | $tinc $c2 exchange | $tinc $c1 import
48
49 # Start tinc
50
51 $tinc $c1 start $r1
52 $tinc $c2 start $r2
53
54 sleep 1
55
56 # The nodes should not be able to ping each other if there is no connection
57
58 ip netns exec ping.test1 ping -W1 -c3 192.168.1.2 && exit 1
59
60 # After connecting they should be
61
62 $tinc $c2 add ConnectTo foo
63 sleep 1
64
65 ip netns exec ping.test1 ping -W1 -c3 192.168.1.2
66
67 # Clean up
68
69 $tinc $c2 stop
70 $tinc $c1 stop
71 ip netns del ping.test2
72 ip netns del ping.test1