aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Grosbein <eugen@FreeBSD.org>2023-04-30 20:14:30 +0000
committerEugene Grosbein <eugen@FreeBSD.org>2023-05-30 09:05:46 +0000
commit773c91ccc8922c047d3632ae5849cd824992c313 (patch)
tree97a4d348e700677dfc2b801cb898f2499f5b0bcf
parent097e721ff4f2be42f1f2705edf6febcf9121d774 (diff)
downloadsrc-773c91ccc892.tar.gz
src-773c91ccc892.zip
MFC: listen(2): improve administrator control over logging
As documented in listen.2 manual page, the kernel emits a LOG_DEBUG syslog message if a socket listen queue overflows. For some appliances, it may be desirable to change the priority to some higher value like LOG_INFO while keeping other debugging suppressed. OTOH there are cases when such overflows are normal and expected. Then it may be desirable to suppress overflow logging altogether, so that dmesg buffer is not flooded over long run. In addition to existing sysctl kern.ipc.sooverinterval, introduce new sysctl kern.ipc.sooverprio that defaults to 7 (LOG_DEBUG) to preserve current behavior. It may be changed to any value in a range of 0..7 for corresponding priority or to -1 to suppress logging. Document it in the listen.2 manual page. (cherry picked from commit 4824d788725987bccff53dec8c103cbac455b3ed)
-rw-r--r--lib/libc/sys/listen.215
-rw-r--r--sys/kern/uipc_socket.c40
2 files changed, 46 insertions, 9 deletions
diff --git a/lib/libc/sys/listen.2 b/lib/libc/sys/listen.2
index 4d0962fd412c..076163548b72 100644
--- a/lib/libc/sys/listen.2
+++ b/lib/libc/sys/listen.2
@@ -28,7 +28,7 @@
.\" From: @(#)listen.2 8.2 (Berkeley) 12/11/93
.\" $FreeBSD$
.\"
-.Dd April 14, 2020
+.Dd April 30, 2023
.Dt LISTEN 2
.Os
.Sh NAME
@@ -111,10 +111,20 @@ or less than zero is specified,
is silently forced to
.Va kern.ipc.soacceptqueue .
.Pp
-If the listen queue overflows, the kernel will emit a LOG_DEBUG syslog message.
+If the listen queue overflows, the kernel will emit a syslog message
+using default priority LOG_DEBUG (7).
The
.Xr sysctl 3
MIB variable
+.Va kern.ipc.sooverprio
+may be used to change this priority to any value in a range of 0..7
+(LOG_EMERG..LOG_DEBUG).
+See
+.Xr syslog 3
+for details.
+It may be set to -1 to disable these messages.
+.Pp
+The variable
.Va kern.ipc.sooverinterval
specifies a per-socket limit on how often the kernel will emit these messages.
.Sh INTERACTION WITH ACCEPT FILTERS
@@ -164,6 +174,7 @@ The socket is not of a type that supports the operation
.Xr connect 2 ,
.Xr socket 2 ,
.Xr sysctl 3 ,
+.Xr syslog 3 ,
.Xr sysctl 8 ,
.Xr accept_filter 9
.Sh HISTORY
diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c
index 5b1e572d786f..32ad819be81b 100644
--- a/sys/kern/uipc_socket.c
+++ b/sys/kern/uipc_socket.c
@@ -574,6 +574,10 @@ SYSCTL_INT(_regression, OID_AUTO, sonewconn_earlytest, CTLFLAG_RW,
&regression_sonewconn_earlytest, 0, "Perform early sonewconn limit test");
#endif
+static int sooverprio = LOG_DEBUG;
+SYSCTL_INT(_kern_ipc, OID_AUTO, sooverprio, CTLFLAG_RW,
+ &sooverprio, 0, "Log priority for listen socket overflows: 0..7 or -1 to disable");
+
static struct timeval overinterval = { 60, 0 };
SYSCTL_TIMEVAL_SEC(_kern_ipc, OID_AUTO, sooverinterval, CTLFLAG_RW,
&overinterval,
@@ -612,7 +616,8 @@ sonewconn(struct socket *head, int connstatus)
if (over) {
#endif
head->sol_overcount++;
- dolog = !!ratecheck(&head->sol_lastover, &overinterval);
+ dolog = (sooverprio >= 0) &&
+ !!ratecheck(&head->sol_lastover, &overinterval);
/*
* If we're going to log, copy the overflow count and queue
@@ -694,12 +699,33 @@ sonewconn(struct socket *head, int connstatus)
}
KASSERT(sbuf_len(&descrsb) > 0,
("%s: sbuf creation failed", __func__));
- log(LOG_DEBUG,
- "%s: pcb %p (%s): Listen queue overflow: "
- "%i already in queue awaiting acceptance "
- "(%d occurrences)\n",
- __func__, head->so_pcb, sbuf_data(&descrsb),
- qlen, overcount);
+ /*
+ * Preserve the historic listen queue overflow log
+ * message, that starts with "sonewconn:". It has
+ * been known to sysadmins for years and also test
+ * sys/kern/sonewconn_overflow checks for it.
+ */
+ if (head->so_cred == 0) {
+ log(LOG_PRI(sooverprio),
+ "sonewconn: pcb %p (%s): "
+ "Listen queue overflow: %i already in "
+ "queue awaiting acceptance (%d "
+ "occurrences)\n", head->so_pcb,
+ sbuf_data(&descrsb),
+ qlen, overcount);
+ } else {
+ log(LOG_PRI(sooverprio),
+ "sonewconn: pcb %p (%s): "
+ "Listen queue overflow: "
+ "%i already in queue awaiting acceptance "
+ "(%d occurrences), euid %d, rgid %d, jail %s\n",
+ head->so_pcb, sbuf_data(&descrsb), qlen,
+ overcount, head->so_cred->cr_uid,
+ head->so_cred->cr_rgid,
+ head->so_cred->cr_prison ?
+ head->so_cred->cr_prison->pr_name :
+ "not_jailed");
+ }
sbuf_delete(&descrsb);
overcount = 0;