Skip to content

Commit 83c1f36

Browse files
qsndavem330
authored andcommitted
tun: send netlink notification when the device is modified
I added dumping of link information about tun devices over netlink in commit 1ec010e ("tun: export flags, uid, gid, queue information over netlink"), but didn't add the missing netlink notifications when the device's exported properties change. This patch adds notifications when owner/group or flags are modified, when queues are attached/detached, and when a tun fd is closed. Reported-by: Thomas Haller <[email protected]> Fixes: 1ec010e ("tun: export flags, uid, gid, queue information over netlink") Signed-off-by: Sabrina Dubroca <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 9fffc5c commit 83c1f36

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

drivers/net/tun.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -743,8 +743,15 @@ static void __tun_detach(struct tun_file *tfile, bool clean)
743743

744744
static void tun_detach(struct tun_file *tfile, bool clean)
745745
{
746+
struct tun_struct *tun;
747+
struct net_device *dev;
748+
746749
rtnl_lock();
750+
tun = rtnl_dereference(tfile->tun);
751+
dev = tun ? tun->dev : NULL;
747752
__tun_detach(tfile, clean);
753+
if (dev)
754+
netdev_state_change(dev);
748755
rtnl_unlock();
749756
}
750757

@@ -2562,13 +2569,15 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
25622569
/* One or more queue has already been attached, no need
25632570
* to initialize the device again.
25642571
*/
2572+
netdev_state_change(dev);
25652573
return 0;
25662574
}
25672575

25682576
tun->flags = (tun->flags & ~TUN_FEATURES) |
25692577
(ifr->ifr_flags & TUN_FEATURES);
2570-
}
2571-
else {
2578+
2579+
netdev_state_change(dev);
2580+
} else {
25722581
char *name;
25732582
unsigned long flags = 0;
25742583
int queues = ifr->ifr_flags & IFF_MULTI_QUEUE ?
@@ -2808,6 +2817,9 @@ static int tun_set_queue(struct file *file, struct ifreq *ifr)
28082817
} else
28092818
ret = -EINVAL;
28102819

2820+
if (ret >= 0)
2821+
netdev_state_change(tun->dev);
2822+
28112823
unlock:
28122824
rtnl_unlock();
28132825
return ret;
@@ -2848,6 +2860,7 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
28482860
unsigned int ifindex;
28492861
int le;
28502862
int ret;
2863+
bool do_notify = false;
28512864

28522865
if (cmd == TUNSETIFF || cmd == TUNSETQUEUE ||
28532866
(_IOC_TYPE(cmd) == SOCK_IOC_TYPE && cmd != SIOCGSKNS)) {
@@ -2944,10 +2957,12 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
29442957
if (arg && !(tun->flags & IFF_PERSIST)) {
29452958
tun->flags |= IFF_PERSIST;
29462959
__module_get(THIS_MODULE);
2960+
do_notify = true;
29472961
}
29482962
if (!arg && (tun->flags & IFF_PERSIST)) {
29492963
tun->flags &= ~IFF_PERSIST;
29502964
module_put(THIS_MODULE);
2965+
do_notify = true;
29512966
}
29522967

29532968
tun_debug(KERN_INFO, tun, "persist %s\n",
@@ -2962,6 +2977,7 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
29622977
break;
29632978
}
29642979
tun->owner = owner;
2980+
do_notify = true;
29652981
tun_debug(KERN_INFO, tun, "owner set to %u\n",
29662982
from_kuid(&init_user_ns, tun->owner));
29672983
break;
@@ -2974,6 +2990,7 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
29742990
break;
29752991
}
29762992
tun->group = group;
2993+
do_notify = true;
29772994
tun_debug(KERN_INFO, tun, "group set to %u\n",
29782995
from_kgid(&init_user_ns, tun->group));
29792996
break;
@@ -3133,6 +3150,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
31333150
break;
31343151
}
31353152

3153+
if (do_notify)
3154+
netdev_state_change(tun->dev);
3155+
31363156
unlock:
31373157
rtnl_unlock();
31383158
if (tun)

0 commit comments

Comments
 (0)