Skip to content

RFC netfilter: conntrack: allow insertion of clashing entries

Florian Westphal netfilter-devel 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest4 patches 7 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4netfilter: conntrack: remove two args from resolve_clashnet/netfilter/nf_conntrack_core.c+51 -180 replies
2/4netfilter: conntrack: place confirm-bit setting in a helpernet/netfilter/nf_conntrack_core.c+14 -70 replies
3/4netfilter: conntrack: split resolve_clash functionnet/netfilter/nf_conntrack_core.c+41 -170 replies
4/4netfilter: conntrack: allow insertion of duplicate/clashing entriesnet/netfilter/nf_conntrack_core.c+85 -20 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [RFC nf-next 0/4] netfilter: conntrack: allow insertion of clashing entries

This series allows conntrack to insert a duplicate conntrack entry if the reply direction doesn't result in a clash with a different original connection.

Background:

kubernetes creates load-balancing rules for DNS using
-m statistics, e.g.:
-p udp --dport 53 -m statistics --mode random ... -j DNAT --to-destination x -p udp --dport 53 -m statistics --mode random ... -j DNAT --to-destination y

When the resolver sends an A and AAAA request back-to-back from different threads on the same socket, this has a high chance of a connection tracking clash at insertion time.

This in turn results in a drop of the clashing udp packet which then results in a 5 second DNS timeout.

The clash cannot be resolved with the current logic because the two conntracks entries have different NAT transformations, the first one from s:highport to x.53, the second from s:highport to y.53.

One solution is to change rules to use a consistent mapping, e.g. using -m cluster or nftables 'jhash' expression. This would cause the A and AAAA requests coming from same socket to match the same rule and thus share the same NAT information.

This change adds a second clash resolution/drop avoidance step:
A clashing entry will be added anyway provided the reply direction is unique.

Because this results in duplicate conntrack entries for the original direction, this comes with strings attached:
1. The clashed conntrack entry will only be around for 3 seconds
2. The clashed entry will still fail to be inserted if hash chain grew too large.

This entire series isn't nice but so far I did not find a better solution.

Comments welcome.