expand cmsg_ipv6.sh with ipv4 support
Subsystems (3)
cover expand cmsg_ipv6.sh with ipv4 support
From: Willem de Bruijn <[email protected]>
Expand IPV6_TCLASS to also cover IP_TOS.
Expand IPV6_HOPLIMIT to also cover IP_TTL.
A series of two patches for basic readability (patch 1 is a noop), and so that git does not interpret code changes + file rename as a whole file del + add.
Willem de Bruijn (2):
selftests/net: prepare cmsg_ipv6.sh for ipv4
selftests/net: expand cmsg_ipv6.sh with ipv4
tools/testing/selftests/net/Makefile | 2 +- tools/testing/selftests/net/cmsg_ip.sh | 184 ++++++++++++++++++++++ tools/testing/selftests/net/cmsg_ipv6.sh | 154 ------------------ tools/testing/selftests/net/cmsg_sender.c | 90 +++++++---- 4 files changed, 240 insertions(+), 190 deletions(-) create mode 100755 tools/testing/selftests/net/cmsg_ip.sh delete mode 100755 tools/testing/selftests/net/cmsg_ipv6.sh
Signature · 1 line
2.48.1.658.g4767266eb4-goog
PATCH 1/2 selftests/net: prepare cmsg_ipv6.sh for ipv4
From: Willem de Bruijn <[email protected]>
Move IPV6_TCLASS and IPV6_HOPLIMIT into loops, to be able to use them for IP_TOS and IP_TTL in a follow-on patch.
Indentation in this file is a mix of four spaces and tabs for double indents. To minimize code churn, maintain that pattern.
Very small diff if viewing with -w.
--- tools/testing/selftests/net/cmsg_ipv6.sh | 109 ++++++++++++----------- 1 file changed, 59 insertions(+), 50 deletions(-)
tools/testing/selftests/net/cmsg_ipv6.sh +59 -50
@@ -64,76 +64,85 @@ for ovr in setsock cmsg both diff; do done # IPV6_TCLASS -TOS=0x10 -TOS2=0x20 -ip -6 -netns $NS rule add tos $TOS lookup 300 -ip -6 -netns $NS route add table 300 prohibit any +test_dscp() { + local -r TOS=0x10 + local -r TOS2=0x20 -for ovr in setsock cmsg both diff; do - for p in u i r; do - [ $p == "u" ] && prot=UDP - [ $p == "i" ] && prot=ICMP - [ $p == "r" ] && prot=RAW + ip -6 -netns $NS rule add tos $TOS lookup 300 + ip -6 -netns $NS route add table 300 prohibit any - [ $ovr == "setsock" ] && m="-C" - [ $ovr == "cmsg" ] && m="-c" - [ $ovr == "both" ] && m="-C $((TOS2)) -c" - [ $ovr == "diff" ] && m="-C $((TOS )) -c" + for ovr in setsock cmsg both diff; do + for p in u i r; do + [ $p == "u" ] && prot=UDP + [ $p == "i" ] && prot=ICMP + [ $p == "r" ] && prot=RAW - $NSEXE nohup tcpdump --immediate-mode -p -ni dummy0 -w $TMPF -c 4 2> /dev/null & - BG=$! - sleep 0.05 + [ $ovr == "setsock" ] && m="-C" + [ $ovr == "cmsg" ] && m="-c" + [ $ovr == "both" ] && m="-C $((TOS2)) -c" + [ $ovr == "diff" ] && m="-C $((TOS )) -c" - $NSEXE ./cmsg_sender -6 -p $p $m $((TOS2)) $TGT6 1234 - check_result $? 0 "TCLASS $prot $ovr - pass" + $NSEXE nohup tcpdump --immediate-mode -p -ni dummy0 -w $TMPF -c 4 2> /dev/null & + BG=$! + sleep 0.05 - while [ -d /proc/$BG ]; do $NSEXE ./cmsg_sender -6 -p $p $m $((TOS2)) $TGT6 1234 - done + check_result $? 0 "TCLASS $prot $ovr - pass" - tcpdump -r $TMPF -v 2>&1 | grep "class $TOS2" >> /dev/null - check_result $? 0 "TCLASS $prot $ovr - packet data" - rm $TMPF + while [ -d /proc/$BG ]; do + $NSEXE ./cmsg_sender -6 -p $p $m $((TOS2)) $TGT6 1234 + done - [ $ovr == "both" ] && m="-C $((TOS )) -c" - [ $ovr == "diff" ] && m="-C $((TOS2)) -c" + tcpdump -r $TMPF -v 2>&1 | grep "class $TOS2" >> /dev/null + check_result $? 0 "TCLASS $prot $ovr - packet data" + rm $TMPF - $NSEXE ./cmsg_sender -6 -p $p $m $((TOS)) -s $TGT6 1234 - check_result $? 1 "TCLASS $prot $ovr - rejection" + [ $ovr == "both" ] && m="-C $((TOS )) -c" + [ $ovr == "diff" ] && m="-C $((TOS2)) -c" + + $NSEXE ./cmsg_sender -6 -p $p $m $((TOS)) -s $TGT6 1234 + check_result $? 1 "TCLASS $prot $ovr - rejection" + done done -done +} -# IPV6_HOPLIMIT -LIM=4 +test_dscp -for ovr in setsock cmsg both diff; do - for p in u i r; do - [ $p == "u" ] && prot=UDP - [ $p == "i" ] && prot=ICMP - [ $p == "r" ] && prot=RAW +# IPV6_HOPLIMIT +test_hoplimit() { + local -r LIM=4 - [ $ovr == "setsock" ] && m="-L" - [ $ovr == "cmsg" ] && m="-l" - [ $ovr == "both" ] && m="-L $LIM -l" - [ $ovr == "diff" ] && m="-L $((LIM + 1)) -l" + for ovr in setsock cmsg both diff; do + for p in u i r; do + [ $p == "u" ] && prot=UDP + [ $p == "i" ] && prot=ICMP + [ $p == "r" ] && prot=RAW - $NSEXE nohup tcpdump --immediate-mode -p -ni dummy0 -w $TMPF -c 4 2> /dev/null & - BG=$! - sleep 0.05 + [ $ovr == "setsock" ] && m="-L" + [ $ovr == "cmsg" ] && m="-l" + [ $ovr == "both" ] && m="-L $LIM -l" + [ $ovr == "diff" ] && m="-L $((LIM + 1)) -l" - $NSEXE ./cmsg_sender -6 -p $p $m $LIM $TGT6 1234 - check_result $? 0 "HOPLIMIT $prot $ovr - pass" + $NSEXE nohup tcpdump --immediate-mode -p -ni dummy0 -w $TMPF -c 4 2> /dev/null & + BG=$! + sleep 0.05 - while [ -d /proc/$BG ]; do $NSEXE ./cmsg_sender -6 -p $p $m $LIM $TGT6 1234 - done + check_result $? 0 "HOPLIMIT $prot $ovr - pass" - tcpdump -r $TMPF -v 2>&1 | grep "hlim $LIM[^0-9]" >> /dev/null - check_result $? 0 "HOPLIMIT $prot $ovr - packet data" - rm $TMPF + while [ -d /proc/$BG ]; do + $NSEXE ./cmsg_sender -6 -p $p $m $LIM $TGT6 1234 + done + + tcpdump -r $TMPF -v 2>&1 | grep "hlim $LIM[^0-9]" >> /dev/null + check_result $? 0 "HOPLIMIT $prot $ovr - packet data" + rm $TMPF + done done -done +} + +test_hoplimit # IPV6 exthdr for p in u i r; do
Signature · 1 line
2.48.1.658.g4767266eb4-goog
PATCH 2/2 selftests/net: expand cmsg_ipv6.sh with ipv4
In reply to Willem de BruijnFrom: Willem de Bruijn <[email protected]>
Expand IPV6_TCLASS to also cover IP_TOS.
Expand IPV6_HOPLIMIT to also cover IP_TTL.
Expand csmg_sender.c to allow setting IPv4 setsockopts. Also rename struct v6 to cmsg to match its expanded scope. Don't bother updating all occurrences of tclass and hoplimit.
Rename cmsg_ipv6.sh to cmsg_ip.sh to match the expanded scope.
Be careful around the subtle API difference between TCLASS and TOS. IP_TOS includes ECN bits. Add a test to verify that these are masked when making routing decisions.
Diff is more concise with --word-diff
---
tools/testing/selftests/net/Makefile | 2 +-
.../net/{cmsg_ipv6.sh => cmsg_ip.sh} | 59 ++++++++----
tools/testing/selftests/net/cmsg_sender.c | 90 +++++++++++--------
3 files changed, 96 insertions(+), 55 deletions(-)
rename tools/testing/selftests/net/{cmsg_ipv6.sh => cmsg_ip.sh} (65%)tools/testing/selftests/net/Makefile +1 -1
@@ -34,7 +34,7 @@ TEST_PROGS += gre_gso.sh TEST_PROGS += cmsg_so_mark.sh TEST_PROGS += cmsg_so_priority.sh TEST_PROGS += test_so_rcv.sh -TEST_PROGS += cmsg_time.sh cmsg_ipv6.sh +TEST_PROGS += cmsg_time.sh cmsg_ip.sh TEST_PROGS += netns-name.sh TEST_PROGS += link_netns.py TEST_PROGS += nl_netdev.py
tools/testing/selftests/net/cmsg_ip.sh renamed from tools/testing/selftests/net/cmsg_ipv6.sh +40 -19
117 lines not on this page · raw message
tools/testing/selftests/net/cmsg_sender.c +55 -35
158 lines not on this page · raw message
Signature · 1 line
2.48.1.658.g4767266eb4-goog
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 10 lines · On Mon, 24 Feb 2025 21:23:57 -0500 you wrote:
From: Willem de Bruijn <[email protected]>
Expand
IPV6_TCLASSto also coverIP_TOS.
ExpandIPV6_HOPLIMITto also coverIP_TTL.A series of two patches for basic readability (patch 1 is a noop), and so that git does not interpret code changes + file rename as a whole file del + add.
[...]
Here is the summary with links:
- [net-next,1/2] selftests/net: prepare cmsg_ipv6.sh for ipv4
https://git.kernel.org/netdev/net-next/c/c1d6d629ab0b - [net-next,2/2] selftests/net: expand cmsg_ipv6.sh with ipv4 https://git.kernel.org/netdev/net-next/c/2e5584e0f913
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html