From owner-svn-src-stable@freebsd.org Sat Oct 24 17:47:45 2020 Return-Path: Delivered-To: svn-src-stable@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 6281C44FE4A; Sat, 24 Oct 2020 17:47:45 +0000 (UTC) (envelope-from rscheff@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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 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 4CJT8K1xYPz3cJZ; Sat, 24 Oct 2020 17:47:45 +0000 (UTC) (envelope-from rscheff@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 225F11C3BF; Sat, 24 Oct 2020 17:47:45 +0000 (UTC) (envelope-from rscheff@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 09OHliDv050091; Sat, 24 Oct 2020 17:47:44 GMT (envelope-from rscheff@FreeBSD.org) Received: (from rscheff@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 09OHlhPB050085; Sat, 24 Oct 2020 17:47:43 GMT (envelope-from rscheff@FreeBSD.org) Message-Id: <202010241747.09OHlhPB050085@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: rscheff set sender to rscheff@FreeBSD.org using -f From: Richard Scheffenegger Date: Sat, 24 Oct 2020 17:47:43 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r367015 - in stable/12: sys/netinet usr.bin/netstat X-SVN-Group: stable-12 X-SVN-Commit-Author: rscheff X-SVN-Commit-Paths: in stable/12: sys/netinet usr.bin/netstat X-SVN-Commit-Revision: 367015 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 24 Oct 2020 17:47:45 -0000 Author: rscheff Date: Sat Oct 24 17:47:43 2020 New Revision: 367015 URL: https://svnweb.freebsd.org/changeset/base/367015 Log: MFC r366566;r366567: Extend netstat to display TCP stack and detailed congestion state Upstreaming the "-c" option used to show detailed per-connection congestion control state for TCP sessions. This is one summary patch, which adds the relevant variables into xtcpcb. As previous "spare" space is used, these changes are ABI compatible (an older version of netstat will simply not show the newly available data from newer kernels, and a newer version of netstat will only show zeroed data querying older kernels. Reviewed by: tuexen MFC after: 2 weeks Sponsored by: NetApp, Inc. Differential Revision: https://reviews.freebsd.org/D26518 Modified: stable/12/sys/netinet/tcp_subr.c stable/12/sys/netinet/tcp_var.h stable/12/usr.bin/netstat/inet.c stable/12/usr.bin/netstat/main.c stable/12/usr.bin/netstat/netstat.1 stable/12/usr.bin/netstat/netstat.h Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/netinet/tcp_subr.c ============================================================================== --- stable/12/sys/netinet/tcp_subr.c Sat Oct 24 17:11:45 2020 (r367014) +++ stable/12/sys/netinet/tcp_subr.c Sat Oct 24 17:47:43 2020 (r367015) @@ -3248,6 +3248,12 @@ tcp_inptoxtp(const struct inpcb *inp, struct xtcpcb *x xt->t_sndzerowin = tp->t_sndzerowin; xt->t_sndrexmitpack = tp->t_sndrexmitpack; xt->t_rcvoopack = tp->t_rcvoopack; + xt->t_rcv_wnd = tp->rcv_wnd; + xt->t_snd_wnd = tp->snd_wnd; + xt->t_snd_cwnd = tp->snd_cwnd; + xt->t_snd_ssthresh = tp->snd_ssthresh; + xt->t_maxseg = tp->t_maxseg; + xt->xt_ecn = (tp->t_flags & TF_ECN_PERMIT) ? 1 : 0; now = getsbinuptime(); #define COPYTIMER(ttt) do { \ Modified: stable/12/sys/netinet/tcp_var.h ============================================================================== --- stable/12/sys/netinet/tcp_var.h Sat Oct 24 17:11:45 2020 (r367014) +++ stable/12/sys/netinet/tcp_var.h Sat Oct 24 17:47:43 2020 (r367015) @@ -710,7 +710,13 @@ struct xtcpcb { int32_t tt_2msl; /* (s) */ int32_t tt_delack; /* (s) */ int32_t t_logstate; /* (3) */ - int32_t spare32[32]; + uint32_t t_snd_cwnd; /* (s) */ + uint32_t t_snd_ssthresh; /* (s) */ + uint32_t t_maxseg; /* (s) */ + uint32_t t_rcv_wnd; /* (s) */ + uint32_t t_snd_wnd; /* (s) */ + uint32_t xt_ecn; /* (s) */ + int32_t spare32[26]; } __aligned(8); #ifdef _KERNEL Modified: stable/12/usr.bin/netstat/inet.c ============================================================================== --- stable/12/usr.bin/netstat/inet.c Sat Oct 24 17:11:45 2020 (r367014) +++ stable/12/usr.bin/netstat/inet.c Sat Oct 24 17:47:43 2020 (r367015) @@ -85,6 +85,8 @@ __FBSDID("$FreeBSD$"); #include "netstat.h" #include "nl_defs.h" +#define max(a, b) (((a) > (b)) ? (a) : (b)) + #ifdef INET static void inetprint(const char *, struct in_addr *, int, const char *, int, const int); @@ -204,6 +206,7 @@ protopr(u_long off, const char *name, int af1, int pro struct xinpcb *inp; struct xinpgen *xig, *oxig; struct xsocket *so; + int fnamelen, cnamelen; istcp = 0; switch (proto) { @@ -236,6 +239,28 @@ protopr(u_long off, const char *name, int af1, int pro if (!pcblist_sysctl(proto, name, &buf)) return; + if (cflag || Cflag) { + fnamelen = strlen("Stack"); + cnamelen = strlen("CC"); + oxig = xig = (struct xinpgen *)buf; + for (xig = (struct xinpgen*)((char *)xig + xig->xig_len); + xig->xig_len > sizeof(struct xinpgen); + xig = (struct xinpgen *)((char *)xig + xig->xig_len)) { + if (istcp) { + tp = (struct xtcpcb *)xig; + inp = &tp->xt_inp; + } else { + continue; + } + if (so->xso_protocol != proto) + continue; + if (inp->inp_gencnt > oxig->xig_gen) + continue; + fnamelen = max(fnamelen, (int)strlen(tp->xt_stack)); + cnamelen = max(cnamelen, (int)strlen(tp->xt_cc)); + } + } + oxig = xig = (struct xinpgen *)buf; for (xig = (struct xinpgen *)((char *)xig + xig->xig_len); xig->xig_len > sizeof(struct xinpgen); @@ -341,9 +366,19 @@ protopr(u_long off, const char *name, int af1, int pro xo_emit(" {T:/%8.8s} {T:/%5.5s}", "flowid", "ftype"); } + if (cflag) { + xo_emit(" {T:/%-*.*s}", + fnamelen, fnamelen, "Stack"); + } if (Cflag) - xo_emit(" {T:/%-*.*s}", TCP_CA_NAME_MAX, - TCP_CA_NAME_MAX, "CC"); + xo_emit(" {T:/%-*.*s} {T:/%10.10s}" + " {T:/%10.10s} {T:/%5.5s}" + " {T:/%3.3s}", cnamelen, + cnamelen, "CC", + "cwin", + "ssthresh", + "MSS", + "ECN"); if (Pflag) xo_emit(" {T:/%s}", "Log ID"); xo_emit("\n"); @@ -518,9 +553,24 @@ protopr(u_long off, const char *name, int af1, int pro inp->inp_flowtype); } if (istcp) { + if (cflag) + xo_emit(" {:stack/%-*.*s}", + + fnamelen, fnamelen, tp->xt_stack); if (Cflag) - xo_emit(" {:cc/%-*.*s}", TCP_CA_NAME_MAX, - TCP_CA_NAME_MAX, tp->xt_cc); + xo_emit(" {:cc/%-*.*s}" + " {:snd-cwnd/%10lu}" + " {:snd-ssthresh/%10lu}" + " {:t-maxseg/%5u} {:ecn/%3s}", + cnamelen, cnamelen, tp->xt_cc, + tp->t_snd_cwnd, tp->t_snd_ssthresh, + tp->t_maxseg, + (tp->t_state >= TCPS_ESTABLISHED ? + (tp->xt_ecn > 0 ? + (tp->xt_ecn == 1 ? + "ecn" : "ace") + : "off") + : "n/a")); if (Pflag) xo_emit(" {:log-id/%s}", tp->xt_logid[0] == '\0' ? Modified: stable/12/usr.bin/netstat/main.c ============================================================================== --- stable/12/usr.bin/netstat/main.c Sat Oct 24 17:11:45 2020 (r367014) +++ stable/12/usr.bin/netstat/main.c Sat Oct 24 17:47:43 2020 (r367015) @@ -205,7 +205,8 @@ int Aflag; /* show addresses of protocol control bloc int aflag; /* show all sockets (including servers) */ static int Bflag; /* show information about bpf consumers */ int bflag; /* show i/f total bytes in/out */ -int Cflag; /* show congestion control */ +int cflag; /* show TCP congestion control stack */ +int Cflag; /* show congestion control algo and vars */ int dflag; /* show i/f dropped packets */ int gflag; /* show group (multicast) routing or stats */ int hflag; /* show counters in human readable format */ @@ -249,7 +250,7 @@ main(int argc, char *argv[]) if (argc < 0) exit(EXIT_FAILURE); - while ((ch = getopt(argc, argv, "46AaBbCdF:f:ghI:iLlM:mN:nPp:Qq:RrSTsuWw:xz")) + while ((ch = getopt(argc, argv, "46AaBbCcdF:f:ghI:iLlM:mN:nPp:Qq:RrSTsuWw:xz")) != -1) switch(ch) { case '4': @@ -278,6 +279,9 @@ main(int argc, char *argv[]) case 'b': bflag = 1; break; + case 'c': + cflag = 1; + break; case 'C': Cflag = 1; break; @@ -862,7 +866,7 @@ static void usage(void) { (void)xo_error("%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n", -"usage: netstat [-46AaLnRSTWx] [-f protocol_family | -p protocol]\n" +"usage: netstat [-46AaCcLnRSTWx] [-f protocol_family | -p protocol]\n" " [-M core] [-N system]", " netstat -i | -I interface [-46abdhnW] [-f address_family]\n" " [-M core] [-N system]", Modified: stable/12/usr.bin/netstat/netstat.1 ============================================================================== --- stable/12/usr.bin/netstat/netstat.1 Sat Oct 24 17:11:45 2020 (r367014) +++ stable/12/usr.bin/netstat/netstat.1 Sat Oct 24 17:47:43 2020 (r367015) @@ -28,7 +28,7 @@ .\" @(#)netstat.1 8.8 (Berkeley) 4/18/94 .\" $FreeBSD$ .\" -.Dd September 13, 2020 +.Dd September 25, 2020 .Dt NETSTAT 1 .Os .Sh NAME @@ -172,8 +172,10 @@ associated with a socket; used for debugging. .It Fl a Show the state of all sockets; normally sockets used by server processes are not shown. +.It Fl c +Show the used TCP stack for each session. .It Fl C -Show the congestion control of TCP sockets. +Show the congestion control algorithm and diagnostic information of TCP sockets. .It Fl L Show the size of the various listen queues. The first count shows the number of unaccepted connections, Modified: stable/12/usr.bin/netstat/netstat.h ============================================================================== --- stable/12/usr.bin/netstat/netstat.h Sat Oct 24 17:11:45 2020 (r367014) +++ stable/12/usr.bin/netstat/netstat.h Sat Oct 24 17:47:43 2020 (r367015) @@ -41,7 +41,8 @@ extern int Aflag; /* show addresses of protocol control block */ extern int aflag; /* show all sockets (including servers) */ extern int bflag; /* show i/f total bytes in/out */ -extern int Cflag; /* show congestion control */ +extern int cflag; /* show congestion control stats */ +extern int Cflag; /* show congestion control algo and stack */ extern int dflag; /* show i/f dropped packets */ extern int gflag; /* show group (multicast) routing or stats */ extern int hflag; /* show counters in human readable format */