fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / drivers / net / bonding / bond_main.c
index 6917b66..6482aed 100644 (file)
  *     b: if a hw mac address already is there, eth0's hw mac address
  *        will then be set from bond0.
  *
- * v0.1 - first working version.
- * v0.2 - changed stats to be calculated by summing slaves stats.
- *
- * Changes:
- * Arnaldo Carvalho de Melo <acme@conectiva.com.br>
- * - fix leaks on failure at bond_init
- *
- * 2000/09/30 - Willy Tarreau <willy at meta-x.org>
- *     - added trivial code to release a slave device.
- *     - fixed security bug (CAP_NET_ADMIN not checked)
- *     - implemented MII link monitoring to disable dead links :
- *       All MII capable slaves are checked every <miimon> milliseconds
- *       (100 ms seems good). This value can be changed by passing it to
- *       insmod. A value of zero disables the monitoring (default).
- *     - fixed an infinite loop in bond_xmit_roundrobin() when there's no
- *       good slave.
- *     - made the code hopefully SMP safe
- *
- * 2000/10/03 - Willy Tarreau <willy at meta-x.org>
- *     - optimized slave lists based on relevant suggestions from Thomas Davis
- *     - implemented active-backup method to obtain HA with two switches:
- *       stay as long as possible on the same active interface, while we
- *       also monitor the backup one (MII link status) because we want to know
- *       if we are able to switch at any time. ( pass "mode=1" to insmod )
- *     - lots of stress testings because we need it to be more robust than the
- *       wires ! :->
- *
- * 2000/10/09 - Willy Tarreau <willy at meta-x.org>
- *     - added up and down delays after link state change.
- *     - optimized the slaves chaining so that when we run forward, we never
- *       repass through the bond itself, but we can find it by searching
- *       backwards. Renders the deletion more difficult, but accelerates the
- *       scan.
- *     - smarter enslaving and releasing.
- *     - finer and more robust SMP locking
- *
- * 2000/10/17 - Willy Tarreau <willy at meta-x.org>
- *     - fixed two potential SMP race conditions
- *
- * 2000/10/18 - Willy Tarreau <willy at meta-x.org>
- *     - small fixes to the monitoring FSM in case of zero delays
- * 2000/11/01 - Willy Tarreau <willy at meta-x.org>
- *     - fixed first slave not automatically used in trunk mode.
- * 2000/11/10 : spelling of "EtherChannel" corrected.
- * 2000/11/13 : fixed a race condition in case of concurrent accesses to ioctl().
- * 2000/12/16 : fixed improper usage of rtnl_exlock_nowait().
- *
- * 2001/1/3 - Chad N. Tindel <ctindel at ieee dot org>
- *     - The bonding driver now simulates MII status monitoring, just like
- *       a normal network device.  It will show that the link is down iff
- *       every slave in the bond shows that their links are down.  If at least
- *       one slave is up, the bond's MII status will appear as up.
- *
- * 2001/2/7 - Chad N. Tindel <ctindel at ieee dot org>
- *     - Applications can now query the bond from user space to get
- *       information which may be useful.  They do this by calling
- *       the BOND_INFO_QUERY ioctl.  Once the app knows how many slaves
- *       are in the bond, it can call the BOND_SLAVE_INFO_QUERY ioctl to
- *       get slave specific information (# link failures, etc).  See
- *       <linux/if_bonding.h> for more details.  The structs of interest
- *       are ifbond and ifslave.
- *
- * 2001/4/5 - Chad N. Tindel <ctindel at ieee dot org>
- *     - Ported to 2.4 Kernel
- *
- * 2001/5/2 - Jeffrey E. Mast <jeff at mastfamily dot com>
- *     - When a device is detached from a bond, the slave device is no longer
- *       left thinking that is has a master.
- *
- * 2001/5/16 - Jeffrey E. Mast <jeff at mastfamily dot com>
- *     - memset did not appropriately initialized the bond rw_locks. Used
- *       rwlock_init to initialize to unlocked state to prevent deadlock when
- *       first attempting a lock
- *     - Called SET_MODULE_OWNER for bond device
- *
- * 2001/5/17 - Tim Anderson <tsa at mvista.com>
- *     - 2 paths for releasing for slave release; 1 through ioctl
- *       and 2) through close. Both paths need to release the same way.
- *     - the free slave in bond release is changing slave status before
- *       the free. The netdev_set_master() is intended to change slave state
- *       so it should not be done as part of the release process.
- *     - Simple rule for slave state at release: only the active in A/B and
- *       only one in the trunked case.
- *
- * 2001/6/01 - Tim Anderson <tsa at mvista.com>
- *     - Now call dev_close when releasing a slave so it doesn't screw up
- *       out routing table.
- *
- * 2001/6/01 - Chad N. Tindel <ctindel at ieee dot org>
- *     - Added /proc support for getting bond and slave information.
- *       Information is in /proc/net/<bond device>/info.
- *     - Changed the locking when calling bond_close to prevent deadlock.
- *
- * 2001/8/05 - Janice Girouard <girouard at us.ibm.com>
- *     - correct problem where refcnt of slave is not incremented in bond_ioctl
- *       so the system hangs when halting.
- *     - correct locking problem when unable to malloc in bond_enslave.
- *     - adding bond_xmit_xor logic.
- *     - adding multiple bond device support.
- *
- * 2001/8/13 - Erik Habbinga <erik_habbinga at hp dot com>
- *     - correct locking problem with rtnl_exlock_nowait
- *
- * 2001/8/23 - Janice Girouard <girouard at us.ibm.com>
- *     - bzero initial dev_bonds, to correct oops
- *     - convert SIOCDEVPRIVATE to new MII ioctl calls
- *
- * 2001/9/13 - Takao Indoh <indou dot takao at jp dot fujitsu dot com>
- *     - Add the BOND_CHANGE_ACTIVE ioctl implementation
- *
- * 2001/9/14 - Mark Huth <mhuth at mvista dot com>
- *     - Change MII_LINK_READY to not check for end of auto-negotiation,
- *       but only for an up link.
- *
- * 2001/9/20 - Chad N. Tindel <ctindel at ieee dot org>
- *     - Add the device field to bonding_t.  Previously the net_device
- *       corresponding to a bond wasn't available from the bonding_t
- *       structure.
- *
- * 2001/9/25 - Janice Girouard <girouard at us.ibm.com>
- *     - add arp_monitor for active backup mode
- *
- * 2001/10/23 - Takao Indoh <indou dot takao at jp dot fujitsu dot com>
- *     - Various memory leak fixes
- *
- * 2001/11/5 - Mark Huth <mark dot huth at mvista dot com>
- *     - Don't take rtnl lock in bond_mii_monitor as it deadlocks under
- *       certain hotswap conditions.
- *       Note:  this same change may be required in bond_arp_monitor ???
- *     - Remove possibility of calling bond_sethwaddr with NULL slave_dev ptr
- *     - Handle hot swap ethernet interface deregistration events to remove
- *       kernel oops following hot swap of enslaved interface
- *
- * 2002/1/2 - Chad N. Tindel <ctindel at ieee dot org>
- *     - Restore original slave flags at release time.
- *
- * 2002/02/18 - Erik Habbinga <erik_habbinga at hp dot com>
- *     - bond_release(): calling kfree on our_slave after call to
- *       bond_restore_slave_flags, not before
- *     - bond_enslave(): saving slave flags into original_flags before
- *       call to netdev_set_master, so the IFF_SLAVE flag doesn't end
- *       up in original_flags
- *
- * 2002/04/05 - Mark Smith <mark.smith at comdev dot cc> and
- *              Steve Mead <steve.mead at comdev dot cc>
- *     - Port Gleb Natapov's multicast support patchs from 2.4.12
- *       to 2.4.18 adding support for multicast.
- *
- * 2002/06/10 - Tony Cureington <tony.cureington * hp_com>
- *     - corrected uninitialized pointer (ifr.ifr_data) in bond_check_dev_link;
- *       actually changed function to use MIIPHY, then MIIREG, and finally
- *       ETHTOOL to determine the link status
- *     - fixed bad ifr_data pointer assignments in bond_ioctl
- *     - corrected mode 1 being reported as active-backup in bond_get_info;
- *       also added text to distinguish type of load balancing (rr or xor)
- *     - change arp_ip_target module param from "1-12s" (array of 12 ptrs)
- *       to "s" (a single ptr)
- *
- * 2002/08/30 - Jay Vosburgh <fubar at us dot ibm dot com>
- *     - Removed acquisition of xmit_lock in set_multicast_list; caused
- *       deadlock on SMP (lock is held by caller).
- *     - Revamped SIOCGMIIPHY, SIOCGMIIREG portion of bond_check_dev_link().
- *
- * 2002/09/18 - Jay Vosburgh <fubar at us dot ibm dot com>
- *     - Fixed up bond_check_dev_link() (and callers): removed some magic
- *      numbers, banished local MII_ defines, wrapped ioctl calls to
- *      prevent EFAULT errors
- *
- * 2002/9/30 - Jay Vosburgh <fubar at us dot ibm dot com>
- *     - make sure the ip target matches the arp_target before saving the
- *      hw address.
- *
- * 2002/9/30 - Dan Eisner <eisner at 2robots dot com>
- *     - make sure my_ip is set before taking down the link, since
- *      not all switches respond if the source ip is not set.
- *
- * 2002/10/8 - Janice Girouard <girouard at us dot ibm dot com>
- *     - read in the local ip address when enslaving a device
- *     - add primary support
- *     - make sure 2*arp_interval has passed when a new device
- *       is brought on-line before taking it down.
- *
- * 2002/09/11 - Philippe De Muyter <phdm at macqel dot be>
- *     - Added bond_xmit_broadcast logic.
- *     - Added bond_mode() support function.
- *
- * 2002/10/26 - Laurent Deniel <laurent.deniel at free.fr>
- *     - allow to register multicast addresses only on active slave
- *       (useful in active-backup mode)
- *     - add multicast module parameter
- *     - fix deletion of multicast groups after unloading module
- *
- * 2002/11/06 - Kameshwara Rayaprolu <kameshwara.rao * wipro_com>
- *     - Changes to prevent panic from closing the device twice; if we close
- *       the device in bond_release, we must set the original_flags to down
- *       so it won't be closed again by the network layer.
- *
- * 2002/11/07 - Tony Cureington <tony.cureington * hp_com>
- *     - Fix arp_target_hw_addr memory leak
- *     - Created activebackup_arp_monitor function to handle arp monitoring
- *       in active backup mode - the bond_arp_monitor had several problems...
- *       such as allowing slaves to tx arps sequentially without any delay
- *       for a response
- *     - Renamed bond_arp_monitor to loadbalance_arp_monitor and re-wrote
- *       this function to just handle arp monitoring in load-balancing mode;
- *       it is a lot more compact now
- *     - Changes to ensure one and only one slave transmits in active-backup
- *       mode
- *     - Robustesize parameters; warn users about bad combinations of
- *       parameters; also if miimon is specified and a network driver does
- *       not support MII or ETHTOOL, inform the user of this
- *     - Changes to support link_failure_count when in arp monitoring mode
- *     - Fix up/down delay reported in /proc
- *     - Added version; log version; make version available from "modinfo -d"
- *     - Fixed problem in bond_check_dev_link - if the first IOCTL (SIOCGMIIPH)
- *      failed, the ETHTOOL ioctl never got a chance
- *
- * 2002/11/16 - Laurent Deniel <laurent.deniel at free.fr>
- *     - fix multicast handling in activebackup_arp_monitor
- *     - remove one unnecessary and confusing curr_active_slave == slave test
- *      in activebackup_arp_monitor
- *
- *  2002/11/17 - Laurent Deniel <laurent.deniel at free.fr>
- *     - fix bond_slave_info_query when slave_id = num_slaves
- *
- *  2002/11/19 - Janice Girouard <girouard at us dot ibm dot com>
- *     - correct ifr_data reference.  Update ifr_data reference
- *       to mii_ioctl_data struct values to avoid confusion.
- *
- *  2002/11/22 - Bert Barbe <bert.barbe at oracle dot com>
- *      - Add support for multiple arp_ip_target
- *
- *  2002/12/13 - Jay Vosburgh <fubar at us dot ibm dot com>
- *     - Changed to allow text strings for mode and multicast, e.g.,
- *       insmod bonding mode=active-backup.  The numbers still work.
- *       One change: an invalid choice will cause module load failure,
- *       rather than the previous behavior of just picking one.
- *     - Minor cleanups; got rid of dup ctype stuff, atoi function
- *
- * 2003/02/07 - Jay Vosburgh <fubar at us dot ibm dot com>
- *     - Added use_carrier module parameter that causes miimon to
- *       use netif_carrier_ok() test instead of MII/ETHTOOL ioctls.
- *     - Minor cleanups; consolidated ioctl calls to one function.
- *
- * 2003/02/07 - Tony Cureington <tony.cureington * hp_com>
- *     - Fix bond_mii_monitor() logic error that could result in
- *       bonding round-robin mode ignoring links after failover/recovery
- *
- * 2003/03/17 - Jay Vosburgh <fubar at us dot ibm dot com>
- *     - kmalloc fix (GFP_KERNEL to GFP_ATOMIC) reported by
- *       Shmulik dot Hen at intel.com.
- *     - Based on discussion on mailing list, changed use of
- *       update_slave_cnt(), created wrapper functions for adding/removing
- *       slaves, changed bond_xmit_xor() to check slave_cnt instead of
- *       checking slave and slave->dev (which only worked by accident).
- *     - Misc code cleanup: get arp_send() prototype from header file,
- *       add max_bonds to bonding.txt.
- *
- * 2003/03/18 - Tsippy Mendelson <tsippy.mendelson at intel dot com> and
- *             Shmulik Hen <shmulik.hen at intel dot com>
- *     - Make sure only bond_attach_slave() and bond_detach_slave() can
- *       manipulate the slave list, including slave_cnt, even when in
- *       bond_release_all().
- *     - Fixed hang in bond_release() with traffic running:
- *       netdev_set_master() must not be called from within the bond lock.
- *
- * 2003/03/18 - Tsippy Mendelson <tsippy.mendelson at intel dot com> and
- *             Shmulik Hen <shmulik.hen at intel dot com>
- *     - Fixed hang in bond_enslave() with traffic running:
- *       netdev_set_master() must not be called from within the bond lock.
- *
- * 2003/03/18 - Amir Noam <amir.noam at intel dot com>
- *     - Added support for getting slave's speed and duplex via ethtool.
- *       Needed for 802.3ad and other future modes.
- *
- * 2003/03/18 - Tsippy Mendelson <tsippy.mendelson at intel dot com> and
- *             Shmulik Hen <shmulik.hen at intel dot com>
- *     - Enable support of modes that need to use the unique mac address of
- *       each slave.
- *       * bond_enslave(): Moved setting the slave's mac address, and
- *         openning it, from the application to the driver. This breaks
- *         backward comaptibility with old versions of ifenslave that open
- *          the slave before enalsving it !!!.
- *       * bond_release(): The driver also takes care of closing the slave
- *         and restoring its original mac address.
- *     - Removed the code that restores all base driver's flags.
- *       Flags are automatically restored once all undo stages are done
- *       properly.
- *     - Block possibility of enslaving before the master is up. This
- *       prevents putting the system in an unstable state.
- *
- * 2003/03/18 - Amir Noam <amir.noam at intel dot com>,
- *             Tsippy Mendelson <tsippy.mendelson at intel dot com> and
- *             Shmulik Hen <shmulik.hen at intel dot com>
- *     - Added support for IEEE 802.3ad Dynamic link aggregation mode.
- *
- * 2003/05/01 - Amir Noam <amir.noam at intel dot com>
- *     - Added ABI version control to restore compatibility between
- *       new/old ifenslave and new/old bonding.
- *
- * 2003/05/01 - Shmulik Hen <shmulik.hen at intel dot com>
- *     - Fixed bug in bond_release_all(): save old value of curr_active_slave
- *       before setting it to NULL.
- *     - Changed driver versioning scheme to include version number instead
- *       of release date (that is already in another field). There are 3
- *       fields X.Y.Z where:
- *             X - Major version - big behavior changes
- *             Y - Minor version - addition of features
- *             Z - Extra version - minor changes and bug fixes
- *       The current version is 1.0.0 as a base line.
- *
- * 2003/05/01 - Tsippy Mendelson <tsippy.mendelson at intel dot com> and
- *             Amir Noam <amir.noam at intel dot com>
- *     - Added support for lacp_rate module param.
- *     - Code beautification and style changes (mainly in comments).
- *       new version - 1.0.1
- *
- * 2003/05/01 - Shmulik Hen <shmulik.hen at intel dot com>
- *     - Based on discussion on mailing list, changed locking scheme
- *       to use lock/unlock or lock_bh/unlock_bh appropriately instead
- *       of lock_irqsave/unlock_irqrestore. The new scheme helps exposing
- *       hidden bugs and solves system hangs that occurred due to the fact
- *       that holding lock_irqsave doesn't prevent softirqs from running.
- *       This also increases total throughput since interrupts are not
- *       blocked on each transmitted packets or monitor timeout.
- *       new version - 2.0.0
- *
- * 2003/05/01 - Shmulik Hen <shmulik.hen at intel dot com>
- *     - Added support for Transmit load balancing mode.
- *     - Concentrate all assignments of curr_active_slave to a single point
- *       so specific modes can take actions when the primary adapter is
- *       changed.
- *     - Take the updelay parameter into consideration during bond_enslave
- *       since some adapters loose their link during setting the device.
- *     - Renamed bond_3ad_link_status_changed() to
- *       bond_3ad_handle_link_change() for compatibility with TLB.
- *       new version - 2.1.0
- *
- * 2003/05/01 - Tsippy Mendelson <tsippy.mendelson at intel dot com>
- *     - Added support for Adaptive load balancing mode which is
- *       equivalent to Transmit load balancing + Receive load balancing.
- *       new version - 2.2.0
- *
- * 2003/05/15 - Jay Vosburgh <fubar at us dot ibm dot com>
- *     - Applied fix to activebackup_arp_monitor posted to bonding-devel
- *       by Tony Cureington <tony.cureington * hp_com>.  Fixes ARP
- *       monitor endless failover bug.  Version to 2.2.10
- *
- * 2003/05/20 - Amir Noam <amir.noam at intel dot com>
- *     - Fixed bug in ABI version control - Don't commit to a specific
- *       ABI version if receiving unsupported ioctl commands.
- *
- * 2003/05/22 - Jay Vosburgh <fubar at us dot ibm dot com>
- *     - Fix ifenslave -c causing bond to loose existing routes;
- *       added bond_set_mac_address() that doesn't require the
- *       bond to be down.
- *     - In conjunction with fix for ifenslave -c, in
- *       bond_change_active(), changing to the already active slave
- *       is no longer an error (it successfully does nothing).
- *
- * 2003/06/30 - Amir Noam <amir.noam at intel dot com>
- *     - Fixed bond_change_active() for ALB/TLB modes.
- *       Version to 2.2.14.
- *
- * 2003/07/29 - Amir Noam <amir.noam at intel dot com>
- *     - Fixed ARP monitoring bug.
- *       Version to 2.2.15.
- *
- * 2003/07/31 - Willy Tarreau <willy at ods dot org>
- *     - Fixed kernel panic when using ARP monitoring without
- *       setting bond's IP address.
- *       Version to 2.2.16.
- *
- * 2003/08/06 - Amir Noam <amir.noam at intel dot com>
- *     - Back port from 2.6: use alloc_netdev(); fix /proc handling;
- *       made stats a part of bond struct so no need to allocate
- *       and free it separately; use standard list operations instead
- *       of pre-allocated array of bonds.
- *       Version to 2.3.0.
- *
- * 2003/08/07 - Jay Vosburgh <fubar at us dot ibm dot com>,
- *            Amir Noam <amir.noam at intel dot com> and
- *            Shmulik Hen <shmulik.hen at intel dot com>
- *     - Propagating master's settings: Distinguish between modes that
- *       use a primary slave from those that don't, and propagate settings
- *       accordingly; Consolidate change_active opeartions and add
- *       reselect_active and find_best opeartions; Decouple promiscuous
- *       handling from the multicast mode setting; Add support for changing
- *       HW address and MTU with proper unwind; Consolidate procfs code,
- *       add CHANGENAME handler; Enhance netdev notification handling.
- *       Version to 2.4.0.
- *
- * 2003/09/15 - Stephen Hemminger <shemminger at osdl dot org>,
- *            Amir Noam <amir.noam at intel dot com>
- *     - Convert /proc to seq_file interface.
- *       Change /proc/net/bondX/info to /proc/net/bonding/bondX.
- *       Set version to 2.4.1.
- *
- * 2003/11/20 - Amir Noam <amir.noam at intel dot com>
- *     - Fix /proc creation/destruction.
- *
- * 2003/12/01 - Shmulik Hen <shmulik.hen at intel dot com>
- *     - Massive cleanup - Set version to 2.5.0
- *       Code changes:
- *       o Consolidate format of prints and debug prints.
- *       o Remove bonding_t/slave_t typedefs and consolidate all casts.
- *       o Remove dead code and unnecessary checks.
- *       o Consolidate starting/stopping timers.
- *       o Consolidate handling of primary module param throughout the code.
- *       o Removed multicast module param support - all settings are done
- *         according to mode.
- *       o Slave list iteration - bond is no longer part of the list,
- *         added cyclic list iteration macros.
- *       o Consolidate error handling in all xmit functions.
- *       Style changes:
- *       o Consolidate function naming and declarations.
- *       o Consolidate function params and local variables names.
- *       o Consolidate return values.
- *       o Consolidate curly braces.
- *       o Consolidate conditionals format.
- *       o Change struct member names and types.
- *       o Chomp trailing spaces, remove empty lines, fix indentations.
- *       o Re-organize code according to context.
- *
- * 2003/12/30 - Amir Noam <amir.noam at intel dot com>
- *     - Fixed: Cannot remove and re-enslave the original active slave.
- *     - Fixed: Releasing the original active slave causes mac address
- *              duplication.
- *     - Add support for slaves that use ethtool_ops.
- *       Set version to 2.5.3.
- *
- * 2004/01/05 - Amir Noam <amir.noam at intel dot com>
- *     - Save bonding parameters per bond instead of using the global values.
- *       Set version to 2.5.4.
- *
- * 2004/01/14 - Shmulik Hen <shmulik.hen at intel dot com>
- *     - Enhance VLAN support:
- *       * Add support for VLAN hardware acceleration capable slaves.
- *       * Add capability to tag self generated packets in ALB/TLB modes.
- *       Set version to 2.6.0.
  */
 
 //#define BONDING_DEBUG 1
 
