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.c148
1 files changed, 84 insertions, 64 deletions
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index b7d45f367d4a..22399374b1e1 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -746,11 +746,9 @@ static void __bond_resend_igmp_join_requests(struct net_device *dev)
746{ 746{
747 struct in_device *in_dev; 747 struct in_device *in_dev;
748 748
749 rcu_read_lock();
750 in_dev = __in_dev_get_rcu(dev); 749 in_dev = __in_dev_get_rcu(dev);
751 if (in_dev) 750 if (in_dev)
752 ip_mc_rejoin_groups(in_dev); 751 ip_mc_rejoin_groups(in_dev);
753 rcu_read_unlock();
754} 752}
755 753
756/* 754/*
@@ -760,9 +758,10 @@ static void __bond_resend_igmp_join_requests(struct net_device *dev)
760 */ 758 */
761static void bond_resend_igmp_join_requests(struct bonding *bond) 759static void bond_resend_igmp_join_requests(struct bonding *bond)
762{ 760{
763 struct net_device *bond_dev, *vlan_dev, *master_dev; 761 struct net_device *bond_dev, *vlan_dev, *upper_dev;
764 struct vlan_entry *vlan; 762 struct vlan_entry *vlan;
765 763
764 rcu_read_lock();
766 read_lock(&bond->lock); 765 read_lock(&bond->lock);
767 766
768 bond_dev = bond->dev; 767 bond_dev = bond->dev;
@@ -774,18 +773,14 @@ static void bond_resend_igmp_join_requests(struct bonding *bond)
774 * if bond is enslaved to a bridge, 773 * if bond is enslaved to a bridge,
775 * then rejoin all groups on its master 774 * then rejoin all groups on its master
776 */ 775 */
777 master_dev = bond_dev->master; 776 upper_dev = netdev_master_upper_dev_get_rcu(bond_dev);
778 if (master_dev) 777 if (upper_dev && upper_dev->priv_flags & IFF_EBRIDGE)
779 if ((master_dev->priv_flags & IFF_EBRIDGE) 778 __bond_resend_igmp_join_requests(upper_dev);
780 && (bond_dev->priv_flags & IFF_BRIDGE_PORT))
781 __bond_resend_igmp_join_requests(master_dev);
782 779
783 /* rejoin all groups on vlan devices */ 780 /* rejoin all groups on vlan devices */
784 list_for_each_entry(vlan, &bond->vlan_list, vlan_list) { 781 list_for_each_entry(vlan, &bond->vlan_list, vlan_list) {
785 rcu_read_lock();
786 vlan_dev = __vlan_find_dev_deep(bond_dev, 782 vlan_dev = __vlan_find_dev_deep(bond_dev,
787 vlan->vlan_id); 783 vlan->vlan_id);
788 rcu_read_unlock();
789 if (vlan_dev) 784 if (vlan_dev)
790 __bond_resend_igmp_join_requests(vlan_dev); 785 __bond_resend_igmp_join_requests(vlan_dev);
791 } 786 }
@@ -794,13 +789,16 @@ static void bond_resend_igmp_join_requests(struct bonding *bond)
794 queue_delayed_work(bond->wq, &bond->mcast_work, HZ/5); 789 queue_delayed_work(bond->wq, &bond->mcast_work, HZ/5);
795 790
796 read_unlock(&bond->lock); 791 read_unlock(&bond->lock);
792 rcu_read_unlock();
797} 793}
798 794
799static void bond_resend_igmp_join_requests_delayed(struct work_struct *work) 795static void bond_resend_igmp_join_requests_delayed(struct work_struct *work)
800{ 796{
801 struct bonding *bond = container_of(work, struct bonding, 797 struct bonding *bond = container_of(work, struct bonding,
802 mcast_work.work); 798 mcast_work.work);
799 rcu_read_lock();
803 bond_resend_igmp_join_requests(bond); 800 bond_resend_igmp_join_requests(bond);
801 rcu_read_unlock();
804} 802}
805 803
806/* 804/*
@@ -1322,14 +1320,15 @@ static void bond_netpoll_cleanup(struct net_device *bond_dev)
1322 1320
1323/*---------------------------------- IOCTL ----------------------------------*/ 1321/*---------------------------------- IOCTL ----------------------------------*/
1324 1322
1325static int bond_sethwaddr(struct net_device *bond_dev, 1323static void bond_set_dev_addr(struct net_device *bond_dev,
1326 struct net_device *slave_dev) 1324 struct net_device *slave_dev)
1327{ 1325{
1328 pr_debug("bond_dev=%p\n", bond_dev); 1326 pr_debug("bond_dev=%p\n", bond_dev);
1329 pr_debug("slave_dev=%p\n", slave_dev); 1327 pr_debug("slave_dev=%p\n", slave_dev);
1330 pr_debug("slave_dev->addr_len=%d\n", slave_dev->addr_len); 1328 pr_debug("slave_dev->addr_len=%d\n", slave_dev->addr_len);
1331 memcpy(bond_dev->dev_addr, slave_dev->dev_addr, slave_dev->addr_len); 1329 memcpy(bond_dev->dev_addr, slave_dev->dev_addr, slave_dev->addr_len);
1332 return 0; 1330 bond_dev->addr_assign_type = NET_ADDR_SET;
1331 call_netdevice_notifiers(NETDEV_CHANGEADDR, bond_dev);
1333} 1332}
1334 1333
1335static netdev_features_t bond_fix_features(struct net_device *dev, 1334static netdev_features_t bond_fix_features(struct net_device *dev,
@@ -1493,6 +1492,27 @@ static rx_handler_result_t bond_handle_frame(struct sk_buff **pskb)
1493 return ret; 1492 return ret;
1494} 1493}
1495 1494
1495static int bond_master_upper_dev_link(struct net_device *bond_dev,
1496 struct net_device *slave_dev)
1497{
1498 int err;
1499
1500 err = netdev_master_upper_dev_link(slave_dev, bond_dev);
1501 if (err)
1502 return err;
1503 slave_dev->flags |= IFF_SLAVE;
1504 rtmsg_ifinfo(RTM_NEWLINK, slave_dev, IFF_SLAVE);
1505 return 0;
1506}
1507
1508static void bond_upper_dev_unlink(struct net_device *bond_dev,
1509 struct net_device *slave_dev)
1510{
1511 netdev_upper_dev_unlink(slave_dev, bond_dev);
1512 slave_dev->flags &= ~IFF_SLAVE;
1513 rtmsg_ifinfo(RTM_NEWLINK, slave_dev, IFF_SLAVE);
1514}
1515
1496/* enslave device <slave> to bond device <master> */ 1516/* enslave device <slave> to bond device <master> */
1497int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev) 1517int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
1498{ 1518{
@@ -1609,10 +1629,8 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
1609 1629
1610 /* If this is the first slave, then we need to set the master's hardware 1630 /* If this is the first slave, then we need to set the master's hardware
1611 * address to be the same as the slave's. */ 1631 * address to be the same as the slave's. */
1612 if (is_zero_ether_addr(bond->dev->dev_addr)) 1632 if (bond->dev_addr_from_first)
1613 memcpy(bond->dev->dev_addr, slave_dev->dev_addr, 1633 bond_set_dev_addr(bond->dev, slave_dev);
1614 slave_dev->addr_len);
1615
1616 1634
1617 new_slave = kzalloc(sizeof(struct slave), GFP_KERNEL); 1635 new_slave = kzalloc(sizeof(struct slave), GFP_KERNEL);
1618 if (!new_slave) { 1636 if (!new_slave) {
@@ -1655,9 +1673,9 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
1655 } 1673 }
1656 } 1674 }
1657 1675
1658 res = netdev_set_bond_master(slave_dev, bond_dev); 1676 res = bond_master_upper_dev_link(bond_dev, slave_dev);
1659 if (res) { 1677 if (res) {
1660 pr_debug("Error %d calling netdev_set_bond_master\n", res); 1678 pr_debug("Error %d calling bond_master_upper_dev_link\n", res);
1661 goto err_restore_mac; 1679 goto err_restore_mac;
1662 } 1680 }
1663 1681
@@ -1891,7 +1909,7 @@ err_close:
1891 dev_close(slave_dev); 1909 dev_close(slave_dev);
1892 1910
1893err_unset_master: 1911err_unset_master:
1894 netdev_set_bond_master(slave_dev, NULL); 1912 bond_upper_dev_unlink(bond_dev, slave_dev);
1895 1913
1896err_restore_mac: 1914err_restore_mac:
1897 if (!bond->params.fail_over_mac) { 1915 if (!bond->params.fail_over_mac) {
@@ -1936,7 +1954,7 @@ int bond_release(struct net_device *bond_dev, struct net_device *slave_dev)
1936 1954
1937 /* slave is not a slave or master is not master of this slave */ 1955 /* slave is not a slave or master is not master of this slave */
1938 if (!(slave_dev->flags & IFF_SLAVE) || 1956 if (!(slave_dev->flags & IFF_SLAVE) ||
1939 (slave_dev->master != bond_dev)) { 1957 !netdev_has_upper_dev(slave_dev, bond_dev)) {
1940 pr_err("%s: Error: cannot release %s.\n", 1958 pr_err("%s: Error: cannot release %s.\n",
1941 bond_dev->name, slave_dev->name); 1959 bond_dev->name, slave_dev->name);
1942 return -EINVAL; 1960 return -EINVAL;
@@ -2029,12 +2047,8 @@ int bond_release(struct net_device *bond_dev, struct net_device *slave_dev)
2029 2047
2030 if (bond->slave_cnt == 0) { 2048 if (bond->slave_cnt == 0) {
2031 bond_set_carrier(bond); 2049 bond_set_carrier(bond);
2032 2050 eth_hw_addr_random(bond_dev);
2033 /* if the last slave was removed, zero the mac address 2051 bond->dev_addr_from_first = true;
2034 * of the master so it will be set by the application
2035 * to the mac address of the first slave
2036 */
2037 memset(bond_dev->dev_addr, 0, bond_dev->addr_len);
2038 2052
2039 if (bond_vlan_used(bond)) { 2053 if (bond_vlan_used(bond)) {
2040 pr_warning("%s: Warning: clearing HW address of %s while it still has VLANs.\n", 2054 pr_warning("%s: Warning: clearing HW address of %s while it still has VLANs.\n",
@@ -2080,7 +2094,7 @@ int bond_release(struct net_device *bond_dev, struct net_device *slave_dev)
2080 netif_addr_unlock_bh(bond_dev); 2094 netif_addr_unlock_bh(bond_dev);
2081 } 2095 }
2082 2096
2083 netdev_set_bond_master(slave_dev, NULL); 2097 bond_upper_dev_unlink(bond_dev, slave_dev);
2084 2098
2085 slave_disable_netpoll(slave); 2099 slave_disable_netpoll(slave);
2086 2100
@@ -2195,7 +2209,7 @@ static int bond_release_all(struct net_device *bond_dev)
2195 netif_addr_unlock_bh(bond_dev); 2209 netif_addr_unlock_bh(bond_dev);
2196 } 2210 }
2197 2211
2198 netdev_set_bond_master(slave_dev, NULL); 2212 bond_upper_dev_unlink(bond_dev, slave_dev);
2199 2213
2200 slave_disable_netpoll(slave); 2214 slave_disable_netpoll(slave);
2201 2215
@@ -2215,11 +2229,8 @@ static int bond_release_all(struct net_device *bond_dev)
2215 write_lock_bh(&bond->lock); 2229 write_lock_bh(&bond->lock);
2216 } 2230 }
2217 2231
2218 /* zero the mac address of the master so it will be 2232 eth_hw_addr_random(bond_dev);
2219 * set by the application to the mac address of the 2233 bond->dev_addr_from_first = true;
2220 * first slave
2221 */
2222 memset(bond_dev->dev_addr, 0, bond_dev->addr_len);
2223 2234
2224 if (bond_vlan_used(bond)) { 2235 if (bond_vlan_used(bond)) {
2225 pr_warning("%s: Warning: clearing HW address of %s while it still has VLANs.\n", 2236 pr_warning("%s: Warning: clearing HW address of %s while it still has VLANs.\n",
@@ -2259,8 +2270,9 @@ static int bond_ioctl_change_active(struct net_device *bond_dev, struct net_devi
2259 if (!USES_PRIMARY(bond->params.mode)) 2270 if (!USES_PRIMARY(bond->params.mode))
2260 return -EINVAL; 2271 return -EINVAL;
2261 2272
2262 /* Verify that master_dev is indeed the master of slave_dev */ 2273 /* Verify that bond_dev is indeed the master of slave_dev */
2263 if (!(slave_dev->flags & IFF_SLAVE) || (slave_dev->master != bond_dev)) 2274 if (!(slave_dev->flags & IFF_SLAVE) ||
2275 !netdev_has_upper_dev(slave_dev, bond_dev))
2264 return -EINVAL; 2276 return -EINVAL;
2265 2277
2266 read_lock(&bond->lock); 2278 read_lock(&bond->lock);
@@ -3258,36 +3270,32 @@ static int bond_master_netdev_event(unsigned long event,
3258static int bond_slave_netdev_event(unsigned long event, 3270static int bond_slave_netdev_event(unsigned long event,
3259 struct net_device *slave_dev) 3271 struct net_device *slave_dev)
3260{ 3272{
3261 struct net_device *bond_dev = slave_dev->master; 3273 struct slave *slave = bond_slave_get_rtnl(slave_dev);
3262 struct bonding *bond = netdev_priv(bond_dev); 3274 struct bonding *bond = slave->bond;
3263 struct slave *slave = NULL; 3275 struct net_device *bond_dev = slave->bond->dev;
3276 u32 old_speed;
3277 u8 old_duplex;
3264 3278
3265 switch (event) { 3279 switch (event) {
3266 case NETDEV_UNREGISTER: 3280 case NETDEV_UNREGISTER:
3267 if (bond_dev) { 3281 if (bond->setup_by_slave)
3268 if (bond->setup_by_slave) 3282 bond_release_and_destroy(bond_dev, slave_dev);
3269 bond_release_and_destroy(bond_dev, slave_dev); 3283 else
3270 else 3284 bond_release(bond_dev, slave_dev);
3271 bond_release(bond_dev, slave_dev);
3272 }
3273 break; 3285 break;
3274 case NETDEV_UP: 3286 case NETDEV_UP:
3275 case NETDEV_CHANGE: 3287 case NETDEV_CHANGE:
3276 slave = bond_get_slave_by_dev(bond, slave_dev); 3288 old_speed = slave->speed;
3277 if (slave) { 3289 old_duplex = slave->duplex;
3278 u32 old_speed = slave->speed;
3279 u8 old_duplex = slave->duplex;
3280 3290
3281 bond_update_speed_duplex(slave); 3291 bond_update_speed_duplex(slave);
3282 3292
3283 if (bond->params.mode == BOND_MODE_8023AD) { 3293 if (bond->params.mode == BOND_MODE_8023AD) {
3284 if (old_speed != slave->speed) 3294 if (old_speed != slave->speed)
3285 bond_3ad_adapter_speed_changed(slave); 3295 bond_3ad_adapter_speed_changed(slave);
3286 if (old_duplex != slave->duplex) 3296 if (old_duplex != slave->duplex)
3287 bond_3ad_adapter_duplex_changed(slave); 3297 bond_3ad_adapter_duplex_changed(slave);
3288 }
3289 } 3298 }
3290
3291 break; 3299 break;
3292 case NETDEV_DOWN: 3300 case NETDEV_DOWN:
3293 /* 3301 /*
@@ -3604,6 +3612,7 @@ static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd
3604 struct ifslave k_sinfo; 3612 struct ifslave k_sinfo;
3605 struct ifslave __user *u_sinfo = NULL; 3613 struct ifslave __user *u_sinfo = NULL;
3606 struct mii_ioctl_data *mii = NULL; 3614 struct mii_ioctl_data *mii = NULL;
3615 struct net *net;
3607 int res = 0; 3616 int res = 0;
3608 3617
3609 pr_debug("bond_ioctl: master=%s, cmd=%d\n", bond_dev->name, cmd); 3618 pr_debug("bond_ioctl: master=%s, cmd=%d\n", bond_dev->name, cmd);
@@ -3670,10 +3679,12 @@ static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd
3670 break; 3679 break;
3671 } 3680 }
3672 3681
3673 if (!capable(CAP_NET_ADMIN)) 3682 net = dev_net(bond_dev);
3683
3684 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
3674 return -EPERM; 3685 return -EPERM;
3675 3686
3676 slave_dev = dev_get_by_name(dev_net(bond_dev), ifr->ifr_slave); 3687 slave_dev = dev_get_by_name(net, ifr->ifr_slave);
3677 3688
3678 pr_debug("slave_dev=%p:\n", slave_dev); 3689 pr_debug("slave_dev=%p:\n", slave_dev);
3679 3690
@@ -3692,7 +3703,8 @@ static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd
3692 break; 3703 break;
3693 case BOND_SETHWADDR_OLD: 3704 case BOND_SETHWADDR_OLD:
3694 case SIOCBONDSETHWADDR: 3705 case SIOCBONDSETHWADDR:
3695 res = bond_sethwaddr(bond_dev, slave_dev); 3706 bond_set_dev_addr(bond_dev, slave_dev);
3707 res = 0;
3696 break; 3708 break;
3697 case BOND_CHANGE_ACTIVE_OLD: 3709 case BOND_CHANGE_ACTIVE_OLD:
3698 case SIOCBONDCHANGEACTIVE: 3710 case SIOCBONDCHANGEACTIVE:
@@ -4314,11 +4326,12 @@ void bond_set_mode_ops(struct bonding *bond, int mode)
4314} 4326}
4315 4327
4316static void bond_ethtool_get_drvinfo(struct net_device *bond_dev, 4328static void bond_ethtool_get_drvinfo(struct net_device *bond_dev,
4317 struct ethtool_drvinfo *drvinfo) 4329 struct ethtool_drvinfo *drvinfo)
4318{ 4330{
4319 strncpy(drvinfo->driver, DRV_NAME, 32); 4331 strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver));
4320 strncpy(drvinfo->version, DRV_VERSION, 32); 4332 strlcpy(drvinfo->version, DRV_VERSION, sizeof(drvinfo->version));
4321 snprintf(drvinfo->fw_version, 32, "%d", BOND_ABI_VERSION); 4333 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version), "%d",
4334 BOND_ABI_VERSION);
4322} 4335}
4323 4336
4324static const struct ethtool_ops bond_ethtool_ops = { 4337static const struct ethtool_ops bond_ethtool_ops = {
@@ -4841,6 +4854,13 @@ static int bond_init(struct net_device *bond_dev)
4841 4854
4842 bond_debug_register(bond); 4855 bond_debug_register(bond);
4843 4856
4857 /* Ensure valid dev_addr */
4858 if (is_zero_ether_addr(bond_dev->dev_addr) &&
4859 bond_dev->addr_assign_type == NET_ADDR_PERM) {
4860 eth_hw_addr_random(bond_dev);
4861 bond->dev_addr_from_first = true;
4862 }
4863
4844 __hw_addr_init(&bond->mc_list); 4864 __hw_addr_init(&bond->mc_list);
4845 return 0; 4865 return 0;
4846} 4866}