netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] tun: TUNGETIFF interface to query name and flags
@ 2008-08-13 14:30 Mark McLoughlin
  2008-08-14  1:58 ` Rusty Russell
  0 siblings, 1 reply; 6+ messages in thread
From: Mark McLoughlin @ 2008-08-13 14:30 UTC (permalink / raw)
  To: Rusty Russell, Max Krasnyansky; +Cc: netdev, virtualization@lists.osdl.org

Rusty/Max,

While adding support to KVM for IFF_VNET_HDR it became apparent that we
need some way of querying a file descriptor for whether IFF_VNET_HDR has
been set.

Basically, some apps like libvirt open the tap fd, connect the interface
to the appropriate bridge and pass the fd to kvm via the command line. 

So, those apps need to set IFF_VNET_HDR and KVM needs to be able to
detect that and handle it correctly.

A very simple approach is attached; I did consider doing a TUNGETFLAGS
that would return tun->flags, but I think it's nicer to have a companion
to TUNGETIFF since it also allows one to query the interface name from
the file descriptor.

Cheers,
Mark.

Subject: [PATCH 1/1] tun: TUNGETIFF interface to query name and flags

Add a TUNGETIFF interface so that userspace can query a
tun/tap descriptor for its name and flags.

This is needed because it is common for one app to create
a tap interface, exec another app and pass it the file
descriptor for the interface. Without TUNGETIFF the spawned
app has no way of detecting wheter the interface has e.g.
IFF_VNET_HDR set.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 drivers/net/tun.c      |   39 +++++++++++++++++++++++++++++++++++++++
 include/linux/if_tun.h |    1 +
 2 files changed, 40 insertions(+), 0 deletions(-)

diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index e6bbc63..95931a5 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -748,6 +748,36 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
 	return err;
 }
 
+static int tun_get_iff(struct net *net, struct file *file, struct ifreq *ifr)
+{
+	struct tun_struct *tun = file->private_data;
+
+	if (!tun)
+		return -EBADFD;
+
+	DBG(KERN_INFO "%s: tun_get_iff\n", tun->dev->name);
+
+	strcpy(ifr->ifr_name, tun->dev->name);
+
+	ifr->ifr_flags = 0;
+
+	if (ifr->ifr_flags & TUN_TUN_DEV)
+		ifr->ifr_flags |= IFF_TUN;
+	else
+		ifr->ifr_flags |= IFF_TAP;
+
+	if (tun->flags & TUN_NO_PI)
+		ifr->ifr_flags |= IFF_NO_PI;
+
+	if (tun->flags & TUN_ONE_QUEUE)
+		ifr->ifr_flags |= IFF_ONE_QUEUE;
+
+	if (tun->flags & TUN_VNET_HDR)
+		ifr->ifr_flags |= IFF_VNET_HDR;
+
+	return 0;
+}
+
 /* This is like a cut-down ethtool ops, except done via tun fd so no
  * privs required. */
 static int set_offload(struct net_device *dev, unsigned long arg)
@@ -833,6 +863,15 @@ static int tun_chr_ioctl(struct inode *inode, struct file *file,
 	DBG(KERN_INFO "%s: tun_chr_ioctl cmd %d\n", tun->dev->name, cmd);
 
 	switch (cmd) {
+	case TUNGETIFF:
+		ret = tun_get_iff(current->nsproxy->net_ns, file, &ifr);
+		if (ret)
+			return ret;
+
+		if (copy_to_user(argp, &ifr, sizeof(ifr)))
+			return -EFAULT;
+		break;
+
 	case TUNSETNOCSUM:
 		/* Disable/Enable checksum */
 		if (arg)
diff --git a/include/linux/if_tun.h b/include/linux/if_tun.h
index 4c6307a..8529f57 100644
--- a/include/linux/if_tun.h
+++ b/include/linux/if_tun.h
@@ -45,6 +45,7 @@
 #define TUNGETFEATURES _IOR('T', 207, unsigned int)
 #define TUNSETOFFLOAD  _IOW('T', 208, unsigned int)
 #define TUNSETTXFILTER _IOW('T', 209, unsigned int)
+#define TUNGETIFF      _IOR('T', 210, unsigned int)
 
 /* TUNSETIFF ifr flags */
 #define IFF_TUN		0x0001
-- 
1.5.4.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] tun: TUNGETIFF interface to query name and flags
  2008-08-13 14:30 [PATCH 1/1] tun: TUNGETIFF interface to query name and flags Mark McLoughlin
@ 2008-08-14  1:58 ` Rusty Russell
  2008-08-15 14:02   ` Mark McLoughlin
  2008-08-15 18:00   ` Max Krasnyansky
  0 siblings, 2 replies; 6+ messages in thread
From: Rusty Russell @ 2008-08-14  1:58 UTC (permalink / raw)
  To: Mark McLoughlin; +Cc: Max Krasnyansky, netdev, virtualization@lists.osdl.org

On Thursday 14 August 2008 00:30:16 Mark McLoughlin wrote:
> A very simple approach is attached; I did consider doing a TUNGETFLAGS
> that would return tun->flags, but I think it's nicer to have a companion
> to TUNGETIFF since it also allows one to query the interface name from
> the file descriptor.

This seems really sensible to me.