-#include <linux/config.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/sched.h>
 #include <linux/ptrace.h>
 #include <linux/ioport.h>
 #include <linux/in.h>
+#include <net/ip.h>
 #include <linux/ip.h>
+#include <linux/tcp.h>
+#include <linux/udp.h>
 #include <linux/slab.h>
 #include <linux/string.h>
 #include <linux/init.h>
 #include <linux/socket.h>
 #include <linux/ctype.h>
 #include <linux/inet.h>
+#include <linux/bitops.h>
 #include <asm/system.h>
-#include <asm/bitops.h>
 #include <asm/io.h>
 #include <asm/dma.h>
 #include <asm/uaccess.h>
 #include <linux/ethtool.h>
 #include <linux/if_vlan.h>
 #include <linux/if_bonding.h>
+#include <net/route.h>
 #include "bonding.h"
 #include "bond_3ad.h"
 #include "bond_alb.h"
@@ -530,67 +93,70 @@ static int use_carrier     = 1;
 static char *mode      = NULL;
 static char *primary   = NULL;
 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;
+struct bond_params bonding_defaults;
 
-MODULE_PARM(max_bonds, "i");
+module_param(max_bonds, int, 0);
 MODULE_PARM_DESC(max_bonds, "Max number of bonded devices");
-MODULE_PARM(miimon, "i");
+module_param(miimon, int, 0);
 MODULE_PARM_DESC(miimon, "Link check interval in milliseconds");
