netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [Bugme-new] [Bug 13688] New: backlog parameter of listen is not working with TCP
       [not found] <bug-13688-10286@http.bugzilla.kernel.org/>
@ 2009-07-01 18:49 ` Andrew Morton
  2009-07-01 21:10   ` Florian Westphal
  0 siblings, 1 reply; 2+ messages in thread
From: Andrew Morton @ 2009-07-01 18:49 UTC (permalink / raw)
  To: netdev; +Cc: bugzilla-daemon, bugme-daemon, florent.cloirec


(switched to email.  Please respond via emailed reply-to-all, not via the
bugzilla web interface).

On Wed, 1 Jul 2009 18:39:07 GMT
bugzilla-daemon@bugzilla.kernel.org wrote:

> http://bugzilla.kernel.org/show_bug.cgi?id=13688
> 
>            Summary: backlog parameter of listen is not working with TCP
>            Product: Networking
>            Version: 2.5
>     Kernel Version: 2.6
>           Platform: All
>         OS/Version: Linux
>               Tree: Mainline
>             Status: NEW
>           Severity: normal
>           Priority: P1
>          Component: IPV4
>         AssignedTo: shemminger@linux-foundation.org
>         ReportedBy: florent.cloirec@free.fr
>         Regression: No
> 
> 
> Created an attachment (id=22171)
>  --> (http://bugzilla.kernel.org/attachment.cgi?id=22171)
> little test server
> 
> When creating a server I usually create a socket, bind it to any address and
> call listen to limit the queue size, then I call accept in a loop to handle
> clients one by one.
> 
> In a particular case I wanted to serve only 1 client and refuse the other
> connection attempts. I tried any value for the backlog parameter, whatever I
> use the server is not refusing any connection, though the queue should be full.
> The SYN+ACK handshake is completed everytime.
> 
> To be sure this is a bug I checked this with BSD and Windows, I can confirm
> that it refuses connections if the max queue size specified with backlog is
> reached (Note that backlog is not exactly the queue size with these systems,
> there is a 3/2 factor, I don't know why).
> 
> Maybe this implementation for linux kernel is wanted even if it is not posix
> compliant, but I did not find anywhere why this is working like this. If this
> is not a bug, could someone explain me the usefullness of the backlog
> parameter?
> 
> I attached a little test program with which anyone should be able to test this
> by connecting multiple telnet to.
> 

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <fcntl.h>
#include <netinet/in.h>
#include <netinet/ip.h>


int main(void)
{
   int servsock = 0;
   int clientsock = 0;
   struct sockaddr_in servaddr;
   struct sockaddr_in clientaddr;
   socklen_t clientaddrlen;
   struct in_addr client_addr;

   servsock = socket(AF_INET, SOCK_STREAM, 0);

   //fcntl(servsock, F_SETFL, O_NONBLOCK);

   if(servsock != -1)
   {
      servaddr.sin_family = AF_INET;
      servaddr.sin_port = htons(6256);
      inet_aton("0.0.0.0", &client_addr);
      servaddr.sin_addr = client_addr;

      if(bind(servsock, &servaddr, sizeof(servaddr)) != -1)
      {
         if(listen(servsock, 0) != -1)
         {
            while(1)
            {
               printf("waiting for clients\n");
               clientsock = accept(servsock, &clientaddr, &clientaddrlen);
               if(clientsock != -1)
               {
                  printf("client accepted, now sleep 60 sec\n");
                  sleep(60);
                  printf("60 sec have elapsed, closing connection\n");
                  close(clientsock);
               }
               else
               {
                  printf("accept error: retrying in 1 sec...\n");
                  sleep(1);
               }
            }
         }
         else
         {
            printf("listen failed\n");
         }
      }
      else
      {
         printf("bind failed\n");
      }

   }
   else
   {
      printf("socket creation failed\n");
   }


   return 0;
}


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

* Re: [Bugme-new] [Bug 13688] New: backlog parameter of listen is not working with TCP
  2009-07-01 18:49 ` [Bugme-new] [Bug 13688] New: backlog parameter of listen is not working with TCP Andrew Morton
@ 2009-07-01 21:10   ` Florian Westphal
  0 siblings, 0 replies; 2+ messages in thread
From: Florian Westphal @ 2009-07-01 21:10 UTC (permalink / raw)
  To: Andrew Morton; +Cc: netdev, bugzilla-daemon, bugme-daemon, florent.cloirec

Andrew Morton <akpm@linux-foundation.org> wrote:
> On Wed, 1 Jul 2009 18:39:07 GMT
> bugzilla-daemon@bugzilla.kernel.org wrote:
> 
> > http://bugzilla.kernel.org/show_bug.cgi?id=13688
> >            Summary: backlog parameter of listen is not working with TCP
> >            Product: Networking
[..]
> > When creating a server I usually create a socket, bind it to any address and
> > call listen to limit the queue size, then I call accept in a loop to handle
> > clients one by one.
> > 
> > In a particular case I wanted to serve only 1 client and refuse the other
> > connection attempts. I tried any value for the backlog parameter, whatever I
> > use the server is not refusing any connection, though the queue should be full.
> > The SYN+ACK handshake is completed everytime.

The behaviour depends on net.ipv4.tcp_abort_on_overflow sysctl.
If its on, new connections are reset once the backlog is exhausted.

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

end of thread, other threads:[~2009-07-01 21:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <bug-13688-10286@http.bugzilla.kernel.org/>
2009-07-01 18:49 ` [Bugme-new] [Bug 13688] New: backlog parameter of listen is not working with TCP Andrew Morton
2009-07-01 21:10   ` Florian Westphal

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