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

Extend '--add-forward-port' (and the forwart-port) rich rule to support the REDIRECT target #78

Closed
hwoarang opened this issue Feb 4, 2016 · 1 comment
Labels
feature New feature or enhancement.
Milestone

Comments

@hwoarang
Copy link
Contributor

hwoarang commented Feb 4, 2016

There is an interesting case when using --add-forward-port or the forward-port rich rule

Assume an existing REDIRECT iptables rule

-A PREROUTING -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 3128

One may think that the equivalent in firewalld would be

rule family=ipv4 forward-port port=80 protocol=tcp to-port=3128

This is not quite right as it would generate

-A PRE_external_allow -p tcp -m mark --mark 0x64 -j DNAT --to-destination :3128

--to-destination :port actually rewrites the port on the packet but leaves the destination address intact. The only way around this is to explicitly set the destination address (to-addr) in the rich rule but this is not as flexible as the REDIRECT target since if the machine's IP change the rule has to be updated whereas REDIRECT does that automatically.

Since the destination IP is an optional argument it would make sense for this forward-port to support the REDIRECT target as least in the rich rule format. How about an extended syntax

forward-port port="" protocol="tcp|udp" to-port="" to-addr="

redirect"

so a REDIRECT target can be generate instead?

Finally, it would be nice to add support for REDIRECT (and DNAT) in the OUTPUT chain as well.

hwoarang referenced this issue in hwoarang/yast-firewall Mar 10, 2016
@t-woerner t-woerner added this to the 0.4.4 milestone Jun 16, 2016
@t-woerner t-woerner modified the milestones: 0.4.5, 0.4.4 Oct 26, 2016
@erig0 erig0 added the feature New feature or enhancement. label Jun 1, 2018
@erig0
Copy link
Collaborator

erig0 commented Apr 27, 2020

The nftables backend does indeed use "redirect" if to-addr is not specified.

if toaddr:
if check_single_address("ipv6", toaddr):
toaddr = normalizeIP6(toaddr)
if toport and toport != "":
expr_fragments.append({"dnat": {"addr": toaddr, "port": self._port_fragment(toport)}})
else:
expr_fragments.append({"dnat": {"addr": toaddr}})
else:
expr_fragments.append({"redirect": {"port": self._port_fragment(toport)}})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or enhancement.
Projects
None yet
Development

No branches or pull requests

3 participants