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

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

File Facts

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

cleanup()
{
	cleanup_all_ns
}

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

trap cleanup EXIT

setup_ns ns0

# make loopback connections get nat null bindings assigned
ip netns exec "$ns0" nft -f - <<EOF
table ip nat {
        chain POSTROUTING {
                type nat hook postrouting priority srcnat; policy accept;
                oifname "nomatch" counter packets 0 bytes 0 masquerade
        }
}
EOF

do_flush()
{
	local end
	local now

	now=$(date +%s)
	end=$((now + 5))

	while [ $now -lt $end ];do
		ip netns exec "$ns0" conntrack -F 2>/dev/null
		now=$(date +%s)
	done
}

do_flush &

if ip netns exec "$ns0" ./conntrack_reverse_clash; then
	echo "PASS: No SNAT performed for null bindings"
else
	echo "ERROR: SNAT performed without any matching snat rule"
	ip netns exec "$ns0" conntrack -L
	ip netns exec "$ns0" conntrack -S
	exit 1
fi

exit 0

Annotation

Implementation Notes