Re: [PATCH net-next v3] bonding: add a vlan+srcmac tx hashing option

2021-01-18 Thread Jarod Wilson
On Mon, Jan 18, 2021 at 04:10:38PM -0700, David Ahern wrote:
> On 1/15/21 12:21 PM, Jarod Wilson wrote:
> > diff --git a/Documentation/networking/bonding.rst 
> > b/Documentation/networking/bonding.rst
> > index adc314639085..36562dcd3e1e 100644
> > --- a/Documentation/networking/bonding.rst
> > +++ b/Documentation/networking/bonding.rst
> > @@ -951,6 +951,19 @@ xmit_hash_policy
> > packets will be distributed according to the encapsulated
> > flows.
> >  
> > +   vlan+srcmac
> > +
> > +   This policy uses a very rudimentary vland ID and source mac
> 
> s/vland/vlan/
> 
> > +   ID hash to load-balance traffic per-vlan, with failover
> 
> drop ID on this line; just 'source mac'.

Bah. Crap. Didn't test documentation, clearly. Or proof-read it. Will fix
in v4. Hopefully, nothing else to change though...

-- 
Jarod Wilson
ja...@redhat.com



Re: [PATCH net-next v3] bonding: add a vlan+srcmac tx hashing option

2021-01-18 Thread David Ahern
On 1/15/21 12:21 PM, Jarod Wilson wrote:
> diff --git a/Documentation/networking/bonding.rst 
> b/Documentation/networking/bonding.rst
> index adc314639085..36562dcd3e1e 100644
> --- a/Documentation/networking/bonding.rst
> +++ b/Documentation/networking/bonding.rst
> @@ -951,6 +951,19 @@ xmit_hash_policy
>   packets will be distributed according to the encapsulated
>   flows.
>  
> + vlan+srcmac
> +
> + This policy uses a very rudimentary vland ID and source mac

s/vland/vlan/

> + ID hash to load-balance traffic per-vlan, with failover

drop ID on this line; just 'source mac'.


> + should one leg fail. The intended use case is for a bond
> + shared by multiple virtual machines, all configured to
> + use their own vlan, to give lacp-like functionality
> + without requiring lacp-capable switching hardware.
> +
> + The formula for the hash is simply
> +
> + hash = (vlan ID) XOR (source MAC vendor) XOR (source MAC dev)
> +
>   The default value is layer2.  This option was added in bonding
>   version 2.6.3.  In earlier versions of bonding, this parameter
>   does not exist, and the layer2 policy is the only policy.  The


[PATCH net-next v3] bonding: add a vlan+srcmac tx hashing option

2021-01-15 Thread Jarod Wilson
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 
Cc: Veaceslav Falico 
Cc: Andy Gospodarek 
Cc: "David S. Miller" 
Cc: Jakub Kicinski 
Cc: Thomas Davis 
Cc: net...@vger.kernel.org
Signed-off-by: Jarod Wilson 
---
v2: verified netlink interfaces working, added Documentation, changed
tx hash mode name to vlan+mac for consistency and clarity.
v3: drop inline from hash function, use full source MAC, not just the
last byte, expand explanation in patch description, extend hash name to
vlan+srcmac.

 Documentation/networking/bonding.rst | 13 +++
 drivers/net/bonding/bond_main.c  | 34 ++--
 drivers/net/bonding/bond_options.c   | 13 ++-
 include/linux/netdevice.h|  1 +
 include/uapi/linux/if_bonding.h  |  1 +
 5 files changed, 54 insertions(+), 8 deletions(-)

diff --git a/Documentation/networking/bonding.rst 
b/Documentation/networking/bonding.rst
index adc314639085..36562dcd3e1e 100644
--- a/Documentation/networking/bonding.rst
+++ b/Documentation/networking/bonding.rst
@@ -951,6 +951,19 @@ xmit_hash_policy
packets will be distributed according to the encapsulated
flows.
 
+   vlan+srcmac
+
+   This policy uses a very rudimentary vland ID and source mac
+   ID hash to load-balance traffic per-vlan, with failover
+   should one leg fail. The intended use case is for a bond
+   shared by multiple virtual machines, all configured to
+   use their own vlan, to give lacp-like functionality
+   without requiring lacp-capable switching hardware.
+
+   The formula for the hash is simply
+
+   hash = (vlan ID) XOR (source MAC vendor) XOR (source MAC dev)
+
The default value is layer2.  This option was added in bonding
version 2.6.3.  In earlier versions of bonding, this parameter
does not exist, and the layer2 policy is the only policy.  The
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 5fe5232cc3f3..d4bc4d4e953b 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -164,7 +164,7 @@ module_param(xmit_hash_policy, charp, 0);
 MODULE_PARM_DESC(xmit_hash_policy, "balance-alb, balance-tlb, balance-xor, 
802.3ad hashing method; "
   "0 for layer 2 (default), 1 for layer 3+4, "
   "2 for layer 2+3, 3 for encap layer 2+3, "
-  "4 for encap layer 3+4");
+  "4 for encap layer 3+4, 5 for vlan+srcmac");
 module_param(arp_interval, int, 0);
 MODULE_PARM_DESC(arp_interval, "arp interval in milliseconds");
 module_param_array(arp_ip_target, charp, NULL, 0);
@@ -1434,6 +1434,8 @@ static enum netdev_lag_hash bond_lag_hash_type(struct 
bonding *bond,
return NETDEV_LAG_HASH_E23;
case BOND_XMIT_POLICY_ENCAP34:
return NETDEV_LAG_HASH_E34;
+   case BOND_XMIT_POLICY_VLAN_SRCMAC:
+   return NETDEV_LAG_HASH_VLAN_SRCMAC;
default:
return NETDEV_LAG_HASH_UNKNOWN;
}
@@ -3494,6 +3496,27 @@ static bool bond_flow_ip(struct sk_buff *skb, struct 
flow_keys *fk,
return true;
 }
 
+static u32 bond_vlan_srcmac_hash(struct sk_buff *skb)
+{
+   struct ethhdr *mac_hdr = (struct ethhdr *)skb_mac_header(skb);
+   u32 srcmac_vendor = 0, srcmac_dev = 0;
+   u16 vlan;
+   int i;
+
+   for (i = 0; i < 3; i++)
+   srcmac_vendor = (srcmac_vendor << 8) | mac_hdr->h_source[i];
+
+   for (i = 3; i < ETH_ALEN; i++)
+   srcmac_dev = (srcmac_dev << 8) | mac_hdr->h_source[i];
+
+   if (!skb_vlan_tag_present(skb))
+