* [PATCH net 1/2] tun: set the flags before registering the netdevice
@ 2018-04-10 14:28 Sabrina Dubroca
2018-04-10 14:28 ` [PATCH net 2/2] tun: send netlink notification when the device is modified Sabrina Dubroca
2018-04-11 18:48 ` [PATCH net 1/2] tun: set the flags before registering the netdevice David Miller
0 siblings, 2 replies; 4+ messages in thread
From: Sabrina Dubroca @ 2018-04-10 14:28 UTC (permalink / raw)
To: netdev; +Cc: Sabrina Dubroca, Thomas Haller, Stefano Brivio
Otherwise, register_netdevice advertises the creation of the device with
the default flags, instead of what the user requested.
Reported-by: Thomas Haller <thaller@redhat.com>
Fixes: 1ec010e70593 ("tun: export flags, uid, gid, queue information over netlink")
Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
---
drivers/net/tun.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index a1ba262f40ad..c9e68fd76a37 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -2564,6 +2564,9 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
*/
return 0;
}
+
+ tun->flags = (tun->flags & ~TUN_FEATURES) |
+ (ifr->ifr_flags & TUN_FEATURES);
}
else {
char *name;
@@ -2642,6 +2645,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 +2662,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.
*/
--
2.16.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH net 2/2] tun: send netlink notification when the device is modified
2018-04-10 14:28 [PATCH net 1/2] tun: set the flags before registering the netdevice Sabrina Dubroca
@ 2018-04-10 14:28 ` Sabrina Dubroca
2018-04-11 18:48 ` David Miller
2018-04-11 18:48 ` [PATCH net 1/2] tun: set the flags before registering the netdevice David Miller
1 sibling, 1 reply; 4+ messages in thread
From: Sabrina Dubroca @ 2018-04-10 14:28 UTC (permalink / raw)
To: netdev; +Cc: Sabrina Dubroca, Thomas Haller, Stefano Brivio
I added dumping of link information about tun devices over netlink in
commit 1ec010e70593 ("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 <thaller@redhat.com>
Fixes: 1ec010e70593 ("tun: export flags, uid, gid, queue information over netlink")
Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
---
drivers/net/tun.c | 24 ++++++++++++++++++++++--
1 file changed, 22 insertions(+), 2 deletions(-)
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index c9e68fd76a37..28583aa0c17d 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -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();
}
@@ -2562,13 +2569,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;
}
tun->flags = (tun->flags & ~TUN_FEATURES) |
(ifr->ifr_flags & TUN_FEATURES);
- }
- else {
+
+ netdev_state_change(dev);
+ } else {
char *name;
unsigned long flags = 0;
int queues = ifr->ifr_flags & IFF_MULTI_QUEUE ?
@@ -2808,6 +2817,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;
@@ -2848,6 +2860,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)) {
@@ -2944,10 +2957,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",
@@ -2962,6 +2977,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;
@@ -2974,6 +2990,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;
@@ -3133,6 +3150,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)
--
2.16.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net 1/2] tun: set the flags before registering the netdevice
2018-04-10 14:28 [PATCH net 1/2] tun: set the flags before registering the netdevice Sabrina Dubroca
2018-04-10 14:28 ` [PATCH net 2/2] tun: send netlink notification when the device is modified Sabrina Dubroca
@ 2018-04-11 18:48 ` David Miller
1 sibling, 0 replies; 4+ messages in thread
From: David Miller @ 2018-04-11 18:48 UTC (permalink / raw)
To: sd; +Cc: netdev, thaller, sbrivio
From: Sabrina Dubroca <sd@queasysnail.net>
Date: Tue, 10 Apr 2018 16:28:55 +0200
> Otherwise, register_netdevice advertises the creation of the device with
> the default flags, instead of what the user requested.
>
> Reported-by: Thomas Haller <thaller@redhat.com>
> Fixes: 1ec010e70593 ("tun: export flags, uid, gid, queue information over netlink")
> Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
Applied and queued up for -stable.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net 2/2] tun: send netlink notification when the device is modified
2018-04-10 14:28 ` [PATCH net 2/2] tun: send netlink notification when the device is modified Sabrina Dubroca
@ 2018-04-11 18:48 ` David Miller
0 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2018-04-11 18:48 UTC (permalink / raw)
To: sd; +Cc: netdev, thaller, sbrivio
From: Sabrina Dubroca <sd@queasysnail.net>
Date: Tue, 10 Apr 2018 16:28:56 +0200
> I added dumping of link information about tun devices over netlink in
> commit 1ec010e70593 ("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 <thaller@redhat.com>
> Fixes: 1ec010e70593 ("tun: export flags, uid, gid, queue information over netlink")
> Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
Applied and queued up for -stable.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-04-11 18:48 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-04-10 14:28 [PATCH net 1/2] tun: set the flags before registering the netdevice Sabrina Dubroca
2018-04-10 14:28 ` [PATCH net 2/2] tun: send netlink notification when the device is modified Sabrina Dubroca
2018-04-11 18:48 ` David Miller
2018-04-11 18:48 ` [PATCH net 1/2] tun: set the flags before registering the netdevice David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).