Re: pre-2.0.30 SOMAXCONN Value

Dean Gaudet (dgaudet-list-linux-kernel@arctic.org)
Sun, 30 Mar 1997 04:08:59 -0800 (PST)


On Sat, 29 Mar 1997, Alan Cox wrote:
> Because the backlog queue is a signed char. If you change that (and test you
> got all the cases), your machine should be happy with a 512 SOMAXCONN

Actually it was an unsigned char. I was looking at this for another
reason -- part of the RST cookies code does a "2*sk->max_ack_backlog", and
since max_ack_backlog was an unsigned char this would roll to 0 pretty
easily. So I changed ack_backlog and max_ack_backlog to unsigned int.
And checked around and it looks like that's all that's really required.

I noticed that only inet_listen tested the listen backlog against
SOMAXCONN, none of the other protocols checked. I'm not sure what the
intent of casting the backlog to (unsigned) was, it probably should have
been (unsigned char).

So anyhow, this patch gives a 512 SOMAXCONN and seems to work after some
testing.

Dean

diff -r -u /usr/src/linux-2.0.29/include/linux/socket.h linux-2.0.29/include/linux/socket.h
--- /usr/src/linux-2.0.29/include/linux/socket.h Mon Jul 8 06:09:16 1996
+++ linux-2.0.29/include/linux/socket.h Sun Mar 30 00:42:17 1997
@@ -78,8 +78,10 @@

#define PF_MAX AF_MAX

-/* Maximum queue length specifiable by listen. */
-#define SOMAXCONN 128
+/* Maximum queue length specifiable by listen.
+ * It's wise to keep this <= 32767
+ */
+#define SOMAXCONN 512

/* Flags we can use with send/ and recv. */
#define MSG_OOB 1
diff -r -u /usr/src/linux-2.0.29/include/net/sock.h linux-2.0.29/include/net/sock.h
--- /usr/src/linux-2.0.29/include/net/sock.h Sat Mar 15 13:15:33 1997
+++ linux-2.0.29/include/net/sock.h Sun Mar 30 03:45:33 1997
@@ -254,10 +254,10 @@
'timed out' */
unsigned char protocol;
volatile unsigned char state;
- unsigned char ack_backlog;
- unsigned char max_ack_backlog;
unsigned char priority;
unsigned char debug;
+ unsigned ack_backlog;
+ unsigned max_ack_backlog;
int rcvbuf;
int sndbuf;
unsigned short type;
diff -r -u /usr/src/linux-2.0.29/net/ipv4/af_inet.c linux-2.0.29/net/ipv4/af_inet.c
--- /usr/src/linux-2.0.29/net/ipv4/af_inet.c Sat Mar 15 11:18:10 1997
+++ linux-2.0.29/net/ipv4/af_inet.c Sun Mar 30 00:36:57 1997
@@ -351,17 +351,6 @@
if(inet_autobind(sk) != 0)
return -EAGAIN;

- /* We might as well re use these. */
- /*
- * note that the backlog is "unsigned char", so truncate it
- * somewhere. We might as well truncate it to what everybody
- * else does..
- * Now truncate to 128 not 5.
- *
- * This was wrong, truncate both cases to SOMAXCONN. -DaveM
- */
- if (((unsigned) backlog == 0) || ((unsigned) backlog > SOMAXCONN))
- backlog = SOMAXCONN;
sk->max_ack_backlog = backlog;
if (sk->state != TCP_LISTEN) {
sk->ack_backlog = 0;
diff -r -u /usr/src/linux-2.0.29/net/socket.c linux-2.0.29/net/socket.c
--- /usr/src/linux-2.0.29/net/socket.c Mon Jul 15 01:31:51 1996
+++ linux-2.0.29/net/socket.c Sun Mar 30 00:40:01 1997
@@ -708,6 +708,10 @@
if (sock->state != SS_UNCONNECTED)
return(-EINVAL);

+ /* do this here since many protocols neglected to do it -dgaudet */
+ if (backlog == 0 || backlog > SOMAXCONN)
+ backlog=SOMAXCONN;
+
if (sock->ops && sock->ops->listen)
{
err=sock->ops->listen(sock, backlog);