If Max acks it, I'd say Dave should merge it.
Rusty.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] tun: TUNGETIFF interface to query name and flags
  2008-08-14  1:58 ` Rusty Russell
@ 2008-08-15 14:02   ` Mark McLoughlin
  2008-08-15 18:10     ` Max Krasnyansky
  2008-08-15 18:00   ` Max Krasnyansky
  1 sibling, 1 reply; 6+ messages in thread
From: Mark McLoughlin @ 2008-08-15 14:02 UTC (permalink / raw)
  To: maxk; +Cc: netdev, virtualization@lists.osdl.org, Rusty Russell

On Thu, 2008-08-14 at 11:58 +1000, Rusty Russell wrote:
> On Thursday 14 August 2008 00:30:16 Mark McLoughlin wrote:
> > A very simple approach is attached; I did consider doing a TUNGETFLAGS
> > that would return tun->flags, but I think it's nicer to have a companion
> > to TUNGETIFF since it also allows one to query the interface name from
> > the file descriptor.
> 
> This seems really sensible to me.
> 
> If Max acks it,

How about it Max?

Trying a different email address - previous mail at:

  http://marc.info/?l=linux-netdev&m=121863813904363

> I'd say Dave should merge it.

Maybe it's too late already, but I'm really hoping to get this in
2.6.27.

Without it, the IFF_VNET_HDR goodness already added in 2.6.27 can't be
used by KVM guests created by libvirt ... which is a good chunk of the
potential users for this stuff.

Cheers,
Mark.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] tun: TUNGETIFF interface to query name and flags
  2008-08-14  1:58 ` Rusty Russell
  2008-08-15 14:02   ` Mark McLoughlin
@ 2008-08-15 18:00   ` Max Krasnyansky
  2008-08-15 22:10     ` David Miller
  1 sibling, 1 reply; 6+ messages in thread
From: Max Krasnyansky @ 2008-08-15 18:00 UTC (permalink / raw)
  To: Rusty Russell; +Cc: Mark McLoughlin, netdev, virtualization@lists.osdl.org

Sorry for the delay guys. Was trying to get QEMU USB changes out and was not
paying attention to the other stuff :)

Rusty Russell wrote:
> On Thursday 14 August 2008 00:30:16 Mark McLoughlin wrote:
>> A very simple approach is attached; I did consider doing a TUNGETFLAGS
>> that would return tun->flags, but I think it's nicer to have a companion
>> to TUNGETIFF since it also allows one to query the interface name from
>> the file descriptor.
> 
> This seems really sensible to me.
> 
> If Max acks it, I'd say Dave should merge it.

Makes perfect sense to me.
Definitely Ack. It has zero impact on existing user and I'd be ok if this goes
 in during .27-rc series.

Max



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] tun: TUNGETIFF interface to query name and flags
  2008-08-15 14:02   ` Mark McLoughlin
@ 2008-08-15 18:10     ` Max Krasnyansky
  0 siblings, 0 replies; 6+ messages in thread
From: Max Krasnyansky @ 2008-08-15 18:10 UTC (permalink / raw)
  To: Mark McLoughlin; +Cc: netdev, virtualization@lists.osdl.org, Rusty Russell

Mark McLoughlin wrote:
> On Thu, 2008-08-14 at 11:58 +1000, Rusty Russell wrote:
>> On Thursday 14 August 2008 00:30:16 Mark McLoughlin wrote:
>>> A very simple approach is attached; I did consider doing a TUNGETFLAGS
>>> that would return tun->flags, but I think it's nicer to have a companion
>>> to TUNGETIFF since it also allows one to query the interface name from
>>> the file descriptor.
>> This seems really sensible to me.
>>
>> If Max acks it,
> 
> How about it Max?

Sorry for the delay Mark. I replied to your other email.
ACK.

Max

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] tun: TUNGETIFF interface to query name and flags
  2008-08-15 18:00   ` Max Krasnyansky
@ 2008-08-15 22:10     ` David Miller
  0 siblings, 0 replies; 6+ messages in thread
From: David Miller @ 2008-08-15 22:10 UTC (permalink / raw)
  To: maxk; +Cc: rusty, markmc, netdev, virtualization

From: Max Krasnyansky <maxk@qualcomm.com>
Date: Fri, 15 Aug 2008 11:00:19 -0700

> Rusty Russell wrote:
> > On Thursday 14 August 2008 00:30:16 Mark McLoughlin wrote:
> >> A very simple approach is attached; I did consider doing a TUNGETFLAGS
> >> that would return tun->flags, but I think it's nicer to have a companion
> >> to TUNGETIFF since it also allows one to query the interface name from
> >> the file descriptor.
> > 
> > This seems really sensible to me.
> > 
> > If Max acks it, I'd say Dave should merge it.
> 
> Makes perfect sense to me.
> Definitely Ack. It has zero impact on existing user and I'd be ok if this goes
>  in during .27-rc series.

I've applied Mark's patch, thanks.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-08-15 22:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-13 14:30 [PATCH 1/1] tun: TUNGETIFF interface to query name and flags Mark McLoughlin
2008-08-14  1:58 ` Rusty Russell
2008-08-15 14:02   ` Mark McLoughlin
2008-08-15 18:10     ` Max Krasnyansky
2008-08-15 18:00   ` Max Krasnyansky
2008-08-15 22:10     ` David Miller

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).