Skip to content

Commit 7b8fc01

Browse files
jarodwilsonkuba-moo
authored andcommitted
bonding: add a vlan+srcmac tx hashing option
This comes from an end-user request, where they're running multiple VMs on hosts with bonded interfaces connected to some interest switch topologies, where 802.3ad isn't an option. They're currently running a proprietary solution that effectively achieves load-balancing of VMs and bandwidth utilization improvements with a similar form of transmission algorithm. Basically, each VM has it's own vlan, so it always sends its traffic out the same interface, unless that interface fails. Traffic gets split between the interfaces, maintaining a consistent path, with failover still available if an interface goes down. Unlike bond_eth_hash(), this hash function is using the full source MAC address instead of just the last byte, as there are so few components to the hash, and in the no-vlan case, we would be returning just the last byte of the source MAC as the hash value. It's entirely possible to have two NICs in a bond with the same last byte of their MAC, but not the same MAC, so this adjustment should guarantee distinct hashes in all cases. This has been rudimetarily tested to provide similar results to the proprietary solution it is aiming to replace. A patch for iproute2 is also posted, to properly support the new mode there as well. Cc: Jay Vosburgh <j.vosburgh@gmail.com> Cc: Veaceslav Falico <vfalico@gmail.com> Cc: Andy Gospodarek <andy@greyhouse.net> Cc: Thomas Davis <tadavis@lbl.gov> Signed-off-by: Jarod Wilson <jarod@redhat.com> Link: https://lore.kernel.org/r/20210119010927.1191922-1-jarod@redhat.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 00b229f commit 7b8fc01

5 files changed

Lines changed: 54 additions & 8 deletions

File tree

‎Documentation/networking/bonding.rst‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,19 @@ xmit_hash_policy
951951
packets will be distributed according to the encapsulated
952952
flows.
953953

954+
vlan+srcmac
955+
956+
This policy uses a very rudimentary vlan ID and source mac
957+
hash to load-balance traffic per-vlan, with failover
958+
should one leg fail. The intended use case is for a bond
959+
shared by multiple virtual machines, all configured to
960+
use their own vlan, to give lacp-like functionality
961+
without requiring lacp-capable switching hardware.
962+
963+
The formula for the hash is simply
964+
965+
hash = (vlan ID) XOR (source MAC vendor) XOR (source MAC dev)
966+
954967
The default value is layer2. This option was added in bonding
955968
version 2.6.3. In earlier versions of bonding, this parameter
956969
does not exist, and the layer2 policy is the only policy. The

‎drivers/net/bonding/bond_main.c‎

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ module_param(xmit_hash_policy, charp, 0);
167167
MODULE_PARM_DESC(xmit_hash_policy, "balance-alb, balance-tlb, balance-xor, 802.3ad hashing method; "
168168
"0 for layer 2 (default), 1 for layer 3+4, "
169169
"2 for layer 2+3, 3 for encap layer 2+3, "
170-
"4 for encap layer 3+4");
170+
"4 for encap layer 3+4, 5 for vlan+srcmac");
171171
module_param(arp_interval, int, 0);
172172
MODULE_PARM_DESC(arp_interval, "arp interval in milliseconds");
173173
module_param_array(arp_ip_target, charp, NULL, 0);
@@ -1457,6 +1457,8 @@ static enum netdev_lag_hash bond_lag_hash_type(struct bonding *bond,
14571457
return NETDEV_LAG_HASH_E23;
14581458
case BOND_XMIT_POLICY_ENCAP34:
14591459
return NETDEV_LAG_HASH_E34;
1460+
case BOND_XMIT_POLICY_VLAN_SRCMAC:
1461+
return NETDEV_LAG_HASH_VLAN_SRCMAC;
14601462
default:
14611463
return NETDEV_LAG_HASH_UNKNOWN;
14621464
}
@@ -3519,17 +3521,42 @@ static bool bond_flow_ip(struct sk_buff *skb, struct flow_keys *fk,
35193521
return true;
35203522
}
35213523