-MODULE_PARM(updelay, "i");
+module_param(updelay, int, 0);
 MODULE_PARM_DESC(updelay, "Delay before considering link up, in milliseconds");
-MODULE_PARM(downdelay, "i");
-MODULE_PARM_DESC(downdelay, "Delay before considering link down, in milliseconds");
-MODULE_PARM(use_carrier, "i");
-MODULE_PARM_DESC(use_carrier, "Use netif_carrier_ok (vs MII ioctls) in miimon; 0 for off, 1 for on (default)");
-MODULE_PARM(mode, "s");
-MODULE_PARM_DESC(mode, "Mode of operation : 0 for round robin, 1 for active-backup, 2 for xor");
-MODULE_PARM(primary, "s");
+module_param(downdelay, int, 0);
+MODULE_PARM_DESC(downdelay, "Delay before considering link down, "
+                           "in milliseconds");
+module_param(use_carrier, int, 0);
+MODULE_PARM_DESC(use_carrier, "Use netif_carrier_ok (vs MII ioctls) in miimon; "
+                             "0 for off, 1 for on (default)");
+module_param(mode, charp, 0);
+MODULE_PARM_DESC(mode, "Mode of operation : 0 for balance-rr, "
+                      "1 for active-backup, 2 for balance-xor, "
+                      "3 for broadcast, 4 for 802.3ad, 5 for balance-tlb, "
+                      "6 for balance-alb");
+module_param(primary, charp, 0);
 MODULE_PARM_DESC(primary, "Primary network device to use");
-MODULE_PARM(lacp_rate, "s");
-MODULE_PARM_DESC(lacp_rate, "LACPDU tx rate to request from 802.3ad partner (slow/fast)");
-MODULE_PARM(arp_interval, "i");
+module_param(lacp_rate, charp, 0);
+MODULE_PARM_DESC(lacp_rate, "LACPDU tx rate to request from 802.3ad partner "
+                           "(slow/fast)");
+module_param(xmit_hash_policy, charp, 0);
+MODULE_PARM_DESC(xmit_hash_policy, "XOR hashing method: 0 for layer 2 (default)"
+                                  ", 1 for layer 3+4");
+module_param(arp_interval, int, 0);
 MODULE_PARM_DESC(arp_interval, "arp interval in milliseconds");
-MODULE_PARM(arp_ip_target, "1-" __MODULE_STRING(BOND_MAX_ARP_TARGETS) "s");
+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");
 
 /*----------------------------- Global variables ----------------------------*/
 
-static const char *version =
+static const char * const version =
        DRV_DESCRIPTION ": v" DRV_VERSION " (" DRV_RELDATE ")\n";
 
-static LIST_HEAD(bond_dev_list);
+LIST_HEAD(bond_dev_list);
 
 #ifdef CONFIG_PROC_FS
 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 int arp_ip_count        = 0;
-static u32 my_ip       = 0;
 static int bond_mode   = BOND_MODE_ROUNDROBIN;
+static int xmit_hashtype= BOND_XMIT_POLICY_LAYER2;
 static int lacp_fast   = 0;
-static int app_abi_ver = 0;
-static int orig_app_abi_ver = -1; /* This is used to save the first ABI version
-                                  * we receive from the application. Once set,
-                                  * it won't be changed, and the module will
-                                  * refuse to enslave/release interfaces if the
-                                  * command comes from an application using
-                                  * another ABI version.
-                                  */
-
-struct bond_parm_tbl {
-       char *modename;
-       int mode;
-};
 
