Commit 36b0bdb6 authored by David S. Miller's avatar David S. Miller

Merge branch 'net-selftests-unique-namespace'

Hangbin Liu says:

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

Here is the 2nd part of converting net selftests to run in unique namespace.
This part converts all bridge, vxlan, vrf tests.

Here is the part 1 link:
https://lore.kernel.org/netdev/20231202020110.362433-1-liuhangbin@gmail.com
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 6b4756be 61b12ebe
......@@ -9,9 +9,8 @@
# option and verifies that packets are no longer received by the second VXLAN
# device.
source lib.sh
ret=0
# Kselftest framework requirement - SKIP code is 4.
ksft_skip=4
TESTS="
nolocalbypass
......@@ -98,20 +97,19 @@ tc_check_packets()
setup()
{
ip netns add ns1
setup_ns ns1
ip -n ns1 link set dev lo up
ip -n ns1 address add 192.0.2.1/32 dev lo
ip -n ns1 address add 198.51.100.1/32 dev lo
ip -n $ns1 address add 192.0.2.1/32 dev lo
ip -n $ns1 address add 198.51.100.1/32 dev lo
ip -n ns1 link add name vx0 up type vxlan id 100 local 198.51.100.1 \
ip -n $ns1 link add name vx0 up type vxlan id 100 local 198.51.100.1 \
dstport 4789 nolearning
ip -n ns1 link add name vx1 up type vxlan id 100 dstport 4790
ip -n $ns1 link add name vx1 up type vxlan id 100 dstport 4790
}
cleanup()
{
ip netns del ns1 &> /dev/null
cleanup_ns $ns1
}
################################################################################
......@@ -122,40 +120,40 @@ nolocalbypass()
local smac=00:01:02:03:04:05
local dmac=00:0a:0b:0c:0d:0e
run_cmd "bridge -n ns1 fdb add $dmac dev vx0 self static dst 192.0.2.1 port 4790"
run_cmd "bridge -n $ns1 fdb add $dmac dev vx0 self static dst 192.0.2.1 port 4790"
run_cmd "tc -n ns1 qdisc add dev vx1 clsact"
run_cmd "tc -n ns1 filter add dev vx1 ingress pref 1 handle 101 proto all flower src_mac $smac dst_mac $dmac action pass"
run_cmd "tc -n $ns1 qdisc add dev vx1 clsact"
run_cmd "tc -n $ns1 filter add dev vx1 ingress pref 1 handle 101 proto all flower src_mac $smac dst_mac $dmac action pass"
run_cmd "tc -n ns1 qdisc add dev lo clsact"
run_cmd "tc -n ns1 filter add dev lo ingress pref 1 handle 101 proto ip flower ip_proto udp dst_port 4790 action drop"
run_cmd "tc -n $ns1 qdisc add dev lo clsact"
run_cmd "tc -n $ns1 filter add dev lo ingress pref 1 handle 101 proto ip flower ip_proto udp dst_port 4790 action drop"
run_cmd "ip -n ns1 -d -j link show dev vx0 | jq -e '.[][\"linkinfo\"][\"info_data\"][\"localbypass\"] == true'"
run_cmd "ip -n $ns1 -d -j link show dev vx0 | jq -e '.[][\"linkinfo\"][\"info_data\"][\"localbypass\"] == true'"
log_test $? 0 "localbypass enabled"
run_cmd "ip netns exec ns1 mausezahn vx0 -a $smac -b $dmac -c 1 -p 100 -q"
run_cmd "ip netns exec $ns1 mausezahn vx0 -a $smac -b $dmac -c 1 -p 100 -q"
tc_check_packets "ns1" "dev vx1 ingress" 101 1
tc_check_packets "$ns1" "dev vx1 ingress" 101 1
log_test $? 0 "Packet received by local VXLAN device - localbypass"
run_cmd "ip -n ns1 link set dev vx0 type vxlan nolocalbypass"
run_cmd "ip -n $ns1 link set dev vx0 type vxlan nolocalbypass"
run_cmd "ip -n ns1 -d -j link show dev vx0 | jq -e '.[][\"linkinfo\"][\"info_data\"][\"localbypass\"] == false'"
run_cmd "ip -n $ns1 -d -j link show dev vx0 | jq -e '.[][\"linkinfo\"][\"info_data\"][\"localbypass\"] == false'"
log_test $? 0 "localbypass disabled"
run_cmd "ip netns exec ns1 mausezahn vx0 -a $smac -b $dmac -c 1 -p 100 -q"
run_cmd "ip netns exec $ns1 mausezahn vx0 -a $smac -b $dmac -c 1 -p 100 -q"
tc_check_packets "ns1" "dev vx1 ingress" 101 1
tc_check_packets "$ns1" "dev vx1 ingress" 101 1
log_test $? 0 "Packet not received by local VXLAN device - nolocalbypass"
run_cmd "ip -n ns1 link set dev vx0 type vxlan localbypass"
run_cmd "ip -n $ns1 link set dev vx0 type vxlan localbypass"
run_cmd "ip -n ns1 -d -j link show dev vx0 | jq -e '.[][\"linkinfo\"][\"info_data\"][\"localbypass\"] == true'"
run_cmd "ip -n $ns1 -d -j link show dev vx0 | jq -e '.[][\"linkinfo\"][\"info_data\"][\"localbypass\"] == true'"
log_test $? 0 "localbypass enabled"
run_cmd "ip netns exec ns1 mausezahn vx0 -a $smac -b $dmac -c 1 -p 100 -q"
run_cmd "ip netns exec $ns1 mausezahn vx0 -a $smac -b $dmac -c 1 -p 100 -q"
tc_check_packets "ns1" "dev vx1 ingress" 101 2
tc_check_packets "$ns1" "dev vx1 ingress" 101 2
log_test $? 0 "Packet received by local VXLAN device - localbypass"
}
......
......@@ -43,15 +43,14 @@
# This tests both the connectivity between vm-1 and vm-2, and that the underlay
# can be moved in and out of the vrf by unsetting and setting veth0's master.
source lib.sh
set -e
cleanup() {
ip link del veth-hv-1 2>/dev/null || true
ip link del veth-tap 2>/dev/null || true
for ns in hv-1 hv-2 vm-1 vm-2; do
ip netns del $ns 2>/dev/null || true
done
cleanup_ns $hv_1 $hv_2 $vm_1 $vm_2
}
# Clean start
......@@ -60,72 +59,75 @@ cleanup &> /dev/null
[[ $1 == "clean" ]] && exit 0
trap cleanup EXIT
setup_ns hv_1 hv_2 vm_1 vm_2
hv[1]=$hv_1
hv[2]=$hv_2
vm[1]=$vm_1
vm[2]=$vm_2
# Setup "Hypervisors" simulated with netns
ip link add veth-hv-1 type veth peer name veth-hv-2
setup-hv-networking() {
hv=$1
id=$1
ip netns add hv-$hv
ip link set veth-hv-$hv netns hv-$hv
ip -netns hv-$hv link set veth-hv-$hv name veth0
ip link set veth-hv-$id netns ${hv[$id]}
ip -netns ${hv[$id]} link set veth-hv-$id name veth0
ip -netns hv-$hv link add vrf-underlay type vrf table 1
ip -netns hv-$hv link set vrf-underlay up
ip -netns hv-$hv addr add 172.16.0.$hv/24 dev veth0
ip -netns hv-$hv link set veth0 up
ip -netns ${hv[$id]} link add vrf-underlay type vrf table 1
ip -netns ${hv[$id]} link set vrf-underlay up
ip -netns ${hv[$id]} addr add 172.16.0.$id/24 dev veth0
ip -netns ${hv[$id]} link set veth0 up
ip -netns hv-$hv link add br0 type bridge
ip -netns hv-$hv link set br0 up
ip -netns ${hv[$id]} link add br0 type bridge
ip -netns ${hv[$id]} link set br0 up
ip -netns hv-$hv link add vxlan0 type vxlan id 10 local 172.16.0.$hv dev veth0 dstport 4789
ip -netns hv-$hv link set vxlan0 master br0
ip -netns hv-$hv link set vxlan0 up
ip -netns ${hv[$id]} link add vxlan0 type vxlan id 10 local 172.16.0.$id dev veth0 dstport 4789
ip -netns ${hv[$id]} link set vxlan0 master br0
ip -netns ${hv[$id]} link set vxlan0 up
}
setup-hv-networking 1
setup-hv-networking 2
# Check connectivity between HVs by pinging hv-2 from hv-1
echo -n "Checking HV connectivity "
ip netns exec hv-1 ping -c 1 -W 1 172.16.0.2 &> /dev/null || (echo "[FAIL]"; false)
ip netns exec $hv_1 ping -c 1 -W 1 172.16.0.2 &> /dev/null || (echo "[FAIL]"; false)
echo "[ OK ]"
# Setups a "VM" simulated by a netns an a veth pair
setup-vm() {
id=$1
ip netns add vm-$id
ip link add veth-tap type veth peer name veth-hv
ip link set veth-tap netns hv-$id
ip -netns hv-$id link set veth-tap master br0
ip -netns hv-$id link set veth-tap up
ip link set veth-tap netns ${hv[$id]}
ip -netns ${hv[$id]} link set veth-tap master br0
ip -netns ${hv[$id]} link set veth-tap up
ip link set veth-hv address 02:1d:8d:dd:0c:6$id
ip link set veth-hv netns vm-$id
ip -netns vm-$id addr add 10.0.0.$id/24 dev veth-hv
ip -netns vm-$id link set veth-hv up
ip link set veth-hv netns ${vm[$id]}
ip -netns ${vm[$id]} addr add 10.0.0.$id/24 dev veth-hv
ip -netns ${vm[$id]} link set veth-hv up
}
setup-vm 1
setup-vm 2
# Setup VTEP routes to make ARP work
bridge -netns hv-1 fdb add 00:00:00:00:00:00 dev vxlan0 dst 172.16.0.2 self permanent
bridge -netns hv-2 fdb add 00:00:00:00:00:00 dev vxlan0 dst 172.16.0.1 self permanent
bridge -netns $hv_1 fdb add 00:00:00:00:00:00 dev vxlan0 dst 172.16.0.2 self permanent
bridge -netns $hv_2 fdb add 00:00:00:00:00:00 dev vxlan0 dst 172.16.0.1 self permanent
echo -n "Check VM connectivity through VXLAN (underlay in the default VRF) "
ip netns exec vm-1 ping -c 1 -W 1 10.0.0.2 &> /dev/null || (echo "[FAIL]"; false)
ip netns exec $vm_1 ping -c 1 -W 1 10.0.0.2 &> /dev/null || (echo "[FAIL]"; false)
echo "[ OK ]"
# Move the underlay to a non-default VRF
ip -netns hv-1 link set veth0 vrf vrf-underlay
ip -netns hv-1 link set vxlan0 down
ip -netns hv-1 link set vxlan0 up
ip -netns hv-2 link set veth0 vrf vrf-underlay
ip -netns hv-2 link set vxlan0 down
ip -netns hv-2 link set vxlan0 up
ip -netns $hv_1 link set veth0 vrf vrf-underlay
ip -netns $hv_1 link set vxlan0 down
ip -netns $hv_1 link set vxlan0 up
ip -netns $hv_2 link set veth0 vrf vrf-underlay
ip -netns $hv_2 link set vxlan0 down
ip -netns $hv_2 link set vxlan0 up
echo -n "Check VM connectivity through VXLAN (underlay in a VRF) "
ip netns exec vm-1 ping -c 1 -W 1 10.0.0.2 &> /dev/null || (echo "[FAIL]"; false)
ip netns exec $vm_1 ping -c 1 -W 1 10.0.0.2 &> /dev/null || (echo "[FAIL]"; false)
echo "[ OK ]"
......@@ -3,9 +3,7 @@
#
# Various combinations of VRF with xfrms and qdisc.
# Kselftest framework requirement - SKIP code is 4.
ksft_skip=4
source lib.sh
PAUSE_ON_FAIL=no
VERBOSE=0
ret=0
......@@ -67,7 +65,7 @@ run_cmd_host1()
printf " COMMAND: $cmd\n"
fi
out=$(eval ip netns exec host1 $cmd 2>&1)
out=$(eval ip netns exec $host1 $cmd 2>&1)
rc=$?
if [ "$VERBOSE" = "1" ]; then
if [ -n "$out" ]; then
......@@ -116,9 +114,6 @@ create_ns()
[ -z "${addr}" ] && addr="-"
[ -z "${addr6}" ] && addr6="-"
ip netns add ${ns}
ip -netns ${ns} link set lo up
if [ "${addr}" != "-" ]; then
ip -netns ${ns} addr add dev lo ${addr}
fi
......@@ -177,25 +172,25 @@ connect_ns()
cleanup()
{
ip netns del host1
ip netns del host2
cleanup_ns $host1 $host2
}
setup()
{
create_ns "host1"
create_ns "host2"
setup_ns host1 host2
create_ns "$host1"
create_ns "$host2"
connect_ns "host1" eth0 ${HOST1_4}/24 ${HOST1_6}/64 \
"host2" eth0 ${HOST2_4}/24 ${HOST2_6}/64
connect_ns "$host1" eth0 ${HOST1_4}/24 ${HOST1_6}/64 \
"$host2" eth0 ${HOST2_4}/24 ${HOST2_6}/64
create_vrf "host1" ${VRF} ${TABLE}
ip -netns host1 link set dev eth0 master ${VRF}
create_vrf "$host1" ${VRF} ${TABLE}
ip -netns $host1 link set dev eth0 master ${VRF}
}
cleanup_xfrm()
{
for ns in host1 host2
for ns in $host1 $host2
do
for x in state policy
do
......@@ -218,57 +213,57 @@ setup_xfrm()
#
# host1 - IPv4 out
ip -netns host1 xfrm policy add \
ip -netns $host1 xfrm policy add \
src ${h1_4} dst ${h2_4} ${devarg} dir out \
tmpl src ${HOST1_4} dst ${HOST2_4} proto esp mode tunnel
# host2 - IPv4 in
ip -netns host2 xfrm policy add \
ip -netns $host2 xfrm policy add \
src ${h1_4} dst ${h2_4} dir in \
tmpl src ${HOST1_4} dst ${HOST2_4} proto esp mode tunnel
# host1 - IPv4 in
ip -netns host1 xfrm policy add \
ip -netns $host1 xfrm policy add \
src ${h2_4} dst ${h1_4} ${devarg} dir in \
tmpl src ${HOST2_4} dst ${HOST1_4} proto esp mode tunnel
# host2 - IPv4 out
ip -netns host2 xfrm policy add \
ip -netns $host2 xfrm policy add \
src ${h2_4} dst ${h1_4} dir out \
tmpl src ${HOST2_4} dst ${HOST1_4} proto esp mode tunnel
# host1 - IPv6 out
ip -6 -netns host1 xfrm policy add \
ip -6 -netns $host1 xfrm policy add \
src ${h1_6} dst ${h2_6} ${devarg} dir out \
tmpl src ${HOST1_6} dst ${HOST2_6} proto esp mode tunnel
# host2 - IPv6 in
ip -6 -netns host2 xfrm policy add \
ip -6 -netns $host2 xfrm policy add \
src ${h1_6} dst ${h2_6} dir in \
tmpl src ${HOST1_6} dst ${HOST2_6} proto esp mode tunnel
# host1 - IPv6 in
ip -6 -netns host1 xfrm policy add \
ip -6 -netns $host1 xfrm policy add \
src ${h2_6} dst ${h1_6} ${devarg} dir in \
tmpl src ${HOST2_6} dst ${HOST1_6} proto esp mode tunnel
# host2 - IPv6 out
ip -6 -netns host2 xfrm policy add \
ip -6 -netns $host2 xfrm policy add \
src ${h2_6} dst ${h1_6} dir out \
tmpl src ${HOST2_6} dst ${HOST1_6} proto esp mode tunnel
#
# state
#
ip -netns host1 xfrm state add src ${HOST1_4} dst ${HOST2_4} \
ip -netns $host1 xfrm state add src ${HOST1_4} dst ${HOST2_4} \
proto esp spi ${SPI_1} reqid 0 mode tunnel \
replay-window 4 replay-oseq 0x4 \
auth-trunc 'hmac(sha1)' ${AUTH_1} 96 \
enc 'cbc(aes)' ${ENC_1} \
sel src ${h1_4} dst ${h2_4} ${devarg}
ip -netns host2 xfrm state add src ${HOST1_4} dst ${HOST2_4} \
ip -netns $host2 xfrm state add src ${HOST1_4} dst ${HOST2_4} \
proto esp spi ${SPI_1} reqid 0 mode tunnel \
replay-window 4 replay-oseq 0x4 \
auth-trunc 'hmac(sha1)' ${AUTH_1} 96 \
......@@ -276,14 +271,14 @@ setup_xfrm()
sel src ${h1_4} dst ${h2_4}
ip -netns host1 xfrm state add src ${HOST2_4} dst ${HOST1_4} \
ip -netns $host1 xfrm state add src ${HOST2_4} dst ${HOST1_4} \
proto esp spi ${SPI_2} reqid 0 mode tunnel \
replay-window 4 replay-oseq 0x4 \
auth-trunc 'hmac(sha1)' ${AUTH_2} 96 \
enc 'cbc(aes)' ${ENC_2} \
sel src ${h2_4} dst ${h1_4} ${devarg}
ip -netns host2 xfrm state add src ${HOST2_4} dst ${HOST1_4} \
ip -netns $host2 xfrm state add src ${HOST2_4} dst ${HOST1_4} \
proto esp spi ${SPI_2} reqid 0 mode tunnel \
replay-window 4 replay-oseq 0x4 \
auth-trunc 'hmac(sha1)' ${AUTH_2} 96 \
......@@ -291,14 +286,14 @@ setup_xfrm()
sel src ${h2_4} dst ${h1_4}
ip -6 -netns host1 xfrm state add src ${HOST1_6} dst ${HOST2_6} \
ip -6 -netns $host1 xfrm state add src ${HOST1_6} dst ${HOST2_6} \
proto esp spi ${SPI_1} reqid 0 mode tunnel \
replay-window 4 replay-oseq 0x4 \
auth-trunc 'hmac(sha1)' ${AUTH_1} 96 \
enc 'cbc(aes)' ${ENC_1} \
sel src ${h1_6} dst ${h2_6} ${devarg}
ip -6 -netns host2 xfrm state add src ${HOST1_6} dst ${HOST2_6} \
ip -6 -netns $host2 xfrm state add src ${HOST1_6} dst ${HOST2_6} \
proto esp spi ${SPI_1} reqid 0 mode tunnel \
replay-window 4 replay-oseq 0x4 \
auth-trunc 'hmac(sha1)' ${AUTH_1} 96 \
......@@ -306,14 +301,14 @@ setup_xfrm()
sel src ${h1_6} dst ${h2_6}
ip -6 -netns host1 xfrm state add src ${HOST2_6} dst ${HOST1_6} \
ip -6 -netns $host1 xfrm state add src ${HOST2_6} dst ${HOST1_6} \
proto esp spi ${SPI_2} reqid 0 mode tunnel \
replay-window 4 replay-oseq 0x4 \
auth-trunc 'hmac(sha1)' ${AUTH_2} 96 \
enc 'cbc(aes)' ${ENC_2} \
sel src ${h2_6} dst ${h1_6} ${devarg}
ip -6 -netns host2 xfrm state add src ${HOST2_6} dst ${HOST1_6} \
ip -6 -netns $host2 xfrm state add src ${HOST2_6} dst ${HOST1_6} \
proto esp spi ${SPI_2} reqid 0 mode tunnel \
replay-window 4 replay-oseq 0x4 \
auth-trunc 'hmac(sha1)' ${AUTH_2} 96 \
......@@ -323,22 +318,22 @@ setup_xfrm()
cleanup_xfrm_dev()
{
ip -netns host1 li del xfrm0
ip -netns host2 addr del ${XFRM2_4}/24 dev eth0
ip -netns host2 addr del ${XFRM2_6}/64 dev eth0
ip -netns $host1 li del xfrm0
ip -netns $host2 addr del ${XFRM2_4}/24 dev eth0
ip -netns $host2 addr del ${XFRM2_6}/64 dev eth0
}
setup_xfrm_dev()
{
local vrfarg="vrf ${VRF}"
ip -netns host1 li add type xfrm dev eth0 if_id ${IF_ID}
ip -netns host1 li set xfrm0 ${vrfarg} up
ip -netns host1 addr add ${XFRM1_4}/24 dev xfrm0
ip -netns host1 addr add ${XFRM1_6}/64 dev xfrm0
ip -netns $host1 li add type xfrm dev eth0 if_id ${IF_ID}
ip -netns $host1 li set xfrm0 ${vrfarg} up
ip -netns $host1 addr add ${XFRM1_4}/24 dev xfrm0
ip -netns $host1 addr add ${XFRM1_6}/64 dev xfrm0
ip -netns host2 addr add ${XFRM2_4}/24 dev eth0
ip -netns host2 addr add ${XFRM2_6}/64 dev eth0
ip -netns $host2 addr add ${XFRM2_4}/24 dev eth0
ip -netns $host2 addr add ${XFRM2_6}/64 dev eth0
setup_xfrm ${XFRM1_4} ${XFRM2_4} ${XFRM1_6} ${XFRM2_6} "if_id ${IF_ID}"
}
......
......@@ -3,9 +3,7 @@
# This test is designed for testing the new VRF strict_mode functionality.
# Kselftest framework requirement - SKIP code is 4.
ksft_skip=4
source lib.sh
ret=0
# identifies the "init" network namespace which is often called root network
......@@ -247,13 +245,12 @@ setup()
{
modprobe vrf
ip netns add testns
ip netns exec testns ip link set lo up
setup_ns testns
}
cleanup()
{
ip netns del testns 2>/dev/null
ip netns del $testns 2>/dev/null
ip link del vrf100 2>/dev/null
ip link del vrf101 2>/dev/null
......@@ -298,28 +295,28 @@ vrf_strict_mode_tests_testns()
{
log_section "VRF strict_mode test on testns network namespace"
vrf_strict_mode_check_support testns
vrf_strict_mode_check_support $testns
strict_mode_check_default testns
strict_mode_check_default $testns
enable_strict_mode_and_check testns
enable_strict_mode_and_check $testns
add_vrf_and_check testns vrf100 100
config_vrf_and_check testns 10.0.100.1/24 vrf100
add_vrf_and_check $testns vrf100 100
config_vrf_and_check $testns 10.0.100.1/24 vrf100
add_vrf_and_check_fail testns vrf101 100
add_vrf_and_check_fail $testns vrf101 100
add_vrf_and_check_fail testns vrf102 100
add_vrf_and_check_fail $testns vrf102 100
add_vrf_and_check testns vrf200 200
add_vrf_and_check $testns vrf200 200
disable_strict_mode_and_check testns
disable_strict_mode_and_check $testns
add_vrf_and_check testns vrf101 100
add_vrf_and_check $testns vrf101 100
add_vrf_and_check testns vrf102 100
add_vrf_and_check $testns vrf102 100
#the strict_mode is disabled in the testns
#the strict_mode is disabled in the $testns
}
vrf_strict_mode_tests_mix()
......@@ -328,25 +325,25 @@ vrf_strict_mode_tests_mix()
read_strict_mode_compare_and_check init 1
read_strict_mode_compare_and_check testns 0
read_strict_mode_compare_and_check $testns 0
del_vrf_and_check testns vrf101
del_vrf_and_check $testns vrf101
del_vrf_and_check testns vrf102
del_vrf_and_check $testns vrf102
disable_strict_mode_and_check init
enable_strict_mode_and_check testns
enable_strict_mode_and_check $testns
enable_strict_mode_and_check init
enable_strict_mode_and_check init
disable_strict_mode_and_check testns
disable_strict_mode_and_check testns
disable_strict_mode_and_check $testns
disable_strict_mode_and_check $testns
read_strict_mode_compare_and_check init 1
read_strict_mode_compare_and_check testns 0
read_strict_mode_compare_and_check $testns 0
}
################################################################################
......
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