selftests/net: convert unicast_extensions.sh to run it in unique namespace
[ Upstream commit 0f4765d0b48d90ede9788c7edb2e072eee20f88e ] Here is the test result after conversion. # ./unicast_extensions.sh /usr/bin/which: no nettest in (/root/.local/bin:/root/bin:/usr/share/Modules/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin) ########################################################################### Unicast address extensions tests (behavior of reserved IPv4 addresses) ########################################################################### TEST: assign and ping within 240/4 (1 of 2) (is allowed) [ OK ] TEST: assign and ping within 240/4 (2 of 2) (is allowed) [ OK ] TEST: assign and ping within 0/8 (1 of 2) (is allowed) [ OK ] ... TEST: assign and ping class D address (is forbidden) [ OK ] TEST: routing using class D (is forbidden) [ OK ] TEST: routing using 127/8 (is forbidden) [ OK ] Acked-by: David Ahern <dsahern@kernel.org> Signed-off-by: Hangbin Liu <liuhangbin@gmail.com> Signed-off-by: Paolo Abeni <pabeni@redhat.com> Stable-dep-of: e71e016ad0f6 ("selftests: net: fix tcp listener handling in pmtu.sh") Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
104ab0e821
commit
7be281a411
@ -28,8 +28,7 @@
|
||||
# These tests provide an easy way to flip the expected result of any
|
||||
# of these behaviors for testing kernel patches that change them.
|
||||
|
||||
# Kselftest framework requirement - SKIP code is 4.
|
||||
ksft_skip=4
|
||||
source ./lib.sh
|
||||
|
||||
# nettest can be run from PATH or from same directory as this selftest
|
||||
if ! which nettest >/dev/null; then
|
||||
@ -61,20 +60,20 @@ _do_segmenttest(){
|
||||
# foo --- bar
|
||||
# Arguments: ip_a ip_b prefix_length test_description
|
||||
#
|
||||
# Caller must set up foo-ns and bar-ns namespaces
|
||||
# Caller must set up $foo_ns and $bar_ns namespaces
|
||||
# containing linked veth devices foo and bar,
|
||||
# respectively.
|
||||
|
||||
ip -n foo-ns address add $1/$3 dev foo || return 1
|
||||
ip -n foo-ns link set foo up || return 1
|
||||
ip -n bar-ns address add $2/$3 dev bar || return 1
|
||||
ip -n bar-ns link set bar up || return 1
|
||||
ip -n $foo_ns address add $1/$3 dev foo || return 1
|
||||
ip -n $foo_ns link set foo up || return 1
|
||||
ip -n $bar_ns address add $2/$3 dev bar || return 1
|
||||
ip -n $bar_ns link set bar up || return 1
|
||||
|
||||
ip netns exec foo-ns timeout 2 ping -c 1 $2 || return 1
|
||||
ip netns exec bar-ns timeout 2 ping -c 1 $1 || return 1
|
||||
ip netns exec $foo_ns timeout 2 ping -c 1 $2 || return 1
|
||||
ip netns exec $bar_ns timeout 2 ping -c 1 $1 || return 1
|
||||
|
||||
nettest -B -N bar-ns -O foo-ns -r $1 || return 1
|
||||
nettest -B -N foo-ns -O bar-ns -r $2 || return 1
|
||||
nettest -B -N $bar_ns -O $foo_ns -r $1 || return 1
|
||||
nettest -B -N $foo_ns -O $bar_ns -r $2 || return 1
|
||||
|
||||
return 0
|
||||
}
|
||||
@ -88,31 +87,31 @@ _do_route_test(){
|
||||
# Arguments: foo_ip foo1_ip bar1_ip bar_ip prefix_len test_description
|
||||
# Displays test result and returns success or failure.
|
||||
|
||||
# Caller must set up foo-ns, bar-ns, and router-ns
|
||||
# Caller must set up $foo_ns, $bar_ns, and $router_ns
|
||||
# containing linked veth devices foo-foo1, bar1-bar
|
||||
# (foo in foo-ns, foo1 and bar1 in router-ns, and
|
||||
# bar in bar-ns).
|
||||
# (foo in $foo_ns, foo1 and bar1 in $router_ns, and
|
||||
# bar in $bar_ns).
|
||||
|
||||
ip -n foo-ns address add $1/$5 dev foo || return 1
|
||||
ip -n foo-ns link set foo up || return 1
|
||||
ip -n foo-ns route add default via $2 || return 1
|
||||
ip -n bar-ns address add $4/$5 dev bar || return 1
|
||||
ip -n bar-ns link set bar up || return 1
|
||||
ip -n bar-ns route add default via $3 || return 1
|
||||
ip -n router-ns address add $2/$5 dev foo1 || return 1
|
||||
ip -n router-ns link set foo1 up || return 1
|
||||
ip -n router-ns address add $3/$5 dev bar1 || return 1
|
||||
ip -n router-ns link set bar1 up || return 1
|
||||
ip -n $foo_ns address add $1/$5 dev foo || return 1
|
||||
ip -n $foo_ns link set foo up || return 1
|
||||
ip -n $foo_ns route add default via $2 || return 1
|
||||
ip -n $bar_ns address add $4/$5 dev bar || return 1
|
||||
ip -n $bar_ns link set bar up || return 1
|
||||
ip -n $bar_ns route add default via $3 || return 1
|
||||
ip -n $router_ns address add $2/$5 dev foo1 || return 1
|
||||
ip -n $router_ns link set foo1 up || return 1
|
||||
ip -n $router_ns address add $3/$5 dev bar1 || return 1
|
||||
ip -n $router_ns link set bar1 up || return 1
|
||||
|
||||
echo 1 | ip netns exec router-ns tee /proc/sys/net/ipv4/ip_forward
|
||||
echo 1 | ip netns exec $router_ns tee /proc/sys/net/ipv4/ip_forward
|
||||
|
||||
ip netns exec foo-ns timeout 2 ping -c 1 $2 || return 1
|
||||
ip netns exec foo-ns timeout 2 ping -c 1 $4 || return 1
|
||||
ip netns exec bar-ns timeout 2 ping -c 1 $3 || return 1
|
||||
ip netns exec bar-ns timeout 2 ping -c 1 $1 || return 1
|
||||
ip netns exec $foo_ns timeout 2 ping -c 1 $2 || return 1
|
||||
ip netns exec $foo_ns timeout 2 ping -c 1 $4 || return 1
|
||||
ip netns exec $bar_ns timeout 2 ping -c 1 $3 || return 1
|
||||
ip netns exec $bar_ns timeout 2 ping -c 1 $1 || return 1
|
||||
|
||||
nettest -B -N bar-ns -O foo-ns -r $1 || return 1
|
||||
nettest -B -N foo-ns -O bar-ns -r $4 || return 1
|
||||
nettest -B -N $bar_ns -O $foo_ns -r $1 || return 1
|
||||
nettest -B -N $foo_ns -O $bar_ns -r $4 || return 1
|
||||
|
||||
return 0
|
||||
}
|
||||
@ -121,17 +120,15 @@ segmenttest(){
|
||||
# Sets up veth link and tries to connect over it.
|
||||
# Arguments: ip_a ip_b prefix_len test_description
|
||||
hide_output
|
||||
ip netns add foo-ns
|
||||
ip netns add bar-ns
|
||||
ip link add foo netns foo-ns type veth peer name bar netns bar-ns
|
||||
setup_ns foo_ns bar_ns
|
||||
ip link add foo netns $foo_ns type veth peer name bar netns $bar_ns
|
||||
|
||||
test_result=0
|
||||
_do_segmenttest "$@" || test_result=1
|
||||
|
||||
ip netns pids foo-ns | xargs -r kill -9
|
||||
ip netns pids bar-ns | xargs -r kill -9
|
||||
ip netns del foo-ns
|
||||
ip netns del bar-ns
|
||||
ip netns pids $foo_ns | xargs -r kill -9
|
||||
ip netns pids $bar_ns | xargs -r kill -9
|
||||
cleanup_ns $foo_ns $bar_ns
|
||||
show_output
|
||||
|
||||
# inverted tests will expect failure instead of success
|
||||
@ -147,21 +144,17 @@ route_test(){
|
||||
# Returns success or failure.
|
||||
|
||||
hide_output
|
||||
ip netns add foo-ns
|
||||
ip netns add bar-ns
|
||||
ip netns add router-ns
|
||||
ip link add foo netns foo-ns type veth peer name foo1 netns router-ns
|
||||
ip link add bar netns bar-ns type veth peer name bar1 netns router-ns
|
||||
setup_ns foo_ns bar_ns router_ns
|
||||
ip link add foo netns $foo_ns type veth peer name foo1 netns $router_ns
|
||||
ip link add bar netns $bar_ns type veth peer name bar1 netns $router_ns
|
||||
|
||||
test_result=0
|
||||
_do_route_test "$@" || test_result=1
|
||||
|
||||
ip netns pids foo-ns | xargs -r kill -9
|
||||
ip netns pids bar-ns | xargs -r kill -9
|
||||
ip netns pids router-ns | xargs -r kill -9
|
||||
ip netns del foo-ns
|
||||
ip netns del bar-ns
|
||||
ip netns del router-ns
|
||||
ip netns pids $foo_ns | xargs -r kill -9
|
||||
ip netns pids $bar_ns | xargs -r kill -9
|
||||
ip netns pids $router_ns | xargs -r kill -9
|
||||
cleanup_ns $foo_ns $bar_ns $router_ns
|
||||
|
||||
show_output
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user