diff options
author | Rusty Russell <rusty@rustcorp.com.au> | 2008-07-03 06:45:32 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2008-07-03 06:45:32 -0400 |
commit | 07240fd0902c872f044f523893364a1a24c9f278 (patch) | |
tree | 096286005c0b1a19c23011b3c7418710704b833e | |
parent | 44d28ab19c64d095314ac66f765d0c747519f4ed (diff) |
tun: Interface to query tun/tap features.
The problem with introducing checksum offload and gso to tun is they
need to set dev->features to enable GSO and/or checksumming, which is
supposed to be done before register_netdevice(), ie. as part of
TUNSETIFF.
Unfortunately, TUNSETIFF has always just ignored flags it doesn't
understand, so there's no good way of detecting whether the kernel
supports new IFF_ flags.
This patch implements a TUNGETFEATURES ioctl which returns all the valid IFF
flags. It could be extended later to include other features.
Here's an example program which uses it:
#include <linux/if_tun.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <err.h>
#include <stdio.h>
static struct {
unsigned int flag;
const char *name;
} known_flags[] = {
{ IFF_TUN, "TUN" },
{ IFF_TAP, "TAP" },
{ IFF_NO_PI, "NO_PI" },
{ IFF_ONE_QUEUE, "ONE_QUEUE" },
};
int main()
{
unsigned int features, i;
int netfd = open("/dev/net/tun", O_RDWR);
if (netfd < 0)
err(1, "Opening /dev/net/tun");
if (ioctl(netfd, TUNGETFEATURES, &features) != 0) {
printf("Kernel does not support TUNGETFEATURES, guessing\n");
features = (IFF_TUN|IFF_TAP|IFF_NO_PI|IFF_ONE_QUEUE);
}
printf("Available features are: ");
for (i = 0; i < sizeof(known_flags)/sizeof(known_flags[0]); i++) {
if (features & known_flags[i].flag) {
features &= ~known_flags[i].flag;
printf("%s ", known_flags[i].name);
}
}
if (features)
printf("(UNKNOWN %#x)", features);
printf("\n");
return 0;
}
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Acked-by: Max Krasnyansky <maxk@qualcomm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | drivers/net/tun.c | 8 | ||||
-rw-r--r-- | include/linux/if_tun.h | 1 |
2 files changed, 9 insertions, 0 deletions
diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 7ab94c825b57..3bb991fd2b51 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c | |||
@@ -640,6 +640,14 @@ static int tun_chr_ioctl(struct inode *inode, struct file *file, | |||
640 | return 0; | 640 | return 0; |
641 | } | 641 | } |
642 | 642 | ||
643 | if (cmd == TUNGETFEATURES) { | ||
644 | /* Currently this just means: "what IFF flags are valid?". | ||
645 | * This is needed because we never checked for invalid flags on | ||
646 | * TUNSETIFF. */ | ||
647 | return put_user(IFF_TUN | IFF_TAP | IFF_NO_PI | IFF_ONE_QUEUE, | ||
648 | (unsigned int __user*)argp); | ||
649 | } | ||
650 | |||
643 | if (!tun) | 651 | if (!tun) |
644 | return -EBADFD; | 652 | return -EBADFD; |
645 | 653 | ||
diff --git a/include/linux/if_tun.h b/include/linux/if_tun.h index 18f31b6187a3..94f76a112303 100644 --- a/include/linux/if_tun.h +++ b/include/linux/if_tun.h | |||
@@ -40,6 +40,7 @@ | |||
40 | #define TUNSETOWNER _IOW('T', 204, int) | 40 | #define TUNSETOWNER _IOW('T', 204, int) |
41 | #define TUNSETLINK _IOW('T', 205, int) | 41 | #define TUNSETLINK _IOW('T', 205, int) |
42 | #define TUNSETGROUP _IOW('T', 206, int) | 42 | #define TUNSETGROUP _IOW('T', 206, int) |
43 | #define TUNGETFEATURES _IOR('T', 207, unsigned int) | ||
43 | 44 | ||
44 | /* TUNSETIFF ifr flags */ | 45 | /* TUNSETIFF ifr flags */ |
45 | #define IFF_TUN 0x0001 | 46 | #define IFF_TUN 0x0001 |