[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20191114104723.GF11663@orbyte.nwl.cc>
Date: Thu, 14 Nov 2019 11:47:23 +0100
From: Phil Sutter <phil@....cc>
To: Pablo Neira Ayuso <pablo@...filter.org>
Cc: netfilter-devel@...r.kernel.org, netdev@...r.kernel.org,
Eric Garver <eric@...ver.life>
Subject: Re: [nf-next PATCH] net: netfilter: Support iif matches in
POSTROUTING
On Thu, Nov 14, 2019 at 12:08:42AM +0100, Pablo Neira Ayuso wrote:
> On Tue, Nov 12, 2019 at 05:14:37PM +0100, Phil Sutter wrote:
> > Instead of generally passing NULL to NF_HOOK_COND() for input device,
> > pass skb->dev which contains input device for routed skbs.
> >
> > Note that iptables (both legacy and nft) reject rules with input
> > interface match from being added to POSTROUTING chains, but nftables
> > allows this.
>
> Yes, it allows this but it will not ever match, right? So even if the
> rule is loaded, it will be useless.
This patch changes that. What you're referring to is the NFWS discussion
about nft_meta: In the past, iif* matches would enter error path if
input interface was NULL, thereby aborting rule traversal (NFT_BREAK).
That was changed in commit cb81572e8cb50 ("netfilter: nf_tables: Make
nft_meta expression more robust") to instead just set dreg to something
that usually doesn't match.
> Do you have a usecase in mind that would benefit from this specifically?
I would like to masquerade traffic coming from a local private
interface, like so:
| nft add rule ip filter POSTROUTING iifname 'vnetbr0' masquerade
A typical idiom commonly used to avoid this disallowed match is to
masquerade anything that's not routed to the private interface:
| iptables -t nat -A POSTROUTING ! -o vnetbr0 -j MASQUERADE
But this rule will match more traffic than necessary, also things get a
bit complicated when using multiple private interfaces between which
traffic shouldn't be masqueraded.
Firewalld has a special workaround, it marks packets for later:
| iptables -t nat -A PREROUTING -i vnetbr0 -j MARK --set-mark 0xbeef
| iptables -t nat -A POSTROUTING -m mark --mark 0xbeef -j MASQUERADE
Cheers, Phil
Powered by blists - more mailing lists