Commit e2748d7e authored by David S. Miller's avatar David S. Miller

Merge branch 'tuntap'

Pavel Emelyanov says:

====================
tun: Some bits required for tun's checkpoint-restore (v2)

After taking a closer look on tun checkpoint-restore I've found several
issues with the tun's API that make it impossible to dump and restore
the state of tun device and attached tun-files.

The proposed API changes are all about extending the existing ioctl-based
stuff. Patches fit today's net-next.

This v2 has David's comments about patch #1 fixed. All the rest is the same.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 5f1cd200 76975e9c
...@@ -138,7 +138,10 @@ struct tun_file { ...@@ -138,7 +138,10 @@ struct tun_file {
struct fasync_struct *fasync; struct fasync_struct *fasync;
/* only used for fasnyc */ /* only used for fasnyc */
unsigned int flags; unsigned int flags;
union {
u16 queue_index; u16 queue_index;
unsigned int ifindex;
};
struct list_head next; struct list_head next;
struct tun_struct *detached; struct tun_struct *detached;
}; };
...@@ -498,7 +501,7 @@ static void tun_detach_all(struct net_device *dev) ...@@ -498,7 +501,7 @@ static void tun_detach_all(struct net_device *dev)
module_put(THIS_MODULE); module_put(THIS_MODULE);
} }
static int tun_attach(struct tun_struct *tun, struct file *file) static int tun_attach(struct tun_struct *tun, struct file *file, bool skip_filter)
{ {
struct tun_file *tfile = file->private_data; struct tun_file *tfile = file->private_data;
int err; int err;
...@@ -523,7 +526,7 @@ static int tun_attach(struct tun_struct *tun, struct file *file) ...@@ -523,7 +526,7 @@ static int tun_attach(struct tun_struct *tun, struct file *file)
err = 0; err = 0;
/* Re-attach the filter to presist device */ /* Re-attach the filter to presist device */
if (tun->filter_attached == true) { if (!skip_filter && (tun->filter_attached == true)) {
err = sk_attach_filter(&tun->fprog, tfile->socket.sk); err = sk_attach_filter(&tun->fprog, tfile->socket.sk);
if (!err) if (!err)
goto out; goto out;
...@@ -1554,7 +1557,7 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr) ...@@ -1554,7 +1557,7 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
if (err < 0) if (err < 0)
return err; return err;
err = tun_attach(tun, file); err = tun_attach(tun, file, ifr->ifr_flags & IFF_NOFILTER);
if (err < 0) if (err < 0)
return err; return err;
...@@ -1601,6 +1604,7 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr) ...@@ -1601,6 +1604,7 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
dev_net_set(dev, net); dev_net_set(dev, net);
dev->rtnl_link_ops = &tun_link_ops; dev->rtnl_link_ops = &tun_link_ops;
dev->ifindex = tfile->ifindex;
tun = netdev_priv(dev); tun = netdev_priv(dev);
tun->dev = dev; tun->dev = dev;
...@@ -1627,7 +1631,7 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr) ...@@ -1627,7 +1631,7 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
dev->vlan_features = dev->features; dev->vlan_features = dev->features;
INIT_LIST_HEAD(&tun->disabled); INIT_LIST_HEAD(&tun->disabled);
err = tun_attach(tun, file); err = tun_attach(tun, file, false);
if (err < 0) if (err < 0)
goto err_free_dev; goto err_free_dev;
...@@ -1791,7 +1795,7 @@ static int tun_set_queue(struct file *file, struct ifreq *ifr) ...@@ -1791,7 +1795,7 @@ static int tun_set_queue(struct file *file, struct ifreq *ifr)
ret = security_tun_dev_attach_queue(tun->security); ret = security_tun_dev_attach_queue(tun->security);
if (ret < 0) if (ret < 0)
goto unlock; goto unlock;
ret = tun_attach(tun, file); ret = tun_attach(tun, file, false);
} else if (ifr->ifr_flags & IFF_DETACH_QUEUE) { } else if (ifr->ifr_flags & IFF_DETACH_QUEUE) {
tun = rtnl_dereference(tfile->tun); tun = rtnl_dereference(tfile->tun);
if (!tun || !(tun->flags & TUN_TAP_MQ) || tfile->detached) if (!tun || !(tun->flags & TUN_TAP_MQ) || tfile->detached)
...@@ -1817,6 +1821,7 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd, ...@@ -1817,6 +1821,7 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
kgid_t group; kgid_t group;
int sndbuf; int sndbuf;
int vnet_hdr_sz; int vnet_hdr_sz;
unsigned int ifindex;
int ret; int ret;
if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) { if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
...@@ -1851,6 +1856,19 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd, ...@@ -1851,6 +1856,19 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
ret = -EFAULT; ret = -EFAULT;
goto unlock; goto unlock;
} }
if (cmd == TUNSETIFINDEX) {
ret = -EPERM;
if (tun)
goto unlock;
ret = -EFAULT;
if (copy_from_user(&ifindex, argp, sizeof(ifindex)))
goto unlock;
ret = 0;
tfile->ifindex = ifindex;
goto unlock;
}
ret = -EBADFD; ret = -EBADFD;
if (!tun) if (!tun)
...@@ -1863,6 +1881,11 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd, ...@@ -1863,6 +1881,11 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
case TUNGETIFF: case TUNGETIFF:
tun_get_iff(current->nsproxy->net_ns, tun, &ifr); tun_get_iff(current->nsproxy->net_ns, tun, &ifr);
if (tfile->detached)
ifr.ifr_flags |= IFF_DETACH_QUEUE;
if (!tfile->socket.sk->sk_filter)
ifr.ifr_flags |= IFF_NOFILTER;
if (copy_to_user(argp, &ifr, ifreq_len)) if (copy_to_user(argp, &ifr, ifreq_len))
ret = -EFAULT; ret = -EFAULT;
break; break;
...@@ -2019,6 +2042,16 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd, ...@@ -2019,6 +2042,16 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
tun_detach_filter(tun, tun->numqueues); tun_detach_filter(tun, tun->numqueues);
break; break;
case TUNGETFILTER:
ret = -EINVAL;
if ((tun->flags & TUN_TYPE_MASK) != TUN_TAP_DEV)
break;
ret = -EFAULT;
if (copy_to_user(argp, &tun->fprog, sizeof(tun->fprog)))
break;
ret = 0;
break;
default: default:
ret = -EINVAL; ret = -EINVAL;
break; break;
...@@ -2099,6 +2132,7 @@ static int tun_chr_open(struct inode *inode, struct file * file) ...@@ -2099,6 +2132,7 @@ static int tun_chr_open(struct inode *inode, struct file * file)
rcu_assign_pointer(tfile->tun, NULL); rcu_assign_pointer(tfile->tun, NULL);
tfile->net = get_net(current->nsproxy->net_ns); tfile->net = get_net(current->nsproxy->net_ns);
tfile->flags = 0; tfile->flags = 0;
tfile->ifindex = 0;
rcu_assign_pointer(tfile->socket.wq, &tfile->wq); rcu_assign_pointer(tfile->socket.wq, &tfile->wq);
init_waitqueue_head(&tfile->wq.wait); init_waitqueue_head(&tfile->wq.wait);
......
...@@ -56,6 +56,8 @@ ...@@ -56,6 +56,8 @@
#define TUNGETVNETHDRSZ _IOR('T', 215, int) #define TUNGETVNETHDRSZ _IOR('T', 215, int)
#define TUNSETVNETHDRSZ _IOW('T', 216, int) #define TUNSETVNETHDRSZ _IOW('T', 216, int)
#define TUNSETQUEUE _IOW('T', 217, int) #define TUNSETQUEUE _IOW('T', 217, int)
#define TUNSETIFINDEX _IOW('T', 218, unsigned int)
#define TUNGETFILTER _IOR('T', 219, struct sock_fprog)
/* TUNSETIFF ifr flags */ /* TUNSETIFF ifr flags */
#define IFF_TUN 0x0001 #define IFF_TUN 0x0001
...@@ -70,6 +72,7 @@ ...@@ -70,6 +72,7 @@
#define IFF_DETACH_QUEUE 0x0400 #define IFF_DETACH_QUEUE 0x0400
/* read-only flag */ /* read-only flag */
#define IFF_PERSIST 0x0800 #define IFF_PERSIST 0x0800
#define IFF_NOFILTER 0x1000
/* Socket options */ /* Socket options */
#define TUN_TX_TIMESTAMP 1 #define TUN_TX_TIMESTAMP 1
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment