diff options
author | wollman <wollman@FreeBSD.org> | 1997-09-25 00:37:32 +0000 |
---|---|---|
committer | wollman <wollman@FreeBSD.org> | 1997-09-25 00:37:32 +0000 |
commit | 92277fa474d464011e3bfb7177f8a1c51d582404 (patch) | |
tree | c575e0d5e7857e59dc91a205ecd44cc0af84cbf2 /usr.bin/systat | |
parent | 6c4e9fc61332696898bfd76840cc344e5d8f7b95 (diff) | |
download | FreeBSD-src-92277fa474d464011e3bfb7177f8a1c51d582404.zip FreeBSD-src-92277fa474d464011e3bfb7177f8a1c51d582404.tar.gz |
Emboldened by the success of yesterday's ICMP statistics display,
I've now added one that does IP (and also UDP) statistics.
Diffstat (limited to 'usr.bin/systat')
-rw-r--r-- | usr.bin/systat/Makefile | 2 | ||||
-rw-r--r-- | usr.bin/systat/cmdtab.c | 5 | ||||
-rw-r--r-- | usr.bin/systat/extern.h | 7 | ||||
-rw-r--r-- | usr.bin/systat/ip.c | 341 |
4 files changed, 353 insertions, 2 deletions
diff --git a/usr.bin/systat/Makefile b/usr.bin/systat/Makefile index 55a8883..4664fd5 100644 --- a/usr.bin/systat/Makefile +++ b/usr.bin/systat/Makefile @@ -3,7 +3,7 @@ PROG= systat CFLAGS+=-I${.CURDIR}/../../sys -I${.CURDIR}/../vmstat SRCS= cmds.c cmdtab.c disks.c fetch.c iostat.c keyboard.c vmstat.c main.c \ - mbufs.c netcmds.c netstat.c pigs.c swap.c icmp.c mode.c + mbufs.c netcmds.c netstat.c pigs.c swap.c icmp.c mode.c ip.c DPADD= ${LIBCURSES} ${LIBTERMCAP} ${LIBM} ${LIBKVM} LDADD= -lcurses -ltermcap -lm -lkvm BINGRP= kmem diff --git a/usr.bin/systat/cmdtab.c b/usr.bin/systat/cmdtab.c index c78587a..d2a2884 100644 --- a/usr.bin/systat/cmdtab.c +++ b/usr.bin/systat/cmdtab.c @@ -36,7 +36,7 @@ static char sccsid[] = "@(#)cmdtab.c 8.1 (Berkeley) 6/6/93"; */ static const char rcsid[] = - "$Id$"; + "$Id: cmdtab.c,v 1.2 1997/09/24 02:43:37 wollman Exp $"; #endif /* not lint */ #include "systat.h" @@ -65,6 +65,9 @@ struct cmdtab cmdtab[] = { { "icmp", showicmp, fetchicmp, labelicmp, initicmp, openicmp, closeicmp, cmdmode, reseticmp, CF_LOADAV }, + { "ip", showip, fetchip, labelip, + initip, openip, closeip, cmdmode, + resetip, CF_LOADAV }, { 0 } }; struct cmdtab *curcmd = &cmdtab[0]; diff --git a/usr.bin/systat/extern.h b/usr.bin/systat/extern.h index e2027c4..0deeeb1 100644 --- a/usr.bin/systat/extern.h +++ b/usr.bin/systat/extern.h @@ -64,6 +64,7 @@ int checkhost __P((struct inpcb *)); int checkport __P((struct inpcb *)); void closeiostat __P((WINDOW *)); void closeicmp __P((WINDOW *)); +void closeip __P((WINDOW *)); void closekre __P((WINDOW *)); void closembufs __P((WINDOW *)); void closenetstat __P((WINDOW *)); @@ -80,6 +81,7 @@ int dkinit __P((void)); int dkcmd __P((char *, char *)); void error __P((const char *fmt, ...)); void fetchicmp __P((void)); +void fetchip __P((void)); void fetchiostat __P((void)); void fetchkre __P((void)); void fetchmbufs __P((void)); @@ -87,6 +89,7 @@ void fetchnetstat __P((void)); void fetchpigs __P((void)); void fetchswap __P((void)); int initicmp __P((void)); +int initip __P((void)); int initiostat __P((void)); int initkre __P((void)); int initmbufs __P((void)); @@ -96,6 +99,7 @@ int initswap __P((void)); int keyboard __P((void)); int kvm_ckread __P((void *, void *, int)); void labelicmp __P((void)); +void labelip __P((void)); void labeliostat __P((void)); void labelkre __P((void)); void labelmbufs __P((void)); @@ -107,6 +111,7 @@ void load __P((void)); int netcmd __P((char *, char *)); void nlisterr __P((struct nlist [])); WINDOW *openicmp __P((void)); +WINDOW *openip __P((void)); WINDOW *openiostat __P((void)); WINDOW *openkre __P((void)); WINDOW *openmbufs __P((void)); @@ -115,7 +120,9 @@ WINDOW *openpigs __P((void)); WINDOW *openswap __P((void)); int prefix __P((char *, char *)); void reseticmp __P((void)); +void resetip __P((void)); void showicmp __P((void)); +void showip __P((void)); void showiostat __P((void)); void showkre __P((void)); void showmbufs __P((void)); diff --git a/usr.bin/systat/ip.c b/usr.bin/systat/ip.c new file mode 100644 index 0000000..ff87721 --- /dev/null +++ b/usr.bin/systat/ip.c @@ -0,0 +1,341 @@ +/*- + * Copyright (c) 1980, 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +/* From: +static char sccsid[] = "@(#)mbufs.c 8.1 (Berkeley) 6/6/93"; +static const char rcsid[] = + "Id: mbufs.c,v 1.5 1997/02/24 20:59:03 wollman Exp"; +*/ +static const char rcsid[] = + "$Id: icmp.c,v 1.1 1997/09/24 02:43:39 wollman Exp $"; +#endif /* not lint */ + +#include <sys/param.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/sysctl.h> + +#include <netinet/in.h> +#include <netinet/in_systm.h> +#include <netinet/ip.h> +#include <netinet/ip_var.h> +#include <netinet/udp.h> +#include <netinet/udp_var.h> + +#include <stdlib.h> +#include <string.h> +#include <paths.h> +#include "systat.h" +#include "extern.h" +#include "mode.h" + +struct stat { + struct ipstat i; + struct udpstat u; +}; + +static struct stat curstat, initstat, oldstat; + +/*- +--0 1 2 3 4 5 6 7 +--0123456789012345678901234567890123456789012345678901234567890123456789012345 +01 IP Input IP Output +02999999999 total packets received 999999999 total packets sent +03999999999 - with bad checksums 999999999 - generated locally +04999999999 - too short for header 999999999 - output drops +05999999999 - too short for data 999999999 output fragments generated +06999999999 - with invalid hlen 999999999 - fragmentation failed +07999999999 - with invalid length 999999999 destinations unreachable +08999999999 - with invalid version 999999999 packets output via raw IP +09999999999 - jumbograms +10999999999 total fragments received UDP Statistics +11999999999 - fragments dropped 999999999 total input packets +12999999999 - fragments timed out 999999999 - too short for header +13999999999 - packets reassembled ok 999999999 - invalid checksum +14999999999 packets forwarded 999999999 - invalid length +15999999999 - unreachable dests 999999999 - no socket for dest port +16999999999 - redirects generated 999999999 - no socket for broadcast +17999999999 option errors 999999999 - socket buffer full +18999999999 unwanted multicasts 999999999 total output packets +19999999999 delivered to upper layer +--0123456789012345678901234567890123456789012345678901234567890123456789012345 +--0 1 2 3 4 5 6 7 +*/ + +WINDOW * +openip(void) +{ + return (subwin(stdscr, LINES-5-1, 0, 5, 0)); +} + +void +closeip(w) + WINDOW *w; +{ + if (w == NULL) + return; + wclear(w); + wrefresh(w); + delwin(w); +} + +void +labelip(void) +{ + wmove(wnd, 0, 0); wclrtoeol(wnd); +#define L(row, str) mvwprintw(wnd, row, 10, str) +#define R(row, str) mvwprintw(wnd, row, 45, str); + L(1, "IP Input"); R(1, "IP Output"); + L(2, "total packets received"); R(2, "total packets sent"); + L(3, "- with bad checksums"); R(3, "- generated locally"); + L(4, "- too short for header"); R(4, "- output drops"); + L(5, "- too short for data"); R(5, "output fragments generated"); + L(6, "- with invalid hlen"); R(6, "- fragmentation failed"); + L(7, "- with invalid length"); R(7, "destinations unreachable"); + L(8, "- with invalid version"); R(8, "packets output via raw IP"); + L(9, "- jumbograms"); + L(10, "total fragments received"); R(10, "UDP Statistics"); + L(11, "- fragments dropped"); R(11, "total input packets"); + L(12, "- fragments timed out"); R(12, "- too short for header"); + L(13, "- packets reassembled ok"); R(13, "- invalid checksum"); + L(14, "packets forwarded"); R(14, "- invalid length"); + L(15, "- unreachable dests"); R(15, "- no socket for dest port"); + L(16, "- redirects generated"); R(16, "- no socket for broadcast"); + L(17, "option errors"); R(17, "- socket buffer full"); + L(18, "unwanted multicasts"); R(18, "total output packets"); + L(19, "delivered to upper layer"); +#undef L +#undef R +} + +static void +domode(struct stat *ret) +{ + const struct stat *sub; + int i, divisor = 1; + + switch(currentmode) { + case display_RATE: + sub = &oldstat; + divisor = naptime; + break; + case display_DELTA: + sub = &oldstat; + break; + case display_SINCE: + sub = &initstat; + break; + default: + *ret = curstat; + return; + } +#define DO(stat) ret->stat = (curstat.stat - sub->stat) / divisor + DO(i.ips_total); + DO(i.ips_badsum); + DO(i.ips_tooshort); + DO(i.ips_toosmall); + DO(i.ips_badhlen); + DO(i.ips_badlen); + DO(i.ips_fragments); + DO(i.ips_fragdropped); + DO(i.ips_fragtimeout); + DO(i.ips_forward); + DO(i.ips_cantforward); + DO(i.ips_redirectsent); + DO(i.ips_noproto); + DO(i.ips_delivered); + DO(i.ips_localout); + DO(i.ips_odropped); + DO(i.ips_reassembled); + DO(i.ips_fragmented); + DO(i.ips_ofragments); + DO(i.ips_cantfrag); + DO(i.ips_badoptions); + DO(i.ips_noroute); + DO(i.ips_badvers); + DO(i.ips_rawout); + DO(i.ips_toolong); + DO(i.ips_notmember); + DO(u.udps_ipackets); + DO(u.udps_hdrops); + DO(u.udps_badsum); + DO(u.udps_badlen); + DO(u.udps_noport); + DO(u.udps_noportbcast); + DO(u.udps_fullsock); + DO(u.udps_opackets); +#undef DO +} + +void +showip(void) +{ + struct stat stats; + u_long totalout; + int i; + + domode(&stats); + totalout = stats.i.ips_forward + stats.i.ips_localout; + +#define DO(stat, row, col) \ + mvwprintw(wnd, row, col, "%9lu", stats.stat) + + DO(i.ips_total, 2, 0); + mvwprintw(wnd, 2, 35, "%9lu", totalout); + DO(i.ips_badsum, 3, 0); + DO(i.ips_localout, 3, 35); + DO(i.ips_tooshort, 4, 0); + DO(i.ips_odropped, 4, 35); + DO(i.ips_toosmall, 5, 0); + DO(i.ips_ofragments, 5, 35); + DO(i.ips_badhlen, 6, 0); + DO(i.ips_cantfrag, 6, 35); + DO(i.ips_badlen, 7, 0); + DO(i.ips_noroute, 7, 35); + DO(i.ips_badvers, 8, 0); + DO(i.ips_rawout, 8, 35); + DO(i.ips_toolong, 9, 0); + DO(i.ips_fragments, 10, 0); + DO(i.ips_fragdropped, 11, 0); + DO(u.udps_ipackets, 11, 35); + DO(i.ips_fragtimeout, 12, 0); + DO(u.udps_hdrops, 12, 35); + DO(i.ips_reassembled, 13, 0); + DO(u.udps_badsum, 13, 35); + DO(i.ips_forward, 14, 0); + DO(u.udps_badlen, 14, 35); + DO(i.ips_cantforward, 15, 0); + DO(u.udps_noport, 15, 35); + DO(i.ips_redirectsent, 16, 0); + DO(u.udps_noportbcast, 16, 35); + DO(i.ips_badoptions, 17, 0); + DO(u.udps_fullsock, 17, 35); + DO(i.ips_notmember, 18, 0); + DO(u.udps_opackets, 18, 35); + DO(i.ips_delivered, 19, 0); +#undef DO +} + +int +initip(void) +{ + size_t len; + int name[4]; + + name[0] = CTL_NET; + name[1] = PF_INET; + name[2] = IPPROTO_IP; + name[3] = IPCTL_STATS; + + len = 0; + if (sysctl(name, 4, 0, &len, 0, 0) < 0) { + error("sysctl getting ipstat size failed"); + return 0; + } + if (len > sizeof curstat.i) { + error("ipstat structure has grown--recompile systat!"); + return 0; + } + if (sysctl(name, 4, &initstat.i, &len, 0, 0) < 0) { + error("sysctl getting ipstat failed"); + return 0; + } + name[2] = IPPROTO_UDP; + name[3] = UDPCTL_STATS; + + len = 0; + if (sysctl(name, 4, 0, &len, 0, 0) < 0) { + error("sysctl getting udpstat size failed"); + return 0; + } + if (len > sizeof curstat.u) { + error("ipstat structure has grown--recompile systat!"); + return 0; + } + if (sysctl(name, 4, &initstat.u, &len, 0, 0) < 0) { + error("sysctl getting udpstat failed"); + return 0; + } + oldstat = initstat; + return 1; +} + +void +resetip(void) +{ + size_t len; + int name[4]; + + name[0] = CTL_NET; + name[1] = PF_INET; + name[2] = IPPROTO_IP; + name[3] = IPCTL_STATS; + + len = sizeof initstat.i; + if (sysctl(name, 4, &initstat.i, &len, 0, 0) < 0) { + error("sysctl getting ipstat failed"); + } + name[2] = IPPROTO_UDP; + name[3] = UDPCTL_STATS; + + len = sizeof initstat.u; + if (sysctl(name, 4, &initstat.u, &len, 0, 0) < 0) { + error("sysctl getting udpstat failed"); + } + oldstat = initstat; +} + +void +fetchip(void) +{ + int name[4]; + size_t len; + + oldstat = curstat; + name[0] = CTL_NET; + name[1] = PF_INET; + name[2] = IPPROTO_IP; + name[3] = IPCTL_STATS; + len = sizeof curstat.i; + + if (sysctl(name, 4, &curstat.i, &len, 0, 0) < 0) + return; + name[2] = IPPROTO_UDP; + name[3] = UDPCTL_STATS; + len = sizeof curstat.u; + + if (sysctl(name, 4, &curstat.u, &len, 0, 0) < 0) + return; +} + |