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

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

File Facts

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

# Conntrack needs to reassemble fragments in order to have complete
# packets for rule matching.  Reassembly can lead to packet loss.

# Consider the following setup:
#            +--------+       +---------+       +--------+
#            |Router A|-------|Wanrouter|-------|Router B|
#            |        |.IPIP..|         |..IPIP.|        |
#            +--------+       +---------+       +--------+
#           /                  mtu 1400                   \
#          /                                               \
#+--------+                                                 +--------+
#|Client A|                                                 |Client B|
#|        |                                                 |        |
#+--------+                                                 +--------+

# Router A and Router B use IPIP tunnel interfaces to tunnel traffic
# between Client A and Client B over WAN. Wanrouter has MTU 1400 set
# on its interfaces.

rx=$(mktemp)

checktool "iptables --version" "run test without iptables"
checktool "socat -h" "run test without socat"

setup_ns r_a r_b r_w c_a c_b

cleanup() {
	cleanup_all_ns
	rm -f "$rx"
}

trap cleanup EXIT

listener_ready()
{
	ns="$1"
	port="$2"
	ss -N "$ns" -lnu -o "sport = :$port" | grep -q "$port"
}

test_path() {
	msg="$1"

	ip netns exec "$c_b" socat -t 3 - udp4-listen:5000,reuseaddr > "$rx" < /dev/null &

	busywait $BUSYWAIT_TIMEOUT listener_ready "$c_b" 5000

	for i in 1 2 3; do
		head -c1400 /dev/zero | tr "\000" "a" | \
			ip netns exec "$c_a" socat -t 1 -u STDIN UDP:192.168.20.2:5000
	done

	wait

	bytes=$(wc -c < "$rx")

	if [ "$bytes" -eq 1400 ];then
		echo "OK: PMTU $msg connection tracking"
	else
		echo "FAIL: PMTU $msg connection tracking: got $bytes, expected 1400"
		exit 1
	fi
}

# Detailed setup for Router A

Annotation

Implementation Notes