sockstat: add -i to display inp_gencnt
The inp_gencnt will be used to identify a TCP endpoint by an upcoming command line tool to set TCP socket options. Reviewed by: rscheff MFC after: 1 week Sponsored by: Netflix, Inc. Differential Revision: https://reviews.freebsd.org/D34137
This commit is contained in:
parent
21a37c3cc6
commit
5f64777a4f
@ -27,7 +27,7 @@
|
|||||||
.\"
|
.\"
|
||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd November 11, 2021
|
.Dd February 2, 2022
|
||||||
.Dt SOCKSTAT 1
|
.Dt SOCKSTAT 1
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@ -35,7 +35,7 @@
|
|||||||
.Nd list open sockets
|
.Nd list open sockets
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.Nm
|
.Nm
|
||||||
.Op Fl 46CcLlnqSsUuvw
|
.Op Fl 46CciLlnqSsUuvw
|
||||||
.Op Fl j Ar jail
|
.Op Fl j Ar jail
|
||||||
.Op Fl p Ar ports
|
.Op Fl p Ar ports
|
||||||
.Op Fl P Ar protocols
|
.Op Fl P Ar protocols
|
||||||
@ -61,6 +61,9 @@ Display the congestion control module, if applicable.
|
|||||||
This is currently only implemented for TCP.
|
This is currently only implemented for TCP.
|
||||||
.It Fl c
|
.It Fl c
|
||||||
Show connected sockets.
|
Show connected sockets.
|
||||||
|
.It Fl i
|
||||||
|
Display the
|
||||||
|
.Dv inp_gencnt .
|
||||||
.It Fl j Ar jail
|
.It Fl j Ar jail
|
||||||
Show only sockets belonging to the specified jail ID or name.
|
Show only sockets belonging to the specified jail ID or name.
|
||||||
.It Fl L
|
.It Fl L
|
||||||
@ -160,6 +163,10 @@ if the endpoint could not be determined.
|
|||||||
(Internet sockets only)
|
(Internet sockets only)
|
||||||
The address the foreign end of the socket is bound to (see
|
The address the foreign end of the socket is bound to (see
|
||||||
.Xr getpeername 2 ) .
|
.Xr getpeername 2 ) .
|
||||||
|
.It Li ID
|
||||||
|
The inp_gencnt if
|
||||||
|
.Fl i
|
||||||
|
is specified (only for TCP or UDP).
|
||||||
.It Li ENCAPS
|
.It Li ENCAPS
|
||||||
The remote UDP encapsulation port number if
|
The remote UDP encapsulation port number if
|
||||||
.Fl U
|
.Fl U
|
||||||
|
@ -59,6 +59,7 @@ __FBSDID("$FreeBSD$");
|
|||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <inttypes.h>
|
||||||
#include <jail.h>
|
#include <jail.h>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
@ -83,6 +84,7 @@ static int opt_4; /* Show IPv4 sockets */
|
|||||||
static int opt_6; /* Show IPv6 sockets */
|
static int opt_6; /* Show IPv6 sockets */
|
||||||
static int opt_C; /* Show congestion control */
|
static int opt_C; /* Show congestion control */
|
||||||
static int opt_c; /* Show connected sockets */
|
static int opt_c; /* Show connected sockets */
|
||||||
|
static int opt_i; /* Show inp_gencnt */
|
||||||
static int opt_j; /* Show specified jail */
|
static int opt_j; /* Show specified jail */
|
||||||
static int opt_L; /* Don't show IPv4 or IPv6 loopback sockets */
|
static int opt_L; /* Don't show IPv4 or IPv6 loopback sockets */
|
||||||
static int opt_l; /* Show listening sockets */
|
static int opt_l; /* Show listening sockets */
|
||||||
@ -120,6 +122,7 @@ struct addr {
|
|||||||
struct sock {
|
struct sock {
|
||||||
kvaddr_t socket;
|
kvaddr_t socket;
|
||||||
kvaddr_t pcb;
|
kvaddr_t pcb;
|
||||||
|
uint64_t inp_gencnt;
|
||||||
int shown;
|
int shown;
|
||||||
int vflag;
|
int vflag;
|
||||||
int family;
|
int family;
|
||||||
@ -713,6 +716,7 @@ gather_inet(int proto)
|
|||||||
err(1, "malloc()");
|
err(1, "malloc()");
|
||||||
sock->socket = so->xso_so;
|
sock->socket = so->xso_so;
|
||||||
sock->proto = proto;
|
sock->proto = proto;
|
||||||
|
sock->inp_gencnt = xip->inp_gencnt;
|
||||||
if (xip->inp_vflag & INP_IPV4) {
|
if (xip->inp_vflag & INP_IPV4) {
|
||||||
sock->family = AF_INET;
|
sock->family = AF_INET;
|
||||||
sockaddr(&laddr->address, sock->family,
|
sockaddr(&laddr->address, sock->family,
|
||||||
@ -1107,6 +1111,15 @@ displaysock(struct sock *s, int pos)
|
|||||||
default:
|
default:
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
if (opt_i) {
|
||||||
|
if (s->proto == IPPROTO_TCP ||
|
||||||
|
s->proto == IPPROTO_UDP) {
|
||||||
|
while (pos < offset)
|
||||||
|
pos += xprintf(" ");
|
||||||
|
pos += xprintf("%" PRIu64, s->inp_gencnt);
|
||||||
|
}
|
||||||
|
offset += 9;
|
||||||
|
}
|
||||||
if (opt_U) {
|
if (opt_U) {
|
||||||
if (faddr != NULL &&
|
if (faddr != NULL &&
|
||||||
((s->proto == IPPROTO_SCTP &&
|
((s->proto == IPPROTO_SCTP &&
|
||||||
@ -1204,6 +1217,8 @@ display(void)
|
|||||||
"USER", "COMMAND", "PID", "FD", "PROTO",
|
"USER", "COMMAND", "PID", "FD", "PROTO",
|
||||||
opt_w ? 45 : 21, "LOCAL ADDRESS",
|
opt_w ? 45 : 21, "LOCAL ADDRESS",
|
||||||
opt_w ? 45 : 21, "FOREIGN ADDRESS");
|
opt_w ? 45 : 21, "FOREIGN ADDRESS");
|
||||||
|
if (opt_i)
|
||||||
|
printf(" %-8s", "ID");
|
||||||
if (opt_U)
|
if (opt_U)
|
||||||
printf(" %-6s", "ENCAPS");
|
printf(" %-6s", "ENCAPS");
|
||||||
if (opt_s) {
|
if (opt_s) {
|
||||||
@ -1324,7 +1339,7 @@ static void
|
|||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"usage: sockstat [-46cLlSsUuvw] [-j jid] [-p ports] [-P protocols]\n");
|
"usage: sockstat [-46ciLlSsUuvw] [-j jid] [-p ports] [-P protocols]\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1339,7 +1354,7 @@ main(int argc, char *argv[])
|
|||||||
int o, i;
|
int o, i;
|
||||||
|
|
||||||
opt_j = -1;
|
opt_j = -1;
|
||||||
while ((o = getopt(argc, argv, "46Ccj:Llnp:P:qSsUuvw")) != -1)
|
while ((o = getopt(argc, argv, "46Ccij:Llnp:P:qSsUuvw")) != -1)
|
||||||
switch (o) {
|
switch (o) {
|
||||||
case '4':
|
case '4':
|
||||||
opt_4 = 1;
|
opt_4 = 1;
|
||||||
@ -1353,6 +1368,9 @@ main(int argc, char *argv[])
|
|||||||
case 'c':
|
case 'c':
|
||||||
opt_c = 1;
|
opt_c = 1;
|
||||||
break;
|
break;
|
||||||
|
case 'i':
|
||||||
|
opt_i = 1;
|
||||||
|
break;
|
||||||
case 'j':
|
case 'j':
|
||||||
opt_j = jail_getid(optarg);
|
opt_j = jail_getid(optarg);
|
||||||
if (opt_j < 0)
|
if (opt_j < 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user