net/bonding: Optionally allow ethernet slaves to keep own MAC
[safe/jmp/linux-2.6] / drivers / net / bonding / bond_main.c
index 2582d98..db80f24 100644 (file)
 
 //#define BONDING_DEBUG 1
 
-#include <linux/config.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
-#include <linux/sched.h>
 #include <linux/types.h>
 #include <linux/fcntl.h>
 #include <linux/interrupt.h>
@@ -62,6 +60,7 @@
 #include <linux/errno.h>
 #include <linux/netdevice.h>
 #include <linux/inetdevice.h>
+#include <linux/igmp.h>
 #include <linux/etherdevice.h>
 #include <linux/skbuff.h>
 #include <net/sock.h>
@@ -76,6 +75,7 @@
 #include <linux/if_vlan.h>
 #include <linux/if_bonding.h>
 #include <net/route.h>
+#include <net/net_namespace.h>
 #include "bonding.h"
 #include "bond_3ad.h"
 #include "bond_alb.h"
@@ -97,6 +97,8 @@ static char *lacp_rate        = NULL;
 static char *xmit_hash_policy = NULL;
 static int arp_interval = BOND_LINK_ARP_INTERV;
 static char *arp_ip_target[BOND_MAX_ARP_TARGETS] = { NULL, };
+static char *arp_validate = NULL;
+static int fail_over_mac = 0;
 struct bond_params bonding_defaults;
 
 module_param(max_bonds, int, 0);
@@ -128,10 +130,14 @@ module_param(arp_interval, int, 0);
 MODULE_PARM_DESC(arp_interval, "arp interval in milliseconds");
 module_param_array(arp_ip_target, charp, NULL, 0);
 MODULE_PARM_DESC(arp_ip_target, "arp targets in n.n.n.n form");
+module_param(arp_validate, charp, 0);
+MODULE_PARM_DESC(arp_validate, "validate src/dst of ARP probes: none (default), active, backup or all");
+module_param(fail_over_mac, int, 0);
+MODULE_PARM_DESC(fail_over_mac, "For active-backup, do not set all slaves to the same MAC.  0 of off (default), 1 for on.");
 
 /*----------------------------- Global variables ----------------------------*/
 
-static const char *version =
+static const char * const version =
        DRV_DESCRIPTION ": v" DRV_VERSION " (" DRV_RELDATE ")\n";
 
 LIST_HEAD(bond_dev_list);
@@ -141,7 +147,7 @@ static struct proc_dir_entry *bond_proc_dir = NULL;
 #endif
 
 extern struct rw_semaphore bonding_rwsem;
-static u32 arp_target[BOND_MAX_ARP_TARGETS] = { 0, } ;
+static __be32 arp_target[BOND_MAX_ARP_TARGETS] = { 0, } ;
 static int arp_ip_count        = 0;
 static int bond_mode   = BOND_MODE_ROUNDROBIN;
 static int xmit_hashtype= BOND_XMIT_POLICY_LAYER2;
@@ -171,13 +177,21 @@ struct bond_parm_tbl xmit_hashtype_tbl[] = {
 {      NULL,                   -1},
 };
 
+struct bond_parm_tbl arp_validate_tbl[] = {
+{      "none",                 BOND_ARP_VALIDATE_NONE},
+{      "active",               BOND_ARP_VALIDATE_ACTIVE},
+{      "backup",               BOND_ARP_VALIDATE_BACKUP},
+{      "all",                  BOND_ARP_VALIDATE_ALL},
+{      NULL,                   -1},
+};
+
 /*-------------------------- Forward declarations ---------------------------*/
 
 static void bond_send_gratuitous_arp(struct bonding *bond);
 
 /*---------------------------- General routines -----------------------------*/
 
-const char *bond_mode_name(int mode)
+static const char *bond_mode_name(int mode)
 {
        switch (mode) {
        case BOND_MODE_ROUNDROBIN :
@@ -479,9 +493,9 @@ static void bond_vlan_rx_kill_vid(struct net_device *bond_dev, uint16_t vid)
                        /* Save and then restore vlan_dev in the grp array,
                         * since the slave's driver might clear it.
                         */
-                       vlan_dev = bond->vlgrp->vlan_devices[vid];
+                       vlan_dev = vlan_group_get_device(bond->vlgrp, vid);
                        slave_dev->vlan_rx_kill_vid(slave_dev, vid);
-                       bond->vlgrp->vlan_devices[vid] = vlan_dev;
+                       vlan_group_set_device(bond->vlgrp, vid, vlan_dev);
                }
        }
 
@@ -541,9 +555,9 @@ static void bond_del_vlans_from_slave(struct bonding *bond, struct net_device *s
                /* Save and then restore vlan_dev in the grp array,
                 * since the slave's driver might clear it.
                 */
-               vlan_dev = bond->vlgrp->vlan_devices[vlan->vlan_id];
+               vlan_dev = vlan_group_get_device(bond->vlgrp, vlan->vlan_id);
                slave_dev->vlan_rx_kill_vid(slave_dev, vlan->vlan_id);
-               bond->vlgrp->vlan_devices[vlan->vlan_id] = vlan_dev;
+               vlan_group_set_device(bond->vlgrp, vlan->vlan_id, vlan_dev);
        }
 
 unreg:
@@ -559,6 +573,42 @@ out:
 /*------------------------------- Link status -------------------------------*/
 
 /*
+ * Set the carrier state for the master according to the state of its
+ * slaves.  If any slaves are up, the master is up.  In 802.3ad mode,
+ * do special 802.3ad magic.
+ *
+ * Returns zero if carrier state does not change, nonzero if it does.
+ */
+static int bond_set_carrier(struct bonding *bond)
+{
+       struct slave *slave;
+       int i;
+
+       if (bond->slave_cnt == 0)
+               goto down;
+
+       if (bond->params.mode == BOND_MODE_8023AD)
+               return bond_3ad_set_carrier(bond);
+
+       bond_for_each_slave(bond, slave, i) {
+               if (slave->link == BOND_LINK_UP) {
+                       if (!netif_carrier_ok(bond->dev)) {
+                               netif_carrier_on(bond->dev);
+                               return 1;
+                       }
+                       return 0;
+               }
+       }
+
+down:
+       if (netif_carrier_ok(bond->dev)) {
+               netif_carrier_off(bond->dev);
+               return 1;
+       }
+       return 0;
+}
+
+/*
  * Get link speed and duplex from the slave's base driver
  * using ethtool. If for some reason the call fails or the
  * values are invalid, fake speed and duplex to 100/Full
@@ -567,42 +617,25 @@ out:
 static int bond_update_speed_duplex(struct slave *slave)
 {
        struct net_device *slave_dev = slave->dev;
-       static int (* ioctl)(struct net_device *, struct ifreq *, int);
-       struct ifreq ifr;
        struct ethtool_cmd etool;
+       int res;
 
        /* Fake speed and duplex */
        slave->speed = SPEED_100;
        slave->duplex = DUPLEX_FULL;
 
-       if (slave_dev->ethtool_ops) {
-               u32 res;
-
-               if (!slave_dev->ethtool_ops->get_settings) {
-                       return -1;
-               }
-
-               res = slave_dev->ethtool_ops->get_settings(slave_dev, &etool);
-               if (res < 0) {
-                       return -1;
-               }
-
-               goto verify;
-       }
+       if (!slave_dev->ethtool_ops || !slave_dev->ethtool_ops->get_settings)
+               return -1;
 
-       ioctl = slave_dev->do_ioctl;
-       strncpy(ifr.ifr_name, slave_dev->name, IFNAMSIZ);
-       etool.cmd = ETHTOOL_GSET;
-       ifr.ifr_data = (char*)&etool;
-       if (!ioctl || (IOCTL(slave_dev, &ifr, SIOCETHTOOL) < 0)) {
+       res = slave_dev->ethtool_ops->get_settings(slave_dev, &etool);
+       if (res < 0)
                return -1;
-       }
 
-verify:
        switch (etool.speed) {
        case SPEED_10:
        case SPEED_100:
        case SPEED_1000:
+       case SPEED_10000:
                break;
        default:
                return -1;
@@ -643,7 +676,6 @@ static int bond_check_dev_link(struct bonding *bond, struct net_device *slave_de
        static int (* ioctl)(struct net_device *, struct ifreq *, int);
        struct ifreq ifr;
        struct mii_ioctl_data *mii;
-       struct ethtool_value etool;
 
        if (bond->params.use_carrier) {
                return netif_carrier_ok(slave_dev) ? BMSR_LSTATUS : 0;
@@ -674,9 +706,10 @@ static int bond_check_dev_link(struct bonding *bond, struct net_device *slave_de
                }
        }
 
-       /* try SIOCETHTOOL ioctl, some drivers cache ETHTOOL_GLINK */
-       /* for a period of time so we attempt to get link status   */
-       /* from it last if the above MII ioctls fail...            */
+       /*
+        * 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;
@@ -687,23 +720,9 @@ static int bond_check_dev_link(struct bonding *bond, struct net_device *slave_de
                }
        }
 
-       if (ioctl) {
-               strncpy(ifr.ifr_name, slave_dev->name, IFNAMSIZ);
-               etool.cmd = ETHTOOL_GLINK;
-               ifr.ifr_data = (char*)&etool;
-               if (IOCTL(slave_dev, &ifr, SIOCETHTOOL) == 0) {
-                       if (etool.data == 1) {
-                               return BMSR_LSTATUS;
-                       } else {
-                               dprintk("SIOCETHTOOL shows link down\n");
-                               return 0;
-                       }
-               }
-       }
-
        /*
         * If reporting, report that either there's no dev->do_ioctl,
-        * or both SIOCGMIIREG and SIOCETHTOOL failed (meaning that we
+        * or both SIOCGMIIREG and get_link failed (meaning that we
         * cannot report link status).  If not reporting, pretend
         * we're ok.
         */
@@ -815,6 +834,28 @@ static void bond_mc_delete(struct bonding *bond, void *addr, int alen)
        }
 }
 
+
+/*
+ * Retrieve the list of registered multicast addresses for the bonding
+ * device and retransmit an IGMP JOIN request to the current active
+ * slave.
+ */
+static void bond_resend_igmp_join_requests(struct bonding *bond)
+{
+       struct in_device *in_dev;
+       struct ip_mc_list *im;
+
+       rcu_read_lock();
+       in_dev = __in_dev_get_rcu(bond->dev);
+       if (in_dev) {
+               for (im = in_dev->mc_list; im; im = im->next) {
+                       ip_mc_rejoin_group(im);
+               }
+       }
+
+       rcu_read_unlock();
+}
+
 /*
  * Totally destroys the mc_list in bond
  */
@@ -828,6 +869,7 @@ static void bond_mc_list_destroy(struct bonding *bond)
                kfree(dmi);
                dmi = bond->mc_list;
        }
+        bond->mc_list = NULL;
 }
 
 /*
@@ -921,6 +963,7 @@ static void bond_mc_swap(struct bonding *bond, struct slave *new_active, struct
                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);
        }
 }
 
@@ -1040,6 +1083,10 @@ void bond_change_active_slave(struct bonding *bond, struct slave *new_active)
        if ((bond->params.mode == BOND_MODE_TLB) ||
            (bond->params.mode == BOND_MODE_ALB)) {
                bond_alb_handle_active_change(bond, new_active);
+               if (old_active)
+                       bond_set_slave_inactive_flags(old_active);
+               if (new_active)
+                       bond_set_slave_active_flags(new_active);
        } else {
                bond->curr_active_slave = new_active;
        }
@@ -1052,7 +1099,21 @@ void bond_change_active_slave(struct bonding *bond, struct slave *new_active)
                if (new_active) {
                        bond_set_slave_active_flags(new_active);
                }
-               bond_send_gratuitous_arp(bond);
+
+               /* when bonding does not set the slave MAC address, the bond MAC
+                * address is the one of the active slave.
+                */
+               if (new_active && bond->params.fail_over_mac)
+                       memcpy(bond->dev->dev_addr,  new_active->dev->dev_addr,
+                               new_active->dev->addr_len);
+               if (bond->curr_active_slave &&
+                       test_bit(__LINK_STATE_LINKWATCH_PENDING,
+                                       &bond->curr_active_slave->dev->state)) {
+                       dprintk("delaying gratuitous arp on %s\n",
+                               bond->curr_active_slave->dev->name);
+                       bond->send_grat_arp = 1;
+               } else
+                       bond_send_gratuitous_arp(bond);
        }
 }
 
