Commit 1891cfe3 authored by Jakub Kicinski's avatar Jakub Kicinski
Browse files

Merge branch 'convert-net-selftests-to-run-in-unique-namespace-part-3'

Hangbin Liu says:

====================
Convert net selftests to run in unique namespace (Part 3)

Here is the 3rd part of converting net selftests to run in unique namespace.
This part converts all srv6 and fib tests.

Note that patch 06 is a fix for testing fib_nexthop_multiprefix.

Here is the part 1 link:
https://lore.kernel.org/netdev/20231202020110.362433-1-liuhangbin@gmail.com
And part 2 link:
https://lore.kernel.org/netdev/20231206070801.1691247-1-liuhangbin@gmail.com
====================

Link: https://lore.kernel.org/r/20231213060856.4030084-1-liuhangbin@gmail.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents fcb29877 b795db18
Loading
Loading
Loading
Loading
+13 −17
Original line number Diff line number Diff line
@@ -37,9 +37,7 @@
#
# server / client nomenclature relative to ns-A

# Kselftest framework requirement - SKIP code is 4.
ksft_skip=4

source lib.sh
VERBOSE=0

NSA_DEV=eth1
@@ -82,14 +80,6 @@ MCAST=ff02::1
NSA_LINKIP6=
NSB_LINKIP6=

NSA=ns-A
NSB=ns-B
NSC=ns-C

NSA_CMD="ip netns exec ${NSA}"
NSB_CMD="ip netns exec ${NSB}"
NSC_CMD="ip netns exec ${NSC}"

which ping6 > /dev/null 2>&1 && ping6=$(which ping6) || ping6=$(which ping)

# Check if FIPS mode is enabled
@@ -406,9 +396,6 @@ create_ns()
	local addr=$2
	local addr6=$3

	ip netns add ${ns}

	ip -netns ${ns} link set lo up
	if [ "${addr}" != "-" ]; then
		ip -netns ${ns} addr add dev lo ${addr}
	fi
@@ -467,13 +454,12 @@ cleanup()
		ip -netns ${NSA} link del dev ${NSA_DEV}

		ip netns pids ${NSA} | xargs kill 2>/dev/null
		ip netns del ${NSA}
		cleanup_ns ${NSA}
	fi

	ip netns pids ${NSB} | xargs kill 2>/dev/null
	ip netns del ${NSB}
	ip netns pids ${NSC} | xargs kill 2>/dev/null
	ip netns del ${NSC} >/dev/null 2>&1
	cleanup_ns ${NSB} ${NSC}
}

