Commit 0dda7b56 authored by Chema Gonzalez's avatar Chema Gonzalez Committed by Ben Hutchings

net: small bug on rxhash calculation

[ Upstream commit 68622342 ]

In the current rxhash calculation function, while the
sorting of the ports/addrs is coherent (you get the
same rxhash for packets sharing the same 4-tuple, in
both directions), ports and addrs are sorted
independently. This implies packets from a connection
between the same addresses but crossed ports hash to
the same rxhash.

For example, traffic between A=S:l and B=L:s is hashed
(in both directions) from {L, S, {s, l}}. The same
rxhash is obtained for packets between C=S:s and D=L:l.

This patch ensures that you either swap both addrs and ports,
or you swap none. Traffic between A and B, and traffic
between C and D, get their rxhash from different sources
({L, S, {l, s}} for A<->B, and {L, S, {s, l}} for C<->D)

The patch is co-written with Eric Dumazet <edumazet@google.com>
Signed-off-by: default avatarChema Gonzalez <chema@google.com>
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
parent db8dbd5b
...@@ -2686,16 +2686,17 @@ void __skb_get_rxhash(struct sk_buff *skb) ...@@ -2686,16 +2686,17 @@ void __skb_get_rxhash(struct sk_buff *skb)
nhoff += poff; nhoff += poff;
if (pskb_may_pull(skb, nhoff + 4)) { if (pskb_may_pull(skb, nhoff + 4)) {
ports.v32 = * (__force u32 *) (skb->data + nhoff); ports.v32 = * (__force u32 *) (skb->data + nhoff);
if (ports.v16[1] < ports.v16[0])
swap(ports.v16[0], ports.v16[1]);
skb->l4_rxhash = 1; skb->l4_rxhash = 1;
} }
} }
/* get a consistent hash (same value on both flow directions) */ /* get a consistent hash (same value on both flow directions) */
if (addr2 < addr1) if (addr2 < addr1 ||
(addr2 == addr1 &&
ports.v16[1] < ports.v16[0])) {
swap(addr1, addr2); swap(addr1, addr2);
swap(ports.v16[0], ports.v16[1]);
}
hash = jhash_3words(addr1, addr2, ports.v32, hashrnd); hash = jhash_3words(addr1, addr2, ports.v32, hashrnd);
if (!hash) if (!hash)
hash = 1; hash = 1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment