All of lore.kernel.org
 help / color / mirror / Atom feed
* Q: need effective backlog for listen()
@ 2014-12-08 12:51 Ulrich Windl
  2014-12-08 15:18 ` Eric Dumazet
  2014-12-08 16:35 ` Philippe Troin
  0 siblings, 2 replies; 7+ messages in thread
From: Ulrich Windl @ 2014-12-08 12:51 UTC (permalink / raw)
  To: netdev

(not subscribed to the list, plese keep me on CC:)

Hi!

I have a problem I could not find the answer. I suspect the problem arises from Linux derivating from standard functionality...

I have written a server that should accept n TCP connections at most. I was expecting that the backlog parameter of listen will cause extra connection requests either
1) to be refused
or
2) to time out eventually

(The standard seems to say that extra connections are refused)

However none of the above see ms true. Even if my server delays accept()ing new connections, no client ever sees a "connection refused" or "connection timed out". Is there any chance to signal the client that no more connections are accepted at the moment?

Regards,
Ulrich Windl

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

* Re: Q: need effective backlog for listen()
  2014-12-08 12:51 Q: need effective backlog for listen() Ulrich Windl
@ 2014-12-08 15:18 ` Eric Dumazet
  2014-12-08 16:31   ` Antw: " Ulrich Windl
  2014-12-08 16:35 ` Philippe Troin
  1 sibling, 1 reply; 7+ messages in thread
From: Eric Dumazet @ 2014-12-08 15:18 UTC (permalink / raw)
  To: Ulrich Windl; +Cc: netdev

On Mon, 2014-12-08 at 13:51 +0100, Ulrich Windl wrote:
> (not subscribed to the list, plese keep me on CC:)
> 
> Hi!
> 
> I have a problem I could not find the answer. I suspect the problem
> arises from Linux derivating from standard functionality...
> 
> I have written a server that should accept n TCP connections at most.
> I was expecting that the backlog parameter of listen will cause extra
> connection requests either
> 1) to be refused
> or
> 2) to time out eventually
> 
> (The standard seems to say that extra connections are refused)
> 
> However none of the above see ms true. Even if my server delays
> accept()ing new connections, no client ever sees a "connection
> refused" or "connection timed out". Is there any chance to signal the
> client that no more connections are accepted at the moment?

This 'standard' makes no sense to me, in light of SYNFLOOD attacks.

It actually makes SYNFLOOD attacks very effective.

Have you tried to disable syncookies for a start ?

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

* Antw: Re: Q: need effective backlog for listen()
  2014-12-08 15:18 ` Eric Dumazet
@ 2014-12-08 16:31   ` Ulrich Windl
  0 siblings, 0 replies; 7+ messages in thread
From: Ulrich Windl @ 2014-12-08 16:31 UTC (permalink / raw)
  To: eric.dumazet; +Cc: netdev

>>> Eric Dumazet <eric.dumazet@gmail.com> schrieb am 08.12.2014 um 16:18 in
Nachricht <1418051901.15618.46.camel@edumazet-glaptop2.roam.corp.google.com>:
> On Mon, 2014-12-08 at 13:51 +0100, Ulrich Windl wrote:
>> (not subscribed to the list, plese keep me on CC:)
>> 
>> Hi!
>> 
>> I have a problem I could not find the answer. I suspect the problem
>> arises from Linux derivating from standard functionality...
>> 
>> I have written a server that should accept n TCP connections at most.
>> I was expecting that the backlog parameter of listen will cause extra
>> connection requests either
>> 1) to be refused
>> or
>> 2) to time out eventually
>> 
>> (The standard seems to say that extra connections are refused)
>> 
>> However none of the above see ms true. Even if my server delays
>> accept()ing new connections, no client ever sees a "connection
>> refused" or "connection timed out". Is there any chance to signal the
>> client that no more connections are accepted at the moment?
> 
> This 'standard' makes no sense to me, in light of SYNFLOOD attacks.
> 
> It actually makes SYNFLOOD attacks very effective.
> 
> Have you tried to disable syncookies for a start ?

No, I tries to temporarily close the listening socket. My priority is not to overload the server with connections. At the sime time I _want_ that the clients see that the server resfuses connections. Before you wonder: The client will actually be a load balancer.

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

* Re: Q: need effective backlog for listen()
  2014-12-08 12:51 Q: need effective backlog for listen() Ulrich Windl
  2014-12-08 15:18 ` Eric Dumazet
@ 2014-12-08 16:35 ` Philippe Troin
  2014-12-09  7:01   ` Antw: " Ulrich Windl
  1 sibling, 1 reply; 7+ messages in thread
From: Philippe Troin @ 2014-12-08 16:35 UTC (permalink / raw)
  To: Ulrich Windl; +Cc: netdev

On Mon, 2014-12-08 at 13:51 +0100, Ulrich Windl wrote:
> (not subscribed to the list, plese keep me on CC:)
> 
> I have a problem I could not find the answer. I suspect the problem
> arises from Linux derivating from standard functionality...
> 
> I have written a server that should accept n TCP connections at most.
> I was expecting that the backlog parameter of listen will cause extra
> connection requests either
> 1) to be refused
> or
> 2) to time out eventually
> 
> (The standard seems to say that extra connections are refused)

The argument to listen() specifies how many connections the system is
allow to keep waiting to be accept()ed.
As soon as you accept() the connection, the count is decremented.
So that won't help for your use case.

> However none of the above see ms true. Even if my server delays
> accept()ing new connections, no client ever sees a "connection
> refused" or "connection timed out". Is there any chance to signal the
> client that no more connections are accepted at the moment?

Close the listening socket.  No new connections will be accepted.
When you reopen the socket for accepting new connections, you may have
to use SO_REUSEADDR before bind()ing to the port.

Phil.

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

* Antw: Re: Q: need effective backlog for listen()
  2014-12-08 16:35 ` Philippe Troin
@ 2014-12-09  7:01   ` Ulrich Windl
  2014-12-09 15:07     ` Philippe Troin
  0 siblings, 1 reply; 7+ messages in thread
From: Ulrich Windl @ 2014-12-09  7:01 UTC (permalink / raw)
  To: phil; +Cc: netdev

>>> Philippe Troin <phil@fifi.org> schrieb am 08.12.2014 um 17:35 in Nachricht
<1418056540.384.5.camel@niobium.home.fifi.org>:
> On Mon, 2014-12-08 at 13:51 +0100, Ulrich Windl wrote:
>> (not subscribed to the list, plese keep me on CC:)
>> 
>> I have a problem I could not find the answer. I suspect the problem
>> arises from Linux derivating from standard functionality...
>> 
>> I have written a server that should accept n TCP connections at most.
>> I was expecting that the backlog parameter of listen will cause extra
>> connection requests either
>> 1) to be refused
>> or
>> 2) to time out eventually
>> 
>> (The standard seems to say that extra connections are refused)
> 
> The argument to listen() specifies how many connections the system is
> allow to keep waiting to be accept()ed.
> As soon as you accept() the connection, the count is decremented.
> So that won't help for your use case.
> 
>> However none of the above see ms true. Even if my server delays
>> accept()ing new connections, no client ever sees a "connection
>> refused" or "connection timed out". Is there any chance to signal the
>> client that no more connections are accepted at the moment?
> 
> Close the listening socket.  No new connections will be accepted.
> When you reopen the socket for accepting new connections, you may have
> to use SO_REUSEADDR before bind()ing to the port.

This is what I had done, but those connections who are waiting to be accepted: If I close the listening socket, will the clients see a connection abort, or will they see a connection refused?
Connection aborts could confuse clients.

Ulrich

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

* Re: Antw: Re: Q: need effective backlog for listen()
  2014-12-09  7:01   ` Antw: " Ulrich Windl
@ 2014-12-09 15:07     ` Philippe Troin
  2014-12-10  7:23       ` Ulrich Windl
  0 siblings, 1 reply; 7+ messages in thread
From: Philippe Troin @ 2014-12-09 15:07 UTC (permalink / raw)
  To: Ulrich Windl; +Cc: netdev

On Tue, 2014-12-09 at 08:01 +0100, Ulrich Windl wrote:
> >>> Philippe Troin <phil@fifi.org> schrieb am 08.12.2014 um 17:35 in Nachricht
> <1418056540.384.5.camel@niobium.home.fifi.org>:
>
> > The argument to listen() specifies how many connections the system is
> > allow to keep waiting to be accept()ed.
> > As soon as you accept() the connection, the count is decremented.
> > So that won't help for your use case.
> > 
> >> However none of the above see ms true. Even if my server delays
> >> accept()ing new connections, no client ever sees a "connection
> >> refused" or "connection timed out". Is there any chance to signal the
> >> client that no more connections are accepted at the moment?
> > 
> > Close the listening socket.  No new connections will be accepted.
> > When you reopen the socket for accepting new connections, you may have
> > to use SO_REUSEADDR before bind()ing to the port.
> 
> This is what I had done, but those connections who are waiting to be
> accepted: If I close the listening socket, will the clients see a
> connection abort, or will they see a connection refused?
> Connection aborts could confuse clients.

The clients that completed the 3-way handshake and are waiting for their
(server-side) socket to be accept()ed will see connection reset I
believe.

You may be able to work something out by having no listen backlog
(listen(0)) and closing and reopening the socket when needed.

Phil.

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

* Re: Antw: Re: Q: need effective backlog for listen()
  2014-12-09 15:07     ` Philippe Troin
@ 2014-12-10  7:23       ` Ulrich Windl
  0 siblings, 0 replies; 7+ messages in thread
From: Ulrich Windl @ 2014-12-10  7:23 UTC (permalink / raw)
  To: phil; +Cc: netdev

>>> Philippe Troin <phil@fifi.org> schrieb am 09.12.2014 um 16:07 in Nachricht
<1418137657.384.17.camel@niobium.home.fifi.org>:
> On Tue, 2014-12-09 at 08:01 +0100, Ulrich Windl wrote:
>> >>> Philippe Troin <phil@fifi.org> schrieb am 08.12.2014 um 17:35 in Nachricht
>> <1418056540.384.5.camel@niobium.home.fifi.org>:
>>
>> > The argument to listen() specifies how many connections the system is
>> > allow to keep waiting to be accept()ed.
>> > As soon as you accept() the connection, the count is decremented.
>> > So that won't help for your use case.
>> > 
>> >> However none of the above see ms true. Even if my server delays
>> >> accept()ing new connections, no client ever sees a "connection
>> >> refused" or "connection timed out". Is there any chance to signal the
>> >> client that no more connections are accepted at the moment?
>> > 
>> > Close the listening socket.  No new connections will be accepted.
>> > When you reopen the socket for accepting new connections, you may have
>> > to use SO_REUSEADDR before bind()ing to the port.
>> 
>> This is what I had done, but those connections who are waiting to be
>> accepted: If I close the listening socket, will the clients see a
>> connection abort, or will they see a connection refused?
>> Connection aborts could confuse clients.
> 
> The clients that completed the 3-way handshake and are waiting for their
> (server-side) socket to be accept()ed will see connection reset I
> believe.
> 
> You may be able to work something out by having no listen backlog
> (listen(0)) and closing and reopening the socket when needed.

I think I'd feel happier if listen() would implement the old semantics by default, and a new ioctl() (or such) would change to the "Linux accept all connections (3-way handshake) mode" on demand... Wishful thinking...

Ulrich

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

end of thread, other threads:[~2014-12-10  7:23 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-08 12:51 Q: need effective backlog for listen() Ulrich Windl
2014-12-08 15:18 ` Eric Dumazet
2014-12-08 16:31   ` Antw: " Ulrich Windl
2014-12-08 16:35 ` Philippe Troin
2014-12-09  7:01   ` Antw: " Ulrich Windl
2014-12-09 15:07     ` Philippe Troin
2014-12-10  7:23       ` Ulrich Windl

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.