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

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

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/net/netfilter/conntrack_icmp_related.sh
Extension
.sh
Size
7763 bytes
Lines
279
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
#
# check that ICMP df-needed/pkttoobig icmp are set are set as related
# state
#
# Setup is:
#
# nsclient1 -> nsrouter1 -> nsrouter2 -> nsclient2
# MTU 1500, except for nsrouter2 <-> nsclient2 link (1280).
# ping nsclient2 from nsclient1, checking that conntrack did set RELATED
# 'fragmentation needed' icmp packet.
#
# In addition, nsrouter1 will perform IP masquerading, i.e. also
# check the icmp errors are propagated to the correct host as per
# nat of "established" icmp-echo "connection".

source lib.sh

if ! nft --version > /dev/null 2>&1;then
	echo "SKIP: Could not run test without nft tool"
	exit $ksft_skip
fi

cleanup() {
	cleanup_all_ns
}

trap cleanup EXIT

setup_ns nsclient1 nsclient2 nsrouter1 nsrouter2

ret=0

add_addr()
{
	ns=$1
	dev=$2
	i=$3

	ip -net "$ns" link set "$dev" up
	ip -net "$ns" addr add "192.168.$i.2/24" dev "$dev"
	ip -net "$ns" addr add "dead:$i::2/64" dev "$dev" nodad
}

check_counter()
{
	ns=$1
	name=$2
	expect=$3
	local lret=0

	if ! ip netns exec "$ns" nft list counter inet filter "$name" | grep -q "$expect"; then
		echo "ERROR: counter $name in $ns has unexpected value (expected $expect)" 1>&2
		ip netns exec "$ns" nft list counter inet filter "$name" 1>&2
		lret=1
	fi

	return $lret
}

check_unknown()
{
	expect="packets 0 bytes 0"
	for n in ${nsclient1} ${nsclient2} ${nsrouter1} ${nsrouter2}; do
		if ! check_counter "$n" "unknown" "$expect"; then
			return 1
		fi
	done

	return 0

Annotation

Implementation Notes