-static struct bond_parm_tbl bond_lacp_tbl[] = {
+
+struct bond_parm_tbl bond_lacp_tbl[] = {
 {      "slow",         AD_LACP_SLOW},
 {      "fast",         AD_LACP_FAST},
 {      NULL,           -1},
 };
 
-static struct bond_parm_tbl bond_mode_tbl[] = {
+struct bond_parm_tbl bond_mode_tbl[] = {
 {      "balance-rr",           BOND_MODE_ROUNDROBIN},
 {      "active-backup",        BOND_MODE_ACTIVEBACKUP},
 {      "balance-xor",          BOND_MODE_XOR},
@@ -601,13 +167,27 @@ static struct bond_parm_tbl bond_mode_tbl[] = {
 {      NULL,                   -1},
 };
 
+struct bond_parm_tbl xmit_hashtype_tbl[] = {
+{      "layer2",               BOND_XMIT_POLICY_LAYER2},
+{      "layer3+4",             BOND_XMIT_POLICY_LAYER34},
+{      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 inline void bond_set_mode_ops(struct net_device *bond_dev, int mode);
+static void bond_send_gratuitous_arp(struct bonding *bond);
 
 /*---------------------------- General routines -----------------------------*/
 
-static const char *bond_mode_name(int mode)
+const char *bond_mode_name(int mode)
 {
        switch (mode) {
        case BOND_MODE_ROUNDROBIN :
@@ -652,6 +232,7 @@ static int bond_add_vlan(struct bonding *bond, unsigned short vlan_id)
 
        INIT_LIST_HEAD(&vlan->vlan_list);
        vlan->vlan_id = vlan_id;
+       vlan->vlan_ip = 0;
 
        write_lock_bh(&bond->lock);
 
@@ -786,29 +367,20 @@ struct vlan_entry *bond_next_vlan(struct bonding *bond, struct vlan_entry *curr)
  * @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 tarnsmit that is
+ * 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
  * hw accel capable, the skb needs to be "unaccelerated",
  * i.e. strip the hwaccel tag and re-insert it as part
  * of the payload.
- * 
- * Assumption - once a VLAN device is created over the bond device, all
- * packets are going to be hardware accelerated VLAN tagged since the IP
- * binding is done over the VLAN device
  */
 int bond_dev_queue_xmit(struct bonding *bond, struct sk_buff *skb, struct net_device *slave_dev)
 {
        unsigned short vlan_id;
-       int res;
 
        if (!list_empty(&bond->vlan_list) &&
-           !(slave_dev->features & NETIF_F_HW_VLAN_TX)) {
-               res = vlan_get_tag(skb, &vlan_id);
-               if (res) {
-                       return -EINVAL;
-               }
-
+           !(slave_dev->features & NETIF_F_HW_VLAN_TX) &&
+           vlan_get_tag(skb, &vlan_id) == 0) {
                skb->dev = slave_dev;
                skb = vlan_put_tag(skb, vlan_id);
                if (!skb) {
@@ -892,7 +464,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: Failed to add vlan id %d\n",
+                      ": %s: Error: Failed to add vlan id %d\n",
                       bond_dev->name, vid);
        }
 }
@@ -926,7 +498,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: Failed to remove vlan id %d\n",
+                      ": %s: Error: Failed to remove vlan id %d\n",
                       bond_dev->name, vid);
        }
 }
@@ -996,6 +568,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
@@ -1014,7 +622,7 @@ static int bond_update_speed_duplex(struct slave *slave)
        slave->duplex = DUPLEX_FULL;
 
        if (slave_dev->ethtool_ops) {
-               u32 res;
+               int res;
 
                if (!slave_dev->ethtool_ops->get_settings) {
                        return -1;
@@ -1041,6 +649,7 @@ verify:
        case SPEED_10:
        case SPEED_100:
        case SPEED_1000:
+       case SPEED_10000:
                break;
        default:
                return -1;
@@ -1271,12 +880,13 @@ static void bond_mc_list_destroy(struct bonding *bond)
 /*
  * Copy all the Multicast addresses from src to the bonding device dst
  */
-static int bond_mc_list_copy(struct dev_mc_list *mc_list, struct bonding *bond, int gpf_flag)
+static int bond_mc_list_copy(struct dev_mc_list *mc_list, struct bonding *bond,
+                            gfp_t gfp_flag)
 {
        struct dev_mc_list *dmi, *new_dmi;
 
        for (dmi = mc_list; dmi; dmi = dmi->next) {
-               new_dmi = kmalloc(sizeof(struct dev_mc_list), gpf_flag);
+               new_dmi = kmalloc(sizeof(struct dev_mc_list), gfp_flag);
 
                if (!new_dmi) {
                        /* FIXME: Potential memory leak !!! */
@@ -1430,7 +1040,7 @@ static struct slave *bond_find_best_slave(struct bonding *bond)
  *
  * Warning: Caller must hold curr_slave_lock for writing.
  */
-static void bond_change_active_slave(struct bonding *bond, struct slave *new_active)
+void bond_change_active_slave(struct bonding *bond, struct slave *new_active)
 {
        struct slave *old_active = bond->curr_active_slave;
 
@@ -1470,16 +1080,6 @@ static void bond_change_active_slave(struct bonding *bond, struct slave *new_act
                }
        }
 
-       if (bond->params.mode == BOND_MODE_ACTIVEBACKUP) {
-               if (old_active) {
-                       bond_set_slave_inactive_flags(old_active);
-               }
-
-               if (new_active) {
-                       bond_set_slave_active_flags(new_active);
-               }
-       }
-
        if (USES_PRIMARY(bond->params.mode)) {
                bond_mc_swap(bond, new_active, old_active);
        }
@@ -1487,9 +1087,24 @@ static void bond_change_active_slave(struct bonding *bond, struct slave *new_act
        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;
        }
+
+       if (bond->params.mode == BOND_MODE_ACTIVEBACKUP) {
+               if (old_active) {
+                       bond_set_slave_inactive_flags(old_active);
+               }
+
+               if (new_active) {
+                       bond_set_slave_active_flags(new_active);
+               }
+               bond_send_gratuitous_arp(bond);
+       }
 }
 
 /**
@@ -1503,13 +1118,27 @@ static void bond_change_active_slave(struct bonding *bond, struct slave *new_act
  *
  * Warning: Caller must hold curr_slave_lock for writing.
  */
-static void bond_select_active_slave(struct bonding *bond)
+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);
+               }
        }
 }
 
@@ -1571,7 +1200,7 @@ static void bond_detach_slave(struct bonding *bond, struct slave *slave)
 
 /*---------------------------------- IOCTL ----------------------------------*/
 
-static int bond_sethwaddr(struct net_device *bond_dev, struct net_device *slave_dev)
+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);
@@ -1580,8 +1209,51 @@ static int bond_sethwaddr(struct net_device *bond_dev, struct net_device *slave_
        return 0;
 }
 
+#define BOND_INTERSECT_FEATURES \
+       (NETIF_F_SG | NETIF_F_ALL_CSUM | NETIF_F_TSO | NETIF_F_UFO)
+
+/* 
+ * 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.
+ */
+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 short max_hard_header_len = ETH_HLEN;
+       int i;
+
+       bond_for_each_slave(bond, slave, i) {
+               features &= (slave->dev->features & BOND_INTERSECT_FEATURES);
+               if (slave->dev->hard_header_len > max_hard_header_len)
+                       max_hard_header_len = slave->dev->hard_header_len;
+       }
+
+       if ((features & NETIF_F_SG) && 
+           !(features & NETIF_F_ALL_CSUM))
+               features &= ~NETIF_F_SG;
+
+       /* 
+        * features will include NETIF_F_TSO (NETIF_F_UFO) iff all 
+        * slave devices support NETIF_F_TSO (NETIF_F_UFO), which 
+        * implies that all slaves also support scatter-gather 
+        * (NETIF_F_SG), which implies that features also includes 
+        * NETIF_F_SG. So no need to check whether we have an  
+        * illegal combination of NETIF_F_{TSO,UFO} and 
+        * !NETIF_F_SG 
+        */
+
+       features |= (bond_dev->features & ~BOND_INTERSECT_FEATURES);
+       bond_dev->features = features;
+       bond_dev->hard_header_len = max_hard_header_len;
+
+       return 0;
+}
+
 /* enslave device <slave> to bond device <master> */
-static int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
+int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
 {
        struct bonding *bond = bond_dev->priv;
        struct slave *new_slave = NULL;
@@ -1591,10 +1263,11 @@ static int bond_enslave(struct net_device *bond_dev, struct net_device *slave_de
        int old_features = bond_dev->features;
        int res = 0;
 
-       if (slave_dev->do_ioctl == NULL) {
+       if (!bond->params.use_carrier && slave_dev->ethtool_ops == NULL &&
+               slave_dev->do_ioctl == NULL) {
                printk(KERN_WARNING DRV_NAME
-                      ": Warning : no link monitoring support for %s\n",
-                      slave_dev->name);
+                      ": %s: Warning: no link monitoring support for %s\n",
+                      bond_dev->name, slave_dev->name);
        }
 
        /* bond must be initialized by bond_open() before enslaving */
@@ -1615,17 +1288,17 @@ static int bond_enslave(struct net_device *bond_dev, struct net_device *slave_de
                dprintk("%s: NETIF_F_VLAN_CHALLENGED\n", slave_dev->name);
                if (!list_empty(&bond->vlan_list)) {
                        printk(KERN_ERR DRV_NAME
-                              ": Error: cannot enslave VLAN "
+                              ": %s: Error: cannot enslave VLAN "
                               "challenged slave %s on VLAN enabled "
-                              "bond %s\n", slave_dev->name,
+                              "bond %s\n", bond_dev->name, slave_dev->name,
                               bond_dev->name);
                        return -EPERM;
                } else {
                        printk(KERN_WARNING DRV_NAME
-                              ": Warning: enslaved VLAN challenged "
+                              ": %s: Warning: enslaved VLAN challenged "
                               "slave %s. Adding VLANs will be blocked as "
                               "long as %s is part of bond %s\n",
-                              slave_dev->name, slave_dev->name,
+                              bond_dev->name, slave_dev->name, slave_dev->name,
                               bond_dev->name);
                        bond_dev->features |= NETIF_F_VLAN_CHALLENGED;
                }
@@ -1639,51 +1312,35 @@ static int bond_enslave(struct net_device *bond_dev, struct net_device *slave_de
                }
        }
 
-       if (app_abi_ver >= 1) {
-               /* The application is using an ABI, which requires the
-                * slave interface to be closed.
-                */
-               if ((slave_dev->flags & IFF_UP)) {
-                       printk(KERN_ERR DRV_NAME
-                              ": Error: %s is up\n",
-                              slave_dev->name);
-                       res = -EPERM;
-                       goto err_undo_flags;
-               }
-
-               if (slave_dev->set_mac_address == NULL) {
-                       printk(KERN_ERR DRV_NAME
-                              ": Error: The slave device you specified does "
-                              "not support setting the MAC address.\n");
-                       printk(KERN_ERR
-                              "Your kernel likely does not support slave "
-                              "devices.\n");
+       /*
+        * Old ifenslave binaries are no longer supported.  These can
+        * be identified with moderate accurary 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",
+                      slave_dev->name);
+               res = -EPERM;
+               goto err_undo_flags;
+       }
 
-                       res = -EOPNOTSUPP;
-                       goto err_undo_flags;
-               }
-       } else {
-               /* The application is not using an ABI, which requires the
-                * slave interface to be open.
-                */
-               if (!(slave_dev->flags & IFF_UP)) {
-                       printk(KERN_ERR DRV_NAME
-                              ": Error: %s is not running\n",
-                              slave_dev->name);
-                       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->params.mode == BOND_MODE_8023AD) ||
-                   (bond->params.mode == BOND_MODE_TLB)    ||
-                   (bond->params.mode == BOND_MODE_ALB)) {
-                       printk(KERN_ERR DRV_NAME
-                              ": Error: to use %s mode, you must upgrade "
-                              "ifenslave.\n",
-                              bond_mode_name(bond->params.mode));
-                       res = -EOPNOTSUPP;
-                       goto err_undo_flags;
-               }
+       if (slave_dev->get_stats == NULL) {
+               printk(KERN_NOTICE DRV_NAME
+                       ": %s: the driver for slave device %s does not provide "
+                       "get_stats function, network statistics will be "
+                       "inaccurate.\n", bond_dev->name, slave_dev->name);
        }
 
        new_slave = kmalloc(sizeof(struct slave), GFP_KERNEL);
@@ -1699,44 +1356,40 @@ static int bond_enslave(struct net_device *bond_dev, struct net_device *slave_de
         */
        new_slave->original_flags = slave_dev->flags;
 
-       if (app_abi_ver >= 1) {
-               /* save slave's original ("permanent") mac address for
-                * modes that needs it, and for restoring it upon release,
-                * and then set it to the master's address
-                */
-               memcpy(new_slave->perm_hwaddr, slave_dev->dev_addr, ETH_ALEN);
+       /*
+        * Save slave's original ("permanent") mac address for modes
+        * that need it, and for restoring it upon release, and then
+        * set it to the master's address
+        */
+       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 = slave_dev->set_mac_address(slave_dev, &addr);
-               if (res) {
-                       dprintk("Error %d calling set_mac_address\n", res);
-                       goto err_free;
-               }
+       /*
+        * 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;
+       }
 
-               /* open the slave since the application closed it */
-               res = dev_open(slave_dev);
-               if (res) {
-                       dprintk("Openning slave %s failed\n", slave_dev->name);
-                       goto err_restore_mac;
-               }
+       /* open the slave since the application closed it */
+       res = dev_open(slave_dev);
+       if (res) {
+               dprintk("Openning slave %s failed\n", slave_dev->name);
+               goto err_restore_mac;
        }
 
        res = netdev_set_master(slave_dev, bond_dev);
        if (res) {
                dprintk("Error %d calling netdev_set_master\n", res);
-               if (app_abi_ver < 1) {
-                       goto err_free;
-               } else {
-                       goto err_close;
-               }
+               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)) {
@@ -1787,6 +1440,10 @@ static int bond_enslave(struct net_device *bond_dev, struct net_device *slave_de
        new_slave->delay = 0;
        new_slave->link_failure_count = 0;
 
+       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);
 
@@ -1801,21 +1458,21 @@ static int bond_enslave(struct net_device *bond_dev, struct net_device *slave_de
                         * the messages for netif_carrier.
                         */
                        printk(KERN_WARNING DRV_NAME
-                              ": Warning: MII and ETHTOOL support not "
+                              ": %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",
-                              slave_dev->name);
+                              bond_dev->name, slave_dev->name);
                } else if (link_reporting == -1) {
                        /* unable get link status using mii/ethtool */
                        printk(KERN_WARNING DRV_NAME
-                              ": Warning: can't get link status from "
+                              ": %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",
-                              slave_dev->name);
+                              bond_dev->name, slave_dev->name);
                }
        }
 
@@ -1842,15 +1499,15 @@ static int bond_enslave(struct net_device *bond_dev, struct net_device *slave_de
        if (bond_update_speed_duplex(new_slave) &&
            (new_slave->link != BOND_LINK_DOWN)) {
                printk(KERN_WARNING DRV_NAME
-                      ": Warning: failed to get speed/duplex from %s, speed "
-                      "forced to 100Mbps, duplex forced to Full.\n",
-                      new_slave->dev->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);
 
                if (bond->params.mode == BOND_MODE_8023AD) {
-                       printk(KERN_WARNING
-                              "Operation of 802.3ad mode requires ETHTOOL "
+                       printk(KERN_WARNING DRV_NAME
+                              ": %s: Warning: Operation of 802.3ad mode requires ETHTOOL "
                               "support in base driver for proper aggregator "
-                              "selection.\n");
+                              "selection.\n", bond_dev->name);
                }
        }
 
@@ -1863,24 +1520,8 @@ static int bond_enslave(struct net_device *bond_dev, struct net_device *slave_de
 
        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
@@ -1912,6 +1553,8 @@ static int bond_enslave(struct net_device *bond_dev, struct net_device *slave_de
                         * 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:
@@ -1930,40 +1573,13 @@ static int bond_enslave(struct net_device *bond_dev, struct net_device *slave_de
                break;
        } /* switch(bond_mode) */
 
-       write_unlock_bh(&bond->lock);
+       bond_set_carrier(bond);
 
-       if (app_abi_ver < 1) {
-               /*
-                * !!! This is to support old versions of ifenslave.
-                * We can remove this in 2.5 because our ifenslave takes
-                * care of this for us.
-                * We check to see if the master has a mac address yet.
-                * If not, we'll give it the mac address of our slave device.
-                */
-               int ndx = 0;
-
-               for (ndx = 0; ndx < bond_dev->addr_len; ndx++) {
-                       dprintk("Checking ndx=%d of bond_dev->dev_addr\n",
-                               ndx);
-                       if (bond_dev->dev_addr[ndx] != 0) {
-                               dprintk("Found non-zero byte at ndx=%d\n",
-                                       ndx);
-                               break;
-                       }
-               }
+       write_unlock_bh(&bond->lock);
 
-               if (ndx == bond_dev->addr_len) {
-                       /*
-                        * We got all the way through the address and it was
-                        * all 0's.
-                        */
-                       dprintk("%s doesn't have a MAC address yet.  \n",
-                               bond_dev->name);
-                       dprintk("Going to give assign it from %s.\n",
-                               slave_dev->name);
-                       bond_sethwaddr(bond_dev, slave_dev);
-               }
-       }
+       res = bond_create_slave_symlinks(bond_dev, slave_dev);
+       if (res)
+               goto err_unset_master;
 
        printk(KERN_INFO DRV_NAME
               ": %s: enslaving %s as a%s interface with a%s link.\n",
@@ -1984,14 +1600,14 @@ err_close:
 err_restore_mac:
        memcpy(addr.sa_data, new_slave->perm_hwaddr, ETH_ALEN);
        addr.sa_family = slave_dev->type;
-       slave_dev->set_mac_address(slave_dev, &addr);
+       dev_set_mac_address(slave_dev, &addr);
 
 err_free:
        kfree(new_slave);
 
 err_undo_flags:
        bond_dev->features = old_features;
-
        return res;
 }
 
@@ -2006,7 +1622,7 @@ err_undo_flags:
  *   for Bonded connections:
  *     The first up interface should be left on and all others downed.
  */
-static int bond_release(struct net_device *bond_dev, struct net_device *slave_dev)
+int bond_release(struct net_device *bond_dev, struct net_device *slave_dev)
 {
        struct bonding *bond = bond_dev->priv;
        struct slave *slave, *oldcurrent;
@@ -2017,7 +1633,7 @@ static int bond_release(struct net_device *bond_dev, struct net_device *slave_de
        if (!(slave_dev->flags & IFF_SLAVE) ||
            (slave_dev->master != bond_dev)) {
                printk(KERN_ERR DRV_NAME
-                      ": Error: %s: cannot release %s.\n",
+                      ": %s: Error: cannot release %s.\n",
                       bond_dev->name, slave_dev->name);
                return -EINVAL;
        }
@@ -2030,6 +1646,7 @@ static int bond_release(struct net_device *bond_dev, struct net_device *slave_de
                printk(KERN_INFO DRV_NAME
                       ": %s: %s not enslaved\n",
                       bond_dev->name, slave_dev->name);
+               write_unlock_bh(&bond->lock);
                return -EINVAL;
        }
 
@@ -2038,11 +1655,12 @@ static int bond_release(struct net_device *bond_dev, struct net_device *slave_de
                                 ETH_ALEN);
        if (!mac_addr_differ && (bond->slave_cnt > 1)) {
                printk(KERN_WARNING DRV_NAME
-                      ": Warning: the permanent HWaddr of %s "
+                      ": %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",
+                      bond_dev->name,
                       slave_dev->name,
                       slave->perm_hwaddr[0],
                       slave->perm_hwaddr[1],
@@ -2076,6 +1694,8 @@ static int bond_release(struct net_device *bond_dev, struct net_device *slave_de
        /* release the slave from its bond */
        bond_detach_slave(bond, slave);
 
+       bond_compute_features(bond);
+
        if (bond->primary_slave == slave) {
                bond->primary_slave = NULL;
        }
@@ -2094,18 +1714,12 @@ static int bond_release(struct net_device *bond_dev, struct net_device *slave_de
                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
@@ -2116,24 +1730,28 @@ static int bond_release(struct net_device *bond_dev, struct net_device *slave_de
                        bond_dev->features |= NETIF_F_VLAN_CHALLENGED;
                } else {
                        printk(KERN_WARNING DRV_NAME
-                              ": Warning: clearing HW address of %s while it "
+                              ": %s: Warning: clearing HW address of %s while it "
                               "still has VLANs.\n",
-                              bond_dev->name);
+                              bond_dev->name, bond_dev->name);
                        printk(KERN_WARNING DRV_NAME
-                              ": When re-adding slaves, make sure the bond's "
-                              "HW address matches its VLANs'.\n");
+                              ": %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
-                      ": last VLAN challenged slave %s "
+                      ": %s: last VLAN challenged slave %s "
                       "left bond %s. VLAN blocking is removed\n",
-                      slave_dev->name, bond_dev->name);
+                      bond_dev->name, slave_dev->name, bond_dev->name);
                bond_dev->features &= ~NETIF_F_VLAN_CHALLENGED;
        }
 
        write_unlock_bh(&bond->lock);
 
+       /* must do this from outside any spinlocks */
+       bond_destroy_slave_symlinks(bond_dev, slave_dev);
+
        bond_del_vlans_from_slave(bond, slave_dev);
 
        /* If the mode USES_PRIMARY, then we should only remove its
@@ -2160,20 +1778,14 @@ static int bond_release(struct net_device *bond_dev, struct net_device *slave_de
        /* close slave before restoring its mac address */
        dev_close(slave_dev);
 
-       if (app_abi_ver >= 1) {
-               /* restore original ("permanent") mac address */
-               memcpy(addr.sa_data, slave->perm_hwaddr, ETH_ALEN);
-               addr.sa_family = slave_dev->type;
-               slave_dev->set_mac_address(slave_dev, &addr);
-       }
+       /* 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;
-       }
+       slave_dev->priv_flags &= ~(IFF_MASTER_8023AD | IFF_MASTER_ALB |
+                                  IFF_SLAVE_INACTIVE | IFF_BONDING |
+                                  IFF_SLAVE_NEEDARP);
 
        kfree(slave);
 
@@ -2192,6 +1804,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;
        }
@@ -2219,12 +1833,15 @@ static int bond_release_all(struct net_device *bond_dev)
                        bond_alb_deinit_slave(bond, slave);
                }
 
+               bond_compute_features(bond);
+
                /* now that the slave is detached, unlock and perform
                 * all the undo steps that should not be called from
                 * within a lock.
                 */
                write_unlock_bh(&bond->lock);
 
+               bond_destroy_slave_symlinks(bond_dev, slave_dev);
                bond_del_vlans_from_slave(bond, slave_dev);
 
                /* If the mode USES_PRIMARY, then we should only remove its
@@ -2251,19 +1868,13 @@ static int bond_release_all(struct net_device *bond_dev)
                /* close slave before restoring its mac address */
                dev_close(slave_dev);
 
-               if (app_abi_ver >= 1) {
-                       /* restore original ("permanent") mac address*/
-                       memcpy(addr.sa_data, slave->perm_hwaddr, ETH_ALEN);
-                       addr.sa_family = slave_dev->type;
-                       slave_dev->set_mac_address(slave_dev, &addr);
-               }
+               /* 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;
-               }
+               slave_dev->priv_flags &= ~(IFF_MASTER_8023AD | IFF_MASTER_ALB |
+                                          IFF_SLAVE_INACTIVE);
 
                kfree(slave);
 
@@ -2281,12 +1892,13 @@ static int bond_release_all(struct net_device *bond_dev)
                bond_dev->features |= NETIF_F_VLAN_CHALLENGED;
        } else {
                printk(KERN_WARNING DRV_NAME
-                      ": Warning: clearing HW address of %s while it "
+                      ": %s: Warning: clearing HW address of %s while it "
                       "still has VLANs.\n",
-                      bond_dev->name);
+                      bond_dev->name, bond_dev->name);
                printk(KERN_WARNING DRV_NAME
-                      ": When re-adding slaves, make sure the bond's "
-                      "HW address matches its VLANs'.\n");
+                      ": %s: When re-adding slaves, make sure the bond's "
+                      "HW address matches its VLANs'.\n",
+                      bond_dev->name);
        }
 
        printk(KERN_INFO DRV_NAME
@@ -2354,57 +1966,6 @@ static int bond_ioctl_change_active(struct net_device *bond_dev, struct net_devi
        return res;
 }
 
-static int bond_ethtool_ioctl(struct net_device *bond_dev, struct ifreq *ifr)
-{
-       struct ethtool_drvinfo info;
-       void __user *addr = ifr->ifr_data;
-       uint32_t cmd;
-
-       if (get_user(cmd, (uint32_t __user *)addr)) {
-               return -EFAULT;
-       }
-
-       switch (cmd) {
-       case ETHTOOL_GDRVINFO:
-               if (copy_from_user(&info, addr, sizeof(info))) {
-                       return -EFAULT;
-               }
-
-               if (strcmp(info.driver, "ifenslave") == 0) {
-                       int new_abi_ver;
-                       char *endptr;
-
-                       new_abi_ver = simple_strtoul(info.fw_version,
-                                                    &endptr, 0);
-                       if (*endptr) {
-                               printk(KERN_ERR DRV_NAME
-                                      ": Error: got invalid ABI "
-                                      "version from application\n");
-
-                               return -EINVAL;
-                       }
-
-                       if (orig_app_abi_ver == -1) {
-                               orig_app_abi_ver  = new_abi_ver;
-                       }
-
-                       app_abi_ver = new_abi_ver;
-               }
-
-               strncpy(info.driver,  DRV_NAME, 32);
-               strncpy(info.version, DRV_VERSION, 32);
-               snprintf(info.fw_version, 32, "%d", BOND_ABI_VERSION);
-
-               if (copy_to_user(addr, &info, sizeof(info))) {
-                       return -EFAULT;
-               }
-
-               return 0;
-       default:
-               return -EOPNOTSUPP;
-       }
-}
-
 static int bond_info_query(struct net_device *bond_dev, struct ifbond *info)
 {
        struct bonding *bond = bond_dev->priv;
@@ -2455,7 +2016,7 @@ static int bond_slave_info_query(struct net_device *bond_dev, struct ifslave *in
 /*-------------------------------- Monitoring -------------------------------*/
 
 /* this function is called regularly to monitor each slave's link. */
-static void bond_mii_monitor(struct net_device *bond_dev)
+void bond_mii_monitor(struct net_device *bond_dev)
 {
        struct bonding *bond = bond_dev->priv;
        struct slave *slave, *oldcurrent;
@@ -2654,8 +2215,11 @@ static void bond_mii_monitor(struct net_device *bond_dev)
                        break;
                default:
                        /* Should not happen */
-                       printk(KERN_ERR "bonding: Error: %s  Illegal value (link=%d)\n",
-                              slave->dev->name, slave->link);
+                       printk(KERN_ERR DRV_NAME
+                              ": %s: Error: %s Illegal value (link=%d)\n",
+                              bond_dev->name,
+                              slave->dev->name,
+                              slave->link);
                        goto out;
                } /* end of switch (slave->link) */
 
@@ -2666,48 +2230,318 @@ static void bond_mii_monitor(struct net_device *bond_dev)
                                bond_3ad_adapter_speed_changed(slave);
                        }
 
-                       if (old_duplex != slave->duplex) {
-                               bond_3ad_adapter_duplex_changed(slave);
+                       if (old_duplex != slave->duplex) {
+                               bond_3ad_adapter_duplex_changed(slave);
+                       }
+               }
+
+       } /* end of for */
+
+       if (do_failover) {
+               write_lock(&bond->curr_slave_lock);
+
+               bond_select_active_slave(bond);
+
+               write_unlock(&bond->curr_slave_lock);
+       } else
+               bond_set_carrier(bond);
+
+re_arm:
+       if (bond->params.miimon) {
+               mod_timer(&bond->mii_timer, jiffies + delta_in_ticks);
+       }
+out:
+       read_unlock(&bond->lock);
+}
+
+
+static u32 bond_glean_dev_ip(struct net_device *dev)
+{
+       struct in_device *idev;
+       struct in_ifaddr *ifa;
+       __be32 addr = 0;
+
+       if (!dev)
+               return 0;
+
+       rcu_read_lock();
+       idev = __in_dev_get_rcu(dev);
+       if (!idev)
+               goto out;
+
+       ifa = idev->ifa_list;
+       if (!ifa)
+               goto out;
+
+       addr = ifa->ifa_local;
+out:
+       rcu_read_unlock();
+       return addr;
+}
+
+static int bond_has_ip(struct bonding *bond)
+{
+       struct vlan_entry *vlan, *vlan_next;
+
+       if (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 (vlan->vlan_ip)
+                       return 1;
+       }
+
+       return 0;
+}
+
+static int bond_has_this_ip(struct bonding *bond, u32 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)
+{
+       struct sk_buff *skb;
+
+       dprintk("arp %d on slave %s: dst %x src %x vid %d\n", arp_op,
+              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");
+               return;
+       }
+       if (vlan_id) {
+               skb = vlan_put_tag(skb, vlan_id);
+               if (!skb) {
+                       printk(KERN_ERR DRV_NAME ": failed to insert VLAN tag\n");
+                       return;
+               }
+       }
+       arp_xmit(skb);
+}
+
+
+static void bond_arp_send_all(struct bonding *bond, struct slave *slave)
+{
+       int i, vlan_id, rv;
+       u32 *targets = bond->params.arp_targets;
+       struct vlan_entry *vlan, *vlan_next;
+       struct net_device *vlan_dev;
+       struct flowi fl;
+       struct rtable *rt;
+
+       for (i = 0; (i < BOND_MAX_ARP_TARGETS); i++) {
+               if (!targets[i])
+                       continue;
+               dprintk("basa: target %x\n", targets[i]);
+               if (list_empty(&bond->vlan_list)) {
+                       dprintk("basa: empty vlan: arp_send\n");
+                       bond_arp_send(slave->dev, ARPOP_REQUEST, targets[i],
+                                     bond->master_ip, 0);
+                       continue;
+               }
+
+               /*
+                * If VLANs are configured, we do a route lookup to
+                * determine which VLAN interface would be used, so we
+                * can tag the ARP with the proper VLAN tag.
+                */
+               memset(&fl, 0, sizeof(fl));
+               fl.fl4_dst = targets[i];
+               fl.fl4_tos = RTO_ONLINK;
+
+               rv = ip_route_output_key(&rt, &fl);
+               if (rv) {
+                       if (net_ratelimit()) {
+                               printk(KERN_WARNING DRV_NAME
+                            ": %s: no route to arp_ip_target %u.%u.%u.%u\n",
+                                      bond->dev->name, NIPQUAD(fl.fl4_dst));
                        }
+                       continue;
                }
 
-       } /* end of for */
+               /*
+                * This target is not on a VLAN
+                */
+               if (rt->u.dst.dev == bond->dev) {
+                       ip_rt_put(rt);
+                       dprintk("basa: rtdev == bond->dev: arp_send\n");
+                       bond_arp_send(slave->dev, ARPOP_REQUEST, targets[i],
+                                     bond->master_ip, 0);
+                       continue;
+               }
 
-       if (do_failover) {
-               write_lock(&bond->curr_slave_lock);
+               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];
+                       if (vlan_dev == rt->u.dst.dev) {
+                               vlan_id = vlan->vlan_id;
+                               dprintk("basa: vlan match on %s %d\n",
+                                      vlan_dev->name, vlan_id);
+                               break;
+                       }
+               }
 
-               bond_select_active_slave(bond);
+               if (vlan_id) {
+                       ip_rt_put(rt);
+                       bond_arp_send(slave->dev, ARPOP_REQUEST, targets[i],
+                                     vlan->vlan_ip, vlan_id);
+                       continue;
+               }
 
-               if (oldcurrent && !bond->curr_active_slave) {
-                       printk(KERN_INFO DRV_NAME
-                              ": %s: now running without any active "
-                              "interface !\n",
-                              bond_dev->name);
+               if (net_ratelimit()) {
+                       printk(KERN_WARNING DRV_NAME
+              ": %s: no path to arp_ip_target %u.%u.%u.%u via rt.dev %s\n",
+                              bond->dev->name, NIPQUAD(fl.fl4_dst),
+                              rt->u.dst.dev ? rt->u.dst.dev->name : "NULL");
                }
+               ip_rt_put(rt);
+       }
+}
 
-               write_unlock(&bond->curr_slave_lock);
+/*
+ * Kick out a gratuitous ARP for an IP on the bonding master plus one
+ * for each VLAN above us.
+ */
+static void bond_send_gratuitous_arp(struct bonding *bond)
+{
+       struct slave *slave = bond->curr_active_slave;
+       struct vlan_entry *vlan;
+       struct net_device *vlan_dev;
+
+       dprintk("bond_send_grat_arp: bond %s slave %s\n", bond->dev->name,
+                               slave ? slave->dev->name : "NULL");
+       if (!slave)
+               return;
+
+       if (bond->master_ip) {
+               bond_arp_send(slave->dev, ARPOP_REPLY, bond->master_ip,
+                                 bond->master_ip, 0);
        }
 
-re_arm:
-       if (bond->params.miimon) {
-               mod_timer(&bond->mii_timer, jiffies + delta_in_ticks);
+       list_for_each_entry(vlan, &bond->vlan_list, vlan_list) {
+               vlan_dev = bond->vlgrp->vlan_devices[vlan->vlan_id];
+               if (vlan->vlan_ip) {
+                       bond_arp_send(slave->dev, ARPOP_REPLY, vlan->vlan_ip,
+                                     vlan->vlan_ip, vlan->vlan_id);
+               }
        }
-out:
-       read_unlock(&bond->lock);
 }
 
-static void bond_arp_send_all(struct bonding *bond, struct slave *slave)
+static void bond_validate_arp(struct bonding *bond, struct slave *slave, u32 sip, u32 tip)
 {
        int i;
        u32 *targets = bond->params.arp_targets;
 
+       targets = bond->params.arp_targets;
        for (i = 0; (i < BOND_MAX_ARP_TARGETS) && targets[i]; i++) {
-               arp_send(ARPOP_REQUEST, ETH_P_ARP, targets[i], slave->dev,
-                        my_ip, NULL, slave->dev->dev_addr,
-                        NULL);
+               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;
+       u32 sip, tip;
+
+       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 = skb->nh.arph;
+       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
@@ -2715,7 +2549,7 @@ static void bond_arp_send_all(struct bonding *bond, struct slave *slave)
  * arp is transmitted to generate traffic. see activebackup_arp_monitor for
  * arp monitoring in active backup mode.
  */
-static void bond_loadbalance_arp_mon(struct net_device *bond_dev)
+void bond_loadbalance_arp_mon(struct net_device *bond_dev)
 {
        struct bonding *bond = bond_dev->priv;
        struct slave *slave, *oldcurrent;
@@ -2783,7 +2617,7 @@ static void bond_loadbalance_arp_mon(struct net_device *bond_dev)
                         */
                        if (((jiffies - slave->dev->trans_start) >= (2*delta_in_ticks)) ||
                            (((jiffies - slave->dev->last_rx) >= (2*delta_in_ticks)) &&
-                            my_ip)) {
+                            bond_has_ip(bond))) {
 
                                slave->link  = BOND_LINK_DOWN;
                                slave->state = BOND_STATE_BACKUP;
@@ -2820,13 +2654,6 @@ static 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);
        }
 
@@ -2853,7 +2680,7 @@ out:
  * may have received.
  * see loadbalance_arp_monitor for arp monitoring in load balancing mode
  */
-static void bond_activebackup_arp_mon(struct net_device *bond_dev)
+void bond_activebackup_arp_mon(struct net_device *bond_dev)
 {
        struct bonding *bond = bond_dev->priv;
        struct slave *slave;
@@ -2879,7 +2706,8 @@ static 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;
 
@@ -2900,12 +2728,15 @@ static 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 "
@@ -2921,8 +2752,8 @@ static 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) &&
-                            my_ip)) {
+                           (((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
                                 * taken out before the backup slave.
@@ -2968,8 +2799,8 @@ static 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)) &&
-                     my_ip)) &&
+           (((jiffies - slave_last_rx(bond, slave)) >= (2*delta_in_ticks)) &&
+            bond_has_ip(bond))) &&
                    ((jiffies - slave->jiffies) >= 2*delta_in_ticks)) {
 
                        slave->link  = BOND_LINK_DOWN;
@@ -3021,7 +2852,7 @@ static void bond_activebackup_arp_mon(struct net_device *bond_dev)
                /* the current slave must tx an arp to ensure backup slaves
                 * rx traffic
                 */
-               if (slave && my_ip) {
+               if (slave && bond_has_ip(bond)) {
                        bond_arp_send_all(bond, slave);
                }
        }
@@ -3039,7 +2870,7 @@ static void bond_activebackup_arp_mon(struct net_device *bond_dev)
                        bond_set_slave_inactive_flags(bond->current_arp_slave);
 
                        /* search for next candidate */
-                       bond_for_each_slave_from(bond, slave, i, bond->current_arp_slave) {
+                       bond_for_each_slave_from(bond, slave, i, bond->current_arp_slave->next) {
                                if (IS_UP(slave->dev)) {
                                        slave->link = BOND_LINK_BACK;
                                        bond_set_slave_active_flags(slave);
@@ -3139,6 +2970,8 @@ static void bond_info_show_master(struct seq_file *seq)
 {
        struct bonding *bond = seq->private;
        struct slave *curr;
+       int i;
+       u32 target;
 
        read_lock(&bond->curr_slave_lock);
        curr = bond->curr_active_slave;
@@ -3147,22 +2980,51 @@ static void bond_info_show_master(struct seq_file *seq)
        seq_printf(seq, "Bonding Mode: %s\n",
                   bond_mode_name(bond->params.mode));
 
+       if (bond->params.mode == BOND_MODE_XOR ||
+               bond->params.mode == BOND_MODE_8023AD) {
+               seq_printf(seq, "Transmit Hash Policy: %s (%d)\n",
+                       xmit_hashtype_tbl[bond->params.xmit_policy].modename,
+                       bond->params.xmit_policy);
+       }
+
        if (USES_PRIMARY(bond->params.mode)) {
                seq_printf(seq, "Primary Slave: %s\n",
-                          (bond->params.primary[0]) ?
-                               bond->params.primary : "None");
+                          (bond->primary_slave) ?
+                          bond->primary_slave->dev->name : "None");
 
                seq_printf(seq, "Currently Active Slave: %s\n",
                           (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);
        seq_printf(seq, "Down Delay (ms): %d\n",
                   bond->params.downdelay * bond->params.miimon);
 
+
+       /* ARP information */
+       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++) {
+                       if (!bond->params.arp_targets[i])
+                               continue;
+                       if (printed)
+                               seq_printf(seq, ",");
+                       target = ntohl(bond->params.arp_targets[i]);
+                       seq_printf(seq, " %d.%d.%d.%d", HIPQUAD(target));
+                       printed = 1;
+               }
+               seq_printf(seq, "\n");
+       }
+
        if (bond->params.mode == BOND_MODE_8023AD) {
                struct ad_info ad_info;
 
@@ -3202,19 +3064,14 @@ static void bond_info_show_slave(struct seq_file *seq, const struct slave *slave
        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);
 
-       if (app_abi_ver >= 1) {
-               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]);
-       }
+       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]);
 
        if (bond->params.mode == BOND_MODE_8023AD) {
                const struct aggregator *agg
@@ -3373,7 +3230,10 @@ static int bond_event_changename(struct bonding *bond)
        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;
 }
 
@@ -3399,6 +3259,7 @@ static int bond_master_netdev_event(unsigned long event, struct net_device *bond
 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 = bond_dev->priv;
 
        switch (event) {
        case NETDEV_UNREGISTER:
@@ -3437,6 +3298,9 @@ static int bond_slave_netdev_event(unsigned long event, struct net_device *slave
                 * TODO: handle changing the primary's name
                 */
                break;
+       case NETDEV_FEAT_CHANGE:
+               bond_compute_features(bond);
+               break;
        default:
                break;
        }
@@ -3448,7 +3312,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).
  */
@@ -3460,6 +3324,9 @@ static int bond_netdev_event(struct notifier_block *this, unsigned long event, v
                (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);
@@ -3473,10 +3340,67 @@ static int bond_netdev_event(struct notifier_block *this, unsigned long event, v
        return NOTIFY_DONE;
 }
 
+/*
+ * bond_inetaddr_event: handle inetaddr notifier chain events.
+ *
+ * We keep track of device IPs primarily to use as source addresses in
+ * ARP monitor probes (rather than spewing out broadcasts all the time).
+ *
+ * We track one IP for the main device (if it has one), plus one per VLAN.
+ */
+static int bond_inetaddr_event(struct notifier_block *this, unsigned long event, void *ptr)
+{
+       struct in_ifaddr *ifa = ptr;
+       struct net_device *vlan_dev, *event_dev = ifa->ifa_dev->dev;
+       struct bonding *bond, *bond_next;
+       struct vlan_entry *vlan, *vlan_next;
+
+       list_for_each_entry_safe(bond, bond_next, &bond_dev_list, bond_list) {
+               if (bond->dev == event_dev) {
+                       switch (event) {
+                       case NETDEV_UP:
+                               bond->master_ip = ifa->ifa_local;
+                               return NOTIFY_OK;
+                       case NETDEV_DOWN:
+                               bond->master_ip = bond_glean_dev_ip(bond->dev);
+                               return NOTIFY_OK;
+                       default:
+                               return NOTIFY_DONE;
+                       }
+               }
+
+               if (list_empty(&bond->vlan_list))
+                       continue;
+
+               list_for_each_entry_safe(vlan, vlan_next, &bond->vlan_list,
+                                        vlan_list) {
+                       vlan_dev = bond->vlgrp->vlan_devices[vlan->vlan_id];
+                       if (vlan_dev == event_dev) {
+                               switch (event) {
+                               case NETDEV_UP:
+                                       vlan->vlan_ip = ifa->ifa_local;
+                                       return NOTIFY_OK;
+                               case NETDEV_DOWN:
+                                       vlan->vlan_ip =
+                                               bond_glean_dev_ip(vlan_dev);
+                                       return NOTIFY_OK;
+                               default:
+                                       return NOTIFY_DONE;
+                               }
+                       }
+               }
+       }
+       return NOTIFY_DONE;
+}
+
 static struct notifier_block bond_netdev_notifier = {
        .notifier_call = bond_netdev_event,
 };
 
+static struct notifier_block bond_inetaddr_notifier = {
+       .notifier_call = bond_inetaddr_event,
+};
+
 /*-------------------------- Packet type handling ---------------------------*/
 
 /* register to receive lacpdus on a bond */
@@ -3498,6 +3422,61 @@ 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;
+
+       pt->type = htons(ETH_P_ARP);
+       pt->dev = NULL; /*bond->dev;XXX*/
+       pt->func = bond_arp_rcv;
+       dev_add_pack(pt);
+}
+
+void bond_unregister_arp(struct bonding *bond)
+{
+       dev_remove_pack(&bond->arp_mon_pt);
+}
+
+/*---------------------------- Hashing Policies -----------------------------*/
+
+/*
+ * Hash for the 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()
+ */
+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);
+       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)));
+               }
+               return (layer4_xor ^
+                       ((ntohl(iph->saddr ^ iph->daddr)) & 0xffff)) % count;
+
+       }
+
+       return (data->h_dest[5] ^ bond_dev->dev_addr[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)
+{
+       struct ethhdr *data = (struct ethhdr *)skb->data;
+
+       return (data->h_dest[5] ^ bond_dev->dev_addr[5]) % count;
+}
+
 /*-------------------------- Device entry points ----------------------------*/
 
 static int bond_open(struct net_device *bond_dev)
@@ -3544,6 +3523,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);
        }
 
