Update to 3.4-final.
[linux-flexiantxendom0-3.2.10.git] / drivers / net / bonding / bond_alb.c
index 8b1c143..2e1f806 100644 (file)
@@ -20,7 +20,7 @@
  *
  */
 
-//#define BONDING_DEBUG 1
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
 #include <linux/skbuff.h>
 #include <linux/netdevice.h>
 #include <linux/in.h>
 #include <net/ipx.h>
 #include <net/arp.h>
+#include <net/ipv6.h>
 #include <asm/byteorder.h>
 #include "bonding.h"
 #include "bond_alb.h"
 
 
-#define ALB_TIMER_TICKS_PER_SEC            10  /* should be a divisor of HZ */
-#define BOND_TLB_REBALANCE_INTERVAL 10 /* In seconds, periodic re-balancing.
-                                        * Used for division - never set
-                                        * to zero !!!
-                                        */
-#define BOND_ALB_LP_INTERVAL       1   /* In seconds, periodic send of
-                                        * learning packets to the switch
-                                        */
-
-#define BOND_TLB_REBALANCE_TICKS (BOND_TLB_REBALANCE_INTERVAL \
-                                 * ALB_TIMER_TICKS_PER_SEC)
-
-#define BOND_ALB_LP_TICKS (BOND_ALB_LP_INTERVAL \
-                          * ALB_TIMER_TICKS_PER_SEC)
-
-#define TLB_HASH_TABLE_SIZE 256        /* The size of the clients hash table.
-                                * Note that this value MUST NOT be smaller
-                                * because the key hash table is BYTE wide !
-                                */
-
 
-#define TLB_NULL_INDEX         0xffffffff
-#define MAX_LP_BURST           3
-
-/* rlb defs */
-#define RLB_HASH_TABLE_SIZE    256
-#define RLB_NULL_INDEX         0xffffffff
-#define RLB_UPDATE_DELAY       2*ALB_TIMER_TICKS_PER_SEC /* 2 seconds */
-#define RLB_ARP_BURST_SIZE     2
-#define RLB_UPDATE_RETRY       3       /* 3-ticks - must be smaller than the rlb
-                                        * rebalance interval (5 min).
-                                        */
-/* RLB_PROMISC_TIMEOUT = 10 sec equals the time that the current slave is
- * promiscuous after failover
- */
-#define RLB_PROMISC_TIMEOUT    10*ALB_TIMER_TICKS_PER_SEC
-
-static const u8 mac_bcast[ETH_ALEN] = {0xff,0xff,0xff,0xff,0xff,0xff};
+#ifndef __long_aligned
+#define __long_aligned __attribute__((aligned((sizeof(long)))))
+#endif
+static const u8 mac_bcast[ETH_ALEN] __long_aligned = {
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff
+};
+static const u8 mac_v6_allmcast[ETH_ALEN] __long_aligned = {
+       0x33, 0x33, 0x00, 0x00, 0x00, 0x01
+};
 static const int alb_delta_in_ticks = HZ / ALB_TIMER_TICKS_PER_SEC;
 
 #pragma pack(1)
 struct learning_pkt {
        u8 mac_dst[ETH_ALEN];
        u8 mac_src[ETH_ALEN];
-       u16 type;
+       __be16 type;
        u8 padding[ETH_ZLEN - ETH_HLEN];
 };
 
 struct arp_pkt {
-       u16     hw_addr_space;
-       u16     prot_addr_space;
+       __be16  hw_addr_space;
+       __be16  prot_addr_space;
        u8      hw_addr_len;
        u8      prot_addr_len;
-       u16     op_code;
+       __be16  op_code;
        u8      mac_src[ETH_ALEN];      /* sender hardware address */
-       u32     ip_src;                 /* sender IP address */
+       __be32  ip_src;                 /* sender IP address */
        u8      mac_dst[ETH_ALEN];      /* target hardware address */
-       u32     ip_dst;                 /* target IP address */
+       __be32  ip_dst;                 /* target IP address */
 };
 #pragma pack()
 
+static inline struct arp_pkt *arp_pkt(const struct sk_buff *skb)
+{
+       return (struct arp_pkt *)skb_network_header(skb);
+}
+
 /* Forward declaration */
 static void alb_send_learning_packets(struct slave *slave, u8 mac_addr[]);
 
