Page MenuHomeFreeBSD

pfctl: Add modern NAT syntax
Needs ReviewPublic

Authored by vegeta_tuxpowered.net on Mar 3 2025, 5:09 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Apr 6, 12:45 AM
Unknown Object (File)
Sat, Apr 5, 11:28 AM
Unknown Object (File)
Wed, Mar 26, 11:19 PM
Unknown Object (File)
Tue, Mar 25, 7:00 AM
Unknown Object (File)
Mon, Mar 24, 1:19 AM
Unknown Object (File)
Fri, Mar 21, 5:25 AM
Unknown Object (File)
Mon, Mar 17, 11:42 PM
Unknown Object (File)
Sun, Mar 9, 11:36 PM

Details

Reviewers
kp
Summary

Now that pfct has separate functions for parsing redirection pools and
ports, we can finally add support for nat-to and rdr-to filter_opts.
NAT and RDR actions are marked by having the respective pools filled in.

Function pf_rule_apply_nat() is responsible for both NAT/RDR and af-to
address translations. It is called both for match rules and the final
pass rule.

Use FreeBSD's original address translation code by splitting it into
pf_translate_compat(). Call this function for old-style NAT ruleset
and for modern NAT rules via pf_rule_apply_nat().

Initialize pfctl_rule's redirection pools on rule allocation, also for
code paths not using expand_rule(), so that they can be safely checked
for being empty in filter_consistent().

Move map-e NAT test to nat.sh for convenience, duplicate critical NAT
tests into _compat (for old-style NAT ruleset) and _pass (for match/
pass) variants.

Features missing:

  • binat-to
  • usage of modern pf_translate()

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

vegeta_tuxpowered.net changed the visibility from "vegeta_tuxpowered.net (Kajetan Staszkiewicz)" to "Public (No Login Required)".

I think we're missing the associated man page updates.

I'm going to revisit this tomorrow, but I've not seen any issues yet.

sbin/pfctl/parse.y
964–965

Is it worth factoring this out into a pfctl_init_rule() or something?

I have re-enabled OpenBSD tests. Some of them required modification to resolve port numbers to service names, include the "keep state" keyword, insert commas between table members, not auto-expand redirection table-like syntax into tables.

Looks good. It does still need the man page updates. We can probably stea^W borrow those from OpenBSD.

sys/netpfil/pf/pf.c
5993

Yeah, I think that makes sense. It'd save us doing the check in multiple places.
(There.s another one like this in pf_test_rule()).

sys/netpfil/pf/pf_lb.c
809

uint8_t in new code.