Skip to content

Commit f138688

Browse files
kprovostcperciva
authored andcommitted
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. Approved by: re (cperciva) PR: 290177 MFC after: 3 days Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D53191 (cherry picked from commit cb36bfe) (cherry picked from commit 536b075)
1 parent 0948c4d commit f138688

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

sys/netpfil/pf/pf.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5939,6 +5939,7 @@ pf_test_rule(struct pf_krule **rm, struct pf_kstate **sm,
59395939
ctx.nat_pool = &(ctx.nr->rdr);
59405940
}
59415941

5942+
*ctx.rm = &V_pf_default_rule;
59425943
if (ctx.nr && ctx.nr->natpass) {
59435944
r = ctx.nr;
59445945
ruleset = *ctx.rsm;

sys/netpfil/pf/pf_lb.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ pf_match_translation_rule(int rs_num, struct pf_test_ctx *ctx, struct pf_krulese
216216
*/
217217
ctx->arsm = ctx->aruleset;
218218
}
219+
break;
219220
} else {
220221
ctx->a = r; /* remember anchor */
221222
ctx->aruleset = ruleset; /* and its ruleset */

tests/sys/netpfil/pf/rdr.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,11 +338,62 @@ natpass_cleanup()
338338
pft_cleanup
339339
}
340340

341+
atf_test_case "pr290177" "cleanup"
342+
pr290177_head()
343+
{
344+
atf_set descr 'Test PR290177'
345+
atf_set require.user root
346+
}
347+
348+
pr290177_body()
349+
{
350+
pft_init
351+
352+
epair=$(vnet_mkepair)
353+
354+
ifconfig ${epair}a 192.0.2.2/24 up
355+
ifconfig ${epair}a inet alias 192.0.2.3/24 up
356+
357+
vnet_mkjail alcatraz ${epair}b
358+
jexec alcatraz ifconfig ${epair}b 192.0.2.1/24 up
359+
jexec alcatraz ifconfig lo0 127.0.0.1/8 up
360+
361+
# Sanity check
362+
atf_check -s exit:0 -o ignore \
363+
ping -c 1 192.0.2.1
364+
365+
jexec alcatraz pfctl -e
366+
pft_set_rules alcatraz \
367+
"table <white> { 192.0.2.2 }" \
368+
"no rdr inet proto tcp from <white> to any port 25" \
369+
"rdr pass inet proto tcp from any to any port 25 -> 127.0.0.1 port 2500"
370+
371+
echo foo | jexec alcatraz nc -N -l 2500 &
372+
sleep 1
373+
374+
reply=$(nc -w 3 -s 192.0.2.2 192.0.2.1 25)
375+
if [ "${reply}" == "foo" ]
376+
then
377+
atf_fail "no rdr rule failed"
378+
fi
379+
reply=$(nc -w 3 -s 192.0.2.3 192.0.2.1 25)
380+
if [ "${reply}" != "foo" ]
381+
then
382+
atf_fail "rdr rule failed"
383+
fi
384+
}
385+
386+
pr290177_cleanup()
387+
{
388+
pft_cleanup
389+
}
390+
341391
atf_init_test_cases()
342392
{
343393
atf_add_test_case "natpass"
344394
atf_add_test_case "tcp_v6_compat"
345395
atf_add_test_case "tcp_v6_pass"
346396
atf_add_test_case "srcport_compat"
347397
atf_add_test_case "srcport_pass"
398+
atf_add_test_case "pr290177"
348399
}

0 commit comments

Comments
 (0)