From: Rusty Russell <rusty@rustcorp.com.au>
To: Max Krasnyansky <maxk@qualcomm.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>,
netdev@vger.kernel.org,
virtualization@lists.linux-foundation.org
Subject: [PATCH 1/4] tun: Interface to query tun/tap features.
Date: Thu, 26 Jun 2008 00:28:07 +1000 [thread overview]
Message-ID: <200806260028.07883.rusty@rustcorp.com.au> (raw)
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>
---
drivers/net/tun.c | 8 ++++++++
include/linux/if_tun.h | 1 +
2 files changed, 9 insertions(+)
diff -r 8414a579e106 drivers/net/tun.c
--- a/drivers/net/tun.c Tue Apr 22 07:36:45 2008 +1000
+++ b/drivers/net/tun.c Tue Apr 22 07:37:33 2008 +1000
@@ -625,6 +625,14 @@ static int tun_chr_ioctl(struct inode *i
return 0;
}
+ if (cmd == TUNGETFEATURES) {
+ /* Currently this just means: "what IFF flags are valid?".
+ * This is needed because we never checked for invalid flags on
+ * TUNSETIFF. */
+ return put_user(IFF_TUN | IFF_TAP | IFF_NO_PI | IFF_ONE_QUEUE,
+ (unsigned int __user*)argp);
+ }
+
if (!tun)
return -EBADFD;
diff -r 8414a579e106 include/linux/if_tun.h
--- a/include/linux/if_tun.h Tue Apr 22 07:36:45 2008 +1000
+++ b/include/linux/if_tun.h Tue Apr 22 07:37:33 2008 +1000
@@ -42,6 +42,7 @@
#define TUNSETOWNER _IOW('T', 204, int)
#define TUNSETLINK _IOW('T', 205, int)
#define TUNSETGROUP _IOW('T', 206, int)
+#define TUNGETFEATURES _IOR('T', 207, unsigned int)
/* TUNSETIFF ifr flags */
#define IFF_TUN 0x0001
next reply other threads:[~2008-06-25 14:29 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-25 14:28 Rusty Russell [this message]
2008-06-25 14:29 ` [PATCH 2/4] tun: TUNSETFEATURES to set gso features Rusty Russell
2008-06-25 14:30 ` [PATCH 3/4] tun: Allow GSO using virtio_net_hdr Rusty Russell
2008-06-25 14:32 ` [PATCH 4/4] lguest: Use GSO/IFF_VNET_HDR extensions on tun/tap Rusty Russell
2008-06-25 15:45 ` Rusty Russell
[not found] ` <200806260032.12359.rusty__46755.7742762894$1214404667$gmane$org@rustcorp.com.au>
2008-06-25 19:07 ` Anthony Liguori
2008-06-26 4:40 ` Rusty Russell
2008-06-26 18:16 ` Anthony Liguori
2008-06-27 3:50 ` Rusty Russell
2008-07-02 5:25 ` Max Krasnyansky
2008-07-02 5:13 ` [PATCH 3/4] tun: Allow GSO using virtio_net_hdr Max Krasnyansky
2008-07-02 7:00 ` Rusty Russell
2008-07-24 14:20 ` Herbert Xu
2008-07-24 23:54 ` Rusty Russell
2008-07-02 5:02 ` [PATCH 2/4] tun: TUNSETFEATURES to set gso features Max Krasnyansky
2008-07-02 4:59 ` [PATCH 1/4] tun: Interface to query tun/tap features Max Krasnyansky
2008-07-02 5:27 ` David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200806260028.07883.rusty@rustcorp.com.au \
--to=rusty@rustcorp.com.au \
--cc=herbert@gondor.apana.org.au \
--cc=maxk@qualcomm.com \
--cc=netdev@vger.kernel.org \
--cc=virtualization@lists.linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).