diff -r -U4 ppp-2.4.4+ifname/pppstats/Makefile.linux ppp-2.4.4+multistats/pppstats/Makefile.linux --- ppp-2.4.4+ifname/pppstats/Makefile.linux 2006-06-04 06:07:46.000000000 +0100 +++ ppp-2.4.4+multistats/pppstats/Makefile.linux 2009-11-03 17:20:27.000000000 +0000 @@ -16,8 +16,9 @@ INSTALL= install CFLAGS = $(COPTS) $(COMPILE_FLAGS) +LIBS += -rt all: pppstats install: pppstats diff -r -U4 ppp-2.4.4+ifname/pppstats/pppstats.c ppp-2.4.4+multistats/pppstats/pppstats.c --- ppp-2.4.4+ifname/pppstats/pppstats.c 2009-11-01 15:24:31.000000000 +0000 +++ ppp-2.4.4+multistats/pppstats/pppstats.c 2010-04-16 19:14:33.000000000 +0100 @@ -1,12 +1,13 @@ /* * print PPP statistics: - * pppstats [-a|-d] [-v|-r|-z] [-c count] [-w wait] [interface] + * pppstats [-a|-d] [-v|-r|-s|-z] [-c count] [-w wait] [interface...] * * -a Show absolute values rather than deltas * -d Show data rate (kB/s) rather than bytes * -v Show more stats for VJ TCP header compression * -r Show compression ratio + * -s Show no VJ stats * -z Show compression statistics instead of default display * * History: * perkins@cps.msu.edu: Added compression statistics and alternate @@ -50,8 +51,9 @@ #include #include #include #include +#include #ifndef STREAMS #if defined(__linux__) && defined(__powerpc__) \ && (__GLIBC__ == 2 && __GLIBC_MINOR__ == 0) @@ -82,18 +84,20 @@ #include #endif /* STREAMS */ -int vflag, rflag, zflag; /* select type of display */ +int vflag, rflag, sflag, zflag; /* select type of display */ int aflag; /* print absolute values, not deltas */ int dflag; /* print data rates, not bytes */ int interval, count; int infinite; int unit; int s; /* socket or /dev/ppp file descriptor */ int signalled; /* set if alarm goes off "early" */ char *progname; -char *interface; +char **interfaces; +int numintf; +#define MAXINTF 16 #if defined(SUNOS4) || defined(ULTRIX) || defined(NeXT) extern int optind; extern char *optarg; @@ -108,18 +112,18 @@ #endif /* !defined(PPP_DRV_NAME) */ static void usage __P((void)); static void catchalarm __P((int)); -static void get_ppp_stats __P((struct ppp_stats *)); -static void get_ppp_cstats __P((struct ppp_comp_stats *)); +static int get_ppp_stats __P((struct ppp_stats *, int)); +static int get_ppp_cstats __P((struct ppp_comp_stats *, int)); static void intpr __P((void)); int main __P((int, char *argv[])); static void usage() { - fprintf(stderr, "Usage: %s [-a|-d] [-v|-r|-z] [-c count] [-w wait] [interface]\n", + fprintf(stderr, "Usage: %s [-a|-d] [-v|-r|-s|-z] [-c count] [-w wait] [interface...]\n", progname); exit(1); } @@ -135,11 +139,12 @@ } #ifndef STREAMS -static void -get_ppp_stats(curp) +static int +get_ppp_stats(curp, num) struct ppp_stats *curp; + int num; { struct ifpppstatsreq req; memset (&req, 0, sizeof (req)); @@ -149,23 +154,21 @@ #undef ifr_name #define ifr_name ifr__name #endif - strncpy(req.ifr_name, interface, sizeof(req.ifr_name)); + strncpy(req.ifr_name, interfaces[num], sizeof(req.ifr_name)); if (ioctl(s, SIOCGPPPSTATS, &req) < 0) { - fprintf(stderr, "%s: ", progname); - if (errno == ENOTTY) - fprintf(stderr, "kernel support missing\n"); - else - perror("couldn't get PPP statistics"); - exit(1); + return 0; } + *curp = req.stats; + return 1; } -static void -get_ppp_cstats(csp) +static int +get_ppp_cstats(csp, num) struct ppp_comp_stats *csp; + int num; { struct ifpppcstatsreq creq; memset (&creq, 0, sizeof (creq)); @@ -175,20 +178,11 @@ #undef ifr_name #define ifr_name ifr__name #endif - strncpy(creq.ifr_name, interface, sizeof(creq.ifr_name)); + strncpy(creq.ifr_name, interfaces[num], sizeof(creq.ifr_name)); if (ioctl(s, SIOCGPPPCSTATS, &creq) < 0) { - fprintf(stderr, "%s: ", progname); - if (errno == ENOTTY) { - fprintf(stderr, "no kernel compression support\n"); - if (zflag) - exit(1); - rflag = 0; - } else { - perror("couldn't get PPP compression stats"); - exit(1); - } + return 0; } #ifdef __linux__ if (creq.stats.c.bytes_out == 0) { @@ -212,8 +206,9 @@ creq.stats.d.bytes_out; #endif *csp = creq.stats; + return 1; } #else /* STREAMS */ @@ -270,15 +265,15 @@ #endif /* STREAMS */ #define MAX0(a) ((int)(a) > 0? (a): 0) -#define V(offset) MAX0(cur.offset - old.offset) -#define W(offset) MAX0(ccs.offset - ocs.offset) +#define V(offset) MAX0(cur[num].offset - old[num].offset) +#define W(offset) MAX0(ccs[num].offset - ocs[num].offset) #define RATIO(c, i, u) ((c) == 0? 1.0: (u) / ((double)(c) + (i))) #define CRATE(x) RATIO(W(x.comp_bytes), W(x.inc_bytes), W(x.unc_bytes)) -#define KBPS(n) ((n) / (interval * 1000.0)) +#define KBPS(n) ((n) / (interval * 1024.0)) /* * Print a running summary of interface statistics. * Repeat display every interval seconds, showing statistics @@ -291,139 +286,217 @@ register int line = 0; sigset_t oldmask, mask; char *bunit; int ratef = 0; - struct ppp_stats cur, old; - struct ppp_comp_stats ccs, ocs; - - memset(&old, 0, sizeof(old)); - memset(&ocs, 0, sizeof(ocs)); + struct ppp_stats cur[MAXINTF], old[MAXINTF]; + struct ppp_comp_stats ccs[MAXINTF], ocs[MAXINTF]; + int ok[MAXINTF], num; + struct timespec begin; + clock_gettime(CLOCK_REALTIME, &begin); + +for (num = 0; num < numintf; num++) { + memset(&old[num], 0, sizeof(old[num])); + memset(&ocs[num], 0, sizeof(ocs[num])); +} while (1) { - get_ppp_stats(&cur); - if (zflag || rflag) - get_ppp_cstats(&ccs); + struct timespec now; + clock_gettime(CLOCK_REALTIME, &now); +#if 0 (void)signal(SIGALRM, catchalarm); signalled = 0; (void)alarm(interval); +#endif + +for (num = 0; num < numintf; num++) { + ok[num] = get_ppp_stats(&cur[num], num); + if (zflag || rflag) + ok[num] = ok && get_ppp_cstats(&ccs[num], num); + if (!ok[num]) { + memset(&old[num], 0, sizeof(old[num])); + memset(&ocs[num], 0, sizeof(ocs[num])); + } +} if ((line % 20) == 0) { +for (num = 0; num < numintf; num++) { + if (num != 0) { printf(" ⏐ "); } if (zflag) { - printf("IN: COMPRESSED INCOMPRESSIBLE COMP | "); - printf("OUT: COMPRESSED INCOMPRESSIBLE COMP\n"); + printf("%91s", interfaces[num]); + } else if (!sflag && !vflag) { + printf("%93s", interfaces[num]); + } else if (!sflag && vflag) { + printf("%129s", interfaces[num]); + } else if (!rflag) { + printf("%39s", interfaces[num]); + } else { + printf("%75s", interfaces[num]); + } +} + putchar('\n'); + if (zflag) { +for (num = 0; num < numintf; num++) { + if (num != 0) { printf(" ⏐ "); } + printf("IN: COMPRESSED INCOMPRESSIBLE COMP ⎸ "); + printf("OUT: COMPRESSED INCOMPRESSIBLE COMP"); +} + putchar('\n'); +for (num = 0; num < numintf; num++) { + if (num != 0) { printf(" ⏐ "); } bunit = dflag? "KB/S": "BYTE"; - printf(" %s PACK %s PACK RATIO | ", bunit, bunit); - printf(" %s PACK %s PACK RATIO", bunit, bunit); + printf(" %s PACK %s PACK RATIO ⎸ ", bunit, bunit); + printf(" %s PACK %s PACK RATIO", bunit, bunit); +} + putchar('\n'); } else { - printf("%8.8s %6.6s %6.6s", - "IN", "PACK", "VJCOMP"); +for (num = 0; num < numintf; num++) { + if (num != 0) { printf(" ⏐ "); } + if (!sflag) + printf("%9.9s %8.8s %8.8s", + "IN", "PACK", "VJCOMP"); + else + printf("%9.9s %8.8s", + "IN", "PACK"); - if (!rflag) - printf(" %6.6s %6.6s", "VJUNC", "VJERR"); - if (vflag) - printf(" %6.6s %6.6s", "VJTOSS", "NON-VJ"); + if (!sflag && !rflag) + printf(" %8.8s %8.8s", "VJUNC", "VJERR"); + if (!sflag && vflag) + printf(" %8.8s %8.8s", "VJTOSS", "NON-VJ"); if (rflag) - printf(" %6.6s %6.6s", "RATIO", "UBYTE"); - printf(" | %8.8s %6.6s %6.6s", - "OUT", "PACK", "VJCOMP"); - - if (!rflag) - printf(" %6.6s %6.6s", "VJUNC", "NON-VJ"); - if (vflag) - printf(" %6.6s %6.6s", "VJSRCH", "VJMISS"); + printf(" %8.8s %8.8s", "RATIO", "UBYTE"); + if (!sflag) + printf(" ⎸ %9.9s %8.8s %8.8s", + "OUT", "PACK", "VJCOMP"); + else + printf(" ⎸ %9.9s %8.8s", + "OUT", "PACK"); + + if (!sflag && !rflag) + printf(" %8.8s %8.8s", "VJUNC", "NON-VJ"); + if (!sflag && vflag) + printf(" %8.8s %8.8s", "VJSRCH", "VJMISS"); if (rflag) - printf(" %6.6s %6.6s", "RATIO", "UBYTE"); + printf(" %8.8s %8.8s", "RATIO", "UBYTE"); +} + putchar('\n'); } - putchar('\n'); } +for (num = 0; num < numintf; num++) { + if (num != 0) { printf(" ⏐ "); } if (zflag) { +if (!ok[num]) { + printf("%9s %8s %9s %8s %6s", "-", "-", "-", "-", "-", "-"); + printf(" ⎸ %9s %8s %9s %8s %6s", "-", "-", "-", "-", "-", "-"); +} else { if (ratef) { - printf("%8.3f %6u %8.3f %6u %6.2f", + printf("%9.3f %8u %9.3f %8u %6.2f", KBPS(W(d.comp_bytes)), W(d.comp_packets), KBPS(W(d.inc_bytes)), W(d.inc_packets), - ccs.d.ratio / 256.0); - printf(" | %8.3f %6u %8.3f %6u %6.2f", + ccs[num].d.ratio / 256.0); + printf(" ⎸ %9.3f %8u %9.3f %8u %6.2f", KBPS(W(c.comp_bytes)), W(c.comp_packets), KBPS(W(c.inc_bytes)), W(c.inc_packets), - ccs.c.ratio / 256.0); + ccs[num].c.ratio / 256.0); } else { - printf("%8u %6u %8u %6u %6.2f", + printf("%9u %8u %9u %8u %6.2f", W(d.comp_bytes), W(d.comp_packets), W(d.inc_bytes), W(d.inc_packets), - ccs.d.ratio / 256.0); - printf(" | %8u %6u %8u %6u %6.2f", + ccs[num].d.ratio / 256.0); + printf(" ⎸ %9u %8u %9u %8u %6.2f", W(c.comp_bytes), W(c.comp_packets), W(c.inc_bytes), W(c.inc_packets), - ccs.c.ratio / 256.0); + ccs[num].c.ratio / 256.0); } - +} } else { +if (!ok[num]) { + printf("%9s %8s", "-", "-"); + if (!sflag) printf(" %8s", "-"); + if (!sflag && !rflag) printf(" %8s %8s", "-", "-"); + if (!sflag && vflag) printf(" %8s %8s", "-", "-"); + if (rflag) printf(" %8s %8s", "-", "-"); + + printf(" ⎸ %9s %8s", "-", "-"); + if (!sflag) printf(" %8s", "-"); + if (!sflag && !rflag) printf(" %8s %8s", "-", "-"); + if (!sflag && vflag) printf(" %8s %8s", "-", "-"); + if (rflag) printf(" %8s %8s", "-", "-"); +} else { if (ratef) - printf("%8.3f", KBPS(V(p.ppp_ibytes))); + printf("%9.3f", KBPS(V(p.ppp_ibytes))); else - printf("%8u", V(p.ppp_ibytes)); - printf(" %6u %6u", - V(p.ppp_ipackets), - V(vj.vjs_compressedin)); - if (!rflag) - printf(" %6u %6u", + printf("%9u", V(p.ppp_ibytes)); + if (!sflag) + printf(" %8u %8u", + V(p.ppp_ipackets), + V(vj.vjs_compressedin)); + else + printf(" %8u", + V(p.ppp_ipackets)); + if (!sflag && !rflag) + printf(" %8u %8u", V(vj.vjs_uncompressedin), V(vj.vjs_errorin)); - if (vflag) - printf(" %6u %6u", + if (!sflag && vflag) + printf(" %8u %8u", V(vj.vjs_tossed), V(p.ppp_ipackets) - V(vj.vjs_compressedin) - V(vj.vjs_uncompressedin) - V(vj.vjs_errorin)); if (rflag) { - printf(" %6.2f ", CRATE(d)); + printf(" %8.2f ", CRATE(d)); if (ratef) - printf("%6.2f", KBPS(W(d.unc_bytes))); + printf("%8.2f", KBPS(W(d.unc_bytes))); else - printf("%6u", W(d.unc_bytes)); + printf("%8u", W(d.unc_bytes)); } if (ratef) - printf(" | %8.3f", KBPS(V(p.ppp_obytes))); + printf(" ⎸ %9.3f", KBPS(V(p.ppp_obytes))); + else + printf(" ⎸ %9u", V(p.ppp_obytes)); + if (!sflag) + printf(" %8u %8u", + V(p.ppp_opackets), + V(vj.vjs_compressed)); else - printf(" | %8u", V(p.ppp_obytes)); - printf(" %6u %6u", - V(p.ppp_opackets), - V(vj.vjs_compressed)); - if (!rflag) - printf(" %6u %6u", + printf(" %8u", + V(p.ppp_opackets)); + if (!sflag && !rflag) + printf(" %8u %8u", V(vj.vjs_packets) - V(vj.vjs_compressed), V(p.ppp_opackets) - V(vj.vjs_packets)); - if (vflag) - printf(" %6u %6u", + if (!sflag && vflag) + printf(" %8u %8u", V(vj.vjs_searches), V(vj.vjs_misses)); if (rflag) { - printf(" %6.2f ", CRATE(c)); + printf(" %8.2f ", CRATE(c)); if (ratef) - printf("%6.2f", KBPS(W(c.unc_bytes))); + printf("%8.2f", KBPS(W(c.unc_bytes))); else - printf("%6u", W(c.unc_bytes)); + printf("%8u", W(c.unc_bytes)); } - +} } +} putchar('\n'); fflush(stdout); line++; count--; if (!infinite && !count) break; - +#if 0 sigemptyset(&mask); sigaddset(&mask, SIGALRM); sigprocmask(SIG_BLOCK, &mask, &oldmask); if (!signalled) { @@ -432,14 +505,23 @@ } sigprocmask(SIG_SETMASK, &oldmask, NULL); signalled = 0; (void)alarm(interval); +#endif if (!aflag) { - old = cur; - ocs = ccs; +for (num = 0; num < numintf; num++) { +if (ok[num]) { + old[num] = cur[num]; + ocs[num] = ccs[num]; +} +} ratef = dflag; } + + now.tv_sec += interval; + now.tv_nsec = begin.tv_nsec; + clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &now, NULL); } } int @@ -451,15 +533,17 @@ #ifdef STREAMS char *dev; #endif +/* interface = PPP_DRV_NAME "0"; +*/ if ((progname = strrchr(argv[0], '/')) == NULL) progname = argv[0]; else ++progname; - while ((c = getopt(argc, argv, "advrzc:w:")) != -1) { + while ((c = getopt(argc, argv, "advrszc:w:")) != -1) { switch (c) { case 'a': ++aflag; break; @@ -471,8 +555,11 @@ break; case 'r': ++rflag; break; + case 's': + ++sflag; + break; case 'z': ++zflag; break; case 'c': @@ -500,14 +587,19 @@ count = 1; if (aflag) dflag = 0; + numintf = argc; + if (numintf == 0 || numintf > MAXINTF) + usage(); + interfaces = argv; + +/* if (argc > 1) usage(); if (argc > 0) interface = argv[0]; -/* if (sscanf(interface, PPP_DRV_NAME "%d", &unit) != 1) { fprintf(stderr, "%s: invalid interface '%s' specified\n", progname, interface); } @@ -527,14 +619,16 @@ #ifdef __linux__ #undef ifr_name #define ifr_name ifr_ifrn.ifrn_name #endif +/* strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name)); if (ioctl(s, SIOCGIFFLAGS, (caddr_t)&ifr) < 0) { fprintf(stderr, "%s: nonexistent interface '%s' specified\n", progname, interface); exit(1); } +*/ } #else /* STREAMS */ #ifdef __osf__