2 * print PPP statistics:
3 * pppstats [-i interval] [-v] [interface] [system] [core]
5 * Brad Parker (brad@cayman.com) 6/92
7 * from the original "slstats" by Van Jaconson
9 * Copyright (c) 1989 Regents of the University of California.
10 * All rights reserved.
12 * Redistribution and use in source and binary forms are permitted
13 * provided that the above copyright notice and this paragraph are
14 * duplicated in all such forms and that any documentation,
15 * advertising materials, and other materials related to such
16 * distribution and use acknowledge that the software was developed
17 * by the University of California, Berkeley. The name of the
18 * University may not be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
22 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
24 * Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989:
25 * - Initial distribution.
29 static char rcsid[] = "$Id: pppstats.c,v 1.2 1994/11/12 19:33:41 lars Exp $";
38 #include <sys/param.h>
40 #include <sys/types.h>
41 #include <sys/socket.h>
42 #include <sys/sockio.h>
45 #include <netinet/in.h>
46 #include <netinet/in_systm.h>
47 #include <netinet/ip.h>
48 #include <netinet/ip_var.h>
51 #include <net/slcompress.h>
54 #include <net/if_ppp.h>
58 #define PPP_STATS 1 /* should be defined iff it is in ppp_if.c */
59 #include <sys/stream.h>
60 #include <net/ppp_str.h>
63 #define INTERFACE_PREFIX "ppp%d"
64 char interface[IFNAMSIZ];
72 #include <machine/pte.h>
74 #include <machine/cpu.h>
79 char *kmemf = "/dev/kmem";
86 #if defined(sun) || defined(BSD4_4)
104 struct nlist nl[] = {
112 char *system = "/vmunix";
115 #if defined(__FreeBSD__)
116 /* _PATH_UNIX is defined as "Do not use _PATH_UNIX" */
119 char *system = _PATH_UNIX;
125 unsigned interval = 5;
128 extern char *malloc();
135 char errbuf[_POSIX2_LINE_MAX];
138 if (strcmp(argv[0], "-v") == 0) {
143 if (strcmp(argv[0], "-i") == 0 && argv[1] &&
144 isdigit(argv[1][0])) {
145 interval = atoi(argv[1]);
152 if (isdigit(argv[0][0])) {
156 unit = atoi(argv[0]);
159 sprintf(interface, INTERFACE_PREFIX, unit);
160 s = socket(AF_INET, SOCK_DGRAM, 0);
162 err(1, "creating socket");
163 strcpy(ifr.ifr_name, interface);
164 if (ioctl(s, SIOCGIFFLAGS, (caddr_t)&ifr) < 0)
166 "unable to confirm existence of interface '%s'",
183 if (nlist(system, nl) < 0 || nl[0].n_type == 0) {
184 fprintf(stderr, "%s: no namelist\n", system);
187 kmem = open(kmemf, O_RDONLY);
196 Sysmap = (struct pte *)
197 malloc((u_int)(nl[N_SYSSIZE].n_value * sizeof(struct pte)));
199 fputs("pppstats: can't get memory for Sysmap.\n", stderr);
202 off = nl[N_SYSMAP].n_value & ~KERNBASE;
203 (void)lseek(kmem, off, L_SET);
204 (void)read(kmem, (char *)Sysmap,
205 (int)(nl[N_SYSSIZE].n_value * sizeof(struct pte)));
211 if ((kd = kvm_open(system, kmemf, (char *)0, O_RDONLY, NULL)) == NULL) {
215 #elif defined(BSD4_4)
217 if ((kd = kvm_openfiles(system, kmemf, NULL, O_RDONLY, errbuf)) == NULL) {
218 fprintf(stderr, "kvm_openfiles: %s", errbuf);
223 if (kvm_openfiles(system, kmemf, (char *)0) == -1) {
224 fprintf(stderr, "kvm_openfiles: %s", kvm_geterr());
229 if (kvm_nlist(KDARG nl)) {
230 fprintf(stderr, "pppstats: can't find symbols in nlist\n");
240 * Seek into the kernel for a value.
243 klseek(fd, base, off)
249 base = K0_TO_PHYS(base);
253 base = ctob(Sysmap[btop(base)].pg_pfnum) + (base & PGOFSET);
256 return (lseek(fd, base, off));
262 fprintf(stderr,"usage: pppstats [-i interval] [-v] [unit] [system] [core]\n");
266 u_char signalled; /* set if alarm goes off "early" */
268 #define V(offset) ((line % 20)? sc->offset - osc->offset : sc->offset)
271 #define STRUCT struct ppp_if_info
272 #define COMP pii_sc_comp
273 #define STATS pii_ifnet
275 #define STRUCT struct ppp_softc
281 * Print a running summary of interface statistics.
282 * Repeat display every interval seconds, showing statistics
283 * collected over that interval. Assumes that interval is non-zero.
284 * First line printed at top of screen is always cumulative.
288 register int line = 0;
291 void catchalarm(int);
298 nl[N_SOFTC].n_value += unit * sizeof(STRUCT);
299 sc = (STRUCT *)malloc(sizeof(STRUCT));
300 osc = (STRUCT *)malloc(sizeof(STRUCT));
302 bzero((char *)osc, sizeof(STRUCT));
306 if (klseek(kmem, (off_t)nl[N_SOFTC].n_value, 0) == -1) {
310 if (read(kmem, (char *)sc, sizeof(STRUCT)) <= 0) {
315 if (kvm_read(KDARG nl[N_SOFTC].n_value, sc,
316 sizeof(STRUCT)) != sizeof(STRUCT)) {
322 (void)signal(SIGALRM, catchalarm);
324 (void)alarm(interval);
326 if ((line % 20) == 0) {
327 printf("%6.6s %6.6s %6.6s %6.6s %6.6s",
328 "in", "pack", "comp", "uncomp", "err");
330 printf(" %6.6s %6.6s", "toss", "ip");
331 printf(" | %6.6s %6.6s %6.6s %6.6s %6.6s",
332 "out", "pack", "comp", "uncomp", "ip");
334 printf(" %6.6s %6.6s", "search", "miss");
338 printf("%6d %6d %6d %6d %6d",
346 V(pii_stats.ppp_ibytes),
352 V(STATS.if_ipackets),
353 V(COMP.sls_compressedin),
354 V(COMP.sls_uncompressedin),
355 V(COMP.sls_errorin));
359 V(STATS.if_ipackets) - V(COMP.sls_compressedin) -
360 V(COMP.sls_uncompressedin) - V(COMP.sls_errorin));
361 printf(" | %6d %6d %6d %6d %6d",
369 V(pii_stats.ppp_obytes),
375 V(STATS.if_opackets),
376 V(COMP.sls_compressed),
377 V(COMP.sls_packets) - V(COMP.sls_compressed),
378 V(STATS.if_opackets) - V(COMP.sls_packets));
381 V(COMP.sls_searches),
388 oldmask = sigblock(sigmask(SIGALRM));
394 (void)alarm(interval);
395 bcopy((char *)sc, (char *)osc, sizeof(STRUCT));
400 * Called if an interval expires before sidewaysintpr has completed a loop.
401 * Sets a flag to not wait for the alarm.