cleanup_vrf_dup()
@@ -487,6 +473,8 @@ setup_vrf_dup()
{
	# some VRF tests use ns-C which has the same config as
	# ns-B but for a device NOT in the VRF
	setup_ns NSC
	NSC_CMD="ip netns exec ${NSC}"
	create_ns ${NSC} "-" "-"
	connect_ns ${NSA} ${NSA_DEV2} ${NSA_IP}/24 ${NSA_IP6}/64 \
		   ${NSC} ${NSC_DEV} ${NSB_IP}/24 ${NSB_IP6}/64
@@ -503,6 +491,10 @@ setup()
	log_debug "Configuring network namespaces"
	set -e

	setup_ns NSA NSB
	NSA_CMD="ip netns exec ${NSA}"
	NSB_CMD="ip netns exec ${NSB}"

	create_ns ${NSA} ${NSA_LO_IP}/32 ${NSA_LO_IP6}/128
	create_ns ${NSB} ${NSB_LO_IP}/32 ${NSB_LO_IP6}/128
	connect_ns ${NSA} ${NSA_DEV} ${NSA_IP}/24 ${NSA_IP6}/64 \
@@ -545,6 +537,10 @@ setup_lla_only()
	log_debug "Configuring network namespaces"
	set -e

	setup_ns NSA NSB NSC
	NSA_CMD="ip netns exec ${NSA}"
	NSB_CMD="ip netns exec ${NSB}"
	NSC_CMD="ip netns exec ${NSC}"
	create_ns ${NSA} "-" "-"
	create_ns ${NSB} "-" "-"
	create_ns ${NSC} "-" "-"
+6 −5
Original line number Diff line number Diff line
@@ -5,6 +5,8 @@
# Check that flush works as expected with all the supported arguments and verify
# some combinations of arguments.

source lib.sh

FLUSH_BY_STATE_TESTS="
	vxlan_test_flush_by_permanent
	vxlan_test_flush_by_nopermanent
@@ -739,10 +741,9 @@ bridge_vxlan_test_flush()

setup()
{
	IP="ip -netns ns1"
	BRIDGE="bridge -netns ns1"

	ip netns add ns1
	setup_ns NS
	IP="ip -netns ${NS}"
	BRIDGE="bridge -netns ${NS}"

	$IP link add name vx10 type vxlan id 1000 dstport "$VXPORT"
	$IP link add name vx20 type vxlan id 2000 dstport "$VXPORT"
@@ -759,7 +760,7 @@ cleanup()
	$IP link del dev vx20
	$IP link del dev vx10

	ip netns del ns1
	cleanup_ns ${NS}
}

################################################################################
+3 −6
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@

# IPv4 and IPv6 onlink tests

source lib.sh
PAUSE_ON_FAIL=${PAUSE_ON_FAIL:=no}
VERBOSE=0

@@ -74,9 +75,6 @@ TEST_NET4IN6[2]=10.2.1.254
# mcast address
MCAST6=ff02::1


PEER_NS=bart
PEER_CMD="ip netns exec ${PEER_NS}"
VRF=lisa
VRF_TABLE=1101
PBR_TABLE=101
@@ -176,8 +174,7 @@ setup()
	set -e

	# create namespace
	ip netns add ${PEER_NS}
	ip -netns ${PEER_NS} li set lo up
	setup_ns PEER_NS

	# add vrf table
	ip li add ${VRF} type vrf table ${VRF_TABLE}
@@ -219,7 +216,7 @@ setup()
cleanup()
{
	# make sure we start from a clean slate
	ip netns del ${PEER_NS} 2>/dev/null
	cleanup_ns ${PEER_NS} 2>/dev/null
	for n in 1 3 5 7; do
		ip link del ${NETIFS[p${n}]} 2>/dev/null
	done
+48 −50
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@
#
# routing in h0 to hN is done with nexthop objects.

source lib.sh
PAUSE_ON_FAIL=no
VERBOSE=0

@@ -72,12 +73,6 @@ create_ns()
{
	local ns=${1}

	ip netns del ${ns} 2>/dev/null

	ip netns add ${ns}
	ip -netns ${ns} addr add 127.0.0.1/8 dev lo
	ip -netns ${ns} link set lo up

	ip netns exec ${ns} sysctl -q -w net.ipv6.conf.all.keep_addr_on_down=1
	case ${ns} in
	h*)
@@ -97,7 +92,13 @@ setup()

	#set -e

	for ns in h0 r1 h1 h2 h3
	setup_ns h0 r1 h1 h2 h3
	h[0]=$h0
	h[1]=$h1
	h[2]=$h2
	h[3]=$h3
	r[1]=$r1
	for ns in ${h[0]} ${r[1]} ${h[1]} ${h[2]} ${h[3]}
	do
		create_ns ${ns}
	done
@@ -108,35 +109,35 @@ setup()

	for i in 0 1 2 3
	do
		ip -netns h${i} li add eth0 type veth peer name r1h${i}
		ip -netns h${i} li set eth0 up
		ip -netns h${i} li set r1h${i} netns r1 name eth${i} up

		ip -netns h${i}    addr add dev eth0 172.16.10${i}.1/24
		ip -netns h${i} -6 addr add dev eth0 2001:db8:10${i}::1/64
		ip -netns r1    addr add dev eth${i} 172.16.10${i}.254/24
		ip -netns r1 -6 addr add dev eth${i} 2001:db8:10${i}::64/64
		ip -netns ${h[$i]} li add eth0 type veth peer name r1h${i}
		ip -netns ${h[$i]} li set eth0 up
		ip -netns ${h[$i]} li set r1h${i} netns ${r[1]} name eth${i} up

		ip -netns ${h[$i]}    addr add dev eth0 172.16.10${i}.1/24
		ip -netns ${h[$i]} -6 addr add dev eth0 2001:db8:10${i}::1/64
		ip -netns ${r[1]}    addr add dev eth${i} 172.16.10${i}.254/24
		ip -netns ${r[1]} -6 addr add dev eth${i} 2001:db8:10${i}::64/64
	done

	ip -netns h0 nexthop add id 4 via 172.16.100.254 dev eth0
	ip -netns h0 nexthop add id 6 via 2001:db8:100::64 dev eth0
	ip -netns ${h[0]} nexthop add id 4 via 172.16.100.254 dev eth0
	ip -netns ${h[0]} nexthop add id 6 via 2001:db8:100::64 dev eth0

	# routing from h0 to h1-h3 and back
	# routing from ${h[0]} to h1-h3 and back
	for i in 1 2 3
	do
		ip -netns h0    ro add 172.16.10${i}.0/24 nhid 4
		ip -netns h${i} ro add 172.16.100.0/24 via 172.16.10${i}.254
		ip -netns ${h[0]}    ro add 172.16.10${i}.0/24 nhid 4
		ip -netns ${h[$i]} ro add 172.16.100.0/24 via 172.16.10${i}.254

		ip -netns h0    -6 ro add 2001:db8:10${i}::/64 nhid 6
		ip -netns h${i} -6 ro add 2001:db8:100::/64 via 2001:db8:10${i}::64
		ip -netns ${h[0]}    -6 ro add 2001:db8:10${i}::/64 nhid 6
		ip -netns ${h[$i]} -6 ro add 2001:db8:100::/64 via 2001:db8:10${i}::64
	done

	if [ "$VERBOSE" = "1" ]; then
		echo
		echo "host 1 config"
		ip -netns h0 li sh
		ip -netns h0 ro sh
		ip -netns h0 -6 ro sh
		ip -netns ${h[0]} li sh
		ip -netns ${h[0]} ro sh
		ip -netns ${h[0]} -6 ro sh
	fi

	#set +e
@@ -144,10 +145,7 @@ setup()

cleanup()
{
	for n in h0 r1 h1 h2 h3
	do
		ip netns del ${n} 2>/dev/null
	done
	cleanup_all_ns
}

change_mtu()
@@ -156,7 +154,7 @@ change_mtu()
	local mtu=$2

	run_cmd ip -netns h${hostid} li set eth0 mtu ${mtu}
	run_cmd ip -netns r1 li set eth${hostid} mtu ${mtu}
	run_cmd ip -netns ${r1} li set eth${hostid} mtu ${mtu}
}

################################################################################
@@ -168,23 +166,23 @@ validate_v4_exception()
	local mtu=$2
	local ping_sz=$3
	local dst="172.16.10${i}.1"
	local h0=172.16.100.1
	local r1=172.16.100.254
	local h0_ip=172.16.100.1
	local r1_ip=172.16.100.254
	local rc

	if [ ${ping_sz} != "0" ]; then
		run_cmd ip netns exec h0 ping -s ${ping_sz} -c5 -w5 ${dst}
		run_cmd ip netns exec ${h0} ping -s ${ping_sz} -c5 -w5 ${dst}
	fi

	if [ "$VERBOSE" = "1" ]; then
		echo "Route get"
		ip -netns h0 ro get ${dst}
		ip -netns ${h0} ro get ${dst}
		echo "Searching for:"
		echo "    cache .* mtu ${mtu}"
		echo
	fi

	ip -netns h0 ro get ${dst} | \
	ip -netns ${h0} ro get ${dst} | \
	grep -q "cache .* mtu ${mtu}"
	rc=$?

@@ -197,24 +195,24 @@ validate_v6_exception()
	local mtu=$2
	local ping_sz=$3
	local dst="2001:db8:10${i}::1"
	local h0=2001:db8:100::1
	local r1=2001:db8:100::64
	local h0_ip=2001:db8:100::1
	local r1_ip=2001:db8:100::64
	local rc

	if [ ${ping_sz} != "0" ]; then
		run_cmd ip netns exec h0 ${ping6} -s ${ping_sz} -c5 -w5 ${dst}
		run_cmd ip netns exec ${h0} ${ping6} -s ${ping_sz} -c5 -w5 ${dst}
	fi

	if [ "$VERBOSE" = "1" ]; then
		echo "Route get"
		ip -netns h0 -6 ro get ${dst}
		ip -netns ${h0} -6 ro get ${dst}
		echo "Searching for:"
		echo "    ${dst} from :: via ${r1} dev eth0 src ${h0} .* mtu ${mtu}"
		echo "    ${dst}.* via ${r1_ip} dev eth0 src ${h0_ip} .* mtu ${mtu}"
		echo
	fi

	ip -netns h0 -6 ro get ${dst} | \
	grep -q "${dst} from :: via ${r1} dev eth0 src ${h0} .* mtu ${mtu}"
	ip -netns ${h0} -6 ro get ${dst} | \
	grep -q "${dst}.* via ${r1_ip} dev eth0 src ${h0_ip} .* mtu ${mtu}"
	rc=$?

	log_test $rc 0 "IPv6: host 0 to host ${i}, mtu ${mtu}"
@@ -242,11 +240,11 @@ for i in 1 2 3
do
	# generate a cached route per-cpu
	for c in ${cpus}; do
		run_cmd taskset -c ${c} ip netns exec h0 ping -c1 -w1 172.16.10${i}.1
		[ $? -ne 0 ] && printf "\nERROR: ping to h${i} failed\n" && ret=1
		run_cmd taskset -c ${c} ip netns exec ${h0} ping -c1 -w1 172.16.10${i}.1
		[ $? -ne 0 ] && printf "\nERROR: ping to ${h[$i]} failed\n" && ret=1

		run_cmd taskset -c ${c} ip netns exec h0 ${ping6} -c1 -w1 2001:db8:10${i}::1
		[ $? -ne 0 ] && printf "\nERROR: ping6 to h${i} failed\n" && ret=1
		run_cmd taskset -c ${c} ip netns exec ${h0} ${ping6} -c1 -w1 2001:db8:10${i}::1
		[ $? -ne 0 ] && printf "\nERROR: ping6 to ${h[$i]} failed\n" && ret=1

		[ $ret -ne 0 ] && break
	done
@@ -282,11 +280,11 @@ if [ $ret -eq 0 ]; then
	validate_v6_exception 3 1400 0

	# targeted deletes to trigger cleanup paths in kernel
	ip -netns h0 ro del 172.16.102.0/24 nhid 4
	ip -netns h0 -6 ro del 2001:db8:102::/64 nhid 6
	ip -netns ${h0} ro del 172.16.102.0/24 nhid 4
	ip -netns ${h0} -6 ro del 2001:db8:102::/64 nhid 6

	ip -netns h0 nexthop del id 4
	ip -netns h0 nexthop del id 6
	ip -netns ${h0} nexthop del id 4
	ip -netns ${h0} nexthop del id 6
fi

cleanup
+15 −19
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@
#            veth0 <---|---> veth1
# Validate source address selection for route without gateway

source lib.sh
PAUSE_ON_FAIL=no
VERBOSE=0
ret=0
@@ -64,35 +65,31 @@ run_cmd()
# config
setup()
{
	ip netns add h1
	ip -n h1 link set lo up
	ip netns add h2
	ip -n h2 link set lo up
	setup_ns h1 h2

	# Add a fake eth0 to support an ip address
	ip -n h1 link add name eth0 type dummy
	ip -n h1 link set eth0 up
	ip -n h1 address add 192.168.0.1/24 dev eth0
	ip -n $h1 link add name eth0 type dummy
	ip -n $h1 link set eth0 up
	ip -n $h1 address add 192.168.0.1/24 dev eth0

	# Configure veths (same @mac, arp off)
	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 add name veth0 type veth peer name veth1 netns $h2
	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
	ip -n h2 address add 192.168.1.1/32 dev veth1
	ip -n h2 route add default dev veth1
	ip -n $h2 address add 192.168.1.1/32 dev veth1
	ip -n $h2 route add default dev veth1

	# Add a nexthop without @gw and use it in a route
	ip -n h1 nexthop add id 1 dev veth0
	ip -n h1 route add 192.168.1.1 nhid 1
	ip -n $h1 nexthop add id 1 dev veth0
	ip -n $h1 route add 192.168.1.1 nhid 1
}

cleanup()
{
	ip netns del h1 2>/dev/null
	ip netns del h2 2>/dev/null
	cleanup_ns $h1 $h2
}

trap cleanup EXIT
@@ -108,12 +105,11 @@ do
	esac
done

cleanup
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"
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"

exit $ret
Loading