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.c244
1 files changed, 182 insertions, 62 deletions
diff --git a/net/core/dev.c b/net/core/dev.c
index 09cb3f6dc40c..d0cbc93fcf32 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -176,8 +176,10 @@
176#define PTYPE_HASH_MASK (PTYPE_HASH_SIZE - 1) 176#define PTYPE_HASH_MASK (PTYPE_HASH_SIZE - 1)
177 177
178static DEFINE_SPINLOCK(ptype_lock); 178static DEFINE_SPINLOCK(ptype_lock);
179static DEFINE_SPINLOCK(offload_lock);
179static struct list_head ptype_base[PTYPE_HASH_SIZE] __read_mostly; 180static struct list_head ptype_base[PTYPE_HASH_SIZE] __read_mostly;
180static struct list_head ptype_all __read_mostly; /* Taps */ 181static struct list_head ptype_all __read_mostly; /* Taps */
182static struct list_head offload_base __read_mostly;
181 183
182/* 184/*
183 * The @dev_base_head list is protected by @dev_base_lock and the rtnl 185 * The @dev_base_head list is protected by @dev_base_lock and the rtnl
@@ -201,6 +203,8 @@ static struct list_head ptype_all __read_mostly; /* Taps */
201DEFINE_RWLOCK(dev_base_lock); 203DEFINE_RWLOCK(dev_base_lock);
202EXPORT_SYMBOL(dev_base_lock); 204EXPORT_SYMBOL(dev_base_lock);
203 205
206DEFINE_SEQLOCK(devnet_rename_seq);
207
204static inline void dev_base_seq_inc(struct net *net) 208static inline void dev_base_seq_inc(struct net *net)
205{ 209{
206 while (++net->dev_base_seq == 0); 210 while (++net->dev_base_seq == 0);
@@ -470,6 +474,82 @@ void dev_remove_pack(struct packet_type *pt)
470} 474}
471EXPORT_SYMBOL(dev_remove_pack); 475EXPORT_SYMBOL(dev_remove_pack);
472 476
477
478/**
479 * dev_add_offload - register offload handlers
480 * @po: protocol offload declaration
481 *
482 * Add protocol offload handlers to the networking stack. The passed
483 * &proto_offload is linked into kernel lists and may not be freed until
484 * it has been removed from the kernel lists.
485 *
486 * This call does not sleep therefore it can not
487 * guarantee all CPU's that are in middle of receiving packets
488 * will see the new offload handlers (until the next received packet).
489 */
490void dev_add_offload(struct packet_offload *po)
491{
492 struct list_head *head = &offload_base;
493
494 spin_lock(&offload_lock);
495 list_add_rcu(&po->list, head);
496 spin_unlock(&offload_lock);
497}
498EXPORT_SYMBOL(dev_add_offload);
499
500/**
501 * __dev_remove_offload - remove offload handler
502 * @po: packet offload declaration
503 *
504 * Remove a protocol offload handler that was previously added to the
505 * kernel offload handlers by dev_add_offload(). The passed &offload_type
506 * is removed from the kernel lists and can be freed or reused once this
507 * function returns.
508 *
509 * The packet type might still be in use by receivers
510 * and must not be freed until after all the CPU's have gone
511 * through a quiescent state.
512 */
513void __dev_remove_offload(struct packet_offload *po)
514{
515 struct list_head *head = &offload_base;
516 struct packet_offload *po1;
517
518 spin_lock(&offload_lock);
519
520 list_for_each_entry(po1, head, list) {
521 if (po == po1) {
522 list_del_rcu(&po->list);
523 goto out;
524 }
525 }
526
527 pr_warn("dev_remove_offload: %p not found\n", po);
528out:
529 spin_unlock(&offload_lock);
530}
531EXPORT_SYMBOL(__dev_remove_offload);
532
533/**
534 * dev_remove_offload - remove packet offload handler
535 * @po: packet offload declaration
536 *
537 * Remove a packet offload handler that was previously added to the kernel
538 * offload handlers by dev_add_offload(). The passed &offload_type is
539 * removed from the kernel lists and can be freed or reused once this
540 * function returns.
541 *
542 * This call sleeps to guarantee that no CPU is looking at the packet
543 * type after return.
544 */
545void dev_remove_offload(struct packet_offload *po)
546{
547 __dev_remove_offload(po);
548
549 synchronize_net();
550}
551EXPORT_SYMBOL(dev_remove_offload);
552
473/****************************************************************************** 553/******************************************************************************
474 554
475 Device Boot-time Settings Routines 555 Device Boot-time Settings Routines
@@ -1013,22 +1093,31 @@ int dev_change_name(struct net_device *dev, const char *newname)
1013 if (dev->flags & IFF_UP) 1093 if (dev->flags & IFF_UP)
1014 return -EBUSY; 1094 return -EBUSY;
1015 1095
1016 if (strncmp(newname, dev->name, IFNAMSIZ) == 0) 1096 write_seqlock(&devnet_rename_seq);
1097
1098 if (strncmp(newname, dev->name, IFNAMSIZ) == 0) {
1099 write_sequnlock(&devnet_rename_seq);
1017 return 0; 1100 return 0;
1101 }
1018 1102
1019 memcpy(oldname, dev->name, IFNAMSIZ); 1103 memcpy(oldname, dev->name, IFNAMSIZ);
1020 1104
1021 err = dev_get_valid_name(net, dev, newname); 1105 err = dev_get_valid_name(net, dev, newname);
1022 if (err < 0) 1106 if (err < 0) {
1107 write_sequnlock(&devnet_rename_seq);
1023 return err; 1108 return err;
1109 }
1024 1110
1025rollback: 1111rollback:
1026 ret = device_rename(&dev->dev, dev->name); 1112 ret = device_rename(&dev->dev, dev->name);
1027 if (ret) { 1113 if (ret) {
1028 memcpy(dev->name, oldname, IFNAMSIZ); 1114 memcpy(dev->name, oldname, IFNAMSIZ);
1115 write_sequnlock(&devnet_rename_seq);
1029 return ret; 1116 return ret;
1030 } 1117 }
1031 1118
1119 write_sequnlock(&devnet_rename_seq);
1120
1032 write_lock_bh(&dev_base_lock); 1121 write_lock_bh(&dev_base_lock);
1033 hlist_del_rcu(&dev->name_hlist); 1122 hlist_del_rcu(&dev->name_hlist);
1034 write_unlock_bh(&dev_base_lock); 1123 write_unlock_bh(&dev_base_lock);
@@ -1046,6 +1135,7 @@ rollback:
1046 /* err >= 0 after dev_alloc_name() or stores the first errno */ 1135 /* err >= 0 after dev_alloc_name() or stores the first errno */
1047 if (err >= 0) { 1136 if (err >= 0) {
1048 err = ret; 1137 err = ret;
1138 write_seqlock(&devnet_rename_seq);
1049 memcpy(dev->name, oldname, IFNAMSIZ); 1139 memcpy(dev->name, oldname, IFNAMSIZ);
1050 goto rollback; 1140 goto rollback;
1051 } else { 1141 } else {
@@ -1075,10 +1165,8 @@ int dev_set_alias(struct net_device *dev, const char *alias, size_t len)
1075 return -EINVAL; 1165 return -EINVAL;
1076 1166
1077 if (!len) { 1167 if (!len) {
1078 if (dev->ifalias) { 1168 kfree(dev->ifalias);
1079 kfree(dev->ifalias); 1169 dev->ifalias = NULL;
1080 dev->ifalias = NULL;
1081 }
1082 return 0; 1170 return 0;
1083 } 1171 }
1084 1172
@@ -1666,7 +1754,7 @@ static inline int deliver_skb(struct sk_buff *skb,
1666 1754
1667static inline bool skb_loop_sk(struct packet_type *ptype, struct sk_buff *skb) 1755static inline bool skb_loop_sk(struct packet_type *ptype, struct sk_buff *skb)
1668{ 1756{
1669 if (ptype->af_packet_priv == NULL) 1757 if (!ptype->af_packet_priv || !skb->sk)
1670 return false; 1758 return false;
1671 1759
1672 if (ptype->id_match) 1760 if (ptype->id_match)
@@ -1994,7 +2082,7 @@ struct sk_buff *skb_gso_segment(struct sk_buff *skb,
1994 netdev_features_t features) 2082 netdev_features_t features)
1995{ 2083{
1996 struct sk_buff *segs = ERR_PTR(-EPROTONOSUPPORT); 2084 struct sk_buff *segs = ERR_PTR(-EPROTONOSUPPORT);
1997 struct packet_type *ptype; 2085 struct packet_offload *ptype;
1998 __be16 type = skb->protocol; 2086 __be16 type = skb->protocol;
1999 int vlan_depth = ETH_HLEN; 2087 int vlan_depth = ETH_HLEN;
2000 int err; 2088 int err;
@@ -2023,18 +2111,17 @@ struct sk_buff *skb_gso_segment(struct sk_buff *skb,
2023 } 2111 }
2024 2112
2025 rcu_read_lock(); 2113 rcu_read_lock();
2026 list_for_each_entry_rcu(ptype, 2114 list_for_each_entry_rcu(ptype, &offload_base, list) {
2027 &ptype_base[ntohs(type) & PTYPE_HASH_MASK], list) { 2115 if (ptype->type == type && ptype->callbacks.gso_segment) {
2028 if (ptype->type == type && !ptype->dev && ptype->gso_segment) {
2029 if (unlikely(skb->ip_summed != CHECKSUM_PARTIAL)) { 2116 if (unlikely(skb->ip_summed != CHECKSUM_PARTIAL)) {
2030 err = ptype->gso_send_check(skb); 2117 err = ptype->callbacks.gso_send_check(skb);
2031 segs = ERR_PTR(err); 2118 segs = ERR_PTR(err);
2032 if (err || skb_gso_ok(skb, features)) 2119 if (err || skb_gso_ok(skb, features))
2033 break; 2120 break;
2034 __skb_push(skb, (skb->data - 2121 __skb_push(skb, (skb->data -
2035 skb_network_header(skb))); 2122 skb_network_header(skb)));
2036 } 2123 }
2037 segs = ptype->gso_segment(skb, features); 2124 segs = ptype->callbacks.gso_segment(skb, features);
2038 break; 2125 break;
2039 } 2126 }
2040 } 2127 }
@@ -2237,6 +2324,13 @@ int dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev,
2237 skb->vlan_tci = 0; 2324 skb->vlan_tci = 0;
2238 } 2325 }
2239 2326
2327 /* If encapsulation offload request, verify we are testing
2328 * hardware encapsulation features instead of standard
2329 * features for the netdev
2330 */
2331 if (skb->encapsulation)
2332 features &= dev->hw_enc_features;
2333
2240 if (netif_needs_gso(skb, features)) { 2334 if (netif_needs_gso(skb, features)) {
2241 if (unlikely(dev_gso_segment(skb, features))) 2335 if (unlikely(dev_gso_segment(skb, features)))
2242 goto out_kfree_skb; 2336 goto out_kfree_skb;
@@ -2252,8 +2346,12 @@ int dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev,
2252 * checksumming here. 2346 * checksumming here.
2253 */ 2347 */
2254 if (skb->ip_summed == CHECKSUM_PARTIAL) { 2348 if (skb->ip_summed == CHECKSUM_PARTIAL) {
2255 skb_set_transport_header(skb, 2349 if (skb->encapsulation)
2256 skb_checksum_start_offset(skb)); 2350 skb_set_inner_transport_header(skb,
2351 skb_checksum_start_offset(skb));
2352 else
2353 skb_set_transport_header(skb,
2354 skb_checksum_start_offset(skb));
2257 if (!(features & NETIF_F_ALL_CSUM) && 2355 if (!(features & NETIF_F_ALL_CSUM) &&
2258 skb_checksum_help(skb)) 2356 skb_checksum_help(skb))
2259 goto out_kfree_skb; 2357 goto out_kfree_skb;
@@ -2818,8 +2916,10 @@ static int get_rps_cpu(struct net_device *dev, struct sk_buff *skb,
2818 if (unlikely(tcpu != next_cpu) && 2916 if (unlikely(tcpu != next_cpu) &&
2819 (tcpu == RPS_NO_CPU || !cpu_online(tcpu) || 2917 (tcpu == RPS_NO_CPU || !cpu_online(tcpu) ||
2820 ((int)(per_cpu(softnet_data, tcpu).input_queue_head - 2918 ((int)(per_cpu(softnet_data, tcpu).input_queue_head -
2821 rflow->last_qtail)) >= 0)) 2919 rflow->last_qtail)) >= 0)) {
2920 tcpu = next_cpu;
2822 rflow = set_rps_cpu(dev, skb, rflow, next_cpu); 2921 rflow = set_rps_cpu(dev, skb, rflow, next_cpu);
2922 }
2823 2923
2824 if (tcpu != RPS_NO_CPU && cpu_online(tcpu)) { 2924 if (tcpu != RPS_NO_CPU && cpu_online(tcpu)) {
2825 *rflowp = rflow; 2925 *rflowp = rflow;
@@ -3444,11 +3544,13 @@ static void flush_backlog(void *arg)
3444 3544
3445static int napi_gro_complete(struct sk_buff *skb) 3545static int napi_gro_complete(struct sk_buff *skb)
3446{ 3546{
3447 struct packet_type *ptype; 3547 struct packet_offload *ptype;
3448 __be16 type = skb->protocol; 3548 __be16 type = skb->protocol;
3449 struct list_head *head = &ptype_base[ntohs(type) & PTYPE_HASH_MASK]; 3549 struct list_head *head = &offload_base;
3450 int err = -ENOENT; 3550 int err = -ENOENT;
3451 3551
3552 BUILD_BUG_ON(sizeof(struct napi_gro_cb) > sizeof(skb->cb));
3553
3452 if (NAPI_GRO_CB(skb)->count == 1) { 3554 if (NAPI_GRO_CB(skb)->count == 1) {
3453 skb_shinfo(skb)->gso_size = 0; 3555 skb_shinfo(skb)->gso_size = 0;
3454 goto out; 3556 goto out;
@@ -3456,10 +3558,10 @@ static int napi_gro_complete(struct sk_buff *skb)
3456 3558
3457 rcu_read_lock(); 3559 rcu_read_lock();
3458 list_for_each_entry_rcu(ptype, head, list) { 3560 list_for_each_entry_rcu(ptype, head, list) {
3459 if (ptype->type != type || ptype->dev || !ptype->gro_complete) 3561 if (ptype->type != type || !ptype->callbacks.gro_complete)
3460 continue; 3562 continue;
3461 3563
3462 err = ptype->gro_complete(skb); 3564 err = ptype->callbacks.gro_complete(skb);
3463 break; 3565 break;
3464 } 3566 }
3465 rcu_read_unlock(); 3567 rcu_read_unlock();
@@ -3503,12 +3605,34 @@ void napi_gro_flush(struct napi_struct *napi, bool flush_old)
3503} 3605}
3504EXPORT_SYMBOL(napi_gro_flush); 3606EXPORT_SYMBOL(napi_gro_flush);
3505 3607
3506enum gro_result dev_gro_receive(struct napi_struct *napi, struct sk_buff *skb) 3608static void gro_list_prepare(struct napi_struct *napi, struct sk_buff *skb)
3609{
3610 struct sk_buff *p;
3611 unsigned int maclen = skb->dev->hard_header_len;
3612
3613 for (p = napi->gro_list; p; p = p->next) {
3614 unsigned long diffs;
3615
3616 diffs = (unsigned long)p->dev ^ (unsigned long)skb->dev;
3617 diffs |= p->vlan_tci ^ skb->vlan_tci;
3618 if (maclen == ETH_HLEN)
3619 diffs |= compare_ether_header(skb_mac_header(p),
3620 skb_gro_mac_header(skb));
3621 else if (!diffs)
3622 diffs = memcmp(skb_mac_header(p),
3623 skb_gro_mac_header(skb),
3624 maclen);
3625 NAPI_GRO_CB(p)->same_flow = !diffs;
3626 NAPI_GRO_CB(p)->flush = 0;
3627 }
3628}
3629
3630static enum gro_result dev_gro_receive(struct napi_struct *napi, struct sk_buff *skb)
3507{ 3631{
3508 struct sk_buff **pp = NULL; 3632 struct sk_buff **pp = NULL;
3509 struct packet_type *ptype; 3633 struct packet_offload *ptype;
3510 __be16 type = skb->protocol; 3634 __be16 type = skb->protocol;
3511 struct list_head *head = &ptype_base[ntohs(type) & PTYPE_HASH_MASK]; 3635 struct list_head *head = &offload_base;
3512 int same_flow; 3636 int same_flow;
3513 int mac_len; 3637 int mac_len;
3514 enum gro_result ret; 3638 enum gro_result ret;
@@ -3519,9 +3643,11 @@ enum gro_result dev_gro_receive(struct napi_struct *napi, struct sk_buff *skb)
3519 if (skb_is_gso(skb) || skb_has_frag_list(skb)) 3643 if (skb_is_gso(skb) || skb_has_frag_list(skb))
3520 goto normal; 3644 goto normal;
3521 3645
3646 gro_list_prepare(napi, skb);
3647
3522 rcu_read_lock(); 3648 rcu_read_lock();
3523 list_for_each_entry_rcu(ptype, head, list) { 3649 list_for_each_entry_rcu(ptype, head, list) {
3524 if (ptype->type != type || ptype->dev || !ptype->gro_receive) 3650 if (ptype->type != type || !ptype->callbacks.gro_receive)
3525 continue; 3651 continue;
3526 3652
3527 skb_set_network_header(skb, skb_gro_offset(skb)); 3653 skb_set_network_header(skb, skb_gro_offset(skb));
@@ -3531,7 +3657,7 @@ enum gro_result dev_gro_receive(struct napi_struct *napi, struct sk_buff *skb)
3531 NAPI_GRO_CB(skb)->flush = 0; 3657 NAPI_GRO_CB(skb)->flush = 0;
3532 NAPI_GRO_CB(skb)->free = 0; 3658 NAPI_GRO_CB(skb)->free = 0;
3533 3659
3534 pp = ptype->gro_receive(&napi->gro_list, skb); 3660 pp = ptype->callbacks.gro_receive(&napi->gro_list, skb);
3535 break; 3661 break;
3536 } 3662 }
3537 rcu_read_unlock(); 3663 rcu_read_unlock();
@@ -3594,34 +3720,9 @@ normal:
3594 ret = GRO_NORMAL; 3720 ret = GRO_NORMAL;
3595 goto pull; 3721 goto pull;
3596} 3722}
3597EXPORT_SYMBOL(dev_gro_receive);
3598 3723
3599static inline gro_result_t
3600__napi_gro_receive(struct napi_struct *napi, struct sk_buff *skb)
3601{
3602 struct sk_buff *p;
3603 unsigned int maclen = skb->dev->hard_header_len;
3604 3724
3605 for (p = napi->gro_list; p; p = p->next) { 3725static gro_result_t napi_skb_finish(gro_result_t ret, struct sk_buff *skb)
3606 unsigned long diffs;
3607
3608 diffs = (unsigned long)p->dev ^ (unsigned long)skb->dev;
3609 diffs |= p->vlan_tci ^ skb->vlan_tci;
3610 if (maclen == ETH_HLEN)
3611 diffs |= compare_ether_header(skb_mac_header(p),
3612 skb_gro_mac_header(skb));
3613 else if (!diffs)
3614 diffs = memcmp(skb_mac_header(p),
3615 skb_gro_mac_header(skb),
3616 maclen);
3617 NAPI_GRO_CB(p)->same_flow = !diffs;
3618 NAPI_GRO_CB(p)->flush = 0;
3619 }
3620
3621 return dev_gro_receive(napi, skb);
3622}
3623
3624gro_result_t napi_skb_finish(gro_result_t ret, struct sk_buff *skb)
3625{ 3726{
3626 switch (ret) { 3727 switch (ret) {
3627 case GRO_NORMAL: 3728 case GRO_NORMAL:
@@ -3647,7 +3748,6 @@ gro_result_t napi_skb_finish(gro_result_t ret, struct sk_buff *skb)
3647 3748
3648 return ret; 3749 return ret;
3649} 3750}
3650EXPORT_SYMBOL(napi_skb_finish);
3651 3751
3652static void skb_gro_reset_offset(struct sk_buff *skb) 3752static void skb_gro_reset_offset(struct sk_buff *skb)
3653{ 3753{
@@ -3670,7 +3770,7 @@ gro_result_t napi_gro_receive(struct napi_struct *napi, struct sk_buff *skb)
3670{ 3770{
3671 skb_gro_reset_offset(skb); 3771 skb_gro_reset_offset(skb);
3672 3772
3673 return napi_skb_finish(__napi_gro_receive(napi, skb), skb); 3773 return napi_skb_finish(dev_gro_receive(napi, skb), skb);
3674} 3774}
3675EXPORT_SYMBOL(napi_gro_receive); 3775EXPORT_SYMBOL(napi_gro_receive);
3676 3776
@@ -3699,7 +3799,7 @@ struct sk_buff *napi_get_frags(struct napi_struct *napi)
3699} 3799}
3700EXPORT_SYMBOL(napi_get_frags); 3800EXPORT_SYMBOL(napi_get_frags);
3701 3801
3702gro_result_t napi_frags_finish(struct napi_struct *napi, struct sk_buff *skb, 3802static gro_result_t napi_frags_finish(struct napi_struct *napi, struct sk_buff *skb,
3703 gro_result_t ret) 3803 gro_result_t ret)
3704{ 3804{
3705 switch (ret) { 3805 switch (ret) {
@@ -3724,7 +3824,6 @@ gro_result_t napi_frags_finish(struct napi_struct *napi, struct sk_buff *skb,
3724 3824
3725 return ret; 3825 return ret;
3726} 3826}
3727EXPORT_SYMBOL(napi_frags_finish);
3728 3827
3729static struct sk_buff *napi_frags_skb(struct napi_struct *napi) 3828static struct sk_buff *napi_frags_skb(struct napi_struct *napi)
3730{ 3829{
@@ -3769,7 +3868,7 @@ gro_result_t napi_gro_frags(struct napi_struct *napi)
3769 if (!skb) 3868 if (!skb)
3770 return GRO_DROP; 3869 return GRO_DROP;
3771 3870
3772 return napi_frags_finish(napi, skb, __napi_gro_receive(napi, skb)); 3871 return napi_frags_finish(napi, skb, dev_gro_receive(napi, skb));
3773} 3872}
3774EXPORT_SYMBOL(napi_gro_frags); 3873EXPORT_SYMBOL(napi_gro_frags);
3775 3874
@@ -4071,6 +4170,7 @@ static int dev_ifname(struct net *net, struct ifreq __user *arg)
4071{ 4170{
4072 struct net_device *dev; 4171 struct net_device *dev;
4073 struct ifreq ifr; 4172 struct ifreq ifr;
4173 unsigned seq;
4074 4174
4075 /* 4175 /*
4076 * Fetch the caller's info block. 4176 * Fetch the caller's info block.
@@ -4079,6 +4179,8 @@ static int dev_ifname(struct net *net, struct ifreq __user *arg)
4079 if (copy_from_user(&ifr, arg, sizeof(struct ifreq))) 4179 if (copy_from_user(&ifr, arg, sizeof(struct ifreq)))
4080 return -EFAULT; 4180 return -EFAULT;
4081 4181
4182retry:
4183 seq = read_seqbegin(&devnet_rename_seq);
4082 rcu_read_lock(); 4184 rcu_read_lock();
4083 dev = dev_get_by_index_rcu(net, ifr.ifr_ifindex); 4185 dev = dev_get_by_index_rcu(net, ifr.ifr_ifindex);
4084 if (!dev) { 4186 if (!dev) {
@@ -4088,6 +4190,8 @@ static int dev_ifname(struct net *net, struct ifreq __user *arg)
4088 4190
4089 strcpy(ifr.ifr_name, dev->name); 4191 strcpy(ifr.ifr_name, dev->name);
4090 rcu_read_unlock(); 4192 rcu_read_unlock();
4193 if (read_seqretry(&devnet_rename_seq, seq))
4194 goto retry;
4091 4195
4092 if (copy_to_user(arg, &ifr, sizeof(struct ifreq))) 4196 if (copy_to_user(arg, &ifr, sizeof(struct ifreq)))
4093 return -EFAULT; 4197 return -EFAULT;
@@ -4880,7 +4984,7 @@ int dev_set_mtu(struct net_device *dev, int new_mtu)
4880 else 4984 else
4881 dev->mtu = new_mtu; 4985 dev->mtu = new_mtu;
4882 4986
4883 if (!err && dev->flags & IFF_UP) 4987 if (!err)
4884 call_netdevice_notifiers(NETDEV_CHANGEMTU, dev); 4988 call_netdevice_notifiers(NETDEV_CHANGEMTU, dev);
4885 return err; 4989 return err;
4886} 4990}
@@ -5200,7 +5304,7 @@ int dev_ioctl(struct net *net, unsigned int cmd, void __user *arg)
5200 case SIOCGMIIPHY: 5304 case SIOCGMIIPHY:
5201 case SIOCGMIIREG: 5305 case SIOCGMIIREG:
5202 case SIOCSIFNAME: 5306 case SIOCSIFNAME:
5203 if (!capable(CAP_NET_ADMIN)) 5307 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
5204 return -EPERM; 5308 return -EPERM;
5205 dev_load(net, ifr.ifr_name); 5309 dev_load(net, ifr.ifr_name);
5206 rtnl_lock(); 5310 rtnl_lock();
@@ -5221,16 +5325,25 @@ int dev_ioctl(struct net *net, unsigned int cmd, void __user *arg)
5221 * - require strict serialization. 5325 * - require strict serialization.
5222 * - do not return a value 5326 * - do not return a value
5223 */ 5327 */
5328 case SIOCSIFMAP:
5329 case SIOCSIFTXQLEN:
5330 if (!capable(CAP_NET_ADMIN))
5331 return -EPERM;
5332 /* fall through */
5333 /*
5334 * These ioctl calls:
5335 * - require local superuser power.
5336 * - require strict serialization.
5337 * - do not return a value
5338 */
5224 case SIOCSIFFLAGS: 5339 case SIOCSIFFLAGS:
5225 case SIOCSIFMETRIC: 5340 case SIOCSIFMETRIC:
5226 case SIOCSIFMTU: 5341 case SIOCSIFMTU:
5227 case SIOCSIFMAP:
5228 case SIOCSIFHWADDR: 5342 case SIOCSIFHWADDR:
5229 case SIOCSIFSLAVE: 5343 case SIOCSIFSLAVE:
5230 case SIOCADDMULTI: 5344 case SIOCADDMULTI:
5231 case SIOCDELMULTI: 5345 case SIOCDELMULTI:
5232 case SIOCSIFHWBROADCAST: 5346 case SIOCSIFHWBROADCAST:
5233 case SIOCSIFTXQLEN:
5234 case SIOCSMIIREG: 5347 case SIOCSMIIREG:
5235 case SIOCBONDENSLAVE: 5348 case SIOCBONDENSLAVE:
5236 case SIOCBONDRELEASE: 5349 case SIOCBONDRELEASE:
@@ -5239,7 +5352,7 @@ int dev_ioctl(struct net *net, unsigned int cmd, void __user *arg)
5239 case SIOCBRADDIF: 5352 case SIOCBRADDIF:
5240 case SIOCBRDELIF: 5353 case SIOCBRDELIF:
5241 case SIOCSHWTSTAMP: 5354 case SIOCSHWTSTAMP:
5242 if (!capable(CAP_NET_ADMIN)) 5355 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
5243 return -EPERM; 5356 return -EPERM;
5244 /* fall through */ 5357 /* fall through */
5245 case SIOCBONDSLAVEINFOQUERY: 5358 case SIOCBONDSLAVEINFOQUERY:
@@ -6264,7 +6377,6 @@ int dev_change_net_namespace(struct net_device *dev, struct net *net, const char
6264 goto out; 6377 goto out;
6265 6378
6266 /* Ensure the device has been registrered */ 6379 /* Ensure the device has been registrered */
6267 err = -EINVAL;
6268 if (dev->reg_state != NETREG_REGISTERED) 6380 if (dev->reg_state != NETREG_REGISTERED)
6269 goto out; 6381 goto out;
6270 6382
@@ -6319,6 +6431,9 @@ int dev_change_net_namespace(struct net_device *dev, struct net *net, const char
6319 dev_uc_flush(dev); 6431 dev_uc_flush(dev);
6320 dev_mc_flush(dev); 6432 dev_mc_flush(dev);
6321 6433
6434 /* Send a netdev-removed uevent to the old namespace */
6435 kobject_uevent(&dev->dev.kobj, KOBJ_REMOVE);
6436
6322 /* Actually switch the network namespace */ 6437 /* Actually switch the network namespace */
6323 dev_net_set(dev, net); 6438 dev_net_set(dev, net);
6324 6439
@@ -6330,6 +6445,9 @@ int dev_change_net_namespace(struct net_device *dev, struct net *net, const char
6330 dev->iflink = dev->ifindex; 6445 dev->iflink = dev->ifindex;
6331 } 6446 }
6332 6447
6448 /* Send a netdev-add uevent to the new namespace */
6449 kobject_uevent(&dev->dev.kobj, KOBJ_ADD);
6450
6333 /* Fixup kobjects */ 6451 /* Fixup kobjects */
6334 err = device_rename(&dev->dev, dev->name); 6452 err = device_rename(&dev->dev, dev->name);
6335 WARN_ON(err); 6453 WARN_ON(err);
@@ -6662,6 +6780,8 @@ static int __init net_dev_init(void)
6662 for (i = 0; i < PTYPE_HASH_SIZE; i++) 6780 for (i = 0; i < PTYPE_HASH_SIZE; i++)
6663 INIT_LIST_HEAD(&ptype_base[i]); 6781 INIT_LIST_HEAD(&ptype_base[i]);
6664 6782
6783 INIT_LIST_HEAD(&offload_base);
6784
6665 if (register_pernet_subsys(&netdev_net_ops)) 6785 if (register_pernet_subsys(&netdev_net_ops))
6666 goto out; 6786 goto out;
6667 6787