diff --git a/sys/netinet/igmp.c b/sys/netinet/igmp.c index 77be25b92fe1..6e485ad79b86 100644 --- a/sys/netinet/igmp.c +++ b/sys/netinet/igmp.c @@ -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; diff --git a/sys/netinet/ip_icmp.c b/sys/netinet/ip_icmp.c index 7e8c722cd821..4b20dd0dd6db 100644 --- a/sys/netinet/ip_icmp.c +++ b/sys/netinet/ip_icmp.c @@ -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; diff --git a/sys/netinet/ip_input.c b/sys/netinet/ip_input.c index 3cf13cf0e6e9..2cc3fd644f95 100644 --- a/sys/netinet/ip_input.c +++ b/sys/netinet/ip_input.c @@ -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 */ diff --git a/sys/netinet/tcp_input.c b/sys/netinet/tcp_input.c index 225e6822a779..babf03fd0ce5 100644 --- a/sys/netinet/tcp_input.c +++ b/sys/netinet/tcp_input.c @@ -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; diff --git a/sys/netinet/tcp_reass.c b/sys/netinet/tcp_reass.c index 225e6822a779..babf03fd0ce5 100644 --- a/sys/netinet/tcp_reass.c +++ b/sys/netinet/tcp_reass.c @@ -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; diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index d546b1f30917..d388538414ca 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -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 }; diff --git a/usr.bin/netstat/inet.c b/usr.bin/netstat/inet.c index 723ec5b09925..594ab7f89b58 100644 --- a/usr.bin/netstat/inet.c +++ b/usr.bin/netstat/inet.c @@ -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; } diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c index 15736f90be2c..d2417de78a5c 100644 --- a/usr.bin/netstat/main.c +++ b/usr.bin/netstat/main.c @@ -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(); diff --git a/usr.bin/netstat/netstat.1 b/usr.bin/netstat/netstat.1 index 667c29f211ad..920962873100 100644 --- a/usr.bin/netstat/netstat.1 +++ b/usr.bin/netstat/netstat.1 @@ -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 diff --git a/usr.bin/netstat/netstat.h b/usr.bin/netstat/netstat.h index fffcfd64a197..f4411e6f5dc3 100644 --- a/usr.bin/netstat/netstat.h +++ b/usr.bin/netstat/netstat.h @@ -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 */