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

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.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents fcb29877 b795db18
......@@ -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} "-" "-"
......
......@@ -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 +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
......
......@@ -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
......@@ -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
This diff is collapsed.
......@@ -3,14 +3,9 @@
# This test is for checking IPv4 and IPv6 FIB rules API
# Kselftest framework requirement - SKIP code is 4.
ksft_skip=4
source lib.sh
ret=0
PAUSE_ON_FAIL=${PAUSE_ON_FAIL:=no}
IP="ip -netns testns"
IP_PEER="ip -netns peerns"
RTABLE=100
RTABLE_PEER=101
......@@ -84,8 +79,8 @@ check_nettest()
setup()
{
set -e
ip netns add testns
$IP link set dev lo up
setup_ns testns
IP="ip -netns $testns"
$IP link add dummy0 type dummy
$IP link set dev dummy0 up
......@@ -98,18 +93,19 @@ setup()
cleanup()
{
$IP link del dev dummy0 &> /dev/null
ip netns del testns
cleanup_ns $testns
}
setup_peer()
{
set -e
ip netns add peerns
setup_ns peerns
IP_PEER="ip -netns $peerns"
$IP_PEER link set dev lo up
ip link add name veth0 netns testns type veth \
peer name veth1 netns peerns
ip link add name veth0 netns $testns type veth \
peer name veth1 netns $peerns
$IP link set dev veth0 up
$IP_PEER link set dev veth1 up
......@@ -131,7 +127,7 @@ setup_peer()
cleanup_peer()
{
$IP link del dev veth0
ip netns del peerns
ip netns del $peerns
}
fib_check_iproute_support()
......@@ -270,11 +266,11 @@ fib_rule6_connect_test()
# (Not-ECT: 0, ECT(1): 1, ECT(0): 2, CE: 3).
# The ECN bits shouldn't influence the result of the test.
for dsfield in 0x04 0x05 0x06 0x07; do
nettest -q -6 -B -t 5 -N testns -O peerns -U -D \
nettest -q -6 -B -t 5 -N $testns -O $peerns -U -D \
-Q "${dsfield}" -l 2001:db8::1:11 -r 2001:db8::1:11
log_test $? 0 "rule6 dsfield udp connect (dsfield ${dsfield})"
nettest -q -6 -B -t 5 -N testns -O peerns -Q "${dsfield}" \
nettest -q -6 -B -t 5 -N $testns -O $peerns -Q "${dsfield}" \
-l 2001:db8::1:11 -r 2001:db8::1:11
log_test $? 0 "rule6 dsfield tcp connect (dsfield ${dsfield})"
done
......@@ -337,11 +333,11 @@ fib_rule4_test()
# need enable forwarding and disable rp_filter temporarily as all the
# addresses are in the same subnet and egress device == ingress device.
ip netns exec testns sysctl -qw net.ipv4.ip_forward=1
ip netns exec testns sysctl -qw net.ipv4.conf.$DEV.rp_filter=0
ip netns exec $testns sysctl -qw net.ipv4.ip_forward=1
ip netns exec $testns sysctl -qw net.ipv4.conf.$DEV.rp_filter=0
match="from $SRC_IP iif $DEV"
fib_rule4_test_match_n_redirect "$match" "$match" "iif redirect to table"
ip netns exec testns sysctl -qw net.ipv4.ip_forward=0
ip netns exec $testns sysctl -qw net.ipv4.ip_forward=0
# Reject dsfield (tos) options which have ECN bits set
for cnt in $(seq 1 3); do
......@@ -407,11 +403,11 @@ fib_rule4_connect_test()
# (Not-ECT: 0, ECT(1): 1, ECT(0): 2, CE: 3).
# The ECN bits shouldn't influence the result of the test.
for dsfield in 0x04 0x05 0x06 0x07; do
nettest -q -B -t 5 -N testns -O peerns -D -U -Q "${dsfield}" \
nettest -q -B -t 5 -N $testns -O $peerns -D -U -Q "${dsfield}" \
-l 198.51.100.11 -r 198.51.100.11
log_test $? 0 "rule4 dsfield udp connect (dsfield ${dsfield})"
nettest -q -B -t 5 -N testns -O peerns -Q "${dsfield}" \
nettest -q -B -t 5 -N $testns -O $peerns -Q "${dsfield}" \
-l 198.51.100.11 -r 198.51.100.11
log_test $? 0 "rule4 dsfield tcp connect (dsfield ${dsfield})"
done
......
This diff is collapsed.
......@@ -6,6 +6,8 @@
# Kselftest framework requirement - SKIP code is 4.
ksft_skip=4
# namespace list created by setup_ns
NS_LIST=""
##############################################################################
# Helpers
......@@ -56,6 +58,11 @@ cleanup_ns()
return $ret
}
cleanup_all_ns()
{
cleanup_ns $NS_LIST
}
# setup netns with given names as prefix. e.g
# setup_ns local remote
setup_ns()
......@@ -82,4 +89,5 @@ setup_ns()
ip -n "$ns" link set lo up
ns_list="$ns_list $ns"
done
NS_LIST="$NS_LIST $ns_list"
}
......@@ -193,8 +193,7 @@
# +---------------------------------------------------+
#
# Kselftest framework requirement - SKIP code is 4.
ksft_skip=4
source lib.sh
readonly LOCALSID_TABLE_ID=90
readonly IPv6_RT_NETWORK=fd00
......@@ -250,26 +249,22 @@ cleanup()
ip link del veth-rt-1 2>/dev/null || true
ip link del veth-rt-2 2>/dev/null || true
# destroy routers rt-* and hosts hs-*
for ns in $(ip netns show | grep -E 'rt-*|hs-*'); do
ip netns del ${ns} || true
done
cleanup_all_ns
}
# Setup the basic networking for the routers
setup_rt_networking()
{
local rt=$1
local nsname=rt-${rt}
local id=$1
eval local nsname=\${rt_${id}}
ip netns add ${nsname}
ip link set veth-rt-${rt} netns ${nsname}
ip -netns ${nsname} link set veth-rt-${rt} name veth0
ip link set veth-rt-${id} netns ${nsname}
ip -netns ${nsname} link set veth-rt-${id} name veth0
ip netns exec ${nsname} sysctl -wq net.ipv6.conf.all.accept_dad=0
ip netns exec ${nsname} sysctl -wq net.ipv6.conf.default.accept_dad=0
ip -netns ${nsname} addr add ${IPv6_RT_NETWORK}::${rt}/64 dev veth0 nodad
ip -netns ${nsname} addr add ${IPv6_RT_NETWORK}::${id}/64 dev veth0 nodad
ip -netns ${nsname} link set veth0 up
ip -netns ${nsname} link set lo up
......@@ -279,16 +274,14 @@ setup_rt_networking()
setup_hs()
{
local hs=$1
local rt=$2
local hid=$1
local rid=$2
local tid=$3
local hsname=hs-t${tid}-${hs}
local rtname=rt-${rt}
eval local hsname=\${hs_t${tid}_${hid}}
eval local rtname=\${rt_${rid}}
local rtveth=veth-t${tid}
# set the networking for the host
ip netns add ${hsname}
ip netns exec ${hsname} sysctl -wq net.ipv6.conf.all.accept_dad=0
ip netns exec ${hsname} sysctl -wq net.ipv6.conf.default.accept_dad=0
......@@ -299,8 +292,8 @@ setup_hs()
ip -netns ${hsname} link add veth0 type veth peer name ${rtveth}
ip -netns ${hsname} link set ${rtveth} netns ${rtname}
ip -netns ${hsname} addr add ${IPv6_HS_NETWORK}::${hs}/64 dev veth0 nodad
ip -netns ${hsname} addr add ${IPv4_HS_NETWORK}.${hs}/24 dev veth0
ip -netns ${hsname} addr add ${IPv6_HS_NETWORK}::${hid}/64 dev veth0 nodad
ip -netns ${hsname} addr add ${IPv4_HS_NETWORK}.${hid}/24 dev veth0
ip -netns ${hsname} link set veth0 up
ip -netns ${hsname} link set lo up
......@@ -332,10 +325,8 @@ setup_vpn_config()
local rtdst=$4
local tid=$5
local hssrc_name=hs-t${tid}-${hssrc}
local hsdst_name=hs-t${tid}-${hsdst}
local rtsrc_name=rt-${rtsrc}
local rtdst_name=rt-${rtdst}
eval local rtsrc_name=\${rt_${rtsrc}}
eval local rtdst_name=\${rt_${rtdst}}
local rtveth=veth-t${tid}
local vpn_sid=${VPN_LOCATOR_SERVICE}:${hssrc}${hsdst}:${tid}::6046
......@@ -379,18 +370,21 @@ setup()
{
ip link add veth-rt-1 type veth peer name veth-rt-2
# setup the networking for router rt-1 and router rt-2
setup_ns rt_1 rt_2
setup_rt_networking 1
setup_rt_networking 2
# setup two hosts for the tenant 100.
# - host hs-1 is directly connected to the router rt-1;
# - host hs-2 is directly connected to the router rt-2.
setup_ns hs_t100_1 hs_t100_2
setup_hs 1 1 100 #args: host router tenant
setup_hs 2 2 100
# setup two hosts for the tenant 200
# - host hs-3 is directly connected to the router rt-1;
# - host hs-4 is directly connected to the router rt-2.
setup_ns hs_t200_3 hs_t200_4
setup_hs 3 1 200
setup_hs 4 2 200
......@@ -409,8 +403,9 @@ check_rt_connectivity()
{
local rtsrc=$1
local rtdst=$2
eval local nsname=\${rt_${rtsrc}}
ip netns exec rt-${rtsrc} ping -c 1 -W 1 ${IPv6_RT_NETWORK}::${rtdst} \
ip netns exec ${nsname} ping -c 1 -W 1 ${IPv6_RT_NETWORK}::${rtdst} \
>/dev/null 2>&1
}
......@@ -428,8 +423,9 @@ check_hs_ipv6_connectivity()
local hssrc=$1
local hsdst=$2
local tid=$3
eval local nsname=\${hs_t${tid}_${hssrc}}
ip netns exec hs-t${tid}-${hssrc} ping -c 1 -W ${PING_TIMEOUT_SEC} \
ip netns exec ${nsname} ping -c 1 -W ${PING_TIMEOUT_SEC} \
${IPv6_HS_NETWORK}::${hsdst} >/dev/null 2>&1
}
......@@ -438,8 +434,9 @@ check_hs_ipv4_connectivity()
local hssrc=$1
local hsdst=$2
local tid=$3
eval local nsname=\${hs_t${tid}_${hssrc}}
ip netns exec hs-t${tid}-${hssrc} ping -c 1 -W ${PING_TIMEOUT_SEC} \
ip netns exec ${nsname} ping -c 1 -W ${PING_TIMEOUT_SEC} \
${IPv4_HS_NETWORK}.${hsdst} >/dev/null 2>&1
}
......
......@@ -163,8 +163,7 @@
# +---------------------------------------------------+
#
# Kselftest framework requirement - SKIP code is 4.
ksft_skip=4
source lib.sh
readonly LOCALSID_TABLE_ID=90
readonly IPv6_RT_NETWORK=fd00
......@@ -219,27 +218,22 @@ cleanup()
ip link del veth-rt-1 2>/dev/null || true
ip link del veth-rt-2 2>/dev/null || true
# destroy routers rt-* and hosts hs-*
for ns in $(ip netns show | grep -E 'rt-*|hs-*'); do
ip netns del ${ns} || true
done
cleanup_all_ns
}
# Setup the basic networking for the routers
setup_rt_networking()
{
local rt=$1
local nsname=rt-${rt}
ip netns add ${nsname}
local id=$1
eval local nsname=\${rt_${id}}
ip netns exec ${nsname} sysctl -wq net.ipv6.conf.all.accept_dad=0
ip netns exec ${nsname} sysctl -wq net.ipv6.conf.default.accept_dad=0
ip link set veth-rt-${rt} netns ${nsname}
ip -netns ${nsname} link set veth-rt-${rt} name veth0
ip link set veth-rt-${id} netns ${nsname}
ip -netns ${nsname} link set veth-rt-${id} name veth0
ip -netns ${nsname} addr add ${IPv6_RT_NETWORK}::${rt}/64 dev veth0 nodad
ip -netns ${nsname} addr add ${IPv6_RT_NETWORK}::${id}/64 dev veth0 nodad
ip -netns ${nsname} link set veth0 up
ip -netns ${nsname} link set lo up
......@@ -249,16 +243,13 @@ setup_rt_networking()
setup_hs()
{
local hs=$1
local rt=$2
local hid=$1
local rid=$2
local tid=$3
local hsname=hs-t${tid}-${hs}
local rtname=rt-${rt}
eval local hsname=\${hs_t${tid}_${hid}}
eval local rtname=\${rt_${rid}}
local rtveth=veth-t${tid}
# set the networking for the host
ip netns add ${hsname}
# disable the rp_filter otherwise the kernel gets confused about how
# to route decap ipv4 packets.
ip netns exec ${rtname} sysctl -wq net.ipv4.conf.all.rp_filter=0
......@@ -266,7 +257,7 @@ setup_hs()
ip -netns ${hsname} link add veth0 type veth peer name ${rtveth}
ip -netns ${hsname} link set ${rtveth} netns ${rtname}
ip -netns ${hsname} addr add ${IPv4_HS_NETWORK}.${hs}/24 dev veth0
ip -netns ${hsname} addr add ${IPv4_HS_NETWORK}.${hid}/24 dev veth0
ip -netns ${hsname} link set veth0 up
ip -netns ${hsname} link set lo up
......@@ -293,10 +284,8 @@ setup_vpn_config()
local rtdst=$4
local tid=$5
local hssrc_name=hs-t${tid}-${hssrc}
local hsdst_name=hs-t${tid}-${hsdst}
local rtsrc_name=rt-${rtsrc}
local rtdst_name=rt-${rtdst}
eval local rtsrc_name=\${rt_${rtsrc}}
eval local rtdst_name=\${rt_${rtdst}}
local vpn_sid=${VPN_LOCATOR_SERVICE}:${hssrc}${hsdst}:${tid}::6004
# set the encap route for encapsulating packets which arrive from the
......@@ -328,18 +317,21 @@ setup()
{
ip link add veth-rt-1 type veth peer name veth-rt-2
# setup the networking for router rt-1 and router rt-2
setup_ns rt_1 rt_2
setup_rt_networking 1
setup_rt_networking 2
# setup two hosts for the tenant 100.
# - host hs-1 is directly connected to the router rt-1;
# - host hs-2 is directly connected to the router rt-2.
setup_ns hs_t100_1 hs_t100_2
setup_hs 1 1 100 #args: host router tenant
setup_hs 2 2 100
# setup two hosts for the tenant 200
# - host hs-3 is directly connected to the router rt-1;
# - host hs-4 is directly connected to the router rt-2.
setup_ns hs_t200_3 hs_t200_4
setup_hs 3 1 200
setup_hs 4 2 200
......@@ -358,8 +350,9 @@ check_rt_connectivity()
{
local rtsrc=$1
local rtdst=$2
eval local nsname=\${rt_${rtsrc}}
ip netns exec rt-${rtsrc} ping -c 1 -W 1 ${IPv6_RT_NETWORK}::${rtdst} \
ip netns exec ${nsname} ping -c 1 -W 1 ${IPv6_RT_NETWORK}::${rtdst} \
>/dev/null 2>&1
}
......@@ -377,8 +370,9 @@ check_hs_connectivity()
local hssrc=$1
local hsdst=$2
local tid=$3
eval local nsname=\${hs_t${tid}_${hssrc}}
ip netns exec hs-t${tid}-${hssrc} ping -c 1 -W ${PING_TIMEOUT_SEC} \
ip netns exec ${nsname} ping -c 1 -W ${PING_TIMEOUT_SEC} \
${IPv4_HS_NETWORK}.${hsdst} >/dev/null 2>&1
}
......
......@@ -164,8 +164,7 @@
# +---------------------------------------------------+
#
# Kselftest framework requirement - SKIP code is 4.
ksft_skip=4
source lib.sh
readonly LOCALSID_TABLE_ID=90
readonly IPv6_RT_NETWORK=fd00
......@@ -220,26 +219,22 @@ cleanup()
ip link del veth-rt-1 2>/dev/null || true
ip link del veth-rt-2 2>/dev/null || true
# destroy routers rt-* and hosts hs-*
for ns in $(ip netns show | grep -E 'rt-*|hs-*'); do
ip netns del ${ns} || true
done
cleanup_all_ns
}
# Setup the basic networking for the routers
setup_rt_networking()
{
local rt=$1
local nsname=rt-${rt}
local id=$1
eval local nsname=\${rt_${id}}
ip netns add ${nsname}
ip link set veth-rt-${rt} netns ${nsname}
ip -netns ${nsname} link set veth-rt-${rt} name veth0
ip link set veth-rt-${id} netns ${nsname}
ip -netns ${nsname} link set veth-rt-${id} name veth0
ip netns exec ${nsname} sysctl -wq net.ipv6.conf.all.accept_dad=0
ip netns exec ${nsname} sysctl -wq net.ipv6.conf.default.accept_dad=0
ip -netns ${nsname} addr add ${IPv6_RT_NETWORK}::${rt}/64 dev veth0 nodad
ip -netns ${nsname} addr add ${IPv6_RT_NETWORK}::${id}/64 dev veth0 nodad
ip -netns ${nsname} link set veth0 up
ip -netns ${nsname} link set lo up
......@@ -248,22 +243,20 @@ setup_rt_networking()
setup_hs()
{
local hs=$1
local rt=$2
local hid=$1
local rid=$2
local tid=$3
local hsname=hs-t${tid}-${hs}
local rtname=rt-${rt}
eval local hsname=\${hs_t${tid}_${hid}}
eval local rtname=\${rt_${rid}}
local rtveth=veth-t${tid}
# set the networking for the host
ip netns add ${hsname}
ip netns exec ${hsname} sysctl -wq net.ipv6.conf.all.accept_dad=0
ip netns exec ${hsname} sysctl -wq net.ipv6.conf.default.accept_dad=0
ip -netns ${hsname} link add veth0 type veth peer name ${rtveth}
ip -netns ${hsname} link set ${rtveth} netns ${rtname}
ip -netns ${hsname} addr add ${IPv6_HS_NETWORK}::${hs}/64 dev veth0 nodad
ip -netns ${hsname} addr add ${IPv6_HS_NETWORK}::${hid}/64 dev veth0 nodad
ip -netns ${hsname} link set veth0 up
ip -netns ${hsname} link set lo up
......@@ -293,10 +286,8 @@ setup_vpn_config()
local rtdst=$4
local tid=$5
local hssrc_name=hs-t${tid}-${hssrc}
local hsdst_name=hs-t${tid}-${hsdst}
local rtsrc_name=rt-${rtsrc}
local rtdst_name=rt-${rtdst}
eval local rtsrc_name=\${rt_${rtsrc}}
eval local rtdst_name=\${rt_${rtdst}}
local rtveth=veth-t${tid}
local vpn_sid=${VPN_LOCATOR_SERVICE}:${hssrc}${hsdst}:${tid}::6006
......@@ -331,18 +322,21 @@ setup()
{
ip link add veth-rt-1 type veth peer name veth-rt-2
# setup the networking for router rt-1 and router rt-2
setup_ns rt_1 rt_2
setup_rt_networking 1
setup_rt_networking 2
# setup two hosts for the tenant 100.
# - host hs-1 is directly connected to the router rt-1;
# - host hs-2 is directly connected to the router rt-2.
setup_ns hs_t100_1 hs_t100_2
setup_hs 1 1 100 #args: host router tenant
setup_hs 2 2 100
# setup two hosts for the tenant 200
# - host hs-3 is directly connected to the router rt-1;
# - host hs-4 is directly connected to the router rt-2.
setup_ns hs_t200_3 hs_t200_4
setup_hs 3 1 200
setup_hs 4 2 200
......@@ -361,8 +355,9 @@ check_rt_connectivity()
{
local rtsrc=$1
local rtdst=$2
eval local nsname=\${rt_${rtsrc}}
ip netns exec rt-${rtsrc} ping -c 1 -W 1 ${IPv6_RT_NETWORK}::${rtdst} \
ip netns exec ${nsname} ping -c 1 -W 1 ${IPv6_RT_NETWORK}::${rtdst} \
>/dev/null 2>&1
}
......@@ -380,8 +375,9 @@ check_hs_connectivity()
local hssrc=$1
local hsdst=$2
local tid=$3
eval local nsname=\${hs_t${tid}_${hssrc}}
ip netns exec hs-t${tid}-${hssrc} ping -c 1 -W ${PING_TIMEOUT_SEC} \
ip netns exec ${nsname} ping -c 1 -W ${PING_TIMEOUT_SEC} \
${IPv6_HS_NETWORK}::${hsdst} >/dev/null 2>&1
}
......
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