netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Paul Moore <paul.moore@hp.com>,
	David Miller <davem@davemloft.net>,
	netdev@vger.kernel.org, herbert@gondor.apana.org.au
Subject: Re: [PATCH RFC] tun: export underlying socket
Date: Fri, 11 Sep 2009 12:44:11 +0300	[thread overview]
Message-ID: <20090911094411.GA11086@redhat.com> (raw)
In-Reply-To: <4AA9E9D3.5070406@gmail.com>

On Fri, Sep 11, 2009 at 08:10:27AM +0200, Eric Dumazet wrote:
> Michael S. Tsirkin a écrit :
> > On Fri, Sep 11, 2009 at 07:59:43AM +0300, Michael S. Tsirkin wrote:
> >> On Fri, Sep 11, 2009 at 12:17:27AM -0400, Paul Moore wrote:
> >>> On Thursday 10 September 2009 08:59:29 am Michael S. Tsirkin wrote:
> >>>> Tun device looks similar to a packet socket
> >>>> in that both pass complete frames from/to userspace.
> >>>>
> >>>> This patch fills in enough fields in the socket underlying tun driver
> >>>> to support sendmsg/recvmsg operations, and exports access to this socket
> >>>> to modules.
> >>>>
> >>>> This way, code using raw sockets to inject packets
> >>>> into a physical device, can support injecting
> >>>> packets into host network stack almost without modification.
> >>>>
> >>>> First user of this interface will be vhost virtualization
> >>>> accelerator.
> >>> No comments on the code at this point - I'm just trying to understand the 
> >>> intended user right now which I'm assuming is the vhost-net bits you sent 
> >>> previously? 
> >> Yes - these now use raw socket,
> > 
> > More specifically, vhost would then be patched with:
> > 
> > diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
> > index aeffb3a..b54f9d6 100644
> > --- a/drivers/vhost/net.c
> > +++ b/drivers/vhost/net.c
> > @@ -331,15 +331,26 @@ err:
> >  	return ERR_PTR(r);
> >  }
> >  
> > +static struct socket *get_tun_socket(int fd)
> > +{
> > +	struct file *file = fget(fd);
> > +	if (!file)
> > +		return ERR_PTR(-EBADF);
> > +	return tun_get_socket(file);
> 
> This would leak a reference on file, if it happens not being a tun file 

Good catch, thanks! So it should be:

diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
index aeffb3a..e70f954 100644
--- a/drivers/vhost/net.c
+++ b/drivers/vhost/net.c
@@ -331,16 +331,30 @@ err:
 	return ERR_PTR(r);
 }
 
+static struct socket *get_tun_socket(int fd)
+{
+	struct file *file = fget(fd);
+	struct socket *sock;
+	if (!file)
+		return ERR_PTR(-EBADF);
+	sock = tun_get_socket(file);
+	if (IS_ERR(sock))
+		fput(file);
+	return sock;
+}
+
 static struct socket *get_socket(int fd)
 {
 	struct socket *sock;
 	sock = get_raw_socket(fd);
 	if (!IS_ERR(sock))
 		return sock;
+	sock = get_tun_socket(fd);
+	if (!IS_ERR(sock))
+		return sock;
 	return ERR_PTR(-ENOTSOCK);
 }
 
-
 static long vhost_net_set_socket(struct vhost_net *n, int fd)
 {
 	struct socket *sock, *oldsock = NULL;

  reply	other threads:[~2009-09-11  9:45 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-10 12:59 [PATCH RFC] tun: export underlying socket Michael S. Tsirkin
2009-09-10 13:19 ` Eric Dumazet
2009-09-10 13:27   ` Michael S. Tsirkin
2009-09-11  4:17 ` Paul Moore
2009-09-11  4:59   ` Michael S. Tsirkin
2009-09-11  5:36     ` Michael S. Tsirkin
2009-09-11  6:10       ` Eric Dumazet
2009-09-11  9:44         ` Michael S. Tsirkin [this message]
2009-09-14  8:01       ` Or Gerlitz
2009-09-14  8:07 ` Or Gerlitz
2009-09-14  8:09   ` Michael S. Tsirkin
2009-09-14  8:17     ` Or Gerlitz
2009-09-14  9:11       ` Michael S. Tsirkin
2009-09-14  9:43         ` Or Gerlitz
2009-09-14 10:10           ` Michael S. Tsirkin
2009-09-14 14:06             ` Or Gerlitz
2009-09-14 15:03               ` Herbert Xu
2009-09-15 13:02                 ` Or Gerlitz
2009-09-15 13:31                   ` Herbert Xu
2009-09-14 15:40               ` Michael S. Tsirkin
2009-09-15 13:11                 ` Or Gerlitz
2009-09-15 13:18                   ` Michael S. Tsirkin
2009-11-02 17:20 ` [PATCHv2] " Michael S. Tsirkin
2009-11-03 15:10   ` Herbert Xu

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=20090911094411.GA11086@redhat.com \
    --to=mst@redhat.com \
    --cc=davem@davemloft.net \
    --cc=eric.dumazet@gmail.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=netdev@vger.kernel.org \
    --cc=paul.moore@hp.com \
    /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).