aboutsummaryrefslogtreecommitdiffstats
path: root/net/core/dev.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/core/dev.c')
-rw-r--r--net/core/dev.c230
1 files changed, 158 insertions, 72 deletions
diff --git a/net/core/dev.c b/net/core/dev.c
index ed4550fd9ece..11560e3258b5 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -269,7 +269,8 @@ static const unsigned short netdev_lock_type[] =
269 ARPHRD_IRDA, ARPHRD_FCPP, ARPHRD_FCAL, ARPHRD_FCPL, 269 ARPHRD_IRDA, ARPHRD_FCPP, ARPHRD_FCAL, ARPHRD_FCPL,
270 ARPHRD_FCFABRIC, ARPHRD_IEEE802_TR, ARPHRD_IEEE80211, 270 ARPHRD_FCFABRIC, ARPHRD_IEEE802_TR, ARPHRD_IEEE80211,
271 ARPHRD_IEEE80211_PRISM, ARPHRD_IEEE80211_RADIOTAP, ARPHRD_PHONET, 271 ARPHRD_IEEE80211_PRISM, ARPHRD_IEEE80211_RADIOTAP, ARPHRD_PHONET,
272 ARPHRD_PHONET_PIPE, ARPHRD_VOID, ARPHRD_NONE}; 272 ARPHRD_PHONET_PIPE, ARPHRD_IEEE802154, ARPHRD_IEEE802154_PHY,
273 ARPHRD_VOID, ARPHRD_NONE};
273 274
274static const char *netdev_lock_name[] = 275static const char *netdev_lock_name[] =
275 {"_xmit_NETROM", "_xmit_ETHER", "_xmit_EETHER", "_xmit_AX25", 276 {"_xmit_NETROM", "_xmit_ETHER", "_xmit_EETHER", "_xmit_AX25",
@@ -286,7 +287,8 @@ static const char *netdev_lock_name[] =
286 "_xmit_IRDA", "_xmit_FCPP", "_xmit_FCAL", "_xmit_FCPL", 287 "_xmit_IRDA", "_xmit_FCPP", "_xmit_FCAL", "_xmit_FCPL",
287 "_xmit_FCFABRIC", "_xmit_IEEE802_TR", "_xmit_IEEE80211", 288 "_xmit_FCFABRIC", "_xmit_IEEE802_TR", "_xmit_IEEE80211",
288 "_xmit_IEEE80211_PRISM", "_xmit_IEEE80211_RADIOTAP", "_xmit_PHONET", 289 "_xmit_IEEE80211_PRISM", "_xmit_IEEE80211_RADIOTAP", "_xmit_PHONET",
289 "_xmit_PHONET_PIPE", "_xmit_VOID", "_xmit_NONE"}; 290 "_xmit_PHONET_PIPE", "_xmit_IEEE802154", "_xmit_IEEE802154_PHY",
291 "_xmit_VOID", "_xmit_NONE"};
290 292
291static struct lock_class_key netdev_xmit_lock_key[ARRAY_SIZE(netdev_lock_type)]; 293static struct lock_class_key netdev_xmit_lock_key[ARRAY_SIZE(netdev_lock_type)];
292static struct lock_class_key netdev_addr_lock_key[ARRAY_SIZE(netdev_lock_type)]; 294static struct lock_class_key netdev_addr_lock_key[ARRAY_SIZE(netdev_lock_type)];
@@ -1048,7 +1050,7 @@ void dev_load(struct net *net, const char *name)
1048int dev_open(struct net_device *dev) 1050int dev_open(struct net_device *dev)
1049{ 1051{
1050 const struct net_device_ops *ops = dev->netdev_ops; 1052 const struct net_device_ops *ops = dev->netdev_ops;
1051 int ret = 0; 1053 int ret;
1052 1054
1053 ASSERT_RTNL(); 1055 ASSERT_RTNL();
1054 1056
@@ -1065,6 +1067,11 @@ int dev_open(struct net_device *dev)
1065 if (!netif_device_present(dev)) 1067 if (!netif_device_present(dev))
1066 return -ENODEV; 1068 return -ENODEV;
1067 1069
1070 ret = call_netdevice_notifiers(NETDEV_PRE_UP, dev);
1071 ret = notifier_to_errno(ret);
1072 if (ret)
1073 return ret;
1074
1068 /* 1075 /*
1069 * Call device private open method 1076 * Call device private open method
1070 */ 1077 */
@@ -1693,10 +1700,9 @@ int dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev,
1693 * If device doesnt need skb->dst, release it right now while 1700 * If device doesnt need skb->dst, release it right now while
1694 * its hot in this cpu cache 1701 * its hot in this cpu cache
1695 */ 1702 */
1696 if ((dev->priv_flags & IFF_XMIT_DST_RELEASE) && skb->dst) { 1703 if (dev->priv_flags & IFF_XMIT_DST_RELEASE)
1697 dst_release(skb->dst); 1704 skb_dst_drop(skb);
1698 skb->dst = NULL; 1705
1699 }
1700 rc = ops->ndo_start_xmit(skb, dev); 1706 rc = ops->ndo_start_xmit(skb, dev);
1701 if (rc == 0) 1707 if (rc == 0)
1702 txq_trans_update(txq); 1708 txq_trans_update(txq);
@@ -1816,7 +1822,7 @@ int dev_queue_xmit(struct sk_buff *skb)
1816 if (netif_needs_gso(dev, skb)) 1822 if (netif_needs_gso(dev, skb))
1817 goto gso; 1823 goto gso;
1818 1824
1819 if (skb_shinfo(skb)->frag_list && 1825 if (skb_has_frags(skb) &&
1820 !(dev->features & NETIF_F_FRAGLIST) && 1826 !(dev->features & NETIF_F_FRAGLIST) &&
1821 __skb_linearize(skb)) 1827 __skb_linearize(skb))
1822 goto out_kfree_skb; 1828 goto out_kfree_skb;
@@ -2403,7 +2409,7 @@ int dev_gro_receive(struct napi_struct *napi, struct sk_buff *skb)
2403 if (!(skb->dev->features & NETIF_F_GRO)) 2409 if (!(skb->dev->features & NETIF_F_GRO))
2404 goto normal; 2410 goto normal;
2405 2411
2406 if (skb_is_gso(skb) || skb_shinfo(skb)->frag_list) 2412 if (skb_is_gso(skb) || skb_has_frags(skb))
2407 goto normal; 2413 goto normal;
2408 2414
2409 rcu_read_lock(); 2415 rcu_read_lock();
@@ -3473,8 +3479,9 @@ void dev_set_rx_mode(struct net_device *dev)
3473 3479
3474/* hw addresses list handling functions */ 3480/* hw addresses list handling functions */
3475 3481
3476static int __hw_addr_add(struct list_head *list, unsigned char *addr, 3482static int __hw_addr_add(struct list_head *list, int *delta,
3477 int addr_len, unsigned char addr_type) 3483 unsigned char *addr, int addr_len,
3484 unsigned char addr_type)
3478{ 3485{
3479 struct netdev_hw_addr *ha; 3486 struct netdev_hw_addr *ha;
3480 int alloc_size; 3487 int alloc_size;
@@ -3482,6 +3489,15 @@ static int __hw_addr_add(struct list_head *list, unsigned char *addr,
3482 if (addr_len > MAX_ADDR_LEN) 3489 if (addr_len > MAX_ADDR_LEN)
3483 return -EINVAL; 3490 return -EINVAL;
3484 3491
3492 list_for_each_entry(ha, list, list) {
3493 if (!memcmp(ha->addr, addr, addr_len) &&
3494 ha->type == addr_type) {
3495 ha->refcount++;
3496 return 0;
3497 }
3498 }
3499
3500
3485 alloc_size = sizeof(*ha); 3501 alloc_size = sizeof(*ha);
3486 if (alloc_size < L1_CACHE_BYTES) 3502 if (alloc_size < L1_CACHE_BYTES)
3487 alloc_size = L1_CACHE_BYTES; 3503 alloc_size = L1_CACHE_BYTES;
@@ -3490,7 +3506,11 @@ static int __hw_addr_add(struct list_head *list, unsigned char *addr,
3490 return -ENOMEM; 3506 return -ENOMEM;
3491 memcpy(ha->addr, addr, addr_len); 3507 memcpy(ha->addr, addr, addr_len);
3492 ha->type = addr_type; 3508 ha->type = addr_type;
3509 ha->refcount = 1;
3510 ha->synced = false;
3493 list_add_tail_rcu(&ha->list, list); 3511 list_add_tail_rcu(&ha->list, list);
3512 if (delta)
3513 (*delta)++;
3494 return 0; 3514 return 0;
3495} 3515}
3496 3516
@@ -3502,29 +3522,30 @@ static void ha_rcu_free(struct rcu_head *head)
3502 kfree(ha); 3522 kfree(ha);
3503} 3523}
3504 3524
3505static int __hw_addr_del_ii(struct list_head *list, unsigned char *addr, 3525static int __hw_addr_del(struct list_head *list, int *delta,
3506 int addr_len, unsigned char addr_type, 3526 unsigned char *addr, int addr_len,
3507 int ignore_index) 3527 unsigned char addr_type)
3508{ 3528{
3509 struct netdev_hw_addr *ha; 3529 struct netdev_hw_addr *ha;
3510 int i = 0;
3511 3530
3512 list_for_each_entry(ha, list, list) { 3531 list_for_each_entry(ha, list, list) {
3513 if (i++ != ignore_index && 3532 if (!memcmp(ha->addr, addr, addr_len) &&
3514 !memcmp(ha->addr, addr, addr_len) &&
3515 (ha->type == addr_type || !addr_type)) { 3533 (ha->type == addr_type || !addr_type)) {
3534 if (--ha->refcount)
3535 return 0;
3516 list_del_rcu(&ha->list); 3536 list_del_rcu(&ha->list);
3517 call_rcu(&ha->rcu_head, ha_rcu_free); 3537 call_rcu(&ha->rcu_head, ha_rcu_free);
3538 if (delta)
3539 (*delta)--;
3518 return 0; 3540 return 0;
3519 } 3541 }
3520 } 3542 }
3521 return -ENOENT; 3543 return -ENOENT;
3522} 3544}
3523 3545
3524static int __hw_addr_add_multiple_ii(struct list_head *to_list, 3546static int __hw_addr_add_multiple(struct list_head *to_list, int *to_delta,
3525 struct list_head *from_list, 3547 struct list_head *from_list, int addr_len,
3526 int addr_len, unsigned char addr_type, 3548 unsigned char addr_type)
3527 int ignore_index)
3528{ 3549{
3529 int err; 3550 int err;
3530 struct netdev_hw_addr *ha, *ha2; 3551 struct netdev_hw_addr *ha, *ha2;
@@ -3532,7 +3553,8 @@ static int __hw_addr_add_multiple_ii(struct list_head *to_list,
3532 3553
3533 list_for_each_entry(ha, from_list, list) { 3554 list_for_each_entry(ha, from_list, list) {
3534 type = addr_type ? addr_type : ha->type; 3555 type = addr_type ? addr_type : ha->type;
3535 err = __hw_addr_add(to_list, ha->addr, addr_len, type); 3556 err = __hw_addr_add(to_list, to_delta, ha->addr,
3557 addr_len, type);
3536 if (err) 3558 if (err)
3537 goto unroll; 3559 goto unroll;
3538 } 3560 }
@@ -3543,27 +3565,69 @@ unroll:
3543 if (ha2 == ha) 3565 if (ha2 == ha)
3544 break; 3566 break;
3545 type = addr_type ? addr_type : ha2->type; 3567 type = addr_type ? addr_type : ha2->type;
3546 __hw_addr_del_ii(to_list, ha2->addr, addr_len, type, 3568 __hw_addr_del(to_list, to_delta, ha2->addr,
3547 ignore_index); 3569 addr_len, type);
3548 } 3570 }
3549 return err; 3571 return err;
3550} 3572}
3551 3573
3552static void __hw_addr_del_multiple_ii(struct list_head *to_list, 3574static void __hw_addr_del_multiple(struct list_head *to_list, int *to_delta,
3553 struct list_head *from_list, 3575 struct list_head *from_list, int addr_len,
3554 int addr_len, unsigned char addr_type, 3576 unsigned char addr_type)
3555 int ignore_index)
3556{ 3577{
3557 struct netdev_hw_addr *ha; 3578 struct netdev_hw_addr *ha;
3558 unsigned char type; 3579 unsigned char type;
3559 3580
3560 list_for_each_entry(ha, from_list, list) { 3581 list_for_each_entry(ha, from_list, list) {
3561 type = addr_type ? addr_type : ha->type; 3582 type = addr_type ? addr_type : ha->type;
3562 __hw_addr_del_ii(to_list, ha->addr, addr_len, addr_type, 3583 __hw_addr_del(to_list, to_delta, ha->addr,
3563 ignore_index); 3584 addr_len, addr_type);
3585 }
3586}
3587
3588static int __hw_addr_sync(struct list_head *to_list, int *to_delta,
3589 struct list_head *from_list, int *from_delta,
3590 int addr_len)
3591{
3592 int err = 0;
3593 struct netdev_hw_addr *ha, *tmp;
3594
3595 list_for_each_entry_safe(ha, tmp, from_list, list) {
3596 if (!ha->synced) {
3597 err = __hw_addr_add(to_list, to_delta, ha->addr,
3598 addr_len, ha->type);
3599 if (err)
3600 break;
3601 ha->synced = true;
3602 ha->refcount++;
3603 } else if (ha->refcount == 1) {
3604 __hw_addr_del(to_list, to_delta, ha->addr,
3605 addr_len, ha->type);
3606 __hw_addr_del(from_list, from_delta, ha->addr,
3607 addr_len, ha->type);
3608 }
3609 }
3610 return err;
3611}
3612
3613static void __hw_addr_unsync(struct list_head *to_list, int *to_delta,
3614 struct list_head *from_list, int *from_delta,
3615 int addr_len)
3616{
3617 struct netdev_hw_addr *ha, *tmp;
3618
3619 list_for_each_entry_safe(ha, tmp, from_list, list) {
3620 if (ha->synced) {
3621 __hw_addr_del(to_list, to_delta, ha->addr,
3622 addr_len, ha->type);
3623 ha->synced = false;
3624 __hw_addr_del(from_list, from_delta, ha->addr,
3625 addr_len, ha->type);
3626 }
3564 } 3627 }
3565} 3628}
3566 3629
3630
3567static void __hw_addr_flush(struct list_head *list) 3631static void __hw_addr_flush(struct list_head *list)
3568{ 3632{
3569 struct netdev_hw_addr *ha, *tmp; 3633 struct netdev_hw_addr *ha, *tmp;
@@ -3593,8 +3657,8 @@ static int dev_addr_init(struct net_device *dev)
3593 /* rtnl_mutex must be held here */ 3657 /* rtnl_mutex must be held here */
3594 3658
3595 INIT_LIST_HEAD(&dev->dev_addr_list); 3659 INIT_LIST_HEAD(&dev->dev_addr_list);
3596 memset(addr, 0, sizeof(*addr)); 3660 memset(addr, 0, sizeof(addr));
3597 err = __hw_addr_add(&dev->dev_addr_list, addr, sizeof(*addr), 3661 err = __hw_addr_add(&dev->dev_addr_list, NULL, addr, sizeof(addr),
3598 NETDEV_HW_ADDR_T_LAN); 3662 NETDEV_HW_ADDR_T_LAN);
3599 if (!err) { 3663 if (!err) {
3600 /* 3664 /*
@@ -3626,7 +3690,7 @@ int dev_addr_add(struct net_device *dev, unsigned char *addr,
3626 3690
3627 ASSERT_RTNL(); 3691 ASSERT_RTNL();
3628 3692
3629 err = __hw_addr_add(&dev->dev_addr_list, addr, dev->addr_len, 3693 err = __hw_addr_add(&dev->dev_addr_list, NULL, addr, dev->addr_len,
3630 addr_type); 3694 addr_type);
3631 if (!err) 3695 if (!err)
3632 call_netdevice_notifiers(NETDEV_CHANGEADDR, dev); 3696 call_netdevice_notifiers(NETDEV_CHANGEADDR, dev);
@@ -3649,11 +3713,20 @@ int dev_addr_del(struct net_device *dev, unsigned char *addr,
3649 unsigned char addr_type) 3713 unsigned char addr_type)
3650{ 3714{
3651 int err; 3715 int err;
3716 struct netdev_hw_addr *ha;
3652 3717
3653 ASSERT_RTNL(); 3718 ASSERT_RTNL();
3654 3719
3655 err = __hw_addr_del_ii(&dev->dev_addr_list, addr, dev->addr_len, 3720 /*
3656 addr_type, 0); 3721 * We can not remove the first address from the list because
3722 * dev->dev_addr points to that.
3723 */
3724 ha = list_first_entry(&dev->dev_addr_list, struct netdev_hw_addr, list);
3725 if (ha->addr == dev->dev_addr && ha->refcount == 1)
3726 return -ENOENT;
3727
3728 err = __hw_addr_del(&dev->dev_addr_list, NULL, addr, dev->addr_len,
3729 addr_type);
3657 if (!err) 3730 if (!err)
3658 call_netdevice_notifiers(NETDEV_CHANGEADDR, dev); 3731 call_netdevice_notifiers(NETDEV_CHANGEADDR, dev);
3659 return err; 3732 return err;
@@ -3680,9 +3753,9 @@ int dev_addr_add_multiple(struct net_device *to_dev,
3680 3753
3681 if (from_dev->addr_len != to_dev->addr_len) 3754 if (from_dev->addr_len != to_dev->addr_len)
3682 return -EINVAL; 3755 return -EINVAL;
3683 err = __hw_addr_add_multiple_ii(&to_dev->dev_addr_list, 3756 err = __hw_addr_add_multiple(&to_dev->dev_addr_list, NULL,
3684 &from_dev->dev_addr_list, 3757 &from_dev->dev_addr_list,
3685 to_dev->addr_len, addr_type, 0); 3758 to_dev->addr_len, addr_type);
3686 if (!err) 3759 if (!err)
3687 call_netdevice_notifiers(NETDEV_CHANGEADDR, to_dev); 3760 call_netdevice_notifiers(NETDEV_CHANGEADDR, to_dev);
3688 return err; 3761 return err;
@@ -3707,9 +3780,9 @@ int dev_addr_del_multiple(struct net_device *to_dev,
3707 3780
3708 if (from_dev->addr_len != to_dev->addr_len) 3781 if (from_dev->addr_len != to_dev->addr_len)
3709 return -EINVAL; 3782 return -EINVAL;
3710 __hw_addr_del_multiple_ii(&to_dev->dev_addr_list, 3783 __hw_addr_del_multiple(&to_dev->dev_addr_list, NULL,
3711 &from_dev->dev_addr_list, 3784 &from_dev->dev_addr_list,
3712 to_dev->addr_len, addr_type, 0); 3785 to_dev->addr_len, addr_type);
3713 call_netdevice_notifiers(NETDEV_CHANGEADDR, to_dev); 3786 call_netdevice_notifiers(NETDEV_CHANGEADDR, to_dev);
3714 return 0; 3787 return 0;
3715} 3788}
@@ -3779,24 +3852,22 @@ int __dev_addr_add(struct dev_addr_list **list, int *count,
3779 * dev_unicast_delete - Release secondary unicast address. 3852 * dev_unicast_delete - Release secondary unicast address.
3780 * @dev: device 3853 * @dev: device
3781 * @addr: address to delete 3854 * @addr: address to delete
3782 * @alen: length of @addr
3783 * 3855 *
3784 * Release reference to a secondary unicast address and remove it 3856 * Release reference to a secondary unicast address and remove it
3785 * from the device if the reference count drops to zero. 3857 * from the device if the reference count drops to zero.
3786 * 3858 *
3787 * The caller must hold the rtnl_mutex. 3859 * The caller must hold the rtnl_mutex.
3788 */ 3860 */
3789int dev_unicast_delete(struct net_device *dev, void *addr, int alen) 3861int dev_unicast_delete(struct net_device *dev, void *addr)
3790{ 3862{
3791 int err; 3863 int err;
3792 3864
3793 ASSERT_RTNL(); 3865 ASSERT_RTNL();
3794 3866
3795 netif_addr_lock_bh(dev); 3867 err = __hw_addr_del(&dev->uc_list, &dev->uc_count, addr,
3796 err = __dev_addr_delete(&dev->uc_list, &dev->uc_count, addr, alen, 0); 3868 dev->addr_len, NETDEV_HW_ADDR_T_UNICAST);
3797 if (!err) 3869 if (!err)
3798 __dev_set_rx_mode(dev); 3870 __dev_set_rx_mode(dev);
3799 netif_addr_unlock_bh(dev);
3800 return err; 3871 return err;
3801} 3872}
3802EXPORT_SYMBOL(dev_unicast_delete); 3873EXPORT_SYMBOL(dev_unicast_delete);
@@ -3805,24 +3876,22 @@ EXPORT_SYMBOL(dev_unicast_delete);
3805 * dev_unicast_add - add a secondary unicast address 3876 * dev_unicast_add - add a secondary unicast address
3806 * @dev: device 3877 * @dev: device
3807 * @addr: address to add 3878 * @addr: address to add
3808 * @alen: length of @addr
3809 * 3879 *
3810 * Add a secondary unicast address to the device or increase 3880 * Add a secondary unicast address to the device or increase
3811 * the reference count if it already exists. 3881 * the reference count if it already exists.
3812 * 3882 *
3813 * The caller must hold the rtnl_mutex. 3883 * The caller must hold the rtnl_mutex.
3814 */ 3884 */
3815int dev_unicast_add(struct net_device *dev, void *addr, int alen) 3885int dev_unicast_add(struct net_device *dev, void *addr)
3816{ 3886{
3817 int err; 3887 int err;
3818 3888
3819 ASSERT_RTNL(); 3889 ASSERT_RTNL();
3820 3890
3821 netif_addr_lock_bh(dev); 3891 err = __hw_addr_add(&dev->uc_list, &dev->uc_count, addr,
3822 err = __dev_addr_add(&dev->uc_list, &dev->uc_count, addr, alen, 0); 3892 dev->addr_len, NETDEV_HW_ADDR_T_UNICAST);
3823 if (!err) 3893 if (!err)
3824 __dev_set_rx_mode(dev); 3894 __dev_set_rx_mode(dev);
3825 netif_addr_unlock_bh(dev);
3826 return err; 3895 return err;
3827} 3896}
3828EXPORT_SYMBOL(dev_unicast_add); 3897EXPORT_SYMBOL(dev_unicast_add);
@@ -3879,8 +3948,7 @@ void __dev_addr_unsync(struct dev_addr_list **to, int *to_count,
3879 * @from: source device 3948 * @from: source device
3880 * 3949 *
3881 * Add newly added addresses to the destination device and release 3950 * Add newly added addresses to the destination device and release
3882 * addresses that have no users left. The source device must be 3951 * addresses that have no users left.
3883 * locked by netif_tx_lock_bh.
3884 * 3952 *
3885 * This function is intended to be called from the dev->set_rx_mode 3953 * This function is intended to be called from the dev->set_rx_mode
3886 * function of layered software devices. 3954 * function of layered software devices.
@@ -3889,12 +3957,15 @@ int dev_unicast_sync(struct net_device *to, struct net_device *from)
3889{ 3957{
3890 int err = 0; 3958 int err = 0;
3891 3959
3892 netif_addr_lock_bh(to); 3960 ASSERT_RTNL();
3893 err = __dev_addr_sync(&to->uc_list, &to->uc_count, 3961
3894 &from->uc_list, &from->uc_count); 3962 if (to->addr_len != from->addr_len)
3963 return -EINVAL;
3964
3965 err = __hw_addr_sync(&to->uc_list, &to->uc_count,
3966 &from->uc_list, &from->uc_count, to->addr_len);
3895 if (!err) 3967 if (!err)
3896 __dev_set_rx_mode(to); 3968 __dev_set_rx_mode(to);
3897 netif_addr_unlock_bh(to);
3898 return err; 3969 return err;
3899} 3970}
3900EXPORT_SYMBOL(dev_unicast_sync); 3971EXPORT_SYMBOL(dev_unicast_sync);
@@ -3910,18 +3981,33 @@ EXPORT_SYMBOL(dev_unicast_sync);
3910 */ 3981 */
3911void dev_unicast_unsync(struct net_device *to, struct net_device *from) 3982void dev_unicast_unsync(struct net_device *to, struct net_device *from)
3912{ 3983{
3913 netif_addr_lock_bh(from); 3984 ASSERT_RTNL();
3914 netif_addr_lock(to);
3915 3985
3916 __dev_addr_unsync(&to->uc_list, &to->uc_count, 3986 if (to->addr_len != from->addr_len)
3917 &from->uc_list, &from->uc_count); 3987 return;
3918 __dev_set_rx_mode(to);
3919 3988
3920 netif_addr_unlock(to); 3989 __hw_addr_unsync(&to->uc_list, &to->uc_count,
3921 netif_addr_unlock_bh(from); 3990 &from->uc_list, &from->uc_count, to->addr_len);
3991 __dev_set_rx_mode(to);
3922} 3992}
3923EXPORT_SYMBOL(dev_unicast_unsync); 3993EXPORT_SYMBOL(dev_unicast_unsync);
3924 3994
3995static void dev_unicast_flush(struct net_device *dev)
3996{
3997 /* rtnl_mutex must be held here */
3998
3999 __hw_addr_flush(&dev->uc_list);
4000 dev->uc_count = 0;
4001}
4002
4003static void dev_unicast_init(struct net_device *dev)
4004{
4005 /* rtnl_mutex must be held here */
4006
4007 INIT_LIST_HEAD(&dev->uc_list);
4008}
4009
4010
3925static void __dev_addr_discard(struct dev_addr_list **list) 4011static void __dev_addr_discard(struct dev_addr_list **list)
3926{ 4012{
3927 struct dev_addr_list *tmp; 4013 struct dev_addr_list *tmp;
@@ -3940,9 +4026,6 @@ static void dev_addr_discard(struct net_device *dev)
3940{ 4026{
3941 netif_addr_lock_bh(dev); 4027 netif_addr_lock_bh(dev);
3942 4028
3943 __dev_addr_discard(&dev->uc_list);
3944 dev->uc_count = 0;
3945
3946 __dev_addr_discard(&dev->mc_list); 4029 __dev_addr_discard(&dev->mc_list);
3947 dev->mc_count = 0; 4030 dev->mc_count = 0;
3948 4031
@@ -4535,6 +4618,7 @@ static void rollback_registered(struct net_device *dev)
4535 /* 4618 /*
4536 * Flush the unicast and multicast chains 4619 * Flush the unicast and multicast chains
4537 */ 4620 */
4621 dev_unicast_flush(dev);
4538 dev_addr_discard(dev); 4622 dev_addr_discard(dev);
4539 4623
4540 if (dev->netdev_ops->ndo_uninit) 4624 if (dev->netdev_ops->ndo_uninit)
@@ -4988,18 +5072,18 @@ struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name,
4988 struct netdev_queue *tx; 5072 struct netdev_queue *tx;
4989 struct net_device *dev; 5073 struct net_device *dev;
4990 size_t alloc_size; 5074 size_t alloc_size;
4991 void *p; 5075 struct net_device *p;
4992 5076
4993 BUG_ON(strlen(name) >= sizeof(dev->name)); 5077 BUG_ON(strlen(name) >= sizeof(dev->name));
4994 5078
4995 alloc_size = sizeof(struct net_device); 5079 alloc_size = sizeof(struct net_device);
4996 if (sizeof_priv) { 5080 if (sizeof_priv) {
4997 /* ensure 32-byte alignment of private area */ 5081 /* ensure 32-byte alignment of private area */
4998 alloc_size = (alloc_size + NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST; 5082 alloc_size = ALIGN(alloc_size, NETDEV_ALIGN);
4999 alloc_size += sizeof_priv; 5083 alloc_size += sizeof_priv;
5000 } 5084 }
5001 /* ensure 32-byte alignment of whole construct */ 5085 /* ensure 32-byte alignment of whole construct */
5002 alloc_size += NETDEV_ALIGN_CONST; 5086 alloc_size += NETDEV_ALIGN - 1;
5003 5087
5004 p = kzalloc(alloc_size, GFP_KERNEL); 5088 p = kzalloc(alloc_size, GFP_KERNEL);
5005 if (!p) { 5089 if (!p) {
@@ -5014,13 +5098,14 @@ struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name,
5014 goto free_p; 5098 goto free_p;
5015 } 5099 }
5016 5100
5017 dev = (struct net_device *) 5101 dev = PTR_ALIGN(p, NETDEV_ALIGN);
5018 (((long)p + NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST);
5019 dev->padded = (char *)dev - (char *)p; 5102 dev->padded = (char *)dev - (char *)p;
5020 5103
5021 if (dev_addr_init(dev)) 5104 if (dev_addr_init(dev))
5022 goto free_tx; 5105 goto free_tx;
5023 5106
5107 dev_unicast_init(dev);
5108
5024 dev_net_set(dev, &init_net); 5109 dev_net_set(dev, &init_net);
5025 5110
5026 dev->_tx = tx; 5111 dev->_tx = tx;
@@ -5224,6 +5309,7 @@ int dev_change_net_namespace(struct net_device *dev, struct net *net, const char
5224 /* 5309 /*
5225 * Flush the unicast and multicast chains 5310 * Flush the unicast and multicast chains
5226 */ 5311 */
5312 dev_unicast_flush(dev);
5227 dev_addr_discard(dev); 5313 dev_addr_discard(dev);
5228 5314
5229 netdev_unregister_kobject(dev); 5315 netdev_unregister_kobject(dev);