tun.c (9fffc5c6dd7dafb2e021dbbe9a30be2566a6949a) | tun.c (83c1f36f9880814b24cdf6c2f91f66f61db65326) |
---|---|
1/* 2 * TUN - Universal TUN/TAP device driver. 3 * Copyright (C) 1999-2002 Maxim Krasnyansky <maxk@qualcomm.com> 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. --- 729 unchanged lines hidden (view full) --- 738 } 739 tun_cleanup_tx_ring(tfile); 740 sock_put(&tfile->sk); 741 } 742} 743 744static void tun_detach(struct tun_file *tfile, bool clean) 745{ | 1/* 2 * TUN - Universal TUN/TAP device driver. 3 * Copyright (C) 1999-2002 Maxim Krasnyansky <maxk@qualcomm.com> 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. --- 729 unchanged lines hidden (view full) --- 738 } 739 tun_cleanup_tx_ring(tfile); 740 sock_put(&tfile->sk); 741 } 742} 743 744static void tun_detach(struct tun_file *tfile, bool clean) 745{ |
746 struct tun_struct *tun; 747 struct net_device *dev; 748 |
|
746 rtnl_lock(); | 749 rtnl_lock(); |
750 tun = rtnl_dereference(tfile->tun); 751 dev = tun ? tun->dev : NULL; |
|
747 __tun_detach(tfile, clean); | 752 __tun_detach(tfile, clean); |
753 if (dev) 754 netdev_state_change(dev); |
|
748 rtnl_unlock(); 749} 750 751static void tun_detach_all(struct net_device *dev) 752{ 753 struct tun_struct *tun = netdev_priv(dev); 754 struct tun_file *tfile, *tmp; 755 int i, n = tun->numqueues; --- 1801 unchanged lines hidden (view full) --- 2557 if (err < 0) 2558 return err; 2559 2560 if (tun->flags & IFF_MULTI_QUEUE && 2561 (tun->numqueues + tun->numdisabled > 1)) { 2562 /* One or more queue has already been attached, no need 2563 * to initialize the device again. 2564 */ | 755 rtnl_unlock(); 756} 757 758static void tun_detach_all(struct net_device *dev) 759{ 760 struct tun_struct *tun = netdev_priv(dev); 761 struct tun_file *tfile, *tmp; 762 int i, n = tun->numqueues; --- 1801 unchanged lines hidden (view full) --- 2564 if (err < 0) 2565 return err; 2566 2567 if (tun->flags & IFF_MULTI_QUEUE && 2568 (tun->numqueues + tun->numdisabled > 1)) { 2569 /* One or more queue has already been attached, no need 2570 * to initialize the device again. 2571 */ |
2572 netdev_state_change(dev); |
|
2565 return 0; 2566 } 2567 2568 tun->flags = (tun->flags & ~TUN_FEATURES) | 2569 (ifr->ifr_flags & TUN_FEATURES); | 2573 return 0; 2574 } 2575 2576 tun->flags = (tun->flags & ~TUN_FEATURES) | 2577 (ifr->ifr_flags & TUN_FEATURES); |
2570 } 2571 else { | 2578 2579 netdev_state_change(dev); 2580 } else { |
2572 char *name; 2573 unsigned long flags = 0; 2574 int queues = ifr->ifr_flags & IFF_MULTI_QUEUE ? 2575 MAX_TAP_QUEUES : 1; 2576 2577 if (!ns_capable(net->user_ns, CAP_NET_ADMIN)) 2578 return -EPERM; 2579 err = security_tun_dev_create(); --- 223 unchanged lines hidden (view full) --- 2803 tun = rtnl_dereference(tfile->tun); 2804 if (!tun || !(tun->flags & IFF_MULTI_QUEUE) || tfile->detached) 2805 ret = -EINVAL; 2806 else 2807 __tun_detach(tfile, false); 2808 } else 2809 ret = -EINVAL; 2810 | 2581 char *name; 2582 unsigned long flags = 0; 2583 int queues = ifr->ifr_flags & IFF_MULTI_QUEUE ? 2584 MAX_TAP_QUEUES : 1; 2585 2586 if (!ns_capable(net->user_ns, CAP_NET_ADMIN)) 2587 return -EPERM; 2588 err = security_tun_dev_create(); --- 223 unchanged lines hidden (view full) --- 2812 tun = rtnl_dereference(tfile->tun); 2813 if (!tun || !(tun->flags & IFF_MULTI_QUEUE) || tfile->detached) 2814 ret = -EINVAL; 2815 else 2816 __tun_detach(tfile, false); 2817 } else 2818 ret = -EINVAL; 2819 |
2820 if (ret >= 0) 2821 netdev_state_change(tun->dev); 2822 |
|
2811unlock: 2812 rtnl_unlock(); 2813 return ret; 2814} 2815 2816static int tun_set_ebpf(struct tun_struct *tun, struct tun_prog **prog_p, 2817 void __user *data) 2818{ --- 24 unchanged lines hidden (view full) --- 2843 struct net *net; 2844 kuid_t owner; 2845 kgid_t group; 2846 int sndbuf; 2847 int vnet_hdr_sz; 2848 unsigned int ifindex; 2849 int le; 2850 int ret; | 2823unlock: 2824 rtnl_unlock(); 2825 return ret; 2826} 2827 2828static int tun_set_ebpf(struct tun_struct *tun, struct tun_prog **prog_p, 2829 void __user *data) 2830{ --- 24 unchanged lines hidden (view full) --- 2855 struct net *net; 2856 kuid_t owner; 2857 kgid_t group; 2858 int sndbuf; 2859 int vnet_hdr_sz; 2860 unsigned int ifindex; 2861 int le; 2862 int ret; |
2863 bool do_notify = false; |
|
2851 2852 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || 2853 (_IOC_TYPE(cmd) == SOCK_IOC_TYPE && cmd != SIOCGSKNS)) { 2854 if (copy_from_user(&ifr, argp, ifreq_len)) 2855 return -EFAULT; 2856 } else { 2857 memset(&ifr, 0, sizeof(ifr)); 2858 } --- 80 unchanged lines hidden (view full) --- 2939 2940 case TUNSETPERSIST: 2941 /* Disable/Enable persist mode. Keep an extra reference to the 2942 * module to prevent the module being unprobed. 2943 */ 2944 if (arg && !(tun->flags & IFF_PERSIST)) { 2945 tun->flags |= IFF_PERSIST; 2946 __module_get(THIS_MODULE); | 2864 2865 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || 2866 (_IOC_TYPE(cmd) == SOCK_IOC_TYPE && cmd != SIOCGSKNS)) { 2867 if (copy_from_user(&ifr, argp, ifreq_len)) 2868 return -EFAULT; 2869 } else { 2870 memset(&ifr, 0, sizeof(ifr)); 2871 } --- 80 unchanged lines hidden (view full) --- 2952 2953 case TUNSETPERSIST: 2954 /* Disable/Enable persist mode. Keep an extra reference to the 2955 * module to prevent the module being unprobed. 2956 */ 2957 if (arg && !(tun->flags & IFF_PERSIST)) { 2958 tun->flags |= IFF_PERSIST; 2959 __module_get(THIS_MODULE); |
2960 do_notify = true; |
|
2947 } 2948 if (!arg && (tun->flags & IFF_PERSIST)) { 2949 tun->flags &= ~IFF_PERSIST; 2950 module_put(THIS_MODULE); | 2961 } 2962 if (!arg && (tun->flags & IFF_PERSIST)) { 2963 tun->flags &= ~IFF_PERSIST; 2964 module_put(THIS_MODULE); |
2965 do_notify = true; |
|
2951 } 2952 2953 tun_debug(KERN_INFO, tun, "persist %s\n", 2954 arg ? "enabled" : "disabled"); 2955 break; 2956 2957 case TUNSETOWNER: 2958 /* Set owner of the device */ 2959 owner = make_kuid(current_user_ns(), arg); 2960 if (!uid_valid(owner)) { 2961 ret = -EINVAL; 2962 break; 2963 } 2964 tun->owner = owner; | 2966 } 2967 2968 tun_debug(KERN_INFO, tun, "persist %s\n", 2969 arg ? "enabled" : "disabled"); 2970 break; 2971 2972 case TUNSETOWNER: 2973 /* Set owner of the device */ 2974 owner = make_kuid(current_user_ns(), arg); 2975 if (!uid_valid(owner)) { 2976 ret = -EINVAL; 2977 break; 2978 } 2979 tun->owner = owner; |
2980 do_notify = true; |
|
2965 tun_debug(KERN_INFO, tun, "owner set to %u\n", 2966 from_kuid(&init_user_ns, tun->owner)); 2967 break; 2968 2969 case TUNSETGROUP: 2970 /* Set group of the device */ 2971 group = make_kgid(current_user_ns(), arg); 2972 if (!gid_valid(group)) { 2973 ret = -EINVAL; 2974 break; 2975 } 2976 tun->group = group; | 2981 tun_debug(KERN_INFO, tun, "owner set to %u\n", 2982 from_kuid(&init_user_ns, tun->owner)); 2983 break; 2984 2985 case TUNSETGROUP: 2986 /* Set group of the device */ 2987 group = make_kgid(current_user_ns(), arg); 2988 if (!gid_valid(group)) { 2989 ret = -EINVAL; 2990 break; 2991 } 2992 tun->group = group; |
2993 do_notify = true; |
|
2977 tun_debug(KERN_INFO, tun, "group set to %u\n", 2978 from_kgid(&init_user_ns, tun->group)); 2979 break; 2980 2981 case TUNSETLINK: 2982 /* Only allow setting the type when the interface is down */ 2983 if (tun->dev->flags & IFF_UP) { 2984 tun_debug(KERN_INFO, tun, --- 143 unchanged lines hidden (view full) --- 3128 ret = tun_set_ebpf(tun, &tun->filter_prog, argp); 3129 break; 3130 3131 default: 3132 ret = -EINVAL; 3133 break; 3134 } 3135 | 2994 tun_debug(KERN_INFO, tun, "group set to %u\n", 2995 from_kgid(&init_user_ns, tun->group)); 2996 break; 2997 2998 case TUNSETLINK: 2999 /* Only allow setting the type when the interface is down */ 3000 if (tun->dev->flags & IFF_UP) { 3001 tun_debug(KERN_INFO, tun, --- 143 unchanged lines hidden (view full) --- 3145 ret = tun_set_ebpf(tun, &tun->filter_prog, argp); 3146 break; 3147 3148 default: 3149 ret = -EINVAL; 3150 break; 3151 } 3152 |
3153 if (do_notify) 3154 netdev_state_change(tun->dev); 3155 |
|
3136unlock: 3137 rtnl_unlock(); 3138 if (tun) 3139 tun_put(tun); 3140 return ret; 3141} 3142 3143static long tun_chr_ioctl(struct file *file, --- 357 unchanged lines hidden --- | 3156unlock: 3157 rtnl_unlock(); 3158 if (tun) 3159 tun_put(tun); 3160 return ret; 3161} 3162 3163static long tun_chr_ioctl(struct file *file, --- 357 unchanged lines hidden --- |