@@ -3566,15 +3548,17 @@ static int bond_close(struct net_device *bond_dev)
 {
        struct bonding *bond = bond_dev->priv;
 
-       write_lock_bh(&bond->lock);
-
-       bond_mc_list_destroy(bond);
-
        if (bond->params.mode == BOND_MODE_8023AD) {
                /* Unregister the receive of LACPDUs */
                bond_unregister_lacpdu(bond);
        }
 
+       if (bond->params.arp_validate)
+               bond_unregister_arp(bond);
+
+       write_lock_bh(&bond->lock);
+
+
        /* signal timers not to re-arm */
        bond->kill_timers = 1;
 
@@ -3604,8 +3588,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)) {
@@ -3630,33 +3612,35 @@ static struct net_device_stats *bond_get_stats(struct net_device *bond_dev)
        read_lock_bh(&bond->lock);
 
        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;
-               stats->rx_dropped += sstats->rx_dropped;
-
-               stats->tx_packets += sstats->tx_packets;
-               stats->tx_bytes += sstats->tx_bytes;
-               stats->tx_errors += sstats->tx_errors;
-               stats->tx_dropped += sstats->tx_dropped;
-
-               stats->multicast += sstats->multicast;
-               stats->collisions += sstats->collisions;
-
-               stats->rx_length_errors += sstats->rx_length_errors;
-               stats->rx_over_errors += sstats->rx_over_errors;
-               stats->rx_crc_errors += sstats->rx_crc_errors;
-               stats->rx_frame_errors += sstats->rx_frame_errors;
-               stats->rx_fifo_errors += sstats->rx_fifo_errors;
-               stats->rx_missed_errors += sstats->rx_missed_errors;
-
-               stats->tx_aborted_errors += sstats->tx_aborted_errors;
-               stats->tx_carrier_errors += sstats->tx_carrier_errors;
-               stats->tx_fifo_errors += sstats->tx_fifo_errors;
-               stats->tx_heartbeat_errors += sstats->tx_heartbeat_errors;
-               stats->tx_window_errors += sstats->tx_window_errors;
+               if (slave->dev->get_stats) {
+                       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;
+                       stats->rx_dropped += sstats->rx_dropped;
+
+                       stats->tx_packets += sstats->tx_packets;
+                       stats->tx_bytes += sstats->tx_bytes;
+                       stats->tx_errors += sstats->tx_errors;
+                       stats->tx_dropped += sstats->tx_dropped;
+
+                       stats->multicast += sstats->multicast;
+                       stats->collisions += sstats->collisions;
+
+                       stats->rx_length_errors += sstats->rx_length_errors;
+                       stats->rx_over_errors += sstats->rx_over_errors;
+                       stats->rx_crc_errors += sstats->rx_crc_errors;
+                       stats->rx_frame_errors += sstats->rx_frame_errors;
+                       stats->rx_fifo_errors += sstats->rx_fifo_errors;
+                       stats->rx_missed_errors += sstats->rx_missed_errors;
+
+                       stats->tx_aborted_errors += sstats->tx_aborted_errors;
+                       stats->tx_carrier_errors += sstats->tx_carrier_errors;
+                       stats->tx_fifo_errors += sstats->tx_fifo_errors;
+                       stats->tx_heartbeat_errors += sstats->tx_heartbeat_errors;
+                       stats->tx_window_errors += sstats->tx_window_errors;
+               }
        }
 
        read_unlock_bh(&bond->lock);
