netfilter: socket: Lookup orig tuple for IPv6 SNAT
authorMaxim Mikityanskiy <maxtram95@gmail.com>
Tue, 18 Mar 2025 16:15:16 +0000 (18:15 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Sun, 23 Mar 2025 09:53:47 +0000 (10:53 +0100)
commit932b32ffd7604fb00b5c57e239a3cc4d901ccf6e
treecbd9a516b8017ee61592ec4fb67a7afee5ef375a
parent3b4aff61ca5dd696856d2db98e9268d94504eff3
netfilter: socket: Lookup orig tuple for IPv6 SNAT

nf_sk_lookup_slow_v4 does the conntrack lookup for IPv4 packets to
restore the original 5-tuple in case of SNAT, to be able to find the
right socket (if any). Then socket_match() can correctly check whether
the socket was transparent.

However, the IPv6 counterpart (nf_sk_lookup_slow_v6) lacks this
conntrack lookup, making xt_socket fail to match on the socket when the
packet was SNATed. Add the same logic to nf_sk_lookup_slow_v6.

IPv6 SNAT is used in Kubernetes clusters for pod-to-world packets, as
pods' addresses are in the fd00::/8 ULA subnet and need to be replaced
with the node's external address. Cilium leverages Envoy to enforce L7
policies, and Envoy uses transparent sockets. Cilium inserts an iptables
prerouting rule that matches on `-m socket --transparent` and redirects
the packets to localhost, but it fails to match SNATed IPv6 packets due
to that missing conntrack lookup.

Closes: https://github.com/cilium/cilium/issues/37932
Fixes: eb31628e37a0 ("netfilter: nf_tables: Add support for IPv6 NAT")
Signed-off-by: Maxim Mikityanskiy <maxim@isovalent.com>
Reviewed-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
net/ipv6/netfilter/nf_socket_ipv6.c