Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 11 Feb 2001 01:55:16 -0800
From:      Alfred Perlstein <bright@wintelcom.net>
To:        net@freebsd.org
Cc:        jlemon@freebsd.org
Subject:   somaxconn and foot removal
Message-ID:  <20010211015516.J3274@fw.wintelcom.net>

next in thread | raw e-mail | index | archive | help
The sysctl for somaxconn is an int, however the queue limits in the 
socket structures are 'short' this can cause some bad behavior if
one sets somaxconn to more than 32k.

A) So, do we bump the sockets to use 'int' for so->so_qlimit?
B) Do we fix solisten() to compensate? 
C) Or de we fix the sysctl (patch below)?

I have patches for A and C.

(untested patch for A)
Index: socketvar.h
===================================================================
RCS file: /home/ncvs/src/sys/sys/socketvar.h,v
retrieving revision 1.55
diff -u -r1.55 socketvar.h
--- socketvar.h	2001/01/09 04:33:49	1.55
+++ socketvar.h	2001/02/11 09:52:58
@@ -31,7 +31,7 @@
  * SUCH DAMAGE.
  *
  *	@(#)socketvar.h	8.3 (Berkeley) 2/19/95
- * $FreeBSD: src/sys/sys/socketvar.h,v 1.55 2001/01/09 04:33:49 wollman Exp $
+ * $FreeBSD: src/sys/sys/socketvar.h,v 1.54 2000/12/31 10:23:24 phk Exp $
  */
 
 #ifndef _SYS_SOCKETVAR_H_
@@ -73,10 +73,10 @@
 	TAILQ_HEAD(, socket) so_incomp;	/* queue of partial unaccepted connections */
 	TAILQ_HEAD(, socket) so_comp;	/* queue of complete unaccepted connections */
 	TAILQ_ENTRY(socket) so_list;	/* list of unaccepted connections */
-	short	so_qlen;		/* number of unaccepted connections */
-	short	so_incqlen;		/* number of unaccepted incomplete
+	int	so_qlen;		/* number of unaccepted connections */
+	int	so_incqlen;		/* number of unaccepted incomplete
 					   connections */
-	short	so_qlimit;		/* max number queued connections */
+	int	so_qlimit;		/* max number queued connections */
 	short	so_timeo;		/* connection timeout */
 	u_short	so_error;		/* error affecting connection */
 	struct  sigio *so_sigio;	/* information for async I/O or
@@ -153,9 +153,9 @@
 	caddr_t	so_pcb;		/* another convenient handle */
 	int	xso_protocol;
 	int	xso_family;
-	short	so_qlen;
-	short	so_incqlen;
-	short	so_qlimit;
+	int	so_qlen;
+	int	so_incqlen;
+	int	so_qlimit;
 	short	so_timeo;
 	u_short	so_error;
 	pid_t	so_pgid;

C)
Index: uipc_socket.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/uipc_socket.c,v
retrieving revision 1.87
diff -u -r1.87 uipc_socket.c
--- uipc_socket.c	2001/01/21 22:23:10	1.87
+++ uipc_socket.c	2001/02/11 09:41:56
@@ -89,8 +89,31 @@
 SYSCTL_DECL(_kern_ipc);
 
 static int somaxconn = SOMAXCONN;
-SYSCTL_INT(_kern_ipc, KIPC_SOMAXCONN, somaxconn, CTLFLAG_RW,
-    &somaxconn, 0, "Maximum pending socket connection queue size");
+
+/*
+ * since sockets have a short for queue len, don't allow
+ * sysadmins to outsmart themselves and overflow somaxconn
+ */
+static int
+sysctl_handle_somaxconn(SYSCTL_HANDLER_ARGS)
+{
+	int error, newval;
+	short trunc;
+
+	newval = somaxconn;
+	error = sysctl_handle_int(oidp, &newval, sizeof(newval), req);
+	if (error == 0 && req->newptr != NULL) {
+		trunc = newval;
+		if (trunc <= 0)
+			return (EINVAL);
+		somaxconn = newval;
+	}
+	return (error);
+}
+
+SYSCTL_PROC(_kern_ipc, KIPC_SOMAXCONN, somaxconn, CTLFLAG_RW,
+	0, sizeof(somaxconn), sysctl_handle_somaxconn, "I",
+	"Maximum pending socket connection queue size");
 
 /*
  * Socket operation routines.

-- 
-Alfred Perlstein - [bright@wintelcom.net|alfred@freebsd.org]
"I have the heart of a child; I keep it in a jar on my desk."


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-net" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010211015516.J3274>