@@ -3672,15 +3656,12 @@ static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd
        struct ifslave k_sinfo;
        struct ifslave __user *u_sinfo = NULL;
        struct mii_ioctl_data *mii = NULL;
-       int prev_abi_ver = orig_app_abi_ver;
        int res = 0;
 
        dprintk("bond_ioctl: master=%s, cmd=%d\n",
                bond_dev->name, cmd);
 
        switch (cmd) {
-       case SIOCETHTOOL:
-               return bond_ethtool_ioctl(bond_dev, ifr);
        case SIOCGMIIPHY:
                mii = if_mii(ifr);
                if (!mii) {
@@ -3703,7 +3684,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);
@@ -3752,21 +3733,7 @@ static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd
                return -EPERM;
        }
 
-       if (orig_app_abi_ver == -1) {
-               /* no orig_app_abi_ver was provided yet, so we'll use the
-                * current one from now on, even if it's 0
-                */
-               orig_app_abi_ver = app_abi_ver;
-
-       } else if (orig_app_abi_ver != app_abi_ver) {
-               printk(KERN_ERR DRV_NAME
-                      ": Error: already using ifenslave ABI version %d; to "
-                      "upgrade ifenslave to version %d, you must first "
-                      "reload bonding.\n",
-                      orig_app_abi_ver, app_abi_ver);
-               return -EINVAL;
-       }
-
+       down_write(&(bonding_rwsem));
        slave_dev = dev_get_by_name(ifr->ifr_slave);
 
        dprintk("slave_dev=%p: \n", slave_dev);
