Commit d2168ea7 authored by Hangbin Liu's avatar Hangbin Liu Committed by Jakub Kicinski

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

Here is the test result after conversion.

 ]# ./fib_nexthop_nongw.sh
 TEST: nexthop: get route with nexthop without gw                    [ OK ]
 TEST: nexthop: ping through nexthop without gw                      [ OK ]
Acked-by: default avatarDavid Ahern <dsahern@kernel.org>
Signed-off-by: default avatarHangbin Liu <liuhangbin@gmail.com>
Link: https://lore.kernel.org/r/20231213060856.4030084-9-liuhangbin@gmail.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 5ae89fe4
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
# veth0 <---|---> veth1 # veth0 <---|---> veth1
# Validate source address selection for route without gateway # Validate source address selection for route without gateway
source lib.sh
PAUSE_ON_FAIL=no PAUSE_ON_FAIL=no
VERBOSE=0 VERBOSE=0
ret=0 ret=0
...@@ -64,35 +65,31 @@ run_cmd() ...@@ -64,35 +65,31 @@ run_cmd()
# config # config
setup() setup()
{ {
ip netns add h1 setup_ns h1 h2
ip -n h1 link set lo up
ip netns add h2
ip -n h2 link set lo up
# Add a fake eth0 to support an ip address # Add a fake eth0 to support an ip address
ip -n h1 link add name eth0 type dummy ip -n $h1 link add name eth0 type dummy
ip -n h1 link set eth0 up ip -n $h1 link set eth0 up
ip -n h1 address add 192.168.0.1/24 dev eth0 ip -n $h1 address add 192.168.0.1/24 dev eth0
# Configure veths (same @mac, arp off) # Configure veths (same @mac, arp off)
ip -n h1 link add name veth0 type veth peer name veth1 netns h2 ip -n $h1 link add name veth0 type veth peer name veth1 netns $h2
ip -n h1 link set veth0 up ip -n $h1 link set veth0 up
ip -n h2 link set veth1 up ip -n $h2 link set veth1 up
# Configure @IP in the peer netns # Configure @IP in the peer netns
ip -n h2 address add 192.168.1.1/32 dev veth1 ip -n $h2 address add 192.168.1.1/32 dev veth1
ip -n h2 route add default dev veth1 ip -n $h2 route add default dev veth1
# Add a nexthop without @gw and use it in a route # Add a nexthop without @gw and use it in a route
ip -n h1 nexthop add id 1 dev veth0 ip -n $h1 nexthop add id 1 dev veth0
ip -n h1 route add 192.168.1.1 nhid 1 ip -n $h1 route add 192.168.1.1 nhid 1
} }
cleanup() cleanup()
{ {
ip netns del h1 2>/dev/null cleanup_ns $h1 $h2
ip netns del h2 2>/dev/null
} }
trap cleanup EXIT trap cleanup EXIT
...@@ -108,12 +105,11 @@ do ...@@ -108,12 +105,11 @@ do
esac esac
done done
cleanup
setup setup
run_cmd ip -netns h1 route get 192.168.1.1 run_cmd ip -netns $h1 route get 192.168.1.1
log_test $? 0 "nexthop: get route with nexthop without gw" log_test $? 0 "nexthop: get route with nexthop without gw"
run_cmd ip netns exec h1 ping -c1 192.168.1.1 run_cmd ip netns exec $h1 ping -c1 192.168.1.1
log_test $? 0 "nexthop: ping through nexthop without gw" log_test $? 0 "nexthop: ping through nexthop without gw"
exit $ret exit $ret
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment