net: spread __net_init, __net_exit
[safe/jmp/linux-2.6] / drivers / net / bonding / bond_main.c
index 2c96b93..99a0ff3 100644 (file)
@@ -31,6 +31,8 @@
  *
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/types.h>
 #include <linux/ctype.h>
 #include <linux/inet.h>
 #include <linux/bitops.h>
+#include <linux/io.h>
 #include <asm/system.h>
-#include <asm/io.h>
 #include <asm/dma.h>
-#include <asm/uaccess.h>
+#include <linux/uaccess.h>
 #include <linux/errno.h>
 #include <linux/netdevice.h>
 #include <linux/inetdevice.h>
@@ -75,6 +77,7 @@
 #include <linux/jiffies.h>
 #include <net/route.h>
 #include <net/net_namespace.h>
+#include <net/netns/generic.h>
 #include "bonding.h"
 #include "bond_3ad.h"
 #include "bond_alb.h"
@@ -89,19 +92,20 @@ static int max_bonds        = BOND_DEFAULT_MAX_BONDS;
 static int num_grat_arp = 1;
 static int num_unsol_na = 1;
 static int miimon      = BOND_LINK_MON_INTERV;
-static int updelay     = 0;
-static int downdelay   = 0;
+static int updelay;
+static int downdelay;
 static int use_carrier = 1;
-static char *mode      = NULL;
-static char *primary   = NULL;
-static char *lacp_rate = NULL;
-static char *ad_select  = NULL;
-static char *xmit_hash_policy = NULL;
+static char *mode;
+static char *primary;
+static char *primary_reselect;
+static char *lacp_rate;
+static char *ad_select;
+static char *xmit_hash_policy;
 static int arp_interval = BOND_LINK_ARP_INTERV;
-static char *arp_ip_target[BOND_MAX_ARP_TARGETS] = { NULL, };
-static char *arp_validate = NULL;
-static char *fail_over_mac = NULL;
-struct bond_params bonding_defaults;
+static char *arp_ip_target[BOND_MAX_ARP_TARGETS];
+static char *arp_validate;
+static char *fail_over_mac;
+static struct bond_params bonding_defaults;
 
 module_param(max_bonds, int, 0);
 MODULE_PARM_DESC(max_bonds, "Max number of bonded devices");
@@ -126,6 +130,14 @@ MODULE_PARM_DESC(mode, "Mode of operation : 0 for balance-rr, "
                       "6 for balance-alb");
 module_param(primary, charp, 0);
 MODULE_PARM_DESC(primary, "Primary network device to use");
+module_param(primary_reselect, charp, 0);
+MODULE_PARM_DESC(primary_reselect, "Reselect primary slave "
+                                  "once it comes up; "
+                                  "0 for always (default), "
+                                  "1 for only if speed of primary is "
+                                  "better, "
+                                  "2 for only on active slave "
+                                  "failure");
 module_param(lacp_rate, charp, 0);
 MODULE_PARM_DESC(lacp_rate, "LACPDU tx rate to request from 802.3ad partner "
                            "(slow/fast)");
@@ -148,17 +160,13 @@ MODULE_PARM_DESC(fail_over_mac, "For active-backup, do not set all slaves to the
 static const char * const version =
        DRV_DESCRIPTION ": v" DRV_VERSION " (" DRV_RELDATE ")\n";
 
-LIST_HEAD(bond_dev_list);
-
-#ifdef CONFIG_PROC_FS
-static struct proc_dir_entry *bond_proc_dir = NULL;
-#endif
+int bond_net_id __read_mostly;
 
-static __be32 arp_target[BOND_MAX_ARP_TARGETS] = { 0, } ;
-static int arp_ip_count        = 0;
+static __be32 arp_target[BOND_MAX_ARP_TARGETS];
+static int arp_ip_count;
 static int bond_mode   = BOND_MODE_ROUNDROBIN;
-static int xmit_hashtype= BOND_XMIT_POLICY_LAYER2;
-static int lacp_fast   = 0;
+static int xmit_hashtype = BOND_XMIT_POLICY_LAYER2;
+static int lacp_fast;
 
 
 const struct bond_parm_tbl bond_lacp_tbl[] = {
@@ -200,6 +208,13 @@ const struct bond_parm_tbl fail_over_mac_tbl[] = {
 {      NULL,                   -1},
 };
 
+const struct bond_parm_tbl pri_reselect_tbl[] = {
+{      "always",               BOND_PRI_RESELECT_ALWAYS},
+{      "better",               BOND_PRI_RESELECT_BETTER},
+{      "failure",              BOND_PRI_RESELECT_FAILURE},
+{      NULL,                   -1},
+};
+
 struct bond_parm_tbl ad_select_tbl[] = {
 {      "stable",       BOND_AD_STABLE},
 {      "bandwidth",    BOND_AD_BANDWIDTH},
@@ -210,7 +225,8 @@ struct bond_parm_tbl ad_select_tbl[] = {
 /*-------------------------- Forward declarations ---------------------------*/
 
 static void bond_send_gratuitous_arp(struct bonding *bond);
-static void bond_deinit(struct net_device *bond_dev);
+static int bond_init(struct net_device *bond_dev);
+static void bond_uninit(struct net_device *bond_dev);
 
 /*---------------------------- General routines -----------------------------*/
 
@@ -221,7 +237,7 @@ static const char *bond_mode_name(int mode)
                [BOND_MODE_ACTIVEBACKUP] = "fault-tolerance (active-backup)",
                [BOND_MODE_XOR] = "load balancing (xor)",
                [BOND_MODE_BROADCAST] = "fault-tolerance (broadcast)",
-               [BOND_MODE_8023AD]= "IEEE 802.3ad Dynamic link aggregation",
+               [BOND_MODE_8023AD] = "IEEE 802.3ad Dynamic link aggregation",
                [BOND_MODE_TLB] = "transmit load balancing",
                [BOND_MODE_ALB] = "adaptive load balancing",
        };
@@ -246,12 +262,11 @@ static int bond_add_vlan(struct bonding *bond, unsigned short vlan_id)
        struct vlan_entry *vlan;
 
        pr_debug("bond: %s, vlan id %d\n",
-               (bond ? bond->dev->name: "None"), vlan_id);
+                (bond ? bond->dev->name : "None"), vlan_id);
 
        vlan = kzalloc(sizeof(struct vlan_entry), GFP_KERNEL);
-       if (!vlan) {
+       if (!vlan)
                return -ENOMEM;
-       }
 
        INIT_LIST_HEAD(&vlan->vlan_list);
        vlan->vlan_id = vlan_id;
@@ -290,8 +305,8 @@ static int bond_del_vlan(struct bonding *bond, unsigned short vlan_id)
                        if (bond_is_lb(bond))
                                bond_alb_clear_vlan(bond, vlan_id);
 
-                       pr_debug("removed VLAN ID %d from bond %s\n", vlan_id,
-                               bond->dev->name);
+                       pr_debug("removed VLAN ID %d from bond %s\n",
+                                vlan_id, bond->dev->name);
 
                        kfree(vlan);
 
@@ -310,8 +325,8 @@ static int bond_del_vlan(struct bonding *bond, unsigned short vlan_id)
                }
        }
 
-       pr_debug("couldn't find VLAN ID %d in bond %s\n", vlan_id,
-               bond->dev->name);
+       pr_debug("couldn't find VLAN ID %d in bond %s\n",
+                vlan_id, bond->dev->name);
 
 out:
        write_unlock_bh(&bond->lock);
@@ -335,7 +350,7 @@ static int bond_has_challenged_slaves(struct bonding *bond)
        bond_for_each_slave(bond, slave, i) {
                if (slave->dev->features & NETIF_F_VLAN_CHALLENGED) {
                        pr_debug("found VLAN challenged slave - %s\n",
-                               slave->dev->name);
+                                slave->dev->name);
                        return 1;
                }
        }
@@ -351,16 +366,15 @@ static int bond_has_challenged_slaves(struct bonding *bond)
  *
  * Returns %NULL if list is empty, bond->next_vlan if @curr is %NULL,
  * or @curr->next otherwise (even if it is @curr itself again).
