Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/net: convert arp_ndisc_evict_nocarrier.sh to run it in unique namespace

Here is the test result after conversion.

]# ./arp_ndisc_evict_nocarrier.sh
run arp_evict_nocarrier=1 test
ok
run arp_evict_nocarrier=0 test
ok
run all.arp_evict_nocarrier=0 test
ok
run ndisc_evict_nocarrier=1 test
ok
run ndisc_evict_nocarrier=0 test
ok
run all.ndisc_evict_nocarrier=0 test
ok

Acked-by: David Ahern <dsahern@kernel.org>
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

authored by

Hangbin Liu and committed by
Paolo Abeni
64227511 25ae948b

+16 -30
+16 -30
tools/testing/selftests/net/arp_ndisc_evict_nocarrier.sh
··· 12 12 # {arp,ndisc}_evict_nocarrer=0 should still contain the single ARP/ND entry 13 13 # 14 14 15 - readonly PEER_NS="ns-peer-$(mktemp -u XXXXXX)" 15 + source lib.sh 16 + 16 17 readonly V4_ADDR0=10.0.10.1 17 18 readonly V4_ADDR1=10.0.10.2 18 19 readonly V6_ADDR0=2001:db8:91::1 ··· 23 22 24 23 cleanup_v6() 25 24 { 26 - ip netns del me 27 - ip netns del peer 25 + cleanup_ns ${me} ${peer} 28 26 29 27 sysctl -w net.ipv6.conf.veth1.ndisc_evict_nocarrier=1 >/dev/null 2>&1 30 28 sysctl -w net.ipv6.conf.all.ndisc_evict_nocarrier=1 >/dev/null 2>&1 31 29 } 32 30 33 - create_ns() 34 - { 35 - local n=${1} 36 - 37 - ip netns del ${n} 2>/dev/null 38 - 39 - ip netns add ${n} 40 - ip netns set ${n} $((nsid++)) 41 - ip -netns ${n} link set lo up 42 - } 43 - 44 - 45 31 setup_v6() { 46 - create_ns me 47 - create_ns peer 32 + setup_ns me peer 48 33 49 - IP="ip -netns me" 34 + IP="ip -netns ${me}" 50 35 51 36 $IP li add veth1 type veth peer name veth2 52 37 $IP li set veth1 up 53 38 $IP -6 addr add $V6_ADDR0/64 dev veth1 nodad 54 - $IP li set veth2 netns peer up 55 - ip -netns peer -6 addr add $V6_ADDR1/64 dev veth2 nodad 39 + $IP li set veth2 netns ${peer} up 40 + ip -netns ${peer} -6 addr add $V6_ADDR1/64 dev veth2 nodad 56 41 57 - ip netns exec me sysctl -w $1 >/dev/null 2>&1 42 + ip netns exec ${me} sysctl -w $1 >/dev/null 2>&1 58 43 59 44 # Establish an ND cache entry 60 - ip netns exec me ping -6 -c1 -Iveth1 $V6_ADDR1 >/dev/null 2>&1 45 + ip netns exec ${me} ping -6 -c1 -Iveth1 $V6_ADDR1 >/dev/null 2>&1 61 46 # Should have the veth1 entry in ND table 62 - ip netns exec me ip -6 neigh get $V6_ADDR1 dev veth1 >/dev/null 2>&1 47 + ip netns exec ${me} ip -6 neigh get $V6_ADDR1 dev veth1 >/dev/null 2>&1 63 48 if [ $? -ne 0 ]; then 64 49 cleanup_v6 65 50 echo "failed" ··· 53 66 fi 54 67 55 68 # Set veth2 down, which will put veth1 in NOCARRIER state 56 - ip netns exec peer ip link set veth2 down 69 + ip netns exec ${peer} ip link set veth2 down 57 70 } 58 71 59 72 setup_v4() { 60 - ip netns add "${PEER_NS}" 73 + setup_ns PEER_NS 61 74 ip link add name veth0 type veth peer name veth1 62 75 ip link set dev veth0 up 63 76 ip link set dev veth1 netns "${PEER_NS}" ··· 86 99 cleanup_v4() { 87 100 ip neigh flush dev veth0 88 101 ip link del veth0 89 - local -r ns="$(ip netns list|grep $PEER_NS)" 90 - [ -n "$ns" ] && ip netns del $ns 2>/dev/null 102 + cleanup_ns $PEER_NS 91 103 92 104 sysctl -w net.ipv4.conf.veth0.arp_evict_nocarrier=1 >/dev/null 2>&1 93 105 sysctl -w net.ipv4.conf.all.arp_evict_nocarrier=1 >/dev/null 2>&1 ··· 149 163 150 164 setup_v6 "net.ipv6.conf.veth1.ndisc_evict_nocarrier=1" 151 165 152 - ip netns exec me ip -6 neigh get $V6_ADDR1 dev veth1 >/dev/null 2>&1 166 + ip netns exec ${me} ip -6 neigh get $V6_ADDR1 dev veth1 >/dev/null 2>&1 153 167 154 168 if [ $? -eq 0 ];then 155 169 echo "failed" ··· 166 180 167 181 setup_v6 "net.ipv6.conf.veth1.ndisc_evict_nocarrier=0" 168 182 169 - ip netns exec me ip -6 neigh get $V6_ADDR1 dev veth1 >/dev/null 2>&1 183 + ip netns exec ${me} ip -6 neigh get $V6_ADDR1 dev veth1 >/dev/null 2>&1 170 184 171 185 if [ $? -eq 0 ];then 172 186 echo "ok" ··· 183 197 184 198 setup_v6 "net.ipv6.conf.all.ndisc_evict_nocarrier=0" 185 199 186 - ip netns exec me ip -6 neigh get $V6_ADDR1 dev veth1 >/dev/null 2>&1 200 + ip netns exec ${me} ip -6 neigh get $V6_ADDR1 dev veth1 >/dev/null 2>&1 187 201 188 202 if [ $? -eq 0 ];then 189 203 echo "ok"