drm/bridge: adv7511: Switch to atomic operations
[drm/drm-misc.git] / tools / testing / selftests / net / arp_ndisc_evict_nocarrier.sh
blob92eb880c52f2808541770fffae8b65ae2bc2078c
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
4 # Tests sysctl options {arp,ndisc}_evict_nocarrier={0,1}
6 # Create a veth pair and set IPs/routes on both. Then ping to establish
7 # an entry in the ARP/ND table. Depending on the test set sysctl option to
8 # 1 or 0. Set remote veth down which will cause local veth to go into a no
9 # carrier state. Depending on the test check the ARP/ND table:
11 # {arp,ndisc}_evict_nocarrier=1 should contain no ARP/ND after no carrier
12 # {arp,ndisc}_evict_nocarrer=0 should still contain the single ARP/ND entry
15 source lib.sh
17 readonly V4_ADDR0=10.0.10.1
18 readonly V4_ADDR1=10.0.10.2
19 readonly V6_ADDR0=2001:db8:91::1
20 readonly V6_ADDR1=2001:db8:91::2
21 nsid=100
22 ret=0
24 cleanup_v6()
26 cleanup_ns ${me} ${peer}
28 sysctl -w net.ipv6.conf.veth1.ndisc_evict_nocarrier=1 >/dev/null 2>&1
29 sysctl -w net.ipv6.conf.all.ndisc_evict_nocarrier=1 >/dev/null 2>&1
32 setup_v6() {
33 setup_ns me peer
35 IP="ip -netns ${me}"
37 $IP li add veth1 type veth peer name veth2
38 $IP li set veth1 up
39 $IP -6 addr add $V6_ADDR0/64 dev veth1 nodad
40 $IP li set veth2 netns ${peer} up
41 ip -netns ${peer} -6 addr add $V6_ADDR1/64 dev veth2 nodad
43 ip netns exec ${me} sysctl -w $1 >/dev/null 2>&1
45 # Establish an ND cache entry
46 ip netns exec ${me} ping -6 -c1 -Iveth1 $V6_ADDR1 >/dev/null 2>&1
47 # Should have the veth1 entry in ND table
48 ip netns exec ${me} ip -6 neigh get $V6_ADDR1 dev veth1 >/dev/null 2>&1
49 if [ $? -ne 0 ]; then
50 cleanup_v6
51 echo "failed"
52 exit 1
55 # Set veth2 down, which will put veth1 in NOCARRIER state
56 ip netns exec ${peer} ip link set veth2 down
59 setup_v4() {
60 setup_ns PEER_NS
61 ip link add name veth0 type veth peer name veth1
62 ip link set dev veth0 up
63 ip link set dev veth1 netns "${PEER_NS}"
64 ip netns exec "${PEER_NS}" ip link set dev veth1 up
65 ip addr add $V4_ADDR0/24 dev veth0
66 ip netns exec "${PEER_NS}" ip addr add $V4_ADDR1/24 dev veth1
67 ip netns exec ${PEER_NS} ip route add default via $V4_ADDR1 dev veth1
68 ip route add default via $V4_ADDR0 dev veth0
70 sysctl -w "$1" >/dev/null 2>&1
72 # Establish an ARP cache entry
73 ping -c1 -I veth0 $V4_ADDR1 -q >/dev/null 2>&1
74 # Should have the veth1 entry in ARP table
75 ip neigh get $V4_ADDR1 dev veth0 >/dev/null 2>&1
76 if [ $? -ne 0 ]; then
77 cleanup_v4
78 echo "failed"
79 exit 1
82 # Set veth1 down, which will put veth0 in NOCARRIER state
83 ip netns exec "${PEER_NS}" ip link set veth1 down
86 cleanup_v4() {
87 ip neigh flush dev veth0
88 ip link del veth0
89 cleanup_ns $PEER_NS
91 sysctl -w net.ipv4.conf.veth0.arp_evict_nocarrier=1 >/dev/null 2>&1
92 sysctl -w net.ipv4.conf.all.arp_evict_nocarrier=1 >/dev/null 2>&1
95 # Run test when arp_evict_nocarrier = 1 (default).
96 run_arp_evict_nocarrier_enabled() {
97 echo "run arp_evict_nocarrier=1 test"
98 setup_v4 "net.ipv4.conf.veth0.arp_evict_nocarrier=1"
100 # ARP table should be empty
101 ip neigh get $V4_ADDR1 dev veth0 >/dev/null 2>&1
103 if [ $? -eq 0 ];then
104 echo "failed"
105 ret=1
106 else
107 echo "ok"
110 cleanup_v4
113 # Run test when arp_evict_nocarrier = 0
114 run_arp_evict_nocarrier_disabled() {
115 echo "run arp_evict_nocarrier=0 test"
116 setup_v4 "net.ipv4.conf.veth0.arp_evict_nocarrier=0"
118 # ARP table should still contain the entry
119 ip neigh get $V4_ADDR1 dev veth0 >/dev/null 2>&1
121 if [ $? -eq 0 ];then
122 echo "ok"
123 else
124 echo "failed"
125 ret=1
128 cleanup_v4
131 run_arp_evict_nocarrier_disabled_all() {
132 echo "run all.arp_evict_nocarrier=0 test"
133 setup_v4 "net.ipv4.conf.all.arp_evict_nocarrier=0"
135 # ARP table should still contain the entry
136 ip neigh get $V4_ADDR1 dev veth0 >/dev/null 2>&1
138 if [ $? -eq 0 ];then
139 echo "ok"
140 else
141 echo "failed"
144 cleanup_v4
147 run_ndisc_evict_nocarrier_enabled() {
148 echo "run ndisc_evict_nocarrier=1 test"
150 setup_v6 "net.ipv6.conf.veth1.ndisc_evict_nocarrier=1"
152 ip netns exec ${me} ip -6 neigh get $V6_ADDR1 dev veth1 >/dev/null 2>&1
154 if [ $? -eq 0 ];then
155 echo "failed"
156 ret=1
157 else
158 echo "ok"
161 cleanup_v6
164 run_ndisc_evict_nocarrier_disabled() {
165 echo "run ndisc_evict_nocarrier=0 test"
167 setup_v6 "net.ipv6.conf.veth1.ndisc_evict_nocarrier=0"
169 ip netns exec ${me} ip -6 neigh get $V6_ADDR1 dev veth1 >/dev/null 2>&1
171 if [ $? -eq 0 ];then
172 echo "ok"
173 else
174 echo "failed"
175 ret=1
178 cleanup_v6
181 run_ndisc_evict_nocarrier_disabled_all() {
182 echo "run all.ndisc_evict_nocarrier=0 test"
184 setup_v6 "net.ipv6.conf.all.ndisc_evict_nocarrier=0"
186 ip netns exec ${me} ip -6 neigh get $V6_ADDR1 dev veth1 >/dev/null 2>&1
188 if [ $? -eq 0 ];then
189 echo "ok"
190 else
191 echo "failed"
192 ret=1
195 cleanup_v6
198 run_all_tests() {
199 run_arp_evict_nocarrier_enabled
200 run_arp_evict_nocarrier_disabled
201 run_arp_evict_nocarrier_disabled_all
202 run_ndisc_evict_nocarrier_enabled
203 run_ndisc_evict_nocarrier_disabled
204 run_ndisc_evict_nocarrier_disabled_all
207 if [ "$(id -u)" -ne 0 ];then
208 echo "SKIP: Need root privileges"
209 exit $ksft_skip;
212 run_all_tests
213 exit $ret