Author: tuexen Date: Sun Sep 13 09:12:25 2020 New Revision: 365687 URL: https://svnweb.freebsd.org/changeset/base/365687
Log: Add a -C option to sockstat to display the congestion control for TCP connections. Reviewed by: rscheff MFC after: 1 week Sponsored by: Netflix, Inc. Differential Revision: https://reviews.freebsd.org/D26413 Modified: head/usr.bin/sockstat/sockstat.1 head/usr.bin/sockstat/sockstat.c Modified: head/usr.bin/sockstat/sockstat.1 ============================================================================== --- head/usr.bin/sockstat/sockstat.1 Sun Sep 13 09:06:50 2020 (r365686) +++ head/usr.bin/sockstat/sockstat.1 Sun Sep 13 09:12:25 2020 (r365687) @@ -27,7 +27,7 @@ .\" .\" $FreeBSD$ .\" -.Dd June 13, 2020 +.Dd September 13, 2020 .Dt SOCKSTAT 1 .Os .Sh NAME @@ -35,7 +35,7 @@ .Nd list open sockets .Sh SYNOPSIS .Nm -.Op Fl 46cLlSsUuvw +.Op Fl 46CcLlSsUuvw .Op Fl j Ar jid .Op Fl p Ar ports .Op Fl P Ar protocols @@ -56,6 +56,9 @@ Show Show .Dv AF_INET6 (IPv6) sockets. +.It Fl C +Display the congestion control module, if applicable. +This is currently only implemented for TCP. .It Fl c Show connected sockets. .It Fl j Ar jail @@ -170,6 +173,10 @@ is specified (only for SCTP or TCP). .It Li STACK The protocol stack if .Fl S +is specified (only for TCP). +.It Li CC +The congestion control if +.Fl C is specified (only for TCP). .El .Pp Modified: head/usr.bin/sockstat/sockstat.c ============================================================================== --- head/usr.bin/sockstat/sockstat.c Sun Sep 13 09:06:50 2020 (r365686) +++ head/usr.bin/sockstat/sockstat.c Sun Sep 13 09:12:25 2020 (r365687) @@ -74,6 +74,7 @@ __FBSDID("$FreeBSD$"); static int opt_4; /* Show IPv4 sockets */ static int opt_6; /* Show IPv6 sockets */ +static int opt_C; /* Show congestion control */ static int opt_c; /* Show connected sockets */ static int opt_j; /* Show specified jail */ static int opt_L; /* Don't show IPv4 or IPv6 loopback sockets */ @@ -118,6 +119,7 @@ struct sock { int state; const char *protoname; char stack[TCP_FUNCTION_NAME_LEN_MAX]; + char cc[TCP_CA_NAME_MAX]; struct addr *laddr; struct addr *faddr; struct sock *next; @@ -716,6 +718,7 @@ gather_inet(int proto) sock->state = xtp->t_state; memcpy(sock->stack, xtp->xt_stack, TCP_FUNCTION_NAME_LEN_MAX); + memcpy(sock->cc, xtp->xt_cc, TCP_CA_NAME_MAX); } sock->protoname = protoname; hash = (int)((uintptr_t)sock->socket % HASHSIZE); @@ -1130,12 +1133,24 @@ displaysock(struct sock *s, int pos) } offset += 13; } - if (opt_S && s->proto == IPPROTO_TCP) { - while (pos < offset) - pos += xprintf(" "); - xprintf("%.*s", TCP_FUNCTION_NAME_LEN_MAX, - s->stack); + if (opt_S) { + if (s->proto == IPPROTO_TCP) { + while (pos < offset) + pos += xprintf(" "); + pos += xprintf("%.*s", + TCP_FUNCTION_NAME_LEN_MAX, + s->stack); + } + offset += TCP_FUNCTION_NAME_LEN_MAX + 1; } + if (opt_C) { + if (s->proto == IPPROTO_TCP) { + while (pos < offset) + pos += xprintf(" "); + xprintf("%.*s", TCP_CA_NAME_MAX, s->cc); + } + offset += TCP_CA_NAME_MAX + 1; + } } if (laddr != NULL) laddr = laddr->next; @@ -1170,7 +1185,10 @@ display(void) printf(" %-12s", "CONN STATE"); } if (opt_S) - printf(" %.*s", TCP_FUNCTION_NAME_LEN_MAX, "STACK"); + printf(" %-*.*s", TCP_FUNCTION_NAME_LEN_MAX, + TCP_FUNCTION_NAME_LEN_MAX, "STACK"); + if (opt_C) + printf(" %-.*s", TCP_CA_NAME_MAX, "CC"); printf("\n"); } setpassent(1); @@ -1286,13 +1304,16 @@ main(int argc, char *argv[]) int o, i; opt_j = -1; - while ((o = getopt(argc, argv, "46cj:Llp:P:qSsUuvw")) != -1) + while ((o = getopt(argc, argv, "46Ccj:Llp:P:qSsUuvw")) != -1) switch (o) { case '4': opt_4 = 1; break; case '6': opt_6 = 1; + break; + case 'C': + opt_C = 1; break; case 'c': opt_c = 1; _______________________________________________ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"