[SRU][F:linux-bluefield][PATCH 26/32] net/bonding: Take IP hash logic into a helper

Daniel Jurgens danielj at nvidia.com
Mon May 3 19:39:11 UTC 2021


From: Tariq Toukan <tariqt at nvidia.com>

BugLink: https://bugs.launchpad.net/bugs/1926994

Hash logic on L3 will be used in a downstream patch for one more use
case.
Take it to a function for a better code reuse.

Signed-off-by: Tariq Toukan <tariqt at nvidia.com>
Reviewed-by: Boris Pismenny <borisp at nvidia.com>
Signed-off-by: Jakub Kicinski <kuba at kernel.org>
(backported from commit 5b99854540e35c2c6a226bcdb4bafbae1bccad5a)
Signed-off-by: Daniel Jurgens <danielj at nvidia.com>

Conflicts:
	drivers/net/bonding/bond_main.c
---
 drivers/net/bonding/bond_main.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 9b738f5..02b4fe7 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -3448,6 +3448,16 @@ static bool bond_flow_dissect(struct bonding *bond, struct sk_buff *skb,
 	return true;
 }
 
+static u32 bond_ip_hash(u32 hash, struct flow_keys *flow)
+{
+	hash ^= (__force u32)flow_get_u32_dst(flow) ^
+		(__force u32)flow_get_u32_src(flow);
+	hash ^= (hash >> 16);
+	hash ^= (hash >> 8);
+	/* discard lowest hash bit to deal with the common even ports pattern */
+	return hash >> 1;
+}
+
 /**
  * bond_xmit_hash - generate a hash value based on the xmit policy
  * @bond: bonding device
@@ -3474,12 +3484,8 @@ u32 bond_xmit_hash(struct bonding *bond, struct sk_buff *skb)
 		hash = bond_eth_hash(skb);
 	else
 		hash = (__force u32)flow.ports.ports;
-	hash ^= (__force u32)flow_get_u32_dst(&flow) ^
-		(__force u32)flow_get_u32_src(&flow);
-	hash ^= (hash >> 16);
-	hash ^= (hash >> 8);
 
-	return hash >> 1;
+	return bond_ip_hash(hash, &flow);
 }
 
 /*-------------------------- Device entry points ----------------------------*/
-- 
1.8.3.1




More information about the kernel-team mailing list