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.c32
1 files changed, 19 insertions, 13 deletions
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 10f9e4021b5a..ad7d3d5f3ee5 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)
@@ -1247,7 +1246,7 @@ static ssize_t tun_put_user(struct tun_struct *tun,
1247 int vlan_hlen = 0; 1246 int vlan_hlen = 0;
1248 int vnet_hdr_sz = 0; 1247 int vnet_hdr_sz = 0;
1249 1248
1250 if (vlan_tx_tag_present(skb)) 1249 if (skb_vlan_tag_present(skb))
1251 vlan_hlen = VLAN_HLEN; 1250 vlan_hlen = VLAN_HLEN;
1252 1251
1253 if (tun->flags & IFF_VNET_HDR) 1252 if (tun->flags & IFF_VNET_HDR)
@@ -1326,7 +1325,7 @@ static ssize_t tun_put_user(struct tun_struct *tun,
1326 } veth; 1325 } veth;
1327 1326
1328 veth.h_vlan_proto = skb->vlan_proto; 1327 veth.h_vlan_proto = skb->vlan_proto;
1329 veth.h_vlan_TCI = htons(vlan_tx_tag_get(skb)); 1328 veth.h_vlan_TCI = htons(skb_vlan_tag_get(skb));
1330 1329
1331 vlan_offset = offsetof(struct vlan_ethhdr, h_vlan_proto); 1330 vlan_offset = offsetof(struct vlan_ethhdr, h_vlan_proto);
1332 1331
@@ -1368,7 +1367,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, 1367 skb = __skb_recv_datagram(tfile->socket.sk, noblock ? MSG_DONTWAIT : 0,
1369 &peeked, &off, &err); 1368 &peeked, &off, &err);
1370 if (!skb) 1369 if (!skb)
1371 return 0; 1370 return err;
1372 1371
1373 ret = tun_put_user(tun, tfile, skb, to); 1372 ret = tun_put_user(tun, tfile, skb, to);
1374 if (unlikely(ret < 0)) 1373 if (unlikely(ret < 0))
@@ -1489,7 +1488,7 @@ static int tun_recvmsg(struct kiocb *iocb, struct socket *sock,
1489 goto out; 1488 goto out;
1490 } 1489 }
1491 ret = tun_do_read(tun, tfile, &m->msg_iter, flags & MSG_DONTWAIT); 1490 ret = tun_do_read(tun, tfile, &m->msg_iter, flags & MSG_DONTWAIT);
1492 if (ret > total_len) { 1491 if (ret > (ssize_t)total_len) {
1493 m->msg_flags |= MSG_TRUNC; 1492 m->msg_flags |= MSG_TRUNC;
1494 ret = flags & MSG_TRUNC ? ret : total_len; 1493 ret = flags & MSG_TRUNC ? ret : total_len;
1495 } 1494 }
@@ -1554,6 +1553,17 @@ static DEVICE_ATTR(tun_flags, 0444, tun_show_flags, NULL);
1554static DEVICE_ATTR(owner, 0444, tun_show_owner, NULL); 1553static DEVICE_ATTR(owner, 0444, tun_show_owner, NULL);
1555static DEVICE_ATTR(group, 0444, tun_show_group, NULL); 1554static DEVICE_ATTR(group, 0444, tun_show_group, NULL);
1556 1555
1556static struct attribute *tun_dev_attrs[] = {
1557 &dev_attr_tun_flags.attr,
1558 &dev_attr_owner.attr,
1559 &dev_attr_group.attr,
1560 NULL
1561};
1562
1563static const struct attribute_group tun_attr_group = {
1564 .attrs = tun_dev_attrs
1565};
1566
1557static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr) 1567static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
1558{ 1568{
1559 struct tun_struct *tun; 1569 struct tun_struct *tun;
@@ -1634,6 +1644,7 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
1634 dev_net_set(dev, net); 1644 dev_net_set(dev, net);
1635 dev->rtnl_link_ops = &tun_link_ops; 1645 dev->rtnl_link_ops = &tun_link_ops;
1636 dev->ifindex = tfile->ifindex; 1646 dev->ifindex = tfile->ifindex;
1647 dev->sysfs_groups[0] = &tun_attr_group;
1637 1648
1638 tun = netdev_priv(dev); 1649 tun = netdev_priv(dev);
1639 tun->dev = dev; 1650 tun->dev = dev;
@@ -1669,11 +1680,6 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
1669 err = register_netdevice(tun->dev); 1680 err = register_netdevice(tun->dev);
1670 if (err < 0) 1681 if (err < 0)
1671 goto err_detach; 1682 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 } 1683 }
1678 1684
1679 netif_carrier_on(tun->dev); 1685 netif_carrier_on(tun->dev);