Merge tag 'v4.17-rc2' into docs-next
[linux-2.6-microblaze.git] / drivers / net / tun.c
index a1ba262..ef33950 100644 (file)
@@ -743,8 +743,15 @@ static void __tun_detach(struct tun_file *tfile, bool clean)
 
 static void tun_detach(struct tun_file *tfile, bool clean)
 {
+       struct tun_struct *tun;
+       struct net_device *dev;
+
        rtnl_lock();
+       tun = rtnl_dereference(tfile->tun);
+       dev = tun ? tun->dev : NULL;
        __tun_detach(tfile, clean);
+       if (dev)
+               netdev_state_change(dev);
        rtnl_unlock();
 }
 
@@ -1095,12 +1102,7 @@ static netdev_tx_t tun_net_xmit(struct sk_buff *skb, struct net_device *dev)
                goto drop;
 
        len = run_ebpf_filter(tun, skb, len);
-
-       /* Trim extra bytes since we may insert vlan proto & TCI
-        * in tun_put_user().
-        */
-       len -= skb_vlan_tag_present(skb) ? sizeof(struct veth) : 0;
-       if (len <= 0 || pskb_trim(skb, len))
+       if (len == 0 || pskb_trim(skb, len))
                goto drop;
 
        if (unlikely(skb_orphan_frags_rx(skb, GFP_ATOMIC)))
@@ -2562,10 +2564,15 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
                        /* One or more queue has already been attached, no need
                         * to initialize the device again.
                         */
+                       netdev_state_change(dev);
                        return 0;
                }
-       }
-       else {
+
+               tun->flags = (tun->flags & ~TUN_FEATURES) |
+                             (ifr->ifr_flags & TUN_FEATURES);
+
+               netdev_state_change(dev);
+       } else {
                char *name;
                unsigned long flags = 0;
                int queues = ifr->ifr_flags & IFF_MULTI_QUEUE ?
@@ -2642,6 +2649,9 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
                                     ~(NETIF_F_HW_VLAN_CTAG_TX |
                                       NETIF_F_HW_VLAN_STAG_TX);
 
+               tun->flags = (tun->flags & ~TUN_FEATURES) |
+                             (ifr->ifr_flags & TUN_FEATURES);
+
                INIT_LIST_HEAD(&tun->disabled);
                err = tun_attach(tun, file, false, ifr->ifr_flags & IFF_NAPI);
                if (err < 0)
@@ -2656,9 +2666,6 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
 
        tun_debug(KERN_INFO, tun, "tun_set_iff\n");
 
-       tun->flags = (tun->flags & ~TUN_FEATURES) |
-               (ifr->ifr_flags & TUN_FEATURES);
-
        /* Make sure persistent devices do not get stuck in
         * xoff state.
         */
@@ -2805,6 +2812,9 @@ static int tun_set_queue(struct file *file, struct ifreq *ifr)
        } else
                ret = -EINVAL;
 
+       if (ret >= 0)
+               netdev_state_change(tun->dev);
+
 unlock:
        rtnl_unlock();
        return ret;
@@ -2845,6 +2855,7 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
        unsigned int ifindex;
        int le;
        int ret;
+       bool do_notify = false;
 
        if (cmd == TUNSETIFF || cmd == TUNSETQUEUE ||
            (_IOC_TYPE(cmd) == SOCK_IOC_TYPE && cmd != SIOCGSKNS)) {
@@ -2941,10 +2952,12 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
                if (arg && !(tun->flags & IFF_PERSIST)) {
                        tun->flags |= IFF_PERSIST;
                        __module_get(THIS_MODULE);
+                       do_notify = true;
                }
                if (!arg && (tun->flags & IFF_PERSIST)) {
                        tun->flags &= ~IFF_PERSIST;
                        module_put(THIS_MODULE);
+                       do_notify = true;
                }
 
                tun_debug(KERN_INFO, tun, "persist %s\n",
@@ -2959,6 +2972,7 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
                        break;
                }
                tun->owner = owner;
+               do_notify = true;
                tun_debug(KERN_INFO, tun, "owner set to %u\n",
                          from_kuid(&init_user_ns, tun->owner));
                break;
@@ -2971,6 +2985,7 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
                        break;
                }
                tun->group = group;
+               do_notify = true;
                tun_debug(KERN_INFO, tun, "group set to %u\n",
                          from_kgid(&init_user_ns, tun->group));
                break;
@@ -3130,6 +3145,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
                break;
        }
 
+       if (do_notify)
+               netdev_state_change(tun->dev);
+
 unlock:
        rtnl_unlock();
        if (tun)