netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC] Zero-length write() does not generate a datagram on connected socket
       [not found] ` <20070922094432.E9BEA108010@picon.linux-foundation.org>
@ 2007-09-24 22:34   ` Stephen Hemminger
  2007-09-26  3:18     ` Herbert Xu
  2007-09-27 20:53     ` David Miller
  0 siblings, 2 replies; 8+ messages in thread
From: Stephen Hemminger @ 2007-09-24 22:34 UTC (permalink / raw)
  To: netdev

The bug http://bugzilla.kernel.org/show_bug.cgi?id=5731
describes an issue where write() can't be used to generate a zero-length
datagram (but send, and sendto do work).

I think the following is needed:

--- a/net/socket.c	2007-08-20 09:54:28.000000000 -0700
+++ b/net/socket.c	2007-09-24 15:31:25.000000000 -0700
@@ -777,8 +777,11 @@ static ssize_t sock_aio_write(struct kio
 	if (pos != 0)
 		return -ESPIPE;
 
-	if (iocb->ki_left == 0)	/* Match SYS5 behaviour */
-		return 0;
+	if (unlikely(iocb->ki_left == 0)) {
+		struct socket *sock = iocb->ki_filp->private_data;
+		if (sock->type == SOCK_STREAM)
+			return 0;
+	}
 
 	x = alloc_sock_iocb(iocb, &siocb);
 	if (!x)

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

* Re: [RFC] Zero-length write() does not generate a datagram on connected socket
  2007-09-24 22:34   ` [RFC] Zero-length write() does not generate a datagram on connected socket Stephen Hemminger
@ 2007-09-26  3:18     ` Herbert Xu
  2007-09-26  5:36       ` Stephen Hemminger
                         ` (2 more replies)
  2007-09-27 20:53     ` David Miller
  1 sibling, 3 replies; 8+ messages in thread
From: Herbert Xu @ 2007-09-26  3:18 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev

Stephen Hemminger <shemminger@linux-foundation.org> wrote:
> The bug http://bugzilla.kernel.org/show_bug.cgi?id=5731
> describes an issue where write() can't be used to generate a zero-length
> datagram (but send, and sendto do work).
> 
> I think the following is needed:
> 
> --- a/net/socket.c      2007-08-20 09:54:28.000000000 -0700
> +++ b/net/socket.c      2007-09-24 15:31:25.000000000 -0700
> @@ -777,8 +777,11 @@ static ssize_t sock_aio_write(struct kio
>        if (pos != 0)
>                return -ESPIPE;
> 
> -       if (iocb->ki_left == 0) /* Match SYS5 behaviour */
> -               return 0;
> +       if (unlikely(iocb->ki_left == 0)) {
> +               struct socket *sock = iocb->ki_filp->private_data;
> +               if (sock->type == SOCK_STREAM)
> +                       return 0;
> +       }

I'm not sure whether all STREAM protocols treat zero-length
sends as no-ops.  What about SCTP?

Put it another way, do we really need to keep the short-circuit
for SOCK_STREAM?

Cheers,
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

* Re: [RFC] Zero-length write() does not generate a datagram on connected socket
  2007-09-26  3:18     ` Herbert Xu
@ 2007-09-26  5:36       ` Stephen Hemminger
  2007-09-26 17:17       ` Rick Jones
  2007-09-26 18:47       ` Vlad Yasevich
  2 siblings, 0 replies; 8+ messages in thread
From: Stephen Hemminger @ 2007-09-26  5:36 UTC (permalink / raw)
  To: Herbert Xu; +Cc: netdev

On Wed, 26 Sep 2007 11:18:39 +0800
Herbert Xu <herbert@gondor.apana.org.au> wrote:

> Stephen Hemminger <shemminger@linux-foundation.org> wrote:
> > The bug http://bugzilla.kernel.org/show_bug.cgi?id=5731
> > describes an issue where write() can't be used to generate a zero-length
> > datagram (but send, and sendto do work).
> > 
> > I think the following is needed:
> > 
> > --- a/net/socket.c      2007-08-20 09:54:28.000000000 -0700
> > +++ b/net/socket.c      2007-09-24 15:31:25.000000000 -0700
> > @@ -777,8 +777,11 @@ static ssize_t sock_aio_write(struct kio
> >        if (pos != 0)
> >                return -ESPIPE;
> > 
> > -       if (iocb->ki_left == 0) /* Match SYS5 behaviour */
> > -               return 0;
> > +       if (unlikely(iocb->ki_left == 0)) {
> > +               struct socket *sock = iocb->ki_filp->private_data;
> > +               if (sock->type == SOCK_STREAM)
> > +                       return 0;
> > +       }
> 
> I'm not sure whether all STREAM protocols treat zero-length
> sends as no-ops.  What about SCTP?
> 
> Put it another way, do we really need to keep the short-circuit
> for SOCK_STREAM?
> 
> Cheers,

Stream is defined as sequence of bytes. So short circuit makes sense
If the application wants message boundaries it needs to use SOCK_SEQPACKET.
I was paranoid about possible breakage in TCP or SCTP. But since
send(s, buf, 0, 0) already filters through, I guess it doesn't matter.

-- 
Stephen Hemminger <shemminger@linux-foundation.org>

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

* Re: [RFC] Zero-length write() does not generate a datagram on connected socket
  2007-09-26  3:18     ` Herbert Xu
  2007-09-26  5:36       ` Stephen Hemminger
@ 2007-09-26 17:17       ` Rick Jones
  2007-09-26 18:47       ` Vlad Yasevich
  2 siblings, 0 replies; 8+ messages in thread
From: Rick Jones @ 2007-09-26 17:17 UTC (permalink / raw)
  To: Herbert Xu; +Cc: Stephen Hemminger, netdev

Herbert Xu wrote:
> Stephen Hemminger <shemminger@linux-foundation.org> wrote:
> 
>>The bug http://bugzilla.kernel.org/show_bug.cgi?id=5731
>>describes an issue where write() can't be used to generate a zero-length
>>datagram (but send, and sendto do work).
>>
>>I think the following is needed:
>>
>>--- a/net/socket.c      2007-08-20 09:54:28.000000000 -0700
>>+++ b/net/socket.c      2007-09-24 15:31:25.000000000 -0700
>>@@ -777,8 +777,11 @@ static ssize_t sock_aio_write(struct kio
>>       if (pos != 0)
>>               return -ESPIPE;
>>
>>-       if (iocb->ki_left == 0) /* Match SYS5 behaviour */
>>-               return 0;
>>+       if (unlikely(iocb->ki_left == 0)) {
>>+               struct socket *sock = iocb->ki_filp->private_data;
>>+               if (sock->type == SOCK_STREAM)
>>+                       return 0;
>>+       }
> 
> 
> I'm not sure whether all STREAM protocols treat zero-length
> sends as no-ops.  What about SCTP?

I asked Vlad that very question, since SCTP can preserve message 
boundaries. He tells me that a zero-length message is not part of SCTP.

rick jones

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

* Re: [RFC] Zero-length write() does not generate a datagram on connected socket
  2007-09-26  3:18     ` Herbert Xu
  2007-09-26  5:36       ` Stephen Hemminger
  2007-09-26 17:17       ` Rick Jones
@ 2007-09-26 18:47       ` Vlad Yasevich
  2 siblings, 0 replies; 8+ messages in thread
From: Vlad Yasevich @ 2007-09-26 18:47 UTC (permalink / raw)
  To: Herbert Xu; +Cc: Stephen Hemminger, netdev

Herbert Xu wrote:
> Stephen Hemminger <shemminger@linux-foundation.org> wrote:
>> The bug http://bugzilla.kernel.org/show_bug.cgi?id=5731
>> describes an issue where write() can't be used to generate a zero-length
>> datagram (but send, and sendto do work).
>>
>> I think the following is needed:
>>
>> --- a/net/socket.c      2007-08-20 09:54:28.000000000 -0700
>> +++ b/net/socket.c      2007-09-24 15:31:25.000000000 -0700
>> @@ -777,8 +777,11 @@ static ssize_t sock_aio_write(struct kio
>>        if (pos != 0)
>>                return -ESPIPE;
>>
>> -       if (iocb->ki_left == 0) /* Match SYS5 behaviour */
>> -               return 0;
>> +       if (unlikely(iocb->ki_left == 0)) {
>> +               struct socket *sock = iocb->ki_filp->private_data;
>> +               if (sock->type == SOCK_STREAM)
>> +                       return 0;
>> +       }
> 
> I'm not sure whether all STREAM protocols treat zero-length
> sends as no-ops.  What about SCTP?

0 byte writes are not allowed in SCTP.  A no-op is fine, otherwise
SCTP would return an error.

-vlad

> 
> Put it another way, do we really need to keep the short-circuit
> for SOCK_STREAM?
> 
> Cheers,


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

* Re: [RFC] Zero-length write() does not generate a datagram on connected socket
  2007-09-24 22:34   ` [RFC] Zero-length write() does not generate a datagram on connected socket Stephen Hemminger
  2007-09-26  3:18     ` Herbert Xu
@ 2007-09-27 20:53     ` David Miller
  2007-09-27 22:41       ` Stephen Hemminger
  1 sibling, 1 reply; 8+ messages in thread
From: David Miller @ 2007-09-27 20:53 UTC (permalink / raw)
  To: shemminger; +Cc: netdev

From: Stephen Hemminger <shemminger@linux-foundation.org>
Date: Mon, 24 Sep 2007 15:34:35 -0700

> The bug http://bugzilla.kernel.org/show_bug.cgi?id=5731
> describes an issue where write() can't be used to generate a zero-length
> datagram (but send, and sendto do work).
> 
> I think the following is needed:
> 
> --- a/net/socket.c	2007-08-20 09:54:28.000000000 -0700
> +++ b/net/socket.c	2007-09-24 15:31:25.000000000 -0700
> @@ -777,8 +777,11 @@ static ssize_t sock_aio_write(struct kio
>  	if (pos != 0)
>  		return -ESPIPE;
>  
> -	if (iocb->ki_left == 0)	/* Match SYS5 behaviour */
> -		return 0;
> +	if (unlikely(iocb->ki_left == 0)) {
> +		struct socket *sock = iocb->ki_filp->private_data;
> +		if (sock->type == SOCK_STREAM)
> +			return 0;
> +	}
>  
>  	x = alloc_sock_iocb(iocb, &siocb);
>  	if (!x)

We should simply remove the check completely.

There is no need to add special code for different types of protocols
and sockets.

As is hinted in the bugzilla, the exact same thing can happen with a
suitably constructed sendto() or sendmsg() call.  write() on a socket
is a sendmsg() with a NULL msg_control and a single entry iovec, plain
and simple.

It's how BSD and many other systems behave, and I double checked
Steven's Volume 2 just to make sure.

So I'm going to check in the following to fix this bugzilla.  There is
a similarly ugly test for len==0 in sys_read() on sockets.  If someone
would do some research on the validity of that thing I'd really
appreciate it :-)

diff --git a/net/socket.c b/net/socket.c
index 7d44453..b09eb90 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -777,9 +777,6 @@ static ssize_t sock_aio_write(struct kiocb *iocb, const struct iovec *iov,
 	if (pos != 0)
 		return -ESPIPE;
 
-	if (iocb->ki_left == 0)	/* Match SYS5 behaviour */
-		return 0;
-
 	x = alloc_sock_iocb(iocb, &siocb);
 	if (!x)
 		return -ENOMEM;

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

* Re: [RFC] Zero-length write() does not generate a datagram on connected socket
  2007-09-27 20:53     ` David Miller
@ 2007-09-27 22:41       ` Stephen Hemminger
  2007-09-28  8:49         ` Michael Kerrisk
  0 siblings, 1 reply; 8+ messages in thread
From: Stephen Hemminger @ 2007-09-27 22:41 UTC (permalink / raw)
  To: David Miller; +Cc: netdev

On Thu, 27 Sep 2007 13:53:34 -0700 (PDT)
David Miller <davem@davemloft.net> wrote:

> From: Stephen Hemminger <shemminger@linux-foundation.org>
> Date: Mon, 24 Sep 2007 15:34:35 -0700
> 
> > The bug http://bugzilla.kernel.org/show_bug.cgi?id=5731
> > describes an issue where write() can't be used to generate a zero-length
> > datagram (but send, and sendto do work).
> > 
> > I think the following is needed:
> > 
> > --- a/net/socket.c	2007-08-20 09:54:28.000000000 -0700
> > +++ b/net/socket.c	2007-09-24 15:31:25.000000000 -0700
> > @@ -777,8 +777,11 @@ static ssize_t sock_aio_write(struct kio
> >  	if (pos != 0)
> >  		return -ESPIPE;
> >  
> > -	if (iocb->ki_left == 0)	/* Match SYS5 behaviour */
> > -		return 0;
> > +	if (unlikely(iocb->ki_left == 0)) {
> > +		struct socket *sock = iocb->ki_filp->private_data;
> > +		if (sock->type == SOCK_STREAM)
> > +			return 0;
> > +	}
> >  
> >  	x = alloc_sock_iocb(iocb, &siocb);
> >  	if (!x)
> 
> We should simply remove the check completely.
> 
> There is no need to add special code for different types of protocols
> and sockets.
> 
> As is hinted in the bugzilla, the exact same thing can happen with a
> suitably constructed sendto() or sendmsg() call.  write() on a socket
> is a sendmsg() with a NULL msg_control and a single entry iovec, plain
> and simple.
> 
> It's how BSD and many other systems behave, and I double checked
> Steven's Volume 2 just to make sure.
> 
> So I'm going to check in the following to fix this bugzilla.  There is
> a similarly ugly test for len==0 in sys_read() on sockets.  If someone
> would do some research on the validity of that thing I'd really
> appreciate it :-)

Read of zero length should be a no-op for SOCK_STREAM but
for SOCK_DATAGRAM or SOCK_SEQPACKET it might be useful as a 
remote wait for event.

-- 
Stephen Hemminger <shemminger@linux-foundation.org>

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

* Re: [RFC] Zero-length write() does not generate a datagram on connected socket
  2007-09-27 22:41       ` Stephen Hemminger
@ 2007-09-28  8:49         ` Michael Kerrisk
  0 siblings, 0 replies; 8+ messages in thread
From: Michael Kerrisk @ 2007-09-28  8:49 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: David Miller, netdev, mtk-manpages

On 9/28/07, Stephen Hemminger <shemminger@linux-foundation.org> wrote:
> On Thu, 27 Sep 2007 13:53:34 -0700 (PDT)
> David Miller <davem@davemloft.net> wrote:
>
> > From: Stephen Hemminger <shemminger@linux-foundation.org>
> > Date: Mon, 24 Sep 2007 15:34:35 -0700
> >
> > > The bug http://bugzilla.kernel.org/show_bug.cgi?id=5731
> > > describes an issue where write() can't be used to generate a zero-length
> > > datagram (but send, and sendto do work).
> > >
> > > I think the following is needed:
> > >
> > > --- a/net/socket.c  2007-08-20 09:54:28.000000000 -0700
> > > +++ b/net/socket.c  2007-09-24 15:31:25.000000000 -0700
> > > @@ -777,8 +777,11 @@ static ssize_t sock_aio_write(struct kio
> > >     if (pos != 0)
> > >             return -ESPIPE;
> > >
> > > -   if (iocb->ki_left == 0) /* Match SYS5 behaviour */
> > > -           return 0;
> > > +   if (unlikely(iocb->ki_left == 0)) {
> > > +           struct socket *sock = iocb->ki_filp->private_data;
> > > +           if (sock->type == SOCK_STREAM)
> > > +                   return 0;
> > > +   }
> > >
> > >     x = alloc_sock_iocb(iocb, &siocb);
> > >     if (!x)
> >
> > We should simply remove the check completely.
> >
> > There is no need to add special code for different types of protocols
> > and sockets.
> >
> > As is hinted in the bugzilla, the exact same thing can happen with a
> > suitably constructed sendto() or sendmsg() call.  write() on a socket
> > is a sendmsg() with a NULL msg_control and a single entry iovec, plain
> > and simple.
> >
> > It's how BSD and many other systems behave, and I double checked
> > Steven's Volume 2 just to make sure.
> >
> > So I'm going to check in the following to fix this bugzilla.  There is
> > a similarly ugly test for len==0 in sys_read() on sockets.  If someone
> > would do some research on the validity of that thing I'd really
> > appreciate it :-)
>
> Read of zero length should be a no-op for SOCK_STREAM but
> for SOCK_DATAGRAM or SOCK_SEQPACKET it might be useful as a
> remote wait for event.

Hmm -- I hadn't checked the behavior for zero-length read() on other
systems.  i will try to do that soonish (probably only Minday or so).

Cheers,

Michael

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

end of thread, other threads:[~2007-09-28  8:49 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <bug-5731-100@http.bugzilla.kernel.org/>
     [not found] ` <20070922094432.E9BEA108010@picon.linux-foundation.org>
2007-09-24 22:34   ` [RFC] Zero-length write() does not generate a datagram on connected socket Stephen Hemminger
2007-09-26  3:18     ` Herbert Xu
2007-09-26  5:36       ` Stephen Hemminger
2007-09-26 17:17       ` Rick Jones
2007-09-26 18:47       ` Vlad Yasevich
2007-09-27 20:53     ` David Miller
2007-09-27 22:41       ` Stephen Hemminger
2007-09-28  8:49         ` Michael Kerrisk

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