Commit 76ca2167 authored by Paolo Abeni's avatar Paolo Abeni

Merge branch 'conver-net-selftests-to-run-in-unique-namespace-part-1'

Hangbin Liu says:

====================
Conver net selftests to run in unique namespace (Part 1)

As Guillaume pointed, many selftests create namespaces with very common
names (like "client" or "server") or even (partially) run directly in init_net.
This makes these tests prone to failure if another namespace with the same
name already exists. It also makes it impossible to run several instances
of these tests in parallel.

This patch set intend to conver all the net selftests to run in unique namespace,
so we can update the selftest freamwork to run all tests in it's own namespace
in parallel. After update, we only need to wait for the test which need
longest time.

As the total patch set is too large. I break it to severl parts. This is
the first part.

v2 -> v3:
- Convert all ip netns del to cleanup_ns (Justin Iurman)

v1 -> v2:
- Split the large patch set to small parts for easy review (Paolo Abeni)
- Move busywait from forwarding/lib.sh to net/lib.sh directly (Petr Machata)
- Update setup_ns/cleanup_ns struct (Petr Machata)
- Remove default trap in lib.sh (Petr Machata)
====================

Link: https://lore.kernel.org/r/20231202020110.362433-1-liuhangbin@gmail.comSigned-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parents 333f3396 0f4765d0
...@@ -54,7 +54,7 @@ TEST_PROGS += ip_local_port_range.sh ...@@ -54,7 +54,7 @@ TEST_PROGS += ip_local_port_range.sh
TEST_PROGS += rps_default_mask.sh TEST_PROGS += rps_default_mask.sh
TEST_PROGS += big_tcp.sh TEST_PROGS += big_tcp.sh
TEST_PROGS_EXTENDED := in_netns.sh setup_loopback.sh setup_veth.sh TEST_PROGS_EXTENDED := in_netns.sh setup_loopback.sh setup_veth.sh
TEST_PROGS_EXTENDED += toeplitz_client.sh toeplitz.sh TEST_PROGS_EXTENDED += toeplitz_client.sh toeplitz.sh lib.sh
TEST_GEN_FILES = socket nettest TEST_GEN_FILES = socket nettest
TEST_GEN_FILES += psock_fanout psock_tpacket msg_zerocopy reuseport_addr_any TEST_GEN_FILES += psock_fanout psock_tpacket msg_zerocopy reuseport_addr_any
TEST_GEN_FILES += tcp_mmap tcp_inq psock_snd txring_overwrite TEST_GEN_FILES += tcp_mmap tcp_inq psock_snd txring_overwrite
......
...@@ -12,7 +12,8 @@ ...@@ -12,7 +12,8 @@
# {arp,ndisc}_evict_nocarrer=0 should still contain the single ARP/ND entry # {arp,ndisc}_evict_nocarrer=0 should still contain the single ARP/ND entry
# #
readonly PEER_NS="ns-peer-$(mktemp -u XXXXXX)" source lib.sh
readonly V4_ADDR0=10.0.10.1 readonly V4_ADDR0=10.0.10.1
readonly V4_ADDR1=10.0.10.2 readonly V4_ADDR1=10.0.10.2
readonly V6_ADDR0=2001:db8:91::1 readonly V6_ADDR0=2001:db8:91::1
...@@ -22,43 +23,29 @@ ret=0 ...@@ -22,43 +23,29 @@ ret=0
cleanup_v6() cleanup_v6()
{ {
ip netns del me cleanup_ns ${me} ${peer}
ip netns del peer
sysctl -w net.ipv6.conf.veth1.ndisc_evict_nocarrier=1 >/dev/null 2>&1 sysctl -w net.ipv6.conf.veth1.ndisc_evict_nocarrier=1 >/dev/null 2>&1
sysctl -w net.ipv6.conf.all.ndisc_evict_nocarrier=1 >/dev/null 2>&1 sysctl -w net.ipv6.conf.all.ndisc_evict_nocarrier=1 >/dev/null 2>&1
} }
create_ns()
{
local n=${1}
ip netns del ${n} 2>/dev/null
ip netns add ${n}
ip netns set ${n} $((nsid++))
ip -netns ${n} link set lo up
}
setup_v6() { setup_v6() {
create_ns me setup_ns me peer
create_ns peer
IP="ip -netns me" IP="ip -netns ${me}"
$IP li add veth1 type veth peer name veth2 $IP li add veth1 type veth peer name veth2
$IP li set veth1 up $IP li set veth1 up
$IP -6 addr add $V6_ADDR0/64 dev veth1 nodad $IP -6 addr add $V6_ADDR0/64 dev veth1 nodad
$IP li set veth2 netns peer up $IP li set veth2 netns ${peer} up
ip -netns peer -6 addr add $V6_ADDR1/64 dev veth2 nodad ip -netns ${peer} -6 addr add $V6_ADDR1/64 dev veth2 nodad
ip netns exec me sysctl -w $1 >/dev/null 2>&1 ip netns exec ${me} sysctl -w $1 >/dev/null 2>&1
# Establish an ND cache entry # Establish an ND cache entry
ip netns exec me ping -6 -c1 -Iveth1 $V6_ADDR1 >/dev/null 2>&1 ip netns exec ${me} ping -6 -c1 -Iveth1 $V6_ADDR1 >/dev/null 2>&1
# Should have the veth1 entry in ND table # Should have the veth1 entry in ND table
ip netns exec me ip -6 neigh get $V6_ADDR1 dev veth1 >/dev/null 2>&1 ip netns exec ${me} ip -6 neigh get $V6_ADDR1 dev veth1 >/dev/null 2>&1
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
cleanup_v6 cleanup_v6
echo "failed" echo "failed"
...@@ -66,11 +53,11 @@ setup_v6() { ...@@ -66,11 +53,11 @@ setup_v6() {
fi fi
# Set veth2 down, which will put veth1 in NOCARRIER state # Set veth2 down, which will put veth1 in NOCARRIER state
ip netns exec peer ip link set veth2 down ip netns exec ${peer} ip link set veth2 down
} }
setup_v4() { setup_v4() {
ip netns add "${PEER_NS}" setup_ns PEER_NS
ip link add name veth0 type veth peer name veth1 ip link add name veth0 type veth peer name veth1
ip link set dev veth0 up ip link set dev veth0 up
ip link set dev veth1 netns "${PEER_NS}" ip link set dev veth1 netns "${PEER_NS}"
...@@ -99,8 +86,7 @@ setup_v4() { ...@@ -99,8 +86,7 @@ setup_v4() {
cleanup_v4() { cleanup_v4() {
ip neigh flush dev veth0 ip neigh flush dev veth0
ip link del veth0 ip link del veth0
local -r ns="$(ip netns list|grep $PEER_NS)" cleanup_ns $PEER_NS
[ -n "$ns" ] && ip netns del $ns 2>/dev/null
sysctl -w net.ipv4.conf.veth0.arp_evict_nocarrier=1 >/dev/null 2>&1 sysctl -w net.ipv4.conf.veth0.arp_evict_nocarrier=1 >/dev/null 2>&1
sysctl -w net.ipv4.conf.all.arp_evict_nocarrier=1 >/dev/null 2>&1 sysctl -w net.ipv4.conf.all.arp_evict_nocarrier=1 >/dev/null 2>&1
...@@ -163,7 +149,7 @@ run_ndisc_evict_nocarrier_enabled() { ...@@ -163,7 +149,7 @@ run_ndisc_evict_nocarrier_enabled() {
setup_v6 "net.ipv6.conf.veth1.ndisc_evict_nocarrier=1" setup_v6 "net.ipv6.conf.veth1.ndisc_evict_nocarrier=1"
ip netns exec me ip -6 neigh get $V6_ADDR1 dev veth1 >/dev/null 2>&1 ip netns exec ${me} ip -6 neigh get $V6_ADDR1 dev veth1 >/dev/null 2>&1
if [ $? -eq 0 ];then if [ $? -eq 0 ];then
echo "failed" echo "failed"
...@@ -180,7 +166,7 @@ run_ndisc_evict_nocarrier_disabled() { ...@@ -180,7 +166,7 @@ run_ndisc_evict_nocarrier_disabled() {
setup_v6 "net.ipv6.conf.veth1.ndisc_evict_nocarrier=0" setup_v6 "net.ipv6.conf.veth1.ndisc_evict_nocarrier=0"
ip netns exec me ip -6 neigh get $V6_ADDR1 dev veth1 >/dev/null 2>&1 ip netns exec ${me} ip -6 neigh get $V6_ADDR1 dev veth1 >/dev/null 2>&1
if [ $? -eq 0 ];then if [ $? -eq 0 ];then
echo "ok" echo "ok"
...@@ -197,7 +183,7 @@ run_ndisc_evict_nocarrier_disabled_all() { ...@@ -197,7 +183,7 @@ run_ndisc_evict_nocarrier_disabled_all() {
setup_v6 "net.ipv6.conf.all.ndisc_evict_nocarrier=0" setup_v6 "net.ipv6.conf.all.ndisc_evict_nocarrier=0"
ip netns exec me ip -6 neigh get $V6_ADDR1 dev veth1 >/dev/null 2>&1 ip netns exec ${me} ip -6 neigh get $V6_ADDR1 dev veth1 >/dev/null 2>&1
if [ $? -eq 0 ];then if [ $? -eq 0 ];then
echo "ok" echo "ok"
......
...@@ -5,16 +5,14 @@ ...@@ -5,16 +5,14 @@
# garp to the router. Router accepts or ignores based on its arp_accept # garp to the router. Router accepts or ignores based on its arp_accept
# or accept_untracked_na configuration. # or accept_untracked_na configuration.
source lib.sh
TESTS="arp ndisc" TESTS="arp ndisc"
ROUTER_NS="ns-router"
ROUTER_NS_V6="ns-router-v6"
ROUTER_INTF="veth-router" ROUTER_INTF="veth-router"
ROUTER_ADDR="10.0.10.1" ROUTER_ADDR="10.0.10.1"
ROUTER_ADDR_V6="2001:db8:abcd:0012::1" ROUTER_ADDR_V6="2001:db8:abcd:0012::1"
HOST_NS="ns-host"
HOST_NS_V6="ns-host-v6"
HOST_INTF="veth-host" HOST_INTF="veth-host"
HOST_ADDR="10.0.10.2" HOST_ADDR="10.0.10.2"
HOST_ADDR_V6="2001:db8:abcd:0012::2" HOST_ADDR_V6="2001:db8:abcd:0012::2"
...@@ -23,13 +21,11 @@ SUBNET_WIDTH=24 ...@@ -23,13 +21,11 @@ SUBNET_WIDTH=24
PREFIX_WIDTH_V6=64 PREFIX_WIDTH_V6=64
cleanup() { cleanup() {
ip netns del ${HOST_NS} cleanup_ns ${HOST_NS} ${ROUTER_NS}
ip netns del ${ROUTER_NS}
} }
cleanup_v6() { cleanup_v6() {
ip netns del ${HOST_NS_V6} cleanup_ns ${HOST_NS_V6} ${ROUTER_NS_V6}
ip netns del ${ROUTER_NS_V6}
} }
setup() { setup() {
...@@ -37,8 +33,7 @@ setup() { ...@@ -37,8 +33,7 @@ setup() {
local arp_accept=$1 local arp_accept=$1
# Set up two namespaces # Set up two namespaces
ip netns add ${ROUTER_NS} setup_ns HOST_NS ROUTER_NS
ip netns add ${HOST_NS}
# Set up interfaces veth0 and veth1, which are pairs in separate # Set up interfaces veth0 and veth1, which are pairs in separate
# namespaces. veth0 is veth-router, veth1 is veth-host. # namespaces. veth0 is veth-router, veth1 is veth-host.
...@@ -72,8 +67,7 @@ setup_v6() { ...@@ -72,8 +67,7 @@ setup_v6() {
local accept_untracked_na=$1 local accept_untracked_na=$1
# Set up two namespaces # Set up two namespaces
ip netns add ${ROUTER_NS_V6} setup_ns HOST_NS_V6 ROUTER_NS_V6
ip netns add ${HOST_NS_V6}
# Set up interfaces veth0 and veth1, which are pairs in separate # Set up interfaces veth0 and veth1, which are pairs in separate
# namespaces. veth0 is veth-router, veth1 is veth-host. # namespaces. veth0 is veth-router, veth1 is veth-host.
...@@ -150,7 +144,7 @@ arp_test_gratuitous() { ...@@ -150,7 +144,7 @@ arp_test_gratuitous() {
fi fi
# Supply arp_accept option to set up which sets it in sysctl # Supply arp_accept option to set up which sets it in sysctl
setup ${arp_accept} setup ${arp_accept}
ip netns exec ${HOST_NS} arping -A -U ${HOST_ADDR} -c1 2>&1 >/dev/null ip netns exec ${HOST_NS} arping -A -I ${HOST_INTF} -U ${HOST_ADDR} -c1 2>&1 >/dev/null
if verify_arp $1 $2; then if verify_arp $1 $2; then
printf " TEST: %-60s [ OK ]\n" "${test_msg[*]}" printf " TEST: %-60s [ OK ]\n" "${test_msg[*]}"
......
#!/bin/bash #!/bin/bash
# SPDX-License-Identifier: GPL-2.0 # SPDX-License-Identifier: GPL-2.0
ksft_skip=4 source lib.sh
NS=ns
IP6=2001:db8:1::1/64 IP6=2001:db8:1::1/64
TGT6=2001:db8:1::2 TGT6=2001:db8:1::2
TMPF=$(mktemp --suffix ".pcap") TMPF=$(mktemp --suffix ".pcap")
...@@ -11,13 +10,11 @@ TMPF=$(mktemp --suffix ".pcap") ...@@ -11,13 +10,11 @@ TMPF=$(mktemp --suffix ".pcap")
cleanup() cleanup()
{ {
rm -f $TMPF rm -f $TMPF
ip netns del $NS cleanup_ns $NS
} }
trap cleanup EXIT trap cleanup EXIT
NSEXE="ip netns exec $NS"
tcpdump -h | grep immediate-mode >> /dev/null tcpdump -h | grep immediate-mode >> /dev/null
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "SKIP - tcpdump with --immediate-mode option required" echo "SKIP - tcpdump with --immediate-mode option required"
...@@ -25,7 +22,8 @@ if [ $? -ne 0 ]; then ...@@ -25,7 +22,8 @@ if [ $? -ne 0 ]; then
fi fi
# Namespaces # Namespaces
ip netns add $NS setup_ns NS
NSEXE="ip netns exec $NS"
$NSEXE sysctl -w net.ipv4.ping_group_range='0 2147483647' > /dev/null $NSEXE sysctl -w net.ipv4.ping_group_range='0 2147483647' > /dev/null
......
#!/bin/bash #!/bin/bash
# SPDX-License-Identifier: GPL-2.0 # SPDX-License-Identifier: GPL-2.0
NS=ns source lib.sh
IP4=172.16.0.1/24 IP4=172.16.0.1/24
TGT4=172.16.0.2 TGT4=172.16.0.2
IP6=2001:db8:1::1/64 IP6=2001:db8:1::1/64
...@@ -10,13 +11,13 @@ MARK=1000 ...@@ -10,13 +11,13 @@ MARK=1000
cleanup() cleanup()
{ {
ip netns del $NS cleanup_ns $NS
} }
trap cleanup EXIT trap cleanup EXIT
# Namespaces # Namespaces
ip netns add $NS setup_ns NS
ip netns exec $NS sysctl -w net.ipv4.ping_group_range='0 2147483647' > /dev/null ip netns exec $NS sysctl -w net.ipv4.ping_group_range='0 2147483647' > /dev/null
......
#!/bin/bash #!/bin/bash
# SPDX-License-Identifier: GPL-2.0 # SPDX-License-Identifier: GPL-2.0
NS=ns source lib.sh
IP4=172.16.0.1/24 IP4=172.16.0.1/24
TGT4=172.16.0.2 TGT4=172.16.0.2
IP6=2001:db8:1::1/64 IP6=2001:db8:1::1/64
...@@ -9,13 +10,13 @@ TGT6=2001:db8:1::2 ...@@ -9,13 +10,13 @@ TGT6=2001:db8:1::2
cleanup() cleanup()
{ {
ip netns del $NS cleanup_ns $NS
} }
trap cleanup EXIT trap cleanup EXIT
# Namespaces # Namespaces
ip netns add $NS setup_ns NS
ip netns exec $NS sysctl -w net.ipv4.ping_group_range='0 2147483647' > /dev/null ip netns exec $NS sysctl -w net.ipv4.ping_group_range='0 2147483647' > /dev/null
......
...@@ -2,10 +2,8 @@ ...@@ -2,10 +2,8 @@
# SPDX-License-Identifier: GPL-2.0 # SPDX-License-Identifier: GPL-2.0
# This test is for checking drop monitor functionality. # This test is for checking drop monitor functionality.
source lib.sh
ret=0 ret=0
# Kselftest framework requirement - SKIP code is 4.
ksft_skip=4
# all tests in this script. Can be overridden with -t option # all tests in this script. Can be overridden with -t option
TESTS=" TESTS="
...@@ -13,10 +11,6 @@ TESTS=" ...@@ -13,10 +11,6 @@ TESTS="
hw_drops hw_drops
" "
IP="ip -netns ns1"
TC="tc -netns ns1"
DEVLINK="devlink -N ns1"
NS_EXEC="ip netns exec ns1"
NETDEVSIM_PATH=/sys/bus/netdevsim/ NETDEVSIM_PATH=/sys/bus/netdevsim/
DEV_ADDR=1337 DEV_ADDR=1337
DEV=netdevsim${DEV_ADDR} DEV=netdevsim${DEV_ADDR}
...@@ -43,7 +37,7 @@ setup() ...@@ -43,7 +37,7 @@ setup()
modprobe netdevsim &> /dev/null modprobe netdevsim &> /dev/null
set -e set -e
ip netns add ns1 setup_ns NS1
$IP link add dummy10 up type dummy $IP link add dummy10 up type dummy
$NS_EXEC echo "$DEV_ADDR 1" > ${NETDEVSIM_PATH}/new_device $NS_EXEC echo "$DEV_ADDR 1" > ${NETDEVSIM_PATH}/new_device
...@@ -57,7 +51,7 @@ setup() ...@@ -57,7 +51,7 @@ setup()
cleanup() cleanup()
{ {
$NS_EXEC echo "$DEV_ADDR" > ${NETDEVSIM_PATH}/del_device $NS_EXEC echo "$DEV_ADDR" > ${NETDEVSIM_PATH}/del_device
ip netns del ns1 cleanup_ns ${NS1}
} }
sw_drops_test() sw_drops_test()
...@@ -194,8 +188,15 @@ if [ $? -ne 0 ]; then ...@@ -194,8 +188,15 @@ if [ $? -ne 0 ]; then
exit $ksft_skip exit $ksft_skip
fi fi
# start clean # create netns first so we can get the namespace name
setup_ns NS1
cleanup &> /dev/null cleanup &> /dev/null
trap cleanup EXIT
IP="ip -netns ${NS1}"
TC="tc -netns ${NS1}"
DEVLINK="devlink -N ${NS1}"
NS_EXEC="ip netns exec ${NS1}"
for t in $TESTS for t in $TESTS
do do
......
...@@ -4,9 +4,6 @@ ...@@ -4,9 +4,6 @@
############################################################################## ##############################################################################
# Defines # Defines
# Kselftest framework requirement - SKIP code is 4.
ksft_skip=4
# Can be overridden by the configuration file. # Can be overridden by the configuration file.
PING=${PING:=ping} PING=${PING:=ping}
PING6=${PING6:=ping6} PING6=${PING6:=ping6}
...@@ -41,6 +38,7 @@ if [[ -f $relative_path/forwarding.config ]]; then ...@@ -41,6 +38,7 @@ if [[ -f $relative_path/forwarding.config ]]; then
source "$relative_path/forwarding.config" source "$relative_path/forwarding.config"
fi fi
source ../lib.sh
############################################################################## ##############################################################################
# Sanity checks # Sanity checks
...@@ -395,29 +393,6 @@ log_info() ...@@ -395,29 +393,6 @@ log_info()
echo "INFO: $msg" echo "INFO: $msg"
} }
busywait()
{
local timeout=$1; shift
local start_time="$(date -u +%s%3N)"
while true
do
local out
out=$("$@")
local ret=$?
if ((!ret)); then
echo -n "$out"
return 0
fi
local current_time="$(date -u +%s%3N)"
if ((current_time - start_time > timeout)); then
echo -n "$out"
return 1
fi
done
}
not() not()
{ {
"$@" "$@"
......
...@@ -18,8 +18,8 @@ ...@@ -18,8 +18,8 @@
# that address space, so the kernel should substitute the dummy address # that address space, so the kernel should substitute the dummy address
# 192.0.0.8 defined in RFC7600. # 192.0.0.8 defined in RFC7600.
NS1=ns1 source lib.sh
NS2=ns2
H1_IP=172.16.0.1/32 H1_IP=172.16.0.1/32
H1_IP6=2001:db8:1::1 H1_IP6=2001:db8:1::1
RT1=172.16.1.0/24 RT1=172.16.1.0/24
...@@ -32,15 +32,13 @@ TMPFILE=$(mktemp) ...@@ -32,15 +32,13 @@ TMPFILE=$(mktemp)
cleanup() cleanup()
{ {
rm -f "$TMPFILE" rm -f "$TMPFILE"
ip netns del $NS1 cleanup_ns $NS1 $NS2
ip netns del $NS2
} }
trap cleanup EXIT trap cleanup EXIT
# Namespaces # Namespaces
ip netns add $NS1 setup_ns NS1 NS2
ip netns add $NS2
# Connectivity # Connectivity
ip -netns $NS1 link add veth0 type veth peer name veth0 netns $NS2 ip -netns $NS1 link add veth0 type veth peer name veth0 netns $NS2
......
This diff is collapsed.
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
# 10.1.1.1 | | 10.1.2.1 # 10.1.1.1 | | 10.1.2.1
# 2001:db8:1::1 | | 2001:db8:2::1 # 2001:db8:1::1 | | 2001:db8:2::1
source lib.sh
VERBOSE=0 VERBOSE=0
PAUSE_ON_FAIL=no PAUSE_ON_FAIL=no
...@@ -80,9 +81,6 @@ create_ns() ...@@ -80,9 +81,6 @@ create_ns()
[ -z "${addr}" ] && addr="-" [ -z "${addr}" ] && addr="-"
[ -z "${addr6}" ] && addr6="-" [ -z "${addr6}" ] && addr6="-"
ip netns add ${ns}
ip -netns ${ns} link set lo up
if [ "${addr}" != "-" ]; then if [ "${addr}" != "-" ]; then
ip -netns ${ns} addr add dev lo ${addr} ip -netns ${ns} addr add dev lo ${addr}
fi fi
...@@ -133,12 +131,7 @@ connect_ns() ...@@ -133,12 +131,7 @@ connect_ns()
cleanup() cleanup()
{ {
local ns cleanup_ns $host_1 $host_2 $router
for ns in host-1 host-2 router
do
ip netns del ${ns} 2>/dev/null
done
} }
setup_l2tp_ipv4() setup_l2tp_ipv4()
...@@ -146,28 +139,28 @@ setup_l2tp_ipv4() ...@@ -146,28 +139,28 @@ setup_l2tp_ipv4()
# #
# configure l2tpv3 tunnel on host-1 # configure l2tpv3 tunnel on host-1
# #
ip -netns host-1 l2tp add tunnel tunnel_id 1041 peer_tunnel_id 1042 \ ip -netns $host_1 l2tp add tunnel tunnel_id 1041 peer_tunnel_id 1042 \
encap ip local 10.1.1.1 remote 10.1.2.1 encap ip local 10.1.1.1 remote 10.1.2.1
ip -netns host-1 l2tp add session name l2tp4 tunnel_id 1041 \ ip -netns $host_1 l2tp add session name l2tp4 tunnel_id 1041 \
session_id 1041 peer_session_id 1042 session_id 1041 peer_session_id 1042
ip -netns host-1 link set dev l2tp4 up ip -netns $host_1 link set dev l2tp4 up
ip -netns host-1 addr add dev l2tp4 172.16.1.1 peer 172.16.1.2 ip -netns $host_1 addr add dev l2tp4 172.16.1.1 peer 172.16.1.2
# #
# configure l2tpv3 tunnel on host-2 # configure l2tpv3 tunnel on host-2
# #
ip -netns host-2 l2tp add tunnel tunnel_id 1042 peer_tunnel_id 1041 \ ip -netns $host_2 l2tp add tunnel tunnel_id 1042 peer_tunnel_id 1041 \
encap ip local 10.1.2.1 remote 10.1.1.1 encap ip local 10.1.2.1 remote 10.1.1.1
ip -netns host-2 l2tp add session name l2tp4 tunnel_id 1042 \ ip -netns $host_2 l2tp add session name l2tp4 tunnel_id 1042 \
session_id 1042 peer_session_id 1041 session_id 1042 peer_session_id 1041
ip -netns host-2 link set dev l2tp4 up ip -netns $host_2 link set dev l2tp4 up
ip -netns host-2 addr add dev l2tp4 172.16.1.2 peer 172.16.1.1 ip -netns $host_2 addr add dev l2tp4 172.16.1.2 peer 172.16.1.1
# #
# add routes to loopback addresses # add routes to loopback addresses
# #
ip -netns host-1 ro add 172.16.101.2/32 via 172.16.1.2 ip -netns $host_1 ro add 172.16.101.2/32 via 172.16.1.2
ip -netns host-2 ro add 172.16.101.1/32 via 172.16.1.1 ip -netns $host_2 ro add 172.16.101.1/32 via 172.16.1.1
} }
setup_l2tp_ipv6() setup_l2tp_ipv6()
...@@ -175,28 +168,28 @@ setup_l2tp_ipv6() ...@@ -175,28 +168,28 @@ setup_l2tp_ipv6()
# #
# configure l2tpv3 tunnel on host-1 # configure l2tpv3 tunnel on host-1
# #
ip -netns host-1 l2tp add tunnel tunnel_id 1061 peer_tunnel_id 1062 \ ip -netns $host_1 l2tp add tunnel tunnel_id 1061 peer_tunnel_id 1062 \
encap ip local 2001:db8:1::1 remote 2001:db8:2::1 encap ip local 2001:db8:1::1 remote 2001:db8:2::1
ip -netns host-1 l2tp add session name l2tp6 tunnel_id 1061 \ ip -netns $host_1 l2tp add session name l2tp6 tunnel_id 1061 \
session_id 1061 peer_session_id 1062 session_id 1061 peer_session_id 1062
ip -netns host-1 link set dev l2tp6 up ip -netns $host_1 link set dev l2tp6 up
ip -netns host-1 addr add dev l2tp6 fc00:1::1 peer fc00:1::2 ip -netns $host_1 addr add dev l2tp6 fc00:1::1 peer fc00:1::2
# #
# configure l2tpv3 tunnel on host-2 # configure l2tpv3 tunnel on host-2
# #
ip -netns host-2 l2tp add tunnel tunnel_id 1062 peer_tunnel_id 1061 \ ip -netns $host_2 l2tp add tunnel tunnel_id 1062 peer_tunnel_id 1061 \
encap ip local 2001:db8:2::1 remote 2001:db8:1::1 encap ip local 2001:db8:2::1 remote 2001:db8:1::1
ip -netns host-2 l2tp add session name l2tp6 tunnel_id 1062 \ ip -netns $host_2 l2tp add session name l2tp6 tunnel_id 1062 \
session_id 1062 peer_session_id 1061 session_id 1062 peer_session_id 1061
ip -netns host-2 link set dev l2tp6 up ip -netns $host_2 link set dev l2tp6 up
ip -netns host-2 addr add dev l2tp6 fc00:1::2 peer fc00:1::1 ip -netns $host_2 addr add dev l2tp6 fc00:1::2 peer fc00:1::1
# #
# add routes to loopback addresses # add routes to loopback addresses
# #
ip -netns host-1 -6 ro add fc00:101::2/128 via fc00:1::2 ip -netns $host_1 -6 ro add fc00:101::2/128 via fc00:1::2
ip -netns host-2 -6 ro add fc00:101::1/128 via fc00:1::1 ip -netns $host_2 -6 ro add fc00:101::1/128 via fc00:1::1
} }
setup() setup()
...@@ -205,21 +198,22 @@ setup() ...@@ -205,21 +198,22 @@ setup()
cleanup cleanup
set -e set -e
create_ns host-1 172.16.101.1/32 fc00:101::1/128 setup_ns host_1 host_2 router
create_ns host-2 172.16.101.2/32 fc00:101::2/128 create_ns $host_1 172.16.101.1/32 fc00:101::1/128
create_ns router create_ns $host_2 172.16.101.2/32 fc00:101::2/128
create_ns $router
connect_ns host-1 eth0 10.1.1.1/24 2001:db8:1::1/64 \ connect_ns $host_1 eth0 10.1.1.1/24 2001:db8:1::1/64 \
router eth1 10.1.1.2/24 2001:db8:1::2/64 $router eth1 10.1.1.2/24 2001:db8:1::2/64
connect_ns host-2 eth0 10.1.2.1/24 2001:db8:2::1/64 \ connect_ns $host_2 eth0 10.1.2.1/24 2001:db8:2::1/64 \
router eth2 10.1.2.2/24 2001:db8:2::2/64 $router eth2 10.1.2.2/24 2001:db8:2::2/64
ip -netns host-1 ro add 10.1.2.0/24 via 10.1.1.2 ip -netns $host_1 ro add 10.1.2.0/24 via 10.1.1.2
ip -netns host-1 -6 ro add 2001:db8:2::/64 via 2001:db8:1::2 ip -netns $host_1 -6 ro add 2001:db8:2::/64 via 2001:db8:1::2
ip -netns host-2 ro add 10.1.1.0/24 via 10.1.2.2 ip -netns $host_2 ro add 10.1.1.0/24 via 10.1.2.2
ip -netns host-2 -6 ro add 2001:db8:1::/64 via 2001:db8:2::2 ip -netns $host_2 -6 ro add 2001:db8:1::/64 via 2001:db8:2::2
setup_l2tp_ipv4 setup_l2tp_ipv4
setup_l2tp_ipv6 setup_l2tp_ipv6
...@@ -231,38 +225,38 @@ setup_ipsec() ...@@ -231,38 +225,38 @@ setup_ipsec()
# #
# IPv4 # IPv4
# #
run_cmd host-1 ip xfrm policy add \ run_cmd $host_1 ip xfrm policy add \
src 10.1.1.1 dst 10.1.2.1 dir out \ src 10.1.1.1 dst 10.1.2.1 dir out \
tmpl proto esp mode transport tmpl proto esp mode transport
run_cmd host-1 ip xfrm policy add \ run_cmd $host_1 ip xfrm policy add \
src 10.1.2.1 dst 10.1.1.1 dir in \ src 10.1.2.1 dst 10.1.1.1 dir in \
tmpl proto esp mode transport tmpl proto esp mode transport
run_cmd host-2 ip xfrm policy add \ run_cmd $host_2 ip xfrm policy add \
src 10.1.1.1 dst 10.1.2.1 dir in \ src 10.1.1.1 dst 10.1.2.1 dir in \
tmpl proto esp mode transport tmpl proto esp mode transport
run_cmd host-2 ip xfrm policy add \ run_cmd $host_2 ip xfrm policy add \
src 10.1.2.1 dst 10.1.1.1 dir out \ src 10.1.2.1 dst 10.1.1.1 dir out \
tmpl proto esp mode transport tmpl proto esp mode transport
ip -netns host-1 xfrm state add \ ip -netns $host_1 xfrm state add \
src 10.1.1.1 dst 10.1.2.1 \ src 10.1.1.1 dst 10.1.2.1 \
spi 0x1000 proto esp aead 'rfc4106(gcm(aes))' \ spi 0x1000 proto esp aead 'rfc4106(gcm(aes))' \
0x0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f 128 mode transport 0x0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f 128 mode transport
ip -netns host-1 xfrm state add \ ip -netns $host_1 xfrm state add \
src 10.1.2.1 dst 10.1.1.1 \ src 10.1.2.1 dst 10.1.1.1 \
spi 0x1001 proto esp aead 'rfc4106(gcm(aes))' \ spi 0x1001 proto esp aead 'rfc4106(gcm(aes))' \
0x0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f 128 mode transport 0x0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f 128 mode transport
ip -netns host-2 xfrm state add \ ip -netns $host_2 xfrm state add \
src 10.1.1.1 dst 10.1.2.1 \ src 10.1.1.1 dst 10.1.2.1 \
spi 0x1000 proto esp aead 'rfc4106(gcm(aes))' \ spi 0x1000 proto esp aead 'rfc4106(gcm(aes))' \
0x0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f 128 mode transport 0x0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f 128 mode transport
ip -netns host-2 xfrm state add \ ip -netns $host_2 xfrm state add \
src 10.1.2.1 dst 10.1.1.1 \ src 10.1.2.1 dst 10.1.1.1 \
spi 0x1001 proto esp aead 'rfc4106(gcm(aes))' \ spi 0x1001 proto esp aead 'rfc4106(gcm(aes))' \
0x0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f 128 mode transport 0x0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f 128 mode transport
...@@ -270,38 +264,38 @@ setup_ipsec() ...@@ -270,38 +264,38 @@ setup_ipsec()
# #
# IPV6 # IPV6
# #
run_cmd host-1 ip -6 xfrm policy add \ run_cmd $host_1 ip -6 xfrm policy add \
src 2001:db8:1::1 dst 2001:db8:2::1 dir out \ src 2001:db8:1::1 dst 2001:db8:2::1 dir out \
tmpl proto esp mode transport tmpl proto esp mode transport
run_cmd host-1 ip -6 xfrm policy add \ run_cmd $host_1 ip -6 xfrm policy add \
src 2001:db8:2::1 dst 2001:db8:1::1 dir in \ src 2001:db8:2::1 dst 2001:db8:1::1 dir in \
tmpl proto esp mode transport tmpl proto esp mode transport
run_cmd host-2 ip -6 xfrm policy add \ run_cmd $host_2 ip -6 xfrm policy add \
src 2001:db8:1::1 dst 2001:db8:2::1 dir in \ src 2001:db8:1::1 dst 2001:db8:2::1 dir in \
tmpl proto esp mode transport tmpl proto esp mode transport
run_cmd host-2 ip -6 xfrm policy add \ run_cmd $host_2 ip -6 xfrm policy add \
src 2001:db8:2::1 dst 2001:db8:1::1 dir out \ src 2001:db8:2::1 dst 2001:db8:1::1 dir out \
tmpl proto esp mode transport tmpl proto esp mode transport
ip -netns host-1 -6 xfrm state add \ ip -netns $host_1 -6 xfrm state add \
src 2001:db8:1::1 dst 2001:db8:2::1 \ src 2001:db8:1::1 dst 2001:db8:2::1 \
spi 0x1000 proto esp aead 'rfc4106(gcm(aes))' \ spi 0x1000 proto esp aead 'rfc4106(gcm(aes))' \
0x0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f 128 mode transport 0x0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f 128 mode transport
ip -netns host-1 -6 xfrm state add \ ip -netns $host_1 -6 xfrm state add \
src 2001:db8:2::1 dst 2001:db8:1::1 \ src 2001:db8:2::1 dst 2001:db8:1::1 \
spi 0x1001 proto esp aead 'rfc4106(gcm(aes))' \ spi 0x1001 proto esp aead 'rfc4106(gcm(aes))' \
0x0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f 128 mode transport 0x0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f 128 mode transport
ip -netns host-2 -6 xfrm state add \ ip -netns $host_2 -6 xfrm state add \
src 2001:db8:1::1 dst 2001:db8:2::1 \ src 2001:db8:1::1 dst 2001:db8:2::1 \
spi 0x1000 proto esp aead 'rfc4106(gcm(aes))' \ spi 0x1000 proto esp aead 'rfc4106(gcm(aes))' \
0x0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f 128 mode transport 0x0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f 128 mode transport
ip -netns host-2 -6 xfrm state add \ ip -netns $host_2 -6 xfrm state add \
src 2001:db8:2::1 dst 2001:db8:1::1 \ src 2001:db8:2::1 dst 2001:db8:1::1 \
spi 0x1001 proto esp aead 'rfc4106(gcm(aes))' \ spi 0x1001 proto esp aead 'rfc4106(gcm(aes))' \
0x0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f 128 mode transport 0x0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f 128 mode transport
...@@ -309,10 +303,10 @@ setup_ipsec() ...@@ -309,10 +303,10 @@ setup_ipsec()
teardown_ipsec() teardown_ipsec()
{ {
run_cmd host-1 ip xfrm state flush run_cmd $host_1 ip xfrm state flush
run_cmd host-1 ip xfrm policy flush run_cmd $host_1 ip xfrm policy flush
run_cmd host-2 ip xfrm state flush run_cmd $host_2 ip xfrm state flush
run_cmd host-2 ip xfrm policy flush run_cmd $host_2 ip xfrm policy flush
} }
################################################################################ ################################################################################
...@@ -322,16 +316,16 @@ run_ping() ...@@ -322,16 +316,16 @@ run_ping()
{ {
local desc="$1" local desc="$1"
run_cmd host-1 ping -c1 -w1 172.16.1.2 run_cmd $host_1 ping -c1 -w1 172.16.1.2
log_test $? 0 "IPv4 basic L2TP tunnel ${desc}" log_test $? 0 "IPv4 basic L2TP tunnel ${desc}"
run_cmd host-1 ping -c1 -w1 -I 172.16.101.1 172.16.101.2 run_cmd $host_1 ping -c1 -w1 -I 172.16.101.1 172.16.101.2
log_test $? 0 "IPv4 route through L2TP tunnel ${desc}" log_test $? 0 "IPv4 route through L2TP tunnel ${desc}"
run_cmd host-1 ${ping6} -c1 -w1 fc00:1::2 run_cmd $host_1 ${ping6} -c1 -w1 fc00:1::2
log_test $? 0 "IPv6 basic L2TP tunnel ${desc}" log_test $? 0 "IPv6 basic L2TP tunnel ${desc}"
run_cmd host-1 ${ping6} -c1 -w1 -I fc00:101::1 fc00:101::2 run_cmd $host_1 ${ping6} -c1 -w1 -I fc00:101::1 fc00:101::2
log_test $? 0 "IPv6 route through L2TP tunnel ${desc}" log_test $? 0 "IPv6 route through L2TP tunnel ${desc}"
} }
...@@ -344,16 +338,16 @@ run_tests() ...@@ -344,16 +338,16 @@ run_tests()
setup_ipsec setup_ipsec
run_ping "- with IPsec" run_ping "- with IPsec"
run_cmd host-1 ping -c1 -w1 172.16.1.2 run_cmd $host_1 ping -c1 -w1 172.16.1.2
log_test $? 0 "IPv4 basic L2TP tunnel ${desc}" log_test $? 0 "IPv4 basic L2TP tunnel ${desc}"
run_cmd host-1 ping -c1 -w1 -I 172.16.101.1 172.16.101.2 run_cmd $host_1 ping -c1 -w1 -I 172.16.101.1 172.16.101.2
log_test $? 0 "IPv4 route through L2TP tunnel ${desc}" log_test $? 0 "IPv4 route through L2TP tunnel ${desc}"
run_cmd host-1 ${ping6} -c1 -w1 fc00:1::2 run_cmd $host_1 ${ping6} -c1 -w1 fc00:1::2
log_test $? 0 "IPv6 basic L2TP tunnel - with IPsec" log_test $? 0 "IPv6 basic L2TP tunnel - with IPsec"
run_cmd host-1 ${ping6} -c1 -w1 -I fc00:101::1 fc00:101::2 run_cmd $host_1 ${ping6} -c1 -w1 -I fc00:101::1 fc00:101::2
log_test $? 0 "IPv6 route through L2TP tunnel - with IPsec" log_test $? 0 "IPv6 route through L2TP tunnel - with IPsec"
teardown_ipsec teardown_ipsec
......
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
##############################################################################
# Defines
# Kselftest framework requirement - SKIP code is 4.
ksft_skip=4
##############################################################################
# Helpers
busywait()
{
local timeout=$1; shift
local start_time="$(date -u +%s%3N)"
while true
do
local out
out=$("$@")
local ret=$?
if ((!ret)); then
echo -n "$out"
return 0
fi
local current_time="$(date -u +%s%3N)"
if ((current_time - start_time > timeout)); then
echo -n "$out"
return 1
fi
done
}
cleanup_ns()
{
local ns=""
local errexit=0
local ret=0
# disable errexit temporary
if [[ $- =~ "e" ]]; then
errexit=1
set +e
fi
for ns in "$@"; do
ip netns delete "${ns}" &> /dev/null
if ! busywait 2 ip netns list \| grep -vq "^$ns$" &> /dev/null; then
echo "Warn: Failed to remove namespace $ns"
ret=1
fi
done
[ $errexit -eq 1 ] && set -e
return $ret
}
# setup netns with given names as prefix. e.g
# setup_ns local remote
setup_ns()
{
local ns=""
local ns_name=""
local ns_list=""
for ns_name in "$@"; do
# Some test may setup/remove same netns multi times
if unset ${ns_name} 2> /dev/null; then
ns="${ns_name,,}-$(mktemp -u XXXXXX)"
eval readonly ${ns_name}="$ns"
else
eval ns='$'${ns_name}
cleanup_ns "$ns"
fi
if ! ip netns add "$ns"; then
echo "Failed to create namespace $ns_name"
cleanup_ns "$ns_list"
return $ksft_skip
fi
ip -n "$ns" link set lo up
ns_list="$ns_list $ns"
done
}
...@@ -10,16 +10,12 @@ ...@@ -10,16 +10,12 @@
# 0 1 0 Don't update NC # 0 1 0 Don't update NC
# 0 1 1 Add a STALE NC entry # 0 1 1 Add a STALE NC entry
source lib.sh
ret=0 ret=0
# Kselftest framework requirement - SKIP code is 4.
ksft_skip=4
PAUSE_ON_FAIL=no PAUSE_ON_FAIL=no
PAUSE=no PAUSE=no
HOST_NS="ns-host"
ROUTER_NS="ns-router"
HOST_INTF="veth-host" HOST_INTF="veth-host"
ROUTER_INTF="veth-router" ROUTER_INTF="veth-router"
...@@ -29,11 +25,6 @@ SUBNET_WIDTH=64 ...@@ -29,11 +25,6 @@ SUBNET_WIDTH=64
ROUTER_ADDR_WITH_MASK="${ROUTER_ADDR}/${SUBNET_WIDTH}" ROUTER_ADDR_WITH_MASK="${ROUTER_ADDR}/${SUBNET_WIDTH}"
HOST_ADDR_WITH_MASK="${HOST_ADDR}/${SUBNET_WIDTH}" HOST_ADDR_WITH_MASK="${HOST_ADDR}/${SUBNET_WIDTH}"
IP_HOST="ip -6 -netns ${HOST_NS}"
IP_HOST_EXEC="ip netns exec ${HOST_NS}"
IP_ROUTER="ip -6 -netns ${ROUTER_NS}"
IP_ROUTER_EXEC="ip netns exec ${ROUTER_NS}"
tcpdump_stdout= tcpdump_stdout=
tcpdump_stderr= tcpdump_stderr=
...@@ -76,8 +67,12 @@ setup() ...@@ -76,8 +67,12 @@ setup()
# Setup two namespaces and a veth tunnel across them. # Setup two namespaces and a veth tunnel across them.
# On end of the tunnel is a router and the other end is a host. # On end of the tunnel is a router and the other end is a host.
ip netns add ${HOST_NS} setup_ns HOST_NS ROUTER_NS
ip netns add ${ROUTER_NS} IP_HOST="ip -6 -netns ${HOST_NS}"
IP_HOST_EXEC="ip netns exec ${HOST_NS}"
IP_ROUTER="ip -6 -netns ${ROUTER_NS}"
IP_ROUTER_EXEC="ip netns exec ${ROUTER_NS}"
${IP_ROUTER} link add ${ROUTER_INTF} type veth \ ${IP_ROUTER} link add ${ROUTER_INTF} type veth \
peer name ${HOST_INTF} netns ${HOST_NS} peer name ${HOST_INTF} netns ${HOST_NS}
......
...@@ -6,13 +6,11 @@ ...@@ -6,13 +6,11 @@
# SERVER_NS # SERVER_NS
# CLIENT_NS2 (veth1) <---> (veth2) -> vrf_s2 # CLIENT_NS2 (veth1) <---> (veth2) -> vrf_s2
CLIENT_NS1="client-ns1" source lib.sh
CLIENT_NS2="client-ns2"
CLIENT_IP4="10.0.0.1" CLIENT_IP4="10.0.0.1"
CLIENT_IP6="2000::1" CLIENT_IP6="2000::1"
CLIENT_PORT=1234 CLIENT_PORT=1234
SERVER_NS="server-ns"
SERVER_IP4="10.0.0.2" SERVER_IP4="10.0.0.2"
SERVER_IP6="2000::2" SERVER_IP6="2000::2"
SERVER_PORT=1234 SERVER_PORT=1234
...@@ -20,9 +18,7 @@ SERVER_PORT=1234 ...@@ -20,9 +18,7 @@ SERVER_PORT=1234
setup() { setup() {
modprobe sctp modprobe sctp
modprobe sctp_diag modprobe sctp_diag
ip netns add $CLIENT_NS1 setup_ns CLIENT_NS1 CLIENT_NS2 SERVER_NS
ip netns add $CLIENT_NS2
ip netns add $SERVER_NS
ip net exec $CLIENT_NS1 sysctl -w net.ipv6.conf.default.accept_dad=0 2>&1 >/dev/null ip net exec $CLIENT_NS1 sysctl -w net.ipv6.conf.default.accept_dad=0 2>&1 >/dev/null
ip net exec $CLIENT_NS2 sysctl -w net.ipv6.conf.default.accept_dad=0 2>&1 >/dev/null ip net exec $CLIENT_NS2 sysctl -w net.ipv6.conf.default.accept_dad=0 2>&1 >/dev/null
...@@ -67,9 +63,7 @@ setup() { ...@@ -67,9 +63,7 @@ setup() {
cleanup() { cleanup() {
ip netns exec $SERVER_NS pkill sctp_hello 2>&1 >/dev/null ip netns exec $SERVER_NS pkill sctp_hello 2>&1 >/dev/null
ip netns del "$CLIENT_NS1" cleanup_ns $CLIENT_NS1 $CLIENT_NS2 $SERVER_NS
ip netns del "$CLIENT_NS2"
ip netns del "$SERVER_NS"
} }
wait_server() { wait_server() {
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
# Run traceroute/traceroute6 tests # Run traceroute/traceroute6 tests
# #
source lib.sh
VERBOSE=0 VERBOSE=0
PAUSE_ON_FAIL=no PAUSE_ON_FAIL=no
...@@ -69,9 +70,6 @@ create_ns() ...@@ -69,9 +70,6 @@ create_ns()
[ -z "${addr}" ] && addr="-" [ -z "${addr}" ] && addr="-"
[ -z "${addr6}" ] && addr6="-" [ -z "${addr6}" ] && addr6="-"
ip netns add ${ns}
ip netns exec ${ns} ip link set lo up
if [ "${addr}" != "-" ]; then if [ "${addr}" != "-" ]; then
ip netns exec ${ns} ip addr add dev lo ${addr} ip netns exec ${ns} ip addr add dev lo ${addr}
fi fi
...@@ -160,12 +158,7 @@ connect_ns() ...@@ -160,12 +158,7 @@ connect_ns()
cleanup_traceroute6() cleanup_traceroute6()
{ {
local ns cleanup_ns $h1 $h2 $r1 $r2
for ns in host-1 host-2 router-1 router-2
do
ip netns del ${ns} 2>/dev/null
done
} }
setup_traceroute6() setup_traceroute6()
...@@ -176,33 +169,34 @@ setup_traceroute6() ...@@ -176,33 +169,34 @@ setup_traceroute6()
cleanup_traceroute6 cleanup_traceroute6
set -e set -e
create_ns host-1 setup_ns h1 h2 r1 r2
create_ns host-2 create_ns $h1
create_ns router-1 create_ns $h2
create_ns router-2 create_ns $r1
create_ns $r2
# Setup N3 # Setup N3
connect_ns router-2 eth3 - 2000:103::2/64 host-2 eth3 - 2000:103::4/64 connect_ns $r2 eth3 - 2000:103::2/64 $h2 eth3 - 2000:103::4/64
ip netns exec host-2 ip route add default via 2000:103::2 ip netns exec $h2 ip route add default via 2000:103::2
# Setup N2 # Setup N2
connect_ns router-1 eth2 - 2000:102::1/64 router-2 eth2 - 2000:102::2/64 connect_ns $r1 eth2 - 2000:102::1/64 $r2 eth2 - 2000:102::2/64
ip netns exec router-1 ip route add default via 2000:102::2 ip netns exec $r1 ip route add default via 2000:102::2
# Setup N1. host-1 and router-2 connect to a bridge in router-1. # Setup N1. host-1 and router-2 connect to a bridge in router-1.
ip netns exec router-1 ip link add name ${brdev} type bridge ip netns exec $r1 ip link add name ${brdev} type bridge
ip netns exec router-1 ip link set ${brdev} up ip netns exec $r1 ip link set ${brdev} up
ip netns exec router-1 ip addr add 2000:101::1/64 dev ${brdev} ip netns exec $r1 ip addr add 2000:101::1/64 dev ${brdev}
connect_ns host-1 eth0 - 2000:101::3/64 router-1 eth0 - - connect_ns $h1 eth0 - 2000:101::3/64 $r1 eth0 - -
ip netns exec router-1 ip link set dev eth0 master ${brdev} ip netns exec $r1 ip link set dev eth0 master ${brdev}
ip netns exec host-1 ip route add default via 2000:101::1 ip netns exec $h1 ip route add default via 2000:101::1
connect_ns router-2 eth1 - 2000:101::2/64 router-1 eth1 - - connect_ns $r2 eth1 - 2000:101::2/64 $r1 eth1 - -
ip netns exec router-1 ip link set dev eth1 master ${brdev} ip netns exec $r1 ip link set dev eth1 master ${brdev}
# Prime the network # Prime the network
ip netns exec host-1 ping6 -c5 2000:103::4 >/dev/null 2>&1 ip netns exec $h1 ping6 -c5 2000:103::4 >/dev/null 2>&1
set +e set +e
} }
...@@ -217,7 +211,7 @@ run_traceroute6() ...@@ -217,7 +211,7 @@ run_traceroute6()
setup_traceroute6 setup_traceroute6
# traceroute6 host-2 from host-1 (expects 2000:102::2) # traceroute6 host-2 from host-1 (expects 2000:102::2)
run_cmd host-1 "traceroute6 2000:103::4 | grep -q 2000:102::2" run_cmd $h1 "traceroute6 2000:103::4 | grep -q 2000:102::2"
log_test $? 0 "IPV6 traceroute" log_test $? 0 "IPV6 traceroute"
cleanup_traceroute6 cleanup_traceroute6
...@@ -240,12 +234,7 @@ run_traceroute6() ...@@ -240,12 +234,7 @@ run_traceroute6()
cleanup_traceroute() cleanup_traceroute()
{ {
local ns cleanup_ns $h1 $h2 $router
for ns in host-1 host-2 router
do
ip netns del ${ns} 2>/dev/null
done
} }
setup_traceroute() setup_traceroute()
...@@ -254,24 +243,25 @@ setup_traceroute() ...@@ -254,24 +243,25 @@ setup_traceroute()
cleanup_traceroute cleanup_traceroute
set -e set -e
create_ns host-1 setup_ns h1 h2 router
create_ns host-2 create_ns $h1
create_ns router create_ns $h2
create_ns $router
connect_ns host-1 eth0 1.0.1.3/24 - \ connect_ns $h1 eth0 1.0.1.3/24 - \
router eth1 1.0.3.1/24 - $router eth1 1.0.3.1/24 -
ip netns exec host-1 ip route add default via 1.0.1.1 ip netns exec $h1 ip route add default via 1.0.1.1
ip netns exec router ip addr add 1.0.1.1/24 dev eth1 ip netns exec $router ip addr add 1.0.1.1/24 dev eth1
ip netns exec router sysctl -qw \ ip netns exec $router sysctl -qw \
net.ipv4.icmp_errors_use_inbound_ifaddr=1 net.ipv4.icmp_errors_use_inbound_ifaddr=1
connect_ns host-2 eth0 1.0.2.4/24 - \ connect_ns $h2 eth0 1.0.2.4/24 - \
router eth2 1.0.2.1/24 - $router eth2 1.0.2.1/24 -
ip netns exec host-2 ip route add default via 1.0.2.1 ip netns exec $h2 ip route add default via 1.0.2.1
# Prime the network # Prime the network
ip netns exec host-1 ping -c5 1.0.2.4 >/dev/null 2>&1 ip netns exec $h1 ping -c5 1.0.2.4 >/dev/null 2>&1
set +e set +e
} }
...@@ -286,7 +276,7 @@ run_traceroute() ...@@ -286,7 +276,7 @@ run_traceroute()
setup_traceroute setup_traceroute
# traceroute host-2 from host-1 (expects 1.0.1.1). Takes a while. # traceroute host-2 from host-1 (expects 1.0.1.1). Takes a while.
run_cmd host-1 "traceroute 1.0.2.4 | grep -q 1.0.1.1" run_cmd $h1 "traceroute 1.0.2.4 | grep -q 1.0.1.1"
log_test $? 0 "IPV4 traceroute" log_test $? 0 "IPV4 traceroute"
cleanup_traceroute cleanup_traceroute
......
...@@ -28,8 +28,7 @@ ...@@ -28,8 +28,7 @@
# These tests provide an easy way to flip the expected result of any # These tests provide an easy way to flip the expected result of any
# of these behaviors for testing kernel patches that change them. # of these behaviors for testing kernel patches that change them.
# Kselftest framework requirement - SKIP code is 4. source ./lib.sh
ksft_skip=4
# nettest can be run from PATH or from same directory as this selftest # nettest can be run from PATH or from same directory as this selftest
if ! which nettest >/dev/null; then if ! which nettest >/dev/null; then
...@@ -61,20 +60,20 @@ _do_segmenttest(){ ...@@ -61,20 +60,20 @@ _do_segmenttest(){
# foo --- bar # foo --- bar
# Arguments: ip_a ip_b prefix_length test_description # 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, # containing linked veth devices foo and bar,
# respectively. # respectively.
ip -n foo-ns address add $1/$3 dev foo || 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 $foo_ns link set foo up || return 1
ip -n bar-ns address add $2/$3 dev bar || 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 $bar_ns link set bar up || 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 $2 || return 1
ip netns exec bar-ns timeout 2 ping -c 1 $1 || 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 $bar_ns -O $foo_ns -r $1 || return 1
nettest -B -N foo-ns -O bar-ns -r $2 || return 1 nettest -B -N $foo_ns -O $bar_ns -r $2 || return 1
return 0 return 0
} }
...@@ -88,31 +87,31 @@ _do_route_test(){ ...@@ -88,31 +87,31 @@ _do_route_test(){
# Arguments: foo_ip foo1_ip bar1_ip bar_ip prefix_len test_description # Arguments: foo_ip foo1_ip bar1_ip bar_ip prefix_len test_description
# Displays test result and returns success or failure. # 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 # containing linked veth devices foo-foo1, bar1-bar
# (foo in foo-ns, foo1 and bar1 in router-ns, and # (foo in $foo_ns, foo1 and bar1 in $router_ns, and
# bar in bar-ns). # bar in $bar_ns).
ip -n foo-ns address add $1/$5 dev foo || 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 link set foo up || return 1
ip -n foo-ns route add default via $2 || 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 address add $4/$5 dev bar || return 1
ip -n bar-ns link set bar up || 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 $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 address add $2/$5 dev foo1 || return 1
ip -n router-ns link set foo1 up || 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 address add $3/$5 dev bar1 || return 1
ip -n router-ns link set bar1 up || 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 $2 || return 1
ip netns exec foo-ns timeout 2 ping -c 1 $4 || 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 $3 || return 1
ip netns exec bar-ns timeout 2 ping -c 1 $1 || 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 $bar_ns -O $foo_ns -r $1 || return 1
nettest -B -N foo-ns -O bar-ns -r $4 || return 1 nettest -B -N $foo_ns -O $bar_ns -r $4 || return 1
return 0 return 0
} }
...@@ -121,17 +120,15 @@ segmenttest(){ ...@@ -121,17 +120,15 @@ segmenttest(){
# Sets up veth link and tries to connect over it. # Sets up veth link and tries to connect over it.
# Arguments: ip_a ip_b prefix_len test_description # Arguments: ip_a ip_b prefix_len test_description
hide_output hide_output
ip netns add foo-ns setup_ns foo_ns bar_ns
ip netns add bar-ns ip link add foo netns $foo_ns type veth peer name bar netns $bar_ns
ip link add foo netns foo-ns type veth peer name bar netns bar-ns
test_result=0 test_result=0
_do_segmenttest "$@" || test_result=1 _do_segmenttest "$@" || test_result=1
ip netns pids foo-ns | xargs -r kill -9 ip netns pids $foo_ns | xargs -r kill -9
ip netns pids bar-ns | xargs -r kill -9 ip netns pids $bar_ns | xargs -r kill -9
ip netns del foo-ns cleanup_ns $foo_ns $bar_ns
ip netns del bar-ns
show_output show_output
# inverted tests will expect failure instead of success # inverted tests will expect failure instead of success
...@@ -147,21 +144,17 @@ route_test(){ ...@@ -147,21 +144,17 @@ route_test(){
# Returns success or failure. # Returns success or failure.
hide_output hide_output
ip netns add foo-ns setup_ns foo_ns bar_ns router_ns
ip netns add bar-ns ip link add foo netns $foo_ns type veth peer name foo1 netns $router_ns
ip netns add router-ns ip link add bar netns $bar_ns type veth peer name bar1 netns $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 test_result=0
_do_route_test "$@" || test_result=1 _do_route_test "$@" || test_result=1
ip netns pids foo-ns | xargs -r kill -9 ip netns pids $foo_ns | xargs -r kill -9
ip netns pids bar-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 pids $router_ns | xargs -r kill -9
ip netns del foo-ns cleanup_ns $foo_ns $bar_ns $router_ns
ip netns del bar-ns
ip netns del router-ns
show_output show_output
......
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