Page MenuHomeFreeBSD

pf: Make nat-to and rdr-to work properly both on in and out rules
ClosedPublic

Authored by vegeta_tuxpowered.net on Oct 20 2025, 2:47 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Feb 8, 10:20 AM
Unknown Object (File)
Fri, Jan 16, 6:24 AM
Unknown Object (File)
Thu, Jan 15, 11:57 PM
Unknown Object (File)
Dec 20 2025, 12:57 AM
Unknown Object (File)
Nov 25 2025, 7:59 AM
Unknown Object (File)
Nov 23 2025, 7:54 AM
Unknown Object (File)
Nov 4 2025, 6:50 PM
Unknown Object (File)
Nov 1 2025, 4:07 PM

Details

Summary

New-style address translation is done by nat-to and rdr-to actions on
normal match and pass rules. Those rules, when used without address
translation, can be specified without direction. But that allows users
to specify pre-routing nat and post-routing rdr. This case is not
handled properly and causes pre-routing nat to modify destination
address, as if it was a rdr rule, and post-routing rdr to modify source
address, as if it was a nat rule.

Ensure that nat-to action modifies source address and rdr-to destination
address no matter in which direction the rule is applied. The man page
for pf.conf already specifies that nat-to and rdr-to rules should be
limited to respective directions.

PR: 288577
MFC after: 3 days
Sponsored by: InnoGames GmbH

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

vegeta_tuxpowered.net edited the summary of this revision. (Show Details)
tests/sys/netpfil/pf/nat.sh
920

I'm unsure if we really need this test case. I have originally developed it when working on kernel side fix to ensure that NAT is properly applied on source address no matter on which direction the rule matters. But with pfctl forbidding loading such rules it can't be tested anymore. But the kernel code will accept such rule and handle it properly. Please advise :)

tests/sys/netpfil/pf/nat.sh
920

Please disregard this comment. Apparently OpenBSD does support nat-to and rdr-to on both directions and clearly states that in man pf.conf. I will rework this patch.

vegeta_tuxpowered.net retitled this revision from pf: Forbid nat-to on in rules and rdr-to on out rules to pf: Make nat-to and rdr-to work properly both on in and out rules.
vegeta_tuxpowered.net edited the summary of this revision. (Show Details)

Don't forbid address translation on non-usual direction, since OpenBSD allows it too. Enable the test for nat-to on inbound direction.

This revision is now accepted and ready to land.Oct 29 2025, 10:17 AM