Index: usr.bin/sockstat/sockstat.1 =================================================================== --- usr.bin/sockstat/sockstat.1 +++ usr.bin/sockstat/sockstat.1 @@ -27,7 +27,7 @@ .\" .\" $FreeBSD$ .\" -.Dd July 3, 2018 +.Dd April 14, 2020 .Dt SOCKSTAT 1 .Os .Sh NAME @@ -36,6 +36,7 @@ .Sh SYNOPSIS .Nm .Op Fl 46cLlSsUuvw +.Op Fl J Ar jid .Op Fl j Ar jid .Op Fl p Ar ports .Op Fl P Ar protocols @@ -58,6 +59,9 @@ (IPv6) sockets. .It Fl c Show connected sockets. +.It Fl J Ar jail +Attach to the specified jail ID or name. +This is useful for inspecting VNET jails, which have their own network stack. .It Fl j Ar jail Show only sockets belonging to the specified jail ID or name. .It Fl L Index: usr.bin/sockstat/sockstat.c =================================================================== --- usr.bin/sockstat/sockstat.c +++ usr.bin/sockstat/sockstat.c @@ -37,6 +37,7 @@ #include #include #include +#include #include #define _WANT_UNPCB @@ -74,6 +75,7 @@ static int opt_4; /* Show IPv4 sockets */ static int opt_6; /* Show IPv6 sockets */ static int opt_c; /* Show connected sockets */ +static int opt_J; /* Attach to 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; /* Show listening sockets */ @@ -1251,8 +1253,8 @@ int protos_defined = -1; int o, i; - opt_j = -1; - while ((o = getopt(argc, argv, "46cj:Llp:P:qSsUuvw")) != -1) + opt_J = opt_j = -1; + while ((o = getopt(argc, argv, "46cJ:j:Llp:P:qSsUuvw")) != -1) switch (o) { case '4': opt_4 = 1; @@ -1263,6 +1265,11 @@ case 'c': opt_c = 1; break; + case 'J': + opt_J = jail_getid(optarg); + if (opt_J < 0) + errx(1, "%s", jail_errmsg); + break; case 'j': opt_j = jail_getid(optarg); if (opt_j < 0) @@ -1310,6 +1317,9 @@ if (argc > 0) usage(); + + if (opt_J >= 0 && jail_attach(opt_J) != 0) + errx(1, "%s", jail_errmsg); if ((!opt_4 && !opt_6) && protos_defined != -1) opt_4 = opt_6 = 1;