aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/tun.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2014-12-11 15:20:31 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2014-12-11 15:20:31 -0500
commit6b9e2cea428cf7af93a84bcb865e478d8bf1c165 (patch)
tree11be387e37129fce0c4c111803df1a2e56637b60 /drivers/net/tun.c
parent14ba9a2e4bacc6f5a0dbe0de5390daedd544508f (diff)
parentf01a2a811ae04124fc9382925038fcbbd2f0b7c8 (diff)
Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
Pull virtio updates from Michael Tsirkin: "virtio: virtio 1.0 support, misc patches This adds a lot of infrastructure for virtio 1.0 support. Notable missing pieces: virtio pci, virtio balloon (needs spec extension), vhost scsi. Plus, there are some minor fixes in a couple of places. Note: some net drivers are affected by these patches. David said he's fine with merging these patches through my tree. Rusty's on vacation, he acked using my tree for these, too" * tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost: (70 commits) virtio_ccw: finalize_features error handling virtio_ccw: future-proof finalize_features virtio_pci: rename virtio_pci -> virtio_pci_common virtio_pci: update file descriptions and copyright virtio_pci: split out legacy device support virtio_pci: setup config vector indirectly virtio_pci: setup vqs indirectly virtio_pci: delete vqs indirectly virtio_pci: use priv for vq notification virtio_pci: free up vq->priv virtio_pci: fix coding style for structs virtio_pci: add isr field virtio: drop legacy_only driver flag virtio_balloon: drop legacy_only driver flag virtio_ccw: rev 1 devices set VIRTIO_F_VERSION_1 virtio: allow finalize_features to fail virtio_ccw: legacy: don't negotiate rev 1/features virtio: add API to detect legacy devices virtio_console: fix sparse warnings vhost: remove unnecessary forward declarations in vhost.h ...
Diffstat (limited to 'drivers/net/tun.c')
-rw-r--r--drivers/net/tun.c168
1 files changed, 71 insertions, 97 deletions
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 4d332dc93b70..798ce70e3d61 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -103,6 +103,15 @@ do { \
103} while (0) 103} while (0)
104#endif 104#endif
105 105
106/* TUN device flags */
107
108/* IFF_ATTACH_QUEUE is never stored in device flags,
109 * overload it to mean fasync when stored there.
110 */
111#define TUN_FASYNC IFF_ATTACH_QUEUE
112
113#define TUN_FEATURES (IFF_NO_PI | IFF_ONE_QUEUE | IFF_VNET_HDR | \
114 IFF_VNET_LE | IFF_MULTI_QUEUE)
106#define GOODCOPY_LEN 128 115#define GOODCOPY_LEN 128
107 116
108#define FLT_EXACT_COUNT 8 117#define FLT_EXACT_COUNT 8
@@ -196,6 +205,16 @@ struct tun_struct {
196 u32 flow_count; 205 u32 flow_count;
197}; 206};
198 207
208static inline u16 tun16_to_cpu(struct tun_struct *tun, __virtio16 val)
209{
210 return __virtio16_to_cpu(tun->flags & IFF_VNET_LE, val);
211}
212
213static inline __virtio16 cpu_to_tun16(struct tun_struct *tun, u16 val)
214{
215 return __cpu_to_virtio16(tun->flags & IFF_VNET_LE, val);
216}
217
199static inline u32 tun_hashfn(u32 rxhash) 218static inline u32 tun_hashfn(u32 rxhash)
200{ 219{
201 return rxhash & 0x3ff; 220 return rxhash & 0x3ff;
@@ -472,7 +491,7 @@ static void __tun_detach(struct tun_file *tfile, bool clean)
472 if (tun && tun->numqueues == 0 && tun->numdisabled == 0) { 491 if (tun && tun->numqueues == 0 && tun->numdisabled == 0) {
473 netif_carrier_off(tun->dev); 492 netif_carrier_off(tun->dev);
474 493
475 if (!(tun->flags & TUN_PERSIST) && 494 if (!(tun->flags & IFF_PERSIST) &&
476 tun->dev->reg_state == NETREG_REGISTERED) 495 tun->dev->reg_state == NETREG_REGISTERED)
477 unregister_netdevice(tun->dev); 496 unregister_netdevice(tun->dev);
478 } 497 }
@@ -523,7 +542,7 @@ static void tun_detach_all(struct net_device *dev)
523 } 542 }
524 BUG_ON(tun->numdisabled != 0); 543 BUG_ON(tun->numdisabled != 0);
525 544
526 if (tun->flags & TUN_PERSIST) 545 if (tun->flags & IFF_PERSIST)
527 module_put(THIS_MODULE); 546 module_put(THIS_MODULE);
528} 547}
529 548
@@ -541,7 +560,7 @@ static int tun_attach(struct tun_struct *tun, struct file *file, bool skip_filte
541 goto out; 560 goto out;
542 561
543 err = -EBUSY; 562 err = -EBUSY;
544 if (!(tun->flags & TUN_TAP_MQ) && tun->numqueues == 1) 563 if (!(tun->flags & IFF_MULTI_QUEUE) && tun->numqueues == 1)
545 goto out; 564 goto out;
546 565
547 err = -E2BIG; 566 err = -E2BIG;
@@ -920,7 +939,7 @@ static void tun_net_init(struct net_device *dev)
920 struct tun_struct *tun = netdev_priv(dev); 939 struct tun_struct *tun = netdev_priv(dev);
921 940
922 switch (tun->flags & TUN_TYPE_MASK) { 941 switch (tun->flags & TUN_TYPE_MASK) {
923 case TUN_TUN_DEV: 942 case IFF_TUN:
924 dev->netdev_ops = &tun_netdev_ops; 943 dev->netdev_ops = &tun_netdev_ops;
925 944
926 /* Point-to-Point TUN Device */ 945 /* Point-to-Point TUN Device */
@@ -934,7 +953,7 @@ static void tun_net_init(struct net_device *dev)
934 dev->tx_queue_len = TUN_READQ_SIZE; /* We prefer our own queue length */ 953 dev->tx_queue_len = TUN_READQ_SIZE; /* We prefer our own queue length */
935 break; 954 break;
936 955
937 case TUN_TAP_DEV: 956 case IFF_TAP:
938 dev->netdev_ops = &tap_netdev_ops; 957 dev->netdev_ops = &tap_netdev_ops;
939 /* Ethernet TAP Device */ 958 /* Ethernet TAP Device */
940 ether_setup(dev); 959 ether_setup(dev);
@@ -1025,7 +1044,7 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
1025 int err; 1044 int err;
1026 u32 rxhash; 1045 u32 rxhash;
1027 1046
1028 if (!(tun->flags & TUN_NO_PI)) { 1047 if (!(tun->flags & IFF_NO_PI)) {
1029 if (len < sizeof(pi)) 1048 if (len < sizeof(pi))
1030 return -EINVAL; 1049 return -EINVAL;
1031 len -= sizeof(pi); 1050 len -= sizeof(pi);
@@ -1035,7 +1054,7 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
1035 offset += sizeof(pi); 1054 offset += sizeof(pi);
1036 } 1055 }
1037 1056
1038 if (tun->flags & TUN_VNET_HDR) { 1057 if (tun->flags & IFF_VNET_HDR) {
1039 if (len < tun->vnet_hdr_sz) 1058 if (len < tun->vnet_hdr_sz)
1040 return -EINVAL; 1059 return -EINVAL;
1041 len -= tun->vnet_hdr_sz; 1060 len -= tun->vnet_hdr_sz;
@@ -1044,18 +1063,18 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
1044 return -EFAULT; 1063 return -EFAULT;
1045 1064
1046 if ((gso.flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) && 1065 if ((gso.flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) &&
1047 gso.csum_start + gso.csum_offset + 2 > gso.hdr_len) 1066 tun16_to_cpu(tun, gso.csum_start) + tun16_to_cpu(tun, gso.csum_offset) + 2 > tun16_to_cpu(tun, gso.hdr_len))
1048 gso.hdr_len = gso.csum_start + gso.csum_offset + 2; 1067 gso.hdr_len = cpu_to_tun16(tun, tun16_to_cpu(tun, gso.csum_start) + tun16_to_cpu(tun, gso.csum_offset) + 2);
1049 1068
1050 if (gso.hdr_len > len) 1069 if (tun16_to_cpu(tun, gso.hdr_len) > len)
1051 return -EINVAL; 1070 return -EINVAL;
1052 offset += tun->vnet_hdr_sz; 1071 offset += tun->vnet_hdr_sz;
1053 } 1072 }
1054 1073
1055 if ((tun->flags & TUN_TYPE_MASK) == TUN_TAP_DEV) { 1074 if ((tun->flags & TUN_TYPE_MASK) == IFF_TAP) {
1056 align += NET_IP_ALIGN; 1075 align += NET_IP_ALIGN;
1057 if (unlikely(len < ETH_HLEN || 1076 if (unlikely(len < ETH_HLEN ||
1058 (gso.hdr_len && gso.hdr_len < ETH_HLEN))) 1077 (gso.hdr_len && tun16_to_cpu(tun, gso.hdr_len) < ETH_HLEN)))
1059 return -EINVAL; 1078 return -EINVAL;
1060 } 1079 }
1061 1080
@@ -1066,7 +1085,7 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
1066 * enough room for skb expand head in case it is used. 1085 * enough room for skb expand head in case it is used.
1067 * The rest of the buffer is mapped from userspace. 1086 * The rest of the buffer is mapped from userspace.
1068 */ 1087 */
1069 copylen = gso.hdr_len ? gso.hdr_len : GOODCOPY_LEN; 1088 copylen = gso.hdr_len ? tun16_to_cpu(tun, gso.hdr_len) : GOODCOPY_LEN;
1070 if (copylen > good_linear) 1089 if (copylen > good_linear)
1071 copylen = good_linear; 1090 copylen = good_linear;
1072 linear = copylen; 1091 linear = copylen;
@@ -1076,10 +1095,10 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
1076 1095
1077 if (!zerocopy) { 1096 if (!zerocopy) {
1078 copylen = len; 1097 copylen = len;
1079 if (gso.hdr_len > good_linear) 1098 if (tun16_to_cpu(tun, gso.hdr_len) > good_linear)
1080 linear = good_linear; 1099 linear = good_linear;
1081 else 1100 else
1082 linear = gso.hdr_len; 1101 linear = tun16_to_cpu(tun, gso.hdr_len);
1083 } 1102 }
1084 1103
1085 skb = tun_alloc_skb(tfile, align, copylen, linear, noblock); 1104 skb = tun_alloc_skb(tfile, align, copylen, linear, noblock);
@@ -1106,8 +1125,8 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
1106 } 1125 }
1107 1126
1108 if (gso.flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) { 1127 if (gso.flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) {
1109 if (!skb_partial_csum_set(skb, gso.csum_start, 1128 if (!skb_partial_csum_set(skb, tun16_to_cpu(tun, gso.csum_start),
1110 gso.csum_offset)) { 1129 tun16_to_cpu(tun, gso.csum_offset))) {
1111 tun->dev->stats.rx_frame_errors++; 1130 tun->dev->stats.rx_frame_errors++;
1112 kfree_skb(skb); 1131 kfree_skb(skb);
1113 return -EINVAL; 1132 return -EINVAL;
@@ -1115,8 +1134,8 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
1115 } 1134 }
1116 1135
1117 switch (tun->flags & TUN_TYPE_MASK) { 1136 switch (tun->flags & TUN_TYPE_MASK) {
1118 case TUN_TUN_DEV: 1137 case IFF_TUN:
1119 if (tun->flags & TUN_NO_PI) { 1138 if (tun->flags & IFF_NO_PI) {
1120 switch (skb->data[0] & 0xf0) { 1139 switch (skb->data[0] & 0xf0) {
1121 case 0x40: 1140 case 0x40:
1122 pi.proto = htons(ETH_P_IP); 1141 pi.proto = htons(ETH_P_IP);
@@ -1135,7 +1154,7 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
1135 skb->protocol = pi.proto; 1154 skb->protocol = pi.proto;
1136 skb->dev = tun->dev; 1155 skb->dev = tun->dev;
1137 break; 1156 break;
1138 case TUN_TAP_DEV: 1157 case IFF_TAP:
1139 skb->protocol = eth_type_trans(skb, tun->dev); 1158 skb->protocol = eth_type_trans(skb, tun->dev);
1140 break; 1159 break;
1141 } 1160 }
@@ -1175,7 +1194,7 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
1175 if (gso.gso_type & VIRTIO_NET_HDR_GSO_ECN) 1194 if (gso.gso_type & VIRTIO_NET_HDR_GSO_ECN)
1176 skb_shinfo(skb)->gso_type |= SKB_GSO_TCP_ECN; 1195 skb_shinfo(skb)->gso_type |= SKB_GSO_TCP_ECN;
1177 1196
1178 skb_shinfo(skb)->gso_size = gso.gso_size; 1197 skb_shinfo(skb)->gso_size = tun16_to_cpu(tun, gso.gso_size);
1179 if (skb_shinfo(skb)->gso_size == 0) { 1198 if (skb_shinfo(skb)->gso_size == 0) {
1180 tun->dev->stats.rx_frame_errors++; 1199 tun->dev->stats.rx_frame_errors++;
1181 kfree_skb(skb); 1200 kfree_skb(skb);
@@ -1241,10 +1260,10 @@ static ssize_t tun_put_user(struct tun_struct *tun,
1241 if (vlan_tx_tag_present(skb)) 1260 if (vlan_tx_tag_present(skb))
1242 vlan_hlen = VLAN_HLEN; 1261 vlan_hlen = VLAN_HLEN;
1243 1262
1244 if (tun->flags & TUN_VNET_HDR) 1263 if (tun->flags & IFF_VNET_HDR)
1245 vnet_hdr_sz = tun->vnet_hdr_sz; 1264 vnet_hdr_sz = tun->vnet_hdr_sz;
1246 1265
1247 if (!(tun->flags & TUN_NO_PI)) { 1266 if (!(tun->flags & IFF_NO_PI)) {
1248 if ((len -= sizeof(pi)) < 0) 1267 if ((len -= sizeof(pi)) < 0)
1249 return -EINVAL; 1268 return -EINVAL;
1250 1269
@@ -1267,8 +1286,8 @@ static ssize_t tun_put_user(struct tun_struct *tun,
1267 struct skb_shared_info *sinfo = skb_shinfo(skb); 1286 struct skb_shared_info *sinfo = skb_shinfo(skb);
1268 1287
1269 /* This is a hint as to how much should be linear. */ 1288 /* This is a hint as to how much should be linear. */
1270 gso.hdr_len = skb_headlen(skb); 1289 gso.hdr_len = cpu_to_tun16(tun, skb_headlen(skb));
1271 gso.gso_size = sinfo->gso_size; 1290 gso.gso_size = cpu_to_tun16(tun, sinfo->gso_size);
1272 if (sinfo->gso_type & SKB_GSO_TCPV4) 1291 if (sinfo->gso_type & SKB_GSO_TCPV4)
1273 gso.gso_type = VIRTIO_NET_HDR_GSO_TCPV4; 1292 gso.gso_type = VIRTIO_NET_HDR_GSO_TCPV4;
1274 else if (sinfo->gso_type & SKB_GSO_TCPV6) 1293 else if (sinfo->gso_type & SKB_GSO_TCPV6)
@@ -1276,12 +1295,12 @@ static ssize_t tun_put_user(struct tun_struct *tun,
1276 else { 1295 else {
1277 pr_err("unexpected GSO type: " 1296 pr_err("unexpected GSO type: "
1278 "0x%x, gso_size %d, hdr_len %d\n", 1297 "0x%x, gso_size %d, hdr_len %d\n",
1279 sinfo->gso_type, gso.gso_size, 1298 sinfo->gso_type, tun16_to_cpu(tun, gso.gso_size),
1280 gso.hdr_len); 1299 tun16_to_cpu(tun, gso.hdr_len));
1281 print_hex_dump(KERN_ERR, "tun: ", 1300 print_hex_dump(KERN_ERR, "tun: ",
1282 DUMP_PREFIX_NONE, 1301 DUMP_PREFIX_NONE,
1283 16, 1, skb->head, 1302 16, 1, skb->head,
1284 min((int)gso.hdr_len, 64), true); 1303 min((int)tun16_to_cpu(tun, gso.hdr_len), 64), true);
1285 WARN_ON_ONCE(1); 1304 WARN_ON_ONCE(1);
1286 return -EINVAL; 1305 return -EINVAL;
1287 } 1306 }
@@ -1292,9 +1311,9 @@ static ssize_t tun_put_user(struct tun_struct *tun,
1292 1311
1293 if (skb->ip_summed == CHECKSUM_PARTIAL) { 1312 if (skb->ip_summed == CHECKSUM_PARTIAL) {
1294 gso.flags = VIRTIO_NET_HDR_F_NEEDS_CSUM; 1313 gso.flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
1295 gso.csum_start = skb_checksum_start_offset(skb) + 1314 gso.csum_start = cpu_to_tun16(tun, skb_checksum_start_offset(skb) +
1296 vlan_hlen; 1315 vlan_hlen);
1297 gso.csum_offset = skb->csum_offset; 1316 gso.csum_offset = cpu_to_tun16(tun, skb->csum_offset);
1298 } else if (skb->ip_summed == CHECKSUM_UNNECESSARY) { 1317 } else if (skb->ip_summed == CHECKSUM_UNNECESSARY) {
1299 gso.flags = VIRTIO_NET_HDR_F_DATA_VALID; 1318 gso.flags = VIRTIO_NET_HDR_F_DATA_VALID;
1300 } /* else everything is zero */ 1319 } /* else everything is zero */
@@ -1521,32 +1540,7 @@ static struct proto tun_proto = {
1521 1540
1522static int tun_flags(struct tun_struct *tun) 1541static int tun_flags(struct tun_struct *tun)
1523{ 1542{
1524 int flags = 0; 1543 return tun->flags & (TUN_FEATURES | IFF_PERSIST | IFF_TUN | IFF_TAP);
1525
1526 if (tun->flags & TUN_TUN_DEV)
1527 flags |= IFF_TUN;
1528 else
1529 flags |= IFF_TAP;
1530
1531 if (tun->flags & TUN_NO_PI)
1532 flags |= IFF_NO_PI;
1533
1534 /* This flag has no real effect. We track the value for backwards
1535 * compatibility.
1536 */
1537 if (tun->flags & TUN_ONE_QUEUE)
1538 flags |= IFF_ONE_QUEUE;
1539
1540 if (tun->flags & TUN_VNET_HDR)
1541 flags |= IFF_VNET_HDR;
1542
1543 if (tun->flags & TUN_TAP_MQ)
1544 flags |= IFF_MULTI_QUEUE;
1545
1546 if (tun->flags & TUN_PERSIST)
1547 flags |= IFF_PERSIST;
1548
1549 return flags;
1550} 1544}
1551 1545
1552static ssize_t tun_show_flags(struct device *dev, struct device_attribute *attr, 1546static ssize_t tun_show_flags(struct device *dev, struct device_attribute *attr,
@@ -1602,7 +1596,7 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
1602 return -EINVAL; 1596 return -EINVAL;
1603 1597
1604 if (!!(ifr->ifr_flags & IFF_MULTI_QUEUE) != 1598 if (!!(ifr->ifr_flags & IFF_MULTI_QUEUE) !=
1605 !!(tun->flags & TUN_TAP_MQ)) 1599 !!(tun->flags & IFF_MULTI_QUEUE))
1606 return -EINVAL; 1600 return -EINVAL;
1607 1601
1608 if (tun_not_capable(tun)) 1602 if (tun_not_capable(tun))
@@ -1615,7 +1609,7 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
1615 if (err < 0) 1609 if (err < 0)
1616 return err; 1610 return err;
1617 1611
1618 if (tun->flags & TUN_TAP_MQ && 1612 if (tun->flags & IFF_MULTI_QUEUE &&
1619 (tun->numqueues + tun->numdisabled > 1)) { 1613 (tun->numqueues + tun->numdisabled > 1)) {
1620 /* One or more queue has already been attached, no need 1614 /* One or more queue has already been attached, no need
1621 * to initialize the device again. 1615 * to initialize the device again.
@@ -1638,11 +1632,11 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
1638 /* Set dev type */ 1632 /* Set dev type */
1639 if (ifr->ifr_flags & IFF_TUN) { 1633 if (ifr->ifr_flags & IFF_TUN) {
1640 /* TUN device */ 1634 /* TUN device */
1641 flags |= TUN_TUN_DEV; 1635 flags |= IFF_TUN;
1642 name = "tun%d"; 1636 name = "tun%d";
1643 } else if (ifr->ifr_flags & IFF_TAP) { 1637 } else if (ifr->ifr_flags & IFF_TAP) {
1644 /* TAP device */ 1638 /* TAP device */
1645 flags |= TUN_TAP_DEV; 1639 flags |= IFF_TAP;
1646 name = "tap%d"; 1640 name = "tap%d";
1647 } else 1641 } else
1648 return -EINVAL; 1642 return -EINVAL;
@@ -1706,28 +1700,8 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
1706 1700
1707 tun_debug(KERN_INFO, tun, "tun_set_iff\n"); 1701 tun_debug(KERN_INFO, tun, "tun_set_iff\n");
1708 1702
1709 if (ifr->ifr_flags & IFF_NO_PI) 1703 tun->flags = (tun->flags & ~TUN_FEATURES) |
1710 tun->flags |= TUN_NO_PI; 1704 (ifr->ifr_flags & TUN_FEATURES);
1711 else
1712 tun->flags &= ~TUN_NO_PI;
1713
1714 /* This flag has no real effect. We track the value for backwards
1715 * compatibility.
1716 */
1717 if (ifr->ifr_flags & IFF_ONE_QUEUE)
1718 tun->flags |= TUN_ONE_QUEUE;
1719 else
1720 tun->flags &= ~TUN_ONE_QUEUE;
1721
1722 if (ifr->ifr_flags & IFF_VNET_HDR)
1723 tun->flags |= TUN_VNET_HDR;
1724 else
1725 tun->flags &= ~TUN_VNET_HDR;
1726
1727 if (ifr->ifr_flags & IFF_MULTI_QUEUE)
1728 tun->flags |= TUN_TAP_MQ;
1729 else
1730 tun->flags &= ~TUN_TAP_MQ;
1731 1705
1732 /* Make sure persistent devices do not get stuck in 1706 /* Make sure persistent devices do not get stuck in
1733 * xoff state. 1707 * xoff state.
@@ -1855,7 +1829,7 @@ static int tun_set_queue(struct file *file, struct ifreq *ifr)
1855 ret = tun_attach(tun, file, false); 1829 ret = tun_attach(tun, file, false);
1856 } else if (ifr->ifr_flags & IFF_DETACH_QUEUE) { 1830 } else if (ifr->ifr_flags & IFF_DETACH_QUEUE) {
1857 tun = rtnl_dereference(tfile->tun); 1831 tun = rtnl_dereference(tfile->tun);
1858 if (!tun || !(tun->flags & TUN_TAP_MQ) || tfile->detached) 1832 if (!tun || !(tun->flags & IFF_MULTI_QUEUE) || tfile->detached)
1859 ret = -EINVAL; 1833 ret = -EINVAL;
1860 else 1834 else
1861 __tun_detach(tfile, false); 1835 __tun_detach(tfile, false);
@@ -1890,9 +1864,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
1890 if (cmd == TUNGETFEATURES) { 1864 if (cmd == TUNGETFEATURES) {
1891 /* Currently this just means: "what IFF flags are valid?". 1865 /* Currently this just means: "what IFF flags are valid?".
1892 * This is needed because we never checked for invalid flags on 1866 * This is needed because we never checked for invalid flags on
1893 * TUNSETIFF. */ 1867 * TUNSETIFF.
1894 return put_user(IFF_TUN | IFF_TAP | IFF_NO_PI | IFF_ONE_QUEUE | 1868 */
1895 IFF_VNET_HDR | IFF_MULTI_QUEUE, 1869 return put_user(IFF_TUN | IFF_TAP | TUN_FEATURES,
1896 (unsigned int __user*)argp); 1870 (unsigned int __user*)argp);
1897 } else if (cmd == TUNSETQUEUE) 1871 } else if (cmd == TUNSETQUEUE)
1898 return tun_set_queue(file, &ifr); 1872 return tun_set_queue(file, &ifr);
@@ -1959,12 +1933,12 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
1959 /* Disable/Enable persist mode. Keep an extra reference to the 1933 /* Disable/Enable persist mode. Keep an extra reference to the
1960 * module to prevent the module being unprobed. 1934 * module to prevent the module being unprobed.
1961 */ 1935 */
1962 if (arg && !(tun->flags & TUN_PERSIST)) { 1936 if (arg && !(tun->flags & IFF_PERSIST)) {
1963 tun->flags |= TUN_PERSIST; 1937 tun->flags |= IFF_PERSIST;
1964 __module_get(THIS_MODULE); 1938 __module_get(THIS_MODULE);
1965 } 1939 }
1966 if (!arg && (tun->flags & TUN_PERSIST)) { 1940 if (!arg && (tun->flags & IFF_PERSIST)) {
1967 tun->flags &= ~TUN_PERSIST; 1941 tun->flags &= ~IFF_PERSIST;
1968 module_put(THIS_MODULE); 1942 module_put(THIS_MODULE);
1969 } 1943 }
1970 1944
@@ -2022,7 +1996,7 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
2022 case TUNSETTXFILTER: 1996 case TUNSETTXFILTER:
2023 /* Can be set only for TAPs */ 1997 /* Can be set only for TAPs */
2024 ret = -EINVAL; 1998 ret = -EINVAL;
2025 if ((tun->flags & TUN_TYPE_MASK) != TUN_TAP_DEV) 1999 if ((tun->flags & TUN_TYPE_MASK) != IFF_TAP)
2026 break; 2000 break;
2027 ret = update_filter(&tun->txflt, (void __user *)arg); 2001 ret = update_filter(&tun->txflt, (void __user *)arg);
2028 break; 2002 break;
@@ -2081,7 +2055,7 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
2081 case TUNATTACHFILTER: 2055 case TUNATTACHFILTER:
2082 /* Can be set only for TAPs */ 2056 /* Can be set only for TAPs */
2083 ret = -EINVAL; 2057 ret = -EINVAL;
2084 if ((tun->flags & TUN_TYPE_MASK) != TUN_TAP_DEV) 2058 if ((tun->flags & TUN_TYPE_MASK) != IFF_TAP)
2085 break; 2059 break;
2086 ret = -EFAULT; 2060 ret = -EFAULT;
2087 if (copy_from_user(&tun->fprog, argp, sizeof(tun->fprog))) 2061 if (copy_from_user(&tun->fprog, argp, sizeof(tun->fprog)))
@@ -2093,7 +2067,7 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
2093 case TUNDETACHFILTER: 2067 case TUNDETACHFILTER:
2094 /* Can be set only for TAPs */ 2068 /* Can be set only for TAPs */
2095 ret = -EINVAL; 2069 ret = -EINVAL;
2096 if ((tun->flags & TUN_TYPE_MASK) != TUN_TAP_DEV) 2070 if ((tun->flags & TUN_TYPE_MASK) != IFF_TAP)
2097 break; 2071 break;
2098 ret = 0; 2072 ret = 0;
2099 tun_detach_filter(tun, tun->numqueues); 2073 tun_detach_filter(tun, tun->numqueues);
@@ -2101,7 +2075,7 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
2101 2075
2102 case TUNGETFILTER: 2076 case TUNGETFILTER:
2103 ret = -EINVAL; 2077 ret = -EINVAL;
2104 if ((tun->flags & TUN_TYPE_MASK) != TUN_TAP_DEV) 2078 if ((tun->flags & TUN_TYPE_MASK) != IFF_TAP)
2105 break; 2079 break;
2106 ret = -EFAULT; 2080 ret = -EFAULT;
2107 if (copy_to_user(argp, &tun->fprog, sizeof(tun->fprog))) 2081 if (copy_to_user(argp, &tun->fprog, sizeof(tun->fprog)))
@@ -2294,10 +2268,10 @@ static void tun_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info
2294 strlcpy(info->version, DRV_VERSION, sizeof(info->version)); 2268 strlcpy(info->version, DRV_VERSION, sizeof(info->version));
2295 2269
2296 switch (tun->flags & TUN_TYPE_MASK) { 2270 switch (tun->flags & TUN_TYPE_MASK) {
2297 case TUN_TUN_DEV: 2271 case IFF_TUN:
2298 strlcpy(info->bus_info, "tun", sizeof(info->bus_info)); 2272 strlcpy(info->bus_info, "tun", sizeof(info->bus_info));
2299 break; 2273 break;
2300 case TUN_TAP_DEV: 2274 case IFF_TAP:
2301 strlcpy(info->bus_info, "tap", sizeof(info->bus_info)); 2275 strlcpy(info->bus_info, "tap", sizeof(info->bus_info));
2302 break; 2276 break;
2303 } 2277 }