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

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

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/net/netfilter/conntrack_resize.sh
Extension
.sh
Size
11381 bytes
Lines
516
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

source lib.sh

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

init_net_max=0
ct_buckets=0
tmpfile=""
tmpfile_proc=""
tmpfile_uniq=""
ret=0
have_socat=0

socat -h > /dev/null && have_socat=1

insert_count=2000
[ "$KSFT_MACHINE_SLOW" = "yes" ] && insert_count=400

modprobe -q nf_conntrack
if ! sysctl -q net.netfilter.nf_conntrack_max >/dev/null;then
	echo "SKIP: conntrack sysctls not available"
	exit $KSFT_SKIP
fi

init_net_max=$(sysctl -n net.netfilter.nf_conntrack_max) || exit 1
ct_buckets=$(sysctl -n net.netfilter.nf_conntrack_buckets) || exit 1

cleanup() {
	cleanup_all_ns

	rm -f "$tmpfile" "$tmpfile_proc" "$tmpfile_uniq"

	# restore original sysctl setting
	sysctl -q net.netfilter.nf_conntrack_max=$init_net_max
	sysctl -q net.netfilter.nf_conntrack_buckets=$ct_buckets
}
trap cleanup EXIT

check_max_alias()
{
	local expected="$1"
	# old name, expected to alias to the first, i.e. changing one
	# changes the other as well.
	local lv=$(sysctl -n net.nf_conntrack_max)

	if [ $expected -ne "$lv" ];then
		echo "nf_conntrack_max sysctls should have identical values"
		exit 1
	fi
}

insert_ctnetlink() {
	local ns="$1"
	local count="$2"
	local i=0
	local bulk=16

	while [ $i -lt $count ] ;do
		ip netns exec "$ns" bash -c "for i in \$(seq 1 $bulk); do \
			if ! conntrack -I -s \$((\$RANDOM%256)).\$((\$RANDOM%256)).\$((\$RANDOM%256)).\$((\$RANDOM%255+1)) \
					  -d \$((\$RANDOM%256)).\$((\$RANDOM%256)).\$((\$RANDOM%256)).\$((\$RANDOM%255+1)) \
					  --protonum 17 --timeout 3600 --status ASSURED,SEEN_REPLY --sport \$RANDOM --dport 53; then \
					  return;\
			fi & \
		done ; wait" 2>/dev/null

		i=$((i+bulk))

Annotation

Implementation Notes