@@ -3799,14 +3766,7 @@ static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd
                dev_put(slave_dev);
        }
 
-       if (res < 0) {
-               /* The ioctl failed, so there's no point in changing the
-                * orig_app_abi_ver. We'll restore it's value just in case
-                * we've changed it earlier in this function.
-                */
-               orig_app_abi_ver = prev_abi_ver;
-       }
-
+       up_write(&(bonding_rwsem));
        return res;
 }
 
@@ -3891,12 +3851,8 @@ static int bond_change_mtu(struct net_device *bond_dev, int new_mtu)
        bond_for_each_slave(bond, slave, i) {
                dprintk("s %p s->p %p c_m %p\n", slave,
                        slave->prev, slave->dev->change_mtu);
-               if (slave->dev->change_mtu) {
-                       res = slave->dev->change_mtu(slave->dev, new_mtu);
-               } else {
-                       slave->dev->mtu = new_mtu;
-                       res = 0;
-               }
+
+               res = dev_set_mtu(slave->dev, new_mtu);
 
                if (res) {
                        /* If we failed to set the slave's mtu to the new value
@@ -3922,14 +3878,10 @@ unwind:
        bond_for_each_slave_from_to(bond, slave, i, bond->first_slave, stop_at) {
                int tmp_res;
 
-               if (slave->dev->change_mtu) {
-                       tmp_res = slave->dev->change_mtu(slave->dev, bond_dev->mtu);
-                       if (tmp_res) {
-                               dprintk("unwind err %d dev %s\n", tmp_res,
-                                       slave->dev->name);
-                       }
-               } else {
-                       slave->dev->mtu = bond_dev->mtu;
+               tmp_res = dev_set_mtu(slave->dev, bond_dev->mtu);
+               if (tmp_res) {
+                       dprintk("unwind err %d dev %s\n", tmp_res,
+                               slave->dev->name);
                }
        }
 
@@ -3981,7 +3933,7 @@ static int bond_set_mac_address(struct net_device *bond_dev, void *addr)
                        goto unwind;
                }
 
-               res = slave->dev->set_mac_address(slave->dev, addr);
+               res = dev_set_mac_address(slave->dev, addr);
                if (res) {
                        /* TODO: consider downing the slave
                         * and retry ?
@@ -4007,7 +3959,7 @@ unwind:
        bond_for_each_slave_from_to(bond, slave, i, bond->first_slave, stop_at) {
                int tmp_res;
 
-               tmp_res = slave->dev->set_mac_address(slave->dev, &tmp_sa);
+               tmp_res = dev_set_mac_address(slave->dev, &tmp_sa);
                if (tmp_res) {
                        dprintk("unwind err %d dev %s\n", tmp_res,
                                slave->dev->name);
@@ -4062,6 +4014,43 @@ 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
  * the bond has a usable interface.
@@ -4071,17 +4060,6 @@ static int bond_xmit_activebackup(struct sk_buff *skb, struct net_device *bond_d
        struct bonding *bond = bond_dev->priv;
        int res = 1;
 
-       /* if we are sending arp packets, try to at least
-          identify our own ip address */
-       if (bond->params.arp_interval && !my_ip &&
-               (skb->protocol == __constant_htons(ETH_P_ARP))) {
-               char *the_ip = (char *)skb->data +
-                               sizeof(struct ethhdr) +
-                               sizeof(struct arphdr) +
-                               ETH_ALEN;
-               memcpy(&my_ip, the_ip, 4);
-       }
-
        read_lock(&bond->lock);
        read_lock(&bond->curr_slave_lock);
 
@@ -4089,10 +4067,26 @@ static int bond_xmit_activebackup(struct sk_buff *skb, struct net_device *bond_d
                goto out;
        }
 
-       if (bond->curr_active_slave) { /* one usable interface */
-               res = bond_dev_queue_xmit(bond, skb, bond->curr_active_slave->dev);
+       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:
        if (res) {
                /* no suitable interface, frame not sent */
@@ -4104,14 +4098,13 @@ out:
 }
 
 /*
- * in XOR mode, we determine the output device by performing xor on
- * the source and destination hw adresses.  If this device is not
- * enabled, find the next slave following this xor slave.
+ * In bond_xmit_xor() , we determine the output device by using a pre-
+ * determined xmit_hash_policy(), If the selected device is not enabled,
+ * find the next active slave.
  */
 static int bond_xmit_xor(struct sk_buff *skb, struct net_device *bond_dev)
 {
        struct bonding *bond = bond_dev->priv;
-       struct ethhdr *data = (struct ethhdr *)skb->data;
        struct slave *slave, *start_at;
        int slave_no;
        int i;
@@ -4123,7 +4116,7 @@ static int bond_xmit_xor(struct sk_buff *skb, struct net_device *bond_dev)
                goto out;
        }
 
-       slave_no = (data->h_dest[5]^bond_dev->dev_addr[5]) % bond->slave_cnt;
+       slave_no = bond->xmit_hash_policy(skb, bond_dev, bond->slave_cnt);
 
        bond_for_each_slave(bond, slave, i) {
                slave_no--;
@@ -4185,8 +4178,9 @@ static int bond_xmit_broadcast(struct sk_buff *skb, struct net_device *bond_dev)
                                struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC);
                                if (!skb2) {
                                        printk(KERN_ERR DRV_NAME
-                                              ": Error: bond_xmit_broadcast(): "
-                                              "skb_clone() failed\n");
+                                              ": %s: Error: bond_xmit_broadcast(): "
+                                              "skb_clone() failed\n",
+                                              bond_dev->name);
                                        continue;
                                }
 
@@ -4219,8 +4213,10 @@ out:
 /*
  * set bond mode specific net device operations
  */
-static inline void bond_set_mode_ops(struct net_device *bond_dev, int mode)
+void bond_set_mode_ops(struct bonding *bond, int mode)
 {
+       struct net_device *bond_dev = bond->dev;
+
        switch (mode) {
        case BOND_MODE_ROUNDROBIN:
                bond_dev->hard_start_xmit = bond_xmit_roundrobin;
@@ -4230,32 +4226,60 @@ static inline void bond_set_mode_ops(struct net_device *bond_dev, int mode)
                break;
        case BOND_MODE_XOR:
                bond_dev->hard_start_xmit = bond_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_BROADCAST:
                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;
        default:
                /* Should never happen, mode already checked */
                printk(KERN_ERR DRV_NAME
-                      ": Error: Unknown bonding mode %d\n",
+                      ": %s: Error: Unknown bonding mode %d\n",
+                      bond_dev->name,
                       mode);
                break;
        }
 }
 
+static void bond_ethtool_get_drvinfo(struct net_device *bond_dev,
+                                   struct ethtool_drvinfo *drvinfo)
+{
+       strncpy(drvinfo->driver, DRV_NAME, 32);
+       strncpy(drvinfo->version, DRV_VERSION, 32);
+       snprintf(drvinfo->fw_version, 32, "%d", BOND_ABI_VERSION);
+}
+
+static const struct ethtool_ops bond_ethtool_ops = {
+       .get_tx_csum            = ethtool_op_get_tx_csum,
+       .get_tso                = ethtool_op_get_tso,
+       .get_ufo                = ethtool_op_get_ufo,
+       .get_sg                 = ethtool_op_get_sg,
+       .get_drvinfo            = bond_ethtool_get_drvinfo,
+};
+
 /*
  * Does not allocate but creates a /proc entry.
  * Allowed to fail.
  */
-static int __init bond_init(struct net_device *bond_dev, struct bond_params *params)
+static int bond_init(struct net_device *bond_dev, struct bond_params *params)
 {
        struct bonding *bond = bond_dev->priv;
 
@@ -4280,17 +4304,19 @@ static int __init bond_init(struct net_device *bond_dev, struct bond_params *par
        bond_dev->stop = bond_close;
        bond_dev->get_stats = bond_get_stats;
        bond_dev->do_ioctl = bond_do_ioctl;
+       bond_dev->ethtool_ops = &bond_ethtool_ops;
        bond_dev->set_multicast_list = bond_set_multicast_list;
        bond_dev->change_mtu = bond_change_mtu;
        bond_dev->set_mac_address = bond_set_mac_address;
 
-       bond_set_mode_ops(bond_dev, bond->params.mode);
+       bond_set_mode_ops(bond, bond->params.mode);
 
        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;
 
        /* At first, we block adding VLANs. That's the only way to
         * prevent problems that occur when adding VLANs over an
@@ -4299,6 +4325,10 @@ static int __init bond_init(struct net_device *bond_dev, struct bond_params *par
         */
        bond_dev->features |= NETIF_F_VLAN_CHALLENGED;
 
+       /* don't acquire bond device's netif_tx_lock when
+        * transmitting */
+       bond_dev->features |= NETIF_F_LLTX;
+
        /* By default, we declare the bond to be fully
         * VLAN hardware accelerated capable. Special
         * care is taken in the various xmit functions
@@ -4324,7 +4354,7 @@ static int __init bond_init(struct net_device *bond_dev, struct bond_params *par
 /* De-initialize device specific data.
  * Caller must hold rtnl_lock.
  */
-static inline void bond_deinit(struct net_device *bond_dev)
+void bond_deinit(struct net_device *bond_dev)
 {
        struct bonding *bond = bond_dev->priv;
 
@@ -4345,6 +4375,9 @@ 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;
 
+               bond_mc_list_destroy(bond);
+               /* Release the bonded slaves */
+               bond_release_all(bond_dev);
                unregister_netdevice(bond_dev);
                bond_deinit(bond_dev);
        }
@@ -4360,7 +4393,7 @@ static void bond_free_all(void)
  * Convert string input module parms.  Accept either the
  * number of the mode or its string name.
  */
-static inline int bond_parse_parm(char *mode_arg, struct bond_parm_tbl *tbl)
+int bond_parse_parm(char *mode_arg, struct bond_parm_tbl *tbl)
 {
        int i;
 
@@ -4378,6 +4411,8 @@ static inline 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.
         */
@@ -4391,6 +4426,25 @@ 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",
+                              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" :
+                                      xmit_hash_policy);
+                               return -EINVAL;
+                       }
+               }
+       }
+
        if (lacp_rate) {
                if (bond_mode != BOND_MODE_8023AD) {
                        printk(KERN_INFO DRV_NAME
@@ -4410,7 +4464,7 @@ static int bond_check_params(struct bond_params *params)
        if (max_bonds < 1 || 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)",
+                      "was reset to BOND_DEFAULT_MAX_BONDS (%d)\n",
                       max_bonds, 1, INT_MAX, BOND_DEFAULT_MAX_BONDS);
                max_bonds = BOND_DEFAULT_MAX_BONDS;
        }
@@ -4562,6 +4616,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",
@@ -4570,8 +4647,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]);
@@ -4602,8 +4681,10 @@ static int bond_check_params(struct bond_params *params)
 
        /* 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;
@@ -4620,86 +4701,120 @@ 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.
+ * 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, struct bonding **newbond)
+{
+       struct net_device *bond_dev;
+       int res;
+
+       rtnl_lock();
+       bond_dev = alloc_netdev(sizeof(struct bonding), name, ether_setup);
+       if (!bond_dev) {
+               printk(KERN_ERR DRV_NAME
+                      ": %s: eek! can't alloc netdev!\n",
+                      name);
+               res = -ENOMEM;
+               goto out_rtnl;
+       }
+
+       /* 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;
+       }
+
+       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;
+out_bond:
+       bond_deinit(bond_dev);
+out_netdev:
+       free_netdev(bond_dev);
+out_rtnl:
+       rtnl_unlock();
+done:
+       return res;
+}
+
 static int __init bonding_init(void)
 {
-       struct bond_params params;
        int i;
        int res;
+       char new_bond_name[8];  /* Enough room for 999 bonds at init. */
 
        printk(KERN_INFO "%s", version);
 
