|
@@ -298,11 +298,12 @@ static void tun_flow_cleanup(unsigned long data)
|
|
}
|
|
}
|
|
|
|
|
|
static void tun_flow_update(struct tun_struct *tun, u32 rxhash,
|
|
static void tun_flow_update(struct tun_struct *tun, u32 rxhash,
|
|
- u16 queue_index)
|
|
|
|
|
|
+ struct tun_file *tfile)
|
|
{
|
|
{
|
|
struct hlist_head *head;
|
|
struct hlist_head *head;
|
|
struct tun_flow_entry *e;
|
|
struct tun_flow_entry *e;
|
|
unsigned long delay = tun->ageing_time;
|
|
unsigned long delay = tun->ageing_time;
|
|
|
|
+ u16 queue_index = tfile->queue_index;
|
|
|
|
|
|
if (!rxhash)
|
|
if (!rxhash)
|
|
return;
|
|
return;
|
|
@@ -311,7 +312,9 @@ static void tun_flow_update(struct tun_struct *tun, u32 rxhash,
|
|
|
|
|
|
rcu_read_lock();
|
|
rcu_read_lock();
|
|
|
|
|
|
- if (tun->numqueues == 1)
|
|
|
|
|
|
+ /* We may get a very small possibility of OOO during switching, not
|
|
|
|
+ * worth to optimize.*/
|
|
|
|
+ if (tun->numqueues == 1 || tfile->detached)
|
|
goto unlock;
|
|
goto unlock;
|
|
|
|
|
|
e = tun_flow_find(head, rxhash);
|
|
e = tun_flow_find(head, rxhash);
|
|
@@ -411,21 +414,21 @@ static void __tun_detach(struct tun_file *tfile, bool clean)
|
|
|
|
|
|
tun = rtnl_dereference(tfile->tun);
|
|
tun = rtnl_dereference(tfile->tun);
|
|
|
|
|
|
- if (tun) {
|
|
|
|
|
|
+ if (tun && !tfile->detached) {
|
|
u16 index = tfile->queue_index;
|
|
u16 index = tfile->queue_index;
|
|
BUG_ON(index >= tun->numqueues);
|
|
BUG_ON(index >= tun->numqueues);
|
|
dev = tun->dev;
|
|
dev = tun->dev;
|
|
|
|
|
|
rcu_assign_pointer(tun->tfiles[index],
|
|
rcu_assign_pointer(tun->tfiles[index],
|
|
tun->tfiles[tun->numqueues - 1]);
|
|
tun->tfiles[tun->numqueues - 1]);
|
|
- rcu_assign_pointer(tfile->tun, NULL);
|
|
|
|
ntfile = rtnl_dereference(tun->tfiles[index]);
|
|
ntfile = rtnl_dereference(tun->tfiles[index]);
|
|
ntfile->queue_index = index;
|
|
ntfile->queue_index = index;
|
|
|
|
|
|
--tun->numqueues;
|
|
--tun->numqueues;
|
|
- if (clean)
|
|
|
|
|
|
+ if (clean) {
|
|
|
|
+ rcu_assign_pointer(tfile->tun, NULL);
|
|
sock_put(&tfile->sk);
|
|
sock_put(&tfile->sk);
|
|
- else
|
|
|
|
|
|
+ } else
|
|
tun_disable_queue(tun, tfile);
|
|
tun_disable_queue(tun, tfile);
|
|
|
|
|
|
synchronize_net();
|
|
synchronize_net();
|
|
@@ -439,10 +442,13 @@ static void __tun_detach(struct tun_file *tfile, bool clean)
|
|
}
|
|
}
|
|
|
|
|
|
if (clean) {
|
|
if (clean) {
|
|
- if (tun && tun->numqueues == 0 && tun->numdisabled == 0 &&
|
|
|
|
- !(tun->flags & TUN_PERSIST))
|
|
|
|
- if (tun->dev->reg_state == NETREG_REGISTERED)
|
|
|
|
|
|
+ if (tun && tun->numqueues == 0 && tun->numdisabled == 0) {
|
|
|
|
+ netif_carrier_off(tun->dev);
|
|
|
|
+
|
|
|
|
+ if (!(tun->flags & TUN_PERSIST) &&
|
|
|
|
+ tun->dev->reg_state == NETREG_REGISTERED)
|
|
unregister_netdevice(tun->dev);
|
|
unregister_netdevice(tun->dev);
|
|
|
|
+ }
|
|
|
|
|
|
BUG_ON(!test_bit(SOCK_EXTERNALLY_ALLOCATED,
|
|
BUG_ON(!test_bit(SOCK_EXTERNALLY_ALLOCATED,
|
|
&tfile->socket.flags));
|
|
&tfile->socket.flags));
|
|
@@ -470,6 +476,10 @@ static void tun_detach_all(struct net_device *dev)
|
|
rcu_assign_pointer(tfile->tun, NULL);
|
|
rcu_assign_pointer(tfile->tun, NULL);
|
|
--tun->numqueues;
|
|
--tun->numqueues;
|
|
}
|
|
}
|
|
|
|
+ list_for_each_entry(tfile, &tun->disabled, next) {
|
|
|
|
+ wake_up_all(&tfile->wq.wait);
|
|
|
|
+ rcu_assign_pointer(tfile->tun, NULL);
|
|
|
|
+ }
|
|
BUG_ON(tun->numqueues != 0);
|
|
BUG_ON(tun->numqueues != 0);
|
|
|
|
|
|
synchronize_net();
|
|
synchronize_net();
|
|
@@ -500,7 +510,7 @@ static int tun_attach(struct tun_struct *tun, struct file *file)
|
|
goto out;
|
|
goto out;
|
|
|
|
|
|
err = -EINVAL;
|
|
err = -EINVAL;
|
|
- if (rtnl_dereference(tfile->tun))
|
|
|
|
|
|
+ if (rtnl_dereference(tfile->tun) && !tfile->detached)
|
|
goto out;
|
|
goto out;
|
|
|
|
|
|
err = -EBUSY;
|
|
err = -EBUSY;
|
|
@@ -1203,7 +1213,7 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
|
|
tun->dev->stats.rx_packets++;
|
|
tun->dev->stats.rx_packets++;
|
|
tun->dev->stats.rx_bytes += len;
|
|
tun->dev->stats.rx_bytes += len;
|
|
|
|
|
|
- tun_flow_update(tun, rxhash, tfile->queue_index);
|
|
|
|
|
|
+ tun_flow_update(tun, rxhash, tfile);
|
|
return total_len;
|
|
return total_len;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1662,10 +1672,10 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
|
|
device_create_file(&tun->dev->dev, &dev_attr_owner) ||
|
|
device_create_file(&tun->dev->dev, &dev_attr_owner) ||
|
|
device_create_file(&tun->dev->dev, &dev_attr_group))
|
|
device_create_file(&tun->dev->dev, &dev_attr_group))
|
|
pr_err("Failed to create tun sysfs files\n");
|
|
pr_err("Failed to create tun sysfs files\n");
|
|
-
|
|
|
|
- netif_carrier_on(tun->dev);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ netif_carrier_on(tun->dev);
|
|
|
|
+
|
|
tun_debug(KERN_INFO, tun, "tun_set_iff\n");
|
|
tun_debug(KERN_INFO, tun, "tun_set_iff\n");
|
|
|
|
|
|
if (ifr->ifr_flags & IFF_NO_PI)
|
|
if (ifr->ifr_flags & IFF_NO_PI)
|
|
@@ -1817,7 +1827,7 @@ static int tun_set_queue(struct file *file, struct ifreq *ifr)
|
|
ret = tun_attach(tun, file);
|
|
ret = tun_attach(tun, file);
|
|
} 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))
|
|
|
|
|
|
+ if (!tun || !(tun->flags & TUN_TAP_MQ) || tfile->detached)
|
|
ret = -EINVAL;
|
|
ret = -EINVAL;
|
|
else
|
|
else
|
|
__tun_detach(tfile, false);
|
|
__tun_detach(tfile, false);
|