OSDN Git Service

netfilter: conntrack: skip confirmation and nat hooks in postrouting for vrf
authorFlorian Westphal <fw@strlen.de>
Mon, 25 Oct 2021 14:13:59 +0000 (16:13 +0200)
committerDavid S. Miller <davem@davemloft.net>
Tue, 26 Oct 2021 12:21:09 +0000 (13:21 +0100)
commit8e0538d8ee061699b7c2cf0b193cc186952cbc21
treee2c937855a6792cb8099c83e8aa26e06d797fa5a
parent4900a7691574033baef966ee7246d7bb8a930283
netfilter: conntrack: skip confirmation and nat hooks in postrouting for vrf

The VRF driver invokes netfilter for output+postrouting hooks so that users
can create rules that check for 'oif $vrf' rather than lower device name.

Afterwards, ip stack calls those hooks again.

This is a problem when conntrack is used with IP masquerading.
masquerading has an internal check that re-validates the output
interface to account for route changes.

This check will trigger in the vrf case.

If the -j MASQUERADE rule matched on the first iteration, then round 2
finds state->out->ifindex != nat->masq_index: the latter is the vrf
index, but out->ifindex is the lower device.

The packet gets dropped and the conntrack entry is invalidated.

This change makes conntrack postrouting skip the nat hooks.
Also skip confirmation.  This allows the second round
(postrouting invocation from ipv4/ipv6) to create nat bindings.

This also prevents the second round from seeing packets that had their
source address changed by the nat hook.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/netfilter/nf_conntrack_proto.c
net/netfilter/nf_nat_core.c