diff options
author | 2019-03-04 21:32:26 +0000 | |
---|---|---|
committer | 2019-03-04 21:32:26 +0000 | |
commit | 21ff97ba4bfe1f2355c0c8879f82f4a8605499b9 (patch) | |
tree | defd54f5ed13cbd52a3be8eb80b59fc49433e800 | |
parent | expose the interface queue drops in the interface view (diff) | |
download | wireguard-openbsd-21ff97ba4bfe1f2355c0c8879f82f4a8605499b9.tar.xz wireguard-openbsd-21ff97ba4bfe1f2355c0c8879f82f4a8605499b9.zip |
when showing interface stats, combine the queue drops with errors as fails
if you want to see errors or queue drops on their own, use -e or
-d respectively.
ok claudio@ deraadt@
-rw-r--r-- | usr.bin/netstat/if.c | 114 | ||||
-rw-r--r-- | usr.bin/netstat/main.c | 9 | ||||
-rw-r--r-- | usr.bin/netstat/netstat.1 | 18 | ||||
-rw-r--r-- | usr.bin/netstat/netstat.h | 6 |
4 files changed, 100 insertions, 47 deletions
diff --git a/usr.bin/netstat/if.c b/usr.bin/netstat/if.c index 72ab1c568d8..bba60fe1d85 100644 --- a/usr.bin/netstat/if.c +++ b/usr.bin/netstat/if.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if.c,v 1.74 2015/10/05 15:40:39 uebayasi Exp $ */ +/* $OpenBSD: if.c,v 1.75 2019/03/04 21:32:26 dlg Exp $ */ /* $NetBSD: if.c,v 1.16.4.2 1996/06/07 21:46:46 thorpej Exp $ */ /* @@ -63,6 +63,26 @@ static void catchalarm(int); static void get_rtaddrs(int, struct sockaddr *, struct sockaddr **); static void fetchifs(void); +struct iftot; + +struct if_show_err { + const char *name; + const char *iname; + const char *oname; + uint64_t (*count)(uint64_t, uint64_t); +}; + +static uint64_t if_show_fails(uint64_t, uint64_t); +static uint64_t if_show_errors(uint64_t, uint64_t); +static uint64_t if_show_qdrops(uint64_t, uint64_t); + +static const struct if_show_err if_show_errs[] = { + [IF_SHOW_FAIL] = { "fails", "Ifail", "Ofail", if_show_fails }, + [IF_SHOW_ERRS] = { "errs", "Ierrs", "Oerrs", if_show_errors }, + [IF_SHOW_DROP] = { "drops", "Idrop", "Odrop", if_show_qdrops }, +}; +static const struct if_show_err *if_errs = if_show_errs; + /* * Print a description of the network interfaces. * NOTE: ifnetaddr is the location of the kernel global "ifnet", @@ -83,6 +103,8 @@ intpr(int interval, int repeatcount) u_int64_t total = 0; size_t len; + if_errs = &if_show_errs[dflag]; + if (interval) { sidewaysintpr((unsigned)interval, repeatcount); return; @@ -94,13 +116,13 @@ intpr(int interval, int repeatcount) "Name", "Mtu", "Network", "Address"); if (bflag) printf("%10.10s %10.10s", "Ibytes", "Obytes"); - else + else { printf("%8.8s %5.5s %8.8s %5.5s %5.5s", - "Ipkts", "Ierrs", "Opkts", "Oerrs", "Colls"); + "Ipkts", if_errs->iname, + "Opkts", if_errs->oname, "Colls"); + } if (tflag) printf(" %s", "Time"); - if (dflag) - printf(" %s", "Drop"); putchar('\n'); lim = buf + len; @@ -137,13 +159,15 @@ intpr(int interval, int repeatcount) if (qflag) { total = ifd->ifi_ibytes + ifd->ifi_obytes + - ifd->ifi_ipackets + ifd->ifi_ierrors + - ifd->ifi_opackets + ifd->ifi_oerrors + + ifd->ifi_ipackets + + ifd->ifi_opackets + ifd->ifi_collisions; + total += if_errs->count(ifd->ifi_ierrors, + ifd->ifi_iqdrops); + total += if_errs->count(ifd->ifi_oerrors, + ifd->ifi_oqdrops); if (tflag) total += 0; // XXX ifnet.if_timer; - if (dflag) - total += ifd->ifi_oqdrops; if (total == 0) continue; } @@ -271,13 +295,13 @@ hexprint: ifd->ifi_ibytes, ifd->ifi_obytes); } else printf("%8llu %5llu %8llu %5llu %5llu", - ifd->ifi_ipackets, ifd->ifi_ierrors, - ifd->ifi_opackets, ifd->ifi_oerrors, + ifd->ifi_ipackets, + if_errs->count(ifd->ifi_ierrors, ifd->ifi_iqdrops), + ifd->ifi_opackets, + if_errs->count(ifd->ifi_oerrors, ifd->ifi_oqdrops), ifd->ifi_collisions); if (tflag) printf(" %4d", 0 /* XXX ifnet.if_timer */); - if (dflag) - printf(" %5llu", ifd->ifi_oqdrops); putchar('\n'); } @@ -286,11 +310,12 @@ struct iftot { u_int64_t ift_ip; /* input packets */ u_int64_t ift_ib; /* input bytes */ u_int64_t ift_ie; /* input errors */ + u_int64_t ift_iq; /* input qdrops */ u_int64_t ift_op; /* output packets */ u_int64_t ift_ob; /* output bytes */ u_int64_t ift_oe; /* output errors */ + u_int64_t ift_oq; /* output qdrops */ u_int64_t ift_co; /* collisions */ - u_int64_t ift_dr; /* drops */ } ip_cur, ip_old, sum_cur, sum_old; volatile sig_atomic_t signalled; /* set if alarm goes off "early" */ @@ -328,8 +353,6 @@ banner: printf("%5.5s in %5.5s%5.5s out %5.5s %5.5s", ip_cur.ift_name, " ", ip_cur.ift_name, " ", " "); - if (dflag) - printf(" %5.5s", " "); if (bflag) printf(" %7.7s in %8.8s %6.6s out %5.5s", @@ -337,17 +360,14 @@ banner: else printf(" %5.5s in %5.5s%5.5s out %5.5s %5.5s", "total", " ", "total", " ", " "); - if (dflag) - printf(" %5.5s", " "); putchar('\n'); if (bflag) printf("%10.10s %8.8s %10.10s %5.5s", "bytes", " ", "bytes", " "); else printf("%8.8s %5.5s %8.8s %5.5s %5.5s", - "packets", "errs", "packets", "errs", "colls"); - if (dflag) - printf(" %5.5s", "drops"); + "packets", if_errs->name, + "packets", if_errs->name, "colls"); if (bflag) printf("%10.10s %8.8s %10.10s %5.5s", @@ -355,8 +375,6 @@ banner: else printf(" %8.8s %5.5s %8.8s %5.5s %5.5s", "packets", "errs", "packets", "errs", "colls"); - if (dflag) - printf(" %5.5s", "drops"); putchar('\n'); fflush(stdout); line = 0; @@ -380,13 +398,12 @@ loop: } else printf("%8llu %5llu %8llu %5llu %5llu", ip_cur.ift_ip - ip_old.ift_ip, - ip_cur.ift_ie - ip_old.ift_ie, + if_errs->count(ip_cur.ift_ie - ip_old.ift_ie, + ip_cur.ift_iq - ip_old.ift_iq), ip_cur.ift_op - ip_old.ift_op, - ip_cur.ift_oe - ip_old.ift_oe, + if_errs->count(ip_cur.ift_oe - ip_old.ift_oe, + ip_cur.ift_oq - ip_old.ift_oq), ip_cur.ift_co - ip_old.ift_co); - if (dflag) - printf(" %5llu", - ip_cur.ift_dr - ip_old.ift_dr); ip_old = ip_cur; @@ -394,21 +411,21 @@ loop: if (hflag) { fmt_scaled(sum_cur.ift_ib - sum_old.ift_ib, ibytes); fmt_scaled(sum_cur.ift_ob - sum_old.ift_ob, obytes); - printf(" %10s %8.8s %10s %5.5s", + printf("%10s %8.8s %10s %5.5s", ibytes, " ", obytes, " "); } else - printf(" %10llu %8.8s %10llu %5.5s", + printf("%10llu %8.8s %10llu %5.5s", sum_cur.ift_ib - sum_old.ift_ib, " ", sum_cur.ift_ob - sum_old.ift_ob, " "); } else - printf(" %8llu %5llu %8llu %5llu %5llu", + printf("%8llu %5llu %8llu %5llu %5llu", sum_cur.ift_ip - sum_old.ift_ip, - sum_cur.ift_ie - sum_old.ift_ie, + if_errs->count(sum_cur.ift_ie - sum_old.ift_ie, + sum_cur.ift_iq - sum_old.ift_iq), sum_cur.ift_op - sum_old.ift_op, - sum_cur.ift_oe - sum_old.ift_oe, + if_errs->count(sum_cur.ift_oe - sum_old.ift_oe, + sum_cur.ift_oq - sum_old.ift_oq), sum_cur.ift_co - sum_old.ift_co); - if (dflag) - printf(" %5llu", sum_cur.ift_dr - sum_old.ift_dr); sum_old = sum_cur; @@ -547,21 +564,23 @@ fetchifs(void) ip_cur.ift_ip = ifd->ifi_ipackets; ip_cur.ift_ib = ifd->ifi_ibytes; ip_cur.ift_ie = ifd->ifi_ierrors; + ip_cur.ift_iq = ifd->ifi_iqdrops; ip_cur.ift_op = ifd->ifi_opackets; ip_cur.ift_ob = ifd->ifi_obytes; ip_cur.ift_oe = ifd->ifi_oerrors; + ip_cur.ift_oq = ifd->ifi_oqdrops; ip_cur.ift_co = ifd->ifi_collisions; - ip_cur.ift_dr = ifd->ifi_oqdrops; } sum_cur.ift_ip += ifd->ifi_ipackets; sum_cur.ift_ib += ifd->ifi_ibytes; sum_cur.ift_ie += ifd->ifi_ierrors; + sum_cur.ift_iq += ifd->ifi_iqdrops; sum_cur.ift_op += ifd->ifi_opackets; sum_cur.ift_ob += ifd->ifi_obytes; sum_cur.ift_oe += ifd->ifi_oerrors; + sum_cur.ift_oq += ifd->ifi_oqdrops; sum_cur.ift_co += ifd->ifi_collisions; - sum_cur.ift_dr += ifd->ifi_oqdrops; break; } } @@ -571,11 +590,30 @@ fetchifs(void) ip_cur.ift_ip = ifd->ifi_ipackets; ip_cur.ift_ib = ifd->ifi_ibytes; ip_cur.ift_ie = ifd->ifi_ierrors; + ip_cur.ift_iq = ifd->ifi_iqdrops; ip_cur.ift_op = ifd->ifi_opackets; ip_cur.ift_ob = ifd->ifi_obytes; ip_cur.ift_oe = ifd->ifi_oerrors; + ip_cur.ift_oq = ifd->ifi_oqdrops; ip_cur.ift_co = ifd->ifi_collisions; - ip_cur.ift_dr = ifd->ifi_oqdrops; } free(buf); } + +static uint64_t +if_show_fails(uint64_t errors, uint64_t qdrops) +{ + return (errors + qdrops); +} + +static uint64_t +if_show_errors(uint64_t errors, uint64_t qdrops) +{ + return (errors); +} + +static uint64_t +if_show_qdrops(uint64_t errors, uint64_t qdrops) +{ + return (qdrops); +} diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c index 17c889768a2..ebe83fe66d2 100644 --- a/usr.bin/netstat/main.c +++ b/usr.bin/netstat/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.113 2018/08/13 14:36:54 mpi Exp $ */ +/* $OpenBSD: main.c,v 1.114 2019/03/04 21:32:26 dlg Exp $ */ /* $NetBSD: main.c,v 1.9 1996/05/07 02:55:02 thorpej Exp $ */ /* @@ -129,7 +129,7 @@ main(int argc, char *argv[]) tableid = getrtable(); while ((ch = getopt(argc, argv, - "AaBbc:dFf:ghI:iLlM:mN:np:P:qrsT:tuvW:w:")) != -1) + "AaBbc:deFf:ghI:iLlM:mN:np:P:qrsT:tuvW:w:")) != -1) switch (ch) { case 'A': Aflag = 1; @@ -149,7 +149,10 @@ main(int argc, char *argv[]) errx(1, "count is %s", errstr); break; case 'd': - dflag = 1; + dflag = IF_SHOW_DROP; + break; + case 'e': + dflag = IF_SHOW_ERRS; break; case 'F': Fflag = 1; diff --git a/usr.bin/netstat/netstat.1 b/usr.bin/netstat/netstat.1 index c352eced60b..ae636e4729d 100644 --- a/usr.bin/netstat/netstat.1 +++ b/usr.bin/netstat/netstat.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: netstat.1,v 1.83 2018/07/13 09:06:58 kn Exp $ +.\" $OpenBSD: netstat.1,v 1.84 2019/03/04 21:32:26 dlg Exp $ .\" $NetBSD: netstat.1,v 1.11 1995/10/03 21:42:43 thorpej Exp $ .\" .\" Copyright (c) 1983, 1990, 1992, 1993 @@ -30,7 +30,7 @@ .\" .\" from: @(#)netstat.1 8.8 (Berkeley) 4/18/94 .\" -.Dd $Mdocdate: July 13 2018 $ +.Dd $Mdocdate: March 4 2019 $ .Dt NETSTAT 1 .Os .Sh NAME @@ -45,7 +45,7 @@ .Op Fl N Ar system .Nm netstat .Bk -words -.Op Fl bdFgilmnqrstu +.Op Fl bdeFgilmnqrstu .Op Fl f Ar address_family .Op Fl p Ar protocol .Op Fl M Ar core @@ -53,7 +53,7 @@ .Op Fl T Ar rtable .Ek .Nm netstat -.Op Fl bdhn +.Op Fl bdehn .Op Fl c Ar count .Op Fl I Ar interface .Op Fl M Ar core @@ -143,7 +143,15 @@ or .Fl i ) or an interval (option .Fl w ) , -show the number of dropped packets. +show only the number of dropped packets. +.It Fl e +With either the interface display (options +.Fl I +or +.Fl i ) +or an interval (option +.Fl w ) , +show only the number of errors on the interface. .It Fl F When showing routes, only show routes whose gateway are in the same address family as the destination. diff --git a/usr.bin/netstat/netstat.h b/usr.bin/netstat/netstat.h index 2cd9f6c0ae1..8f8e01f8718 100644 --- a/usr.bin/netstat/netstat.h +++ b/usr.bin/netstat/netstat.h @@ -1,4 +1,4 @@ -/* $OpenBSD: netstat.h,v 1.72 2018/08/13 14:36:54 mpi Exp $ */ +/* $OpenBSD: netstat.h,v 1.73 2019/03/04 21:32:26 dlg Exp $ */ /* $NetBSD: netstat.h,v 1.6 1996/05/07 02:55:05 thorpej Exp $ */ /* @@ -142,6 +142,10 @@ void routepr(u_long, u_long, u_long, u_long, u_int); void nsprotopr(u_long, char *); +#define IF_SHOW_FAIL 0 +#define IF_SHOW_ERRS 1 +#define IF_SHOW_DROP 2 + void intpr(int, int); void mroutepr(void); |