tools/testing/selftests/net/netfilter/nft_interface_stress.sh

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

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/net/netfilter/nft_interface_stress.sh
Extension
.sh
Size
3699 bytes
Lines
158
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 -e
#
# SPDX-License-Identifier: GPL-2.0
#
# Torture nftables' netdevice notifier callbacks and related code by frequent
# renaming of interfaces which netdev-family chains and flowtables hook into.

source lib.sh

checktool "nft --version" "run test without nft tool"
checktool "iperf3 --version" "run test without iperf3 tool"

read kernel_tainted < /proc/sys/kernel/tainted

# how many seconds to torture the kernel?
# default to 80% of max run time but don't exceed 48s
TEST_RUNTIME=$((${kselftest_timeout:-60} * 8 / 10))
[[ $TEST_RUNTIME -gt 48 ]] && TEST_RUNTIME=48

trap "cleanup_all_ns" EXIT

setup_ns nsc nsr nss

ip -net $nsc link add cr0 type veth peer name rc0 netns $nsr
ip -net $nsc addr add 10.0.0.1/24 dev cr0
ip -net $nsc link set cr0 up
ip -net $nsc route add default via 10.0.0.2

ip -net $nss link add sr0 type veth peer name rs0 netns $nsr
ip -net $nss addr add 10.1.0.1/24 dev sr0
ip -net $nss link set sr0 up
ip -net $nss route add default via 10.1.0.2

ip -net $nsr addr add 10.0.0.2/24 dev rc0
ip -net $nsr link set rc0 up
ip -net $nsr addr add 10.1.0.2/24 dev rs0
ip -net $nsr link set rs0 up
ip netns exec $nsr sysctl -q net.ipv4.ip_forward=1
ip netns exec $nsr sysctl -q net.ipv4.conf.all.forwarding=1

{
	echo "table netdev t {"
	for ((i = 0; i < 10; i++)); do
		cat <<-EOF
		chain chain_rc$i {
			type filter hook ingress device rc$i priority 0
			counter
		}
		chain chain_rs$i {
			type filter hook ingress device rs$i priority 0
			counter
		}
		EOF
	done
	echo "}"
	echo "table ip t {"
	for ((i = 0; i < 10; i++)); do
		cat <<-EOF
		flowtable ft_${i} {
			hook ingress priority 0
			devices = { rc$i, rs$i }
		}
		EOF
	done
	echo "chain c {"
	echo "type filter hook forward priority 0"
	for ((i = 0; i < 10; i++)); do
		echo -n "iifname rc$i oifname rs$i "
		echo    "ip protocol tcp counter flow add @ft_${i}"
	done

Annotation

Implementation Notes