Skip to content

Commit 49aefd1

Browse files
suresh2514davem330
authored andcommitted
bonding: do not discard lowest hash bit for non layer3+4 hashing
Commit b5f8621 was introduced to discard lowest hash bit for layer3+4 hashing but it also removes last bit from non layer3+4 hashing Below script shows layer2+3 hashing will result in same slave to be used with above commit. $ cat hash.py #/usr/bin/python3.6 h_dests=[0xa0, 0xa1] h_source=0xe3 hproto=0x8 saddr=0x1e7aa8c0 daddr=0x17aa8c0 for h_dest in h_dests: hash = (h_dest ^ h_source ^ hproto ^ saddr ^ daddr) hash ^= hash >> 16 hash ^= hash >> 8 print(hash) print("with last bit removed") for h_dest in h_dests: hash = (h_dest ^ h_source ^ hproto ^ saddr ^ daddr) hash ^= hash >> 16 hash ^= hash >> 8 hash = hash >> 1 print(hash) Output: $ python3.6 hash.py 522133332 522133333 <-------------- will result in both slaves being used with last bit removed 261066666 261066666 <-------------- only single slave used Signed-off-by: suresh kumar <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent d08ed85 commit 49aefd1

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

drivers/net/bonding/bond_main.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4027,14 +4027,19 @@ static bool bond_flow_dissect(struct bonding *bond, struct sk_buff *skb, const v
40274027
return true;
40284028
}
40294029

4030-
static u32 bond_ip_hash(u32 hash, struct flow_keys *flow)
4030+
static u32 bond_ip_hash(u32 hash, struct flow_keys *flow, int xmit_policy)
40314031
{
40324032
hash ^= (__force u32)flow_get_u32_dst(flow) ^
40334033
(__force u32)flow_get_u32_src(flow);
40344034
hash ^= (hash >> 16);
40354035
hash ^= (hash >> 8);
4036+
40364037
/* discard lowest hash bit to deal with the common even ports pattern */
4037-
return hash >> 1;
4038+
if (xmit_policy == BOND_XMIT_POLICY_LAYER34 ||
4039+
xmit_policy == BOND_XMIT_POLICY_ENCAP34)
4040+
return hash >> 1;
4041+
4042+
return hash;
40384043
}
40394044

40404045
/* Generate hash based on xmit policy. If @skb is given it is used to linearize
@@ -4064,7 +4069,7 @@ static u32 __bond_xmit_hash(struct bonding *bond, struct sk_buff *skb, const voi
40644069
memcpy(&hash, &flow.ports.ports, sizeof(hash));
40654070
}
40664071

4067-
return bond_ip_hash(hash, &flow);
4072+
return bond_ip_hash(hash, &flow, bond->params.xmit_policy);
40684073
}
40694074

40704075
/**
@@ -5259,7 +5264,7 @@ static u32 bond_sk_hash_l34(struct sock *sk)
52595264
/* L4 */
52605265
memcpy(&hash, &flow.ports.ports, sizeof(hash));
52615266
/* L3 */
5262-
return bond_ip_hash(hash, &flow);
5267+
return bond_ip_hash(hash, &flow, BOND_XMIT_POLICY_LAYER34);
52635268
}
52645269

52655270
static struct net_device *__bond_sk_get_lower_dev(struct bonding *bond,

0 commit comments

Comments
 (0)