tools/testing/selftests/net/ipvtap_test.sh

Source file repositories/reference/linux-study-clean/tools/testing/selftests/net/ipvtap_test.sh

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/net/ipvtap_test.sh
Extension
.sh
Size
3301 bytes
Lines
169
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: tools
Status
atlas-only

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
#
# Simple tests for ipvtap


#
# The testing environment looks this way:
#
# |------HNS-------|     |------PHY-------|
# |      veth<----------------->veth      |
# |------|--|------|     |----------------|
#        |  |
#        |  |            |-----TST0-------|
#        |  |------------|----ipvlan      |
#        |               |----------------|
#        |
#        |               |-----TST1-------|
#        |---------------|----ipvlan      |
#                        |----------------|
#

ALL_TESTS="
	test_ip_set
"

source lib.sh

DEBUG=0

VETH_HOST=vethtst.h
VETH_PHY=vethtst.p

NS_COUNT=32
IP_ITERATIONS=1024
IPSET_TIMEOUT="60s"

ns_run() {
	ns=$1
	shift
	if [[ "$ns" == "global" ]]; then
		"$@" >/dev/null
	else
		ip netns exec "$ns" "$@" >/dev/null
	fi
}

test_ip_setup_env() {
	setup_ns NS_PHY
	setup_ns HST_NS

	# setup simulated other-host (phy) and host itself
	ns_run "$HST_NS" ip link add $VETH_HOST type veth peer name $VETH_PHY \
		netns "$NS_PHY" >/dev/null
	ns_run "$HST_NS" ip link set $VETH_HOST up
	ns_run "$NS_PHY" ip link set $VETH_PHY up

	for ((i=0; i<NS_COUNT; i++)); do
		setup_ns ipvlan_ns_$i
		ns="ipvlan_ns_$i"
		if [ "$DEBUG" = "1" ]; then
			echo "created NS ${!ns}"
		fi
		if ! ns_run "$HST_NS" ip link add netns ${!ns} ipvlan0 \
		    link $VETH_HOST \
		    type ipvtap mode l2 bridge; then
			exit_error "FAIL: Failed to configure ipvlan link."
		fi
	done
}

Annotation

Implementation Notes