netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: Small bug on rxhash calculation
@ 2012-09-06  6:35 Chema Gonzalez
  2012-09-06  6:42 ` Eric Dumazet
  2012-09-07 16:57 ` David Miller
  0 siblings, 2 replies; 9+ messages in thread
From: Chema Gonzalez @ 2012-09-06  6:35 UTC (permalink / raw)
  To: netdev; +Cc: edumazet, Chema Gonzalez

>From 5c02179069826bfba9360383b88601b31ff05517 Mon Sep 17 00:00:00 2001
From: Chema Gonzalez <chema@google.com>
Date: Wed, 5 Sep 2012 17:05:48 -0700
Subject: [PATCH] net: Small bug on rxhash calculation

While the (current) sorting of the ports/addresses is coherent
(you get the same rxhash for packets sharing the same (unsorted)
4-tuple), ports and addresses should not be sorted independently,
which currently are: For traffic between A=S:l and B=L:s, packets
in both directions would get their rxhash from hashing
{L, S, {s, l}}. The same rxhash is obtained from packets between
C=S:s and D=L:l.

This patch ensures traffic between A and B gets their rxhash
from {S, L, {s, l}}, and traffic between C and D from {S, L,
{l, s}}

The patch is co-written with Eric Dumazet <edumazet@google.com>

Signed-off-by: Chema Gonzalez <chema@google.com>
---
 net/core/dev.c |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/net/core/dev.c b/net/core/dev.c
index b1e6d63..dcc673d 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -2655,15 +2655,16 @@ void __skb_get_rxhash(struct sk_buff *skb)
        if (!skb_flow_dissect(skb, &keys))
                return;

-       if (keys.ports) {
-               if ((__force u16)keys.port16[1] < (__force u16)keys.port16[0])
-                       swap(keys.port16[0], keys.port16[1]);
+       if (keys.ports)
                skb->l4_rxhash = 1;
-       }

        /* get a consistent hash (same value on both flow directions) */
-       if ((__force u32)keys.dst < (__force u32)keys.src)
+       if (((__force u32)keys.dst < (__force u32)keys.src) ||
+           (((__force u32)keys.dst == (__force u32)keys.src) &&
+            ((__force u16)keys.port16[1] < (__force u16)keys.port16[0]))) {
                swap(keys.dst, keys.src);
+               swap(keys.port16[0], keys.port16[1]);
+       }

        hash = jhash_3words((__force u32)keys.dst,
                            (__force u32)keys.src,
--
1.7.7.3

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2012-09-08 22:43 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-06  6:35 [PATCH] net: Small bug on rxhash calculation Chema Gonzalez
2012-09-06  6:42 ` Eric Dumazet
2012-09-07 16:57 ` David Miller
2012-09-07 23:40   ` [PATCH] net: small " Chema Gonzalez
2012-09-07 23:40     ` Chema Gonzalez
2012-09-07 23:50       ` David Miller
2012-09-08  0:24         ` Chema Gonzalez
2012-09-08  8:18     ` Eric Dumazet
2012-09-08 22:43       ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).