mirror of
https://github.com/freebsd/freebsd-src.git
synced 2026-10-30 20:35:03 +01:00
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:
1 parent
a6369fb9e4
commit
cb36bfee25
3 files changed
+53
No files matched your search
@@ -5965,6 +5965,7 @@ pf_test_rule(struct pf_krule **rm, struct pf_kstate **sm,
|
||||
ctx.nat_pool = &(ctx.nr->rdr);
|
||||
}
|
||||
|
||||
*ctx.rm = &V_pf_default_rule;
|
||||
if (ctx.nr && ctx.nr->natpass) {
|
||||
r = ctx.nr;
|
||||
ruleset = *ctx.rsm;
|
||||
|
||||
@@ -216,6 +216,7 @@ pf_match_translation_rule(int rs_num, struct pf_test_ctx *ctx, struct pf_krulese
|
||||
*/
|
||||
ctx->arsm = ctx->aruleset;
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
ctx->a = r; /* remember anchor */
|
||||
ctx->aruleset = ruleset; /* and its ruleset */
|
||||
|
||||
@@ -338,6 +338,56 @@ natpass_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_add_test_case "natpass"
|
||||
@@ -345,4 +395,5 @@ atf_init_test_cases()
|
||||
atf_add_test_case "tcp_v6_pass"
|
||||
atf_add_test_case "srcport_compat"
|
||||
atf_add_test_case "srcport_pass"
|
||||
atf_add_test_case "pr290177"
|
||||
}
|
||||
Reference in new issue
Block a user