aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/tun.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/tun.c')
-rw-r--r--drivers/net/tun.c37
1 files changed, 20 insertions, 17 deletions
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 10f9e4021b5a..857dca47bf80 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -123,10 +123,9 @@ struct tap_filter {
123 unsigned char addr[FLT_EXACT_COUNT][ETH_ALEN]; 123 unsigned char addr[FLT_EXACT_COUNT][ETH_ALEN];
124}; 124};
125 125
126/* DEFAULT_MAX_NUM_RSS_QUEUES were chosen to let the rx/tx queues allocated for 126/* MAX_TAP_QUEUES 256 is chosen to allow rx/tx queues to be equal
127 * the netdevice to be fit in one page. So we can make sure the success of 127 * to max number of VCPUs in guest. */
128 * memory allocation. TODO: increase the limit. */ 128#define MAX_TAP_QUEUES 256
129#define MAX_TAP_QUEUES DEFAULT_MAX_NUM_RSS_QUEUES
130#define MAX_TAP_FLOWS 4096 129#define MAX_TAP_FLOWS 4096
131 130
132#define TUN_FLOW_EXPIRE (3 * HZ) 131#define TUN_FLOW_EXPIRE (3 * HZ)
@@ -257,7 +256,6 @@ static void tun_flow_delete(struct tun_struct *tun, struct tun_flow_entry *e)
257{ 256{
258 tun_debug(KERN_INFO, tun, "delete flow: hash %u index %u\n", 257 tun_debug(KERN_INFO, tun, "delete flow: hash %u index %u\n",
259 e->rxhash, e->queue_index); 258 e->rxhash, e->queue_index);
260 sock_rps_reset_flow_hash(e->rps_rxhash);
261 hlist_del_rcu(&e->hash_link); 259 hlist_del_rcu(&e->hash_link);
262 kfree_rcu(e, rcu); 260 kfree_rcu(e, rcu);
263 --tun->flow_count; 261 --tun->flow_count;
@@ -374,10 +372,8 @@ unlock:
374 */ 372 */
375static inline void tun_flow_save_rps_rxhash(struct tun_flow_entry *e, u32 hash) 373static inline void tun_flow_save_rps_rxhash(struct tun_flow_entry *e, u32 hash)
376{ 374{
377 if (unlikely(e->rps_rxhash != hash)) { 375 if (unlikely(e->rps_rxhash != hash))
378 sock_rps_reset_flow_hash(e->rps_rxhash);
379 e->rps_rxhash = hash; 376 e->rps_rxhash = hash;
380 }
381} 377}
382 378
383/* We try to identify a flow through its rxhash first. The reason that 379/* We try to identify a flow through its rxhash first. The reason that
@@ -1247,7 +1243,7 @@ static ssize_t tun_put_user(struct tun_struct *tun,
1247 int vlan_hlen = 0; 1243 int vlan_hlen = 0;
1248 int vnet_hdr_sz = 0; 1244 int vnet_hdr_sz = 0;
1249 1245
1250 if (vlan_tx_tag_present(skb)) 1246 if (skb_vlan_tag_present(skb))
1251 vlan_hlen = VLAN_HLEN; 1247 vlan_hlen = VLAN_HLEN;
1252 1248
1253 if (tun->flags & IFF_VNET_HDR) 1249 if (tun->flags & IFF_VNET_HDR)
@@ -1326,7 +1322,7 @@ static ssize_t tun_put_user(struct tun_struct *tun,
1326 } veth; 1322 } veth;
1327 1323
1328 veth.h_vlan_proto = skb->vlan_proto; 1324 veth.h_vlan_proto = skb->vlan_proto;
1329 veth.h_vlan_TCI = htons(vlan_tx_tag_get(skb)); 1325 veth.h_vlan_TCI = htons(skb_vlan_tag_get(skb));
1330 1326
1331 vlan_offset = offsetof(struct vlan_ethhdr, h_vlan_proto); 1327 vlan_offset = offsetof(struct vlan_ethhdr, h_vlan_proto);
1332 1328
@@ -1368,7 +1364,7 @@ static ssize_t tun_do_read(struct tun_struct *tun, struct tun_file *tfile,
1368 skb = __skb_recv_datagram(tfile->socket.sk, noblock ? MSG_DONTWAIT : 0, 1364 skb = __skb_recv_datagram(tfile->socket.sk, noblock ? MSG_DONTWAIT : 0,
1369 &peeked, &off, &err); 1365 &peeked, &off, &err);
1370 if (!skb) 1366 if (!skb)
1371 return 0; 1367 return err;
1372 1368
1373 ret = tun_put_user(tun, tfile, skb, to); 1369 ret = tun_put_user(tun, tfile, skb, to);
1374 if (unlikely(ret < 0)) 1370 if (unlikely(ret < 0))
@@ -1489,7 +1485,7 @@ static int tun_recvmsg(struct kiocb *iocb, struct socket *sock,
1489 goto out; 1485 goto out;
1490 } 1486 }
1491 ret = tun_do_read(tun, tfile, &m->msg_iter, flags & MSG_DONTWAIT); 1487 ret = tun_do_read(tun, tfile, &m->msg_iter, flags & MSG_DONTWAIT);
1492 if (ret > total_len) { 1488 if (ret > (ssize_t)total_len) {
1493 m->msg_flags |= MSG_TRUNC; 1489 m->msg_flags |= MSG_TRUNC;
1494 ret = flags & MSG_TRUNC ? ret : total_len; 1490 ret = flags & MSG_TRUNC ? ret : total_len;
1495 } 1491 }
@@ -1554,6 +1550,17 @@ static DEVICE_ATTR(tun_flags, 0444, tun_show_flags, NULL);
1554static DEVICE_ATTR(owner, 0444, tun_show_owner, NULL); 1550static DEVICE_ATTR(owner, 0444, tun_show_owner, NULL);
1555static DEVICE_ATTR(group, 0444, tun_show_group, NULL); 1551static DEVICE_ATTR(group, 0444, tun_show_group, NULL);
1556 1552
1553static struct attribute *tun_dev_attrs[] = {
1554 &dev_attr_tun_flags.attr,
1555 &dev_attr_owner.attr,
1556 &dev_attr_group.attr,
1557 NULL
1558};
1559
1560static const struct attribute_group tun_attr_group = {
1561 .attrs = tun_dev_attrs
1562};
1563
1557static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr) 1564static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
1558{ 1565{
1559 struct tun_struct *tun; 1566 struct tun_struct *tun;
@@ -1634,6 +1641,7 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
1634 dev_net_set(dev, net); 1641 dev_net_set(dev, net);
1635 dev->rtnl_link_ops = &tun_link_ops; 1642 dev->rtnl_link_ops = &tun_link_ops;
1636 dev->ifindex = tfile->ifindex; 1643 dev->ifindex = tfile->ifindex;
1644 dev->sysfs_groups[0] = &tun_attr_group;
1637 1645
1638 tun = netdev_priv(dev); 1646 tun = netdev_priv(dev);
1639 tun->dev = dev; 1647 tun->dev = dev;
@@ -1669,11 +1677,6 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
1669 err = register_netdevice(tun->dev); 1677 err = register_netdevice(tun->dev);
1670 if (err < 0) 1678 if (err < 0)
1671 goto err_detach; 1679 goto err_detach;
1672
1673 if (device_create_file(&tun->dev->dev, &dev_attr_tun_flags) ||
1674 device_create_file(&tun->dev->dev, &dev_attr_owner) ||
1675 device_create_file(&tun->dev->dev, &dev_attr_group))
1676 pr_err("Failed to create tun sysfs files\n");
1677 } 1680 }
1678 1681
1679 netif_carrier_on(tun->dev); 1682 netif_carrier_on(tun->dev);