Allow source NAT to use interface networks #9220
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The old interface only lists interface addesses, not nets, and the rule parser parser only looks for interface names suffixed by
ip. In pf, interface address is used dynamically by being surrounded by parenthesis and includes the ":0" modifier to exclude aliases. By combining this with the ":network" modifier, source nat can also use an interface's network, dynamically, i.e. "($iface:network:0)".This is different to one-to-one nat because the source and target networks do not need to be the same size. Any of pf's pool options are valid in this situation.
Noticing PR #8495, I think updating the refactoring done there to include support for this would be fairly simple, with an update around https://github.com/opnsense/core/pull/8495/files#diff-fa864e1de379b514cb12d89d3e3c738b31c6c340fba099be98ba03520035c676R79
I made these changes because I wanted to source NAT onto a prefix delegated subnet, where the source subnet is larger than the target prefix and so masking/NPTv6 won't work, and the prefix is dynamic (DHCP assigned by ISP) so so must be based on an interface reference.