From d084122f3697505f1422b27c5d64204b1bcf66d4 Mon Sep 17 00:00:00 2001 From: glebius Date: Mon, 24 Jan 2005 12:20:21 +0000 Subject: [PATCH] - Convert so_qlen, so_incqlen, so_qlimit fields of struct socket from short to unsigned short. - Add SYSCTL_PROC() around somaxconn, not accepting values < 1 or > U_SHRTMAX. Before this change setting somaxconn to smth above 32767 and calling listen(fd, -1) lead to a socket, which doesn't accept connections at all. Reviewed by: rwatson Reported by: Igor Sysoev --- sys/kern/uipc_socket.c | 25 +++++++++++++++++++++++-- sys/sys/socketvar.h | 12 ++++++------ 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index e81166c5c35..a6bf3a19794 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -94,8 +94,11 @@ MALLOC_DEFINE(M_PCB, "pcb", "protocol control block"); 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"); +static int somaxconn_sysctl(SYSCTL_HANDLER_ARGS); +/* XXX: we dont have SYSCTL_USHORT */ +SYSCTL_PROC(_kern_ipc, KIPC_SOMAXCONN, somaxconn, CTLTYPE_UINT | CTLFLAG_RW, + 0, sizeof(int), somaxconn_sysctl, "I", "Maximum pending socket connection " + "queue size"); static int numopensockets; SYSCTL_INT(_kern_ipc, OID_AUTO, numopensockets, CTLFLAG_RD, &numopensockets, 0, "Number of open sockets"); @@ -2263,3 +2266,21 @@ socheckuid(struct socket *so, uid_t uid) return (0); return (EPERM); } + +static int +somaxconn_sysctl(SYSCTL_HANDLER_ARGS) +{ + int error; + int val; + + val = somaxconn; + error = sysctl_handle_int(oidp, &val, sizeof(int), req); + if (error || !req->newptr ) + return (error); + + if (val < 1 || val > USHRT_MAX) + return (EINVAL); + + somaxconn = val; + return (0); +} diff --git a/sys/sys/socketvar.h b/sys/sys/socketvar.h index 391ed3f7b80..5c889cc3abd 100644 --- a/sys/sys/socketvar.h +++ b/sys/sys/socketvar.h @@ -81,10 +81,10 @@ struct socket { TAILQ_HEAD(, socket) so_incomp; /* (e) queue of partial unaccepted connections */ TAILQ_HEAD(, socket) so_comp; /* (e) queue of complete unaccepted connections */ TAILQ_ENTRY(socket) so_list; /* (e) list of unaccepted connections */ - short so_qlen; /* (e) number of unaccepted connections */ - short so_incqlen; /* (e) number of unaccepted incomplete + u_short so_qlen; /* (e) number of unaccepted connections */ + u_short so_incqlen; /* (e) number of unaccepted incomplete connections */ - short so_qlimit; /* (e) max number queued connections */ + u_short so_qlimit; /* (e) max number queued connections */ short so_timeo; /* (g) connection timeout */ u_short so_error; /* (f) error affecting connection */ struct sigio *so_sigio; /* [sg] information for async I/O or @@ -235,9 +235,9 @@ struct xsocket { caddr_t so_pcb; /* another convenient handle */ int xso_protocol; int xso_family; - short so_qlen; - short so_incqlen; - short so_qlimit; + u_short so_qlen; + u_short so_incqlen; + u_short so_qlimit; short so_timeo; u_short so_error; pid_t so_pgid; -- 2.45.2