Skip to content

Commit 1e60ceb

Browse files
zhangkaihebdavem330
authored andcommitted
net: let flow have same hash in two directions
using same source and destination ip/port for flow hash calculation within the two directions. Signed-off-by: zhang kai <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 5e7b30d commit 1e60ceb

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

net/core/flow_dissector.c

+9-9
Original file line numberDiff line numberDiff line change
@@ -1504,7 +1504,7 @@ __be32 flow_get_u32_dst(const struct flow_keys *flow)
15041504
}
15051505
EXPORT_SYMBOL(flow_get_u32_dst);
15061506

1507-
/* Sort the source and destination IP (and the ports if the IP are the same),
1507+
/* Sort the source and destination IP and the ports,
15081508
* to have consistent hash within the two directions
15091509
*/
15101510
static inline void __flow_hash_consistentify(struct flow_keys *keys)
@@ -1515,25 +1515,25 @@ static inline void __flow_hash_consistentify(struct flow_keys *keys)
15151515
case FLOW_DISSECTOR_KEY_IPV4_ADDRS:
15161516
addr_diff = (__force u32)keys->addrs.v4addrs.dst -
15171517
(__force u32)keys->addrs.v4addrs.src;
1518-
if ((addr_diff < 0) ||
1519-
(addr_diff == 0 &&
1520-
((__force u16)keys->ports.dst <
1521-
(__force u16)keys->ports.src))) {
1518+
if (addr_diff < 0)
15221519
swap(keys->addrs.v4addrs.src, keys->addrs.v4addrs.dst);
1520+
1521+
if ((__force u16)keys->ports.dst <
1522+
(__force u16)keys->ports.src) {
15231523
swap(keys->ports.src, keys->ports.dst);
15241524
}
15251525
break;
15261526
case FLOW_DISSECTOR_KEY_IPV6_ADDRS:
15271527
addr_diff = memcmp(&keys->addrs.v6addrs.dst,
15281528
&keys->addrs.v6addrs.src,
15291529
sizeof(keys->addrs.v6addrs.dst));
1530-
if ((addr_diff < 0) ||
1531-
(addr_diff == 0 &&
1532-
((__force u16)keys->ports.dst <
1533-
(__force u16)keys->ports.src))) {
1530+
if (addr_diff < 0) {
15341531
for (i = 0; i < 4; i++)
15351532
swap(keys->addrs.v6addrs.src.s6_addr32[i],
15361533
keys->addrs.v6addrs.dst.s6_addr32[i]);
1534+
}
1535+
if ((__force u16)keys->ports.dst <
1536+
(__force u16)keys->ports.src) {
15371537
swap(keys->ports.src, keys->ports.dst);
15381538
}
15391539
break;

0 commit comments

Comments
 (0)