diff options
author | Michael S. Tsirkin <mst@redhat.com> | 2014-11-19 07:44:40 -0500 |
---|---|---|
committer | Michael S. Tsirkin <mst@redhat.com> | 2014-12-09 05:05:30 -0500 |
commit | 031f5e0338ef672e728c878129fa044e8830c31a (patch) | |
tree | 80e1444cb8cf3ac62894b03b0c319e1fa6492819 | |
parent | 41e3e42108bc5ebc77d40d6fe1216c483a6b1f9d (diff) |
tun: move internal flag defines out of uapi
TUN_ flags are internal and never exposed
to userspace. Any application using it is almost
certainly buggy.
Move them out to tun.c.
Note: we remove these completely in follow-up patches,
this code movement is split out for ease of review.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
-rw-r--r-- | drivers/net/tun.c | 72 | ||||
-rw-r--r-- | include/uapi/linux/if_tun.h | 16 |
2 files changed, 24 insertions, 64 deletions
diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 9dd3746994a4..b4e4ca01facc 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c | |||
@@ -103,6 +103,21 @@ 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 | #define TUN_NO_PI IFF_NO_PI | ||
113 | /* This flag has no real effect */ | ||
114 | #define TUN_ONE_QUEUE IFF_ONE_QUEUE | ||
115 | #define TUN_PERSIST IFF_PERSIST | ||
116 | #define TUN_VNET_HDR IFF_VNET_HDR | ||
117 | #define TUN_TAP_MQ IFF_MULTI_QUEUE | ||
118 | |||
119 | #define TUN_FEATURES (IFF_NO_PI | IFF_ONE_QUEUE | IFF_VNET_HDR | \ | ||
120 | IFF_MULTI_QUEUE) | ||
106 | #define GOODCOPY_LEN 128 | 121 | #define GOODCOPY_LEN 128 |
107 | 122 | ||
108 | #define FLT_EXACT_COUNT 8 | 123 | #define FLT_EXACT_COUNT 8 |
@@ -1521,32 +1536,7 @@ static struct proto tun_proto = { | |||
1521 | 1536 | ||
1522 | static int tun_flags(struct tun_struct *tun) | 1537 | static int tun_flags(struct tun_struct *tun) |
1523 | { | 1538 | { |
1524 | int flags = 0; | 1539 | 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 | } | 1540 | } |
1551 | 1541 | ||
1552 | static ssize_t tun_show_flags(struct device *dev, struct device_attribute *attr, | 1542 | static ssize_t tun_show_flags(struct device *dev, struct device_attribute *attr, |
@@ -1706,28 +1696,8 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr) | |||
1706 | 1696 | ||
1707 | tun_debug(KERN_INFO, tun, "tun_set_iff\n"); | 1697 | tun_debug(KERN_INFO, tun, "tun_set_iff\n"); |
1708 | 1698 | ||
1709 | if (ifr->ifr_flags & IFF_NO_PI) | 1699 | tun->flags = (tun->flags & ~TUN_FEATURES) | |
1710 | tun->flags |= TUN_NO_PI; | 1700 | (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 | 1701 | ||
1732 | /* Make sure persistent devices do not get stuck in | 1702 | /* Make sure persistent devices do not get stuck in |
1733 | * xoff state. | 1703 | * xoff state. |
@@ -1890,9 +1860,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd, | |||
1890 | if (cmd == TUNGETFEATURES) { | 1860 | if (cmd == TUNGETFEATURES) { |
1891 | /* Currently this just means: "what IFF flags are valid?". | 1861 | /* Currently this just means: "what IFF flags are valid?". |
1892 | * This is needed because we never checked for invalid flags on | 1862 | * This is needed because we never checked for invalid flags on |
1893 | * TUNSETIFF. */ | 1863 | * TUNSETIFF. |
1894 | return put_user(IFF_TUN | IFF_TAP | IFF_NO_PI | IFF_ONE_QUEUE | | 1864 | */ |
1895 | IFF_VNET_HDR | IFF_MULTI_QUEUE, | 1865 | return put_user(IFF_TUN | IFF_TAP | TUN_FEATURES, |
1896 | (unsigned int __user*)argp); | 1866 | (unsigned int __user*)argp); |
1897 | } else if (cmd == TUNSETQUEUE) | 1867 | } else if (cmd == TUNSETQUEUE) |
1898 | return tun_set_queue(file, &ifr); | 1868 | return tun_set_queue(file, &ifr); |
diff --git a/include/uapi/linux/if_tun.h b/include/uapi/linux/if_tun.h index e9502dd1ee2c..277a2607d166 100644 --- a/include/uapi/linux/if_tun.h +++ b/include/uapi/linux/if_tun.h | |||
@@ -22,21 +22,11 @@ | |||
22 | 22 | ||
23 | /* Read queue size */ | 23 | /* Read queue size */ |
24 | #define TUN_READQ_SIZE 500 | 24 | #define TUN_READQ_SIZE 500 |
25 | 25 | /* TUN device type flags: deprecated. Use IFF_TUN/IFF_TAP instead. */ | |
26 | /* TUN device flags */ | 26 | #define TUN_TUN_DEV IFF_TUN |
27 | #define TUN_TUN_DEV 0x0001 | 27 | #define TUN_TAP_DEV IFF_TAP |
28 | #define TUN_TAP_DEV 0x0002 | ||
29 | #define TUN_TYPE_MASK 0x000f | 28 | #define TUN_TYPE_MASK 0x000f |
30 | 29 | ||
31 | #define TUN_FASYNC 0x0010 | ||
32 | #define TUN_NOCHECKSUM 0x0020 | ||
33 | #define TUN_NO_PI 0x0040 | ||
34 | /* This flag has no real effect */ | ||
35 | #define TUN_ONE_QUEUE 0x0080 | ||
36 | #define TUN_PERSIST 0x0100 | ||
37 | #define TUN_VNET_HDR 0x0200 | ||
38 | #define TUN_TAP_MQ 0x0400 | ||
39 | |||
40 | /* Ioctl defines */ | 30 | /* Ioctl defines */ |
41 | #define TUNSETNOCSUM _IOW('T', 200, int) | 31 | #define TUNSETNOCSUM _IOW('T', 200, int) |
42 | #define TUNSETDEBUG _IOW('T', 201, int) | 32 | #define TUNSETDEBUG _IOW('T', 201, int) |