naccyde / rpms / iproute

Forked from rpms/iproute a year ago
Clone

Blame SOURCES/0008-tc-u32-Fix-key-folding-in-sample-option.patch

8792a8
From 7fcfc0e4d6949ff32df3ed749bad8eb419cebbda Mon Sep 17 00:00:00 2001
8792a8
Message-Id: <7fcfc0e4d6949ff32df3ed749bad8eb419cebbda.1628790091.git.aclaudi@redhat.com>
8792a8
In-Reply-To: <650694eb0120722499207078f965442ef7343bb1.1628790091.git.aclaudi@redhat.com>
8792a8
References: <650694eb0120722499207078f965442ef7343bb1.1628790091.git.aclaudi@redhat.com>
8792a8
From: Andrea Claudi <aclaudi@redhat.com>
8792a8
Date: Wed, 11 Aug 2021 14:49:33 +0200
8792a8
Subject: [PATCH] tc: u32: Fix key folding in sample option
8792a8
8792a8
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1979425
8792a8
Upstream Status: iproute2.git commit 9b7ea92b
8792a8
8792a8
commit 9b7ea92b9e3feff2876f772ace01148b7406839c
8792a8
Author: Phil Sutter <phil@nwl.cc>
8792a8
Date:   Wed Aug 4 11:18:28 2021 +0200
8792a8
8792a8
    tc: u32: Fix key folding in sample option
8792a8
8792a8
    In between Linux kernel 2.4 and 2.6, key folding for hash tables changed
8792a8
    in kernel space. When iproute2 dropped support for the older algorithm,
8792a8
    the wrong code was removed and kernel 2.4 folding method remained in
8792a8
    place. To get things functional for recent kernels again, restoring the
8792a8
    old code alone was not sufficient - additional byteorder fixes were
8792a8
    needed.
8792a8
8792a8
    While being at it, make use of ffs() and thereby align the code with how
8792a8
    kernel determines the shift width.
8792a8
8792a8
    Fixes: 267480f55383c ("Backout the 2.4 utsname hash patch.")
8792a8
    Signed-off-by: Phil Sutter <phil@nwl.cc>
8792a8
    Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
8792a8
8792a8
Signed-off-by: Andrea Claudi <aclaudi@redhat.com>
8792a8
---
8792a8
 tc/f_u32.c | 11 ++++++++---
8792a8
 1 file changed, 8 insertions(+), 3 deletions(-)
8792a8
8792a8
diff --git a/tc/f_u32.c b/tc/f_u32.c
8792a8
index 2ed5254a..a5747f67 100644
8792a8
--- a/tc/f_u32.c
8792a8
+++ b/tc/f_u32.c
8792a8
@@ -978,6 +978,13 @@ show_k:
8792a8
 	goto show_k;
8792a8
 }
8792a8
 
8792a8
+static __u32 u32_hash_fold(struct tc_u32_key *key)
8792a8
+{
8792a8
+	__u8 fshift = key->mask ? ffs(ntohl(key->mask)) - 1 : 0;
8792a8
+
8792a8
+	return ntohl(key->val & key->mask) >> fshift;
8792a8
+}
8792a8
+
8792a8
 static int u32_parse_opt(struct filter_util *qu, char *handle,
8792a8
 			 int argc, char **argv, struct nlmsghdr *n)
8792a8
 {
8792a8
@@ -1110,9 +1117,7 @@ static int u32_parse_opt(struct filter_util *qu, char *handle,
8792a8
 				}
8792a8
 				NEXT_ARG();
8792a8
 			}
8792a8
-			hash = sel2.keys[0].val & sel2.keys[0].mask;
8792a8
-			hash ^= hash >> 16;
8792a8
-			hash ^= hash >> 8;
8792a8
+			hash = u32_hash_fold(&sel2.keys[0]);
8792a8
 			htid = ((hash % divisor) << 12) | (htid & 0xFFF00000);
8792a8
 			sample_ok = 1;
8792a8
 			continue;
8792a8
-- 
8792a8
2.31.1
8792a8