[PATCH v2 1/2] selftests: net: add test for broadcast destination
From: Brett A C Sheffield <hidden>
Date: 2025-08-23 12:15:06
Also in:
regressions, stable
Subsystem:
kernel selftest framework, networking [general], the rest · Maintainers:
Shuah Khan, "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Linus Torvalds
Add test to check the broadcast ethernet destination field is set correctly. This test uses the tcpdump and socat programs. Send a UDP broadcast packet to UDP port 9 (DISCARD), capture this with tcpdump and ensure that all bits of the 6 octet ethernet destination are correctly set. Cc: stable@vger.kernel.org Signed-off-by: Brett A C Sheffield <redacted> Link: https://lore.kernel.org/regressions/20250822165231.4353-4-bacs@librecast.net (local) --- tools/testing/selftests/net/Makefile | 1 + .../selftests/net/broadcast_ether_dst.sh | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100755 tools/testing/selftests/net/broadcast_ether_dst.sh
diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile
index b31a71f2b372..463642a78eea 100644
--- a/tools/testing/selftests/net/Makefile
+++ b/tools/testing/selftests/net/Makefile@@ -116,6 +116,7 @@ TEST_GEN_FILES += skf_net_off TEST_GEN_FILES += tfo TEST_PROGS += tfo_passive.sh TEST_PROGS += broadcast_pmtu.sh +TEST_PROGS += broadcast_ether_dst.sh TEST_PROGS += ipv6_force_forwarding.sh # YNL files, must be before "include ..lib.mk"
diff --git a/tools/testing/selftests/net/broadcast_ether_dst.sh b/tools/testing/selftests/net/broadcast_ether_dst.sh
new file mode 100755
index 000000000000..de6abe3513b6
--- /dev/null
+++ b/tools/testing/selftests/net/broadcast_ether_dst.sh@@ -0,0 +1,38 @@ +#!/bin/bash -eu +# SPDX-License-Identifier: GPL-2.0 +# +# Author: Brett A C Sheffield <bacs@librecast.net> +# +# Ensure destination ethernet field is correctly set for +# broadcast packets + +if ! which tcpdump > /dev/null 2>&1; then + echo "No tcpdump found. Required for this test." + exit $ERR +fi + +CAPFILE=$(mktemp -u cap.XXXXXXXXXX) + +# start tcpdump listening on udp port 9 +# tcpdump will exit after receiving a single packet +# timeout will kill tcpdump if it is still running after 2s +timeout 2s tcpdump -c 1 -w ${CAPFILE} udp port 9 > /dev/null 2>&1 & +PID=$! +sleep 0.1 # let tcpdump wake up + +echo "Testing ethernet broadcast destination" + +# send broadcast UDP packet to port 9 (DISCARD) +echo "Alonso is a good boy" | socat - udp-datagram:255.255.255.255:9,broadcast + +# wait for tcpdump for exit after receiving packet +wait $PID + +# compare ethernet destination field to ff:ff:ff:ff:ff:ff +# pcap has a 24 octet header + 16 octet header for each packet +# ethernet destination is the first field in the packet +printf '\xff\xff\xff\xff\xff\xff'| cmp -i40:0 -n6 ${CAPFILE} > /dev/null 2>&1 +RESULT=$? + +rm -f "${CAPFILE}" +exit $RESULT
base-commit: 01b9128c5db1b470575d07b05b67ffa3cb02ebf1 -- 2.49.1