pf: fix 'no rdr'

Ensure we always have a non-NULL rule pointer (ctx.rm).
It might have gotten set to NULL by pf_get_translation().

While here also restore the previous rdr behaviour be re-adding the incorrectly
removed 'break' in pf_match_translation_rule.

PR:		290177
MFC after:	3 days
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D53191
This commit is contained in:
Kristof Provost
2025-10-18 17:47:47 +02:00
parent a6369fb9e4
commit cb36bfee25
3 changed files with 53 additions and 0 deletions
+1
View File
@@ -5965,6 +5965,7 @@ pf_test_rule(struct pf_krule **rm, struct pf_kstate **sm,
ctx.nat_pool = &(ctx.nr->rdr); ctx.nat_pool = &(ctx.nr->rdr);
} }
*ctx.rm = &V_pf_default_rule;
if (ctx.nr && ctx.nr->natpass) { if (ctx.nr && ctx.nr->natpass) {
r = ctx.nr; r = ctx.nr;
ruleset = *ctx.rsm; ruleset = *ctx.rsm;
+1
View File
@@ -216,6 +216,7 @@ pf_match_translation_rule(int rs_num, struct pf_test_ctx *ctx, struct pf_krulese
*/ */
ctx->arsm = ctx->aruleset; ctx->arsm = ctx->aruleset;
} }
break;
} else { } else {
ctx->a = r; /* remember anchor */ ctx->a = r; /* remember anchor */
ctx->aruleset = ruleset; /* and its ruleset */ ctx->aruleset = ruleset; /* and its ruleset */
+51
View File
@@ -338,6 +338,56 @@ natpass_cleanup()
pft_cleanup pft_cleanup
} }
atf_test_case "pr290177" "cleanup"
pr290177_head()
{
atf_set descr 'Test PR290177'
atf_set require.user root
}
pr290177_body()
{
pft_init
epair=$(vnet_mkepair)
ifconfig ${epair}a 192.0.2.2/24 up
ifconfig ${epair}a inet alias 192.0.2.3/24 up
vnet_mkjail alcatraz ${epair}b
jexec alcatraz ifconfig ${epair}b 192.0.2.1/24 up
jexec alcatraz ifconfig lo0 127.0.0.1/8 up
# Sanity check
atf_check -s exit:0 -o ignore \
ping -c 1 192.0.2.1
jexec alcatraz pfctl -e
pft_set_rules alcatraz \
"table <white> { 192.0.2.2 }" \
"no rdr inet proto tcp from <white> to any port 25" \
"rdr pass inet proto tcp from any to any port 25 -> 127.0.0.1 port 2500"
echo foo | jexec alcatraz nc -N -l 2500 &
sleep 1
reply=$(nc -w 3 -s 192.0.2.2 192.0.2.1 25)
if [ "${reply}" == "foo" ]
then
atf_fail "no rdr rule failed"
fi
reply=$(nc -w 3 -s 192.0.2.3 192.0.2.1 25)
if [ "${reply}" != "foo" ]
then
atf_fail "rdr rule failed"
fi
}
pr290177_cleanup()
{
pft_cleanup
}
atf_init_test_cases() atf_init_test_cases()
{ {
atf_add_test_case "natpass" atf_add_test_case "natpass"
@@ -345,4 +395,5 @@ atf_init_test_cases()
atf_add_test_case "tcp_v6_pass" atf_add_test_case "tcp_v6_pass"
atf_add_test_case "srcport_compat" atf_add_test_case "srcport_compat"
atf_add_test_case "srcport_pass" atf_add_test_case "srcport_pass"
atf_add_test_case "pr290177"
} }