@@ -1070,10 +1131,24 @@ void bond_change_active_slave(struct bonding *bond, struct slave *new_active)
 void bond_select_active_slave(struct bonding *bond)
 {
        struct slave *best_slave;
+       int rv;
 
        best_slave = bond_find_best_slave(bond);
        if (best_slave != bond->curr_active_slave) {
                bond_change_active_slave(bond, best_slave);
+               rv = bond_set_carrier(bond);
+               if (!rv)
+                       return;
+
+               if (netif_carrier_ok(bond->dev)) {
+                       printk(KERN_INFO DRV_NAME
+                              ": %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);
+               }
        }
 }
 
@@ -1135,7 +1210,8 @@ static void bond_detach_slave(struct bonding *bond, struct slave *slave)
 
 /*---------------------------------- IOCTL ----------------------------------*/
 
-int bond_sethwaddr(struct net_device *bond_dev, struct net_device *slave_dev)
+static int bond_sethwaddr(struct net_device *bond_dev,
+                         struct net_device *slave_dev)
 {
        dprintk("bond_dev=%p\n", bond_dev);
        dprintk("slave_dev=%p\n", slave_dev);
@@ -1144,36 +1220,59 @@ int bond_sethwaddr(struct net_device *bond_dev, struct net_device *slave_dev)
        return 0;
 }
 
-#define BOND_INTERSECT_FEATURES \
-       (NETIF_F_SG|NETIF_F_IP_CSUM|NETIF_F_NO_CSUM|NETIF_F_HW_CSUM)
+#define BOND_VLAN_FEATURES \
+       (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 feature bits set on
- * master device that are not part of the examined set.
+ * feature bits are managed elsewhere, so preserve those feature bits
+ * on the master device.
  */
 static int bond_compute_features(struct bonding *bond)
 {
-       unsigned long features = BOND_INTERSECT_FEATURES;
        struct slave *slave;
        struct net_device *bond_dev = bond->dev;
+       unsigned long features = bond_dev->features;
+       unsigned short max_hard_header_len = max((u16)ETH_HLEN,
+                                               bond_dev->hard_header_len);
        int i;
 
-       bond_for_each_slave(bond, slave, i)
-               features &= (slave->dev->features & BOND_INTERSECT_FEATURES);
+       features &= ~(NETIF_F_ALL_CSUM | BOND_VLAN_FEATURES);
+       features |= NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_HIGHDMA |
+                   NETIF_F_GSO_MASK | NETIF_F_NO_CSUM;
 
-       if ((features & NETIF_F_SG) && 
-           !(features & (NETIF_F_IP_CSUM |
-                         NETIF_F_NO_CSUM |
-                         NETIF_F_HW_CSUM)))
-               features &= ~NETIF_F_SG;
+       bond_for_each_slave(bond, slave, i) {
+               features = netdev_compute_features(features,
+                                                  slave->dev->features);
+               if (slave->dev->hard_header_len > max_hard_header_len)
+                       max_hard_header_len = slave->dev->hard_header_len;
+       }
 
-       features |= (bond_dev->features & ~BOND_INTERSECT_FEATURES);
+       features |= (bond_dev->features & BOND_VLAN_FEATURES);
        bond_dev->features = features;
+       bond_dev->hard_header_len = max_hard_header_len;
 
        return 0;
 }
 
+
+static void bond_setup_by_slave(struct net_device *bond_dev,
+                               struct net_device *slave_dev)
+{
+       struct bonding *bond = bond_dev->priv;
+
+       bond_dev->neigh_setup           = slave_dev->neigh_setup;
+
+       bond_dev->type              = slave_dev->type;
+       bond_dev->hard_header_len   = slave_dev->hard_header_len;
+       bond_dev->addr_len          = slave_dev->addr_len;
+
+       memcpy(bond_dev->broadcast, slave_dev->broadcast,
+               slave_dev->addr_len);
+       bond->setup_by_slave = 1;
+}
+
 /* enslave device <slave> to bond device <master> */
 int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
 {
@@ -1194,8 +1293,9 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
 
        /* bond must be initialized by bond_open() before enslaving */
        if (!(bond_dev->flags & IFF_UP)) {
-               dprintk("Error, master_dev is not up\n");
-               return -EPERM;
+               printk(KERN_WARNING DRV_NAME
+                       " %s: master_dev is not up in bond_enslave\n",
+                       bond_dev->name);
        }
 
        /* already enslaved */
@@ -1248,24 +1348,50 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
                goto err_undo_flags;
        }
 
+       /* set bonding device ether type by slave - bonding netdevices are
+        * created with ether_setup, so when the slave type is not ARPHRD_ETHER
+        * there is a need to override some of the type dependent attribs/funcs.
+        *
+        * bond ether type mutual exclusion - don't allow slaves of dissimilar
+        * 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);
+       } 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;
+       }
+
        if (slave_dev->set_mac_address == NULL) {
-               printk(KERN_ERR DRV_NAME
-                       ": %s: Error: The slave device you specified does "
-                       "not support setting the MAC address. "
-                       "Your kernel likely does not support slave "
-                       "devices.\n", bond_dev->name);
-               res = -EOPNOTSUPP;
-               goto err_undo_flags;
+               if (bond->slave_cnt == 0) {
+                       printk(KERN_WARNING DRV_NAME
+                              ": %s: Warning: The first slave device "
+                              "specified does not support setting the MAC "
+                              "address. Enabling the fail_over_mac option.",
+                              bond_dev->name);
+                       bond->params.fail_over_mac = 1;
+               } else if (!bond->params.fail_over_mac) {
+                       printk(KERN_ERR DRV_NAME
+                               ": %s: Error: The slave device specified "
+                               "does not support setting the MAC address, "
+                               "but fail_over_mac is not enabled.\n"
+                               , bond_dev->name);
+                       res = -EOPNOTSUPP;
+                       goto err_undo_flags;
+               }
        }
 
-       new_slave = kmalloc(sizeof(struct slave), GFP_KERNEL);
+       new_slave = kzalloc(sizeof(struct slave), GFP_KERNEL);
        if (!new_slave) {
                res = -ENOMEM;
                goto err_undo_flags;
        }
 
-       memset(new_slave, 0, sizeof(struct slave));
-
        /* save slave's original flags before calling
         * netdev_set_master and dev_open
         */
@@ -1278,18 +1404,25 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
         */
        memcpy(new_slave->perm_hwaddr, slave_dev->dev_addr, ETH_ALEN);
 
-       /*
-        * Set slave to master's mac address.  The application already
-        * set the master's mac address to that of the first slave
-        */
-       memcpy(addr.sa_data, bond_dev->dev_addr, bond_dev->addr_len);
-       addr.sa_family = slave_dev->type;
-       res = dev_set_mac_address(slave_dev, &addr);
-       if (res) {
-               dprintk("Error %d calling set_mac_address\n", res);
-               goto err_free;
+       if (!bond->params.fail_over_mac) {
+               /*
+                * Set slave to master's mac address.  The application already
+                * set the master's mac address to that of the first slave
+                */
+               memcpy(addr.sa_data, bond_dev->dev_addr, bond_dev->addr_len);
+               addr.sa_family = slave_dev->type;
+               res = dev_set_mac_address(slave_dev, &addr);
+               if (res) {
+                       dprintk("Error %d calling set_mac_address\n", res);
+                       goto err_free;
+               }
        }
 
+       res = netdev_set_master(slave_dev, bond_dev);
+       if (res) {
+               dprintk("Error %d calling netdev_set_master\n", res);
+               goto err_close;
+       }
        /* open the slave since the application closed it */
        res = dev_open(slave_dev);
        if (res) {
@@ -1297,13 +1430,8 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
                goto err_restore_mac;
        }
 
-       res = netdev_set_master(slave_dev, bond_dev);
-       if (res) {
-               dprintk("Error %d calling netdev_set_master\n", res);
-               goto err_close;
-       }
-
        new_slave->dev = slave_dev;
+       slave_dev->priv_flags |= IFF_BONDING;
 
        if ((bond->params.mode == BOND_MODE_TLB) ||
            (bond->params.mode == BOND_MODE_ALB)) {
@@ -1356,6 +1484,8 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
 
        bond_compute_features(bond);
 
+       new_slave->last_arp_rx = jiffies;
+
        if (bond->params.miimon && !bond->params.use_carrier) {
                link_reporting = bond_check_dev_link(bond, slave_dev, 1);
 
@@ -1432,24 +1562,8 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
 
        switch (bond->params.mode) {
        case BOND_MODE_ACTIVEBACKUP:
-               /* if we're in active-backup mode, we need one and only one active
-                * interface. The backup interfaces will have their NOARP flag set
-                * because we need them to be completely deaf and not to respond to
-                * any ARP request on the network to avoid fooling a switch. Thus,
-                * since we guarantee that curr_active_slave always point to the last
-                * usable interface, we just have to verify this interface's flag.
-                */
-               if (((!bond->curr_active_slave) ||
-                    (bond->curr_active_slave->dev->flags & IFF_NOARP)) &&
-                   (new_slave->link != BOND_LINK_DOWN)) {
-                       dprintk("This is the first active slave\n");
-                       /* first slave or no active slave yet, and this link
-                          is OK, so make this interface the active one */
-                       bond_change_active_slave(bond, new_slave);
-               } else {
-                       dprintk("This is just a backup slave\n");
-                       bond_set_slave_inactive_flags(new_slave);
-               }
+               bond_set_slave_inactive_flags(new_slave);
+               bond_select_active_slave(bond);
                break;
        case BOND_MODE_8023AD:
                /* in 802.3ad mode, the internal mechanism
@@ -1481,6 +1595,8 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
                         * is OK, so make this interface the active one
                         */
                        bond_change_active_slave(bond, new_slave);
+               } else {
+                       bond_set_slave_inactive_flags(new_slave);
                }
                break;
        default:
@@ -1499,6 +1615,8 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
                break;
        } /* switch(bond_mode) */
 
+       bond_set_carrier(bond);
+
        write_unlock_bh(&bond->lock);
 
        res = bond_create_slave_symlinks(bond_dev, slave_dev);
@@ -1522,9 +1640,11 @@ err_close:
        dev_close(slave_dev);
 
 err_restore_mac:
-       memcpy(addr.sa_data, new_slave->perm_hwaddr, ETH_ALEN);
-       addr.sa_family = slave_dev->type;
-       dev_set_mac_address(slave_dev, &addr);
+       if (!bond->params.fail_over_mac) {
+               memcpy(addr.sa_data, new_slave->perm_hwaddr, ETH_ALEN);
+               addr.sa_family = slave_dev->type;
+               dev_set_mac_address(slave_dev, &addr);
+       }
 
 err_free:
        kfree(new_slave);
@@ -1552,6 +1672,7 @@ int bond_release(struct net_device *bond_dev, struct net_device *slave_dev)
        struct slave *slave, *oldcurrent;
        struct sockaddr addr;
        int mac_addr_differ;
+       DECLARE_MAC_BUF(mac);
 
        /* slave is not a slave or master is not master of this slave */
        if (!(slave_dev->flags & IFF_SLAVE) ||
@@ -1570,6 +1691,7 @@ int bond_release(struct net_device *bond_dev, struct net_device *slave_dev)
                printk(KERN_INFO DRV_NAME
                       ": %s: %s not enslaved\n",
                       bond_dev->name, slave_dev->name);
+               write_unlock_bh(&bond->lock);
                return -EINVAL;
        }
 
@@ -1578,19 +1700,13 @@ int bond_release(struct net_device *bond_dev, struct net_device *slave_dev)
                                 ETH_ALEN);
        if (!mac_addr_differ && (bond->slave_cnt > 1)) {
                printk(KERN_WARNING DRV_NAME
-                      ": %s: Warning: the permanent HWaddr of %s "
-                      "- %02X:%02X:%02X:%02X:%02X:%02X - is "
-                      "still in use by %s. Set the HWaddr of "
-                      "%s to a different address to avoid "
-                      "conflicts.\n",
+                      ": %s: Warning: the permanent HWaddr of %s - "
+                      "%s - 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[0],
-                      slave->perm_hwaddr[1],
-                      slave->perm_hwaddr[2],
-                      slave->perm_hwaddr[3],
-                      slave->perm_hwaddr[4],
-                      slave->perm_hwaddr[5],
+                      print_mac(mac, slave->perm_hwaddr),
                       bond_dev->name,
                       slave_dev->name);
        }
@@ -1637,18 +1753,12 @@ int bond_release(struct net_device *bond_dev, struct net_device *slave_dev)
                bond_alb_deinit_slave(bond, slave);
        }
 
-       if (oldcurrent == slave) {
+       if (oldcurrent == slave)
                bond_select_active_slave(bond);
 
-               if (!bond->curr_active_slave) {
-                       printk(KERN_INFO DRV_NAME
-                              ": %s: now running without any active "
-                              "interface !\n",
-                              bond_dev->name);
-               }
-       }
-
        if (bond->slave_cnt == 0) {
+               bond_set_carrier(bond);
+
                /* if the last slave was removed, zero the mac address
                 * of the master so it will be set by the application
                 * to the mac address of the first slave
@@ -1707,25 +1817,52 @@ int bond_release(struct net_device *bond_dev, struct net_device *slave_dev)
        /* close slave before restoring its mac address */
        dev_close(slave_dev);
 
-       /* restore original ("permanent") mac address */
-       memcpy(addr.sa_data, slave->perm_hwaddr, ETH_ALEN);
-       addr.sa_family = slave_dev->type;
-       dev_set_mac_address(slave_dev, &addr);
-
-       /* restore the original state of the
-        * IFF_NOARP flag that might have been
-        * set by bond_set_slave_inactive_flags()
-        */
-       if ((slave->original_flags & IFF_NOARP) == 0) {
-               slave_dev->flags &= ~IFF_NOARP;
+       if (!bond->params.fail_over_mac) {
+               /* restore original ("permanent") mac address */
+               memcpy(addr.sa_data, slave->perm_hwaddr, ETH_ALEN);
+               addr.sa_family = slave_dev->type;
+               dev_set_mac_address(slave_dev, &addr);
        }
 
+       slave_dev->priv_flags &= ~(IFF_MASTER_8023AD | IFF_MASTER_ALB |
+                                  IFF_SLAVE_INACTIVE | IFF_BONDING |
+                                  IFF_SLAVE_NEEDARP);
+
        kfree(slave);
 
        return 0;  /* deletion OK */
 }
 
 /*
+* Destroy a bonding device.
+* 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);
+}
+
+/*
+* 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)
+{
+       struct bonding *bond = bond_dev->priv;
+       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);
+       }
+       return ret;
+}
+
+/*
  * This function releases all slaves.
  */
 static int bond_release_all(struct net_device *bond_dev)
@@ -1737,6 +1874,8 @@ static int bond_release_all(struct net_device *bond_dev)
 
        write_lock_bh(&bond->lock);
 
+       netif_carrier_off(bond_dev);
+
        if (bond->slave_cnt == 0) {
                goto out;
        }
@@ -1799,18 +1938,16 @@ static int bond_release_all(struct net_device *bond_dev)
                /* close slave before restoring its mac address */
                dev_close(slave_dev);
 
-               /* restore original ("permanent") mac address*/
-               memcpy(addr.sa_data, slave->perm_hwaddr, ETH_ALEN);
-               addr.sa_family = slave_dev->type;
-               dev_set_mac_address(slave_dev, &addr);
-
-               /* restore the original state of the IFF_NOARP flag that might have
-                * been set by bond_set_slave_inactive_flags()
-                */
-               if ((slave->original_flags & IFF_NOARP) == 0) {
-                       slave_dev->flags &= ~IFF_NOARP;
+               if (!bond->params.fail_over_mac) {
+                       /* restore original ("permanent") mac address*/
+                       memcpy(addr.sa_data, slave->perm_hwaddr, ETH_ALEN);
+                       addr.sa_family = slave_dev->type;
+                       dev_set_mac_address(slave_dev, &addr);
                }
 
+               slave_dev->priv_flags &= ~(IFF_MASTER_8023AD | IFF_MASTER_ALB |
+                                          IFF_SLAVE_INACTIVE);
+
                kfree(slave);
 
                /* re-acquire the lock before getting the next slave */
@@ -1977,6 +2114,17 @@ void bond_mii_monitor(struct net_device *bond_dev)
         * program could monitor the link itself if needed.
         */
 
+       if (bond->send_grat_arp) {
+               if (bond->curr_active_slave && test_bit(__LINK_STATE_LINKWATCH_PENDING,
+                               &bond->curr_active_slave->dev->state))
+                       dprintk("Needs to send gratuitous arp but not yet\n");
+               else {
+                       dprintk("sending delayed gratuitous arp on on %s\n",
+                               bond->curr_active_slave->dev->name);
+                       bond_send_gratuitous_arp(bond);
+                       bond->send_grat_arp = 0;
+               }
+       }
        read_lock(&bond->curr_slave_lock);
        oldcurrent = bond->curr_active_slave;
        read_unlock(&bond->curr_slave_lock);
@@ -2177,15 +2325,9 @@ void bond_mii_monitor(struct net_device *bond_dev)
 
                bond_select_active_slave(bond);
 
-               if (oldcurrent && !bond->curr_active_slave) {
-                       printk(KERN_INFO DRV_NAME
-                              ": %s: now running without any active "
-                              "interface !\n",
-                              bond_dev->name);
-               }
-
                write_unlock(&bond->curr_slave_lock);
-       }
+       } else
+               bond_set_carrier(bond);
 
 re_arm:
        if (bond->params.miimon) {
@@ -2196,11 +2338,11 @@ out:
 }
 
 
-static u32 bond_glean_dev_ip(struct net_device *dev)
+static __be32 bond_glean_dev_ip(struct net_device *dev)
 {
        struct in_device *idev;
        struct in_ifaddr *ifa;
-       u32 addr = 0;
+       __be32 addr = 0;
 
        if (!dev)
                return 0;
@@ -2239,12 +2381,31 @@ static int bond_has_ip(struct bonding *bond)
        return 0;
 }
 
+static int bond_has_this_ip(struct bonding *bond, __be32 ip)
+{
+       struct vlan_entry *vlan, *vlan_next;
+
+       if (ip == bond->master_ip)
+               return 1;
+
+       if (list_empty(&bond->vlan_list))
+               return 0;
+
+       list_for_each_entry_safe(vlan, vlan_next, &bond->vlan_list,
+                                vlan_list) {
+               if (ip == vlan->vlan_ip)
+                       return 1;
+       }
+
+       return 0;
+}
+
 /*
  * We go to the (large) trouble of VLAN tagging ARP frames because
  * switches in VLAN mode (especially if ports are configured as
  * "native" to a VLAN) might not pass non-tagged frames.
  */
-static void bond_arp_send(struct net_device *slave_dev, int arp_op, u32 dest_ip, u32 src_ip, unsigned short vlan_id)
+static void bond_arp_send(struct net_device *slave_dev, int arp_op, __be32 dest_ip, __be32 src_ip, unsigned short vlan_id)
 {
        struct sk_buff *skb;
 
@@ -2272,7 +2433,7 @@ static void bond_arp_send(struct net_device *slave_dev, int arp_op, u32 dest_ip,
 static void bond_arp_send_all(struct bonding *bond, struct slave *slave)
 {
        int i, vlan_id, rv;
-       u32 *targets = bond->params.arp_targets;
+       __be32 *targets = bond->params.arp_targets;
        struct vlan_entry *vlan, *vlan_next;
        struct net_device *vlan_dev;
        struct flowi fl;
@@ -2322,7 +2483,7 @@ static void bond_arp_send_all(struct bonding *bond, struct slave *slave)
                vlan_id = 0;
                list_for_each_entry_safe(vlan, vlan_next, &bond->vlan_list,
                                         vlan_list) {
-                       vlan_dev = bond->vlgrp->vlan_devices[vlan->vlan_id];
+                       vlan_dev = vlan_group_get_device(bond->vlgrp, vlan->vlan_id);
                        if (vlan_dev == rt->u.dst.dev) {
                                vlan_id = vlan->vlan_id;
                                dprintk("basa: vlan match on %s %d\n",
@@ -2365,11 +2526,11 @@ static void bond_send_gratuitous_arp(struct bonding *bond)
 
        if (bond->master_ip) {
                bond_arp_send(slave->dev, ARPOP_REPLY, bond->master_ip,
-                                 bond->master_ip, 0);
+                               bond->master_ip, 0);
        }
 
        list_for_each_entry(vlan, &bond->vlan_list, vlan_list) {
-               vlan_dev = bond->vlgrp->vlan_devices[vlan->vlan_id];
+               vlan_dev = vlan_group_get_device(bond->vlgrp, vlan->vlan_id);
                if (vlan->vlan_ip) {
                        bond_arp_send(slave->dev, ARPOP_REPLY, vlan->vlan_ip,
                                      vlan->vlan_ip, vlan->vlan_id);
@@ -2377,6 +2538,96 @@ static void bond_send_gratuitous_arp(struct bonding *bond)
        }
 }
 
+static void bond_validate_arp(struct bonding *bond, struct slave *slave, __be32 sip, __be32 tip)
+{
+       int i;
+       __be32 *targets = bond->params.arp_targets;
+
+       targets = bond->params.arp_targets;
+       for (i = 0; (i < BOND_MAX_ARP_TARGETS) && targets[i]; i++) {
+               dprintk("bva: sip %u.%u.%u.%u tip %u.%u.%u.%u t[%d] "
+                       "%u.%u.%u.%u bhti(tip) %d\n",
+                      NIPQUAD(sip), NIPQUAD(tip), i, NIPQUAD(targets[i]),
+                      bond_has_this_ip(bond, tip));
+               if (sip == targets[i]) {
+                       if (bond_has_this_ip(bond, tip))
+                               slave->last_arp_rx = jiffies;
+                       return;
+               }
+       }
+}
+
+static int bond_arp_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, struct net_device *orig_dev)
+{
+       struct arphdr *arp;
+       struct slave *slave;
+       struct bonding *bond;
+       unsigned char *arp_ptr;
+       __be32 sip, tip;
+
+       if (dev->nd_net != &init_net)
+               goto out;
+
+       if (!(dev->priv_flags & IFF_BONDING) || !(dev->flags & IFF_MASTER))
+               goto out;
+
+       bond = dev->priv;
+       read_lock(&bond->lock);
+
+       dprintk("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");
+
+       slave = bond_get_slave_by_dev(bond, orig_dev);
+       if (!slave || !slave_do_arp_validate(bond, slave))
+               goto out_unlock;
+
+       /* ARP header, plus 2 device addresses, plus 2 IP addresses.  */
+       if (!pskb_may_pull(skb, (sizeof(struct arphdr) +
+                                (2 * dev->addr_len) +
+                                (2 * sizeof(u32)))))
+               goto out_unlock;
+
+       arp = arp_hdr(skb);
+       if (arp->ar_hln != dev->addr_len ||
+           skb->pkt_type == PACKET_OTHERHOST ||
+           skb->pkt_type == PACKET_LOOPBACK ||
+           arp->ar_hrd != htons(ARPHRD_ETHER) ||
+           arp->ar_pro != htons(ETH_P_IP) ||
+           arp->ar_pln != 4)
+               goto out_unlock;
+
+       arp_ptr = (unsigned char *)(arp + 1);
+       arp_ptr += dev->addr_len;
+       memcpy(&sip, arp_ptr, 4);
+       arp_ptr += 4 + dev->addr_len;
+       memcpy(&tip, arp_ptr, 4);
+
+       dprintk("bond_arp_rcv: %s %s/%d av %d sv %d sip %u.%u.%u.%u"
+               " tip %u.%u.%u.%u\n", bond->dev->name, slave->dev->name,
+               slave->state, bond->params.arp_validate,
+               slave_do_arp_validate(bond, slave), NIPQUAD(sip), NIPQUAD(tip));
+
+       /*
+        * Backup slaves won't see the ARP reply, but do come through
+        * here for each ARP probe (so we swap the sip/tip to validate
+        * the probe).  In a "redundant switch, common router" type of
+        * configuration, the ARP probe will (hopefully) travel from
+        * the active, through one switch, the router, then the other
+        * switch before reaching the backup.
+        */
+       if (slave->state == BOND_STATE_ACTIVE)
+               bond_validate_arp(bond, slave, sip, tip);
+       else
+               bond_validate_arp(bond, slave, tip, sip);
+
+out_unlock:
+       read_unlock(&bond->lock);
+out:
+       dev_kfree_skb(skb);
+       return NET_RX_SUCCESS;
+}
+
 /*
  * this function is called regularly to monitor each slave's link
  * ensuring that traffic is being sent and received when arp monitoring
@@ -2489,13 +2740,6 @@ void bond_loadbalance_arp_mon(struct net_device *bond_dev)
 
                bond_select_active_slave(bond);
 
-               if (oldcurrent && !bond->curr_active_slave) {
-                       printk(KERN_INFO DRV_NAME
-                              ": %s: now running without any active "
-                              "interface !\n",
-                              bond_dev->name);
-               }
-
                write_unlock(&bond->curr_slave_lock);
        }
 
@@ -2548,7 +2792,8 @@ void bond_activebackup_arp_mon(struct net_device *bond_dev)
         */
        bond_for_each_slave(bond, slave, i) {
                if (slave->link != BOND_LINK_UP) {
-                       if ((jiffies - slave->dev->last_rx) <= delta_in_ticks) {
+                       if ((jiffies - slave_last_rx(bond, slave)) <=
+                            delta_in_ticks) {
 
                                slave->link = BOND_LINK_UP;
 
@@ -2569,12 +2814,15 @@ void bond_activebackup_arp_mon(struct net_device *bond_dev)
                                        bond->current_arp_slave = NULL;
                                }
 
+                               bond_set_carrier(bond);
+
                                if (slave == bond->curr_active_slave) {
                                        printk(KERN_INFO DRV_NAME
                                               ": %s: %s is up and now the "
                                               "active interface\n",
                                               bond_dev->name,
                                               slave->dev->name);
+                                       netif_carrier_on(bond->dev);
                                } else {
                                        printk(KERN_INFO DRV_NAME
                                               ": %s: backup interface %s is "
@@ -2590,7 +2838,7 @@ void bond_activebackup_arp_mon(struct net_device *bond_dev)
 
                        if ((slave != bond->curr_active_slave) &&
                            (!bond->current_arp_slave) &&
-                           (((jiffies - slave->dev->last_rx) >= 3*delta_in_ticks) &&
+                           (((jiffies - slave_last_rx(bond, slave)) >= 3*delta_in_ticks) &&
                             bond_has_ip(bond))) {
                                /* a backup slave has gone down; three times
                                 * the delta allows the current slave to be
@@ -2637,7 +2885,7 @@ void bond_activebackup_arp_mon(struct net_device *bond_dev)
                 * if it is up and needs to take over as the curr_active_slave
                 */
                if ((((jiffies - slave->dev->trans_start) >= (2*delta_in_ticks)) ||
-           (((jiffies - slave->dev->last_rx) >= (2*delta_in_ticks)) &&
+           (((jiffies - slave_last_rx(bond, slave)) >= (2*delta_in_ticks)) &&
             bond_has_ip(bond))) &&
                    ((jiffies - slave->jiffies) >= 2*delta_in_ticks)) {
 
@@ -2815,9 +3063,15 @@ static void bond_info_show_master(struct seq_file *seq)
        curr = bond->curr_active_slave;
        read_unlock(&bond->curr_slave_lock);
 
-       seq_printf(seq, "Bonding Mode: %s\n",
+       seq_printf(seq, "Bonding Mode: %s",
                   bond_mode_name(bond->params.mode));
 
+       if (bond->params.mode == BOND_MODE_ACTIVEBACKUP &&
+           bond->params.fail_over_mac)
+               seq_printf(seq, " (fail_over_mac)");
+
+       seq_printf(seq, "\n");
+
        if (bond->params.mode == BOND_MODE_XOR ||
                bond->params.mode == BOND_MODE_8023AD) {
                seq_printf(seq, "Transmit Hash Policy: %s (%d)\n",
@@ -2834,7 +3088,8 @@ static void bond_info_show_master(struct seq_file *seq)
                           (curr) ? curr->dev->name : "None");
        }
 
-       seq_printf(seq, "MII Status: %s\n", (curr) ? "up" : "down");
+       seq_printf(seq, "MII Status: %s\n", netif_carrier_ok(bond->dev) ?
+                  "up" : "down");
        seq_printf(seq, "MII Polling Interval (ms): %d\n", bond->params.miimon);
        seq_printf(seq, "Up Delay (ms): %d\n",
                   bond->params.updelay * bond->params.miimon);
@@ -2864,6 +3119,7 @@ static void bond_info_show_master(struct seq_file *seq)
 
        if (bond->params.mode == BOND_MODE_8023AD) {
                struct ad_info ad_info;
+               DECLARE_MAC_BUF(mac);
 
                seq_puts(seq, "\n802.3ad info\n");
                seq_printf(seq, "LACP rate: %s\n",
@@ -2883,13 +3139,8 @@ static void bond_info_show_master(struct seq_file *seq)
                                   ad_info.actor_key);
                        seq_printf(seq, "\tPartner Key: %d\n",
                                   ad_info.partner_key);
-                       seq_printf(seq, "\tPartner Mac Address: %02x:%02x:%02x:%02x:%02x:%02x\n",
-                                  ad_info.partner_system[0],
-                                  ad_info.partner_system[1],
-                                  ad_info.partner_system[2],
-                                  ad_info.partner_system[3],
-                                  ad_info.partner_system[4],
-                                  ad_info.partner_system[5]);
+                       seq_printf(seq, "\tPartner Mac Address: %s\n",
+                                  print_mac(mac, ad_info.partner_system));
                }
        }
 }
@@ -2897,18 +3148,17 @@ static void bond_info_show_master(struct seq_file *seq)
 static void bond_info_show_slave(struct seq_file *seq, const struct slave *slave)
 {
        struct bonding *bond = seq->private;
+       DECLARE_MAC_BUF(mac);
 
        seq_printf(seq, "\nSlave Interface: %s\n", slave->dev->name);
        seq_printf(seq, "MII Status: %s\n",
                   (slave->link == BOND_LINK_UP) ?  "up" : "down");
-       seq_printf(seq, "Link Failure Count: %d\n",
+       seq_printf(seq, "Link Failure Count: %u\n",
                   slave->link_failure_count);
 
        seq_printf(seq,
-                  "Permanent HW addr: %02x:%02x:%02x:%02x:%02x:%02x\n",
-                  slave->perm_hwaddr[0], slave->perm_hwaddr[1],
-                  slave->perm_hwaddr[2], slave->perm_hwaddr[3],
-                  slave->perm_hwaddr[4], slave->perm_hwaddr[5]);
+                  "Permanent HW addr: %s\n",
+                  print_mac(mac, slave->perm_hwaddr));
 
        if (bond->params.mode == BOND_MODE_8023AD) {
                const struct aggregator *agg
@@ -2959,7 +3209,7 @@ static int bond_info_open(struct inode *inode, struct file *file)
        return res;
 }
 
-static struct file_operations bond_info_fops = {
+static const struct file_operations bond_info_fops = {
        .owner   = THIS_MODULE,
        .open    = bond_info_open,
        .read    = seq_read,
@@ -3006,7 +3256,7 @@ static void bond_create_proc_dir(void)
 {
        int len = strlen(DRV_NAME);
 
-       for (bond_proc_dir = proc_net->subdir; bond_proc_dir;
+       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)) {
@@ -3015,7 +3265,7 @@ static void bond_create_proc_dir(void)
        }
 
        if (!bond_proc_dir) {
-               bond_proc_dir = proc_mkdir(DRV_NAME, proc_net);
+               bond_proc_dir = proc_mkdir(DRV_NAME, init_net.proc_net);
                if (bond_proc_dir) {
                        bond_proc_dir->owner = THIS_MODULE;
                } else {
@@ -3050,7 +3300,7 @@ static void bond_destroy_proc_dir(void)
                        bond_proc_dir->owner = NULL;
                }
        } else {
-               remove_proc_entry(DRV_NAME, proc_net);
+               remove_proc_entry(DRV_NAME, init_net.proc_net);
                bond_proc_dir = NULL;
        }
 }
@@ -3116,6 +3366,11 @@ static int bond_slave_netdev_event(unsigned long event, struct net_device *slave
                 * ... Or is it this?
                 */
                break;
+       case NETDEV_GOING_DOWN:
+               dprintk("slave %s is going down\n", slave_dev->name);
+               if (bond->setup_by_slave)
+                       bond_release_and_destroy(bond_dev, slave_dev);
+               break;
        case NETDEV_CHANGEMTU:
                /*
                 * TODO: Should slaves be allowed to
@@ -3149,7 +3404,7 @@ static int bond_slave_netdev_event(unsigned long event, struct net_device *slave
  * bond_netdev_event: handle netdev notifier chain events.
  *
  * This function receives events for the netdev chain.  The caller (an
- * ioctl handler calling notifier_call_chain) holds the necessary
+ * ioctl handler calling blocking_notifier_call_chain) holds the necessary
  * locks for us to safely manipulate the slave devices (RTNL lock,
  * dev_probe_lock).
  */
@@ -3157,10 +3412,16 @@ static int bond_netdev_event(struct notifier_block *this, unsigned long event, v
 {
        struct net_device *event_dev = (struct net_device *)ptr;
 
+       if (event_dev->nd_net != &init_net)
+               return NOTIFY_DONE;
+
        dprintk("event_dev: %s, event: %lx\n",
                (event_dev ? event_dev->name : "None"),
                event);
 
+       if (!(event_dev->priv_flags & IFF_BONDING))
+               return NOTIFY_DONE;
+
        if (event_dev->flags & IFF_MASTER) {
                dprintk("IFF_MASTER\n");
                return bond_master_netdev_event(event, event_dev);
@@ -3208,7 +3469,7 @@ static int bond_inetaddr_event(struct notifier_block *this, unsigned long event,
 
                list_for_each_entry_safe(vlan, vlan_next, &bond->vlan_list,
                                         vlan_list) {
-                       vlan_dev = bond->vlgrp->vlan_devices[vlan->vlan_id];
+                       vlan_dev = vlan_group_get_device(bond->vlgrp, vlan->vlan_id);
                        if (vlan_dev == event_dev) {
                                switch (event) {
                                case NETDEV_UP:
@@ -3256,10 +3517,31 @@ static void bond_unregister_lacpdu(struct bonding *bond)
        dev_remove_pack(&(BOND_AD_INFO(bond).ad_pkt_type));
 }
 
+void bond_register_arp(struct bonding *bond)
+{
+       struct packet_type *pt = &bond->arp_mon_pt;
+
+       if (pt->type)
+               return;
+
+       pt->type = htons(ETH_P_ARP);
+       pt->dev = bond->dev;
+       pt->func = bond_arp_rcv;
+       dev_add_pack(pt);
+}
+
+void bond_unregister_arp(struct bonding *bond)
+{
+       struct packet_type *pt = &bond->arp_mon_pt;
+
+       dev_remove_pack(pt);
+       pt->type = 0;
+}
+
 /*---------------------------- Hashing Policies -----------------------------*/
 
 /*
- * Hash for the the output device based upon layer 3 and layer 4 data. If
+ * Hash for the output device based upon layer 3 and layer 4 data. If
  * 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()
  */
@@ -3267,15 +3549,15 @@ static int bond_xmit_hash_policy_l34(struct sk_buff *skb,
                                    struct net_device *bond_dev, int count)
 {
        struct ethhdr *data = (struct ethhdr *)skb->data;
-       struct iphdr *iph = skb->nh.iph;
-       u16 *layer4hdr = (u16 *)((u32 *)iph + iph->ihl);
+       struct iphdr *iph = ip_hdr(skb);
+       __be16 *layer4hdr = (__be16 *)((u32 *)iph + iph->ihl);
        int layer4_xor = 0;
 
        if (skb->protocol == __constant_htons(ETH_P_IP)) {
                if (!(iph->frag_off & __constant_htons(IP_MF|IP_OFFSET)) &&
                    (iph->protocol == IPPROTO_TCP ||
                     iph->protocol == IPPROTO_UDP)) {
-                       layer4_xor = htons((*layer4hdr ^ *(layer4hdr + 1)));
+                       layer4_xor = ntohs((*layer4hdr ^ *(layer4hdr + 1)));
                }
                return (layer4_xor ^
                        ((ntohl(iph->saddr ^ iph->daddr)) & 0xffff)) % count;
@@ -3342,6 +3624,9 @@ static int bond_open(struct net_device *bond_dev)
                } else {
                        arp_timer->function = (void *)&bond_loadbalance_arp_mon;
                }
+               if (bond->params.arp_validate)
+                       bond_register_arp(bond);
+
                add_timer(arp_timer);
        }
 
@@ -3369,9 +3654,11 @@ static int bond_close(struct net_device *bond_dev)
                bond_unregister_lacpdu(bond);
        }
 
+       if (bond->params.arp_validate)
+               bond_unregister_arp(bond);
+
        write_lock_bh(&bond->lock);
 
-       bond_mc_list_destroy(bond);
 
        /* signal timers not to re-arm */
        bond->kill_timers = 1;
@@ -3402,8 +3689,6 @@ static int bond_close(struct net_device *bond_dev)
                break;
        }
 
-       /* Release the bonded slaves */
-       bond_release_all(bond_dev);
 
        if ((bond->params.mode == BOND_MODE_TLB) ||
            (bond->params.mode == BOND_MODE_ALB)) {
@@ -3429,7 +3714,6 @@ static struct net_device_stats *bond_get_stats(struct net_device *bond_dev)
 
        bond_for_each_slave(bond, slave, i) {
                sstats = slave->dev->get_stats(slave->dev);
-
                stats->rx_packets += sstats->rx_packets;
                stats->rx_bytes += sstats->rx_bytes;
                stats->rx_errors += sstats->rx_errors;
@@ -3498,7 +3782,7 @@ static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd
                        mii->val_out = 0;
                        read_lock_bh(&bond->lock);
                        read_lock(&bond->curr_slave_lock);
-                       if (bond->curr_active_slave) {
+                       if (netif_carrier_ok(bond->dev)) {
                                mii->val_out = BMSR_LSTATUS;
                        }
                        read_unlock(&bond->curr_slave_lock);
@@ -3548,7 +3832,7 @@ static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd
        }
 
        down_write(&(bonding_rwsem));
-       slave_dev = dev_get_by_name(ifr->ifr_slave);
+       slave_dev = dev_get_by_name(&init_net, ifr->ifr_slave);
 
        dprintk("slave_dev=%p: \n", slave_dev);
 
@@ -3719,6 +4003,13 @@ static int bond_set_mac_address(struct net_device *bond_dev, void *addr)
 
        dprintk("bond=%p, name=%s\n", bond, (bond_dev ? bond_dev->name : "None"));
 
+       /*
+        * If fail_over_mac is enabled, do nothing and return success.
+        * Returning an error causes ifenslave to fail.
+        */
+       if (bond->params.fail_over_mac)
+               return 0;
+
        if (!is_valid_ether_addr(sa->sa_data)) {
                return -EADDRNOTAVAIL;
        }
@@ -3828,42 +4119,6 @@ out:
        return 0;
 }
 
-static void bond_activebackup_xmit_copy(struct sk_buff *skb,
-                                        struct bonding *bond,
-                                        struct slave *slave)
-{
-       struct sk_buff *skb2 = skb_copy(skb, GFP_ATOMIC);
-       struct ethhdr *eth_data;
-       u8 *hwaddr;
-       int res;
-
-       if (!skb2) {
-               printk(KERN_ERR DRV_NAME ": Error: "
-                      "bond_activebackup_xmit_copy(): skb_copy() failed\n");
-               return;
-       }
-
-       skb2->mac.raw = (unsigned char *)skb2->data;
-       eth_data = eth_hdr(skb2);
-
-       /* Pick an appropriate source MAC address
-        *      -- use slave's perm MAC addr, unless used by bond
-        *      -- otherwise, borrow active slave's perm MAC addr
-        *         since that will not be used
-        */
-       hwaddr = slave->perm_hwaddr;
-       if (!memcmp(eth_data->h_source, hwaddr, ETH_ALEN))
-               hwaddr = bond->curr_active_slave->perm_hwaddr;
-
-       /* Set source MAC address appropriately */
-       memcpy(eth_data->h_source, hwaddr, ETH_ALEN);
-
-       res = bond_dev_queue_xmit(bond, skb2, slave->dev);
-       if (res)
-               dev_kfree_skb(skb2);
-
-       return;
-}
 
 /*
  * in active-backup mode, we know that bond->curr_active_slave is always valid if
@@ -3884,21 +4139,6 @@ static int bond_xmit_activebackup(struct sk_buff *skb, struct net_device *bond_d
        if (!bond->curr_active_slave)
                goto out;
 
-       /* Xmit IGMP frames on all slaves to ensure rapid fail-over
-          for multicast traffic on snooping switches */
-       if (skb->protocol == __constant_htons(ETH_P_IP) &&
-           skb->nh.iph->protocol == IPPROTO_IGMP) {
-               struct slave *slave, *active_slave;
-               int i;
-
-               active_slave = bond->curr_active_slave;
-               bond_for_each_slave_from_to(bond, slave, i, active_slave->next,
-                                           active_slave->prev)
-                       if (IS_UP(slave->dev) &&
-                           (slave->link == BOND_LINK_UP))
-                               bond_activebackup_xmit_copy(skb, bond, slave);
-       }
-
        res = bond_dev_queue_xmit(bond, skb, bond->curr_active_slave->dev);
 
 out:
@@ -4049,14 +4289,17 @@ void bond_set_mode_ops(struct bonding *bond, int mode)
                bond_dev->hard_start_xmit = bond_xmit_broadcast;
                break;
        case BOND_MODE_8023AD:
+               bond_set_master_3ad_flags(bond);
                bond_dev->hard_start_xmit = bond_3ad_xmit_xor;
                if (bond->params.xmit_policy == BOND_XMIT_POLICY_LAYER34)
                        bond->xmit_hash_policy = bond_xmit_hash_policy_l34;
                else
                        bond->xmit_hash_policy = bond_xmit_hash_policy_l2;
                break;
-       case BOND_MODE_TLB:
        case BOND_MODE_ALB:
+               bond_set_master_alb_flags(bond);
+               /* FALLTHRU */
+       case BOND_MODE_TLB:
                bond_dev->hard_start_xmit = bond_alb_xmit;
                bond_dev->set_mac_address = bond_alb_set_mac_address;
                break;
@@ -4078,9 +4321,7 @@ static void bond_ethtool_get_drvinfo(struct net_device *bond_dev,
        snprintf(drvinfo->fw_version, 32, "%d", BOND_ABI_VERSION);
 }
 
-static struct ethtool_ops bond_ethtool_ops = {
-       .get_tx_csum            = ethtool_op_get_tx_csum,
-       .get_sg                 = ethtool_op_get_sg,
+static const struct ethtool_ops bond_ethtool_ops = {
        .get_drvinfo            = bond_ethtool_get_drvinfo,
 };
 
@@ -4106,6 +4347,8 @@ static int bond_init(struct net_device *bond_dev, struct bond_params *params)
        bond->current_arp_slave = NULL;
        bond->primary_slave = NULL;
        bond->dev = bond_dev;
+       bond->send_grat_arp = 0;
+       bond->setup_by_slave = 0;
        INIT_LIST_HEAD(&bond->vlan_list);
 
        /* Initialize the device entry points */
@@ -4125,6 +4368,7 @@ static int bond_init(struct net_device *bond_dev, struct bond_params *params)
        /* Initialize the device options */
        bond_dev->tx_queue_len = 0;
        bond_dev->flags |= IFF_MASTER|IFF_MULTICAST;
+       bond_dev->priv_flags |= IFF_BONDING;
 
        /* At first, we block adding VLANs. That's the only way to
         * prevent problems that occur when adding VLANs over an
@@ -4133,7 +4377,7 @@ static int bond_init(struct net_device *bond_dev, struct bond_params *params)
         */
        bond_dev->features |= NETIF_F_VLAN_CHALLENGED;
 
-       /* don't acquire bond device's xmit_lock when 
+       /* don't acquire bond device's netif_tx_lock when
         * transmitting */
        bond_dev->features |= NETIF_F_LLTX;
 
@@ -4153,7 +4397,6 @@ static int bond_init(struct net_device *bond_dev, struct bond_params *params)
 #ifdef CONFIG_PROC_FS
        bond_create_proc_entry(bond);
 #endif
-
        list_add_tail(&bond->bond_list, &bond_dev_list);
 
        return 0;
@@ -4183,8 +4426,11 @@ static void bond_free_all(void)
        list_for_each_entry_safe(bond, nxt, &bond_dev_list, bond_list) {
                struct net_device *bond_dev = bond->dev;
 
-               unregister_netdevice(bond_dev);
+               bond_mc_list_destroy(bond);
+               /* Release the bonded slaves */
+               bond_release_all(bond_dev);
                bond_deinit(bond_dev);
+               unregister_netdevice(bond_dev);
        }
 
 #ifdef CONFIG_PROC_FS
@@ -4216,6 +4462,8 @@ int bond_parse_parm(char *mode_arg, struct bond_parm_tbl *tbl)
 
 static int bond_check_params(struct bond_params *params)
 {
+       int arp_validate_value;
+
        /*
         * Convert string parameters.
         */
@@ -4404,7 +4652,7 @@ static int bond_check_params(struct bond_params *params)
                               arp_ip_target[arp_ip_count]);
                        arp_interval = 0;
                } else {
-                       u32 ip = in_aton(arp_ip_target[arp_ip_count]);
+                       __be32 ip = in_aton(arp_ip_target[arp_ip_count]);
                        arp_target[arp_ip_count] = ip;
                }
        }
@@ -4419,6 +4667,29 @@ static int bond_check_params(struct bond_params *params)
                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");
+                       return -EINVAL;
+               }
+               if (!arp_interval) {
+                       printk(KERN_ERR DRV_NAME
+                              ": 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",
+                              arp_validate == NULL ? "NULL" : arp_validate);
+                       return -EINVAL;
+               }
+       } else
+               arp_validate_value = 0;
+
        if (miimon) {
                printk(KERN_INFO DRV_NAME
                       ": MII link monitoring set to %d ms\n",
@@ -4427,8 +4698,10 @@ static int bond_check_params(struct bond_params *params)
                int i;
 
                printk(KERN_INFO DRV_NAME
-                      ": ARP monitoring set to %d ms with %d target(s):",
-                      arp_interval, arp_ip_count);
+                      ": 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]);
@@ -4457,16 +4730,23 @@ static int bond_check_params(struct bond_params *params)
                primary = NULL;
        }
 
+       if (fail_over_mac && (bond_mode != BOND_MODE_ACTIVEBACKUP))
+               printk(KERN_WARNING DRV_NAME
+                      ": Warning: fail_over_mac only affects "
+                      "active-backup mode.\n");
+
        /* fill params struct with the proper values */
        params->mode = bond_mode;
        params->xmit_policy = xmit_hashtype;
        params->miimon = miimon;
        params->arp_interval = arp_interval;
+       params->arp_validate = arp_validate_value;
        params->updelay = updelay;
        params->downdelay = downdelay;
        params->use_carrier = use_carrier;
        params->lacp_fast = lacp_fast;
        params->primary[0] = 0;
+       params->fail_over_mac = fail_over_mac;
 
        if (primary) {
                strncpy(params->primary, primary, IFNAMSIZ);
@@ -4478,7 +4758,10 @@ static int bond_check_params(struct bond_params *params)
        return 0;
 }
 
+static struct lock_class_key bonding_netdev_xmit_lock_key;
+
 /* 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.
  */
@@ -4488,7 +4771,8 @@ int bond_create(char *name, struct bond_params *params, struct bonding **newbond
        int res;
 
        rtnl_lock();
-       bond_dev = alloc_netdev(sizeof(struct bonding), name, ether_setup);
+       bond_dev = alloc_netdev(sizeof(struct bonding), name ? name : "",
+                               ether_setup);
        if (!bond_dev) {
                printk(KERN_ERR DRV_NAME
                       ": %s: eek! can't alloc netdev!\n",
@@ -4497,6 +4781,12 @@ int bond_create(char *name, struct bond_params *params, struct bonding **newbond
                goto out_rtnl;
        }
 
+       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.
@@ -4507,25 +4797,33 @@ int bond_create(char *name, struct bond_params *params, struct bonding **newbond
                goto out_netdev;
        }
 
-       SET_MODULE_OWNER(bond_dev);
-
        res = register_netdevice(bond_dev);
        if (res < 0) {
                goto out_bond;
        }
+
+       lockdep_set_class(&bond_dev->_xmit_lock, &bonding_netdev_xmit_lock_key);
+
        if (newbond)
                *newbond = bond_dev->priv;
 
+       netif_carrier_off(bond_dev);
+
        rtnl_unlock(); /* allows sysfs registration of net device */
        res = bond_create_sysfs_entry(bond_dev->priv);
-       goto done;
+       if (res < 0) {
+               rtnl_lock();
+               goto out_bond;
+       }
+
+       return 0;
+
 out_bond:
        bond_deinit(bond_dev);
 out_netdev:
        free_netdev(bond_dev);
 out_rtnl:
        rtnl_unlock();
-done:
        return res;
 }
 
@@ -4533,7 +4831,6 @@ static int __init bonding_init(void)
 {
        int i;
        int res;
-       char new_bond_name[8];  /* Enough room for 999 bonds at init. */
 
        printk(KERN_INFO "%s", version);
 
@@ -4546,8 +4843,7 @@ static int __init bonding_init(void)
        bond_create_proc_dir();
 #endif
        for (i = 0; i < max_bonds; i++) {
-               sprintf(new_bond_name, "bond%d",i);
-               res = bond_create(new_bond_name,&bonding_defaults, NULL);
+               res = bond_create(NULL, &bonding_defaults, NULL);
                if (res)
                        goto err;
        }