From owner-svn-src-head@freebsd.org Tue Apr 14 15:30:35 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id C26062C31F4; Tue, 14 Apr 2020 15:30:35 +0000 (UTC) (envelope-from jtl@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 491qF72VzJz4M0l; Tue, 14 Apr 2020 15:30:35 +0000 (UTC) (envelope-from jtl@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 5161375FE; Tue, 14 Apr 2020 15:30:35 +0000 (UTC) (envelope-from jtl@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 03EFUZvD056533; Tue, 14 Apr 2020 15:30:35 GMT (envelope-from jtl@FreeBSD.org) Received: (from jtl@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 03EFUZ5D056532; Tue, 14 Apr 2020 15:30:35 GMT (envelope-from jtl@FreeBSD.org) Message-Id: <202004141530.03EFUZ5D056532@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jtl set sender to jtl@FreeBSD.org using -f From: "Jonathan T. Looney" Date: Tue, 14 Apr 2020 15:30:35 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r359922 - head/sys/kern X-SVN-Group: head X-SVN-Commit-Author: jtl X-SVN-Commit-Paths: head/sys/kern X-SVN-Commit-Revision: 359922 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Apr 2020 15:30:35 -0000 Author: jtl Date: Tue Apr 14 15:30:34 2020 New Revision: 359922 URL: https://svnweb.freebsd.org/changeset/base/359922 Log: Print more detail as part of the sonewconn() overflow message. When a socket's listen queue overflows, sonewconn() emits a debug-level log message. These messages are sometimes useful to systems administrators in highlighting a process which is not keeping up with its listen queue. This commit attempts to enhance the usefulness of this message by printing more details about the socket's address. If all else fails, it will at least print the domain name of the socket. Reviewed by: bz, jhb, kbowling MFC after: 2 weeks Sponsored by: Netflix, Inc. Differential Revision: https://reviews.freebsd.org/D24272 Modified: head/sys/kern/uipc_socket.c Modified: head/sys/kern/uipc_socket.c ============================================================================== --- head/sys/kern/uipc_socket.c Tue Apr 14 15:27:24 2020 (r359921) +++ head/sys/kern/uipc_socket.c Tue Apr 14 15:30:34 2020 (r359922) @@ -130,6 +130,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -140,9 +141,12 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include +#include #include #include #include +#include #include #include @@ -587,8 +591,17 @@ sonewconn(struct socket *head, int connstatus) static struct timeval overinterval = { 60, 0 }; static int overcount; + struct sbuf descrsb; struct socket *so; u_int over; + int len; + const char localprefix[] = "local:"; + char descrbuf[SUNPATHLEN + sizeof(localprefix)]; +#if defined(INET6) + char addrbuf[INET6_ADDRSTRLEN]; +#elif defined(INET) + char addrbuf[INET_ADDRSTRLEN]; +#endif SOLISTEN_LOCK(head); over = (head->sol_qlen > 3 * head->sol_qlimit / 2); @@ -601,10 +614,80 @@ sonewconn(struct socket *head, int connstatus) overcount++; if (ratecheck(&lastover, &overinterval)) { - log(LOG_DEBUG, "%s: pcb %p: Listen queue overflow: " + /* + * Try to print something descriptive about the + * socket for the error message. + */ + sbuf_new(&descrsb, descrbuf, sizeof(descrbuf), + SBUF_FIXEDLEN); + switch (head->so_proto->pr_domain->dom_family) { +#if defined(INET) || defined(INET6) +#ifdef INET + case AF_INET: +#endif +#ifdef INET6 + case AF_INET6: + if (head->so_proto->pr_domain->dom_family == + AF_INET6 || + (sotoinpcb(head)->inp_inc.inc_flags & + INC_ISIPV6)) { + ip6_sprintf(addrbuf, + &sotoinpcb(head)->inp_inc.inc6_laddr); + sbuf_printf(&descrsb, "[%s]", addrbuf); + } else +#endif + { +#ifdef INET + inet_ntoa_r( + sotoinpcb(head)->inp_inc.inc_laddr, + addrbuf); + sbuf_cat(&descrsb, addrbuf); +#endif + } + sbuf_printf(&descrsb, ":%hu (proto %u)", + ntohs(sotoinpcb(head)->inp_inc.inc_lport), + head->so_proto->pr_protocol); + break; +#endif /* INET || INET6 */ + case AF_UNIX: + sbuf_cat(&descrsb, localprefix); + if (sotounpcb(head)->unp_addr != NULL) + len = + sotounpcb(head)->unp_addr->sun_len - + offsetof(struct sockaddr_un, + sun_path); + else + len = 0; + if (len > 0) + sbuf_bcat(&descrsb, + sotounpcb(head)->unp_addr->sun_path, + len); + else + sbuf_cat(&descrsb, "(unknown)"); + break; + } + + /* + * If we can't print something more specific, at least + * print the domain name. + */ + if (sbuf_finish(&descrsb) != 0 || + sbuf_len(&descrsb) <= 0) { + sbuf_clear(&descrsb); + sbuf_cat(&descrsb, + head->so_proto->pr_domain->dom_name ?: + "unknown"); + sbuf_finish(&descrsb); + } + 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, head->sol_qlen, overcount); + __func__, head->so_pcb, sbuf_data(&descrsb), + head->sol_qlen, overcount); + sbuf_delete(&descrsb); overcount = 0; }