-       res = bond_check_params(&params);
+       res = bond_check_params(&bonding_defaults);
        if (res) {
-               return res;
+               goto out;
        }
 
-       rtnl_lock();
-
 #ifdef CONFIG_PROC_FS
        bond_create_proc_dir();
 #endif
-
        for (i = 0; i < max_bonds; i++) {
-               struct net_device *bond_dev;
-
-               bond_dev = alloc_netdev(sizeof(struct bonding), "", ether_setup);
-               if (!bond_dev) {
-                       res = -ENOMEM;
-                       goto out_err;
-               }
-
-               res = dev_alloc_name(bond_dev, "bond%d");
-               if (res < 0) {
-                       free_netdev(bond_dev);
-                       goto out_err;
-               }
-
-               /* 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) {
-                       free_netdev(bond_dev);
-                       goto out_err;
-               }
-
-               SET_MODULE_OWNER(bond_dev);
-
-               res = register_netdevice(bond_dev);
-               if (res < 0) {
-                       bond_deinit(bond_dev);
-                       free_netdev(bond_dev);
-                       goto out_err;
-               }
+               sprintf(new_bond_name, "bond%d",i);
+               res = bond_create(new_bond_name,&bonding_defaults, NULL);
+               if (res)
+                       goto err;
        }
 
-       rtnl_unlock();
-       register_netdevice_notifier(&bond_netdev_notifier);
+       res = bond_create_sysfs();
+       if (res)
+               goto err;
 
-       return 0;
+       register_netdevice_notifier(&bond_netdev_notifier);
+       register_inetaddr_notifier(&bond_inetaddr_notifier);
 
-out_err:
-       /* free and unregister all bonds that were successfully added */
+       goto out;
+err:
+       rtnl_lock();
        bond_free_all();
-
+       bond_destroy_sysfs();
        rtnl_unlock();
-
+out:
        return res;
+
 }
 
 static void __exit bonding_exit(void)
 {
        unregister_netdevice_notifier(&bond_netdev_notifier);
+       unregister_inetaddr_notifier(&bond_inetaddr_notifier);
 
        rtnl_lock();
        bond_free_all();
+       bond_destroy_sysfs();
        rtnl_unlock();
 }
 
 module_init(bonding_init);
 module_exit(bonding_exit);
 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");