- * 
+ *
  * Caller must hold bond->lock
  */
 struct vlan_entry *bond_next_vlan(struct bonding *bond, struct vlan_entry *curr)
 {
        struct vlan_entry *next, *last;
 
-       if (list_empty(&bond->vlan_list)) {
+       if (list_empty(&bond->vlan_list))
                return NULL;
-       }
 
        if (!curr) {
                next = list_entry(bond->vlan_list.next,
@@ -382,11 +396,11 @@ struct vlan_entry *bond_next_vlan(struct bonding *bond, struct vlan_entry *curr)
 
 /**
  * bond_dev_queue_xmit - Prepare skb for xmit.
- * 
+ *
  * @bond: bond device that got this skb for tx.
  * @skb: hw accel VLAN tagged skb to transmit
  * @slave_dev: slave that is supposed to xmit this skbuff
- * 
+ *
  * When the bond gets an skb to transmit that is
  * already hardware accelerated VLAN tagged, and it
  * needs to relay this skb to a slave that is not
@@ -394,7 +408,8 @@ struct vlan_entry *bond_next_vlan(struct bonding *bond, struct vlan_entry *curr)
  * i.e. strip the hwaccel tag and re-insert it as part
  * of the payload.
  */
-int bond_dev_queue_xmit(struct bonding *bond, struct sk_buff *skb, struct net_device *slave_dev)
+int bond_dev_queue_xmit(struct bonding *bond, struct sk_buff *skb,
+                       struct net_device *slave_dev)
 {
        unsigned short uninitialized_var(vlan_id);
 
@@ -428,7 +443,7 @@ int bond_dev_queue_xmit(struct bonding *bond, struct sk_buff *skb, struct net_de
  * b. The operation is protected by the RTNL semaphore in the 8021q code,
  * c. Holding a lock with BH disabled while directly calling a base driver
  *    entry point is generally a BAD idea.
- * 
+ *
  * The design of synchronization/protection for this operation in the 8021q
  * module is good for one or more VLAN devices over a single physical device
  * and cannot be extended for a teaming solution like bonding, so there is a
@@ -443,7 +458,8 @@ int bond_dev_queue_xmit(struct bonding *bond, struct sk_buff *skb, struct net_de
  * @bond_dev: bonding net device that got called
  * @grp: vlan group being registered
  */
-static void bond_vlan_rx_register(struct net_device *bond_dev, struct vlan_group *grp)
+static void bond_vlan_rx_register(struct net_device *bond_dev,
+                                 struct vlan_group *grp)
 {
        struct bonding *bond = netdev_priv(bond_dev);
        struct slave *slave;
@@ -485,8 +501,7 @@ static void bond_vlan_rx_add_vid(struct net_device *bond_dev, uint16_t vid)
 
        res = bond_add_vlan(bond, vid);
        if (res) {
-               printk(KERN_ERR DRV_NAME
-                      ": %s: Error: Failed to add vlan id %d\n",
+               pr_err("%s: Error: Failed to add vlan id %d\n",
                       bond_dev->name, vid);
        }
 }
@@ -520,8 +535,7 @@ static void bond_vlan_rx_kill_vid(struct net_device *bond_dev, uint16_t vid)
 
        res = bond_del_vlan(bond, vid);
        if (res) {
-               printk(KERN_ERR DRV_NAME
-                      ": %s: Error: Failed to remove vlan id %d\n",
+               pr_err("%s: Error: Failed to remove vlan id %d\n",
                       bond_dev->name, vid);
        }
 }
@@ -551,7 +565,8 @@ out:
        write_unlock_bh(&bond->lock);
 }
 
-static void bond_del_vlans_from_slave(struct bonding *bond, struct net_device *slave_dev)
+static void bond_del_vlans_from_slave(struct bonding *bond,
+                                     struct net_device *slave_dev)
 {
        const struct net_device_ops *slave_ops = slave_dev->netdev_ops;
        struct vlan_entry *vlan;
@@ -673,7 +688,7 @@ static int bond_update_speed_duplex(struct slave *slave)
  * if <dev> supports MII link status reporting, check its link status.
  *
  * We either do MII/ETHTOOL ioctls, or check netif_carrier_ok(),
- * depening upon the setting of the use_carrier parameter.
+ * depending upon the setting of the use_carrier parameter.
  *
  * Return either BMSR_LSTATUS, meaning that the link is up (or we
  * can't tell and just pretend it is), or 0, meaning that the link is
@@ -685,16 +700,32 @@ static int bond_update_speed_duplex(struct slave *slave)
  * It'd be nice if there was a good way to tell if a driver supports
  * netif_carrier, but there really isn't.
  */
-static int bond_check_dev_link(struct bonding *bond, struct net_device *slave_dev, int reporting)
+static int bond_check_dev_link(struct bonding *bond,
+                              struct net_device *slave_dev, int reporting)
 {
        const struct net_device_ops *slave_ops = slave_dev->netdev_ops;
-       static int (* ioctl)(struct net_device *, struct ifreq *, int);
+       int (*ioctl)(struct net_device *, struct ifreq *, int);
        struct ifreq ifr;
        struct mii_ioctl_data *mii;
 
+       if (!reporting && !netif_running(slave_dev))
+               return 0;
+
        if (bond->params.use_carrier)
                return netif_carrier_ok(slave_dev) ? BMSR_LSTATUS : 0;
 
+       /* Try to get link status using Ethtool first. */
+       if (slave_dev->ethtool_ops) {
+               if (slave_dev->ethtool_ops->get_link) {
+                       u32 link;
+
+                       link = slave_dev->ethtool_ops->get_link(slave_dev);
+
+                       return link ? BMSR_LSTATUS : 0;
+               }
+       }
+
+       /* Ethtool can't be used, fallback to MII ioctls. */
        ioctl = slave_ops->ndo_do_ioctl;
        if (ioctl) {
                /* TODO: set pointer to correct ioctl on a per team member */
@@ -714,23 +745,8 @@ static int bond_check_dev_link(struct bonding *bond, struct net_device *slave_de
                mii = if_mii(&ifr);
                if (IOCTL(slave_dev, &ifr, SIOCGMIIPHY) == 0) {
                        mii->reg_num = MII_BMSR;
-                       if (IOCTL(slave_dev, &ifr, SIOCGMIIREG) == 0) {
-                               return (mii->val_out & BMSR_LSTATUS);
-                       }
-               }
-       }
-
-       /*
-        * Some drivers cache ETHTOOL_GLINK for a period of time so we only
-        * attempt to get link status from it if the above MII ioctls fail.
-        */
-       if (slave_dev->ethtool_ops) {
-               if (slave_dev->ethtool_ops->get_link) {
-                       u32 link;
-
-                       link = slave_dev->ethtool_ops->get_link(slave_dev);
-
-                       return link ? BMSR_LSTATUS : 0;
+                       if (IOCTL(slave_dev, &ifr, SIOCGMIIREG) == 0)
+                               return mii->val_out & BMSR_LSTATUS;
                }
        }
 
@@ -740,7 +756,7 @@ static int bond_check_dev_link(struct bonding *bond, struct net_device *slave_de
         * cannot report link status).  If not reporting, pretend
         * we're ok.
         */
-       return (reporting ? -1 : BMSR_LSTATUS);
+       return reporting ? -1 : BMSR_LSTATUS;
 }
 
 /*----------------------------- Multicast list ------------------------------*/
@@ -748,7 +764,8 @@ static int bond_check_dev_link(struct bonding *bond, struct net_device *slave_de
 /*
  * Returns 0 if dmi1 and dmi2 are the same, non-0 otherwise
  */
-static inline int bond_is_dmi_same(struct dev_mc_list *dmi1, struct dev_mc_list *dmi2)
+static inline int bond_is_dmi_same(const struct dev_mc_list *dmi1,
+                                  const struct dev_mc_list *dmi2)
 {
        return memcmp(dmi1->dmi_addr, dmi2->dmi_addr, dmi1->dmi_addrlen) == 0 &&
                        dmi1->dmi_addrlen == dmi2->dmi_addrlen;
@@ -757,14 +774,14 @@ static inline int bond_is_dmi_same(struct dev_mc_list *dmi1, struct dev_mc_list
 /*
  * returns dmi entry if found, NULL otherwise
  */
-static struct dev_mc_list *bond_mc_list_find_dmi(struct dev_mc_list *dmi, struct dev_mc_list *mc_list)
+static struct dev_mc_list *bond_mc_list_find_dmi(struct dev_mc_list *dmi,
+                                                struct dev_mc_list *mc_list)
 {
        struct dev_mc_list *idmi;
 
        for (idmi = mc_list; idmi; idmi = idmi->next) {
-               if (bond_is_dmi_same(dmi, idmi)) {
+               if (bond_is_dmi_same(dmi, idmi))
                        return idmi;
-               }
        }
 
        return NULL;
@@ -826,15 +843,14 @@ static void bond_mc_add(struct bonding *bond, void *addr, int alen)
 {
        if (USES_PRIMARY(bond->params.mode)) {
                /* write lock already acquired */
-               if (bond->curr_active_slave) {
+               if (bond->curr_active_slave)
                        dev_mc_add(bond->curr_active_slave->dev, addr, alen, 0);
-               }
        } else {
                struct slave *slave;
                int i;
-               bond_for_each_slave(bond, slave, i) {
+
+               bond_for_each_slave(bond, slave, i)
                        dev_mc_add(slave->dev, addr, alen, 0);
-               }
        }
 }
 
@@ -846,9 +862,9 @@ static void bond_mc_delete(struct bonding *bond, void *addr, int alen)
 {
        if (USES_PRIMARY(bond->params.mode)) {
                /* write lock already acquired */
-               if (bond->curr_active_slave) {
-                       dev_mc_delete(bond->curr_active_slave->dev, addr, alen, 0);
-               }
+               if (bond->curr_active_slave)
+                       dev_mc_delete(bond->curr_active_slave->dev, addr,
+                                     alen, 0);
        } else {
                struct slave *slave;
                int i;
@@ -872,9 +888,8 @@ static void bond_resend_igmp_join_requests(struct bonding *bond)
        rcu_read_lock();
        in_dev = __in_dev_get_rcu(bond->dev);
        if (in_dev) {
-               for (im = in_dev->mc_list; im; im = im->next) {
+               for (im = in_dev->mc_list; im; im = im->next)
                        ip_mc_rejoin_group(im);
-               }
        }
 
        rcu_read_unlock();
@@ -893,7 +908,8 @@ static void bond_mc_list_destroy(struct bonding *bond)
                kfree(dmi);
                dmi = bond->mc_list;
        }
-        bond->mc_list = NULL;
+
+       bond->mc_list = NULL;
 }
 
 /*
@@ -926,14 +942,14 @@ static int bond_mc_list_copy(struct dev_mc_list *mc_list, struct bonding *bond,
 /*
  * flush all members of flush->mc_list from device dev->mc_list
  */
-static void bond_mc_list_flush(struct net_device *bond_dev, struct net_device *slave_dev)
+static void bond_mc_list_flush(struct net_device *bond_dev,
+                              struct net_device *slave_dev)
 {
        struct bonding *bond = netdev_priv(bond_dev);
        struct dev_mc_list *dmi;
 
-       for (dmi = bond_dev->mc_list; dmi; dmi = dmi->next) {
+       for (dmi = bond_dev->mc_list; dmi; dmi = dmi->next)
                dev_mc_delete(slave_dev, dmi->dmi_addr, dmi->dmi_addrlen, 0);
-       }
 
        if (bond->params.mode == BOND_MODE_8023AD) {
                /* del lacpdu mc addr from mc list */
@@ -950,44 +966,40 @@ static void bond_mc_list_flush(struct net_device *bond_dev, struct net_device *s
  * old active slaves (if any) according to the multicast mode, and
  * promiscuous flags unconditionally.
  */
-static void bond_mc_swap(struct bonding *bond, struct slave *new_active, struct slave *old_active)
+static void bond_mc_swap(struct bonding *bond, struct slave *new_active,
+                        struct slave *old_active)
 {
        struct dev_mc_list *dmi;
 
-       if (!USES_PRIMARY(bond->params.mode)) {
+       if (!USES_PRIMARY(bond->params.mode))
                /* nothing to do -  mc list is already up-to-date on
                 * all slaves
                 */
                return;
-       }
 
        if (old_active) {
-               if (bond->dev->flags & IFF_PROMISC) {
+               if (bond->dev->flags & IFF_PROMISC)
                        dev_set_promiscuity(old_active->dev, -1);
-               }
 
-               if (bond->dev->flags & IFF_ALLMULTI) {
+               if (bond->dev->flags & IFF_ALLMULTI)
                        dev_set_allmulti(old_active->dev, -1);
-               }
 
-               for (dmi = bond->dev->mc_list; dmi; dmi = dmi->next) {
-                       dev_mc_delete(old_active->dev, dmi->dmi_addr, dmi->dmi_addrlen, 0);
-               }
+               for (dmi = bond->dev->mc_list; dmi; dmi = dmi->next)
+                       dev_mc_delete(old_active->dev, dmi->dmi_addr,
+                                     dmi->dmi_addrlen, 0);
        }
 
        if (new_active) {
                /* FIXME: Signal errors upstream. */
-               if (bond->dev->flags & IFF_PROMISC) {
+               if (bond->dev->flags & IFF_PROMISC)
                        dev_set_promiscuity(new_active->dev, 1);
-               }
 
-               if (bond->dev->flags & IFF_ALLMULTI) {
+               if (bond->dev->flags & IFF_ALLMULTI)
                        dev_set_allmulti(new_active->dev, 1);
-               }
 
-               for (dmi = bond->dev->mc_list; dmi; dmi = dmi->next) {
-                       dev_mc_add(new_active->dev, dmi->dmi_addr, dmi->dmi_addrlen, 0);
-               }
+               for (dmi = bond->dev->mc_list; dmi; dmi = dmi->next)
+                       dev_mc_add(new_active->dev, dmi->dmi_addr,
+                                  dmi->dmi_addrlen, 0);
                bond_resend_igmp_join_requests(bond);
        }
 }
@@ -1041,8 +1053,7 @@ static void bond_do_fail_over_mac(struct bonding *bond,
 
                rv = dev_set_mac_address(new_active->dev, &saddr);
                if (rv) {
-                       printk(KERN_ERR DRV_NAME
-                              ": %s: Error %d setting MAC of slave %s\n",
+                       pr_err("%s: Error %d setting MAC of slave %s\n",
                               bond->dev->name, -rv, new_active->dev->name);
                        goto out;
                }
@@ -1055,22 +1066,39 @@ static void bond_do_fail_over_mac(struct bonding *bond,
 
                rv = dev_set_mac_address(old_active->dev, &saddr);
                if (rv)
-                       printk(KERN_ERR DRV_NAME
-                              ": %s: Error %d setting MAC of slave %s\n",
+                       pr_err("%s: Error %d setting MAC of slave %s\n",
                               bond->dev->name, -rv, new_active->dev->name);
 out:
                read_lock(&bond->lock);
                write_lock_bh(&bond->curr_slave_lock);
                break;
        default:
-               printk(KERN_ERR DRV_NAME
-                      ": %s: bond_do_fail_over_mac impossible: bad policy %d\n",
+               pr_err("%s: bond_do_fail_over_mac impossible: bad policy %d\n",
                       bond->dev->name, bond->params.fail_over_mac);
                break;
        }
 
 }
 
+static bool bond_should_change_active(struct bonding *bond)
+{
+       struct slave *prim = bond->primary_slave;
+       struct slave *curr = bond->curr_active_slave;
+
+       if (!prim || !curr || curr->link != BOND_LINK_UP)
+               return true;
+       if (bond->force_primary) {
+               bond->force_primary = false;
+               return true;
+       }
+       if (bond->params.primary_reselect == BOND_PRI_RESELECT_BETTER &&
+           (prim->speed < curr->speed ||
+            (prim->speed == curr->speed && prim->duplex <= curr->duplex)))
+               return false;
+       if (bond->params.primary_reselect == BOND_PRI_RESELECT_FAILURE)
+               return false;
+       return true;
+}
 
 /**
  * find_best_interface - select the best available slave to be the active one
@@ -1085,24 +1113,18 @@ static struct slave *bond_find_best_slave(struct bonding *bond)
        int mintime = bond->params.updelay;
        int i;
 
-       new_active = old_active = bond->curr_active_slave;
+       new_active = bond->curr_active_slave;
 
        if (!new_active) { /* there were no active slaves left */
-               if (bond->slave_cnt > 0) {  /* found one slave */
+               if (bond->slave_cnt > 0)   /* found one slave */
                        new_active = bond->first_slave;
-               } else {
+               else
                        return NULL; /* still no slave, return NULL */
-               }
        }
 
-       /* first try the primary link; if arping, a link must tx/rx traffic
-        * before it can be considered the curr_active_slave - also, we would skip
-        * slaves between the curr_active_slave and primary_slave that may be up
-        * and able to arp
-        */
        if ((bond->primary_slave) &&
-           (!bond->params.arp_interval) &&
-           (IS_UP(bond->primary_slave->dev))) {
+           bond->primary_slave->link == BOND_LINK_UP &&
+           bond_should_change_active(bond)) {
                new_active = bond->primary_slave;
        }
 
@@ -1110,15 +1132,14 @@ static struct slave *bond_find_best_slave(struct bonding *bond)
        old_active = new_active;
 
        bond_for_each_slave_from(bond, new_active, i, old_active) {
-               if (IS_UP(new_active->dev)) {
-                       if (new_active->link == BOND_LINK_UP) {
-                               return new_active;
-                       } else if (new_active->link == BOND_LINK_BACK) {
-                               /* link up, but waiting for stabilization */
-                               if (new_active->delay < mintime) {
-                                       mintime = new_active->delay;
-                                       bestslave = new_active;
-                               }
+               if (new_active->link == BOND_LINK_UP) {
+                       return new_active;
+               } else if (new_active->link == BOND_LINK_BACK &&
+                          IS_UP(new_active->dev)) {
+                       /* link up, but waiting for stabilization */
+                       if (new_active->delay < mintime) {
+                               mintime = new_active->delay;
+                               bestslave = new_active;
                        }
                }
        }
@@ -1146,44 +1167,37 @@ void bond_change_active_slave(struct bonding *bond, struct slave *new_active)
 {
        struct slave *old_active = bond->curr_active_slave;
 
-       if (old_active == new_active) {
+       if (old_active == new_active)
                return;
-       }
 
        if (new_active) {
                new_active->jiffies = jiffies;
 
                if (new_active->link == BOND_LINK_BACK) {
                        if (USES_PRIMARY(bond->params.mode)) {
-                               printk(KERN_INFO DRV_NAME
-                                      ": %s: making interface %s the new "
-                                      "active one %d ms earlier.\n",
-                                      bond->dev->name, new_active->dev->name,
-                                      (bond->params.updelay - new_active->delay) * bond->params.miimon);
+                               pr_info("%s: making interface %s the new active one %d ms earlier.\n",
+                                       bond->dev->name, new_active->dev->name,
+                                       (bond->params.updelay - new_active->delay) * bond->params.miimon);
                        }
 
                        new_active->delay = 0;
                        new_active->link = BOND_LINK_UP;
 
-                       if (bond->params.mode == BOND_MODE_8023AD) {
+                       if (bond->params.mode == BOND_MODE_8023AD)
                                bond_3ad_handle_link_change(new_active, BOND_LINK_UP);
-                       }
 
                        if (bond_is_lb(bond))
                                bond_alb_handle_link_change(bond, new_active, BOND_LINK_UP);
                } else {
                        if (USES_PRIMARY(bond->params.mode)) {
-                               printk(KERN_INFO DRV_NAME
-                                      ": %s: making interface %s the new "
-                                      "active one.\n",
-                                      bond->dev->name, new_active->dev->name);
+                               pr_info("%s: making interface %s the new active one.\n",
+                                       bond->dev->name, new_active->dev->name);
                        }
                }
        }
 
-       if (USES_PRIMARY(bond->params.mode)) {
+       if (USES_PRIMARY(bond->params.mode))
                bond_mc_swap(bond, new_active, old_active);
-       }
 
        if (bond_is_lb(bond)) {
                bond_alb_handle_active_change(bond, new_active);
@@ -1196,9 +1210,8 @@ void bond_change_active_slave(struct bonding *bond, struct slave *new_active)
        }
 
        if (bond->params.mode == BOND_MODE_ACTIVEBACKUP) {
-               if (old_active) {
+               if (old_active)
                        bond_set_slave_inactive_flags(old_active);
-               }
 
                if (new_active) {
                        bond_set_slave_active_flags(new_active);
@@ -1216,7 +1229,7 @@ void bond_change_active_slave(struct bonding *bond, struct slave *new_active)
                        write_unlock_bh(&bond->curr_slave_lock);
                        read_unlock(&bond->lock);
 
-                       netdev_bonding_change(bond->dev);
+                       netdev_bonding_change(bond->dev, NETDEV_BONDING_FAILOVER);
 
                        read_lock(&bond->lock);
                        write_lock_bh(&bond->curr_slave_lock);
@@ -1228,7 +1241,7 @@ void bond_change_active_slave(struct bonding *bond, struct slave *new_active)
  * bond_select_active_slave - select a new active slave, if needed
  * @bond: our bonding struct
  *
- * This functions shoud be called when one of the following occurs:
+ * This functions should be called when one of the following occurs:
  * - The old curr_active_slave has been released or lost its link.
  * - The primary_slave has got its link back.
  * - A slave has got its link back and there's no old curr_active_slave.
@@ -1248,13 +1261,11 @@ void bond_select_active_slave(struct bonding *bond)
                        return;
 
                if (netif_carrier_ok(bond->dev)) {
-                       printk(KERN_INFO DRV_NAME
-                              ": %s: first active interface up!\n",
-                              bond->dev->name);
+                       pr_info("%s: first active interface up!\n",
+                               bond->dev->name);
                } else {
-                       printk(KERN_INFO DRV_NAME ": %s: "
-                              "now running without any active interface !\n",
-                              bond->dev->name);
+                       pr_info("%s: now running without any active interface !\n",
+                               bond->dev->name);
                }
        }
 }
@@ -1294,13 +1305,11 @@ static void bond_attach_slave(struct bonding *bond, struct slave *new_slave)
  */
 static void bond_detach_slave(struct bonding *bond, struct slave *slave)
 {
-       if (slave->next) {
+       if (slave->next)
                slave->next->prev = slave->prev;
-       }
 
-       if (slave->prev) {
+       if (slave->prev)
                slave->prev->next = slave->next;
-       }
 
        if (bond->first_slave == slave) { /* slave is the first slave */
                if (bond->slave_cnt > 1) { /* there are more slave */
@@ -1331,7 +1340,7 @@ static int bond_sethwaddr(struct net_device *bond_dev,
        (NETIF_F_VLAN_CHALLENGED | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX | \
         NETIF_F_HW_VLAN_FILTER)
 
-/* 
+/*
  * Compute the common dev->feature set available to all slaves.  Some
  * feature bits are managed elsewhere, so preserve those feature bits
  * on the master device.
@@ -1341,6 +1350,7 @@ static int bond_compute_features(struct bonding *bond)
        struct slave *slave;
        struct net_device *bond_dev = bond->dev;
        unsigned long features = bond_dev->features;
+       unsigned long vlan_features = 0;
        unsigned short max_hard_header_len = max((u16)ETH_HLEN,
                                                bond_dev->hard_header_len);
        int i;
@@ -1353,10 +1363,14 @@ static int bond_compute_features(struct bonding *bond)
 
        features &= ~NETIF_F_ONE_FOR_ALL;
 
+       vlan_features = bond->first_slave->dev->vlan_features;
        bond_for_each_slave(bond, slave, i) {
                features = netdev_increment_features(features,
                                                     slave->dev->features,
                                                     NETIF_F_ONE_FOR_ALL);
+               vlan_features = netdev_increment_features(vlan_features,
+                                                       slave->dev->vlan_features,
+                                                       NETIF_F_ONE_FOR_ALL);
                if (slave->dev->hard_header_len > max_hard_header_len)
                        max_hard_header_len = slave->dev->hard_header_len;
        }
@@ -1364,6 +1378,7 @@ static int bond_compute_features(struct bonding *bond)
 done:
        features |= (bond_dev->features & BOND_VLAN_FEATURES);
        bond_dev->features = netdev_fix_features(features, NULL);
+       bond_dev->vlan_features = netdev_fix_features(vlan_features, NULL);
        bond_dev->hard_header_len = max_hard_header_len;
 
        return 0;
@@ -1399,16 +1414,14 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
 
        if (!bond->params.use_carrier && slave_dev->ethtool_ops == NULL &&
                slave_ops->ndo_do_ioctl == NULL) {
-               printk(KERN_WARNING DRV_NAME
-                      ": %s: Warning: no link monitoring support for %s\n",
-                      bond_dev->name, slave_dev->name);
+               pr_warning("%s: Warning: no link monitoring support for %s\n",
+                          bond_dev->name, slave_dev->name);
        }
 
        /* bond must be initialized by bond_open() before enslaving */
        if (!(bond_dev->flags & IFF_UP)) {
-               printk(KERN_WARNING DRV_NAME
-                       " %s: master_dev is not up in bond_enslave\n",
-                       bond_dev->name);
+               pr_warning("%s: master_dev is not up in bond_enslave\n",
+                          bond_dev->name);
        }
 
        /* already enslaved */
@@ -1422,19 +1435,13 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
        if (slave_dev->features & NETIF_F_VLAN_CHALLENGED) {
                pr_debug("%s: NETIF_F_VLAN_CHALLENGED\n", slave_dev->name);
                if (!list_empty(&bond->vlan_list)) {
-                       printk(KERN_ERR DRV_NAME
-                              ": %s: Error: cannot enslave VLAN "
-                              "challenged slave %s on VLAN enabled "
-                              "bond %s\n", bond_dev->name, slave_dev->name,
-                              bond_dev->name);
+                       pr_err("%s: Error: cannot enslave VLAN challenged slave %s on VLAN enabled bond %s\n",
+                              bond_dev->name, slave_dev->name, bond_dev->name);
                        return -EPERM;
                } else {
-                       printk(KERN_WARNING DRV_NAME
-                              ": %s: Warning: enslaved VLAN challenged "
-                              "slave %s. Adding VLANs will be blocked as "
-                              "long as %s is part of bond %s\n",
-                              bond_dev->name, slave_dev->name, slave_dev->name,
-                              bond_dev->name);
+                       pr_warning("%s: Warning: enslaved VLAN challenged slave %s. Adding VLANs will be blocked as long as %s is part of bond %s\n",
+                                  bond_dev->name, slave_dev->name,
+                                  slave_dev->name, bond_dev->name);
                        bond_dev->features |= NETIF_F_VLAN_CHALLENGED;
                }
        } else {
@@ -1449,13 +1456,12 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
 
        /*
         * Old ifenslave binaries are no longer supported.  These can
-        * be identified with moderate accurary by the state of the slave:
+        * be identified with moderate accuracy by the state of the slave:
         * the current ifenslave will set the interface down prior to
         * enslaving it; the old ifenslave will not.
         */
        if ((slave_dev->flags & IFF_UP)) {
-               printk(KERN_ERR DRV_NAME ": %s is up. "
-                      "This may be due to an out of date ifenslave.\n",
+               pr_err("%s is up. This may be due to an out of date ifenslave.\n",
                       slave_dev->name);
                res = -EPERM;
                goto err_undo_flags;
@@ -1469,31 +1475,36 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
         * ether type (eg ARPHRD_ETHER and ARPHRD_INFINIBAND) share the same bond
         */
        if (bond->slave_cnt == 0) {
-               if (slave_dev->type != ARPHRD_ETHER)
-                       bond_setup_by_slave(bond_dev, slave_dev);
+               if (bond_dev->type != slave_dev->type) {
+                       pr_debug("%s: change device type from %d to %d\n",
+                                bond_dev->name,
+                                bond_dev->type, slave_dev->type);
+
+                       netdev_bonding_change(bond_dev, NETDEV_BONDING_OLDTYPE);
+
+                       if (slave_dev->type != ARPHRD_ETHER)
+                               bond_setup_by_slave(bond_dev, slave_dev);
+                       else
+                               ether_setup(bond_dev);
+
+                       netdev_bonding_change(bond_dev, NETDEV_BONDING_NEWTYPE);
+               }
        } else if (bond_dev->type != slave_dev->type) {
-               printk(KERN_ERR DRV_NAME ": %s ether type (%d) is different "
-                       "from other slaves (%d), can not enslave it.\n",
-                       slave_dev->name,
-                       slave_dev->type, bond_dev->type);
-                       res = -EINVAL;
-                       goto err_undo_flags;
+               pr_err("%s ether type (%d) is different from other slaves (%d), can not enslave it.\n",
+                      slave_dev->name,
+                      slave_dev->type, bond_dev->type);
+               res = -EINVAL;
+               goto err_undo_flags;
        }
 
        if (slave_ops->ndo_set_mac_address == NULL) {
                if (bond->slave_cnt == 0) {
-                       printk(KERN_WARNING DRV_NAME
-                              ": %s: Warning: The first slave device "
-                              "specified does not support setting the MAC "
-                              "address. Setting fail_over_mac to active.",
-                              bond_dev->name);
+                       pr_warning("%s: Warning: The first slave device specified does not support setting the MAC address. Setting fail_over_mac to active.",
+                                  bond_dev->name);
                        bond->params.fail_over_mac = BOND_FOM_ACTIVE;
                } else if (bond->params.fail_over_mac != BOND_FOM_ACTIVE) {
-                       printk(KERN_ERR DRV_NAME
-                               ": %s: Error: The slave device specified "
-                               "does not support setting the MAC address, "
-                               "but fail_over_mac is not set to active.\n"
-                               , bond_dev->name);
+                       pr_err("%s: Error: The slave device specified does not support setting the MAC address, but fail_over_mac is not set to active.\n",
+                              bond_dev->name);
                        res = -EOPNOTSUPP;
                        goto err_undo_flags;
                }
@@ -1539,7 +1550,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
        /* open the slave since the application closed it */
        res = dev_open(slave_dev);
        if (res) {
-               pr_debug("Openning slave %s failed\n", slave_dev->name);
+               pr_debug("Opening slave %s failed\n", slave_dev->name);
                goto err_unset_master;
        }
 
@@ -1551,9 +1562,8 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
                 * it might fail and we do not want to have to undo everything
                 */
                res = bond_alb_init_slave(bond, new_slave);
-               if (res) {
+               if (res)
                        goto err_close;
-               }
        }
 
        /* If the mode USES_PRIMARY, then the new slave gets the
@@ -1578,9 +1588,9 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
 
                netif_addr_lock_bh(bond_dev);
                /* upload master's mc_list to new slave */
-               for (dmi = bond_dev->mc_list; dmi; dmi = dmi->next) {
-                       dev_mc_add (slave_dev, dmi->dmi_addr, dmi->dmi_addrlen, 0);
-               }
+               for (dmi = bond_dev->mc_list; dmi; dmi = dmi->next)
+                       dev_mc_add(slave_dev, dmi->dmi_addr,
+                                  dmi->dmi_addrlen, 0);
                netif_addr_unlock_bh(bond_dev);
        }
 
@@ -1621,22 +1631,12 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
                         * supported); thus, we don't need to change
                         * the messages for netif_carrier.
                         */
-                       printk(KERN_WARNING DRV_NAME
-                              ": %s: Warning: MII and ETHTOOL support not "
-                              "available for interface %s, and "
-                              "arp_interval/arp_ip_target module parameters "
-                              "not specified, thus bonding will not detect "
-                              "link failures! see bonding.txt for details.\n",
+                       pr_warning("%s: Warning: MII and ETHTOOL support not available for interface %s, and arp_interval/arp_ip_target module parameters not specified, thus bonding will not detect link failures! see bonding.txt for details.\n",
                               bond_dev->name, slave_dev->name);
                } else if (link_reporting == -1) {
                        /* unable get link status using mii/ethtool */
-                       printk(KERN_WARNING DRV_NAME
-                              ": %s: Warning: can't get link status from "
-                              "interface %s; the network driver associated "
-                              "with this interface does not support MII or "
-                              "ETHTOOL link status reporting, thus miimon "
-                              "has no effect on this interface.\n",
-                              bond_dev->name, slave_dev->name);
+                       pr_warning("%s: Warning: can't get link status from interface %s; the network driver associated with this interface does not support MII or ETHTOOL link status reporting, thus miimon has no effect on this interface.\n",
+                                  bond_dev->name, slave_dev->name);
                }
        }
 
@@ -1644,34 +1644,27 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
        if (!bond->params.miimon ||
            (bond_check_dev_link(bond, slave_dev, 0) == BMSR_LSTATUS)) {
                if (bond->params.updelay) {
-                       pr_debug("Initial state of slave_dev is "
-                               "BOND_LINK_BACK\n");
+                       pr_debug("Initial state of slave_dev is BOND_LINK_BACK\n");
                        new_slave->link  = BOND_LINK_BACK;
                        new_slave->delay = bond->params.updelay;
                } else {
-                       pr_debug("Initial state of slave_dev is "
-                               "BOND_LINK_UP\n");
+                       pr_debug("Initial state of slave_dev is BOND_LINK_UP\n");
                        new_slave->link  = BOND_LINK_UP;
                }
                new_slave->jiffies = jiffies;
        } else {
-               pr_debug("Initial state of slave_dev is "
-                       "BOND_LINK_DOWN\n");
+               pr_debug("Initial state of slave_dev is BOND_LINK_DOWN\n");
                new_slave->link  = BOND_LINK_DOWN;
        }
 
        if (bond_update_speed_duplex(new_slave) &&
            (new_slave->link != BOND_LINK_DOWN)) {
-               printk(KERN_WARNING DRV_NAME
-                      ": %s: Warning: failed to get speed and duplex from %s, "
-                      "assumed to be 100Mb/sec and Full.\n",
-                      bond_dev->name, new_slave->dev->name);
+               pr_warning("%s: Warning: failed to get speed and duplex from %s, assumed to be 100Mb/sec and Full.\n",
+                          bond_dev->name, new_slave->dev->name);
 
                if (bond->params.mode == BOND_MODE_8023AD) {
-                       printk(KERN_WARNING DRV_NAME
-                              ": %s: Warning: Operation of 802.3ad mode requires ETHTOOL "
-                              "support in base driver for proper aggregator "
-                              "selection.\n", bond_dev->name);
+                       pr_warning("%s: Warning: Operation of 802.3ad mode requires ETHTOOL support in base driver for proper aggregator selection.\n",
+                                  bond_dev->name);
                }
        }
 
@@ -1679,6 +1672,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
                /* if there is a primary slave, remember it */
                if (strcmp(bond->params.primary, new_slave->dev->name) == 0) {
                        bond->primary_slave = new_slave;
+                       bond->force_primary = true;
                }
        }
 
@@ -1714,6 +1708,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
        case BOND_MODE_ALB:
                new_slave->state = BOND_STATE_ACTIVE;
                bond_set_slave_inactive_flags(new_slave);
+               bond_select_active_slave(bond);
                break;
        default:
                pr_debug("This slave is always active in trunk mode\n");
@@ -1725,9 +1720,9 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
                 * anyway (it holds no special properties of the bond device),
                 * so we can change it without calling change_active_interface()
                 */
-               if (!bond->curr_active_slave) {
+               if (!bond->curr_active_slave)
                        bond->curr_active_slave = new_slave;
-               }
+
                break;
        } /* switch(bond_mode) */
 
@@ -1741,11 +1736,10 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
        if (res)
                goto err_close;
 
-       printk(KERN_INFO DRV_NAME
-              ": %s: enslaving %s as a%s interface with a%s link.\n",
-              bond_dev->name, slave_dev->name,
-              new_slave->state == BOND_STATE_ACTIVE ? "n active" : " backup",
-              new_slave->link != BOND_LINK_DOWN ? "n up" : " down");
+       pr_info("%s: enslaving %s as a%s interface with a%s link.\n",
+               bond_dev->name, slave_dev->name,
+               new_slave->state == BOND_STATE_ACTIVE ? "n active" : " backup",
+               new_slave->link != BOND_LINK_DOWN ? "n up" : " down");
 
        /* enslave is successful */
        return 0;
@@ -1773,7 +1767,7 @@ err_free:
 
 err_undo_flags:
        bond_dev->features = old_features;
+
        return res;
 }
 
@@ -1793,13 +1787,11 @@ int bond_release(struct net_device *bond_dev, struct net_device *slave_dev)
        struct bonding *bond = netdev_priv(bond_dev);
        struct slave *slave, *oldcurrent;
        struct sockaddr addr;
-       int mac_addr_differ;
 
        /* slave is not a slave or master is not master of this slave */
        if (!(slave_dev->flags & IFF_SLAVE) ||
            (slave_dev->master != bond_dev)) {
-               printk(KERN_ERR DRV_NAME
-                      ": %s: Error: cannot release %s.\n",
+               pr_err("%s: Error: cannot release %s.\n",
                       bond_dev->name, slave_dev->name);
                return -EINVAL;
        }
@@ -1809,25 +1801,19 @@ int bond_release(struct net_device *bond_dev, struct net_device *slave_dev)
        slave = bond_get_slave_by_dev(bond, slave_dev);
        if (!slave) {
                /* not a slave of this bond */
-               printk(KERN_INFO DRV_NAME
-                      ": %s: %s not enslaved\n",
-                      bond_dev->name, slave_dev->name);
+               pr_info("%s: %s not enslaved\n",
+                       bond_dev->name, slave_dev->name);
                write_unlock_bh(&bond->lock);
                return -EINVAL;
        }
 
        if (!bond->params.fail_over_mac) {
-               mac_addr_differ = memcmp(bond_dev->dev_addr, slave->perm_hwaddr,
-                                        ETH_ALEN);
-               if (!mac_addr_differ && (bond->slave_cnt > 1))
-                       printk(KERN_WARNING DRV_NAME
-                              ": %s: Warning: the permanent HWaddr of %s - "
-                              "%pM - is still in use by %s. "
-                              "Set the HWaddr of %s to a different address "
-                              "to avoid conflicts.\n",
-                              bond_dev->name, slave_dev->name,
-                              slave->perm_hwaddr,
-                              bond_dev->name, slave_dev->name);
+               if (!compare_ether_addr(bond_dev->dev_addr, slave->perm_hwaddr) &&
+                   bond->slave_cnt > 1)
+                       pr_warning("%s: Warning: the permanent HWaddr of %s - %pM - is still in use by %s. Set the HWaddr of %s to a different address to avoid conflicts.\n",
+                                  bond_dev->name, slave_dev->name,
+                                  slave->perm_hwaddr,
+                                  bond_dev->name, slave_dev->name);
        }
 
        /* Inform AD package of unbinding of slave. */
@@ -1838,12 +1824,10 @@ int bond_release(struct net_device *bond_dev, struct net_device *slave_dev)
                bond_3ad_unbind_slave(slave);
        }
 
-       printk(KERN_INFO DRV_NAME
-              ": %s: releasing %s interface %s\n",
-              bond_dev->name,
-              (slave->state == BOND_STATE_ACTIVE)
-              ? "active" : "backup",
-              slave_dev->name);
+       pr_info("%s: releasing %s interface %s\n",
+               bond_dev->name,
+               (slave->state == BOND_STATE_ACTIVE) ? "active" : "backup",
+               slave_dev->name);
 
        oldcurrent = bond->curr_active_slave;
 
@@ -1854,13 +1838,11 @@ int bond_release(struct net_device *bond_dev, struct net_device *slave_dev)
 
        bond_compute_features(bond);
 
-       if (bond->primary_slave == slave) {
+       if (bond->primary_slave == slave)
                bond->primary_slave = NULL;
-       }
 
-       if (oldcurrent == slave) {
+       if (oldcurrent == slave)
                bond_change_active_slave(bond, NULL);
-       }
 
        if (bond_is_lb(bond)) {
                /* Must be called only after the slave has been
@@ -1902,21 +1884,15 @@ int bond_release(struct net_device *bond_dev, struct net_device *slave_dev)
                if (list_empty(&bond->vlan_list)) {
                        bond_dev->features |= NETIF_F_VLAN_CHALLENGED;
                } else {
-                       printk(KERN_WARNING DRV_NAME
-                              ": %s: Warning: clearing HW address of %s while it "
-                              "still has VLANs.\n",
-                              bond_dev->name, bond_dev->name);
-                       printk(KERN_WARNING DRV_NAME
-                              ": %s: When re-adding slaves, make sure the bond's "
-                              "HW address matches its VLANs'.\n",
-                              bond_dev->name);
+                       pr_warning("%s: Warning: clearing HW address of %s while it still has VLANs.\n",
+                                  bond_dev->name, bond_dev->name);
+                       pr_warning("%s: When re-adding slaves, make sure the bond's HW address matches its VLANs'.\n",
+                                  bond_dev->name);
                }
        } else if ((bond_dev->features & NETIF_F_VLAN_CHALLENGED) &&
                   !bond_has_challenged_slaves(bond)) {
-               printk(KERN_INFO DRV_NAME
-                      ": %s: last VLAN challenged slave %s "
-                      "left bond %s. VLAN blocking is removed\n",
-                      bond_dev->name, slave_dev->name, bond_dev->name);
+               pr_info("%s: last VLAN challenged slave %s left bond %s. VLAN blocking is removed\n",
+                       bond_dev->name, slave_dev->name, bond_dev->name);
                bond_dev->features &= ~NETIF_F_VLAN_CHALLENGED;
        }
 
@@ -1933,14 +1909,12 @@ int bond_release(struct net_device *bond_dev, struct net_device *slave_dev)
         */
        if (!USES_PRIMARY(bond->params.mode)) {
                /* unset promiscuity level from slave */
-               if (bond_dev->flags & IFF_PROMISC) {
+               if (bond_dev->flags & IFF_PROMISC)
                        dev_set_promiscuity(slave_dev, -1);
-               }
 
                /* unset allmulti level from slave */
-               if (bond_dev->flags & IFF_ALLMULTI) {
+               if (bond_dev->flags & IFF_ALLMULTI)
                        dev_set_allmulti(slave_dev, -1);
-               }
 
                /* flush master's mc_list from slave */
                netif_addr_lock_bh(bond_dev);
@@ -1970,44 +1944,20 @@ int bond_release(struct net_device *bond_dev, struct net_device *slave_dev)
 }
 
 /*
-* Destroy a bonding device.
+* First release a slave and than destroy the bond if no more slaves are left.
 * Must be under rtnl_lock when this function is called.
 */
-void bond_destroy(struct bonding *bond)
-{
-       bond_deinit(bond->dev);
-       bond_destroy_sysfs_entry(bond);
-       unregister_netdevice(bond->dev);
-}
-
-static void bond_destructor(struct net_device *bond_dev)
-{
-       struct bonding *bond = netdev_priv(bond_dev);
-
-       if (bond->wq)
-               destroy_workqueue(bond->wq);
-
-       netif_addr_lock_bh(bond_dev);
-       bond_mc_list_destroy(bond);
-       netif_addr_unlock_bh(bond_dev);
-
-       free_netdev(bond_dev);
-}
-
-/*
-* First release a slave and than destroy the bond if no more slaves iare left.
-* Must be under rtnl_lock when this function is called.
-*/
-int  bond_release_and_destroy(struct net_device *bond_dev, struct net_device *slave_dev)
+int  bond_release_and_destroy(struct net_device *bond_dev,
+                             struct net_device *slave_dev)
 {
        struct bonding *bond = netdev_priv(bond_dev);
        int ret;
 
        ret = bond_release(bond_dev, slave_dev);
        if ((ret == 0) && (bond->slave_cnt == 0)) {
-               printk(KERN_INFO DRV_NAME ": %s: destroying bond %s.\n",
-                      bond_dev->name, bond_dev->name);
-               bond_destroy(bond);
+               pr_info("%s: destroying bond %s.\n",
+                       bond_dev->name, bond_dev->name);
+               unregister_netdevice(bond_dev);
        }
        return ret;
 }
@@ -2026,9 +1976,8 @@ static int bond_release_all(struct net_device *bond_dev)
 
        netif_carrier_off(bond_dev);
 
-       if (bond->slave_cnt == 0) {
+       if (bond->slave_cnt == 0)
                goto out;
-       }
 
        bond->current_arp_slave = NULL;
        bond->primary_slave = NULL;
@@ -2038,9 +1987,8 @@ static int bond_release_all(struct net_device *bond_dev)
                /* Inform AD package of unbinding of slave
                 * before slave is detached from the list.
                 */
-               if (bond->params.mode == BOND_MODE_8023AD) {
+               if (bond->params.mode == BOND_MODE_8023AD)
                        bond_3ad_unbind_slave(slave);
-               }
 
                slave_dev = slave->dev;
                bond_detach_slave(bond, slave);
@@ -2069,14 +2017,12 @@ static int bond_release_all(struct net_device *bond_dev)
                 */
                if (!USES_PRIMARY(bond->params.mode)) {
                        /* unset promiscuity level from slave */
-                       if (bond_dev->flags & IFF_PROMISC) {
+                       if (bond_dev->flags & IFF_PROMISC)
                                dev_set_promiscuity(slave_dev, -1);
-                       }
 
                        /* unset allmulti level from slave */
-                       if (bond_dev->flags & IFF_ALLMULTI) {
+                       if (bond_dev->flags & IFF_ALLMULTI)
                                dev_set_allmulti(slave_dev, -1);
-                       }
 
                        /* flush master's mc_list from slave */
                        netif_addr_lock_bh(bond_dev);
@@ -2111,22 +2057,16 @@ static int bond_release_all(struct net_device *bond_dev)
         */
        memset(bond_dev->dev_addr, 0, bond_dev->addr_len);
 
-       if (list_empty(&bond->vlan_list)) {
+       if (list_empty(&bond->vlan_list))
                bond_dev->features |= NETIF_F_VLAN_CHALLENGED;
-       } else {
-               printk(KERN_WARNING DRV_NAME
-                      ": %s: Warning: clearing HW address of %s while it "
-                      "still has VLANs.\n",
-                      bond_dev->name, bond_dev->name);
-               printk(KERN_WARNING DRV_NAME
-                      ": %s: When re-adding slaves, make sure the bond's "
-                      "HW address matches its VLANs'.\n",
-                      bond_dev->name);
+       else {
+               pr_warning("%s: Warning: clearing HW address of %s while it still has VLANs.\n",
+                          bond_dev->name, bond_dev->name);
+               pr_warning("%s: When re-adding slaves, make sure the bond's HW address matches its VLANs'.\n",
+                          bond_dev->name);
        }
 
-       printk(KERN_INFO DRV_NAME
-              ": %s: released all slaves\n",
-              bond_dev->name);
+       pr_info("%s: released all slaves\n", bond_dev->name);
 
 out:
        write_unlock_bh(&bond->lock);
@@ -2142,8 +2082,8 @@ out:
  *  - <slave_dev> is already active.
  *  - The link state of <slave_dev> is not BOND_LINK_UP.
  *  - <slave_dev> is not running.
- * In these cases, this fuction does nothing.
- * In the other cases, currnt_slave pointer is changed and 0 is returned.
+ * In these cases, this function does nothing.
+ * In the other cases, current_slave pointer is changed and 0 is returned.
  */
 static int bond_ioctl_change_active(struct net_device *bond_dev, struct net_device *slave_dev)
 {
@@ -2152,15 +2092,12 @@ static int bond_ioctl_change_active(struct net_device *bond_dev, struct net_devi
        struct slave *new_active = NULL;
        int res = 0;
 
-       if (!USES_PRIMARY(bond->params.mode)) {
+       if (!USES_PRIMARY(bond->params.mode))
                return -EINVAL;
-       }
 
        /* Verify that master_dev is indeed the master of slave_dev */
-       if (!(slave_dev->flags & IFF_SLAVE) ||
-           (slave_dev->master != bond_dev)) {
+       if (!(slave_dev->flags & IFF_SLAVE) || (slave_dev->master != bond_dev))
                return -EINVAL;
-       }
 
        read_lock(&bond->lock);
 
@@ -2185,9 +2122,8 @@ static int bond_ioctl_change_active(struct net_device *bond_dev, struct net_devi
                write_lock_bh(&bond->curr_slave_lock);
                bond_change_active_slave(bond, new_active);
                write_unlock_bh(&bond->curr_slave_lock);
-       } else {
+       } else
                res = -EINVAL;
-       }
 
        read_unlock(&bond->lock);
 
@@ -2212,33 +2148,24 @@ static int bond_slave_info_query(struct net_device *bond_dev, struct ifslave *in
 {
        struct bonding *bond = netdev_priv(bond_dev);
        struct slave *slave;
-       int i, found = 0;
-
-       if (info->slave_id < 0) {
-               return -ENODEV;
-       }
+       int i, res = -ENODEV;
 
        read_lock(&bond->lock);
 
        bond_for_each_slave(bond, slave, i) {
                if (i == (int)info->slave_id) {
-                       found = 1;
+                       res = 0;
+                       strcpy(info->slave_name, slave->dev->name);
+                       info->link = slave->link;
+                       info->state = slave->state;
+                       info->link_failure_count = slave->link_failure_count;
                        break;
                }
        }
 
        read_unlock(&bond->lock);
 
-       if (found) {
-               strcpy(info->slave_name, slave->dev->name);
-               info->link = slave->link;
-               info->state = slave->state;
-               info->link_failure_count = slave->link_failure_count;
-       } else {
-               return -ENODEV;
-       }
-
-       return 0;
+       return res;
 }
 
 /*-------------------------------- Monitoring -------------------------------*/
@@ -2248,6 +2175,9 @@ static int bond_miimon_inspect(struct bonding *bond)
 {
        struct slave *slave;
        int i, link_state, commit = 0;
+       bool ignore_updelay;
+
+       ignore_updelay = !bond->curr_active_slave ? true : false;
 
        bond_for_each_slave(bond, slave, i) {
                slave->new_link = BOND_LINK_NOCHANGE;
@@ -2262,16 +2192,14 @@ static int bond_miimon_inspect(struct bonding *bond)
                        slave->link = BOND_LINK_FAIL;
                        slave->delay = bond->params.downdelay;
                        if (slave->delay) {
-                               printk(KERN_INFO DRV_NAME
-                                      ": %s: link status down for %s"
-                                      "interface %s, disabling it in %d ms.\n",
-                                      bond->dev->name,
-                                      (bond->params.mode ==
-                                       BOND_MODE_ACTIVEBACKUP) ?
-                                      ((slave->state == BOND_STATE_ACTIVE) ?
-                                       "active " : "backup ") : "",
-                                      slave->dev->name,
-                                      bond->params.downdelay * bond->params.miimon);
+                               pr_info("%s: link status down for %sinterface %s, disabling it in %d ms.\n",
+                                       bond->dev->name,
+                                       (bond->params.mode ==
+                                        BOND_MODE_ACTIVEBACKUP) ?
+                                       ((slave->state == BOND_STATE_ACTIVE) ?
+                                        "active " : "backup ") : "",
+                                       slave->dev->name,
+                                       bond->params.downdelay * bond->params.miimon);
                        }
                        /*FALLTHRU*/
                case BOND_LINK_FAIL:
@@ -2281,13 +2209,11 @@ static int bond_miimon_inspect(struct bonding *bond)
                                 */
                                slave->link = BOND_LINK_UP;
                                slave->jiffies = jiffies;
-                               printk(KERN_INFO DRV_NAME
-                                      ": %s: link status up again after %d "
-                                      "ms for interface %s.\n",
-                                      bond->dev->name,
-                                      (bond->params.downdelay - slave->delay) *
-                                      bond->params.miimon,
-                                      slave->dev->name);
+                               pr_info("%s: link status up again after %d ms for interface %s.\n",
+                                       bond->dev->name,
+                                       (bond->params.downdelay - slave->delay) *
+                                       bond->params.miimon,
+                                       slave->dev->name);
                                continue;
                        }
 
@@ -2308,31 +2234,32 @@ static int bond_miimon_inspect(struct bonding *bond)
                        slave->delay = bond->params.updelay;
 
                        if (slave->delay) {
-                               printk(KERN_INFO DRV_NAME
-                                      ": %s: link status up for "
-                                      "interface %s, enabling it in %d ms.\n",
-                                      bond->dev->name, slave->dev->name,
-                                      bond->params.updelay *
-                                      bond->params.miimon);
+                               pr_info("%s: link status up for interface %s, enabling it in %d ms.\n",
+                                       bond->dev->name, slave->dev->name,
+                                       ignore_updelay ? 0 :
+                                       bond->params.updelay *
+                                       bond->params.miimon);
                        }
                        /*FALLTHRU*/
                case BOND_LINK_BACK:
                        if (!link_state) {
                                slave->link = BOND_LINK_DOWN;
-                               printk(KERN_INFO DRV_NAME
-                                      ": %s: link status down again after %d "
-                                      "ms for interface %s.\n",
-                                      bond->dev->name,
-                                      (bond->params.updelay - slave->delay) *
-                                      bond->params.miimon,
-                                      slave->dev->name);
+                               pr_info("%s: link status down again after %d ms for interface %s.\n",
+                                       bond->dev->name,
+                                       (bond->params.updelay - slave->delay) *
+                                       bond->params.miimon,
+                                       slave->dev->name);
 
                                continue;
                        }
 
+                       if (ignore_updelay)
+                               slave->delay = 0;
+
                        if (slave->delay <= 0) {
                                slave->new_link = BOND_LINK_UP;
                                commit++;
+                               ignore_updelay = false;
                                continue;
                        }
 
@@ -2369,10 +2296,8 @@ static void bond_miimon_commit(struct bonding *bond)
                                slave->state = BOND_STATE_BACKUP;
                        }
 
-                       printk(KERN_INFO DRV_NAME
-                              ": %s: link status definitely "
-                              "up for interface %s.\n",
-                              bond->dev->name, slave->dev->name);
+                       pr_info("%s: link status definitely up for interface %s.\n",
+                               bond->dev->name, slave->dev->name);
 
                        /* notify ad that the link status has changed */
                        if (bond->params.mode == BOND_MODE_8023AD)
@@ -2398,17 +2323,14 @@ static void bond_miimon_commit(struct bonding *bond)
                            bond->params.mode == BOND_MODE_8023AD)
                                bond_set_slave_inactive_flags(slave);
 
-                       printk(KERN_INFO DRV_NAME
-                              ": %s: link status definitely down for "
-                              "interface %s, disabling it\n",
-                              bond->dev->name, slave->dev->name);
+                       pr_info("%s: link status definitely down for interface %s, disabling it\n",
+                               bond->dev->name, slave->dev->name);
 
                        if (bond->params.mode == BOND_MODE_8023AD)
                                bond_3ad_handle_link_change(slave,
                                                            BOND_LINK_DOWN);
 
-                       if (bond->params.mode == BOND_MODE_TLB ||
-                           bond->params.mode == BOND_MODE_ALB)
+                       if (bond_is_lb(bond))
                                bond_alb_handle_link_change(bond, slave,
                                                            BOND_LINK_DOWN);
 
@@ -2418,8 +2340,7 @@ static void bond_miimon_commit(struct bonding *bond)
                        continue;
 
                default:
-                       printk(KERN_ERR DRV_NAME
-                              ": %s: invalid new link %d on slave %s\n",
+                       pr_err("%s: invalid new link %d on slave %s\n",
                               bond->dev->name, slave->new_link,
                               slave->dev->name);
                        slave->new_link = BOND_LINK_NOCHANGE;
@@ -2538,19 +2459,19 @@ static void bond_arp_send(struct net_device *slave_dev, int arp_op, __be32 dest_
        struct sk_buff *skb;
 
        pr_debug("arp %d on slave %s: dst %x src %x vid %d\n", arp_op,
-              slave_dev->name, dest_ip, src_ip, vlan_id);
-              
+                slave_dev->name, dest_ip, src_ip, vlan_id);
+
        skb = arp_create(arp_op, ETH_P_ARP, dest_ip, slave_dev, src_ip,
                         NULL, slave_dev->dev_addr, NULL);
 
        if (!skb) {
-               printk(KERN_ERR DRV_NAME ": ARP packet allocation failed\n");
+               pr_err("ARP packet allocation failed\n");
                return;
        }
        if (vlan_id) {
                skb = vlan_put_tag(skb, vlan_id);
                if (!skb) {
-                       printk(KERN_ERR DRV_NAME ": failed to insert VLAN tag\n");
+                       pr_err("failed to insert VLAN tag\n");
                        return;
                }
        }
@@ -2569,7 +2490,7 @@ static void bond_arp_send_all(struct bonding *bond, struct slave *slave)
 
        for (i = 0; (i < BOND_MAX_ARP_TARGETS); i++) {
                if (!targets[i])
-                       continue;
+                       break;
                pr_debug("basa: target %x\n", targets[i]);
                if (list_empty(&bond->vlan_list)) {
                        pr_debug("basa: empty vlan: arp_send\n");
@@ -2587,12 +2508,11 @@ static void bond_arp_send_all(struct bonding *bond, struct slave *slave)
                fl.fl4_dst = targets[i];
                fl.fl4_tos = RTO_ONLINK;
 
-               rv = ip_route_output_key(&init_net, &rt, &fl);
+               rv = ip_route_output_key(dev_net(bond->dev), &rt, &fl);
                if (rv) {
                        if (net_ratelimit()) {
-                               printk(KERN_WARNING DRV_NAME
-                            ": %s: no route to arp_ip_target %pI4\n",
-                                      bond->dev->name, &fl.fl4_dst);
+                               pr_warning("%s: no route to arp_ip_target %pI4\n",
+                                          bond->dev->name, &fl.fl4_dst);
                        }
                        continue;
                }
@@ -2627,10 +2547,9 @@ static void bond_arp_send_all(struct bonding *bond, struct slave *slave)
                }
 
                if (net_ratelimit()) {
-                       printk(KERN_WARNING DRV_NAME
-              ": %s: no path to arp_ip_target %pI4 via rt.dev %s\n",
-                              bond->dev->name, &fl.fl4_dst,
-                              rt->u.dst.dev ? rt->u.dst.dev->name : "NULL");
+                       pr_warning("%s: no path to arp_ip_target %pI4 via rt.dev %s\n",
+                                  bond->dev->name, &fl.fl4_dst,
+                                  rt->u.dst.dev ? rt->u.dst.dev->name : "NULL");
                }
                ip_rt_put(rt);
        }
@@ -2648,8 +2567,8 @@ static void bond_send_gratuitous_arp(struct bonding *bond)
        struct vlan_entry *vlan;
        struct net_device *vlan_dev;
 
-       pr_debug("bond_send_grat_arp: bond %s slave %s\n", bond->dev->name,
-                               slave ? slave->dev->name : "NULL");
+       pr_debug("bond_send_grat_arp: bond %s slave %s\n",
+                bond->dev->name, slave ? slave->dev->name : "NULL");
 
        if (!slave || !bond->send_grat_arp ||
            test_bit(__LINK_STATE_LINKWATCH_PENDING, &slave->dev->state))
@@ -2676,10 +2595,10 @@ static void bond_validate_arp(struct bonding *bond, struct slave *slave, __be32
        int i;
        __be32 *targets = bond->params.arp_targets;
 
-       targets = bond->params.arp_targets;
        for (i = 0; (i < BOND_MAX_ARP_TARGETS) && targets[i]; i++) {
                pr_debug("bva: sip %pI4 tip %pI4 t[%d] %pI4 bhti(tip) %d\n",
-                       &sip, &tip, i, &targets[i], bond_has_this_ip(bond, tip));
+                        &sip, &tip, i, &targets[i],
+                        bond_has_this_ip(bond, tip));
                if (sip == targets[i]) {
                        if (bond_has_this_ip(bond, tip))
                                slave->last_arp_rx = jiffies;
@@ -2696,8 +2615,16 @@ static int bond_arp_rcv(struct sk_buff *skb, struct net_device *dev, struct pack
        unsigned char *arp_ptr;
        __be32 sip, tip;
 
-       if (dev_net(dev) != &init_net)
-               goto out;
+       if (dev->priv_flags & IFF_802_1Q_VLAN) {
+               /*
+                * When using VLANS and bonding, dev and oriv_dev may be
+                * incorrect if the physical interface supports VLAN
+                * acceleration.  With this change ARP validation now
+                * works for hosts only reachable on the VLAN interface.
+                */
+               dev = vlan_dev_real_dev(dev);
+               orig_dev = dev_get_by_index_rcu(dev_net(skb->dev),skb->skb_iif);
+       }
 
        if (!(dev->priv_flags & IFF_BONDING) || !(dev->flags & IFF_MASTER))
                goto out;
@@ -2706,8 +2633,8 @@ static int bond_arp_rcv(struct sk_buff *skb, struct net_device *dev, struct pack
        read_lock(&bond->lock);
 
        pr_debug("bond_arp_rcv: bond %s skb->dev %s orig_dev %s\n",
-               bond->dev->name, skb->dev ? skb->dev->name : "NULL",
-               orig_dev ? orig_dev->name : "NULL");
+                bond->dev->name, skb->dev ? skb->dev->name : "NULL",
+                orig_dev ? orig_dev->name : "NULL");
 
        slave = bond_get_slave_by_dev(bond, orig_dev);
        if (!slave || !slave_do_arp_validate(bond, slave))
@@ -2732,9 +2659,9 @@ static int bond_arp_rcv(struct sk_buff *skb, struct net_device *dev, struct pack
        memcpy(&tip, arp_ptr, 4);
 
        pr_debug("bond_arp_rcv: %s %s/%d av %d sv %d sip %pI4 tip %pI4\n",
-               bond->dev->name, slave->dev->name, slave->state,
-               bond->params.arp_validate, slave_do_arp_validate(bond, slave),
-               &sip, &tip);
+                bond->dev->name, slave->dev->name, slave->state,
+                bond->params.arp_validate, slave_do_arp_validate(bond, slave),
+                &sip, &tip);
 
        /*
         * Backup slaves won't see the ARP reply, but do come through
@@ -2776,13 +2703,11 @@ void bond_loadbalance_arp_mon(struct work_struct *work)
 
        delta_in_ticks = msecs_to_jiffies(bond->params.arp_interval);
 
-       if (bond->kill_timers) {
+       if (bond->kill_timers)
                goto out;
-       }
 
-       if (bond->slave_cnt == 0) {
+       if (bond->slave_cnt == 0)
                goto re_arm;
-       }
 
        read_lock(&bond->curr_slave_lock);
        oldcurrent = bond->curr_active_slave;
@@ -2798,7 +2723,7 @@ void bond_loadbalance_arp_mon(struct work_struct *work)
         */
        bond_for_each_slave(bond, slave, i) {
                if (slave->link != BOND_LINK_UP) {
-                       if (time_before_eq(jiffies, slave->dev->trans_start + delta_in_ticks) &&
+                       if (time_before_eq(jiffies, dev_trans_start(slave->dev) + delta_in_ticks) &&
                            time_before_eq(jiffies, slave->dev->last_rx + delta_in_ticks)) {
 
                                slave->link  = BOND_LINK_UP;
@@ -2810,17 +2735,14 @@ void bond_loadbalance_arp_mon(struct work_struct *work)
                                 * is closed.
                                 */
                                if (!oldcurrent) {
-                                       printk(KERN_INFO DRV_NAME
-                                              ": %s: link status definitely "
-                                              "up for interface %s, ",
-                                              bond->dev->name,
-                                              slave->dev->name);
+                                       pr_info("%s: link status definitely up for interface %s, ",
+                                               bond->dev->name,
+                                               slave->dev->name);
                                        do_failover = 1;
                                } else {
-                                       printk(KERN_INFO DRV_NAME
-                                              ": %s: interface %s is now up\n",
-                                              bond->dev->name,
-                                              slave->dev->name);
+                                       pr_info("%s: interface %s is now up\n",
+                                               bond->dev->name,
+                                               slave->dev->name);
                                }
                        }
                } else {
@@ -2830,24 +2752,21 @@ void bond_loadbalance_arp_mon(struct work_struct *work)
                         * when the source ip is 0, so don't take the link down
                         * if we don't know our ip yet
                         */
-                       if (time_after_eq(jiffies, slave->dev->trans_start + 2*delta_in_ticks) ||
+                       if (time_after_eq(jiffies, dev_trans_start(slave->dev) + 2*delta_in_ticks) ||
                            (time_after_eq(jiffies, slave->dev->last_rx + 2*delta_in_ticks))) {
 
                                slave->link  = BOND_LINK_DOWN;
                                slave->state = BOND_STATE_BACKUP;
 
-                               if (slave->link_failure_count < UINT_MAX) {
+                               if (slave->link_failure_count < UINT_MAX)
                                        slave->link_failure_count++;
-                               }
 
-                               printk(KERN_INFO DRV_NAME
-                                      ": %s: interface %s is now down.\n",
-                                      bond->dev->name,
-                                      slave->dev->name);
+                               pr_info("%s: interface %s is now down.\n",
+                                       bond->dev->name,
+                                       slave->dev->name);
 
-                               if (slave == oldcurrent) {
+                               if (slave == oldcurrent)
                                        do_failover = 1;
-                               }
                        }
                }
 
@@ -2858,9 +2777,8 @@ void bond_loadbalance_arp_mon(struct work_struct *work)
                 * do - all replies will be rx'ed on same link causing slaves
                 * to be unstable during low/no traffic periods
                 */
-               if (IS_UP(slave->dev)) {
+               if (IS_UP(slave->dev))
                        bond_arp_send_all(bond, slave);
-               }
        }
 
        if (do_failover) {
@@ -2941,7 +2859,7 @@ static int bond_ab_arp_inspect(struct bonding *bond, int delta_in_ticks)
                 *    the bond has an IP address)
                 */
                if ((slave->state == BOND_STATE_ACTIVE) &&
-                   (time_after_eq(jiffies, slave->dev->trans_start +
+                   (time_after_eq(jiffies, dev_trans_start(slave->dev) +
                                    2 * delta_in_ticks) ||
                      (time_after_eq(jiffies, slave_last_rx(bond, slave)
                                     + 2 * delta_in_ticks)))) {
@@ -2950,18 +2868,6 @@ static int bond_ab_arp_inspect(struct bonding *bond, int delta_in_ticks)
                }
        }
 
-       read_lock(&bond->curr_slave_lock);
-
-       /*
-        * Trigger a commit if the primary option setting has changed.
-        */
-       if (bond->primary_slave &&
-           (bond->primary_slave != bond->curr_active_slave) &&
-           (bond->primary_slave->link == BOND_LINK_UP))
-               commit++;
-
-       read_unlock(&bond->curr_slave_lock);
-
        return commit;
 }
 
@@ -2982,90 +2888,53 @@ static void bond_ab_arp_commit(struct bonding *bond, int delta_in_ticks)
                        continue;
 
                case BOND_LINK_UP:
-                       write_lock_bh(&bond->curr_slave_lock);
-
-                       if (!bond->curr_active_slave &&
-                           time_before_eq(jiffies, slave->dev->trans_start +
-                                          delta_in_ticks)) {
+                       if ((!bond->curr_active_slave &&
+                            time_before_eq(jiffies,
+                                           dev_trans_start(slave->dev) +
+                                           delta_in_ticks)) ||
+                           bond->curr_active_slave != slave) {
                                slave->link = BOND_LINK_UP;
-                               bond_change_active_slave(bond, slave);
                                bond->current_arp_slave = NULL;
 
-                               printk(KERN_INFO DRV_NAME
-                                      ": %s: %s is up and now the "
-                                      "active interface\n",
-                                      bond->dev->name, slave->dev->name);
-
-                       } else if (bond->curr_active_slave != slave) {
-                               /* this slave has just come up but we
-                                * already have a current slave; this can
-                                * also happen if bond_enslave adds a new
-                                * slave that is up while we are searching
-                                * for a new slave
-                                */
-                               slave->link = BOND_LINK_UP;
-                               bond_set_slave_inactive_flags(slave);
-                               bond->current_arp_slave = NULL;
+                               pr_info("%s: link status definitely up for interface %s.\n",
+                                       bond->dev->name, slave->dev->name);
 
-                               printk(KERN_INFO DRV_NAME
-                                      ": %s: backup interface %s is now up\n",
-                                      bond->dev->name, slave->dev->name);
-                       }
+                               if (!bond->curr_active_slave ||
+                                   (slave == bond->primary_slave))
+                                       goto do_failover;
 
-                       write_unlock_bh(&bond->curr_slave_lock);
+                       }
 
-                       break;
+                       continue;
 
                case BOND_LINK_DOWN:
                        if (slave->link_failure_count < UINT_MAX)
                                slave->link_failure_count++;
 
                        slave->link = BOND_LINK_DOWN;
+                       bond_set_slave_inactive_flags(slave);
 
-                       if (slave == bond->curr_active_slave) {
-                               printk(KERN_INFO DRV_NAME
-                                      ": %s: link status down for active "
-                                      "interface %s, disabling it\n",
-                                      bond->dev->name, slave->dev->name);
-
-                               bond_set_slave_inactive_flags(slave);
-
-                               write_lock_bh(&bond->curr_slave_lock);
-
-                               bond_select_active_slave(bond);
-                               if (bond->curr_active_slave)
-                                       bond->curr_active_slave->jiffies =
-                                               jiffies;
-
-                               write_unlock_bh(&bond->curr_slave_lock);
+                       pr_info("%s: link status definitely down for interface %s, disabling it\n",
+                               bond->dev->name, slave->dev->name);
 
+                       if (slave == bond->curr_active_slave) {
                                bond->current_arp_slave = NULL;
-
-                       } else if (slave->state == BOND_STATE_BACKUP) {
-                               printk(KERN_INFO DRV_NAME
-                                      ": %s: backup interface %s is now down\n",
-                                      bond->dev->name, slave->dev->name);
-
-                               bond_set_slave_inactive_flags(slave);
+                               goto do_failover;
                        }
-                       break;
+
+                       continue;
 
                default:
-                       printk(KERN_ERR DRV_NAME
-                              ": %s: impossible: new_link %d on slave %s\n",
+                       pr_err("%s: impossible: new_link %d on slave %s\n",
                               bond->dev->name, slave->new_link,
                               slave->dev->name);
+                       continue;
                }
-       }
 
-       /*
-        * No race with changes to primary via sysfs, as we hold rtnl.
-        */
-       if (bond->primary_slave &&
-           (bond->primary_slave != bond->curr_active_slave) &&
-           (bond->primary_slave->link == BOND_LINK_UP)) {
+do_failover:
+               ASSERT_RTNL();
                write_lock_bh(&bond->curr_slave_lock);
-               bond_change_active_slave(bond, bond->primary_slave);
+               bond_select_active_slave(bond);
                write_unlock_bh(&bond->curr_slave_lock);
        }
 
@@ -3085,9 +2954,9 @@ static void bond_ab_arp_probe(struct bonding *bond)
        read_lock(&bond->curr_slave_lock);
 
        if (bond->current_arp_slave && bond->curr_active_slave)
-               printk("PROBE: c_arp %s && cas %s BAD\n",
-                      bond->current_arp_slave->dev->name,
-                      bond->curr_active_slave->dev->name);
+               pr_info("PROBE: c_arp %s && cas %s BAD\n",
+                       bond->current_arp_slave->dev->name,
+                       bond->curr_active_slave->dev->name);
 
        if (bond->curr_active_slave) {
                bond_arp_send_all(bond, bond->curr_active_slave);
@@ -3135,9 +3004,8 @@ static void bond_ab_arp_probe(struct bonding *bond)
 
                        bond_set_slave_inactive_flags(slave);
 
-                       printk(KERN_INFO DRV_NAME
-                              ": %s: backup interface %s is now down.\n",
-                              bond->dev->name, slave->dev->name);
+                       pr_info("%s: backup interface %s is now down.\n",
+                               bond->dev->name, slave->dev->name);
                }
        }
 }
@@ -3185,9 +3053,8 @@ void bond_activebackup_arp_mon(struct work_struct *work)
        bond_ab_arp_probe(bond);
 
 re_arm:
-       if (bond->params.arp_interval) {
+       if (bond->params.arp_interval)
                queue_delayed_work(bond->wq, &bond->arp_work, delta_in_ticks);
-       }
 out:
        read_unlock(&bond->lock);
 }
@@ -3209,14 +3076,12 @@ static void *bond_info_seq_start(struct seq_file *seq, loff_t *pos)
        read_lock(&dev_base_lock);
        read_lock(&bond->lock);
 
-       if (*pos == 0) {
+       if (*pos == 0)
                return SEQ_START_TOKEN;
-       }
 
        bond_for_each_slave(bond, slave, i) {
-               if (++off == *pos) {
+               if (++off == *pos)
                        return slave;
-               }
        }
 
        return NULL;
@@ -3228,9 +3093,8 @@ static void *bond_info_seq_next(struct seq_file *seq, void *v, loff_t *pos)
        struct slave *slave = v;
 
        ++*pos;
-       if (v == SEQ_START_TOKEN) {
+       if (v == SEQ_START_TOKEN)
                return bond->first_slave;
-       }
 
        slave = slave->next;
 
@@ -3275,11 +3139,14 @@ static void bond_info_show_master(struct seq_file *seq)
        }
 
        if (USES_PRIMARY(bond->params.mode)) {
-               seq_printf(seq, "Primary Slave: %s\n",
+               seq_printf(seq, "Primary Slave: %s",
                           (bond->primary_slave) ?
                           bond->primary_slave->dev->name : "None");
+               if (bond->primary_slave)
+                       seq_printf(seq, " (primary_reselect %s)",
+                  pri_reselect_tbl[bond->params.primary_reselect].modename);
 
-               seq_printf(seq, "Currently Active Slave: %s\n",
+               seq_printf(seq, "\nCurrently Active Slave: %s\n",
                           (curr) ? curr->dev->name : "None");
        }
 
@@ -3293,16 +3160,16 @@ static void bond_info_show_master(struct seq_file *seq)
 
 
        /* ARP information */
-       if(bond->params.arp_interval > 0) {
-               int printed=0;
+       if (bond->params.arp_interval > 0) {
+               int printed = 0;
                seq_printf(seq, "ARP Polling Interval (ms): %d\n",
                                bond->params.arp_interval);
 
                seq_printf(seq, "ARP IP target/s (n.n.n.n form):");
 
-               for(i = 0; (i < BOND_MAX_ARP_TARGETS) ;i++) {
+               for (i = 0; (i < BOND_MAX_ARP_TARGETS); i++) {
                        if (!bond->params.arp_targets[i])
-                               continue;
+                               break;
                        if (printed)
                                seq_printf(seq, ",");
                        seq_printf(seq, " %pI4", &bond->params.arp_targets[i]);
@@ -3340,7 +3207,8 @@ static void bond_info_show_master(struct seq_file *seq)
        }
 }
 
-static void bond_info_show_slave(struct seq_file *seq, const struct slave *slave)
+static void bond_info_show_slave(struct seq_file *seq,
+                                const struct slave *slave)
 {
        struct bonding *bond = seq->private;
 
@@ -3356,12 +3224,11 @@ static void bond_info_show_slave(struct seq_file *seq, const struct slave *slave
                const struct aggregator *agg
                        = SLAVE_AD_INFO(slave).port.aggregator;
 
-               if (agg) {
+               if (agg)
                        seq_printf(seq, "Aggregator ID: %d\n",
                                   agg->aggregator_identifier);
-               } else {
+               else
                        seq_puts(seq, "Aggregator ID: N/A\n");
-               }
        }
 }
 
@@ -3370,9 +3237,8 @@ static int bond_info_seq_show(struct seq_file *seq, void *v)
        if (v == SEQ_START_TOKEN) {
                seq_printf(seq, "%s\n", version);
                bond_info_show_master(seq);
-       } else {
+       } else
                bond_info_show_slave(seq, v);
-       }
 
        return 0;
 }
@@ -3409,30 +3275,30 @@ static const struct file_operations bond_info_fops = {
        .release = seq_release,
 };
 
-static int bond_create_proc_entry(struct bonding *bond)
+static void bond_create_proc_entry(struct bonding *bond)
 {
        struct net_device *bond_dev = bond->dev;
+       struct bond_net *bn = net_generic(dev_net(bond_dev), bond_net_id);
 
-       if (bond_proc_dir) {
+       if (bn->proc_dir) {
                bond->proc_entry = proc_create_data(bond_dev->name,
-                                                   S_IRUGO, bond_proc_dir,
+                                                   S_IRUGO, bn->proc_dir,
                                                    &bond_info_fops, bond);
-               if (bond->proc_entry == NULL) {
-                       printk(KERN_WARNING DRV_NAME
-                              ": Warning: Cannot create /proc/net/%s/%s\n",
-                              DRV_NAME, bond_dev->name);
-               } else {
+               if (bond->proc_entry == NULL)
+                       pr_warning("Warning: Cannot create /proc/net/%s/%s\n",
+                                  DRV_NAME, bond_dev->name);
+               else
                        memcpy(bond->proc_file_name, bond_dev->name, IFNAMSIZ);
-               }
        }
-
-       return 0;
 }
 
 static void bond_remove_proc_entry(struct bonding *bond)
 {
-       if (bond_proc_dir && bond->proc_entry) {
-               remove_proc_entry(bond->proc_file_name, bond_proc_dir);
+       struct net_device *bond_dev = bond->dev;
+       struct bond_net *bn = net_generic(dev_net(bond_dev), bond_net_id);
+
+       if (bn->proc_dir && bond->proc_entry) {
+               remove_proc_entry(bond->proc_file_name, bn->proc_dir);
                memset(bond->proc_file_name, 0, IFNAMSIZ);
                bond->proc_entry = NULL;
        }
@@ -3441,60 +3307,48 @@ static void bond_remove_proc_entry(struct bonding *bond)
 /* Create the bonding directory under /proc/net, if doesn't exist yet.
  * Caller must hold rtnl_lock.
  */
-static void bond_create_proc_dir(void)
+static void __net_init bond_create_proc_dir(struct bond_net *bn)
 {
-       int len = strlen(DRV_NAME);
-
-       for (bond_proc_dir = init_net.proc_net->subdir; bond_proc_dir;
-            bond_proc_dir = bond_proc_dir->next) {
-               if ((bond_proc_dir->namelen == len) &&
-                   !memcmp(bond_proc_dir->name, DRV_NAME, len)) {
-                       break;
-               }
-       }
-
-       if (!bond_proc_dir) {
-               bond_proc_dir = proc_mkdir(DRV_NAME, init_net.proc_net);
-               if (bond_proc_dir) {
-                       bond_proc_dir->owner = THIS_MODULE;
-               } else {
-                       printk(KERN_WARNING DRV_NAME
-                               ": Warning: cannot create /proc/net/%s\n",
-                               DRV_NAME);
-               }
+       if (!bn->proc_dir) {
+               bn->proc_dir = proc_mkdir(DRV_NAME, bn->net->proc_net);
+               if (!bn->proc_dir)
+                       pr_warning("Warning: cannot create /proc/net/%s\n",
+                                  DRV_NAME);
        }
 }
 
 /* Destroy the bonding directory under /proc/net, if empty.
  * Caller must hold rtnl_lock.
  */
-static void bond_destroy_proc_dir(void)
+static void __net_exit bond_destroy_proc_dir(struct bond_net *bn)
 {
-       struct proc_dir_entry *de;
-
-       if (!bond_proc_dir) {
-               return;
+       if (bn->proc_dir) {
+               remove_proc_entry(DRV_NAME, bn->net->proc_net);
+               bn->proc_dir = NULL;
        }
+}
 
-       /* verify that the /proc dir is empty */
-       for (de = bond_proc_dir->subdir; de; de = de->next) {
-               /* ignore . and .. */
-               if (*(de->name) != '.') {
-                       break;
-               }
-       }
+#else /* !CONFIG_PROC_FS */
 
-       if (de) {
-               if (bond_proc_dir->owner == THIS_MODULE) {
-                       bond_proc_dir->owner = NULL;
-               }
-       } else {
-               remove_proc_entry(DRV_NAME, init_net.proc_net);
-               bond_proc_dir = NULL;
-       }
+static void bond_create_proc_entry(struct bonding *bond)
+{
+}
+
+static void bond_remove_proc_entry(struct bonding *bond)
+{
 }
+
+static inline void bond_create_proc_dir(struct bond_net *bn)
+{
+}
+
+static inline void bond_destroy_proc_dir(struct bond_net *bn)
+{
+}
+
 #endif /* CONFIG_PROC_FS */
 
+
 /*-------------------------- netdev event handling --------------------------*/
 
 /*
@@ -3502,27 +3356,20 @@ static void bond_destroy_proc_dir(void)
  */
 static int bond_event_changename(struct bonding *bond)
 {
-#ifdef CONFIG_PROC_FS
        bond_remove_proc_entry(bond);
        bond_create_proc_entry(bond);
-#endif
-       down_write(&(bonding_rwsem));
-        bond_destroy_sysfs_entry(bond);
-        bond_create_sysfs_entry(bond);
-       up_write(&(bonding_rwsem));
+
        return NOTIFY_DONE;
 }
 
-static int bond_master_netdev_event(unsigned long event, struct net_device *bond_dev)
+static int bond_master_netdev_event(unsigned long event,
+                                   struct net_device *bond_dev)
 {
        struct bonding *event_bond = netdev_priv(bond_dev);
 
        switch (event) {
        case NETDEV_CHANGENAME:
                return bond_event_changename(event_bond);
-       case NETDEV_UNREGISTER:
-               bond_release_all(event_bond->dev);
-               break;
        default:
                break;
        }
@@ -3530,7 +3377,8 @@ static int bond_master_netdev_event(unsigned long event, struct net_device *bond
        return NOTIFY_DONE;
 }
 
-static int bond_slave_netdev_event(unsigned long event, struct net_device *slave_dev)
+static int bond_slave_netdev_event(unsigned long event,
+                                  struct net_device *slave_dev)
 {
        struct net_device *bond_dev = slave_dev->master;
        struct bonding *bond = netdev_priv(bond_dev);
@@ -3545,11 +3393,26 @@ static int bond_slave_netdev_event(unsigned long event, struct net_device *slave
                }
                break;
        case NETDEV_CHANGE:
-               /*
-                * TODO: is this what we get if somebody
-                * sets up a hierarchical bond, then rmmod's
-                * one of the slave bonding devices?
-                */
+               if (bond->params.mode == BOND_MODE_8023AD || bond_is_lb(bond)) {
+                       struct slave *slave;
+
+                       slave = bond_get_slave_by_dev(bond, slave_dev);
+                       if (slave) {
+                               u16 old_speed = slave->speed;
+                               u16 old_duplex = slave->duplex;
+
+                               bond_update_speed_duplex(slave);
+
+                               if (bond_is_lb(bond))
+                                       break;
+
+                               if (old_speed != slave->speed)
+                                       bond_3ad_adapter_speed_changed(slave);
+                               if (old_duplex != slave->duplex)
+                                       bond_3ad_adapter_duplex_changed(slave);
+                       }
+               }
+
                break;
        case NETDEV_DOWN:
                /*
@@ -3593,16 +3456,14 @@ static int bond_slave_netdev_event(unsigned long event, struct net_device *slave
  * locks for us to safely manipulate the slave devices (RTNL lock,
  * dev_probe_lock).
  */
-static int bond_netdev_event(struct notifier_block *this, unsigned long event, void *ptr)
+static int bond_netdev_event(struct notifier_block *this,
+                            unsigned long event, void *ptr)
 {
        struct net_device *event_dev = (struct net_device *)ptr;
 
-       if (dev_net(event_dev) != &init_net)
-               return NOTIFY_DONE;
-
        pr_debug("event_dev: %s, event: %lx\n",
-               (event_dev ? event_dev->name : "None"),
-               event);
+                event_dev ? event_dev->name : "None",
+                event);
 
        if (!(event_dev->priv_flags & IFF_BONDING))
                return NOTIFY_DONE;
@@ -3632,13 +3493,11 @@ static int bond_inetaddr_event(struct notifier_block *this, unsigned long event,
 {
        struct in_ifaddr *ifa = ptr;
        struct net_device *vlan_dev, *event_dev = ifa->ifa_dev->dev;
+       struct bond_net *bn = net_generic(dev_net(event_dev), bond_net_id);
        struct bonding *bond;
        struct vlan_entry *vlan;
 
-       if (dev_net(ifa->ifa_dev->dev) != &init_net)
-               return NOTIFY_DONE;
-
-       list_for_each_entry(bond, &bond_dev_list, bond_list) {
+       list_for_each_entry(bond, &bn->dev_list, bond_list) {
                if (bond->dev == event_dev) {
                        switch (event) {
                        case NETDEV_UP:
@@ -3728,18 +3587,17 @@ void bond_unregister_arp(struct bonding *bond)
  * Hash for the output device based upon layer 2 and layer 3 data. If
  * the packet is not IP mimic bond_xmit_hash_policy_l2()
  */
-static int bond_xmit_hash_policy_l23(struct sk_buff *skb,
-                                    struct net_device *bond_dev, int count)
+static int bond_xmit_hash_policy_l23(struct sk_buff *skb, int count)
 {
        struct ethhdr *data = (struct ethhdr *)skb->data;
        struct iphdr *iph = ip_hdr(skb);
 
        if (skb->protocol == htons(ETH_P_IP)) {
                return ((ntohl(iph->saddr ^ iph->daddr) & 0xffff) ^
-                       (data->h_dest[5] ^ bond_dev->dev_addr[5])) % count;
+                       (data->h_dest[5] ^ data->h_source[5])) % count;
        }
 
-       return (data->h_dest[5] ^ bond_dev->dev_addr[5]) % count;
+       return (data->h_dest[5] ^ data->h_source[5]) % count;
 }
 
 /*
@@ -3747,8 +3605,7 @@ static int bond_xmit_hash_policy_l23(struct sk_buff *skb,
  * the packet is a frag or not TCP or UDP, just use layer 3 data.  If it is
  * altogether not IP, mimic bond_xmit_hash_policy_l2()
  */
-static int bond_xmit_hash_policy_l34(struct sk_buff *skb,
-                                   struct net_device *bond_dev, int count)
+static int bond_xmit_hash_policy_l34(struct sk_buff *skb, int count)
 {
        struct ethhdr *data = (struct ethhdr *)skb->data;
        struct iphdr *iph = ip_hdr(skb);
@@ -3766,18 +3623,17 @@ static int bond_xmit_hash_policy_l34(struct sk_buff *skb,
 
        }
 
-       return (data->h_dest[5] ^ bond_dev->dev_addr[5]) % count;
+       return (data->h_dest[5] ^ data->h_source[5]) % count;
 }
 
 /*
  * Hash for the output device based upon layer 2 data
  */
-static int bond_xmit_hash_policy_l2(struct sk_buff *skb,
-                                  struct net_device *bond_dev, int count)
+static int bond_xmit_hash_policy_l2(struct sk_buff *skb, int count)
 {
        struct ethhdr *data = (struct ethhdr *)skb->data;
 
-       return (data->h_dest[5] ^ bond_dev->dev_addr[5]) % count;
+       return (data->h_dest[5] ^ data->h_source[5]) % count;
 }
 
 /*-------------------------- Device entry points ----------------------------*/
@@ -3942,15 +3798,14 @@ static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd
        struct mii_ioctl_data *mii = NULL;
        int res = 0;
 
-       pr_debug("bond_ioctl: master=%s, cmd=%d\n",
-               bond_dev->name, cmd);
+       pr_debug("bond_ioctl: master=%s, cmd=%d\n", bond_dev->name, cmd);
 
        switch (cmd) {
        case SIOCGMIIPHY:
                mii = if_mii(ifr);
-               if (!mii) {
+               if (!mii)
                        return -EINVAL;
-               }
+
                mii->phy_id = 0;
                /* Fall Through */
        case SIOCGMIIREG:
@@ -3959,18 +3814,18 @@ static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd
                 * instead of SIOCGMIIPHY.
                 */
                mii = if_mii(ifr);
-               if (!mii) {
+               if (!mii)
                        return -EINVAL;
-               }
+
 
                if (mii->reg_num == 1) {
                        struct bonding *bond = netdev_priv(bond_dev);
                        mii->val_out = 0;
                        read_lock(&bond->lock);
                        read_lock(&bond->curr_slave_lock);
-                       if (netif_carrier_ok(bond->dev)) {
+                       if (netif_carrier_ok(bond->dev))
                                mii->val_out = BMSR_LSTATUS;
-                       }
+
                        read_unlock(&bond->curr_slave_lock);
                        read_unlock(&bond->lock);
                }
@@ -3980,32 +3835,26 @@ static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd
        case SIOCBONDINFOQUERY:
                u_binfo = (struct ifbond __user *)ifr->ifr_data;
 
-               if (copy_from_user(&k_binfo, u_binfo, sizeof(ifbond))) {
+               if (copy_from_user(&k_binfo, u_binfo, sizeof(ifbond)))
                        return -EFAULT;
-               }
 
                res = bond_info_query(bond_dev, &k_binfo);
-               if (res == 0) {
-                       if (copy_to_user(u_binfo, &k_binfo, sizeof(ifbond))) {
-                               return -EFAULT;
-                       }
-               }
+               if (res == 0 &&
+                   copy_to_user(u_binfo, &k_binfo, sizeof(ifbond)))
+                       return -EFAULT;
 
                return res;
        case BOND_SLAVE_INFO_QUERY_OLD:
        case SIOCBONDSLAVEINFOQUERY:
                u_sinfo = (struct ifslave __user *)ifr->ifr_data;
 
-               if (copy_from_user(&k_sinfo, u_sinfo, sizeof(ifslave))) {
+               if (copy_from_user(&k_sinfo, u_sinfo, sizeof(ifslave)))
                        return -EFAULT;
-               }
 
                res = bond_slave_info_query(bond_dev, &k_sinfo);
-               if (res == 0) {
-                       if (copy_to_user(u_sinfo, &k_sinfo, sizeof(ifslave))) {
-                               return -EFAULT;
-                       }
-               }
+               if (res == 0 &&
+                   copy_to_user(u_sinfo, &k_sinfo, sizeof(ifslave)))
+                       return -EFAULT;
 
                return res;
        default:
@@ -4013,19 +3862,17 @@ static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd
                break;
        }
 
-       if (!capable(CAP_NET_ADMIN)) {
+       if (!capable(CAP_NET_ADMIN))
                return -EPERM;
-       }
 
-       down_write(&(bonding_rwsem));
-       slave_dev = dev_get_by_name(&init_net, ifr->ifr_slave);
+       slave_dev = dev_get_by_name(dev_net(bond_dev), ifr->ifr_slave);
 
-       pr_debug("slave_dev=%p: \n", slave_dev);
+       pr_debug("slave_dev=%p:\n", slave_dev);
 
-       if (!slave_dev) {
+       if (!slave_dev)
                res = -ENODEV;
-       else {
-               pr_debug("slave_dev->name=%s: \n", slave_dev->name);
+       else {
+               pr_debug("slave_dev->name=%s:\n", slave_dev->name);
                switch (cmd) {
                case BOND_ENSLAVE_OLD:
                case SIOCBONDENSLAVE:
@@ -4050,7 +3897,6 @@ static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd
                dev_put(slave_dev);
        }
 
-       up_write(&(bonding_rwsem));
        return res;
 }
 
@@ -4062,30 +3908,30 @@ static void bond_set_multicast_list(struct net_device *bond_dev)
        /*
         * Do promisc before checking multicast_mode
         */
-       if ((bond_dev->flags & IFF_PROMISC) && !(bond->flags & IFF_PROMISC)) {
+       if ((bond_dev->flags & IFF_PROMISC) && !(bond->flags & IFF_PROMISC))
                /*
                 * FIXME: Need to handle the error when one of the multi-slaves
                 * encounters error.
                 */
                bond_set_promiscuity(bond, 1);
-       }
 
-       if (!(bond_dev->flags & IFF_PROMISC) && (bond->flags & IFF_PROMISC)) {
+
+       if (!(bond_dev->flags & IFF_PROMISC) && (bond->flags & IFF_PROMISC))
                bond_set_promiscuity(bond, -1);
-       }
+
 
        /* set allmulti flag to slaves */
-       if ((bond_dev->flags & IFF_ALLMULTI) && !(bond->flags & IFF_ALLMULTI)) {
+       if ((bond_dev->flags & IFF_ALLMULTI) && !(bond->flags & IFF_ALLMULTI))
                /*
                 * FIXME: Need to handle the error when one of the multi-slaves
                 * encounters error.
                 */
                bond_set_allmulti(bond, 1);
-       }
 
-       if (!(bond_dev->flags & IFF_ALLMULTI) && (bond->flags & IFF_ALLMULTI)) {
+
+       if (!(bond_dev->flags & IFF_ALLMULTI) && (bond->flags & IFF_ALLMULTI))
                bond_set_allmulti(bond, -1);
-       }
+
 
        read_lock(&bond->lock);
 
@@ -4093,16 +3939,14 @@ static void bond_set_multicast_list(struct net_device *bond_dev)
 
        /* looking for addresses to add to slaves' mc list */
        for (dmi = bond_dev->mc_list; dmi; dmi = dmi->next) {
-               if (!bond_mc_list_find_dmi(dmi, bond->mc_list)) {
+               if (!bond_mc_list_find_dmi(dmi, bond->mc_list))
                        bond_mc_add(bond, dmi->dmi_addr, dmi->dmi_addrlen);
-               }
        }
 
        /* looking for addresses to delete from slaves' list */
        for (dmi = bond->mc_list; dmi; dmi = dmi->next) {
-               if (!bond_mc_list_find_dmi(dmi, bond_dev->mc_list)) {
+               if (!bond_mc_list_find_dmi(dmi, bond_dev->mc_list))
                        bond_mc_delete(bond, dmi->dmi_addr, dmi->dmi_addrlen);
-               }
        }
 
        /* save master's multicast list */
@@ -4121,7 +3965,7 @@ static int bond_neigh_setup(struct net_device *dev, struct neigh_parms *parms)
                const struct net_device_ops *slave_ops
                        = slave->dev->netdev_ops;
                if (slave_ops->ndo_neigh_setup)
-                       return slave_ops->ndo_neigh_setup(dev, parms);
+                       return slave_ops->ndo_neigh_setup(slave->dev, parms);
        }
        return 0;
 }
@@ -4137,7 +3981,7 @@ static int bond_change_mtu(struct net_device *bond_dev, int new_mtu)
        int i;
 
        pr_debug("bond=%p, name=%s, new_mtu=%d\n", bond,
-               (bond_dev ? bond_dev->name : "None"), new_mtu);
+                (bond_dev ? bond_dev->name : "None"), new_mtu);
 
        /* Can't hold bond->lock with bh disabled here since
         * some base drivers panic. On the other hand we can't
@@ -4155,8 +3999,10 @@ static int bond_change_mtu(struct net_device *bond_dev, int new_mtu)
         */
 
        bond_for_each_slave(bond, slave, i) {
-               pr_debug("s %p s->p %p c_m %p\n", slave,
-                       slave->prev, slave->dev->netdev_ops->ndo_change_mtu);
+               pr_debug("s %p s->p %p c_m %p\n",
+                        slave,
+                        slave->prev,
+                        slave->dev->netdev_ops->ndo_change_mtu);
 
                res = dev_set_mtu(slave->dev, new_mtu);
 
@@ -4186,8 +4032,8 @@ unwind:
 
                tmp_res = dev_set_mtu(slave->dev, bond_dev->mtu);
                if (tmp_res) {
-                       pr_debug("unwind err %d dev %s\n", tmp_res,
-                               slave->dev->name);
+                       pr_debug("unwind err %d dev %s\n",
+                                tmp_res, slave->dev->name);
                }
        }
 
@@ -4213,7 +4059,8 @@ static int bond_set_mac_address(struct net_device *bond_dev, void *addr)
                return bond_alb_set_mac_address(bond_dev, addr);
 
 
-       pr_debug("bond=%p, name=%s\n", bond, (bond_dev ? bond_dev->name : "None"));
+       pr_debug("bond=%p, name=%s\n",
+                bond, bond_dev ? bond_dev->name : "None");
 
        /*
         * If fail_over_mac is set to active, do nothing and return
@@ -4222,9 +4069,8 @@ static int bond_set_mac_address(struct net_device *bond_dev, void *addr)
        if (bond->params.fail_over_mac == BOND_FOM_ACTIVE)
                return 0;
 
-       if (!is_valid_ether_addr(sa->sa_data)) {
+       if (!is_valid_ether_addr(sa->sa_data))
                return -EADDRNOTAVAIL;
-       }
 
        /* Can't hold bond->lock with bh disabled here since
         * some base drivers panic. On the other hand we can't
@@ -4279,8 +4125,8 @@ unwind:
 
                tmp_res = dev_set_mac_address(slave->dev, &tmp_sa);
                if (tmp_res) {
-                       pr_debug("unwind err %d dev %s\n", tmp_res,
-                               slave->dev->name);
+                       pr_debug("unwind err %d dev %s\n",
+                                tmp_res, slave->dev->name);
                }
        }
 
@@ -4295,9 +4141,8 @@ static int bond_xmit_roundrobin(struct sk_buff *skb, struct net_device *bond_dev
 
        read_lock(&bond->lock);
 
-       if (!BOND_IS_OK(bond)) {
+       if (!BOND_IS_OK(bond))
                goto out;
-       }
 
        /*
         * Concurrent TX may collide on rr_tx_counter; we accept that
@@ -4307,9 +4152,8 @@ static int bond_xmit_roundrobin(struct sk_buff *skb, struct net_device *bond_dev
 
        bond_for_each_slave(bond, slave, i) {
                slave_no--;
-               if (slave_no < 0) {
+               if (slave_no < 0)
                        break;
-               }
        }
 
        start_at = slave;
@@ -4328,7 +4172,7 @@ out:
                dev_kfree_skb(skb);
        }
        read_unlock(&bond->lock);
-       return 0;
+       return NETDEV_TX_OK;
 }
 
 
@@ -4344,9 +4188,8 @@ static int bond_xmit_activebackup(struct sk_buff *skb, struct net_device *bond_d
        read_lock(&bond->lock);
        read_lock(&bond->curr_slave_lock);
 
-       if (!BOND_IS_OK(bond)) {
+       if (!BOND_IS_OK(bond))
                goto out;
-       }
 
        if (!bond->curr_active_slave)
                goto out;
@@ -4354,13 +4197,13 @@ static int bond_xmit_activebackup(struct sk_buff *skb, struct net_device *bond_d
        res = bond_dev_queue_xmit(bond, skb, bond->curr_active_slave->dev);
 
 out:
-       if (res) {
+       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;
 }
 
 /*
@@ -4378,17 +4221,15 @@ static int bond_xmit_xor(struct sk_buff *skb, struct net_device *bond_dev)
 
        read_lock(&bond->lock);
 
-       if (!BOND_IS_OK(bond)) {
+       if (!BOND_IS_OK(bond))
                goto out;
-       }
 
-       slave_no = bond->xmit_hash_policy(skb, bond_dev, bond->slave_cnt);
+       slave_no = bond->xmit_hash_policy(skb, bond->slave_cnt);
 
        bond_for_each_slave(bond, slave, i) {
                slave_no--;
-               if (slave_no < 0) {
+               if (slave_no < 0)
                        break;
-               }
        }
 
        start_at = slave;
@@ -4408,7 +4249,7 @@ out:
                dev_kfree_skb(skb);
        }
        read_unlock(&bond->lock);
-       return 0;
+       return NETDEV_TX_OK;
 }
 
 /*
@@ -4424,17 +4265,15 @@ static int bond_xmit_broadcast(struct sk_buff *skb, struct net_device *bond_dev)
 
        read_lock(&bond->lock);
 
-       if (!BOND_IS_OK(bond)) {
+       if (!BOND_IS_OK(bond))
                goto out;
-       }
 
        read_lock(&bond->curr_slave_lock);
        start_at = bond->curr_active_slave;
        read_unlock(&bond->curr_slave_lock);
 
-       if (!start_at) {
+       if (!start_at)
                goto out;
-       }
 
        bond_for_each_slave_from(bond, slave, i, start_at) {
                if (IS_UP(slave->dev) &&
@@ -4443,9 +4282,7 @@ static int bond_xmit_broadcast(struct sk_buff *skb, struct net_device *bond_dev)
                        if (tx_dev) {
                                struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC);
                                if (!skb2) {
-                                       printk(KERN_ERR DRV_NAME
-                                              ": %s: Error: bond_xmit_broadcast(): "
-                                              "skb_clone() failed\n",
+                                       pr_err("%s: Error: bond_xmit_broadcast(): skb_clone() failed\n",
                                               bond_dev->name);
                                        continue;
                                }
@@ -4460,18 +4297,17 @@ static int bond_xmit_broadcast(struct sk_buff *skb, struct net_device *bond_dev)
                }
        }
 
-       if (tx_dev) {
+       if (tx_dev)
                res = bond_dev_queue_xmit(bond, skb, tx_dev);
-       }
 
 out:
-       if (res) {
+       if (res)
                /* no suitable interface, frame not sent */
                dev_kfree_skb(skb);
-       }
+
        /* frame sent to all suitable interfaces */
        read_unlock(&bond->lock);
-       return 0;
+       return NETDEV_TX_OK;
 }
 
 /*------------------------- Device initialization ---------------------------*/
@@ -4492,7 +4328,7 @@ static void bond_set_xmit_hash_policy(struct bonding *bond)
        }
 }
 
-static int bond_start_xmit(struct sk_buff *skb, struct net_device *dev)
+static netdev_tx_t bond_start_xmit(struct sk_buff *skb, struct net_device *dev)
 {
        const struct bonding *bond = netdev_priv(dev);
 
@@ -4512,8 +4348,8 @@ static int bond_start_xmit(struct sk_buff *skb, struct net_device *dev)
                return bond_alb_xmit(skb, dev);
        default:
                /* Should never happen, mode already checked */
-               printk(KERN_ERR DRV_NAME ": %s: Error: Unknown bonding mode %d\n",
-                    dev->name, bond->params.mode);
+               pr_err("%s: Error: Unknown bonding mode %d\n",
+                      dev->name, bond->params.mode);
                WARN_ON_ONCE(1);
                dev_kfree_skb(skb);
                return NETDEV_TX_OK;
@@ -4549,10 +4385,8 @@ void bond_set_mode_ops(struct bonding *bond, int mode)
                break;
        default:
                /* Should never happen, mode already checked */
-               printk(KERN_ERR DRV_NAME
-                      ": %s: Error: Unknown bonding mode %d\n",
-                      bond_dev->name,
-                      mode);
+               pr_err("%s: Error: Unknown bonding mode %d\n",
+                      bond_dev->name, mode);
                break;
        }
 }
@@ -4576,6 +4410,8 @@ static const struct ethtool_ops bond_ethtool_ops = {
 };
 
 static const struct net_device_ops bond_netdev_ops = {
+       .ndo_init               = bond_init,
+       .ndo_uninit             = bond_uninit,
        .ndo_open               = bond_open,
        .ndo_stop               = bond_close,
        .ndo_start_xmit         = bond_start_xmit,
@@ -4590,48 +4426,34 @@ static const struct net_device_ops bond_netdev_ops = {
        .ndo_vlan_rx_kill_vid   = bond_vlan_rx_kill_vid,
 };
 
-/*
- * Does not allocate but creates a /proc entry.
- * Allowed to fail.
- */
-static int bond_init(struct net_device *bond_dev, struct bond_params *params)
+static void bond_setup(struct net_device *bond_dev)
 {
        struct bonding *bond = netdev_priv(bond_dev);
 
-       pr_debug("Begin bond_init for %s\n", bond_dev->name);
-
        /* initialize rwlocks */
        rwlock_init(&bond->lock);
        rwlock_init(&bond->curr_slave_lock);
 
-       bond->params = *params; /* copy params struct */
-
-       bond->wq = create_singlethread_workqueue(bond_dev->name);
-       if (!bond->wq)
-               return -ENOMEM;
+       bond->params = bonding_defaults;
 
        /* Initialize pointers */
-       bond->first_slave = NULL;
-       bond->curr_active_slave = NULL;
-       bond->current_arp_slave = NULL;
-       bond->primary_slave = NULL;
        bond->dev = bond_dev;
-       bond->send_grat_arp = 0;
-       bond->send_unsol_na = 0;
-       bond->setup_by_slave = 0;
        INIT_LIST_HEAD(&bond->vlan_list);
 
        /* Initialize the device entry points */
+       ether_setup(bond_dev);
        bond_dev->netdev_ops = &bond_netdev_ops;
        bond_dev->ethtool_ops = &bond_ethtool_ops;
        bond_set_mode_ops(bond, bond->params.mode);
 
-       bond_dev->destructor = bond_destructor;
+       bond_dev->destructor = free_netdev;
 
        /* Initialize the device options */
        bond_dev->tx_queue_len = 0;
        bond_dev->flags |= IFF_MASTER|IFF_MULTICAST;
        bond_dev->priv_flags |= IFF_BONDING;
+       bond_dev->priv_flags &= ~IFF_XMIT_DST_RELEASE;
+
        if (bond->params.arp_interval)
                bond_dev->priv_flags |= IFF_MASTER_ARPMON;
 
@@ -4656,12 +4478,6 @@ static int bond_init(struct net_device *bond_dev, struct bond_params *params)
                               NETIF_F_HW_VLAN_RX |
                               NETIF_F_HW_VLAN_FILTER);
 
-#ifdef CONFIG_PROC_FS
-       bond_create_proc_entry(bond);
-#endif
-       list_add_tail(&bond->bond_list, &bond_dev_list);
-
-       return 0;
 }
 
 static void bond_work_cancel_all(struct bonding *bond)
@@ -4685,41 +4501,29 @@ static void bond_work_cancel_all(struct bonding *bond)
                cancel_delayed_work(&bond->ad_work);
 }
 
-/* De-initialize device specific data.
- * Caller must hold rtnl_lock.
- */
-static void bond_deinit(struct net_device *bond_dev)
+/*
+* Destroy a bonding device.
+* Must be under rtnl_lock when this function is called.
+*/
+static void bond_uninit(struct net_device *bond_dev)
 {
        struct bonding *bond = netdev_priv(bond_dev);
 
+       /* Release the bonded slaves */
+       bond_release_all(bond_dev);
+
        list_del(&bond->bond_list);
 
        bond_work_cancel_all(bond);
 
-#ifdef CONFIG_PROC_FS
        bond_remove_proc_entry(bond);
-#endif
-}
-
-/* Unregister and free all bond devices.
- * Caller must hold rtnl_lock.
- */
-static void bond_free_all(void)
-{
-       struct bonding *bond, *nxt;
 
-       list_for_each_entry_safe(bond, nxt, &bond_dev_list, bond_list) {
-               struct net_device *bond_dev = bond->dev;
-
-               bond_work_cancel_all(bond);
-               /* Release the bonded slaves */
-               bond_release_all(bond_dev);
-               bond_destroy(bond);
-       }
+       if (bond->wq)
+               destroy_workqueue(bond->wq);
 
-#ifdef CONFIG_PROC_FS
-       bond_destroy_proc_dir();
-#endif
+       netif_addr_lock_bh(bond_dev);
+       bond_mc_list_destroy(bond);
+       netif_addr_unlock_bh(bond_dev);
 }
 
 /*------------------------- Module initialization ---------------------------*/
@@ -4759,7 +4563,7 @@ int bond_parse_parm(const char *buf, const struct bond_parm_tbl *tbl)
 
 static int bond_check_params(struct bond_params *params)
 {
-       int arp_validate_value, fail_over_mac_value;
+       int arp_validate_value, fail_over_mac_value, primary_reselect_value;
 
        /*
         * Convert string parameters.
@@ -4767,8 +4571,7 @@ static int bond_check_params(struct bond_params *params)
        if (mode) {
                bond_mode = bond_parse_parm(mode, bond_mode_tbl);
                if (bond_mode == -1) {
-                       printk(KERN_ERR DRV_NAME
-                              ": Error: Invalid bonding mode \"%s\"\n",
+                       pr_err("Error: Invalid bonding mode \"%s\"\n",
                               mode == NULL ? "NULL" : mode);
                        return -EINVAL;
                }
@@ -4777,16 +4580,14 @@ static int bond_check_params(struct bond_params *params)
        if (xmit_hash_policy) {
                if ((bond_mode != BOND_MODE_XOR) &&
                    (bond_mode != BOND_MODE_8023AD)) {
-                       printk(KERN_INFO DRV_NAME
-                              ": xor_mode param is irrelevant in mode %s\n",
+                       pr_info("xmit_hash_policy param is irrelevant in mode %s\n",
                               bond_mode_name(bond_mode));
                } else {
                        xmit_hashtype = bond_parse_parm(xmit_hash_policy,
                                                        xmit_hashtype_tbl);
                        if (xmit_hashtype == -1) {
-                               printk(KERN_ERR DRV_NAME
-                               ": Error: Invalid xmit_hash_policy \"%s\"\n",
-                               xmit_hash_policy == NULL ? "NULL" :
+                               pr_err("Error: Invalid xmit_hash_policy \"%s\"\n",
+                                      xmit_hash_policy == NULL ? "NULL" :
                                       xmit_hash_policy);
                                return -EINVAL;
                        }
@@ -4795,14 +4596,12 @@ static int bond_check_params(struct bond_params *params)
 
        if (lacp_rate) {
                if (bond_mode != BOND_MODE_8023AD) {
-                       printk(KERN_INFO DRV_NAME
-                              ": lacp_rate param is irrelevant in mode %s\n",
-                              bond_mode_name(bond_mode));
+                       pr_info("lacp_rate param is irrelevant in mode %s\n",
+                               bond_mode_name(bond_mode));
                } else {
                        lacp_fast = bond_parse_parm(lacp_rate, bond_lacp_tbl);
                        if (lacp_fast == -1) {
-                               printk(KERN_ERR DRV_NAME
-                                      ": Error: Invalid lacp rate \"%s\"\n",
+                               pr_err("Error: Invalid lacp rate \"%s\"\n",
                                       lacp_rate == NULL ? "NULL" : lacp_rate);
                                return -EINVAL;
                        }
@@ -4812,83 +4611,65 @@ static int bond_check_params(struct bond_params *params)
        if (ad_select) {
                params->ad_select = bond_parse_parm(ad_select, ad_select_tbl);
                if (params->ad_select == -1) {
-                       printk(KERN_ERR DRV_NAME
-                              ": Error: Invalid ad_select \"%s\"\n",
+                       pr_err("Error: Invalid ad_select \"%s\"\n",
                               ad_select == NULL ? "NULL" : ad_select);
                        return -EINVAL;
                }
 
                if (bond_mode != BOND_MODE_8023AD) {
-                       printk(KERN_WARNING DRV_NAME
-                              ": ad_select param only affects 802.3ad mode\n");
+                       pr_warning("ad_select param only affects 802.3ad mode\n");
                }
        } else {
                params->ad_select = BOND_AD_STABLE;
        }
 
-       if (max_bonds < 0 || max_bonds > INT_MAX) {
-               printk(KERN_WARNING DRV_NAME
-                      ": Warning: max_bonds (%d) not in range %d-%d, so it "
-                      "was reset to BOND_DEFAULT_MAX_BONDS (%d)\n",
-                      max_bonds, 0, INT_MAX, BOND_DEFAULT_MAX_BONDS);
+       if (max_bonds < 0) {
+               pr_warning("Warning: max_bonds (%d) not in range %d-%d, so it was reset to BOND_DEFAULT_MAX_BONDS (%d)\n",
+                          max_bonds, 0, INT_MAX, BOND_DEFAULT_MAX_BONDS);
                max_bonds = BOND_DEFAULT_MAX_BONDS;
        }
 
        if (miimon < 0) {
-               printk(KERN_WARNING DRV_NAME
-                      ": Warning: miimon module parameter (%d), "
-                      "not in range 0-%d, so it was reset to %d\n",
-                      miimon, INT_MAX, BOND_LINK_MON_INTERV);
+               pr_warning("Warning: miimon module parameter (%d), not in range 0-%d, so it was reset to %d\n",
+                          miimon, INT_MAX, BOND_LINK_MON_INTERV);
                miimon = BOND_LINK_MON_INTERV;
        }
 
        if (updelay < 0) {
-               printk(KERN_WARNING DRV_NAME
-                      ": Warning: updelay module parameter (%d), "
-                      "not in range 0-%d, so it was reset to 0\n",
-                      updelay, INT_MAX);
+               pr_warning("Warning: updelay module parameter (%d), not in range 0-%d, so it was reset to 0\n",
+                          updelay, INT_MAX);
                updelay = 0;
        }
 
        if (downdelay < 0) {
-               printk(KERN_WARNING DRV_NAME
-                      ": Warning: downdelay module parameter (%d), "
-                      "not in range 0-%d, so it was reset to 0\n",
-                      downdelay, INT_MAX);
+               pr_warning("Warning: downdelay module parameter (%d), not in range 0-%d, so it was reset to 0\n",
+                          downdelay, INT_MAX);
                downdelay = 0;
        }
 
        if ((use_carrier != 0) && (use_carrier != 1)) {
-               printk(KERN_WARNING DRV_NAME
-                      ": Warning: use_carrier module parameter (%d), "
-                      "not of valid value (0/1), so it was set to 1\n",
-                      use_carrier);
+               pr_warning("Warning: use_carrier module parameter (%d), not of valid value (0/1), so it was set to 1\n",
+                          use_carrier);
                use_carrier = 1;
        }
 
        if (num_grat_arp < 0 || num_grat_arp > 255) {
-               printk(KERN_WARNING DRV_NAME
-                      ": Warning: num_grat_arp (%d) not in range 0-255 so it "
-                      "was reset to 1 \n", num_grat_arp);
+               pr_warning("Warning: num_grat_arp (%d) not in range 0-255 so it was reset to 1 \n",
+                          num_grat_arp);
                num_grat_arp = 1;
        }
 
        if (num_unsol_na < 0 || num_unsol_na > 255) {
-               printk(KERN_WARNING DRV_NAME
-                      ": Warning: num_unsol_na (%d) not in range 0-255 so it "
-                      "was reset to 1 \n", num_unsol_na);
+               pr_warning("Warning: num_unsol_na (%d) not in range 0-255 so it was reset to 1 \n",
+                          num_unsol_na);
                num_unsol_na = 1;
        }
 
        /* reset values for 802.3ad */
        if (bond_mode == BOND_MODE_8023AD) {
                if (!miimon) {
-                       printk(KERN_WARNING DRV_NAME
-                              ": Warning: miimon must be specified, "
-                              "otherwise bonding will not detect link "
-                              "failure, speed and duplex which are "
-                              "essential for 802.3ad operation\n");
-                       printk(KERN_WARNING "Forcing miimon to 100msec\n");
+                       pr_warning("Warning: miimon must be specified, otherwise bonding will not detect link failure, speed and duplex which are essential for 802.3ad operation\n");
+                       pr_warning("Forcing miimon to 100msec\n");
                        miimon = 100;
                }
        }
@@ -4897,24 +4678,15 @@ static int bond_check_params(struct bond_params *params)
        if ((bond_mode == BOND_MODE_TLB) ||
            (bond_mode == BOND_MODE_ALB)) {
                if (!miimon) {
-                       printk(KERN_WARNING DRV_NAME
-                              ": Warning: miimon must be specified, "
-                              "otherwise bonding will not detect link "
-                              "failure and link speed which are essential "
-                              "for TLB/ALB load balancing\n");
-                       printk(KERN_WARNING "Forcing miimon to 100msec\n");
+                       pr_warning("Warning: miimon must be specified, otherwise bonding will not detect link failure and link speed which are essential for TLB/ALB load balancing\n");
+                       pr_warning("Forcing miimon to 100msec\n");
                        miimon = 100;
                }
        }
 
        if (bond_mode == BOND_MODE_ALB) {
-               printk(KERN_NOTICE DRV_NAME
-                      ": In ALB mode you might experience client "
-                      "disconnections upon reconnection of a link if the "
-                      "bonding module updelay parameter (%d msec) is "
-                      "incompatible with the forwarding delay time of the "
-                      "switch\n",
-                      updelay);
+               pr_notice("In ALB mode you might experience client disconnections upon reconnection of a link if the bonding module updelay parameter (%d msec) is incompatible with the forwarding delay time of the switch\n",
+                         updelay);
        }
 
        if (!miimon) {
@@ -4922,49 +4694,37 @@ static int bond_check_params(struct bond_params *params)
                        /* just warn the user the up/down delay will have
                         * no effect since miimon is zero...
                         */
-                       printk(KERN_WARNING DRV_NAME
-                              ": Warning: miimon module parameter not set "
-                              "and updelay (%d) or downdelay (%d) module "
-                              "parameter is set; updelay and downdelay have "
-                              "no effect unless miimon is set\n",
-                              updelay, downdelay);
+                       pr_warning("Warning: miimon module parameter not set and updelay (%d) or downdelay (%d) module parameter is set; updelay and downdelay have no effect unless miimon is set\n",
+                                  updelay, downdelay);
                }
        } else {
                /* don't allow arp monitoring */
                if (arp_interval) {
-                       printk(KERN_WARNING DRV_NAME
-                              ": Warning: miimon (%d) and arp_interval (%d) "
-                              "can't be used simultaneously, disabling ARP "
-                              "monitoring\n",
-                              miimon, arp_interval);
+                       pr_warning("Warning: miimon (%d) and arp_interval (%d) can't be used simultaneously, disabling ARP monitoring\n",
+                                  miimon, arp_interval);
                        arp_interval = 0;
                }
 
                if ((updelay % miimon) != 0) {
-                       printk(KERN_WARNING DRV_NAME
-                              ": Warning: updelay (%d) is not a multiple "
-                              "of miimon (%d), updelay rounded to %d ms\n",
-                              updelay, miimon, (updelay / miimon) * miimon);
+                       pr_warning("Warning: updelay (%d) is not a multiple of miimon (%d), updelay rounded to %d ms\n",
+                                  updelay, miimon,
+                                  (updelay / miimon) * miimon);
                }
 
                updelay /= miimon;
 
                if ((downdelay % miimon) != 0) {
-                       printk(KERN_WARNING DRV_NAME
-                              ": Warning: downdelay (%d) is not a multiple "
-                              "of miimon (%d), downdelay rounded to %d ms\n",
-                              downdelay, miimon,
-                              (downdelay / miimon) * miimon);
+                       pr_warning("Warning: downdelay (%d) is not a multiple of miimon (%d), downdelay rounded to %d ms\n",
+                                  downdelay, miimon,
+                                  (downdelay / miimon) * miimon);
                }
 
                downdelay /= miimon;
        }
 
        if (arp_interval < 0) {
-               printk(KERN_WARNING DRV_NAME
-                      ": Warning: arp_interval module parameter (%d) "
-                      ", not in range 0-%d, so it was reset to %d\n",
-                      arp_interval, INT_MAX, BOND_LINK_ARP_INTERV);
+               pr_warning("Warning: arp_interval module parameter (%d) , not in range 0-%d, so it was reset to %d\n",
+                          arp_interval, INT_MAX, BOND_LINK_ARP_INTERV);
                arp_interval = BOND_LINK_ARP_INTERV;
        }
 
@@ -4974,10 +4734,8 @@ static int bond_check_params(struct bond_params *params)
                /* not complete check, but should be good enough to
                   catch mistakes */
                if (!isdigit(arp_ip_target[arp_ip_count][0])) {
-                       printk(KERN_WARNING DRV_NAME
-                              ": Warning: bad arp_ip_target module parameter "
-                              "(%s), ARP monitoring will not be performed\n",
-                              arp_ip_target[arp_ip_count]);
+                       pr_warning("Warning: bad arp_ip_target module parameter (%s), ARP monitoring will not be performed\n",
+                                  arp_ip_target[arp_ip_count]);
                        arp_interval = 0;
                } else {
                        __be32 ip = in_aton(arp_ip_target[arp_ip_count]);
@@ -4987,31 +4745,25 @@ static int bond_check_params(struct bond_params *params)
 
        if (arp_interval && !arp_ip_count) {
                /* don't allow arping if no arp_ip_target given... */
-               printk(KERN_WARNING DRV_NAME
-                      ": Warning: arp_interval module parameter (%d) "
-                      "specified without providing an arp_ip_target "
-                      "parameter, arp_interval was reset to 0\n",
-                      arp_interval);
+               pr_warning("Warning: arp_interval module parameter (%d) specified without providing an arp_ip_target parameter, arp_interval was reset to 0\n",
+                          arp_interval);
                arp_interval = 0;
        }
 
        if (arp_validate) {
                if (bond_mode != BOND_MODE_ACTIVEBACKUP) {
-                       printk(KERN_ERR DRV_NAME
-              ": arp_validate only supported in active-backup mode\n");
+                       pr_err("arp_validate only supported in active-backup mode\n");
                        return -EINVAL;
                }
                if (!arp_interval) {
-                       printk(KERN_ERR DRV_NAME
-                              ": arp_validate requires arp_interval\n");
+                       pr_err("arp_validate requires arp_interval\n");
                        return -EINVAL;
                }
 
                arp_validate_value = bond_parse_parm(arp_validate,
                                                     arp_validate_tbl);
                if (arp_validate_value == -1) {
-                       printk(KERN_ERR DRV_NAME
-                              ": Error: invalid arp_validate \"%s\"\n",
+                       pr_err("Error: invalid arp_validate \"%s\"\n",
                               arp_validate == NULL ? "NULL" : arp_validate);
                        return -EINVAL;
                }
@@ -5019,59 +4771,60 @@ static int bond_check_params(struct bond_params *params)
                arp_validate_value = 0;
 
        if (miimon) {
-               printk(KERN_INFO DRV_NAME
-                      ": MII link monitoring set to %d ms\n",
-                      miimon);
+               pr_info("MII link monitoring set to %d ms\n", miimon);
        } else if (arp_interval) {
                int i;
 
-               printk(KERN_INFO DRV_NAME
-                      ": ARP monitoring set to %d ms, validate %s, with %d target(s):",
-                      arp_interval,
-                      arp_validate_tbl[arp_validate_value].modename,
-                      arp_ip_count);
+               pr_info("ARP monitoring set to %d ms, validate %s, with %d target(s):",
+                       arp_interval,
+                       arp_validate_tbl[arp_validate_value].modename,
+                       arp_ip_count);
 
                for (i = 0; i < arp_ip_count; i++)
-                       printk (" %s", arp_ip_target[i]);
+                       pr_info(" %s", arp_ip_target[i]);
 
-               printk("\n");
+               pr_info("\n");
 
        } else if (max_bonds) {
                /* miimon and arp_interval not set, we need one so things
                 * work as expected, see bonding.txt for details
                 */
-               printk(KERN_WARNING DRV_NAME
-                      ": Warning: either miimon or arp_interval and "
-                      "arp_ip_target module parameters must be specified, "
-                      "otherwise bonding will not detect link failures! see "
-                      "bonding.txt for details.\n");
+               pr_warning("Warning: either miimon or arp_interval and arp_ip_target module parameters must be specified, otherwise bonding will not detect link failures! see bonding.txt for details.\n");
        }
 
        if (primary && !USES_PRIMARY(bond_mode)) {
                /* currently, using a primary only makes sense
                 * in active backup, TLB or ALB modes
                 */
-               printk(KERN_WARNING DRV_NAME
-                      ": Warning: %s primary device specified but has no "
-                      "effect in %s mode\n",
-                      primary, bond_mode_name(bond_mode));
+               pr_warning("Warning: %s primary device specified but has no effect in %s mode\n",
+                          primary, bond_mode_name(bond_mode));
                primary = NULL;
        }
 
+       if (primary && primary_reselect) {
+               primary_reselect_value = bond_parse_parm(primary_reselect,
+                                                        pri_reselect_tbl);
+               if (primary_reselect_value == -1) {
+                       pr_err("Error: Invalid primary_reselect \"%s\"\n",
+                              primary_reselect ==
+                                       NULL ? "NULL" : primary_reselect);
+                       return -EINVAL;
+               }
+       } else {
+               primary_reselect_value = BOND_PRI_RESELECT_ALWAYS;
+       }
+
        if (fail_over_mac) {
                fail_over_mac_value = bond_parse_parm(fail_over_mac,
                                                      fail_over_mac_tbl);
                if (fail_over_mac_value == -1) {
-                       printk(KERN_ERR DRV_NAME
-                              ": Error: invalid fail_over_mac \"%s\"\n",
+                       pr_err("Error: invalid fail_over_mac \"%s\"\n",
                               arp_validate == NULL ? "NULL" : arp_validate);
                        return -EINVAL;
                }
 
                if (bond_mode != BOND_MODE_ACTIVEBACKUP)
-                       printk(KERN_WARNING DRV_NAME
-                              ": Warning: fail_over_mac only affects "
-                              "active-backup mode.\n");
+                       pr_warning("Warning: fail_over_mac only affects active-backup mode.\n");
        } else {
                fail_over_mac_value = BOND_FOM_NONE;
        }
@@ -5089,6 +4842,7 @@ static int bond_check_params(struct bond_params *params)
        params->use_carrier = use_carrier;
        params->lacp_fast = lacp_fast;
        params->primary[0] = 0;
+       params->primary_reselect = primary_reselect_value;
        params->fail_over_mac = fail_over_mac_value;
 
        if (primary) {
@@ -5119,111 +4873,135 @@ static void bond_set_lockdep_class(struct net_device *dev)
        netdev_for_each_tx_queue(dev, bond_set_lockdep_class_one, NULL);
 }
 
+/*
+ * Called from registration process
+ */
+static int bond_init(struct net_device *bond_dev)
+{
+       struct bonding *bond = netdev_priv(bond_dev);
+       struct bond_net *bn = net_generic(dev_net(bond_dev), bond_net_id);
+
+       pr_debug("Begin bond_init for %s\n", bond_dev->name);
+
+       bond->wq = create_singlethread_workqueue(bond_dev->name);
+       if (!bond->wq)
+               return -ENOMEM;
+
+       bond_set_lockdep_class(bond_dev);
+
+       netif_carrier_off(bond_dev);
+
+       bond_create_proc_entry(bond);
+       list_add_tail(&bond->bond_list, &bn->dev_list);
+
+       bond_prepare_sysfs_group(bond);
+       return 0;
+}
+
+static int bond_validate(struct nlattr *tb[], struct nlattr *data[])
+{
+       if (tb[IFLA_ADDRESS]) {
+               if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN)
+                       return -EINVAL;
+               if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS])))
+                       return -EADDRNOTAVAIL;
+       }
+       return 0;
+}
+
+static struct rtnl_link_ops bond_link_ops __read_mostly = {
+       .kind           = "bond",
+       .priv_size      = sizeof(struct bonding),
+       .setup          = bond_setup,
+       .validate       = bond_validate,
+};
+
 /* Create a new bond based on the specified name and bonding parameters.
  * If name is NULL, obtain a suitable "bond%d" name for us.
  * Caller must NOT hold rtnl_lock; we need to release it here before we
  * set up our sysfs entries.
  */
-int bond_create(char *name, struct bond_params *params)
+int bond_create(struct net *net, const char *name)
 {
        struct net_device *bond_dev;
-       struct bonding *bond;
        int res;
 
        rtnl_lock();
-       down_write(&bonding_rwsem);
-
-       /* Check to see if the bond already exists. */
-       if (name) {
-               list_for_each_entry(bond, &bond_dev_list, bond_list)
-                       if (strnicmp(bond->dev->name, name, IFNAMSIZ) == 0) {
-                               printk(KERN_ERR DRV_NAME
-                              ": cannot add bond %s; it already exists\n",
-                                      name);
-                               res = -EPERM;
-                               goto out_rtnl;
-                       }
-       }
 
        bond_dev = alloc_netdev(sizeof(struct bonding), name ? name : "",
-                               ether_setup);
+                               bond_setup);
        if (!bond_dev) {
-               printk(KERN_ERR DRV_NAME
-                      ": %s: eek! can't alloc netdev!\n",
-                      name);
+               pr_err("%s: eek! can't alloc netdev!\n", name);
                res = -ENOMEM;
-               goto out_rtnl;
+               goto out;
        }
 
+       dev_net_set(bond_dev, net);
+       bond_dev->rtnl_link_ops = &bond_link_ops;
+
        if (!name) {
                res = dev_alloc_name(bond_dev, "bond%d");
                if (res < 0)
                        goto out_netdev;
        }
 
-       /* bond_init() must be called after dev_alloc_name() (for the
-        * /proc files), but before register_netdevice(), because we
-        * need to set function pointers.
-        */
-
-       res = bond_init(bond_dev, params);
-       if (res < 0) {
-               goto out_netdev;
-       }
-
        res = register_netdevice(bond_dev);
-       if (res < 0) {
-               goto out_bond;
-       }
 
-       bond_set_lockdep_class(bond_dev);
+out:
+       rtnl_unlock();
+       return res;
+out_netdev:
+       free_netdev(bond_dev);
+       goto out;
+}
 
-       netif_carrier_off(bond_dev);
+static int __net_init bond_net_init(struct net *net)
+{
+       struct bond_net *bn = net_generic(net, bond_net_id);
 
-       up_write(&bonding_rwsem);
-       rtnl_unlock(); /* allows sysfs registration of net device */
-       res = bond_create_sysfs_entry(netdev_priv(bond_dev));
-       if (res < 0) {
-               rtnl_lock();
-               down_write(&bonding_rwsem);
-               bond_deinit(bond_dev);
-               unregister_netdevice(bond_dev);
-               goto out_rtnl;
-       }
+       bn->net = net;
+       INIT_LIST_HEAD(&bn->dev_list);
 
+       bond_create_proc_dir(bn);
+       
        return 0;
+}
 
-out_bond:
-       bond_deinit(bond_dev);
-out_netdev:
-       free_netdev(bond_dev);
-out_rtnl:
-       up_write(&bonding_rwsem);
-       rtnl_unlock();
-       return res;
+static void __net_exit bond_net_exit(struct net *net)
+{
+       struct bond_net *bn = net_generic(net, bond_net_id);
+
+       bond_destroy_proc_dir(bn);
 }
 
+static struct pernet_operations bond_net_ops = {
+       .init = bond_net_init,
+       .exit = bond_net_exit,
+       .id   = &bond_net_id,
+       .size = sizeof(struct bond_net),
+};
+
 static int __init bonding_init(void)
 {
        int i;
        int res;
-       struct bonding *bond;
 
-       printk(KERN_INFO "%s", version);
+       pr_info("%s", version);
 
        res = bond_check_params(&bonding_defaults);
-       if (res) {
+       if (res)
                goto out;
-       }
 
-#ifdef CONFIG_PROC_FS
-       bond_create_proc_dir();
-#endif
+       res = register_pernet_subsys(&bond_net_ops);
+       if (res)
+               goto out;
 
-       init_rwsem(&bonding_rwsem);
+       res = rtnl_link_register(&bond_link_ops);
+       if (res)
+               goto err_link;
 
        for (i = 0; i < max_bonds; i++) {
-               res = bond_create(NULL, &bonding_defaults);
+               res = bond_create(&init_net, NULL);
                if (res)
                        goto err;
        }
@@ -5235,21 +5013,13 @@ static int __init bonding_init(void)
        register_netdevice_notifier(&bond_netdev_notifier);
        register_inetaddr_notifier(&bond_inetaddr_notifier);
        bond_register_ipv6_notifier();
-
-       goto out;
-err:
-       list_for_each_entry(bond, &bond_dev_list, bond_list) {
-               bond_work_cancel_all(bond);
-               destroy_workqueue(bond->wq);
-       }
-
-       bond_destroy_sysfs();
-
-       rtnl_lock();
-       bond_free_all();
-       rtnl_unlock();
 out:
        return res;
+err:
+       rtnl_link_unregister(&bond_link_ops);
+err_link:
+       unregister_pernet_subsys(&bond_net_ops);
+       goto out;
 
 }
 
@@ -5261,9 +5031,8 @@ static void __exit bonding_exit(void)
 
        bond_destroy_sysfs();
 
-       rtnl_lock();
-       bond_free_all();
-       rtnl_unlock();
+       rtnl_link_unregister(&bond_link_ops);
+       unregister_pernet_subsys(&bond_net_ops);
 }
 
 module_init(bonding_init);
@@ -5272,13 +5041,4 @@ MODULE_LICENSE("GPL");
 MODULE_VERSION(DRV_VERSION);
 MODULE_DESCRIPTION(DRV_DESCRIPTION ", v" DRV_VERSION);
 MODULE_AUTHOR("Thomas Davis, tadavis@lbl.gov and many others");
-MODULE_SUPPORTED_DEVICE("most ethernet devices");
-
-/*
- * Local variables:
- *  c-indent-level: 8
- *  c-basic-offset: 8
- *  tab-width: 8
- * End:
- */
-
+MODULE_ALIAS_RTNL_LINK("bond");