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

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.com


Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parents 333f3396 0f4765d0
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -54,7 +54,7 @@ TEST_PROGS += ip_local_port_range.sh
TEST_PROGS += rps_default_mask.sh
TEST_PROGS += big_tcp.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 += psock_fanout psock_tpacket msg_zerocopy reuseport_addr_any
TEST_GEN_FILES += tcp_mmap tcp_inq psock_snd txring_overwrite
+16 −30
Original line number Diff line number Diff line
@@ -12,7 +12,8 @@
# {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_ADDR1=10.0.10.2
readonly V6_ADDR0=2001:db8:91::1
@@ -22,43 +23,29 @@ ret=0

cleanup_v6()
{
    ip netns del me
    ip netns del peer
    cleanup_ns ${me} ${peer}

    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
}

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() {
    create_ns me
    create_ns peer
    setup_ns me peer

    IP="ip -netns me"
    IP="ip -netns ${me}"

    $IP li add veth1 type veth peer name veth2
    $IP li set veth1 up
    $IP -6 addr add $V6_ADDR0/64 dev veth1 nodad
    $IP li set veth2 netns peer up
    ip -netns peer -6 addr add $V6_ADDR1/64 dev veth2 nodad
    $IP li set veth2 netns ${peer} up
    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
    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
    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
        cleanup_v6
        echo "failed"
@@ -66,11 +53,11 @@ setup_v6() {
    fi

    # 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() {
    ip netns add "${PEER_NS}"
    setup_ns PEER_NS
    ip link add name veth0 type veth peer name veth1
    ip link set dev veth0 up
    ip link set dev veth1 netns "${PEER_NS}"
@@ -99,8 +86,7 @@ setup_v4() {
cleanup_v4() {
    ip neigh flush dev veth0
    ip link del veth0
    local -r ns="$(ip netns list|grep $PEER_NS)"
    [ -n "$ns" ] && ip netns del $ns 2>/dev/null
    cleanup_ns $PEER_NS

    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
@@ -163,7 +149,7 @@ run_ndisc_evict_nocarrier_enabled() {

    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
        echo "failed"
@@ -180,7 +166,7 @@ run_ndisc_evict_nocarrier_disabled() {

    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
        echo "ok"
@@ -197,7 +183,7 @@ run_ndisc_evict_nocarrier_disabled_all() {

    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
        echo "ok"
+7 −13
Original line number Diff line number Diff line
@@ -5,16 +5,14 @@
# garp to the router. Router accepts or ignores based on its arp_accept
# or accept_untracked_na configuration.

source lib.sh

TESTS="arp ndisc"

ROUTER_NS="ns-router"
ROUTER_NS_V6="ns-router-v6"
ROUTER_INTF="veth-router"
ROUTER_ADDR="10.0.10.1"
ROUTER_ADDR_V6="2001:db8:abcd:0012::1"

HOST_NS="ns-host"
HOST_NS_V6="ns-host-v6"
HOST_INTF="veth-host"
HOST_ADDR="10.0.10.2"
HOST_ADDR_V6="2001:db8:abcd:0012::2"
@@ -23,13 +21,11 @@ SUBNET_WIDTH=24
PREFIX_WIDTH_V6=64

cleanup() {
	ip netns del ${HOST_NS}
	ip netns del ${ROUTER_NS}
	cleanup_ns ${HOST_NS} ${ROUTER_NS}
}

cleanup_v6() {
	ip netns del ${HOST_NS_V6}
	ip netns del ${ROUTER_NS_V6}
	cleanup_ns ${HOST_NS_V6} ${ROUTER_NS_V6}
}

setup() {
@@ -37,8 +33,7 @@ setup() {
	local arp_accept=$1

	# Set up two namespaces
	ip netns add ${ROUTER_NS}
	ip netns add ${HOST_NS}
	setup_ns HOST_NS ROUTER_NS

	# Set up interfaces veth0 and veth1, which are pairs in separate
	# namespaces. veth0 is veth-router, veth1 is veth-host.
@@ -72,8 +67,7 @@ setup_v6() {
	local accept_untracked_na=$1

	# Set up two namespaces
	ip netns add ${ROUTER_NS_V6}
	ip netns add ${HOST_NS_V6}
	setup_ns HOST_NS_V6 ROUTER_NS_V6

	# Set up interfaces veth0 and veth1, which are pairs in separate
	# namespaces. veth0 is veth-router, veth1 is veth-host.
@@ -150,7 +144,7 @@ arp_test_gratuitous() {
	fi
	# Supply arp_accept option to set up which sets it in sysctl
	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
		printf "    TEST: %-60s  [ OK ]\n" "${test_msg[*]}"
+4 −6
Original line number Diff line number Diff line
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0

ksft_skip=4
source lib.sh

NS=ns
IP6=2001:db8:1::1/64
TGT6=2001:db8:1::2
TMPF=$(mktemp --suffix ".pcap")
@@ -11,13 +10,11 @@ TMPF=$(mktemp --suffix ".pcap")
cleanup()
{
    rm -f $TMPF
    ip netns del $NS
    cleanup_ns $NS
}

trap cleanup EXIT

NSEXE="ip netns exec $NS"

tcpdump -h | grep immediate-mode >> /dev/null
if [ $? -ne 0 ]; then
    echo "SKIP - tcpdump with --immediate-mode option required"
@@ -25,7 +22,8 @@ if [ $? -ne 0 ]; then
fi

# 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

+4 −3
Original line number Diff line number Diff line
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0

NS=ns
source lib.sh

IP4=172.16.0.1/24
TGT4=172.16.0.2
IP6=2001:db8:1::1/64
@@ -10,13 +11,13 @@ MARK=1000

cleanup()
{
    ip netns del $NS
    cleanup_ns $NS
}

trap cleanup EXIT

# Namespaces
ip netns add $NS
setup_ns NS

ip netns exec $NS sysctl -w net.ipv4.ping_group_range='0 2147483647' > /dev/null

Loading