Page MenuHomeFreeBSD

D62441.1796656023.diff
No OneTemporary

Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None

D62441.1796656023.diff

Index: tests/sys/netpfil/ipfw/Makefile
===================================================================
--- tests/sys/netpfil/ipfw/Makefile
+++ tests/sys/netpfil/ipfw/Makefile
@@ -8,6 +8,7 @@
log \
lookup \
nat \
+ setmss \
table \
tcpmss \
unmapped
Index: tests/sys/netpfil/ipfw/setmss.sh
===================================================================
--- /dev/null
+++ tests/sys/netpfil/ipfw/setmss.sh
@@ -0,0 +1,155 @@
+#
+# SPDX-License-Identifier: BSD-2-Clause
+#
+# Copyright (c) 2026 Osvaldo Janeri Filho <ojanerif@amd.com>
+#
+
+. $(atf_get_srcdir)/../common/utils.subr
+
+# Verify that the tcp-setmss eaction clamps the MSS in a TCP SYN.
+
+setmss_test()
+{
+ af=$1
+ src=$2
+ dst=$3
+ plen=$4
+
+ firewall_init ipfw
+
+ epair=$(vnet_mkepair)
+ vnet_mkjail srv ${epair}b
+ if [ ${af} = "inet" ]; then
+ ifconfig ${epair}a inet ${src}/${plen} up
+ jexec srv ifconfig ${epair}b inet ${dst}/${plen} up
+ else
+ ifconfig ${epair}a inet6 ${src}/${plen} up no_dad -ifdisabled
+ jexec srv ifconfig ${epair}b inet6 ${dst}/${plen} up no_dad \
+ -ifdisabled
+ fi
+
+ jexec srv kldload -n ipfw_pmod
+ firewall_config srv ipfw ipfw \
+ "ipfw -q add 100 tcp-setmss 1400 tcp from any to any setup"
+
+ # Start a listener in the jail.
+ jexec srv nc -l ${dst} 9999 &
+ sleep 1
+
+ # Capture the SYN-ACK to check the MSS.
+ jexec srv tcpdump -c 1 -n -i ${epair}b \
+ 'tcp[tcpflags] & (tcp-syn|tcp-ack) == (tcp-syn|tcp-ack)' \
+ -w /tmp/setmss.pcap &
+ sleep 1
+
+ echo x | nc -w 2 ${dst} 9999
+ sleep 2
+
+ # Extract the MSS from the SYN-ACK.
+ mss=$(jexec srv tcpdump -r /tmp/setmss.pcap -v 2>/dev/null |
+ sed -n 's/.*mss \([0-9]*\).*/\1/p' | head -1)
+
+ atf_check test -n "${mss}"
+ atf_check test "${mss}" -le 1400
+}
+
+atf_test_case "setmss4" "cleanup"
+setmss4_head()
+{
+ atf_set descr 'tcp-setmss clamps MSS in SYN-ACK, IPv4'
+ atf_set require.user root
+ atf_set require.kmods ipfw ipfw_pmod
+}
+
+setmss4_body()
+{
+ setmss_test inet 192.0.2.1 192.0.2.2 24
+}
+
+setmss4_cleanup()
+{
+ firewall_cleanup ipfw
+}
+
+atf_test_case "setmss6" "cleanup"
+setmss6_head()
+{
+ atf_set descr 'tcp-setmss clamps MSS in SYN-ACK, IPv6'
+ atf_set require.user root
+ atf_set require.kmods ipfw ipfw_pmod
+}
+
+setmss6_body()
+{
+ setmss_test inet6 2001:db8:42::1 2001:db8:42::2 64
+}
+
+setmss6_cleanup()
+{
+ firewall_cleanup ipfw
+}
+
+# Verify that rules after a tcp-setmss eaction still match.
+# The eaction runs ipfw_run_eaction() which may reallocate the mbuf;
+# ipfw_chk must refresh its cached pointers before evaluating
+# subsequent rules.
+setmss_chain_test()
+{
+ af=$1
+ src=$2
+ dst=$3
+ plen=$4
+
+ firewall_init ipfw
+
+ epair=$(vnet_mkepair)
+ vnet_mkjail srv ${epair}b
+ if [ ${af} = "inet" ]; then
+ ifconfig ${epair}a inet ${src}/${plen} up
+ jexec srv ifconfig ${epair}b inet ${dst}/${plen} up
+ else
+ ifconfig ${epair}a inet6 ${src}/${plen} up no_dad -ifdisabled
+ jexec srv ifconfig ${epair}b inet6 ${dst}/${plen} up no_dad \
+ -ifdisabled
+ fi
+
+ jexec srv kldload -n ipfw_pmod
+ firewall_config srv ipfw ipfw \
+ "ipfw -q add 100 tcp-setmss 1400 tcp from any to any setup" \
+ "ipfw -q add 200 count tcp from ${src} to any in"
+
+ jexec srv nc -l ${dst} 9999 &
+ sleep 1
+ echo x | nc -w 2 ${dst} 9999
+ sleep 2
+
+ # Rule 200 must have counted the packets that passed through
+ # the eaction in rule 100.
+ count=$(jexec srv ipfw show 200 | awk '{ print $2 }')
+ atf_check test "${count}" -gt 0
+}
+
+atf_test_case "setmss_chain4" "cleanup"
+setmss_chain4_head()
+{
+ atf_set descr 'rules after tcp-setmss eaction still match, IPv4'
+ atf_set require.user root
+ atf_set require.kmods ipfw ipfw_pmod
+}
+
+setmss_chain4_body()
+{
+ setmss_chain_test inet 192.0.2.1 192.0.2.2 24
+}
+
+setmss_chain4_cleanup()
+{
+ firewall_cleanup ipfw
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case "setmss4"
+ atf_add_test_case "setmss6"
+ atf_add_test_case "setmss_chain4"
+}

File Metadata

Mime Type
text/plain
Expires
Mon, Dec 7, 3:07 PM (23 h, 29 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
42261712
Default Alt Text
D62441.1796656023.diff (3 KB)

Event Timeline