Skip to content

Commit 4e35c1c

Browse files
Martynas Pumputisummakynes
authored andcommitted
netfilter: nf_nat: skip nat clash resolution for same-origin entries
It is possible that two concurrent packets originating from the same socket of a connection-less protocol (e.g. UDP) can end up having different IP_CT_DIR_REPLY tuples which results in one of the packets being dropped. To illustrate this, consider the following simplified scenario: 1. Packet A and B are sent at the same time from two different threads by same UDP socket. No matching conntrack entry exists yet. Both packets cause allocation of a new conntrack entry. 2. get_unique_tuple gets called for A. No clashing entry found. conntrack entry for A is added to main conntrack table. 3. get_unique_tuple is called for B and will find that the reply tuple of B is already taken by A. It will allocate a new UDP source port for B to resolve the clash. 4. conntrack entry for B cannot be added to main conntrack table because its ORIGINAL direction is clashing with A and the REPLY directions of A and B are not the same anymore due to UDP source port reallocation done in step 3. This patch modifies nf_conntrack_tuple_taken so it doesn't consider colliding reply tuples if the IP_CT_DIR_ORIGINAL tuples are equal. [ Florian: simplify patch to not use .allow_clash setting and always ignore identical flows ] Signed-off-by: Martynas Pumputis <[email protected]> Signed-off-by: Florian Westphal <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 98bfc34 commit 4e35c1c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

net/netfilter/nf_conntrack_core.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,22 @@ nf_conntrack_tuple_taken(const struct nf_conntrack_tuple *tuple,
10071007
}
10081008

10091009
if (nf_ct_key_equal(h, tuple, zone, net)) {
1010+
/* Tuple is taken already, so caller will need to find
1011+
* a new source port to use.
1012+
*
1013+
* Only exception:
1014+
* If the *original tuples* are identical, then both
1015+
* conntracks refer to the same flow.
1016+
* This is a rare situation, it can occur e.g. when
1017+
* more than one UDP packet is sent from same socket
1018+
* in different threads.
1019+
*
1020+
* Let nf_ct_resolve_clash() deal with this later.
1021+
*/
1022+
if (nf_ct_tuple_equal(&ignored_conntrack->tuplehash[IP_CT_DIR_ORIGINAL].tuple,
1023+
&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple))
1024+
continue;
1025+
10101026
NF_CT_STAT_INC_ATOMIC(net, found);
10111027
rcu_read_unlock();
10121028
return 1;

0 commit comments

Comments
 (0)