tools/testing/selftests/net/netfilter/bridge_brouter.sh
Source file repositories/reference/linux-study-clean/tools/testing/selftests/net/netfilter/bridge_brouter.sh
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/net/netfilter/bridge_brouter.sh- Extension
.sh- Size
- 3782 bytes
- Lines
- 121
- 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 cleanup
Annotated Snippet
#!/bin/bash
#
# This test is for bridge 'brouting', i.e. make some packets being routed
# rather than getting bridged even though they arrive on interface that is
# part of a bridge.
# eth0 br0 eth0
# setup is: ns1 <-> nsbr <-> ns2
source lib.sh
if ! ebtables -V > /dev/null 2>&1;then
echo "SKIP: Could not run test without ebtables"
exit $ksft_skip
fi
cleanup() {
cleanup_all_ns
}
trap cleanup EXIT
setup_ns nsbr ns1 ns2
if ! ip link add veth0 netns "$nsbr" type veth peer name eth0 netns "$ns1"; then
echo "SKIP: Can't create veth device"
exit $ksft_skip
fi
ip link add veth1 netns "$nsbr" type veth peer name eth0 netns "$ns2"
if ! ip -net "$nsbr" link add br0 type bridge; then
echo "SKIP: Can't create bridge br0"
exit $ksft_skip
fi
ip -net "$nsbr" link set veth0 up
ip -net "$nsbr" link set veth1 up
ip -net "$nsbr" link set veth0 master br0
ip -net "$nsbr" link set veth1 master br0
ip -net "$nsbr" link set br0 up
ip -net "$nsbr" addr add 10.0.0.1/24 dev br0
# place both in same subnet, ${ns1} and ${ns2} connected via ${nsbr}:br0
ip -net "$ns1" link set eth0 up
ip -net "$ns2" link set eth0 up
ip -net "$ns1" addr add 10.0.0.11/24 dev eth0
ip -net "$ns2" addr add 10.0.0.12/24 dev eth0
test_ebtables_broute()
{
# redirect is needed so the dstmac is rewritten to the bridge itself,
# ip stack won't process OTHERHOST (foreign unicast mac) packets.
if ! ip netns exec "$nsbr" ebtables -t broute -A BROUTING -p ipv4 --ip-protocol icmp -j redirect --redirect-target=DROP; then
echo "SKIP: Could not add ebtables broute redirect rule"
return $ksft_skip
fi
ip netns exec "$nsbr" sysctl -q net.ipv4.conf.veth0.forwarding=0
# ping net${ns1}, expected to not work (ip forwarding is off)
if ip netns exec "$ns1" ping -q -c 1 10.0.0.12 -W 0.5 > /dev/null 2>&1; then
echo "ERROR: ping works, should have failed" 1>&2
return 1
fi
# enable forwarding on both interfaces.
# neither needs an ip address, but at least the bridge needs
# an ip address in same network segment as ${ns1} and ${ns2} (${nsbr}
# needs to be able to determine route for to-be-forwarded packet).
Annotation
- Detected declarations: `function cleanup`.
- 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.