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
This commit is contained in:
Michael Tuexen 2020-09-13 09:12:25 +00:00
parent 42d7560796
commit 2ac089d0e6
2 changed files with 37 additions and 9 deletions

View File

@ -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
@ -171,6 +174,10 @@ is specified (only for SCTP or TCP).
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
If a socket is associated with more than one file descriptor,

View File

@ -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,11 +1133,23 @@ 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)
@ -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,7 +1304,7 @@ 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;
@ -1294,6 +1312,9 @@ main(int argc, char *argv[])
case '6':
opt_6 = 1;
break;
case 'C':
opt_C = 1;
break;
case 'c':
opt_c = 1;
break;