summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authorreyk <reyk@openbsd.org>2005-04-12 14:11:49 +0000
committerreyk <reyk@openbsd.org>2005-04-12 14:11:49 +0000
commit9f414a08df1d9266255162df3aba825d5781a5b5 (patch)
tree42ab4878d2a0ef26ab2f1d41832783dd371d82dd /usr.bin
parentnote that args w/ whitespace and single quotes must be double quoted; (diff)
downloadwireguard-openbsd-9f414a08df1d9266255162df3aba825d5781a5b5.tar.xz
wireguard-openbsd-9f414a08df1d9266255162df3aba825d5781a5b5.zip
add '-W interface' for 802.11 wireless statistics of the net80211 stack.
ok dlg@ deraadt@ jmc@
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/netstat/Makefile4
-rw-r--r--usr.bin/netstat/main.c24
-rw-r--r--usr.bin/netstat/net80211.c112
-rw-r--r--usr.bin/netstat/netstat.17
-rw-r--r--usr.bin/netstat/netstat.h3
5 files changed, 143 insertions, 7 deletions
diff --git a/usr.bin/netstat/Makefile b/usr.bin/netstat/Makefile
index ca5e2a34cbf..3e7e60fe683 100644
--- a/usr.bin/netstat/Makefile
+++ b/usr.bin/netstat/Makefile
@@ -1,8 +1,8 @@
-# $OpenBSD: Makefile,v 1.14 2005/02/10 14:25:08 itojun Exp $
+# $OpenBSD: Makefile,v 1.15 2005/04/12 14:11:49 reyk Exp $
PROG= netstat
SRCS= if.c inet.c inet6.c ipx.c main.c mbuf.c mroute.c ns.c route.c \
- unix.c atalk.c mroute6.c
+ unix.c atalk.c mroute6.c net80211.c
BINGRP= kmem
BINMODE=2555
LDADD= -lkvm
diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c
index bd6feb1e057..995f8af4c7c 100644
--- a/usr.bin/netstat/main.c
+++ b/usr.bin/netstat/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.55 2005/03/30 17:45:51 deraadt Exp $ */
+/* $OpenBSD: main.c,v 1.56 2005/04/12 14:11:49 reyk Exp $ */
/* $NetBSD: main.c,v 1.9 1996/05/07 02:55:02 thorpej Exp $ */
/*
@@ -40,7 +40,7 @@ char copyright[] =
#if 0
static char sccsid[] = "from: @(#)main.c 8.4 (Berkeley) 3/1/94";
#else
-static char *rcsid = "$OpenBSD: main.c,v 1.55 2005/03/30 17:45:51 deraadt Exp $";
+static char *rcsid = "$OpenBSD: main.c,v 1.56 2005/04/12 14:11:49 reyk Exp $";
#endif
#endif /* not lint */
@@ -276,7 +276,7 @@ main(int argc, char *argv[])
af = AF_UNSPEC;
- while ((ch = getopt(argc, argv, "Aabdf:gI:ilM:mN:np:qrstuvw:")) != -1)
+ while ((ch = getopt(argc, argv, "Aabdf:gI:ilM:mN:np:qrstuvW:w:")) != -1)
switch (ch) {
case 'A':
Aflag = 1;
@@ -366,6 +366,10 @@ main(int argc, char *argv[])
case 'v':
vflag = 1;
break;
+ case 'W':
+ Wflag = 1;
+ interface = optarg;
+ break;
case 'w':
interval = atoi(optarg);
iflag = 1;
@@ -378,6 +382,17 @@ main(int argc, char *argv[])
argc -= optind;
/*
+ * Show per-interface statistics which don't need access to
+ * kernel memory (they're using IOCTLs)
+ */
+ if (Wflag) {
+ if (interface == NULL)
+ usage();
+ net80211_ifstats(interface);
+ exit(0);
+ }
+
+ /*
* Discard setgid privileges if not the running kernel so that bad
* guys can't print interesting stuff from kernel memory.
*/
@@ -435,6 +450,7 @@ main(int argc, char *argv[])
*/
sethostent(1);
setnetent(1);
+
if (iflag) {
intpr(interval, nl[N_IFNET].n_value);
exit(0);
@@ -613,5 +629,7 @@ usage(void)
" %s [-s] [-M core] [-N system] [-p protocol]\n", __progname);
(void)fprintf(stderr,
" %s [-a] [-f address_family] [-i | -I interface]\n", __progname);
+ (void)fprintf(stderr,
+" %s [-W interface]\n", __progname);
exit(1);
}
diff --git a/usr.bin/netstat/net80211.c b/usr.bin/netstat/net80211.c
new file mode 100644
index 00000000000..aff671f1c12
--- /dev/null
+++ b/usr.bin/netstat/net80211.c
@@ -0,0 +1,112 @@
+/* $OpenBSD: net80211.c,v 1.1 2005/04/12 14:11:49 reyk Exp $ */
+
+/*
+ * Copyright (c) 2005 Reyk Floeter <reyk@vantronix.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/cdefs.h>
+#include <sys/param.h>
+#include <sys/time.h>
+#include <sys/socket.h>
+#include <sys/file.h>
+#include <sys/ioctl.h>
+
+#include <net/if.h>
+
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+#include <netinet/if_ether.h>
+
+#include <net80211/ieee80211.h>
+#include <net80211/ieee80211_ioctl.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include "netstat.h"
+
+/*
+ * Dump IEEE802.11 per-interface statistics
+ */
+void
+net80211_ifstats(char *ifname)
+{
+ struct ifreq ifr;
+ struct ieee80211_stats stats;
+ int s;
+
+#define p(f, m) printf(m, (unsigned long)stats.f, plural(stats.f))
+
+ if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
+ perror("Warning: socket(AF_INET)");
+ return;
+ }
+
+ ifr.ifr_data = (caddr_t)&stats;
+ strlcpy(ifr.ifr_name, ifname, sizeof ifr.ifr_name);
+ printf("ieee80211 on %s:\n", ifr.ifr_name);
+
+ if (ioctl(s, SIOCG80211STATS, &ifr) < 0) {
+ perror("Warning: ioctl(SIOCG80211STATS)");
+ goto end;
+ }
+
+ p(is_rx_badversion, "\t%lu input packet%s with bad version\n");
+ p(is_rx_tooshort, "\t%lu input packet%s too short\n");
+ p(is_rx_wrongbss, "\t%lu input packet%s from wrong bssid\n");
+ p(is_rx_dup, "\t%lu input packet duplicate%s discarded\n");
+ p(is_rx_wrongdir, "\t%lu input packet%s with wrong direction\n");
+ p(is_rx_mcastecho, "\t%lu input multicast echo packet%s discarded\n");
+ p(is_rx_notassoc, "\t%lu input packet%s from unassociated station discarded\n");
+ p(is_rx_nowep, "\t%lu input wep packet%s without wep discarded\n");
+ p(is_rx_wepfail, "\t%lu input wep packet%s processing failed\n");
+ p(is_rx_decap, "\t%lu input packet decapsulation%s failed\n");
+ p(is_rx_mgtdiscard, "\t%lu input management packet%s discarded\n");
+ p(is_rx_ctl, "\t%lu input control packet%s discarded\n");
+ p(is_rx_rstoobig, "\t%lu input packet%s with truncated rate set\n");
+ p(is_rx_elem_missing, "\t%lu input packet%s with missing elements\n");
+ p(is_rx_elem_toobig, "\t%lu input packet%s with elements too big\n");
+ p(is_rx_elem_toosmall, "\t%lu input packet%s with elements too small\n");
+ p(is_rx_elem_unknown, "\t%lu input packet%s with unknown elements\n");
+ p(is_rx_badchan, "\t%lu input packet%s with invalid channel\n");
+ p(is_rx_chanmismatch, "\t%lu input packet%s with mismatched channel\n");
+ p(is_rx_nodealloc, "\t%lu input packet%s dropped\n");
+ p(is_rx_ssidmismatch, "\t%lu input packet%s with mismatched ssid\n");
+ p(is_rx_auth_unsupported, "\t%lu input packet%s with unsupported auth algorithm\n");
+ p(is_rx_auth_fail, "\t%lu input authentication%s failed\n");
+ p(is_rx_assoc_bss, "\t%lu input association%s from wrong bssid\n");
+ p(is_rx_assoc_notauth, "\t%lu input association%s without authentication\n");
+ p(is_rx_assoc_capmismatch, "\t%lu input association%s with mismatched capabilities\n");
+ p(is_rx_assoc_norate, "\t%lu input association%s without matching rates\n");
+ p(is_rx_deauth, "\t%lu input deauthentication packet%s\n");
+ p(is_rx_disassoc, "\t%lu input disassociation packet%s\n");
+ p(is_rx_badsubtype, "\t%lu input packet%s with unknown subtype\n");
+ p(is_rx_nombuf, "\t%lu input packet%s failed for lack of mbufs\n");
+ p(is_rx_decryptcrc, "\t%lu input decryption%s failed on crc\n");
+ p(is_rx_ahdemo_mgt, "\t%lu input ahdemo management packet%s discarded\n");
+ p(is_rx_bad_auth, "\t%lu input packet%s with bad auth request\n");
+ p(is_tx_nombuf, "\t%lu output packet%s failed for lack of mbufs\n");
+ p(is_tx_nonode, "\t%lu output packet%s failed for no nodes\n");
+ p(is_tx_unknownmgt, "\t%lu output packet%s of unknown management type\n");
+ p(is_scan_active, "\t%lu active scan%s started\n");
+ p(is_scan_passive, "\t%lu passive scan%s started\n");
+ p(is_node_timeout, "\t%lu node%s timed out\n");
+ p(is_crypto_nomem, "\t%lu failure%s with no memory for crypto ctx\n");
+
+ end:
+ close(s);
+
+#undef p
+}
diff --git a/usr.bin/netstat/netstat.1 b/usr.bin/netstat/netstat.1
index 9e152c94942..5c3fe22016e 100644
--- a/usr.bin/netstat/netstat.1
+++ b/usr.bin/netstat/netstat.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: netstat.1,v 1.41 2005/03/30 08:23:47 jaredy Exp $
+.\" $OpenBSD: netstat.1,v 1.42 2005/04/12 14:11:49 reyk Exp $
.\" $NetBSD: netstat.1,v 1.11 1995/10/03 21:42:43 thorpej Exp $
.\"
.\" Copyright (c) 1983, 1990, 1992, 1993
@@ -62,6 +62,8 @@
.Op Fl a
.Op Fl f Ar address_family
.Op Fl i | I Ar interface
+.Nm netstat
+.Op Fl W Ar interface
.Sh DESCRIPTION
The
.Nm
@@ -236,6 +238,9 @@ address family.
.It Fl v
Be verbose.
Avoids truncation of long addresses.
+.It Fl W Ar interface
+(IEEE 802.11 devices only)
+Show per-interface IEEE 802.11 wireless statistics.
.It Fl w Ar wait
Show network interface statistics at intervals of
.Ar wait
diff --git a/usr.bin/netstat/netstat.h b/usr.bin/netstat/netstat.h
index a06f1c55402..5f8c6ada545 100644
--- a/usr.bin/netstat/netstat.h
+++ b/usr.bin/netstat/netstat.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: netstat.h,v 1.33 2005/03/30 08:23:47 jaredy Exp $ */
+/* $OpenBSD: netstat.h,v 1.34 2005/04/12 14:11:49 reyk Exp $ */
/* $NetBSD: netstat.h,v 1.6 1996/05/07 02:55:05 thorpej Exp $ */
/*
@@ -52,6 +52,7 @@ int rflag; /* show routing tables (or routing stats) */
int sflag; /* show protocol statistics */
int tflag; /* show i/f watchdog timers */
int vflag; /* be verbose */
+int Wflag; /* show net80211 protocol statistics */
int interval; /* repeat interval for i/f stats */