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
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
# Route on r1 changed to go to r2 via eth0. This causes a redirect to be sent # Route on r1 changed to go to r2 via eth0. This causes a redirect to be sent
# from r1 to h1 telling h1 to use r2 when talking to h2. # from r1 to h1 telling h1 to use r2 when talking to h2.
source lib.sh
VERBOSE=0 VERBOSE=0
PAUSE_ON_FAIL=no PAUSE_ON_FAIL=no
...@@ -140,11 +141,7 @@ get_linklocal() ...@@ -140,11 +141,7 @@ get_linklocal()
cleanup() cleanup()
{ {
local ns cleanup_ns $h1 $h2 $r1 $r2
for ns in h1 h2 r1 r2; do
ip netns del $ns 2>/dev/null
done
} }
create_vrf() create_vrf()
...@@ -171,102 +168,99 @@ setup() ...@@ -171,102 +168,99 @@ setup()
# #
# create nodes as namespaces # create nodes as namespaces
# setup_ns h1 h2 r1 r2
for ns in h1 h2 r1 r2; do for ns in $h1 $h2 $r1 $r2; do
ip netns add $ns if echo $ns | grep -q h[12]-; then
ip -netns $ns li set lo up ip netns exec $ns sysctl -q -w net.ipv4.conf.all.accept_redirects=1
case "${ns}" in
h[12]) ip netns exec $ns sysctl -q -w net.ipv4.conf.all.accept_redirects=1
ip netns exec $ns sysctl -q -w net.ipv6.conf.all.forwarding=0 ip netns exec $ns sysctl -q -w net.ipv6.conf.all.forwarding=0
ip netns exec $ns sysctl -q -w net.ipv6.conf.all.accept_redirects=1 ip netns exec $ns sysctl -q -w net.ipv6.conf.all.accept_redirects=1
ip netns exec $ns sysctl -q -w net.ipv6.conf.all.keep_addr_on_down=1 ip netns exec $ns sysctl -q -w net.ipv6.conf.all.keep_addr_on_down=1
;; else
r[12]) ip netns exec $ns sysctl -q -w net.ipv4.ip_forward=1 ip netns exec $ns sysctl -q -w net.ipv4.ip_forward=1
ip netns exec $ns sysctl -q -w net.ipv4.conf.all.send_redirects=1 ip netns exec $ns sysctl -q -w net.ipv4.conf.all.send_redirects=1
ip netns exec $ns sysctl -q -w net.ipv4.conf.default.rp_filter=0 ip netns exec $ns sysctl -q -w net.ipv4.conf.default.rp_filter=0
ip netns exec $ns sysctl -q -w net.ipv4.conf.all.rp_filter=0 ip netns exec $ns sysctl -q -w net.ipv4.conf.all.rp_filter=0
ip netns exec $ns sysctl -q -w net.ipv6.conf.all.forwarding=1 ip netns exec $ns sysctl -q -w net.ipv6.conf.all.forwarding=1
ip netns exec $ns sysctl -q -w net.ipv6.route.mtu_expires=10 ip netns exec $ns sysctl -q -w net.ipv6.route.mtu_expires=10
esac fi
done done
# #
# create interconnects # create interconnects
# #
ip -netns h1 li add eth0 type veth peer name r1h1 ip -netns $h1 li add eth0 type veth peer name r1h1
ip -netns h1 li set r1h1 netns r1 name eth0 up ip -netns $h1 li set r1h1 netns $r1 name eth0 up
ip -netns h1 li add eth1 type veth peer name r2h1 ip -netns $h1 li add eth1 type veth peer name r2h1
ip -netns h1 li set r2h1 netns r2 name eth0 up ip -netns $h1 li set r2h1 netns $r2 name eth0 up
ip -netns h2 li add eth0 type veth peer name r2h2 ip -netns $h2 li add eth0 type veth peer name r2h2
ip -netns h2 li set eth0 up ip -netns $h2 li set eth0 up
ip -netns h2 li set r2h2 netns r2 name eth2 up ip -netns $h2 li set r2h2 netns $r2 name eth2 up
ip -netns r1 li add eth1 type veth peer name r2r1 ip -netns $r1 li add eth1 type veth peer name r2r1
ip -netns r1 li set eth1 up ip -netns $r1 li set eth1 up
ip -netns r1 li set r2r1 netns r2 name eth1 up ip -netns $r1 li set r2r1 netns $r2 name eth1 up
# #
# h1 # h1
# #
if [ "${WITH_VRF}" = "yes" ]; then if [ "${WITH_VRF}" = "yes" ]; then
create_vrf "h1" create_vrf "$h1"
H1_VRF_ARG="vrf ${VRF}" H1_VRF_ARG="vrf ${VRF}"
H1_PING_ARG="-I ${VRF}" H1_PING_ARG="-I ${VRF}"
else else
H1_VRF_ARG= H1_VRF_ARG=
H1_PING_ARG= H1_PING_ARG=
fi fi
ip -netns h1 li add br0 type bridge ip -netns $h1 li add br0 type bridge
if [ "${WITH_VRF}" = "yes" ]; then if [ "${WITH_VRF}" = "yes" ]; then
ip -netns h1 li set br0 vrf ${VRF} up ip -netns $h1 li set br0 vrf ${VRF} up
else else
ip -netns h1 li set br0 up ip -netns $h1 li set br0 up
fi fi
ip -netns h1 addr add dev br0 ${H1_N1_IP}/24 ip -netns $h1 addr add dev br0 ${H1_N1_IP}/24
ip -netns h1 -6 addr add dev br0 ${H1_N1_IP6}/64 nodad ip -netns $h1 -6 addr add dev br0 ${H1_N1_IP6}/64 nodad
ip -netns h1 li set eth0 master br0 up ip -netns $h1 li set eth0 master br0 up
ip -netns h1 li set eth1 master br0 up ip -netns $h1 li set eth1 master br0 up
# #
# h2 # h2
# #
ip -netns h2 addr add dev eth0 ${H2_N2_IP}/24 ip -netns $h2 addr add dev eth0 ${H2_N2_IP}/24
ip -netns h2 ro add default via ${R2_N2_IP} dev eth0 ip -netns $h2 ro add default via ${R2_N2_IP} dev eth0
ip -netns h2 -6 addr add dev eth0 ${H2_N2_IP6}/64 nodad ip -netns $h2 -6 addr add dev eth0 ${H2_N2_IP6}/64 nodad
ip -netns h2 -6 ro add default via ${R2_N2_IP6} dev eth0 ip -netns $h2 -6 ro add default via ${R2_N2_IP6} dev eth0
# #
# r1 # r1
# #
ip -netns r1 addr add dev eth0 ${R1_N1_IP}/24 ip -netns $r1 addr add dev eth0 ${R1_N1_IP}/24
ip -netns r1 -6 addr add dev eth0 ${R1_N1_IP6}/64 nodad ip -netns $r1 -6 addr add dev eth0 ${R1_N1_IP6}/64 nodad
ip -netns r1 addr add dev eth1 ${R1_R2_N1_IP}/30 ip -netns $r1 addr add dev eth1 ${R1_R2_N1_IP}/30
ip -netns r1 -6 addr add dev eth1 ${R1_R2_N1_IP6}/126 nodad ip -netns $r1 -6 addr add dev eth1 ${R1_R2_N1_IP6}/126 nodad
# #
# r2 # r2
# #
ip -netns r2 addr add dev eth0 ${R2_N1_IP}/24 ip -netns $r2 addr add dev eth0 ${R2_N1_IP}/24
ip -netns r2 -6 addr add dev eth0 ${R2_N1_IP6}/64 nodad ip -netns $r2 -6 addr add dev eth0 ${R2_N1_IP6}/64 nodad
ip -netns r2 addr add dev eth1 ${R2_R1_N1_IP}/30 ip -netns $r2 addr add dev eth1 ${R2_R1_N1_IP}/30
ip -netns r2 -6 addr add dev eth1 ${R2_R1_N1_IP6}/126 nodad ip -netns $r2 -6 addr add dev eth1 ${R2_R1_N1_IP6}/126 nodad
ip -netns r2 addr add dev eth2 ${R2_N2_IP}/24 ip -netns $r2 addr add dev eth2 ${R2_N2_IP}/24
ip -netns r2 -6 addr add dev eth2 ${R2_N2_IP6}/64 nodad ip -netns $r2 -6 addr add dev eth2 ${R2_N2_IP6}/64 nodad
sleep 2 sleep 2
R1_LLADDR=$(get_linklocal r1 eth0) R1_LLADDR=$(get_linklocal $r1 eth0)
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Error: Failed to get link-local address of r1's eth0" echo "Error: Failed to get link-local address of r1's eth0"
exit 1 exit 1
fi fi
log_debug "initial gateway is R1's lladdr = ${R1_LLADDR}" log_debug "initial gateway is R1's lladdr = ${R1_LLADDR}"
R2_LLADDR=$(get_linklocal r2 eth0) R2_LLADDR=$(get_linklocal $r2 eth0)
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Error: Failed to get link-local address of r2's eth0" echo "Error: Failed to get link-local address of r2's eth0"
exit 1 exit 1
...@@ -278,8 +272,8 @@ change_h2_mtu() ...@@ -278,8 +272,8 @@ change_h2_mtu()
{ {
local mtu=$1 local mtu=$1
run_cmd ip -netns h2 li set eth0 mtu ${mtu} run_cmd ip -netns $h2 li set eth0 mtu ${mtu}
run_cmd ip -netns r2 li set eth2 mtu ${mtu} run_cmd ip -netns $r2 li set eth2 mtu ${mtu}
} }
check_exception() check_exception()
...@@ -291,40 +285,40 @@ check_exception() ...@@ -291,40 +285,40 @@ check_exception()
# From 172.16.1.101: icmp_seq=1 Redirect Host(New nexthop: 172.16.1.102) # From 172.16.1.101: icmp_seq=1 Redirect Host(New nexthop: 172.16.1.102)
if [ "$VERBOSE" = "1" ]; then if [ "$VERBOSE" = "1" ]; then
echo "Commands to check for exception:" echo "Commands to check for exception:"
run_cmd ip -netns h1 ro get ${H1_VRF_ARG} ${H2_N2_IP} run_cmd ip -netns $h1 ro get ${H1_VRF_ARG} ${H2_N2_IP}
run_cmd ip -netns h1 -6 ro get ${H1_VRF_ARG} ${H2_N2_IP6} run_cmd ip -netns $h1 -6 ro get ${H1_VRF_ARG} ${H2_N2_IP6}
fi fi
if [ -n "${mtu}" ]; then if [ -n "${mtu}" ]; then
mtu=" mtu ${mtu}" mtu=" mtu ${mtu}"
fi fi
if [ "$with_redirect" = "yes" ]; then if [ "$with_redirect" = "yes" ]; then
ip -netns h1 ro get ${H1_VRF_ARG} ${H2_N2_IP} | \ ip -netns $h1 ro get ${H1_VRF_ARG} ${H2_N2_IP} | \
grep -q "cache <redirected> expires [0-9]*sec${mtu}" grep -q "cache <redirected> expires [0-9]*sec${mtu}"
elif [ -n "${mtu}" ]; then elif [ -n "${mtu}" ]; then
ip -netns h1 ro get ${H1_VRF_ARG} ${H2_N2_IP} | \ ip -netns $h1 ro get ${H1_VRF_ARG} ${H2_N2_IP} | \
grep -q "cache expires [0-9]*sec${mtu}" grep -q "cache expires [0-9]*sec${mtu}"
else else
# want to verify that neither mtu nor redirected appears in # want to verify that neither mtu nor redirected appears in
# the route get output. The -v will wipe out the cache line # the route get output. The -v will wipe out the cache line
# if either are set so the last grep -q will not find a match # if either are set so the last grep -q will not find a match
ip -netns h1 ro get ${H1_VRF_ARG} ${H2_N2_IP} | \ ip -netns $h1 ro get ${H1_VRF_ARG} ${H2_N2_IP} | \
grep -E -v 'mtu|redirected' | grep -q "cache" grep -E -v 'mtu|redirected' | grep -q "cache"
fi fi
log_test $? 0 "IPv4: ${desc}" 0 log_test $? 0 "IPv4: ${desc}" 0
# No PMTU info for test "redirect" and "mtu exception plus redirect" # No PMTU info for test "redirect" and "mtu exception plus redirect"
if [ "$with_redirect" = "yes" ] && [ "$desc" != "redirect exception plus mtu" ]; then if [ "$with_redirect" = "yes" ] && [ "$desc" != "redirect exception plus mtu" ]; then
ip -netns h1 -6 ro get ${H1_VRF_ARG} ${H2_N2_IP6} | \ ip -netns $h1 -6 ro get ${H1_VRF_ARG} ${H2_N2_IP6} | \
grep -v "mtu" | grep -q "${H2_N2_IP6} .*via ${R2_LLADDR} dev br0" grep -v "mtu" | grep -q "${H2_N2_IP6} .*via ${R2_LLADDR} dev br0"
elif [ -n "${mtu}" ]; then elif [ -n "${mtu}" ]; then
ip -netns h1 -6 ro get ${H1_VRF_ARG} ${H2_N2_IP6} | \ ip -netns $h1 -6 ro get ${H1_VRF_ARG} ${H2_N2_IP6} | \
grep -q "${mtu}" grep -q "${mtu}"
else else
# IPv6 is a bit harder. First strip out the match if it # IPv6 is a bit harder. First strip out the match if it
# contains an mtu exception and then look for the first # contains an mtu exception and then look for the first
# gateway - R1's lladdr # gateway - R1's lladdr
ip -netns h1 -6 ro get ${H1_VRF_ARG} ${H2_N2_IP6} | \ ip -netns $h1 -6 ro get ${H1_VRF_ARG} ${H2_N2_IP6} | \
grep -v "mtu" | grep -q "${R1_LLADDR}" grep -v "mtu" | grep -q "${R1_LLADDR}"
fi fi
log_test $? 0 "IPv6: ${desc}" 1 log_test $? 0 "IPv6: ${desc}" 1
...@@ -334,21 +328,21 @@ run_ping() ...@@ -334,21 +328,21 @@ run_ping()
{ {
local sz=$1 local sz=$1
run_cmd ip netns exec h1 ping -q -M want -i 0.5 -c 10 -w 2 -s ${sz} ${H1_PING_ARG} ${H2_N2_IP} run_cmd ip netns exec $h1 ping -q -M want -i 0.5 -c 10 -w 2 -s ${sz} ${H1_PING_ARG} ${H2_N2_IP}
run_cmd ip netns exec h1 ${ping6} -q -M want -i 0.5 -c 10 -w 2 -s ${sz} ${H1_PING_ARG} ${H2_N2_IP6} run_cmd ip netns exec $h1 ${ping6} -q -M want -i 0.5 -c 10 -w 2 -s ${sz} ${H1_PING_ARG} ${H2_N2_IP6}
} }
replace_route_new() replace_route_new()
{ {
# r1 to h2 via r2 and eth0 # r1 to h2 via r2 and eth0
run_cmd ip -netns r1 nexthop replace id 1 via ${R2_N1_IP} dev eth0 run_cmd ip -netns $r1 nexthop replace id 1 via ${R2_N1_IP} dev eth0
run_cmd ip -netns r1 nexthop replace id 2 via ${R2_LLADDR} dev eth0 run_cmd ip -netns $r1 nexthop replace id 2 via ${R2_LLADDR} dev eth0
} }
reset_route_new() reset_route_new()
{ {
run_cmd ip -netns r1 nexthop flush run_cmd ip -netns $r1 nexthop flush
run_cmd ip -netns h1 nexthop flush run_cmd ip -netns $h1 nexthop flush
initial_route_new initial_route_new
} }
...@@ -356,34 +350,34 @@ reset_route_new() ...@@ -356,34 +350,34 @@ reset_route_new()
initial_route_new() initial_route_new()
{ {
# r1 to h2 via r2 and eth1 # r1 to h2 via r2 and eth1
run_cmd ip -netns r1 nexthop add id 1 via ${R2_R1_N1_IP} dev eth1 run_cmd ip -netns $r1 nexthop add id 1 via ${R2_R1_N1_IP} dev eth1
run_cmd ip -netns r1 ro add ${H2_N2} nhid 1 run_cmd ip -netns $r1 ro add ${H2_N2} nhid 1
run_cmd ip -netns r1 nexthop add id 2 via ${R2_R1_N1_IP6} dev eth1 run_cmd ip -netns $r1 nexthop add id 2 via ${R2_R1_N1_IP6} dev eth1
run_cmd ip -netns r1 -6 ro add ${H2_N2_6} nhid 2 run_cmd ip -netns $r1 -6 ro add ${H2_N2_6} nhid 2
# h1 to h2 via r1 # h1 to h2 via r1
run_cmd ip -netns h1 nexthop add id 1 via ${R1_N1_IP} dev br0 run_cmd ip -netns $h1 nexthop add id 1 via ${R1_N1_IP} dev br0
run_cmd ip -netns h1 ro add ${H1_VRF_ARG} ${H2_N2} nhid 1 run_cmd ip -netns $h1 ro add ${H1_VRF_ARG} ${H2_N2} nhid 1
run_cmd ip -netns h1 nexthop add id 2 via ${R1_LLADDR} dev br0 run_cmd ip -netns $h1 nexthop add id 2 via ${R1_LLADDR} dev br0
run_cmd ip -netns h1 -6 ro add ${H1_VRF_ARG} ${H2_N2_6} nhid 2 run_cmd ip -netns $h1 -6 ro add ${H1_VRF_ARG} ${H2_N2_6} nhid 2
} }
replace_route_legacy() replace_route_legacy()
{ {
# r1 to h2 via r2 and eth0 # r1 to h2 via r2 and eth0
run_cmd ip -netns r1 ro replace ${H2_N2} via ${R2_N1_IP} dev eth0 run_cmd ip -netns $r1 ro replace ${H2_N2} via ${R2_N1_IP} dev eth0
run_cmd ip -netns r1 -6 ro replace ${H2_N2_6} via ${R2_LLADDR} dev eth0 run_cmd ip -netns $r1 -6 ro replace ${H2_N2_6} via ${R2_LLADDR} dev eth0
} }
reset_route_legacy() reset_route_legacy()
{ {
run_cmd ip -netns r1 ro del ${H2_N2} run_cmd ip -netns $r1 ro del ${H2_N2}
run_cmd ip -netns r1 -6 ro del ${H2_N2_6} run_cmd ip -netns $r1 -6 ro del ${H2_N2_6}
run_cmd ip -netns h1 ro del ${H1_VRF_ARG} ${H2_N2} run_cmd ip -netns $h1 ro del ${H1_VRF_ARG} ${H2_N2}
run_cmd ip -netns h1 -6 ro del ${H1_VRF_ARG} ${H2_N2_6} run_cmd ip -netns $h1 -6 ro del ${H1_VRF_ARG} ${H2_N2_6}
initial_route_legacy initial_route_legacy
} }
...@@ -391,22 +385,22 @@ reset_route_legacy() ...@@ -391,22 +385,22 @@ reset_route_legacy()
initial_route_legacy() initial_route_legacy()
{ {
# r1 to h2 via r2 and eth1 # r1 to h2 via r2 and eth1
run_cmd ip -netns r1 ro add ${H2_N2} via ${R2_R1_N1_IP} dev eth1 run_cmd ip -netns $r1 ro add ${H2_N2} via ${R2_R1_N1_IP} dev eth1
run_cmd ip -netns r1 -6 ro add ${H2_N2_6} via ${R2_R1_N1_IP6} dev eth1 run_cmd ip -netns $r1 -6 ro add ${H2_N2_6} via ${R2_R1_N1_IP6} dev eth1
# h1 to h2 via r1 # h1 to h2 via r1
# - IPv6 redirect only works if gateway is the LLA # - IPv6 redirect only works if gateway is the LLA
run_cmd ip -netns h1 ro add ${H1_VRF_ARG} ${H2_N2} via ${R1_N1_IP} dev br0 run_cmd ip -netns $h1 ro add ${H1_VRF_ARG} ${H2_N2} via ${R1_N1_IP} dev br0
run_cmd ip -netns h1 -6 ro add ${H1_VRF_ARG} ${H2_N2_6} via ${R1_LLADDR} dev br0 run_cmd ip -netns $h1 -6 ro add ${H1_VRF_ARG} ${H2_N2_6} via ${R1_LLADDR} dev br0
} }
check_connectivity() check_connectivity()
{ {
local rc local rc
run_cmd ip netns exec h1 ping -c1 -w1 ${H1_PING_ARG} ${H2_N2_IP} run_cmd ip netns exec $h1 ping -c1 -w1 ${H1_PING_ARG} ${H2_N2_IP}
rc=$? rc=$?
run_cmd ip netns exec h1 ${ping6} -c1 -w1 ${H1_PING_ARG} ${H2_N2_IP6} run_cmd ip netns exec $h1 ${ping6} -c1 -w1 ${H1_PING_ARG} ${H2_N2_IP6}
[ $? -ne 0 ] && rc=$? [ $? -ne 0 ] && rc=$?
return $rc return $rc
......
...@@ -117,8 +117,7 @@ ...@@ -117,8 +117,7 @@
# | Schema Data | | # | Schema Data | |
# +-----------------------------------------------------------+ # +-----------------------------------------------------------+
# Kselftest framework requirement - SKIP code is 4. source lib.sh
ksft_skip=4
################################################################################ ################################################################################
# # # #
...@@ -195,32 +194,32 @@ TESTS_GLOBAL=" ...@@ -195,32 +194,32 @@ TESTS_GLOBAL="
check_kernel_compatibility() check_kernel_compatibility()
{ {
ip netns add ioam-tmp-node setup_ns ioam_tmp_node
ip link add name veth0 netns ioam-tmp-node type veth \ ip link add name veth0 netns $ioam_tmp_node type veth \
peer name veth1 netns ioam-tmp-node peer name veth1 netns $ioam_tmp_node
ip -netns ioam-tmp-node link set veth0 up ip -netns $ioam_tmp_node link set veth0 up
ip -netns ioam-tmp-node link set veth1 up ip -netns $ioam_tmp_node link set veth1 up
ip -netns ioam-tmp-node ioam namespace add 0 ip -netns $ioam_tmp_node ioam namespace add 0
ns_ad=$? ns_ad=$?
ip -netns ioam-tmp-node ioam namespace show | grep -q "namespace 0" ip -netns $ioam_tmp_node ioam namespace show | grep -q "namespace 0"
ns_sh=$? ns_sh=$?
if [[ $ns_ad != 0 || $ns_sh != 0 ]] if [[ $ns_ad != 0 || $ns_sh != 0 ]]
then then
echo "SKIP: kernel version probably too old, missing ioam support" echo "SKIP: kernel version probably too old, missing ioam support"
ip link del veth0 2>/dev/null || true ip link del veth0 2>/dev/null || true
ip netns del ioam-tmp-node || true cleanup_ns $ioam_tmp_node || true
exit $ksft_skip exit $ksft_skip
fi fi
ip -netns ioam-tmp-node route add db02::/64 encap ioam6 mode inline \ ip -netns $ioam_tmp_node route add db02::/64 encap ioam6 mode inline \
trace prealloc type 0x800000 ns 0 size 4 dev veth0 trace prealloc type 0x800000 ns 0 size 4 dev veth0
tr_ad=$? tr_ad=$?
ip -netns ioam-tmp-node -6 route | grep -q "encap ioam6" ip -netns $ioam_tmp_node -6 route | grep -q "encap ioam6"
tr_sh=$? tr_sh=$?
if [[ $tr_ad != 0 || $tr_sh != 0 ]] if [[ $tr_ad != 0 || $tr_sh != 0 ]]
...@@ -228,12 +227,12 @@ check_kernel_compatibility() ...@@ -228,12 +227,12 @@ check_kernel_compatibility()
echo "SKIP: cannot attach an ioam trace to a route, did you compile" \ echo "SKIP: cannot attach an ioam trace to a route, did you compile" \
"without CONFIG_IPV6_IOAM6_LWTUNNEL?" "without CONFIG_IPV6_IOAM6_LWTUNNEL?"
ip link del veth0 2>/dev/null || true ip link del veth0 2>/dev/null || true
ip netns del ioam-tmp-node || true cleanup_ns $ioam_tmp_node || true
exit $ksft_skip exit $ksft_skip
fi fi
ip link del veth0 2>/dev/null || true ip link del veth0 2>/dev/null || true
ip netns del ioam-tmp-node || true cleanup_ns $ioam_tmp_node || true
lsmod | grep -q "ip6_tunnel" lsmod | grep -q "ip6_tunnel"
ip6tnl_loaded=$? ip6tnl_loaded=$?
...@@ -265,9 +264,7 @@ cleanup() ...@@ -265,9 +264,7 @@ cleanup()
ip link del ioam-veth-alpha 2>/dev/null || true ip link del ioam-veth-alpha 2>/dev/null || true
ip link del ioam-veth-gamma 2>/dev/null || true ip link del ioam-veth-gamma 2>/dev/null || true
ip netns del ioam-node-alpha || true cleanup_ns $ioam_node_alpha $ioam_node_beta $ioam_node_gamma || true
ip netns del ioam-node-beta || true
ip netns del ioam-node-gamma || true
if [ $ip6tnl_loaded != 0 ] if [ $ip6tnl_loaded != 0 ]
then then
...@@ -277,69 +274,67 @@ cleanup() ...@@ -277,69 +274,67 @@ cleanup()
setup() setup()
{ {
ip netns add ioam-node-alpha setup_ns ioam_node_alpha ioam_node_beta ioam_node_gamma
ip netns add ioam-node-beta
ip netns add ioam-node-gamma ip link add name ioam-veth-alpha netns $ioam_node_alpha type veth \
peer name ioam-veth-betaL netns $ioam_node_beta
ip link add name ioam-veth-alpha netns ioam-node-alpha type veth \ ip link add name ioam-veth-betaR netns $ioam_node_beta type veth \
peer name ioam-veth-betaL netns ioam-node-beta peer name ioam-veth-gamma netns $ioam_node_gamma
ip link add name ioam-veth-betaR netns ioam-node-beta type veth \
peer name ioam-veth-gamma netns ioam-node-gamma ip -netns $ioam_node_alpha link set ioam-veth-alpha name veth0
ip -netns $ioam_node_beta link set ioam-veth-betaL name veth0
ip -netns ioam-node-alpha link set ioam-veth-alpha name veth0 ip -netns $ioam_node_beta link set ioam-veth-betaR name veth1
ip -netns ioam-node-beta link set ioam-veth-betaL name veth0 ip -netns $ioam_node_gamma link set ioam-veth-gamma name veth0
ip -netns ioam-node-beta link set ioam-veth-betaR name veth1
ip -netns ioam-node-gamma link set ioam-veth-gamma name veth0 ip -netns $ioam_node_alpha addr add db01::2/64 dev veth0
ip -netns $ioam_node_alpha link set veth0 up
ip -netns ioam-node-alpha addr add db01::2/64 dev veth0 ip -netns $ioam_node_alpha link set lo up
ip -netns ioam-node-alpha link set veth0 up ip -netns $ioam_node_alpha route add db02::/64 via db01::1 dev veth0
ip -netns ioam-node-alpha link set lo up ip -netns $ioam_node_alpha route del db01::/64
ip -netns ioam-node-alpha route add db02::/64 via db01::1 dev veth0 ip -netns $ioam_node_alpha route add db01::/64 dev veth0
ip -netns ioam-node-alpha route del db01::/64
ip -netns ioam-node-alpha route add db01::/64 dev veth0 ip -netns $ioam_node_beta addr add db01::1/64 dev veth0
ip -netns $ioam_node_beta addr add db02::1/64 dev veth1
ip -netns ioam-node-beta addr add db01::1/64 dev veth0 ip -netns $ioam_node_beta link set veth0 up
ip -netns ioam-node-beta addr add db02::1/64 dev veth1 ip -netns $ioam_node_beta link set veth1 up
ip -netns ioam-node-beta link set veth0 up ip -netns $ioam_node_beta link set lo up
ip -netns ioam-node-beta link set veth1 up
ip -netns ioam-node-beta link set lo up ip -netns $ioam_node_gamma addr add db02::2/64 dev veth0
ip -netns $ioam_node_gamma link set veth0 up
ip -netns ioam-node-gamma addr add db02::2/64 dev veth0 ip -netns $ioam_node_gamma link set lo up
ip -netns ioam-node-gamma link set veth0 up ip -netns $ioam_node_gamma route add db01::/64 via db02::1 dev veth0
ip -netns ioam-node-gamma link set lo up
ip -netns ioam-node-gamma route add db01::/64 via db02::1 dev veth0
# - IOAM config - # - IOAM config -
ip netns exec ioam-node-alpha sysctl -wq net.ipv6.ioam6_id=${ALPHA[0]} ip netns exec $ioam_node_alpha sysctl -wq net.ipv6.ioam6_id=${ALPHA[0]}
ip netns exec ioam-node-alpha sysctl -wq net.ipv6.ioam6_id_wide=${ALPHA[1]} ip netns exec $ioam_node_alpha sysctl -wq net.ipv6.ioam6_id_wide=${ALPHA[1]}
ip netns exec ioam-node-alpha sysctl -wq net.ipv6.conf.veth0.ioam6_id=${ALPHA[4]} ip netns exec $ioam_node_alpha sysctl -wq net.ipv6.conf.veth0.ioam6_id=${ALPHA[4]}
ip netns exec ioam-node-alpha sysctl -wq net.ipv6.conf.veth0.ioam6_id_wide=${ALPHA[5]} ip netns exec $ioam_node_alpha sysctl -wq net.ipv6.conf.veth0.ioam6_id_wide=${ALPHA[5]}
ip -netns ioam-node-alpha ioam namespace add 123 data ${ALPHA[6]} wide ${ALPHA[7]} ip -netns $ioam_node_alpha ioam namespace add 123 data ${ALPHA[6]} wide ${ALPHA[7]}
ip -netns ioam-node-alpha ioam schema add ${ALPHA[8]} "${ALPHA[9]}" ip -netns $ioam_node_alpha ioam schema add ${ALPHA[8]} "${ALPHA[9]}"
ip -netns ioam-node-alpha ioam namespace set 123 schema ${ALPHA[8]} ip -netns $ioam_node_alpha ioam namespace set 123 schema ${ALPHA[8]}
ip netns exec ioam-node-beta sysctl -wq net.ipv6.conf.all.forwarding=1 ip netns exec $ioam_node_beta sysctl -wq net.ipv6.conf.all.forwarding=1
ip netns exec ioam-node-beta sysctl -wq net.ipv6.ioam6_id=${BETA[0]} ip netns exec $ioam_node_beta sysctl -wq net.ipv6.ioam6_id=${BETA[0]}
ip netns exec ioam-node-beta sysctl -wq net.ipv6.ioam6_id_wide=${BETA[1]} ip netns exec $ioam_node_beta sysctl -wq net.ipv6.ioam6_id_wide=${BETA[1]}
ip netns exec ioam-node-beta sysctl -wq net.ipv6.conf.veth0.ioam6_enabled=1 ip netns exec $ioam_node_beta sysctl -wq net.ipv6.conf.veth0.ioam6_enabled=1
ip netns exec ioam-node-beta sysctl -wq net.ipv6.conf.veth0.ioam6_id=${BETA[2]} ip netns exec $ioam_node_beta sysctl -wq net.ipv6.conf.veth0.ioam6_id=${BETA[2]}
ip netns exec ioam-node-beta sysctl -wq net.ipv6.conf.veth0.ioam6_id_wide=${BETA[3]} ip netns exec $ioam_node_beta sysctl -wq net.ipv6.conf.veth0.ioam6_id_wide=${BETA[3]}
ip netns exec ioam-node-beta sysctl -wq net.ipv6.conf.veth1.ioam6_id=${BETA[4]} ip netns exec $ioam_node_beta sysctl -wq net.ipv6.conf.veth1.ioam6_id=${BETA[4]}
ip netns exec ioam-node-beta sysctl -wq net.ipv6.conf.veth1.ioam6_id_wide=${BETA[5]} ip netns exec $ioam_node_beta sysctl -wq net.ipv6.conf.veth1.ioam6_id_wide=${BETA[5]}
ip -netns ioam-node-beta ioam namespace add 123 data ${BETA[6]} wide ${BETA[7]} ip -netns $ioam_node_beta ioam namespace add 123 data ${BETA[6]} wide ${BETA[7]}
ip -netns ioam-node-beta ioam schema add ${BETA[8]} "${BETA[9]}" ip -netns $ioam_node_beta ioam schema add ${BETA[8]} "${BETA[9]}"
ip -netns ioam-node-beta ioam namespace set 123 schema ${BETA[8]} ip -netns $ioam_node_beta ioam namespace set 123 schema ${BETA[8]}
ip netns exec ioam-node-gamma sysctl -wq net.ipv6.ioam6_id=${GAMMA[0]} ip netns exec $ioam_node_gamma sysctl -wq net.ipv6.ioam6_id=${GAMMA[0]}
ip netns exec ioam-node-gamma sysctl -wq net.ipv6.ioam6_id_wide=${GAMMA[1]} ip netns exec $ioam_node_gamma sysctl -wq net.ipv6.ioam6_id_wide=${GAMMA[1]}
ip netns exec ioam-node-gamma sysctl -wq net.ipv6.conf.veth0.ioam6_enabled=1 ip netns exec $ioam_node_gamma sysctl -wq net.ipv6.conf.veth0.ioam6_enabled=1
ip netns exec ioam-node-gamma sysctl -wq net.ipv6.conf.veth0.ioam6_id=${GAMMA[2]} ip netns exec $ioam_node_gamma sysctl -wq net.ipv6.conf.veth0.ioam6_id=${GAMMA[2]}
ip netns exec ioam-node-gamma sysctl -wq net.ipv6.conf.veth0.ioam6_id_wide=${GAMMA[3]} ip netns exec $ioam_node_gamma sysctl -wq net.ipv6.conf.veth0.ioam6_id_wide=${GAMMA[3]}
ip -netns ioam-node-gamma ioam namespace add 123 data ${GAMMA[6]} wide ${GAMMA[7]} ip -netns $ioam_node_gamma ioam namespace add 123 data ${GAMMA[6]} wide ${GAMMA[7]}
sleep 1 sleep 1
ip netns exec ioam-node-alpha ping6 -c 5 -W 1 db02::2 &>/dev/null ip netns exec $ioam_node_alpha ping6 -c 5 -W 1 db02::2 &>/dev/null
if [ $? != 0 ] if [ $? != 0 ]
then then
echo "Setup FAILED" echo "Setup FAILED"
...@@ -412,7 +407,7 @@ run() ...@@ -412,7 +407,7 @@ run()
echo echo
# set OUTPUT settings # set OUTPUT settings
ip netns exec ioam-node-beta sysctl -wq net.ipv6.conf.veth0.ioam6_enabled=0 ip netns exec $ioam_node_beta sysctl -wq net.ipv6.conf.veth0.ioam6_enabled=0
for t in $TESTS_OUTPUT for t in $TESTS_OUTPUT
do do
...@@ -421,8 +416,8 @@ run() ...@@ -421,8 +416,8 @@ run()
done done
# clean OUTPUT settings # clean OUTPUT settings
ip netns exec ioam-node-beta sysctl -wq net.ipv6.conf.veth0.ioam6_enabled=1 ip netns exec $ioam_node_beta sysctl -wq net.ipv6.conf.veth0.ioam6_enabled=1
ip -netns ioam-node-alpha route change db01::/64 dev veth0 ip -netns $ioam_node_alpha route change db01::/64 dev veth0
echo echo
...@@ -433,7 +428,7 @@ run() ...@@ -433,7 +428,7 @@ run()
echo echo
# set INPUT settings # set INPUT settings
ip -netns ioam-node-alpha ioam namespace del 123 ip -netns $ioam_node_alpha ioam namespace del 123
for t in $TESTS_INPUT for t in $TESTS_INPUT
do do
...@@ -442,10 +437,10 @@ run() ...@@ -442,10 +437,10 @@ run()
done done
# clean INPUT settings # clean INPUT settings
ip -netns ioam-node-alpha ioam namespace add 123 \ ip -netns $ioam_node_alpha ioam namespace add 123 \
data ${ALPHA[6]} wide ${ALPHA[7]} data ${ALPHA[6]} wide ${ALPHA[7]}
ip -netns ioam-node-alpha ioam namespace set 123 schema ${ALPHA[8]} ip -netns $ioam_node_alpha ioam namespace set 123 schema ${ALPHA[8]}
ip -netns ioam-node-alpha route change db01::/64 dev veth0 ip -netns $ioam_node_alpha route change db01::/64 dev veth0
echo echo
printf "%0.s-" {1..74} printf "%0.s-" {1..74}
...@@ -488,15 +483,15 @@ out_undef_ns() ...@@ -488,15 +483,15 @@ out_undef_ns()
local desc="Unknown IOAM namespace" local desc="Unknown IOAM namespace"
[ "$1" = "encap" ] && mode="$1 tundst db01::1" || mode="$1" [ "$1" = "encap" ] && mode="$1 tundst db01::1" || mode="$1"
[ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 up [ "$1" = "encap" ] && ip -netns $ioam_node_beta link set ip6tnl0 up
ip -netns ioam-node-alpha route change db01::/64 encap ioam6 mode $mode \ ip -netns $ioam_node_alpha route change db01::/64 encap ioam6 mode $mode \
trace prealloc type 0x800000 ns 0 size 4 dev veth0 trace prealloc type 0x800000 ns 0 size 4 dev veth0
run_test ${FUNCNAME[0]} "${desc} ($1 mode)" ioam-node-alpha ioam-node-beta \ run_test ${FUNCNAME[0]} "${desc} ($1 mode)" $ioam_node_alpha $ioam_node_beta \
db01::2 db01::1 veth0 0x800000 0 db01::2 db01::1 veth0 0x800000 0
[ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 down [ "$1" = "encap" ] && ip -netns $ioam_node_beta link set ip6tnl0 down
} }
out_no_room() out_no_room()
...@@ -508,15 +503,15 @@ out_no_room() ...@@ -508,15 +503,15 @@ out_no_room()
local desc="Missing trace room" local desc="Missing trace room"
[ "$1" = "encap" ] && mode="$1 tundst db01::1" || mode="$1" [ "$1" = "encap" ] && mode="$1 tundst db01::1" || mode="$1"
[ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 up [ "$1" = "encap" ] && ip -netns $ioam_node_beta link set ip6tnl0 up
ip -netns ioam-node-alpha route change db01::/64 encap ioam6 mode $mode \ ip -netns $ioam_node_alpha route change db01::/64 encap ioam6 mode $mode \
trace prealloc type 0xc00000 ns 123 size 4 dev veth0 trace prealloc type 0xc00000 ns 123 size 4 dev veth0
run_test ${FUNCNAME[0]} "${desc} ($1 mode)" ioam-node-alpha ioam-node-beta \ run_test ${FUNCNAME[0]} "${desc} ($1 mode)" $ioam_node_alpha $ioam_node_beta \
db01::2 db01::1 veth0 0xc00000 123 db01::2 db01::1 veth0 0xc00000 123
[ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 down [ "$1" = "encap" ] && ip -netns $ioam_node_beta link set ip6tnl0 down
} }
out_bits() out_bits()
...@@ -532,11 +527,11 @@ out_bits() ...@@ -532,11 +527,11 @@ out_bits()
bit2size[22]=$(( $tmp + ${#ALPHA[9]} + ((4 - (${#ALPHA[9]} % 4)) % 4) )) bit2size[22]=$(( $tmp + ${#ALPHA[9]} + ((4 - (${#ALPHA[9]} % 4)) % 4) ))
[ "$1" = "encap" ] && mode="$1 tundst db01::1" || mode="$1" [ "$1" = "encap" ] && mode="$1 tundst db01::1" || mode="$1"
[ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 up [ "$1" = "encap" ] && ip -netns $ioam_node_beta link set ip6tnl0 up
for i in {0..22} for i in {0..22}
do do
ip -netns ioam-node-alpha route change db01::/64 encap ioam6 mode $mode \ ip -netns $ioam_node_alpha route change db01::/64 encap ioam6 mode $mode \
trace prealloc type ${bit2type[$i]} ns 123 size ${bit2size[$i]} \ trace prealloc type ${bit2type[$i]} ns 123 size ${bit2size[$i]} \
dev veth0 &>/dev/null dev veth0 &>/dev/null
...@@ -554,12 +549,12 @@ out_bits() ...@@ -554,12 +549,12 @@ out_bits()
log_test_failed "$descr" log_test_failed "$descr"
fi fi
else else
run_test "out_bit$i" "$descr ($1 mode)" ioam-node-alpha \ run_test "out_bit$i" "$descr ($1 mode)" $ioam_node_alpha \
ioam-node-beta db01::2 db01::1 veth0 ${bit2type[$i]} 123 $ioam_node_beta db01::2 db01::1 veth0 ${bit2type[$i]} 123
fi fi
done done
[ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 down [ "$1" = "encap" ] && ip -netns $ioam_node_beta link set ip6tnl0 down
bit2size[22]=$tmp bit2size[22]=$tmp
} }
...@@ -573,15 +568,15 @@ out_full_supp_trace() ...@@ -573,15 +568,15 @@ out_full_supp_trace()
local desc="Full supported trace" local desc="Full supported trace"
[ "$1" = "encap" ] && mode="$1 tundst db01::1" || mode="$1" [ "$1" = "encap" ] && mode="$1 tundst db01::1" || mode="$1"
[ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 up [ "$1" = "encap" ] && ip -netns $ioam_node_beta link set ip6tnl0 up
ip -netns ioam-node-alpha route change db01::/64 encap ioam6 mode $mode \ ip -netns $ioam_node_alpha route change db01::/64 encap ioam6 mode $mode \
trace prealloc type 0xfff002 ns 123 size 100 dev veth0 trace prealloc type 0xfff002 ns 123 size 100 dev veth0
run_test ${FUNCNAME[0]} "${desc} ($1 mode)" ioam-node-alpha ioam-node-beta \ run_test ${FUNCNAME[0]} "${desc} ($1 mode)" $ioam_node_alpha $ioam_node_beta \
db01::2 db01::1 veth0 0xfff002 123 db01::2 db01::1 veth0 0xfff002 123
[ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 down [ "$1" = "encap" ] && ip -netns $ioam_node_beta link set ip6tnl0 down
} }
...@@ -603,15 +598,15 @@ in_undef_ns() ...@@ -603,15 +598,15 @@ in_undef_ns()
local desc="Unknown IOAM namespace" local desc="Unknown IOAM namespace"
[ "$1" = "encap" ] && mode="$1 tundst db01::1" || mode="$1" [ "$1" = "encap" ] && mode="$1 tundst db01::1" || mode="$1"
[ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 up [ "$1" = "encap" ] && ip -netns $ioam_node_beta link set ip6tnl0 up
ip -netns ioam-node-alpha route change db01::/64 encap ioam6 mode $mode \ ip -netns $ioam_node_alpha route change db01::/64 encap ioam6 mode $mode \
trace prealloc type 0x800000 ns 0 size 4 dev veth0 trace prealloc type 0x800000 ns 0 size 4 dev veth0
run_test ${FUNCNAME[0]} "${desc} ($1 mode)" ioam-node-alpha ioam-node-beta \ run_test ${FUNCNAME[0]} "${desc} ($1 mode)" $ioam_node_alpha $ioam_node_beta \
db01::2 db01::1 veth0 0x800000 0 db01::2 db01::1 veth0 0x800000 0
[ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 down [ "$1" = "encap" ] && ip -netns $ioam_node_beta link set ip6tnl0 down
} }
in_no_room() in_no_room()
...@@ -623,15 +618,15 @@ in_no_room() ...@@ -623,15 +618,15 @@ in_no_room()
local desc="Missing trace room" local desc="Missing trace room"
[ "$1" = "encap" ] && mode="$1 tundst db01::1" || mode="$1" [ "$1" = "encap" ] && mode="$1 tundst db01::1" || mode="$1"
[ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 up [ "$1" = "encap" ] && ip -netns $ioam_node_beta link set ip6tnl0 up
ip -netns ioam-node-alpha route change db01::/64 encap ioam6 mode $mode \ ip -netns $ioam_node_alpha route change db01::/64 encap ioam6 mode $mode \
trace prealloc type 0xc00000 ns 123 size 4 dev veth0 trace prealloc type 0xc00000 ns 123 size 4 dev veth0
run_test ${FUNCNAME[0]} "${desc} ($1 mode)" ioam-node-alpha ioam-node-beta \ run_test ${FUNCNAME[0]} "${desc} ($1 mode)" $ioam_node_alpha $ioam_node_beta \
db01::2 db01::1 veth0 0xc00000 123 db01::2 db01::1 veth0 0xc00000 123
[ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 down [ "$1" = "encap" ] && ip -netns $ioam_node_beta link set ip6tnl0 down
} }
in_bits() in_bits()
...@@ -647,19 +642,19 @@ in_bits() ...@@ -647,19 +642,19 @@ in_bits()
bit2size[22]=$(( $tmp + ${#BETA[9]} + ((4 - (${#BETA[9]} % 4)) % 4) )) bit2size[22]=$(( $tmp + ${#BETA[9]} + ((4 - (${#BETA[9]} % 4)) % 4) ))
[ "$1" = "encap" ] && mode="$1 tundst db01::1" || mode="$1" [ "$1" = "encap" ] && mode="$1 tundst db01::1" || mode="$1"
[ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 up [ "$1" = "encap" ] && ip -netns $ioam_node_beta link set ip6tnl0 up
for i in {0..11} {22..22} for i in {0..11} {22..22}
do do
ip -netns ioam-node-alpha route change db01::/64 encap ioam6 mode $mode \ ip -netns $ioam_node_alpha route change db01::/64 encap ioam6 mode $mode \
trace prealloc type ${bit2type[$i]} ns 123 size ${bit2size[$i]} \ trace prealloc type ${bit2type[$i]} ns 123 size ${bit2size[$i]} \
dev veth0 dev veth0
run_test "in_bit$i" "${desc/<n>/$i} ($1 mode)" ioam-node-alpha \ run_test "in_bit$i" "${desc/<n>/$i} ($1 mode)" $ioam_node_alpha \
ioam-node-beta db01::2 db01::1 veth0 ${bit2type[$i]} 123 $ioam_node_beta db01::2 db01::1 veth0 ${bit2type[$i]} 123
done done
[ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 down [ "$1" = "encap" ] && ip -netns $ioam_node_beta link set ip6tnl0 down
bit2size[22]=$tmp bit2size[22]=$tmp
} }
...@@ -675,22 +670,22 @@ in_oflag() ...@@ -675,22 +670,22 @@ in_oflag()
# Exception: # Exception:
# Here, we need the sender to set the Overflow flag. For that, we will add # Here, we need the sender to set the Overflow flag. For that, we will add
# back the IOAM namespace that was previously configured on the sender. # back the IOAM namespace that was previously configured on the sender.
ip -netns ioam-node-alpha ioam namespace add 123 ip -netns $ioam_node_alpha ioam namespace add 123
[ "$1" = "encap" ] && mode="$1 tundst db01::1" || mode="$1" [ "$1" = "encap" ] && mode="$1 tundst db01::1" || mode="$1"
[ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 up [ "$1" = "encap" ] && ip -netns $ioam_node_beta link set ip6tnl0 up
ip -netns ioam-node-alpha route change db01::/64 encap ioam6 mode $mode \ ip -netns $ioam_node_alpha route change db01::/64 encap ioam6 mode $mode \
trace prealloc type 0xc00000 ns 123 size 4 dev veth0 trace prealloc type 0xc00000 ns 123 size 4 dev veth0
run_test ${FUNCNAME[0]} "${desc} ($1 mode)" ioam-node-alpha ioam-node-beta \ run_test ${FUNCNAME[0]} "${desc} ($1 mode)" $ioam_node_alpha $ioam_node_beta \
db01::2 db01::1 veth0 0xc00000 123 db01::2 db01::1 veth0 0xc00000 123
[ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 down [ "$1" = "encap" ] && ip -netns $ioam_node_beta link set ip6tnl0 down
# And we clean the exception for this test to get things back to normal for # And we clean the exception for this test to get things back to normal for
# other INPUT tests # other INPUT tests
ip -netns ioam-node-alpha ioam namespace del 123 ip -netns $ioam_node_alpha ioam namespace del 123
} }
in_full_supp_trace() in_full_supp_trace()
...@@ -702,15 +697,15 @@ in_full_supp_trace() ...@@ -702,15 +697,15 @@ in_full_supp_trace()
local desc="Full supported trace" local desc="Full supported trace"
[ "$1" = "encap" ] && mode="$1 tundst db01::1" || mode="$1" [ "$1" = "encap" ] && mode="$1 tundst db01::1" || mode="$1"
[ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 up [ "$1" = "encap" ] && ip -netns $ioam_node_beta link set ip6tnl0 up
ip -netns ioam-node-alpha route change db01::/64 encap ioam6 mode $mode \ ip -netns $ioam_node_alpha route change db01::/64 encap ioam6 mode $mode \
trace prealloc type 0xfff002 ns 123 size 80 dev veth0 trace prealloc type 0xfff002 ns 123 size 80 dev veth0
run_test ${FUNCNAME[0]} "${desc} ($1 mode)" ioam-node-alpha ioam-node-beta \ run_test ${FUNCNAME[0]} "${desc} ($1 mode)" $ioam_node_alpha $ioam_node_beta \
db01::2 db01::1 veth0 0xfff002 123 db01::2 db01::1 veth0 0xfff002 123
[ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 down [ "$1" = "encap" ] && ip -netns $ioam_node_beta link set ip6tnl0 down
} }
...@@ -730,15 +725,15 @@ fwd_full_supp_trace() ...@@ -730,15 +725,15 @@ fwd_full_supp_trace()
local desc="Forward - Full supported trace" local desc="Forward - Full supported trace"
[ "$1" = "encap" ] && mode="$1 tundst db02::2" || mode="$1" [ "$1" = "encap" ] && mode="$1 tundst db02::2" || mode="$1"
[ "$1" = "encap" ] && ip -netns ioam-node-gamma link set ip6tnl0 up [ "$1" = "encap" ] && ip -netns $ioam_node_gamma link set ip6tnl0 up
ip -netns ioam-node-alpha route change db02::/64 encap ioam6 mode $mode \ ip -netns $ioam_node_alpha route change db02::/64 encap ioam6 mode $mode \
trace prealloc type 0xfff002 ns 123 size 244 via db01::1 dev veth0 trace prealloc type 0xfff002 ns 123 size 244 via db01::1 dev veth0
run_test ${FUNCNAME[0]} "${desc} ($1 mode)" ioam-node-alpha ioam-node-gamma \ run_test ${FUNCNAME[0]} "${desc} ($1 mode)" $ioam_node_alpha $ioam_node_gamma \
db01::2 db02::2 veth0 0xfff002 123 db01::2 db02::2 veth0 0xfff002 123
[ "$1" = "encap" ] && ip -netns ioam-node-gamma link set ip6tnl0 down [ "$1" = "encap" ] && ip -netns $ioam_node_gamma link set ip6tnl0 down
} }
......
...@@ -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