Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F146649374
D47777.id.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D47777.id.diff
View Options
diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c
--- a/sys/netpfil/pf/pf.c
+++ b/sys/netpfil/pf/pf.c
@@ -4975,7 +4975,7 @@
KASSERT(nk != NULL, ("%s: null nk", __func__));
if (nr->log) {
- PFLOG_PACKET(PF_PASS, PFRES_MATCH, nr, a,
+ PFLOG_PACKET(nr->action, PFRES_MATCH, nr, a,
ruleset, pd, 1);
}
diff --git a/tests/sys/netpfil/pf/pflog.sh b/tests/sys/netpfil/pf/pflog.sh
--- a/tests/sys/netpfil/pf/pflog.sh
+++ b/tests/sys/netpfil/pf/pflog.sh
@@ -2,6 +2,7 @@
# SPDX-License-Identifier: BSD-2-Clause
#
# Copyright (c) 2023 Rubicon Communications, LLC (Netgate)
+# Copyright (c) 2024 Deciso B.V.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -132,8 +133,67 @@
pft_cleanup
}
+atf_test_case "rdr" "cleanup"
+rdr_head()
+{
+ atf_set descr 'Test RDR rule logging'
+ atf_set require.user root
+}
+
+rdr_body()
+{
+ j="pflog:rdr"
+ epair_c=$(vnet_mkepair)
+ epair_srv=$(vnet_mkepair)
+
+ vnet_mkjail ${j}srv ${epair_srv}a
+ vnet_mkjail ${j}gw ${epair_srv}b ${epair_c}a
+ vnet_mkjail ${j}c ${epair_c}b
+
+ jexec ${j}srv ifconfig ${epair_srv}a 198.51.100.1/24 up
+ # No default route in srv jail, to ensure we're NAT-ing
+ jexec ${j}gw ifconfig ${epair_srv}b 198.51.100.2/24 up
+ jexec ${j}gw ifconfig ${epair_c}a 192.0.2.1/24 up
+ jexec ${j}gw sysctl net.inet.ip.forwarding=1
+ jexec ${j}c ifconfig ${epair_c}b 192.0.2.2/24 up
+ jexec ${j}c route add default 192.0.2.1
+
+ jexec ${j}gw pfctl -e
+ jexec ${j}gw ifconfig pflog0 up
+ pft_set_rules ${j}gw \
+ "rdr log on ${epair_srv}b proto tcp from 198.51.100.0/24 to any port 1234 -> 192.0.2.2 port 1234" \
+ "block quick inet6" \
+ "pass in log"
+
+ jexec ${j}gw tcpdump -n -e -ttt --immediate-mode -l -U -i pflog0 >> ${PWD}/pflog.txt &
+ sleep 1 # Wait for tcpdump to start
+
+ # send a SYN to catch in the log
+ jexec ${j}srv nc -N -w 0 198.51.100.2 1234
+
+ echo "Log"
+ cat ${PWD}/pflog.txt
+
+ # log line generated for rdr hit (pre-NAT)
+ atf_check -o match:".*.*rule 0/0\(match\): rdr in on ${epair_srv}b: 198.51.100.1.[0-9]* > 198.51.100.2.1234: Flags \[S\].*" \
+ cat pflog.txt
+
+ # log line generated for pass hit (post-NAT)
+ atf_check -o match:".*.*rule 1/0\(match\): pass in on ${epair_srv}b: 198.51.100.1.[0-9]* > 192.0.2.2.1234: Flags \[S\].*" \
+ cat pflog.txt
+
+ # only two log lines shall be written
+ atf_check -o match:2 grep -c . pflog.txt
+}
+
+rdr_cleanup()
+{
+ pft_cleanup
+}
+
atf_init_test_cases()
{
atf_add_test_case "malformed"
atf_add_test_case "matches"
+ atf_add_test_case "rdr"
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Mar 5, 10:18 AM (16 h, 48 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
29281507
Default Alt Text
D47777.id.diff (2 KB)
Attached To
Mode
D47777: pf: NAT rule logs its own NAT action, not PF_PASS
Attached
Detach File
Event Timeline
Log In to Comment