3524+
static u32 bond_vlan_srcmac_hash(struct sk_buff *skb)
3525+
{
3526+
struct ethhdr *mac_hdr = (struct ethhdr *)skb_mac_header(skb);
3527+
u32 srcmac_vendor = 0, srcmac_dev = 0;
3528+
u16 vlan;
3529+
int i;
3530+
3531+
for (i = 0; i < 3; i++)
3532+
srcmac_vendor = (srcmac_vendor << 8) | mac_hdr->h_source[i];
3533+
3534+
for (i = 3; i < ETH_ALEN; i++)
3535+
srcmac_dev = (srcmac_dev << 8) | mac_hdr->h_source[i];
3536+
3537+
if (!skb_vlan_tag_present(skb))
3538+
return srcmac_vendor ^ srcmac_dev;
3539+
3540+
vlan = skb_vlan_tag_get(skb);
3541+
3542+
return vlan ^ srcmac_vendor ^ srcmac_dev;
3543+
}
3544+
35223545
/* Extract the appropriate headers based on bond's xmit policy */
35233546
static bool bond_flow_dissect(struct bonding *bond, struct sk_buff *skb,
35243547
struct flow_keys *fk)
35253548
{
35263549
bool l34 = bond->params.xmit_policy == BOND_XMIT_POLICY_LAYER34;
35273550
int noff, proto = -1;
35283551

3529-
if (bond->params.xmit_policy > BOND_XMIT_POLICY_LAYER23) {
3552+
switch (bond->params.xmit_policy) {
3553+
case BOND_XMIT_POLICY_ENCAP23:
3554+
case BOND_XMIT_POLICY_ENCAP34:
35303555
memset(fk, 0, sizeof(*fk));
35313556
return __skb_flow_dissect(NULL, skb, &flow_keys_bonding,
35323557
fk, NULL, 0, 0, 0, 0);
3558+
default:
3559+
break;
35333560
}
35343561

35353562
fk->ports.ports = 0;
@@ -3591,6 +3618,9 @@ u32 bond_xmit_hash(struct bonding *bond, struct sk_buff *skb)
35913618
skb->l4_hash)
35923619
return skb->hash;
35933620

3621+
if (bond->params.xmit_policy == BOND_XMIT_POLICY_VLAN_SRCMAC)
3622+
return bond_vlan_srcmac_hash(skb);
3623+
35943624
if (bond->params.xmit_policy == BOND_XMIT_POLICY_LAYER2 ||
35953625
!bond_flow_dissect(bond, skb, &flow))
35963626
return bond_eth_hash(skb);

‎drivers/net/bonding/bond_options.c‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,13 @@ static const struct bond_opt_value bond_pps_tbl[] = {
9696
};
9797

9898
static const struct bond_opt_value bond_xmit_hashtype_tbl[] = {
99-
{ "layer2", BOND_XMIT_POLICY_LAYER2, BOND_VALFLAG_DEFAULT},
100-
{ "layer3+4", BOND_XMIT_POLICY_LAYER34, 0},
101-
{ "layer2+3", BOND_XMIT_POLICY_LAYER23, 0},
102-
{ "encap2+3", BOND_XMIT_POLICY_ENCAP23, 0},
103-
{ "encap3+4", BOND_XMIT_POLICY_ENCAP34, 0},
104-
{ NULL, -1, 0},
99+
{ "layer2", BOND_XMIT_POLICY_LAYER2, BOND_VALFLAG_DEFAULT},
100+
{ "layer3+4", BOND_XMIT_POLICY_LAYER34, 0},
101+
{ "layer2+3", BOND_XMIT_POLICY_LAYER23, 0},
102+
{ "encap2+3", BOND_XMIT_POLICY_ENCAP23, 0},
103+
{ "encap3+4", BOND_XMIT_POLICY_ENCAP34, 0},
104+
{ "vlan+srcmac", BOND_XMIT_POLICY_VLAN_SRCMAC, 0},
105+
{ NULL, -1, 0},
105106
};
106107

107108
static const struct bond_opt_value bond_arp_validate_tbl[] = {

‎include/linux/netdevice.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2617,6 +2617,7 @@ enum netdev_lag_hash {
26172617
NETDEV_LAG_HASH_L23,
26182618
NETDEV_LAG_HASH_E23,
26192619
NETDEV_LAG_HASH_E34,
2620+
NETDEV_LAG_HASH_VLAN_SRCMAC,
26202621
NETDEV_LAG_HASH_UNKNOWN,
26212622
};
26222623

‎include/uapi/linux/if_bonding.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
#define BOND_XMIT_POLICY_LAYER23 2 /* layer 2+3 (IP ^ MAC) */
9595
#define BOND_XMIT_POLICY_ENCAP23 3 /* encapsulated layer 2+3 */
9696
#define BOND_XMIT_POLICY_ENCAP34 4 /* encapsulated layer 3+4 */
97+
#define BOND_XMIT_POLICY_VLAN_SRCMAC 5 /* vlan + source MAC */
9798

9899
/* 802.3ad port state definitions (43.4.2.2 in the 802.3ad standard) */
99100
#define LACP_STATE_LACP_ACTIVITY 0x1

0 commit comments

Comments
 (0)