aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/bonding/bond_main.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/bonding/bond_main.c')
-rw-r--r--drivers/net/bonding/bond_main.c301
1 files changed, 86 insertions, 215 deletions
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 94c9f68dd16b..f264ff162979 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -487,6 +487,8 @@
487 * * Added xmit_hash_policy_layer34() 487 * * Added xmit_hash_policy_layer34()
488 * - Modified by Jay Vosburgh <fubar@us.ibm.com> to also support mode 4. 488 * - Modified by Jay Vosburgh <fubar@us.ibm.com> to also support mode 4.
489 * Set version to 2.6.3. 489 * Set version to 2.6.3.
490 * 2005/09/26 - Jay Vosburgh <fubar@us.ibm.com>
491 * - Removed backwards compatibility for old ifenslaves. Version 2.6.4.
490 */ 492 */
491 493
492//#define BONDING_DEBUG 1 494//#define BONDING_DEBUG 1
@@ -595,14 +597,7 @@ static int arp_ip_count = 0;
595static int bond_mode = BOND_MODE_ROUNDROBIN; 597static int bond_mode = BOND_MODE_ROUNDROBIN;
596static int xmit_hashtype= BOND_XMIT_POLICY_LAYER2; 598static int xmit_hashtype= BOND_XMIT_POLICY_LAYER2;
597static int lacp_fast = 0; 599static int lacp_fast = 0;
598static int app_abi_ver = 0; 600
599static int orig_app_abi_ver = -1; /* This is used to save the first ABI version
600 * we receive from the application. Once set,
601 * it won't be changed, and the module will
602 * refuse to enslave/release interfaces if the
603 * command comes from an application using
604 * another ABI version.
605 */
606struct bond_parm_tbl { 601struct bond_parm_tbl {
607 char *modename; 602 char *modename;
608 int mode; 603 int mode;
@@ -1294,12 +1289,13 @@ static void bond_mc_list_destroy(struct bonding *bond)
1294/* 1289/*
1295 * Copy all the Multicast addresses from src to the bonding device dst 1290 * Copy all the Multicast addresses from src to the bonding device dst
1296 */ 1291 */
1297static int bond_mc_list_copy(struct dev_mc_list *mc_list, struct bonding *bond, int gpf_flag) 1292static int bond_mc_list_copy(struct dev_mc_list *mc_list, struct bonding *bond,
1293 gfp_t gfp_flag)
1298{ 1294{
1299 struct dev_mc_list *dmi, *new_dmi; 1295 struct dev_mc_list *dmi, *new_dmi;
1300 1296
1301 for (dmi = mc_list; dmi; dmi = dmi->next) { 1297 for (dmi = mc_list; dmi; dmi = dmi->next) {
1302 new_dmi = kmalloc(sizeof(struct dev_mc_list), gpf_flag); 1298 new_dmi = kmalloc(sizeof(struct dev_mc_list), gfp_flag);
1303 1299
1304 if (!new_dmi) { 1300 if (!new_dmi) {
1305 /* FIXME: Potential memory leak !!! */ 1301 /* FIXME: Potential memory leak !!! */
@@ -1653,7 +1649,8 @@ static int bond_enslave(struct net_device *bond_dev, struct net_device *slave_de
1653 int old_features = bond_dev->features; 1649 int old_features = bond_dev->features;
1654 int res = 0; 1650 int res = 0;
1655 1651
1656 if (slave_dev->do_ioctl == NULL) { 1652 if (!bond->params.use_carrier && slave_dev->ethtool_ops == NULL &&
1653 slave_dev->do_ioctl == NULL) {
1657 printk(KERN_WARNING DRV_NAME 1654 printk(KERN_WARNING DRV_NAME
1658 ": Warning : no link monitoring support for %s\n", 1655 ": Warning : no link monitoring support for %s\n",
1659 slave_dev->name); 1656 slave_dev->name);
@@ -1701,51 +1698,29 @@ static int bond_enslave(struct net_device *bond_dev, struct net_device *slave_de
1701 } 1698 }
1702 } 1699 }
1703 1700
1704 if (app_abi_ver >= 1) { 1701 /*
1705 /* The application is using an ABI, which requires the 1702 * Old ifenslave binaries are no longer supported. These can
1706 * slave interface to be closed. 1703 * be identified with moderate accurary by the state of the slave:
1707 */ 1704 * the current ifenslave will set the interface down prior to
1708 if ((slave_dev->flags & IFF_UP)) { 1705 * enslaving it; the old ifenslave will not.
1709 printk(KERN_ERR DRV_NAME 1706 */
1710 ": Error: %s is up\n", 1707 if ((slave_dev->flags & IFF_UP)) {
1711 slave_dev->name); 1708 printk(KERN_ERR DRV_NAME ": %s is up. "
1712 res = -EPERM; 1709 "This may be due to an out of date ifenslave.\n",
1713 goto err_undo_flags; 1710 slave_dev->name);
1714 } 1711 res = -EPERM;
1715 1712 goto err_undo_flags;
1716 if (slave_dev->set_mac_address == NULL) { 1713 }
1717 printk(KERN_ERR DRV_NAME
1718 ": Error: The slave device you specified does "
1719 "not support setting the MAC address.\n");
1720 printk(KERN_ERR
1721 "Your kernel likely does not support slave "
1722 "devices.\n");
1723 1714
1724 res = -EOPNOTSUPP; 1715 if (slave_dev->set_mac_address == NULL) {
1725 goto err_undo_flags; 1716 printk(KERN_ERR DRV_NAME
1726 } 1717 ": Error: The slave device you specified does "
1727 } else { 1718 "not support setting the MAC address.\n");
1728 /* The application is not using an ABI, which requires the 1719 printk(KERN_ERR
1729 * slave interface to be open. 1720 "Your kernel likely does not support slave devices.\n");
1730 */
1731 if (!(slave_dev->flags & IFF_UP)) {
1732 printk(KERN_ERR DRV_NAME
1733 ": Error: %s is not running\n",
1734 slave_dev->name);
1735 res = -EINVAL;
1736 goto err_undo_flags;
1737 }
1738 1721
1739 if ((bond->params.mode == BOND_MODE_8023AD) || 1722 res = -EOPNOTSUPP;
1740 (bond->params.mode == BOND_MODE_TLB) || 1723 goto err_undo_flags;
1741 (bond->params.mode == BOND_MODE_ALB)) {
1742 printk(KERN_ERR DRV_NAME
1743 ": Error: to use %s mode, you must upgrade "
1744 "ifenslave.\n",
1745 bond_mode_name(bond->params.mode));
1746 res = -EOPNOTSUPP;
1747 goto err_undo_flags;
1748 }
1749 } 1724 }
1750 1725
1751 new_slave = kmalloc(sizeof(struct slave), GFP_KERNEL); 1726 new_slave = kmalloc(sizeof(struct slave), GFP_KERNEL);
@@ -1761,41 +1736,36 @@ static int bond_enslave(struct net_device *bond_dev, struct net_device *slave_de
1761 */ 1736 */
1762 new_slave->original_flags = slave_dev->flags; 1737 new_slave->original_flags = slave_dev->flags;
1763 1738
1764 if (app_abi_ver >= 1) { 1739 /*
1765 /* save slave's original ("permanent") mac address for 1740 * Save slave's original ("permanent") mac address for modes
1766 * modes that needs it, and for restoring it upon release, 1741 * that need it, and for restoring it upon release, and then
1767 * and then set it to the master's address 1742 * set it to the master's address
1768 */ 1743 */
1769 memcpy(new_slave->perm_hwaddr, slave_dev->dev_addr, ETH_ALEN); 1744 memcpy(new_slave->perm_hwaddr, slave_dev->dev_addr, ETH_ALEN);
1770 1745
1771 /* set slave to master's mac address 1746 /*
1772 * The application already set the master's 1747 * Set slave to master's mac address. The application already
1773 * mac address to that of the first slave 1748 * set the master's mac address to that of the first slave
1774 */ 1749 */
1775 memcpy(addr.sa_data, bond_dev->dev_addr, bond_dev->addr_len); 1750 memcpy(addr.sa_data, bond_dev->dev_addr, bond_dev->addr_len);
1776 addr.sa_family = slave_dev->type; 1751 addr.sa_family = slave_dev->type;
1777 res = dev_set_mac_address(slave_dev, &addr); 1752 res = dev_set_mac_address(slave_dev, &addr);
1778 if (res) { 1753 if (res) {
1779 dprintk("Error %d calling set_mac_address\n", res); 1754 dprintk("Error %d calling set_mac_address\n", res);
1780 goto err_free; 1755 goto err_free;
1781 } 1756 }
1782 1757
1783 /* open the slave since the application closed it */ 1758 /* open the slave since the application closed it */
1784 res = dev_open(slave_dev); 1759 res = dev_open(slave_dev);
1785 if (res) { 1760 if (res) {
1786 dprintk("Openning slave %s failed\n", slave_dev->name); 1761 dprintk("Openning slave %s failed\n", slave_dev->name);
1787 goto err_restore_mac; 1762 goto err_restore_mac;
1788 }
1789 } 1763 }
1790 1764
1791 res = netdev_set_master(slave_dev, bond_dev); 1765 res = netdev_set_master(slave_dev, bond_dev);
1792 if (res) { 1766 if (res) {
1793 dprintk("Error %d calling netdev_set_master\n", res); 1767 dprintk("Error %d calling netdev_set_master\n", res);
1794 if (app_abi_ver < 1) { 1768 goto err_close;
1795 goto err_free;
1796 } else {
1797 goto err_close;
1798 }
1799 } 1769 }
1800 1770
1801 new_slave->dev = slave_dev; 1771 new_slave->dev = slave_dev;
@@ -1996,39 +1966,6 @@ static int bond_enslave(struct net_device *bond_dev, struct net_device *slave_de
1996 1966
1997 write_unlock_bh(&bond->lock); 1967 write_unlock_bh(&bond->lock);
1998 1968
1999 if (app_abi_ver < 1) {
2000 /*
2001 * !!! This is to support old versions of ifenslave.
2002 * We can remove this in 2.5 because our ifenslave takes
2003 * care of this for us.
2004 * We check to see if the master has a mac address yet.
2005 * If not, we'll give it the mac address of our slave device.
2006 */
2007 int ndx = 0;
2008
2009 for (ndx = 0; ndx < bond_dev->addr_len; ndx++) {
2010 dprintk("Checking ndx=%d of bond_dev->dev_addr\n",
2011 ndx);
2012 if (bond_dev->dev_addr[ndx] != 0) {
2013 dprintk("Found non-zero byte at ndx=%d\n",
2014 ndx);
2015 break;
2016 }
2017 }
2018
2019 if (ndx == bond_dev->addr_len) {
2020 /*
2021 * We got all the way through the address and it was
2022 * all 0's.
2023 */
2024 dprintk("%s doesn't have a MAC address yet. \n",
2025 bond_dev->name);
2026 dprintk("Going to give assign it from %s.\n",
2027 slave_dev->name);
2028 bond_sethwaddr(bond_dev, slave_dev);
2029 }
2030 }
2031
2032 printk(KERN_INFO DRV_NAME 1969 printk(KERN_INFO DRV_NAME
2033 ": %s: enslaving %s as a%s interface with a%s link.\n", 1970 ": %s: enslaving %s as a%s interface with a%s link.\n",
2034 bond_dev->name, slave_dev->name, 1971 bond_dev->name, slave_dev->name,
@@ -2226,12 +2163,10 @@ static int bond_release(struct net_device *bond_dev, struct net_device *slave_de
2226 /* close slave before restoring its mac address */ 2163 /* close slave before restoring its mac address */
2227 dev_close(slave_dev); 2164 dev_close(slave_dev);
2228 2165
2229 if (app_abi_ver >= 1) { 2166 /* restore original ("permanent") mac address */
2230 /* restore original ("permanent") mac address */ 2167 memcpy(addr.sa_data, slave->perm_hwaddr, ETH_ALEN);
2231 memcpy(addr.sa_data, slave->perm_hwaddr, ETH_ALEN); 2168 addr.sa_family = slave_dev->type;
2232 addr.sa_family = slave_dev->type; 2169 dev_set_mac_address(slave_dev, &addr);
2233 dev_set_mac_address(slave_dev, &addr);
2234 }
2235 2170
2236 /* restore the original state of the 2171 /* restore the original state of the
2237 * IFF_NOARP flag that might have been 2172 * IFF_NOARP flag that might have been
@@ -2319,12 +2254,10 @@ static int bond_release_all(struct net_device *bond_dev)
2319 /* close slave before restoring its mac address */ 2254 /* close slave before restoring its mac address */
2320 dev_close(slave_dev); 2255 dev_close(slave_dev);
2321 2256
2322 if (app_abi_ver >= 1) { 2257 /* restore original ("permanent") mac address*/
2323 /* restore original ("permanent") mac address*/ 2258 memcpy(addr.sa_data, slave->perm_hwaddr, ETH_ALEN);
2324 memcpy(addr.sa_data, slave->perm_hwaddr, ETH_ALEN); 2259 addr.sa_family = slave_dev->type;
2325 addr.sa_family = slave_dev->type; 2260 dev_set_mac_address(slave_dev, &addr);
2326 dev_set_mac_address(slave_dev, &addr);
2327 }
2328 2261
2329 /* restore the original state of the IFF_NOARP flag that might have 2262 /* restore the original state of the IFF_NOARP flag that might have
2330 * been set by bond_set_slave_inactive_flags() 2263 * been set by bond_set_slave_inactive_flags()
@@ -2422,57 +2355,6 @@ static int bond_ioctl_change_active(struct net_device *bond_dev, struct net_devi
2422 return res; 2355 return res;
2423} 2356}
2424 2357
2425static int bond_ethtool_ioctl(struct net_device *bond_dev, struct ifreq *ifr)
2426{
2427 struct ethtool_drvinfo info;
2428 void __user *addr = ifr->ifr_data;
2429 uint32_t cmd;
2430
2431 if (get_user(cmd, (uint32_t __user *)addr)) {
2432 return -EFAULT;
2433 }
2434
2435 switch (cmd) {
2436 case ETHTOOL_GDRVINFO:
2437 if (copy_from_user(&info, addr, sizeof(info))) {
2438 return -EFAULT;
2439 }
2440
2441 if (strcmp(info.driver, "ifenslave") == 0) {
2442 int new_abi_ver;
2443 char *endptr;
2444
2445 new_abi_ver = simple_strtoul(info.fw_version,
2446 &endptr, 0);
2447 if (*endptr) {
2448 printk(KERN_ERR DRV_NAME
2449 ": Error: got invalid ABI "
2450 "version from application\n");
2451
2452 return -EINVAL;
2453 }
2454
2455 if (orig_app_abi_ver == -1) {
2456 orig_app_abi_ver = new_abi_ver;
2457 }
2458
2459 app_abi_ver = new_abi_ver;
2460 }
2461
2462 strncpy(info.driver, DRV_NAME, 32);
2463 strncpy(info.version, DRV_VERSION, 32);
2464 snprintf(info.fw_version, 32, "%d", BOND_ABI_VERSION);
2465
2466 if (copy_to_user(addr, &info, sizeof(info))) {
2467 return -EFAULT;
2468 }
2469
2470 return 0;
2471 default:
2472 return -EOPNOTSUPP;
2473 }
2474}
2475
2476static int bond_info_query(struct net_device *bond_dev, struct ifbond *info) 2358static int bond_info_query(struct net_device *bond_dev, struct ifbond *info)
2477{ 2359{
2478 struct bonding *bond = bond_dev->priv; 2360 struct bonding *bond = bond_dev->priv;
@@ -2775,7 +2657,7 @@ static u32 bond_glean_dev_ip(struct net_device *dev)
2775 return 0; 2657 return 0;
2776 2658
2777 rcu_read_lock(); 2659 rcu_read_lock();
2778 idev = __in_dev_get(dev); 2660 idev = __in_dev_get_rcu(dev);
2779 if (!idev) 2661 if (!idev)
2780 goto out; 2662 goto out;
2781 2663
@@ -2879,6 +2761,7 @@ static void bond_arp_send_all(struct bonding *bond, struct slave *slave)
2879 * This target is not on a VLAN 2761 * This target is not on a VLAN
2880 */ 2762 */
2881 if (rt->u.dst.dev == bond->dev) { 2763 if (rt->u.dst.dev == bond->dev) {
2764 ip_rt_put(rt);
2882 dprintk("basa: rtdev == bond->dev: arp_send\n"); 2765 dprintk("basa: rtdev == bond->dev: arp_send\n");
2883 bond_arp_send(slave->dev, ARPOP_REQUEST, targets[i], 2766 bond_arp_send(slave->dev, ARPOP_REQUEST, targets[i],
2884 bond->master_ip, 0); 2767 bond->master_ip, 0);
@@ -2898,6 +2781,7 @@ static void bond_arp_send_all(struct bonding *bond, struct slave *slave)
2898 } 2781 }
2899 2782
2900 if (vlan_id) { 2783 if (vlan_id) {
2784 ip_rt_put(rt);
2901 bond_arp_send(slave->dev, ARPOP_REQUEST, targets[i], 2785 bond_arp_send(slave->dev, ARPOP_REQUEST, targets[i],
2902 vlan->vlan_ip, vlan_id); 2786 vlan->vlan_ip, vlan_id);
2903 continue; 2787 continue;
@@ -2909,6 +2793,7 @@ static void bond_arp_send_all(struct bonding *bond, struct slave *slave)
2909 bond->dev->name, NIPQUAD(fl.fl4_dst), 2793 bond->dev->name, NIPQUAD(fl.fl4_dst),
2910 rt->u.dst.dev ? rt->u.dst.dev->name : "NULL"); 2794 rt->u.dst.dev ? rt->u.dst.dev->name : "NULL");
2911 } 2795 }
2796 ip_rt_put(rt);
2912 } 2797 }
2913} 2798}
2914 2799
@@ -3438,16 +3323,11 @@ static void bond_info_show_slave(struct seq_file *seq, const struct slave *slave
3438 seq_printf(seq, "Link Failure Count: %d\n", 3323 seq_printf(seq, "Link Failure Count: %d\n",
3439 slave->link_failure_count); 3324 slave->link_failure_count);
3440 3325
3441 if (app_abi_ver >= 1) { 3326 seq_printf(seq,
3442 seq_printf(seq, 3327 "Permanent HW addr: %02x:%02x:%02x:%02x:%02x:%02x\n",
3443 "Permanent HW addr: %02x:%02x:%02x:%02x:%02x:%02x\n", 3328 slave->perm_hwaddr[0], slave->perm_hwaddr[1],
3444 slave->perm_hwaddr[0], 3329 slave->perm_hwaddr[2], slave->perm_hwaddr[3],
3445 slave->perm_hwaddr[1], 3330 slave->perm_hwaddr[4], slave->perm_hwaddr[5]);
3446 slave->perm_hwaddr[2],
3447 slave->perm_hwaddr[3],
3448 slave->perm_hwaddr[4],
3449 slave->perm_hwaddr[5]);
3450 }
3451 3331
3452 if (bond->params.mode == BOND_MODE_8023AD) { 3332 if (bond->params.mode == BOND_MODE_8023AD) {
3453 const struct aggregator *agg 3333 const struct aggregator *agg
@@ -4006,15 +3886,12 @@ static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd
4006 struct ifslave k_sinfo; 3886 struct ifslave k_sinfo;
4007 struct ifslave __user *u_sinfo = NULL; 3887 struct ifslave __user *u_sinfo = NULL;
4008 struct mii_ioctl_data *mii = NULL; 3888 struct mii_ioctl_data *mii = NULL;
4009 int prev_abi_ver = orig_app_abi_ver;
4010 int res = 0; 3889 int res = 0;
4011 3890
4012 dprintk("bond_ioctl: master=%s, cmd=%d\n", 3891 dprintk("bond_ioctl: master=%s, cmd=%d\n",
4013 bond_dev->name, cmd); 3892 bond_dev->name, cmd);
4014 3893
4015 switch (cmd) { 3894 switch (cmd) {
4016 case SIOCETHTOOL:
4017 return bond_ethtool_ioctl(bond_dev, ifr);
4018 case SIOCGMIIPHY: 3895 case SIOCGMIIPHY:
4019 mii = if_mii(ifr); 3896 mii = if_mii(ifr);
4020 if (!mii) { 3897 if (!mii) {
@@ -4086,21 +3963,6 @@ static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd
4086 return -EPERM; 3963 return -EPERM;
4087 } 3964 }
4088 3965
4089 if (orig_app_abi_ver == -1) {
4090 /* no orig_app_abi_ver was provided yet, so we'll use the
4091 * current one from now on, even if it's 0
4092 */
4093 orig_app_abi_ver = app_abi_ver;
4094
4095 } else if (orig_app_abi_ver != app_abi_ver) {
4096 printk(KERN_ERR DRV_NAME
4097 ": Error: already using ifenslave ABI version %d; to "
4098 "upgrade ifenslave to version %d, you must first "
4099 "reload bonding.\n",
4100 orig_app_abi_ver, app_abi_ver);
4101 return -EINVAL;
4102 }
4103
4104 slave_dev = dev_get_by_name(ifr->ifr_slave); 3966 slave_dev = dev_get_by_name(ifr->ifr_slave);
4105 3967
4106 dprintk("slave_dev=%p: \n", slave_dev); 3968 dprintk("slave_dev=%p: \n", slave_dev);
@@ -4133,14 +3995,6 @@ static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd
4133 dev_put(slave_dev); 3995 dev_put(slave_dev);
4134 } 3996 }
4135 3997
4136 if (res < 0) {
4137 /* The ioctl failed, so there's no point in changing the
4138 * orig_app_abi_ver. We'll restore it's value just in case
4139 * we've changed it earlier in this function.
4140 */
4141 orig_app_abi_ver = prev_abi_ver;
4142 }
4143
4144 return res; 3998 return res;
4145} 3999}
4146 4000
@@ -4574,9 +4428,18 @@ static inline void bond_set_mode_ops(struct bonding *bond, int mode)
4574 } 4428 }
4575} 4429}
4576 4430
4431static void bond_ethtool_get_drvinfo(struct net_device *bond_dev,
4432 struct ethtool_drvinfo *drvinfo)
4433{
4434 strncpy(drvinfo->driver, DRV_NAME, 32);
4435 strncpy(drvinfo->version, DRV_VERSION, 32);
4436 snprintf(drvinfo->fw_version, 32, "%d", BOND_ABI_VERSION);
4437}
4438
4577static struct ethtool_ops bond_ethtool_ops = { 4439static struct ethtool_ops bond_ethtool_ops = {
4578 .get_tx_csum = ethtool_op_get_tx_csum, 4440 .get_tx_csum = ethtool_op_get_tx_csum,
4579 .get_sg = ethtool_op_get_sg, 4441 .get_sg = ethtool_op_get_sg,
4442 .get_drvinfo = bond_ethtool_get_drvinfo,
4580}; 4443};
4581 4444
4582/* 4445/*
@@ -5036,6 +4899,14 @@ static int __init bonding_init(void)
5036 return 0; 4899 return 0;
5037 4900
5038out_err: 4901out_err:
4902 /*
4903 * rtnl_unlock() will run netdev_run_todo(), putting the
4904 * thus-far-registered bonding devices into a state which
4905 * unregigister_netdevice() will accept
4906 */
4907 rtnl_unlock();
4908 rtnl_lock();
4909
5039 /* free and unregister all bonds that were successfully added */ 4910 /* free and unregister all bonds that were successfully added */
5040 bond_free_all(); 4911 bond_free_all();
5041 4912