Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] net: let flow have same hash in two directions
@ 2021-07-28 10:54 zhang kai
  2021-07-28 12:00 ` patchwork-bot+netdevbpf
  2021-07-30 10:59 ` Jakub Kicinski
  0 siblings, 2 replies; 3+ messages in thread
From: zhang kai @ 2021-07-28 10:54 UTC (permalink / raw)
  To: davem
  Cc: kuba, ast, daniel, andrii, kafai, songliubraving, yhs,
	john.fastabend, kpsingh, krzysztof.kozlowski, netdev,
	linux-kernel, zhang kai

using same source and destination ip/port for flow hash calculation
within the two directions.

Signed-off-by: zhang kai <zhangkaiheb@126.com>
---
 net/core/flow_dissector.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c
index 3ed7c98a9..dfc18f212 100644
--- a/net/core/flow_dissector.c
+++ b/net/core/flow_dissector.c
@@ -1504,7 +1504,7 @@ __be32 flow_get_u32_dst(const struct flow_keys *flow)
 }
 EXPORT_SYMBOL(flow_get_u32_dst);
 
-/* Sort the source and destination IP (and the ports if the IP are the same),
+/* Sort the source and destination IP and the ports,
  * to have consistent hash within the two directions
  */
 static inline void __flow_hash_consistentify(struct flow_keys *keys)
@@ -1515,11 +1515,11 @@ static inline void __flow_hash_consistentify(struct flow_keys *keys)
 	case FLOW_DISSECTOR_KEY_IPV4_ADDRS:
 		addr_diff = (__force u32)keys->addrs.v4addrs.dst -
 			    (__force u32)keys->addrs.v4addrs.src;
-		if ((addr_diff < 0) ||
-		    (addr_diff == 0 &&
-		     ((__force u16)keys->ports.dst <
-		      (__force u16)keys->ports.src))) {
+		if (addr_diff < 0)
 			swap(keys->addrs.v4addrs.src, keys->addrs.v4addrs.dst);
+
+		if ((__force u16)keys->ports.dst <
+		    (__force u16)keys->ports.src) {
 			swap(keys->ports.src, keys->ports.dst);
 		}
 		break;
@@ -1527,13 +1527,13 @@ static inline void __flow_hash_consistentify(struct flow_keys *keys)
 		addr_diff = memcmp(&keys->addrs.v6addrs.dst,
 				   &keys->addrs.v6addrs.src,
 				   sizeof(keys->addrs.v6addrs.dst));
-		if ((addr_diff < 0) ||
-		    (addr_diff == 0 &&
-		     ((__force u16)keys->ports.dst <
-		      (__force u16)keys->ports.src))) {
+		if (addr_diff < 0) {
 			for (i = 0; i < 4; i++)
 				swap(keys->addrs.v6addrs.src.s6_addr32[i],
 				     keys->addrs.v6addrs.dst.s6_addr32[i]);
+		}
+		if ((__force u16)keys->ports.dst <
+		    (__force u16)keys->ports.src) {
 			swap(keys->ports.src, keys->ports.dst);
 		}
 		break;
-- 
2.17.1


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

* Re: [PATCH] net: let flow have same hash in two directions
  2021-07-28 10:54 [PATCH] net: let flow have same hash in two directions zhang kai
@ 2021-07-28 12:00 ` patchwork-bot+netdevbpf
  2021-07-30 10:59 ` Jakub Kicinski
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-07-28 12:00 UTC (permalink / raw)
  To: zhang kai
  Cc: davem, kuba, ast, daniel, andrii, kafai, songliubraving, yhs,
	john.fastabend, kpsingh, krzysztof.kozlowski, netdev,
	linux-kernel

Hello:

This patch was applied to netdev/net.git (refs/heads/master):

On Wed, 28 Jul 2021 18:54:18 +0800 you wrote:
> using same source and destination ip/port for flow hash calculation
> within the two directions.
> 
> Signed-off-by: zhang kai <zhangkaiheb@126.com>
> ---
>  net/core/flow_dissector.c | 18 +++++++++---------
>  1 file changed, 9 insertions(+), 9 deletions(-)

Here is the summary with links:
  - net: let flow have same hash in two directions
    https://git.kernel.org/netdev/net/c/1e60cebf8294

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

* Re: [PATCH] net: let flow have same hash in two directions
  2021-07-28 10:54 [PATCH] net: let flow have same hash in two directions zhang kai
  2021-07-28 12:00 ` patchwork-bot+netdevbpf
@ 2021-07-30 10:59 ` Jakub Kicinski
  1 sibling, 0 replies; 3+ messages in thread
From: Jakub Kicinski @ 2021-07-30 10:59 UTC (permalink / raw)
  To: zhang kai
  Cc: davem, ast, daniel, andrii, kafai, songliubraving, yhs,
	john.fastabend, kpsingh, krzysztof.kozlowski, netdev,
	linux-kernel

On Wed, 28 Jul 2021 18:54:18 +0800 zhang kai wrote:
> using same source and destination ip/port for flow hash calculation
> within the two directions.

Did you observe the hash being different, or just found this by code
inspection? AFAICT the existing code was fine, and probably slightly
faster.

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

end of thread, other threads:[~2021-07-30 10:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-28 10:54 [PATCH] net: let flow have same hash in two directions zhang kai
2021-07-28 12:00 ` patchwork-bot+netdevbpf
2021-07-30 10:59 ` Jakub Kicinski

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).