summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorru <ru@FreeBSD.org>2001-06-23 17:17:59 +0000
committerru <ru@FreeBSD.org>2001-06-23 17:17:59 +0000
commitf8e11dde2671e192fa12edbf3487f63e8e0ade6e (patch)
tree1118088749c1baef05d754645d1ad80a5646de4e
parentdb2094554ee872866a777f43b3a558c744e82e2f (diff)
downloadFreeBSD-src-f8e11dde2671e192fa12edbf3487f63e8e0ade6e.zip
FreeBSD-src-f8e11dde2671e192fa12edbf3487f63e8e0ade6e.tar.gz
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
-rw-r--r--sys/netinet/igmp.c2
-rw-r--r--sys/netinet/ip_icmp.c2
-rw-r--r--sys/netinet/ip_input.c2
-rw-r--r--sys/netinet/tcp_input.c2
-rw-r--r--sys/netinet/tcp_reass.c2
-rw-r--r--sys/netinet/udp_usrreq.c2
-rw-r--r--usr.bin/netstat/inet.c40
-rw-r--r--usr.bin/netstat/main.c6
-rw-r--r--usr.bin/netstat/netstat.13
-rw-r--r--usr.bin/netstat/netstat.h1
10 files changed, 43 insertions, 19 deletions
diff --git a/sys/netinet/igmp.c b/sys/netinet/igmp.c
index 77be25b..6e485ad 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 7e8c722..4b20dd0 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 3cf13cf..2cc3fd6 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 225e682..babf03f 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 225e682..babf03f 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 d546b1f..d388538 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 723ec5b..594ab7f 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 15736f9..d2417de 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 667c29f..9209628 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 fffcfd6..f4411e6 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 */
OpenPOWER on IntegriCloud