Add netstat(1) knob to reset net.inet.{ip|icmp|tcp|udp|igmp}.stats.
For example, ``netstat -s -p ip -z'' will show and reset IP stats. PR: bin/17338
This commit is contained in:
parent
6fe615f6bb
commit
c73d99b567
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=78667
@ -78,7 +78,7 @@ static struct router_info *
|
||||
|
||||
static struct igmpstat igmpstat;
|
||||
|
||||
SYSCTL_STRUCT(_net_inet_igmp, IGMPCTL_STATS, stats, CTLFLAG_RD,
|
||||
SYSCTL_STRUCT(_net_inet_igmp, IGMPCTL_STATS, stats, CTLFLAG_RW,
|
||||
&igmpstat, igmpstat, "");
|
||||
|
||||
static int igmp_timers_are_running;
|
||||
|
@ -76,7 +76,7 @@
|
||||
*/
|
||||
|
||||
static struct icmpstat icmpstat;
|
||||
SYSCTL_STRUCT(_net_inet_icmp, ICMPCTL_STATS, stats, CTLFLAG_RD,
|
||||
SYSCTL_STRUCT(_net_inet_icmp, ICMPCTL_STATS, stats, CTLFLAG_RW,
|
||||
&icmpstat, icmpstat, "");
|
||||
|
||||
static int icmpmaskrepl = 0;
|
||||
|
@ -163,7 +163,7 @@ SYSCTL_INT(_net_inet_ip, IPCTL_INTRQDROPS, intr_queue_drops, CTLFLAG_RD,
|
||||
&ipintrq.ifq_drops, 0, "Number of packets dropped from the IP input queue");
|
||||
|
||||
struct ipstat ipstat;
|
||||
SYSCTL_STRUCT(_net_inet_ip, IPCTL_STATS, stats, CTLFLAG_RD,
|
||||
SYSCTL_STRUCT(_net_inet_ip, IPCTL_STATS, stats, CTLFLAG_RW,
|
||||
&ipstat, ipstat, "IP statistics (struct ipstat, netinet/ip_var.h)");
|
||||
|
||||
/* Packet reassembly stuff */
|
||||
|
@ -105,7 +105,7 @@ tcp_seq tcp_iss;
|
||||
tcp_cc tcp_ccgen;
|
||||
|
||||
struct tcpstat tcpstat;
|
||||
SYSCTL_STRUCT(_net_inet_tcp, TCPCTL_STATS, stats, CTLFLAG_RD,
|
||||
SYSCTL_STRUCT(_net_inet_tcp, TCPCTL_STATS, stats, CTLFLAG_RW,
|
||||
&tcpstat , tcpstat, "TCP statistics (struct tcpstat, netinet/tcp_var.h)");
|
||||
|
||||
static int log_in_vain = 0;
|
||||
|
@ -105,7 +105,7 @@ tcp_seq tcp_iss;
|
||||
tcp_cc tcp_ccgen;
|
||||
|
||||
struct tcpstat tcpstat;
|
||||
SYSCTL_STRUCT(_net_inet_tcp, TCPCTL_STATS, stats, CTLFLAG_RD,
|
||||
SYSCTL_STRUCT(_net_inet_tcp, TCPCTL_STATS, stats, CTLFLAG_RW,
|
||||
&tcpstat , tcpstat, "TCP statistics (struct tcpstat, netinet/tcp_var.h)");
|
||||
|
||||
static int log_in_vain = 0;
|
||||
|
@ -108,7 +108,7 @@ struct inpcbinfo udbinfo;
|
||||
#endif
|
||||
|
||||
struct udpstat udpstat; /* from udp_var.h */
|
||||
SYSCTL_STRUCT(_net_inet_udp, UDPCTL_STATS, stats, CTLFLAG_RD,
|
||||
SYSCTL_STRUCT(_net_inet_udp, UDPCTL_STATS, stats, CTLFLAG_RW,
|
||||
&udpstat, udpstat, "UDP statistics (struct udpstat, netinet/udp_var.h)");
|
||||
|
||||
static struct sockaddr_in udp_in = { sizeof(udp_in), AF_INET };
|
||||
|
@ -348,10 +348,13 @@ protopr(u_long proto, /* for sysctl version we pass proto # */
|
||||
void
|
||||
tcp_stats(u_long off __unused, char *name, int af __unused)
|
||||
{
|
||||
struct tcpstat tcpstat;
|
||||
struct tcpstat tcpstat, zerostat;
|
||||
size_t len = sizeof tcpstat;
|
||||
|
||||
if (sysctlbyname("net.inet.tcp.stats", &tcpstat, &len, 0, 0) < 0) {
|
||||
if (zflag)
|
||||
memset(&zerostat, 0, len);
|
||||
if (sysctlbyname("net.inet.tcp.stats", &tcpstat, &len,
|
||||
zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
|
||||
warn("sysctl: net.inet.tcp.stats");
|
||||
return;
|
||||
}
|
||||
@ -446,11 +449,14 @@ tcp_stats(u_long off __unused, char *name, int af __unused)
|
||||
void
|
||||
udp_stats(u_long off __unused, char *name, int af __unused)
|
||||
{
|
||||
struct udpstat udpstat;
|
||||
struct udpstat udpstat, zerostat;
|
||||
size_t len = sizeof udpstat;
|
||||
u_long delivered;
|
||||
|
||||
if (sysctlbyname("net.inet.udp.stats", &udpstat, &len, 0, 0) < 0) {
|
||||
if (zflag)
|
||||
memset(&zerostat, 0, len);
|
||||
if (sysctlbyname("net.inet.udp.stats", &udpstat, &len,
|
||||
zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
|
||||
warn("sysctl: net.inet.udp.stats");
|
||||
return;
|
||||
}
|
||||
@ -497,10 +503,13 @@ udp_stats(u_long off __unused, char *name, int af __unused)
|
||||
void
|
||||
ip_stats(u_long off __unused, char *name, int af __unused)
|
||||
{
|
||||
struct ipstat ipstat;
|
||||
struct ipstat ipstat, zerostat;
|
||||
size_t len = sizeof ipstat;
|
||||
|
||||
if (sysctlbyname("net.inet.ip.stats", &ipstat, &len, 0, 0) < 0) {
|
||||
if (zflag)
|
||||
memset(&zerostat, 0, len);
|
||||
if (sysctlbyname("net.inet.ip.stats", &ipstat, &len,
|
||||
zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
|
||||
warn("sysctl: net.inet.ip.stats");
|
||||
return;
|
||||
}
|
||||
@ -577,7 +586,7 @@ static char *icmpnames[] = {
|
||||
void
|
||||
icmp_stats(u_long off __unused, char *name, int af __unused)
|
||||
{
|
||||
struct icmpstat icmpstat;
|
||||
struct icmpstat icmpstat, zerostat;
|
||||
int i, first;
|
||||
int mib[4]; /* CTL_NET + PF_INET + IPPROTO_ICMP + req */
|
||||
size_t len;
|
||||
@ -588,9 +597,13 @@ icmp_stats(u_long off __unused, char *name, int af __unused)
|
||||
mib[3] = ICMPCTL_STATS;
|
||||
|
||||
len = sizeof icmpstat;
|
||||
memset(&icmpstat, 0, len);
|
||||
if (sysctl(mib, 4, &icmpstat, &len, (void *)0, 0) < 0)
|
||||
return; /* XXX should complain, but not traditional */
|
||||
if (zflag)
|
||||
memset(&zerostat, 0, len);
|
||||
if (sysctl(mib, 4, &icmpstat, &len,
|
||||
zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
|
||||
warn("sysctl: net.inet.icmp.stats");
|
||||
return;
|
||||
}
|
||||
|
||||
printf("%s:\n", name);
|
||||
|
||||
@ -643,10 +656,13 @@ icmp_stats(u_long off __unused, char *name, int af __unused)
|
||||
void
|
||||
igmp_stats(u_long off __unused, char *name, int af __unused)
|
||||
{
|
||||
struct igmpstat igmpstat;
|
||||
struct igmpstat igmpstat, zerostat;
|
||||
size_t len = sizeof igmpstat;
|
||||
|
||||
if (sysctlbyname("net.inet.igmp.stats", &igmpstat, &len, 0, 0) < 0) {
|
||||
if (zflag)
|
||||
memset(&zerostat, 0, len);
|
||||
if (sysctlbyname("net.inet.igmp.stats", &igmpstat, &len,
|
||||
zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
|
||||
warn("sysctl: net.inet.igmp.stats");
|
||||
return;
|
||||
}
|
||||
|
@ -330,6 +330,7 @@ int rflag; /* show routing tables (or routing stats) */
|
||||
int sflag; /* show protocol statistics */
|
||||
int tflag; /* show i/f watchdog timers */
|
||||
int Wflag; /* wide display */
|
||||
int zflag; /* zero stats */
|
||||
|
||||
int interval; /* repeat interval for i/f stats */
|
||||
|
||||
@ -348,7 +349,7 @@ main(argc, argv)
|
||||
|
||||
af = AF_UNSPEC;
|
||||
|
||||
while ((ch = getopt(argc, argv, "Aabdf:gI:iLlM:mN:np:rSstuWw:")) != -1)
|
||||
while ((ch = getopt(argc, argv, "Aabdf:gI:iLlM:mN:np:rSstuWw:z")) != -1)
|
||||
switch(ch) {
|
||||
case 'A':
|
||||
Aflag = 1;
|
||||
@ -458,6 +459,9 @@ main(argc, argv)
|
||||
interval = atoi(optarg);
|
||||
iflag = 1;
|
||||
break;
|
||||
case 'z':
|
||||
zflag = 1;
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
usage();
|
||||
|
@ -57,6 +57,7 @@
|
||||
.Op Fl N Ar system
|
||||
.Nm
|
||||
.Fl s Op Fl s
|
||||
.Op Fl z
|
||||
.Op Fl f Ar address_family | Fl p Ar protocol
|
||||
.Op Fl M Ar core
|
||||
.Op Fl N Ar system
|
||||
@ -272,6 +273,8 @@ some fields to overflow.
|
||||
Show network interface statistics at intervals of
|
||||
.Ar wait
|
||||
seconds.
|
||||
.It Fl z
|
||||
Reset statistics.
|
||||
.El
|
||||
.Pp
|
||||
The default display, for active sockets, shows the local
|
||||
|
@ -51,6 +51,7 @@ extern int rflag; /* show routing tables (or routing stats) */
|
||||
extern int sflag; /* show protocol statistics */
|
||||
extern int tflag; /* show i/f watchdog timers */
|
||||
extern int Wflag; /* wide display */
|
||||
extern int zflag; /* zero stats */
|
||||
|
||||
extern int interval; /* repeat interval for i/f stats */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user