-static inline u8 _simple_hash(u8 *hash_start, int hash_size)
+static inline u8 _simple_hash(const u8 *hash_start, int hash_size)
 {
        int i;
        u8 hash = 0;
@@ -121,16 +99,26 @@ static inline u8 _simple_hash(u8 *hash_start, int hash_size)
 
 /*********************** tlb specific functions ***************************/
 
-static inline void _lock_tx_hashtbl(struct bonding *bond)
+static inline void _lock_tx_hashtbl_bh(struct bonding *bond)
 {
        spin_lock_bh(&(BOND_ALB_INFO(bond).tx_hashtbl_lock));
 }
 
-static inline void _unlock_tx_hashtbl(struct bonding *bond)
+static inline void _unlock_tx_hashtbl_bh(struct bonding *bond)
 {
        spin_unlock_bh(&(BOND_ALB_INFO(bond).tx_hashtbl_lock));
 }
 
+static inline void _lock_tx_hashtbl(struct bonding *bond)
+{
+       spin_lock(&(BOND_ALB_INFO(bond).tx_hashtbl_lock));
+}
+
+static inline void _unlock_tx_hashtbl(struct bonding *bond)
+{
+       spin_unlock(&(BOND_ALB_INFO(bond).tx_hashtbl_lock));
+}
+
 /* Caller must hold tx_hashtbl lock */
 static inline void tlb_init_table_entry(struct tlb_client_info *entry, int save_load)
 {
@@ -151,27 +139,36 @@ static inline void tlb_init_slave(struct slave *slave)
        SLAVE_TLB_INFO(slave).head = TLB_NULL_INDEX;
 }
 
-/* Caller must hold bond lock for read */
-static void tlb_clear_slave(struct bonding *bond, struct slave *slave, int save_load)
+/* Caller must hold bond lock for read, BH disabled */
+static void __tlb_clear_slave(struct bonding *bond, struct slave *slave,
+                        int save_load)
 {
        struct tlb_client_info *tx_hash_table;
        u32 index;
 
-       _lock_tx_hashtbl(bond);
-
        /* clear slave from tx_hashtbl */
        tx_hash_table = BOND_ALB_INFO(bond).tx_hashtbl;
 
-       index = SLAVE_TLB_INFO(slave).head;
-       while (index != TLB_NULL_INDEX) {
-               u32 next_index = tx_hash_table[index].next;
-               tlb_init_table_entry(&tx_hash_table[index], save_load);
-               index = next_index;
+       /* skip this if we've already freed the tx hash table */
+       if (tx_hash_table) {
+               index = SLAVE_TLB_INFO(slave).head;
+               while (index != TLB_NULL_INDEX) {
+                       u32 next_index = tx_hash_table[index].next;
+                       tlb_init_table_entry(&tx_hash_table[index], save_load);
+                       index = next_index;
+               }
        }
 
        tlb_init_slave(slave);
+}
 
-       _unlock_tx_hashtbl(bond);
+/* Caller must hold bond lock for read */
+static void tlb_clear_slave(struct bonding *bond, struct slave *slave,
+                        int save_load)
+{
+       _lock_tx_hashtbl_bh(bond);
+       __tlb_clear_slave(bond, slave, save_load);
+       _unlock_tx_hashtbl_bh(bond);
 }
 
 /* Must be called before starting the monitor timer */
@@ -182,26 +179,19 @@ static int tlb_initialize(struct bonding *bond)
        struct tlb_client_info *new_hashtbl;
        int i;
 
-       spin_lock_init(&(bond_info->tx_hashtbl_lock));
-
-       new_hashtbl = kmalloc(size, GFP_KERNEL);
-       if (!new_hashtbl) {
-               printk(KERN_ERR DRV_NAME
-                      ": %s: Error: Failed to allocate TLB hash table\n",
-                      bond->dev->name);
+       new_hashtbl = kzalloc(size, GFP_KERNEL);
+       if (!new_hashtbl)
                return -1;
-       }
-       _lock_tx_hashtbl(bond);
 
-       bond_info->tx_hashtbl = new_hashtbl;
+       _lock_tx_hashtbl_bh(bond);
 
-       memset(bond_info->tx_hashtbl, 0, size);
+       bond_info->tx_hashtbl = new_hashtbl;
 
        for (i = 0; i < TLB_HASH_TABLE_SIZE; i++) {
-               tlb_init_table_entry(&bond_info->tx_hashtbl[i], 1);
+               tlb_init_table_entry(&bond_info->tx_hashtbl[i], 0);
        }
 
-       _unlock_tx_hashtbl(bond);
+       _unlock_tx_hashtbl_bh(bond);
 
        return 0;
 }
@@ -211,42 +201,35 @@ static void tlb_deinitialize(struct bonding *bond)
 {
        struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
 
-       _lock_tx_hashtbl(bond);
+       _lock_tx_hashtbl_bh(bond);
 
        kfree(bond_info->tx_hashtbl);
        bond_info->tx_hashtbl = NULL;
 
-       _unlock_tx_hashtbl(bond);
+       _unlock_tx_hashtbl_bh(bond);
+}
+
+static long long compute_gap(struct slave *slave)
+{
+       return (s64) (slave->speed << 20) - /* Convert to Megabit per sec */
+              (s64) (SLAVE_TLB_INFO(slave).load << 3); /* Bytes to bits */
 }
 
 /* Caller must hold bond lock for read */
 static struct slave *tlb_get_least_loaded_slave(struct bonding *bond)
 {
        struct slave *slave, *least_loaded;
-       s64 max_gap;
-       int i, found = 0;
-
-       /* Find the first enabled slave */
-       bond_for_each_slave(bond, slave, i) {
-               if (SLAVE_IS_OK(slave)) {
-                       found = 1;
-                       break;
-               }
-       }
-
-       if (!found) {
-               return NULL;
-       }
+       long long max_gap;
+       int i;
 
-       least_loaded = slave;
-       max_gap = (s64)(slave->speed << 20) - /* Convert to Megabit per sec */
-                       (s64)(SLAVE_TLB_INFO(slave).load << 3); /* Bytes to bits */
+       least_loaded = NULL;
+       max_gap = LLONG_MIN;
 
        /* Find the slave with the largest gap */
-       bond_for_each_slave_from(bond, slave, i, least_loaded) {
+       bond_for_each_slave(bond, slave, i) {
                if (SLAVE_IS_OK(slave)) {
-                       s64 gap = (s64)(slave->speed << 20) -
-                                       (s64)(SLAVE_TLB_INFO(slave).load << 3);
+                       long long gap = compute_gap(slave);
+
                        if (max_gap < gap) {
                                least_loaded = slave;
                                max_gap = gap;
@@ -257,15 +240,13 @@ static struct slave *tlb_get_least_loaded_slave(struct bonding *bond)
        return least_loaded;
 }
 
-/* Caller must hold bond lock for read */
-static struct slave *tlb_choose_channel(struct bonding *bond, u32 hash_index, u32 skb_len)
+static struct slave *__tlb_choose_channel(struct bonding *bond, u32 hash_index,
+                                               u32 skb_len)
 {
        struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
        struct tlb_client_info *hash_table;
        struct slave *assigned_slave;
 
-       _lock_tx_hashtbl(bond);
-
        hash_table = bond_info->tx_hashtbl;
        assigned_slave = hash_table[hash_index].tx_slave;
        if (!assigned_slave) {
@@ -294,22 +275,46 @@ static struct slave *tlb_choose_channel(struct bonding *bond, u32 hash_index, u3
                hash_table[hash_index].tx_bytes += skb_len;
        }
 
-       _unlock_tx_hashtbl(bond);
-
        return assigned_slave;
 }
 
+/* Caller must hold bond lock for read */
+static struct slave *tlb_choose_channel(struct bonding *bond, u32 hash_index,
+                                       u32 skb_len)
+{
+       struct slave *tx_slave;
+       /*
+        * We don't need to disable softirq here, becase
+        * tlb_choose_channel() is only called by bond_alb_xmit()
+        * which already has softirq disabled.
+        */
+       _lock_tx_hashtbl(bond);
+       tx_slave = __tlb_choose_channel(bond, hash_index, skb_len);
+       _unlock_tx_hashtbl(bond);
+       return tx_slave;
+}
+
 /*********************** rlb specific functions ***************************/
-static inline void _lock_rx_hashtbl(struct bonding *bond)
+static inline void _lock_rx_hashtbl_bh(struct bonding *bond)
 {
        spin_lock_bh(&(BOND_ALB_INFO(bond).rx_hashtbl_lock));
 }
 
-static inline void _unlock_rx_hashtbl(struct bonding *bond)
+static inline void _unlock_rx_hashtbl_bh(struct bonding *bond)
 {
        spin_unlock_bh(&(BOND_ALB_INFO(bond).rx_hashtbl_lock));
 }
 
+static inline void _lock_rx_hashtbl(struct bonding *bond)
+{
+       spin_lock(&(BOND_ALB_INFO(bond).rx_hashtbl_lock));
+}
+
+static inline void _unlock_rx_hashtbl(struct bonding *bond)
+{
+       spin_unlock(&(BOND_ALB_INFO(bond).rx_hashtbl_lock));
+}
+
 /* when an ARP REPLY is received from a client update its info
  * in the rx_hashtbl
  */
@@ -319,54 +324,53 @@ static void rlb_update_entry_from_arp(struct bonding *bond, struct arp_pkt *arp)
        struct rlb_client_info *client_info;
        u32 hash_index;
 
-       _lock_rx_hashtbl(bond);
+       _lock_rx_hashtbl_bh(bond);
 
        hash_index = _simple_hash((u8*)&(arp->ip_src), sizeof(arp->ip_src));
        client_info = &(bond_info->rx_hashtbl[hash_index]);
 
        if ((client_info->assigned) &&
            (client_info->ip_src == arp->ip_dst) &&
-           (client_info->ip_dst == arp->ip_src)) {
+           (client_info->ip_dst == arp->ip_src) &&
+           (compare_ether_addr_64bits(client_info->mac_dst, arp->mac_src))) {
                /* update the clients MAC address */
                memcpy(client_info->mac_dst, arp->mac_src, ETH_ALEN);
                client_info->ntt = 1;
                bond_info->rx_ntt = 1;
        }
 
-       _unlock_rx_hashtbl(bond);
+       _unlock_rx_hashtbl_bh(bond);
 }
 
-static int rlb_arp_recv(struct sk_buff *skb, struct net_device *bond_dev, struct packet_type *ptype, struct net_device *orig_dev)
+static int rlb_arp_recv(struct sk_buff *skb, struct bonding *bond,
+                        struct slave *slave)
 {
-       struct bonding *bond = bond_dev->priv;
-       struct arp_pkt *arp = (struct arp_pkt *)skb->data;
-       int res = NET_RX_DROP;
+       struct arp_pkt *arp;
 
-       if (!(bond_dev->flags & IFF_MASTER))
+       if (skb->protocol != cpu_to_be16(ETH_P_ARP))
                goto out;
 
+       arp = (struct arp_pkt *) skb->data;
        if (!arp) {
-               dprintk("Packet has no ARP data\n");
+               pr_debug("Packet has no ARP data\n");
                goto out;
        }
 
+       if (!pskb_may_pull(skb, arp_hdr_len(bond->dev)))
+               goto out;
+
        if (skb->len < sizeof(struct arp_pkt)) {
-               dprintk("Packet is too small to be an ARP\n");
+               pr_debug("Packet is too small to be an ARP\n");
                goto out;
        }
 
        if (arp->op_code == htons(ARPOP_REPLY)) {
                /* update rx hash table for this ARP */
                rlb_update_entry_from_arp(bond, arp);
-               dprintk("Server received an ARP Reply from client\n");
+               pr_debug("Server received an ARP Reply from client\n");
        }
-
-       res = NET_RX_SUCCESS;
-
 out:
-       dev_kfree_skb(skb);
-
-       return res;
+       return RX_HANDLER_ANOTHER;
 }
 
 /* Caller must hold bond lock for read */
@@ -413,8 +417,10 @@ static void rlb_teach_disabled_mac_on_primary(struct bonding *bond, u8 addr[])
        }
 
        if (!bond->alb_info.primary_is_promisc) {
-               bond->alb_info.primary_is_promisc = 1;
-               dev_set_promiscuity(bond->curr_active_slave->dev, 1);
+               if (!dev_set_promiscuity(bond->curr_active_slave->dev, 1))
+                       bond->alb_info.primary_is_promisc = 1;
+               else
+                       bond->alb_info.primary_is_promisc = 0;
        }
 
        bond->alb_info.rlb_promisc_timeout_counter = 0;
@@ -433,7 +439,7 @@ static void rlb_clear_slave(struct bonding *bond, struct slave *slave)
        u32 index, next_index;
 
        /* clear slave from rx_hashtbl */
-       _lock_rx_hashtbl(bond);
+       _lock_rx_hashtbl_bh(bond);
 
        rx_hash_table = bond_info->rx_hashtbl;
        index = bond_info->rx_hashtbl_head;
@@ -444,8 +450,8 @@ static void rlb_clear_slave(struct bonding *bond, struct slave *slave)
 
                        if (assigned_slave) {
                                rx_hash_table[index].slave = assigned_slave;
-                               if (memcmp(rx_hash_table[index].mac_dst,
-                                          mac_bcast, ETH_ALEN)) {
+                               if (compare_ether_addr_64bits(rx_hash_table[index].mac_dst,
+                                                             mac_bcast)) {
                                        bond_info->rx_hashtbl[index].ntt = 1;
                                        bond_info->rx_ntt = 1;
                                        /* A slave has been removed from the
@@ -464,15 +470,15 @@ static void rlb_clear_slave(struct bonding *bond, struct slave *slave)
                }
        }
 
-       _unlock_rx_hashtbl(bond);
+       _unlock_rx_hashtbl_bh(bond);
 
-       write_lock(&bond->curr_slave_lock);
+       write_lock_bh(&bond->curr_slave_lock);
 
        if (slave != bond->curr_active_slave) {
                rlb_teach_disabled_mac_on_primary(bond, slave->dev->dev_addr);
        }
 
-       write_unlock(&bond->curr_slave_lock);
+       write_unlock_bh(&bond->curr_slave_lock);
 }
 
 static void rlb_update_client(struct rlb_client_info *client_info)
@@ -494,8 +500,7 @@ static void rlb_update_client(struct rlb_client_info *client_info)
                                 client_info->slave->dev->dev_addr,
                                 client_info->mac_dst);
                if (!skb) {
-                       printk(KERN_ERR DRV_NAME
-                              ": %s: Error: failed to create an ARP packet\n",
+                       pr_err("%s: Error: failed to create an ARP packet\n",
                               client_info->slave->dev->master->name);
                        continue;
                }
@@ -505,8 +510,7 @@ static void rlb_update_client(struct rlb_client_info *client_info)
                if (client_info->tag) {
                        skb = vlan_put_tag(skb, client_info->vlan_id);
                        if (!skb) {
-                               printk(KERN_ERR DRV_NAME
-                                      ": %s: Error: failed to insert VLAN tag\n",
+                               pr_err("%s: Error: failed to insert VLAN tag\n",
                                       client_info->slave->dev->master->name);
                                continue;
                        }
@@ -523,7 +527,7 @@ static void rlb_update_rx_clients(struct bonding *bond)
        struct rlb_client_info *client_info;
        u32 hash_index;
 
-       _lock_rx_hashtbl(bond);
+       _lock_rx_hashtbl_bh(bond);
 
        hash_index = bond_info->rx_hashtbl_head;
        for (; hash_index != RLB_NULL_INDEX; hash_index = client_info->next) {
@@ -536,12 +540,12 @@ static void rlb_update_rx_clients(struct bonding *bond)
                }
        }
 
-       /* do not update the entries again untill this counter is zero so that
+       /* do not update the entries again until this counter is zero so that
         * not to confuse the clients.
         */
        bond_info->rlb_update_delay_counter = RLB_UPDATE_DELAY;
 
-       _unlock_rx_hashtbl(bond);
+       _unlock_rx_hashtbl_bh(bond);
 }
 
 /* The slave was assigned a new mac address - update the clients */
@@ -552,14 +556,14 @@ static void rlb_req_update_slave_clients(struct bonding *bond, struct slave *sla
        int ntt = 0;
        u32 hash_index;
 
-       _lock_rx_hashtbl(bond);
+       _lock_rx_hashtbl_bh(bond);
 
        hash_index = bond_info->rx_hashtbl_head;
        for (; hash_index != RLB_NULL_INDEX; hash_index = client_info->next) {
                client_info = &(bond_info->rx_hashtbl[hash_index]);
 
                if ((client_info->slave == slave) &&
-                   memcmp(client_info->mac_dst, mac_bcast, ETH_ALEN)) {
+                   compare_ether_addr_64bits(client_info->mac_dst, mac_bcast)) {
                        client_info->ntt = 1;
                        ntt = 1;
                }
@@ -572,11 +576,11 @@ static void rlb_req_update_slave_clients(struct bonding *bond, struct slave *sla
                bond_info->rlb_update_retry_counter = RLB_UPDATE_RETRY;
        }
 
-       _unlock_rx_hashtbl(bond);
+       _unlock_rx_hashtbl_bh(bond);
 }
 
 /* mark all clients using src_ip to be updated */
-static void rlb_req_update_subnet_clients(struct bonding *bond, u32 src_ip)
+static void rlb_req_update_subnet_clients(struct bonding *bond, __be32 src_ip)
 {
        struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
        struct rlb_client_info *client_info;
@@ -589,9 +593,7 @@ static void rlb_req_update_subnet_clients(struct bonding *bond, u32 src_ip)
                client_info = &(bond_info->rx_hashtbl[hash_index]);
 
                if (!client_info->slave) {
-                       printk(KERN_ERR DRV_NAME
-                              ": %s: Error: found a client with no channel in "
-                              "the client's hash table\n",
+                       pr_err("%s: Error: found a client with no channel in the client's hash table\n",
                               bond->dev->name);
                        continue;
                }
@@ -600,9 +602,9 @@ static void rlb_req_update_subnet_clients(struct bonding *bond, u32 src_ip)
                 * unicast mac address.
                 */
                if ((client_info->ip_src == src_ip) &&
-                   memcmp(client_info->slave->dev->dev_addr,
-                          bond->dev->dev_addr, ETH_ALEN) &&
-                   memcmp(client_info->mac_dst, mac_bcast, ETH_ALEN)) {
+                   compare_ether_addr_64bits(client_info->slave->dev->dev_addr,
+                          bond->dev->dev_addr) &&
+                   compare_ether_addr_64bits(client_info->mac_dst, mac_bcast)) {
                        client_info->ntt = 1;
                        bond_info->rx_ntt = 1;
                }
@@ -615,21 +617,21 @@ static void rlb_req_update_subnet_clients(struct bonding *bond, u32 src_ip)
 static struct slave *rlb_choose_channel(struct sk_buff *skb, struct bonding *bond)
 {
        struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
-       struct arp_pkt *arp = (struct arp_pkt *)skb->nh.raw;
+       struct arp_pkt *arp = arp_pkt(skb);
        struct slave *assigned_slave;
        struct rlb_client_info *client_info;
        u32 hash_index = 0;
 
        _lock_rx_hashtbl(bond);
 
-       hash_index = _simple_hash((u8 *)&arp->ip_dst, sizeof(arp->ip_src));
+       hash_index = _simple_hash((u8 *)&arp->ip_dst, sizeof(arp->ip_dst));
        client_info = &(bond_info->rx_hashtbl[hash_index]);
 
        if (client_info->assigned) {
                if ((client_info->ip_src == arp->ip_src) &&
                    (client_info->ip_dst == arp->ip_dst)) {
                        /* the entry is already assigned to this client */
-                       if (memcmp(arp->mac_dst, mac_bcast, ETH_ALEN)) {
+                       if (compare_ether_addr_64bits(arp->mac_dst, mac_bcast)) {
                                /* update mac address from arp */
                                memcpy(client_info->mac_dst, arp->mac_dst, ETH_ALEN);
                        }
@@ -664,20 +666,16 @@ static struct slave *rlb_choose_channel(struct sk_buff *skb, struct bonding *bon
                memcpy(client_info->mac_dst, arp->mac_dst, ETH_ALEN);
                client_info->slave = assigned_slave;
 
-               if (memcmp(client_info->mac_dst, mac_bcast, ETH_ALEN)) {
+               if (compare_ether_addr_64bits(client_info->mac_dst, mac_bcast)) {
                        client_info->ntt = 1;
                        bond->alb_info.rx_ntt = 1;
                } else {
                        client_info->ntt = 0;
                }
 
-               if (!list_empty(&bond->vlan_list)) {
-                       unsigned short vlan_id;
-                       int res = vlan_get_tag(skb, &vlan_id);
-                       if (!res) {
+               if (bond_vlan_used(bond)) {
+                       if (!vlan_get_tag(skb, &client_info->vlan_id))
                                client_info->tag = 1;
-                               client_info->vlan_id = vlan_id;
-                       }
                }
 
                if (!client_info->assigned) {
@@ -703,10 +701,10 @@ static struct slave *rlb_choose_channel(struct sk_buff *skb, struct bonding *bon
  */
 static struct slave *rlb_arp_xmit(struct sk_buff *skb, struct bonding *bond)
 {
-       struct arp_pkt *arp = (struct arp_pkt *)skb->nh.raw;
+       struct arp_pkt *arp = arp_pkt(skb);
        struct slave *tx_slave = NULL;
 
-       if (arp->op_code == __constant_htons(ARPOP_REPLY)) {
+       if (arp->op_code == htons(ARPOP_REPLY)) {
                /* the arp must be sent on the selected
                * rx channel
                */
@@ -714,8 +712,8 @@ static struct slave *rlb_arp_xmit(struct sk_buff *skb, struct bonding *bond)
                if (tx_slave) {
                        memcpy(arp->mac_src,tx_slave->dev->dev_addr, ETH_ALEN);
                }
-               dprintk("Server sent ARP Reply packet\n");
-       } else if (arp->op_code == __constant_htons(ARPOP_REQUEST)) {
+               pr_debug("Server sent ARP Reply packet\n");
+       } else if (arp->op_code == htons(ARPOP_REQUEST)) {
                /* Create an entry in the rx_hashtbl for this client as a
                 * place holder.
                 * When the arp reply is received the entry will be updated
@@ -723,7 +721,7 @@ static struct slave *rlb_arp_xmit(struct sk_buff *skb, struct bonding *bond)
                 */
                rlb_choose_channel(skb, bond);
 
-               /* The ARP relpy packets must be delayed so that
+               /* The ARP reply packets must be delayed so that
                 * they can cancel out the influence of the ARP request.
                 */
                bond->alb_info.rlb_update_delay_counter = RLB_UPDATE_DELAY;
@@ -734,7 +732,7 @@ static struct slave *rlb_arp_xmit(struct sk_buff *skb, struct bonding *bond)
                 * updated with their assigned mac.
                 */
                rlb_req_update_subnet_clients(bond, arp->ip_src);
-               dprintk("Server sent ARP Request packet\n");
+               pr_debug("Server sent ARP Request packet\n");
        }
 
        return tx_slave;
@@ -749,7 +747,7 @@ static void rlb_rebalance(struct bonding *bond)
        int ntt;
        u32 hash_index;
 
-       _lock_rx_hashtbl(bond);
+       _lock_rx_hashtbl_bh(bond);
 
        ntt = 0;
        hash_index = bond_info->rx_hashtbl_head;
@@ -767,7 +765,7 @@ static void rlb_rebalance(struct bonding *bond)
        if (ntt) {
                bond_info->rx_ntt = 1;
        }
-       _unlock_rx_hashtbl(bond);
+       _unlock_rx_hashtbl_bh(bond);
 }
 
 /* Caller must hold rx_hashtbl lock */
@@ -781,21 +779,15 @@ static void rlb_init_table_entry(struct rlb_client_info *entry)
 static int rlb_initialize(struct bonding *bond)
 {
        struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
-       struct packet_type *pk_type = &(BOND_ALB_INFO(bond).rlb_pkt_type);
        struct rlb_client_info  *new_hashtbl;
        int size = RLB_HASH_TABLE_SIZE * sizeof(struct rlb_client_info);
        int i;
 
-       spin_lock_init(&(bond_info->rx_hashtbl_lock));
-
        new_hashtbl = kmalloc(size, GFP_KERNEL);
-       if (!new_hashtbl) {
-               printk(KERN_ERR DRV_NAME
-                      ": %s: Error: Failed to allocate RLB hash table\n",
-                      bond->dev->name);
+       if (!new_hashtbl)
                return -1;
-       }
-       _lock_rx_hashtbl(bond);
+
+       _lock_rx_hashtbl_bh(bond);
 
        bond_info->rx_hashtbl = new_hashtbl;
 
@@ -805,15 +797,10 @@ static int rlb_initialize(struct bonding *bond)
                rlb_init_table_entry(bond_info->rx_hashtbl + i);
        }
 
-       _unlock_rx_hashtbl(bond);
-
-       /*initialize packet type*/
-       pk_type->type = __constant_htons(ETH_P_ARP);
-       pk_type->dev = bond->dev;
-       pk_type->func = rlb_arp_recv;
+       _unlock_rx_hashtbl_bh(bond);
 
        /* register to receive ARPs */
-       dev_add_pack(pk_type);
+       bond->recv_probe = rlb_arp_recv;
 
        return 0;
 }
@@ -822,15 +809,13 @@ static void rlb_deinitialize(struct bonding *bond)
 {
        struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
 
-       dev_remove_pack(&(bond_info->rlb_pkt_type));
-
-       _lock_rx_hashtbl(bond);
+       _lock_rx_hashtbl_bh(bond);
 
        kfree(bond_info->rx_hashtbl);
        bond_info->rx_hashtbl = NULL;
        bond_info->rx_hashtbl_head = RLB_NULL_INDEX;
 
-       _unlock_rx_hashtbl(bond);
+       _unlock_rx_hashtbl_bh(bond);
 }
 
 static void rlb_clear_vlan(struct bonding *bond, unsigned short vlan_id)
@@ -838,7 +823,7 @@ static void rlb_clear_vlan(struct bonding *bond, unsigned short vlan_id)
        struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
        u32 curr_index;
 
-       _lock_rx_hashtbl(bond);
+       _lock_rx_hashtbl_bh(bond);
 
        curr_index = bond_info->rx_hashtbl_head;
        while (curr_index != RLB_NULL_INDEX) {
@@ -863,7 +848,7 @@ static void rlb_clear_vlan(struct bonding *bond, unsigned short vlan_id)
                curr_index = next_index;
        }
 
-       _unlock_rx_hashtbl(bond);
+       _unlock_rx_hashtbl_bh(bond);
 }
 
 /*********************** tlb/rlb shared functions *********************/
@@ -878,7 +863,7 @@ static void alb_send_learning_packets(struct slave *slave, u8 mac_addr[])
        memset(&pkt, 0, size);
        memcpy(pkt.mac_dst, mac_addr, ETH_ALEN);
        memcpy(pkt.mac_src, mac_addr, ETH_ALEN);
-       pkt.type = __constant_htons(ETH_P_LOOP);
+       pkt.type = cpu_to_be16(ETH_P_LOOP);
 
        for (i = 0; i < MAX_LP_BURST; i++) {
                struct sk_buff *skb;
@@ -892,13 +877,13 @@ static void alb_send_learning_packets(struct slave *slave, u8 mac_addr[])
                data = skb_put(skb, size);
                memcpy(data, &pkt, size);
 
-               skb->mac.raw = data;
-               skb->nh.raw = data + ETH_HLEN;
+               skb_reset_mac_header(skb);
+               skb->network_header = skb->mac_header + ETH_HLEN;
                skb->protocol = pkt.type;
                skb->priority = TC_PRIO_CONTROL;
                skb->dev = slave->dev;
 
-               if (!list_empty(&bond->vlan_list)) {
+               if (bond_vlan_used(bond)) {
                        struct vlan_entry *vlan;
 
                        vlan = bond_next_vlan(bond,
@@ -912,8 +897,7 @@ static void alb_send_learning_packets(struct slave *slave, u8 mac_addr[])
 
                        skb = vlan_put_tag(skb, vlan->vlan_id);
                        if (!skb) {
-                               printk(KERN_ERR DRV_NAME
-                                      ": %s: Error: failed to insert VLAN tag\n",
+                               pr_err("%s: Error: failed to insert VLAN tag\n",
                                       bond->dev->name);
                                continue;
                        }
@@ -923,16 +907,12 @@ static void alb_send_learning_packets(struct slave *slave, u8 mac_addr[])
        }
 }
 
-/* hw is a boolean parameter that determines whether we should try and
- * set the hw address of the device as well as the hw address of the
- * net_device
- */
-static int alb_set_slave_mac_addr(struct slave *slave, u8 addr[], int hw)
+static int alb_set_slave_mac_addr(struct slave *slave, u8 addr[])
 {
        struct net_device *dev = slave->dev;
        struct sockaddr s_addr;
 
-       if (!hw) {
+       if (slave->bond->params.mode == BOND_MODE_TLB) {
                memcpy(dev->dev_addr, addr, dev->addr_len);
                return 0;
        }
@@ -942,29 +922,43 @@ static int alb_set_slave_mac_addr(struct slave *slave, u8 addr[], int hw)
        memcpy(s_addr.sa_data, addr, dev->addr_len);
        s_addr.sa_family = dev->type;
        if (dev_set_mac_address(dev, &s_addr)) {
-               printk(KERN_ERR DRV_NAME
-                      ": %s: Error: dev_set_mac_address of dev %s failed! ALB "
-                      "mode requires that the base driver support setting "
-                      "the hw address also when the network device's "
-                      "interface is open\n",
+               pr_err("%s: Error: dev_set_mac_address of dev %s failed!\n"
+                      "ALB mode requires that the base driver support setting the hw address also when the network device's interface is open\n",
                       dev->master->name, dev->name);
                return -EOPNOTSUPP;
        }
        return 0;
 }
 
-/* Caller must hold bond lock for write or curr_slave_lock for write*/
+/*
+ * Swap MAC addresses between two slaves.
+ *
+ * Called with RTNL held, and no other locks.
+ *
+ */
+
 static void alb_swap_mac_addr(struct bonding *bond, struct slave *slave1, struct slave *slave2)
 {
-       struct slave *disabled_slave = NULL;
        u8 tmp_mac_addr[ETH_ALEN];
-       int slaves_state_differ;
-
-       slaves_state_differ = (SLAVE_IS_OK(slave1) != SLAVE_IS_OK(slave2));
 
        memcpy(tmp_mac_addr, slave1->dev->dev_addr, ETH_ALEN);
-       alb_set_slave_mac_addr(slave1, slave2->dev->dev_addr, bond->alb_info.rlb_enabled);
-       alb_set_slave_mac_addr(slave2, tmp_mac_addr, bond->alb_info.rlb_enabled);
+       alb_set_slave_mac_addr(slave1, slave2->dev->dev_addr);
+       alb_set_slave_mac_addr(slave2, tmp_mac_addr);
+
+}
+
+/*
+ * Send learning packets after MAC address swap.
+ *
+ * Called with RTNL and no other locks
+ */
+static void alb_fasten_mac_swap(struct bonding *bond, struct slave *slave1,
+                               struct slave *slave2)
+{
+       int slaves_state_differ = (SLAVE_IS_OK(slave1) != SLAVE_IS_OK(slave2));
+       struct slave *disabled_slave = NULL;
+
+       ASSERT_RTNL();
 
        /* fasten the change in the switch */
        if (SLAVE_IS_OK(slave1)) {
@@ -1010,35 +1004,34 @@ static void alb_swap_mac_addr(struct bonding *bond, struct slave *slave1, struct
  * a slave that has @slave's permanet address as its current address.
  * We'll make sure that that slave no longer uses @slave's permanent address.
  *
- * Caller must hold bond lock
+ * Caller must hold RTNL and no other locks
  */
 static void alb_change_hw_addr_on_detach(struct bonding *bond, struct slave *slave)
 {
        int perm_curr_diff;
        int perm_bond_diff;
 
-       perm_curr_diff = memcmp(slave->perm_hwaddr,
-                               slave->dev->dev_addr,
-                               ETH_ALEN);
-       perm_bond_diff = memcmp(slave->perm_hwaddr,
-                               bond->dev->dev_addr,
-                               ETH_ALEN);
+       perm_curr_diff = compare_ether_addr_64bits(slave->perm_hwaddr,
+                                                  slave->dev->dev_addr);
+       perm_bond_diff = compare_ether_addr_64bits(slave->perm_hwaddr,
+                                                  bond->dev->dev_addr);
 
        if (perm_curr_diff && perm_bond_diff) {
                struct slave *tmp_slave;
                int i, found = 0;
 
                bond_for_each_slave(bond, tmp_slave, i) {
-                       if (!memcmp(slave->perm_hwaddr,
-                                   tmp_slave->dev->dev_addr,
-                                   ETH_ALEN)) {
+                       if (!compare_ether_addr_64bits(slave->perm_hwaddr,
+                                                      tmp_slave->dev->dev_addr)) {
                                found = 1;
                                break;
                        }
                }
 
                if (found) {
+                       /* locking: needs RTNL and nothing else */
                        alb_swap_mac_addr(bond, slave, tmp_slave);
+                       alb_fasten_mac_swap(bond, slave, tmp_slave);
                }
        }
 }
@@ -1053,7 +1046,7 @@ static void alb_change_hw_addr_on_detach(struct bonding *bond, struct slave *sla
  *
  * If the permanent hw address of @slave is @bond's hw address, we need to
  * find a different hw address to give @slave, that isn't in use by any other
- * slave in the bond. This address must be, of course, one of the premanent
+ * slave in the bond. This address must be, of course, one of the permanent
  * addresses of the other slaves.
  *
  * We go over the slave list, and for each slave there we compare its
@@ -1083,10 +1076,10 @@ static int alb_handle_addr_collision_on_attach(struct bonding *bond, struct slav
         * check uniqueness of slave's mac address against the other
         * slaves in the bond.
         */
-       if (memcmp(slave->perm_hwaddr, bond->dev->dev_addr, ETH_ALEN)) {
+       if (compare_ether_addr_64bits(slave->perm_hwaddr, bond->dev->dev_addr)) {
                bond_for_each_slave(bond, tmp_slave1, i) {
-                       if (!memcmp(tmp_slave1->dev->dev_addr, slave->dev->dev_addr,
-                                   ETH_ALEN)) {
+                       if (!compare_ether_addr_64bits(tmp_slave1->dev->dev_addr,
+                                                      slave->dev->dev_addr)) {
                                found = 1;
                                break;
                        }
@@ -1097,8 +1090,7 @@ static int alb_handle_addr_collision_on_attach(struct bonding *bond, struct slav
 
                /* Try setting slave mac to bond address and fall-through
                   to code handling that situation below... */
-               alb_set_slave_mac_addr(slave, bond->dev->dev_addr,
-                                      bond->alb_info.rlb_enabled);
+               alb_set_slave_mac_addr(slave, bond->dev->dev_addr);
        }
 
        /* The slave's address is equal to the address of the bond.
@@ -1109,9 +1101,8 @@ static int alb_handle_addr_collision_on_attach(struct bonding *bond, struct slav
        bond_for_each_slave(bond, tmp_slave1, i) {
                found = 0;
                bond_for_each_slave(bond, tmp_slave2, j) {
-                       if (!memcmp(tmp_slave1->perm_hwaddr,
-                                   tmp_slave2->dev->dev_addr,
-                                   ETH_ALEN)) {
+                       if (!compare_ether_addr_64bits(tmp_slave1->perm_hwaddr,
+                                                      tmp_slave2->dev->dev_addr)) {
                                found = 1;
                                break;
                        }
@@ -1126,9 +1117,8 @@ static int alb_handle_addr_collision_on_attach(struct bonding *bond, struct slav
                }
 
                if (!has_bond_addr) {
-                       if (!memcmp(tmp_slave1->dev->dev_addr,
-                                   bond->dev->dev_addr,
-                                   ETH_ALEN)) {
+                       if (!compare_ether_addr_64bits(tmp_slave1->dev->dev_addr,
+                                                      bond->dev->dev_addr)) {
 
                                has_bond_addr = tmp_slave1;
                        }
@@ -1136,19 +1126,14 @@ static int alb_handle_addr_collision_on_attach(struct bonding *bond, struct slav
        }
 
        if (free_mac_slave) {
-               alb_set_slave_mac_addr(slave, free_mac_slave->perm_hwaddr,
-                                      bond->alb_info.rlb_enabled);
+               alb_set_slave_mac_addr(slave, free_mac_slave->perm_hwaddr);
 
-               printk(KERN_WARNING DRV_NAME
-                      ": %s: Warning: the hw address of slave %s is in use by "
-                      "the bond; giving it the hw address of %s\n",
-                      bond->dev->name, slave->dev->name, free_mac_slave->dev->name);
+               pr_warning("%s: Warning: the hw address of slave %s is in use by the bond; giving it the hw address of %s\n",
+                          bond->dev->name, slave->dev->name,
+                          free_mac_slave->dev->name);
 
        } else if (has_bond_addr) {
-               printk(KERN_ERR DRV_NAME
-                      ": %s: Error: the hw address of slave %s is in use by the "
-                      "bond; couldn't find a slave with a free hw address to "
-                      "give it (this should not have happened)\n",
+               pr_err("%s: Error: the hw address of slave %s is in use by the bond; couldn't find a slave with a free hw address to give it (this should not have happened)\n",
                       bond->dev->name, slave->dev->name);
                return -EFAULT;
        }
@@ -1183,11 +1168,6 @@ static int alb_set_mac_address(struct bonding *bond, void *addr)
        }
 
        bond_for_each_slave(bond, slave, i) {
-               if (slave->dev->set_mac_address == NULL) {
-                       res = -EOPNOTSUPP;
-                       goto unwind;
-               }
-
                /* save net_device's current hw address */
                memcpy(tmp_addr, slave->dev->dev_addr, ETH_ALEN);
 
@@ -1196,9 +1176,8 @@ static int alb_set_mac_address(struct bonding *bond, void *addr)
                /* restore net_device's hw address */
                memcpy(slave->dev->dev_addr, tmp_addr, ETH_ALEN);
 
-               if (res) {
+               if (res)
                        goto unwind;
-               }
        }
 
        return 0;
@@ -1257,53 +1236,71 @@ void bond_alb_deinitialize(struct bonding *bond)
 
 int bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev)
 {
-       struct bonding *bond = bond_dev->priv;
+       struct bonding *bond = netdev_priv(bond_dev);
        struct ethhdr *eth_data;
        struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
        struct slave *tx_slave = NULL;
-       static const u32 ip_bcast = 0xffffffff;
+       static const __be32 ip_bcast = htonl(0xffffffff);
        int hash_size = 0;
        int do_tx_balance = 1;
        u32 hash_index = 0;
-       u8 *hash_start = NULL;
+       const u8 *hash_start = NULL;
        int res = 1;
+       struct ipv6hdr *ip6hdr;
 
-       skb->mac.raw = (unsigned char *)skb->data;
+       skb_reset_mac_header(skb);
        eth_data = eth_hdr(skb);
 
-       /* make sure that the curr_active_slave and the slaves list do
-        * not change during tx
+       /* make sure that the curr_active_slave do not change during tx
         */
-       read_lock(&bond->lock);
        read_lock(&bond->curr_slave_lock);
 
-       if (!BOND_IS_OK(bond)) {
-               goto out;
-       }
-
        switch (ntohs(skb->protocol)) {
-       case ETH_P_IP:
-               if ((memcmp(eth_data->h_dest, mac_bcast, ETH_ALEN) == 0) ||
-                   (skb->nh.iph->daddr == ip_bcast) ||
-                   (skb->nh.iph->protocol == IPPROTO_IGMP)) {
+       case ETH_P_IP: {
+               const struct iphdr *iph = ip_hdr(skb);
+
+               if (!compare_ether_addr_64bits(eth_data->h_dest, mac_bcast) ||
+                   (iph->daddr == ip_bcast) ||
+                   (iph->protocol == IPPROTO_IGMP)) {
                        do_tx_balance = 0;
                        break;
                }
-               hash_start = (char*)&(skb->nh.iph->daddr);
-               hash_size = sizeof(skb->nh.iph->daddr);
+               hash_start = (char *)&(iph->daddr);
+               hash_size = sizeof(iph->daddr);
+       }
                break;
        case ETH_P_IPV6:
-               if (memcmp(eth_data->h_dest, mac_bcast, ETH_ALEN) == 0) {
+               /* IPv6 doesn't really use broadcast mac address, but leave
+                * that here just in case.
+                */
+               if (!compare_ether_addr_64bits(eth_data->h_dest, mac_bcast)) {
                        do_tx_balance = 0;
                        break;
                }
 
-               hash_start = (char*)&(skb->nh.ipv6h->daddr);
-               hash_size = sizeof(skb->nh.ipv6h->daddr);
+               /* IPv6 uses all-nodes multicast as an equivalent to
+                * broadcasts in IPv4.
+                */
+               if (!compare_ether_addr_64bits(eth_data->h_dest, mac_v6_allmcast)) {
+                       do_tx_balance = 0;
+                       break;
+               }
+
+               /* Additianally, DAD probes should not be tx-balanced as that
+                * will lead to false positives for duplicate addresses and
+                * prevent address configuration from working.
+                */
+               ip6hdr = ipv6_hdr(skb);
+               if (ipv6_addr_any(&ip6hdr->saddr)) {
+                       do_tx_balance = 0;
+                       break;
+               }
+
+               hash_start = (char *)&(ipv6_hdr(skb)->daddr);
+               hash_size = sizeof(ipv6_hdr(skb)->daddr);
                break;
        case ETH_P_IPX:
-               if (ipx_hdr(skb)->ipx_checksum !=
-                   __constant_htons(IPX_NO_CHECKSUM)) {
+               if (ipx_hdr(skb)->ipx_checksum != IPX_NO_CHECKSUM) {
                        /* something is wrong with this packet */
                        do_tx_balance = 0;
                        break;
@@ -1353,32 +1350,31 @@ int bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev)
                res = bond_dev_queue_xmit(bond, skb, tx_slave->dev);
        } else {
                if (tx_slave) {
-                       tlb_clear_slave(bond, tx_slave, 0);
+                       _lock_tx_hashtbl(bond);
+                       __tlb_clear_slave(bond, tx_slave, 0);
+                       _unlock_tx_hashtbl(bond);
                }
        }
 
-out:
        if (res) {
                /* no suitable interface, frame not sent */
                dev_kfree_skb(skb);
        }
        read_unlock(&bond->curr_slave_lock);
-       read_unlock(&bond->lock);
-       return 0;
+
+       return NETDEV_TX_OK;
 }
 
-void bond_alb_monitor(struct bonding *bond)
+void bond_alb_monitor(struct work_struct *work)
 {
+       struct bonding *bond = container_of(work, struct bonding,
+                                           alb_work.work);
        struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
        struct slave *slave;
        int i;
 
        read_lock(&bond->lock);
 
-       if (bond->kill_timers) {
-               goto out;
-       }
-
        if (bond->slave_cnt == 0) {
                bond_info->tx_rebalance_counter = 0;
                bond_info->lp_counter = 0;
@@ -1428,16 +1424,19 @@ void bond_alb_monitor(struct bonding *bond)
 
        /* handle rlb stuff */
        if (bond_info->rlb_enabled) {
-               /* the following code changes the promiscuity of the
-                * the curr_active_slave. It needs to be locked with a
-                * write lock to protect from other code that also
-                * sets the promiscuity.
-                */
-               write_lock_bh(&bond->curr_slave_lock);
-
                if (bond_info->primary_is_promisc &&
                    (++bond_info->rlb_promisc_timeout_counter >= RLB_PROMISC_TIMEOUT)) {
 
+                       /*
+                        * dev_set_promiscuity requires rtnl and
+                        * nothing else.  Avoid race with bond_close.
+                        */
+                       read_unlock(&bond->lock);
+                       if (!rtnl_trylock()) {
+                               read_lock(&bond->lock);
+                               goto re_arm;
+                       }
+
                        bond_info->rlb_promisc_timeout_counter = 0;
 
                        /* If the primary was set to promiscuous mode
@@ -1446,9 +1445,10 @@ void bond_alb_monitor(struct bonding *bond)
                         */
                        dev_set_promiscuity(bond->curr_active_slave->dev, -1);
                        bond_info->primary_is_promisc = 0;
-               }
 
-               write_unlock_bh(&bond->curr_slave_lock);
+                       rtnl_unlock();
+                       read_lock(&bond->lock);
+               }
 
                if (bond_info->rlb_rebalance) {
                        bond_info->rlb_rebalance = 0;
@@ -1471,8 +1471,8 @@ void bond_alb_monitor(struct bonding *bond)
        }
 
 re_arm:
-       mod_timer(&(bond_info->alb_timer), jiffies + alb_delta_in_ticks);
-out:
+       queue_delayed_work(bond->wq, &bond->alb_work, alb_delta_in_ticks);
+
        read_unlock(&bond->lock);
 }
 
@@ -1483,8 +1483,7 @@ int bond_alb_init_slave(struct bonding *bond, struct slave *slave)
 {
        int res;
 
-       res = alb_set_slave_mac_addr(slave, slave->perm_hwaddr,
-                                    bond->alb_info.rlb_enabled);
+       res = alb_set_slave_mac_addr(slave, slave->perm_hwaddr);
        if (res) {
                return res;
        }
@@ -1492,11 +1491,11 @@ int bond_alb_init_slave(struct bonding *bond, struct slave *slave)
        /* caller must hold the bond lock for write since the mac addresses
         * are compared and may be swapped.
         */
-       write_lock_bh(&bond->lock);
+       read_lock(&bond->lock);
 
        res = alb_handle_addr_collision_on_attach(bond, slave);
 
-       write_unlock_bh(&bond->lock);
+       read_unlock(&bond->lock);
 
        if (res) {
                return res;
@@ -1514,7 +1513,12 @@ int bond_alb_init_slave(struct bonding *bond, struct slave *slave)
        return 0;
 }
 
-/* Caller must hold bond lock for write */
+/*
+ * Remove slave from tlb and rlb hash tables, and fix up MAC addresses
+ * if necessary.
+ *
+ * Caller must hold RTNL and no other locks
+ */
 void bond_alb_deinit_slave(struct bonding *bond, struct slave *slave)
 {
        if (bond->slave_cnt > 1) {
@@ -1561,9 +1565,18 @@ void bond_alb_handle_link_change(struct bonding *bond, struct slave *slave, char
  * Set the bond->curr_active_slave to @new_slave and handle
  * mac address swapping and promiscuity changes as needed.
  *
- * Caller must hold bond curr_slave_lock for write (or bond lock for write)
+ * If new_slave is NULL, caller must hold curr_slave_lock or
+ * bond->lock for write.
+ *
+ * If new_slave is not NULL, caller must hold RTNL, bond->lock for
+ * read and curr_slave_lock for write.  Processing here may sleep, so
+ * no other locks may be held.
  */
 void bond_alb_handle_active_change(struct bonding *bond, struct slave *new_slave)
+       __releases(&bond->curr_slave_lock)
+       __releases(&bond->lock)
+       __acquires(&bond->lock)
+       __acquires(&bond->curr_slave_lock)
 {
        struct slave *swap_slave;
        int i;
@@ -1592,30 +1605,57 @@ void bond_alb_handle_active_change(struct bonding *bond, struct slave *new_slave
                struct slave *tmp_slave;
                /* find slave that is holding the bond's mac address */
                bond_for_each_slave(bond, tmp_slave, i) {
-                       if (!memcmp(tmp_slave->dev->dev_addr,
-                                   bond->dev->dev_addr, ETH_ALEN)) {
+                       if (!compare_ether_addr_64bits(tmp_slave->dev->dev_addr,
+                                                      bond->dev->dev_addr)) {
                                swap_slave = tmp_slave;
                                break;
                        }
                }
        }
 
+       /*
+        * Arrange for swap_slave and new_slave to temporarily be
+        * ignored so we can mess with their MAC addresses without
+        * fear of interference from transmit activity.
+        */
+       if (swap_slave) {
+               tlb_clear_slave(bond, swap_slave, 1);
+       }
+       tlb_clear_slave(bond, new_slave, 1);
+
+       write_unlock_bh(&bond->curr_slave_lock);
+       read_unlock(&bond->lock);
+
+       ASSERT_RTNL();
+
        /* curr_active_slave must be set before calling alb_swap_mac_addr */
        if (swap_slave) {
                /* swap mac address */
                alb_swap_mac_addr(bond, swap_slave, new_slave);
        } else {
                /* set the new_slave to the bond mac address */
-               alb_set_slave_mac_addr(new_slave, bond->dev->dev_addr,
-                                      bond->alb_info.rlb_enabled);
-               /* fasten bond mac on new current slave */
+               alb_set_slave_mac_addr(new_slave, bond->dev->dev_addr);
+       }
+
+       if (swap_slave) {
+               alb_fasten_mac_swap(bond, swap_slave, new_slave);
+               read_lock(&bond->lock);
+       } else {
+               read_lock(&bond->lock);
                alb_send_learning_packets(new_slave, bond->dev->dev_addr);
        }
+
+       write_lock_bh(&bond->curr_slave_lock);
 }
 
+/*
+ * Called with RTNL
+ */
 int bond_alb_set_mac_address(struct net_device *bond_dev, void *addr)
+       __acquires(&bond->lock)
+       __releases(&bond->lock)
 {
-       struct bonding *bond = bond_dev->priv;
+       struct bonding *bond = netdev_priv(bond_dev);
        struct sockaddr *sa = addr;
        struct slave *slave, *swap_slave;
        int res;
@@ -1643,7 +1683,8 @@ int bond_alb_set_mac_address(struct net_device *bond_dev, void *addr)
        swap_slave = NULL;
 
        bond_for_each_slave(bond, slave, i) {
-               if (!memcmp(slave->dev->dev_addr, bond_dev->dev_addr, ETH_ALEN)) {
+               if (!compare_ether_addr_64bits(slave->dev->dev_addr,
+                                              bond_dev->dev_addr)) {
                        swap_slave = slave;
                        break;
                }
@@ -1651,15 +1692,17 @@ int bond_alb_set_mac_address(struct net_device *bond_dev, void *addr)
 
        if (swap_slave) {
                alb_swap_mac_addr(bond, swap_slave, bond->curr_active_slave);
+               alb_fasten_mac_swap(bond, swap_slave, bond->curr_active_slave);
        } else {
-               alb_set_slave_mac_addr(bond->curr_active_slave, bond_dev->dev_addr,
-                                      bond->alb_info.rlb_enabled);
+               alb_set_slave_mac_addr(bond->curr_active_slave, bond_dev->dev_addr);
 
+               read_lock(&bond->lock);
                alb_send_learning_packets(bond->curr_active_slave, bond_dev->dev_addr);
                if (bond->alb_info.rlb_enabled) {
                        /* inform clients mac address has changed */
                        rlb_req_update_slave_clients(bond, bond->curr_active_slave);
                }
+               read_unlock(&bond->lock);
        }
 
        return 0;