tools/testing/selftests/net/netfilter/nf_nat_edemux.sh
Source file repositories/reference/linux-study-clean/tools/testing/selftests/net/netfilter/nf_nat_edemux.sh
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/net/netfilter/nf_nat_edemux.sh- Extension
.sh- Size
- 3484 bytes
- Lines
- 122
- 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.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
function connect_done
Annotated Snippet
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
#
# Test NAT source port clash resolution
#
source lib.sh
ret=0
socatpid=0
cleanup()
{
[ "$socatpid" -gt 0 ] && kill "$socatpid"
cleanup_all_ns
}
checktool "socat -h" "run test without socat"
checktool "iptables --version" "run test without iptables"
checktool "conntrack --version" "run test without conntrack"
trap cleanup EXIT
connect_done()
{
local ns="$1"
local port="$2"
ip netns exec "$ns" ss -nt -o state established "dport = :$port" | grep -q "$port"
}
check_ctstate()
{
local ns="$1"
local dp="$2"
if ! ip netns exec "$ns" conntrack --get -s 192.168.1.2 -d 192.168.1.1 -p tcp \
--sport 10000 --dport "$dp" --state ESTABLISHED > /dev/null 2>&1;then
echo "FAIL: Did not find expected state for dport $2"
ip netns exec "$ns" bash -c 'conntrack -L; conntrack -S; ss -nt'
ret=1
fi
}
setup_ns ns1 ns2
# Connect the namespaces using a veth pair
ip link add name veth2 type veth peer name veth1
ip link set netns "$ns1" dev veth1
ip link set netns "$ns2" dev veth2
ip netns exec "$ns1" ip link set up dev lo
ip netns exec "$ns1" ip link set up dev veth1
ip netns exec "$ns1" ip addr add 192.168.1.1/24 dev veth1
ip netns exec "$ns2" ip link set up dev lo
ip netns exec "$ns2" ip link set up dev veth2
ip netns exec "$ns2" ip addr add 192.168.1.2/24 dev veth2
# Create a server in one namespace
ip netns exec "$ns1" socat -u TCP-LISTEN:5201,fork OPEN:/dev/null,wronly=1 &
socatpid=$!
# Restrict source port to just one so we don't have to exhaust
# all others.
ip netns exec "$ns2" sysctl -q net.ipv4.ip_local_port_range="10000 10000"
# add a virtual IP using DNAT
ip netns exec "$ns2" iptables -t nat -A OUTPUT -d 10.96.0.1/32 -p tcp --dport 443 -j DNAT --to-destination 192.168.1.1:5201 || exit 1
Annotation
- Detected declarations: `function connect_done`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: atlas-only.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.