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
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
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
37 $IP li add veth1
type veth peer name veth2
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
55 # Set veth2 down, which will put veth1 in NOCARRIER state
56 ip netns
exec ${peer} ip link
set veth2 down
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
82 # Set veth1 down, which will put veth0 in NOCARRIER state
83 ip netns
exec "${PEER_NS}" ip link
set veth1 down
87 ip neigh flush dev veth0
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
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
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
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
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
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
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"