Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A couple of RDR enhancements #684

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

robertek
Copy link

This PR adds two enhancements:

  1. RDR list and RDR clear for persistent rules file rdr.conf.
    The major rationale behind this was, that the rdr clear does not clear the rdr.conf and only clears the applied pf rules. I didn't want to change the current default behavior (it may be useful in some cases).

  2. RDR ip and dev commands. It allows changing the globally configured ext_if device and defining specific host target ip address. Even this change extends the rdr.conf format it is consistent with the current format and no migration is needed.

Now a following format of rdr.conf is allowed:

tcp 22 22
udp 53 53 log (all, to pflog1)
ip 192.168.1.1 tcp 22 22
dev wg0 tcp 22 22
ip 192.168.1.1 dev wg0 udp 53 53
ip 192.168.1.1 dev wg0 tcp 23 22 log

It allows bigger flexibility of redirection and fix some issues.
For example when the system is a gateway and the ext_if is the device being a gateway, the former redirection (from any to any) cause a redirect of all the packets heading to that port on this device even if the destination ip was different.
Another possible example of use case is having a two outgoing interfaces (in all my cases an ethernet port and a wireguard tunnel) with a possibility to selectively redirect from.

Then there are two extra commits. One is for the overall rdr.sh cleanup (deduplication, consistent formating, and generalization). And the last commit is update to the rdr documentation, which was not updated for a while.

This commit adds a persistent keyword for rdr list and rdr clean.

"rdr list persistent" shows rules in the rdr.conf file for the TARGET.

"rdr clear persistent" removes also the rdr.conf file for the TARGET.
This is enhancement for the rdr command to allow to specify
the target host ip and network device.

The "ip" modifier sets the target ip replacing the "to any" to "to <IP>".
The "dev" modifier replaces the default device to the specified one.

Both are stored to the persistent rdr.conf.
The format of old rdr.conf entries does not change.

All of these rule combinations are now supported (any has a valid usecase):
tcp 22 22
ip 192.168.1.1 tcp 22 22
dev wg0 tcp 22 22
ip 192.168.1.1 dev wg0 tcp 22 22
ip 192.168.1.1 dev wg0 tcp 23 22 log
@yaazkal yaazkal added the enhancement New feature or request label Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants