Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F171341072
D56869.id177369.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
6 KB
Referenced Files
None
Subscribers
None
D56869.id177369.diff
View Options
diff --git a/sbin/ipfw/ipfw2.c b/sbin/ipfw/ipfw2.c
--- a/sbin/ipfw/ipfw2.c
+++ b/sbin/ipfw/ipfw2.c
@@ -5514,10 +5514,7 @@
break;
case TOK_FLOWID:
- if (proto != IPPROTO_IPV6 )
- errx( EX_USAGE, "flow-id filter is active "
- "only for ipv6 protocol\n");
- fill_flow6( (ipfw_insn_u32 *) cmd, *av, cblen);
+ fill_flow6(insntod(cmd, u32), *av, cblen);
av++;
break;
diff --git a/sys/netpfil/ipfw/ip_fw2.c b/sys/netpfil/ipfw/ip_fw2.c
--- a/sys/netpfil/ipfw/ip_fw2.c
+++ b/sys/netpfil/ipfw/ip_fw2.c
@@ -780,7 +780,9 @@
flow6id_match(int curr_flow, ipfw_insn_u32 *cmd)
{
int i;
- for (i=0; i <= cmd->o.arg1; ++i)
+ /* Mask proto version and traffic class out before comparing flow-id */
+ curr_flow &= ntohl(IPV6_FLOWLABEL_MASK);
+ for (i=0; i < cmd->o.arg1; ++i)
if (curr_flow == cmd->d[i])
return 1;
return 0;
diff --git a/tests/sys/netpfil/common/pft_ping.py b/tests/sys/netpfil/common/pft_ping.py
--- a/tests/sys/netpfil/common/pft_ping.py
+++ b/tests/sys/netpfil/common/pft_ping.py
@@ -63,6 +63,7 @@
dst_address = send_params.get('dst_address')
hlim = send_params.get('hlim')
tc = send_params.get('tc')
+ fl = send_params.get('fl')
ip6 = sp.IPv6(dst=dst_address)
if src_address:
ip6.src = src_address
@@ -70,6 +71,8 @@
ip6.hlim = hlim
if tc:
ip6.tc = tc
+ if fl:
+ ip6.fl = fl
return ip6
@@ -224,6 +227,7 @@
flags = expect_params.get('flags')
hlim = expect_params.get('hlim')
tc = expect_params.get('tc')
+ fl = expect_params.get('fl')
ip6 = packet.getlayer(sp.IPv6)
if not ip6:
LOGGER.debug('Packet is not IPv6!')
@@ -245,6 +249,9 @@
if tc and ip6.tc != tc:
LOGGER.debug(f'Wrong TC value {ip6.tc}, expected {tc}')
return False
+ if fl and ip6.fl != fl:
+ LOGGER.debug(f'Wrong Flow Label value {ip6.fl}, expected {fl}')
+ return False
return True
@@ -635,6 +642,8 @@
help='ICMP Echo Request payload size')
parser_send.add_argument('--send-tc', type=int,
help='IPv6 Traffic Class or IPv4 DiffServ / ToS')
+ parser_send.add_argument('--send-fl', type=int,
+ help='IPv6 Flow label')
parser_send.add_argument('--send-tcpopt-unaligned', action='store_true',
help='Include unaligned TCP options')
parser_send.add_argument('--send-nop', action='store_true',
@@ -652,6 +661,8 @@
help='TCP sequence number')
parser_expect.add_argument('--expect-tc', type=int,
help='IPv6 Traffic Class or IPv4 DiffServ / ToS')
+ parser_expect.add_argument('--expect-fl', type=int,
+ help='IPv6 Flow Label')
parser.add_argument('-v', '--verbose', action='store_true',
help=('Enable verbose logging. Apart of potentially useful information '
@@ -673,7 +684,7 @@
send_params = {}
expect_params = {}
for param_name in (
- 'flags', 'hlim', 'length', 'mss', 'seq', 'tc', 'frag_length',
+ 'flags', 'hlim', 'length', 'mss', 'seq', 'tc', 'fl', 'frag_length',
'sport', 'dport',
):
param_arg = vars(args).get(f'send_{param_name}')
diff --git a/tests/sys/netpfil/ipfw/Makefile b/tests/sys/netpfil/ipfw/Makefile
--- a/tests/sys/netpfil/ipfw/Makefile
+++ b/tests/sys/netpfil/ipfw/Makefile
@@ -4,7 +4,8 @@
ATF_TESTS_SH+= fwd \
divert \
- lookup
+ lookup \
+ ipv6-flow-id
${PACKAGE}FILES+= fwd_inetd.conf \
lookup_inetd.conf
diff --git a/tests/sys/netpfil/ipfw/ipv6-flow-id.sh b/tests/sys/netpfil/ipfw/ipv6-flow-id.sh
new file mode 100644
--- /dev/null
+++ b/tests/sys/netpfil/ipfw/ipv6-flow-id.sh
@@ -0,0 +1,100 @@
+#-
+# SPDX-License-Identifier: BSD-2-Clause
+#
+# Copyright (c) 2026 Boris Lytochkin
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+#
+#
+
+common_dir="$(atf_get_srcdir)/../common"
+. ${common_dir}/utils.subr
+
+NC="nc -w 1 -dnN"
+
+setup_network_v6()
+{
+ epair="$1"
+
+ ifconfig ${epair}a inet6 2001:db8:42::1/64 up no_dad -ifdisabled
+
+ vnet_mkjail alcatraz ${epair}b
+
+ jexec alcatraz ifconfig ${epair}b inet6 2001:db8:42::2/64 up no_dad -ifdisabled
+
+ jexec alcatraz /usr/sbin/inetd -p /dev/null $(atf_get_srcdir)/lookup_inetd.conf
+
+ # Sanity checks
+ atf_check -s exit:0 -o ignore ping6 -i .1 -c 3 -s 1200 2001:db8:42::2
+ atf_check -o "inline:GOOD 82\n" ${NC} 2001:db8:42::2 82
+}
+
+atf_test_case "ipv6fl" "cleanup"
+
+ipv6fl_head()
+{
+ atf_set descr 'flow-id test'
+ atf_set require.user root
+ atf_set require.progs python3 scapy
+}
+
+ipv6fl_body()
+{
+
+ firewall_init "ipfw"
+
+ epair=$(vnet_mkepair)
+
+ setup_network_v6 ${epair}
+
+ # Check if the firewall is able to match exact IPv6 flow label
+ firewall_config "alcatraz" ipfw ipfw \
+ "ipfw -q add 100 allow ip6 from any to any flow-id 0xbaad" \
+ "ipfw -q add 200 deny ipv6-icmp from any to any icmp6types 128 in"
+
+ # Check Flow Label matches
+ atf_check -s exit:0 ${common_dir}/pft_ping.py \
+ --sendif ${epair}a \
+ --fromaddr 2001:db8:42::1 \
+ --to 2001:db8:42::2 \
+ --send-fl $((0xbaad)) \
+ --replyif ${epair}a
+
+ # Check Flow Label mismatch
+ atf_check -s exit:1 ${common_dir}/pft_ping.py \
+ --sendif ${epair}a \
+ --fromaddr 2001:db8:42::1 \
+ --to 2001:db8:42::2 \
+ --send-fl $((0xf001)) \
+ --replyif ${epair}a
+
+}
+
+ipv6fl_cleanup()
+{
+ firewall_cleanup $1
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case "ipv6fl"
+}
diff --git a/tests/sys/netpfil/ipfw/lookup.sh b/tests/sys/netpfil/ipfw/lookup.sh
--- a/tests/sys/netpfil/ipfw/lookup.sh
+++ b/tests/sys/netpfil/ipfw/lookup.sh
@@ -56,7 +56,6 @@
{
atf_set descr 'IPv4 lookup test'
atf_set require.user root
- atf_set require.progs scapy
}
ip4_body()
@@ -141,7 +140,6 @@
{
atf_set descr 'IPv6 lookup test'
atf_set require.user root
- atf_set require.progs scapy
}
ip6_body()
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Sep 11, 1:32 PM (19 h, 12 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
38707552
Default Alt Text
D56869.id177369.diff (6 KB)
Attached To
Mode
D56869: Fix IPv6 flow label match in ipfw
Attached
Detach File
Event Timeline
Log In to Comment