naccyde / rpms / iproute

Forked from rpms/iproute 12 months ago
Clone

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

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