📄 pfstat.c
字号:
#ifndef lintstatic char *sccsid = "@(#)pfstat.c 4.2 (ULTRIX) 2/26/91";#endif lint/************************************************************************ * * * Copyright (c) 1989 by * * Digital Equipment Corporation, Maynard, MA * * All rights reserved. * * * * This software is furnished under a license and may be used and * * copied only in accordance with the terms of such license and * * with the inclusion of the above copyright notice. This * * software or any other copies thereof may not be provided or * * otherwise made available to any other person. No title to and * * ownership of the software is hereby transferred. * * * * This software is derived from software received from the * * University of California, Berkeley, and from Bell * * Laboratories. Use, duplication, or disclosure is subject to * * restrictions under license agreements with University of * * California and with AT&T. * * * * The information in this software is subject to change without * * notice and should not be construed as a commitment by Digital * * Equipment Corporation. * * * * Digital assumes no responsibility for the use or reliability * * of its software on equipment which is not supplied by Digital. * * * ************************************************************************//* * pfstat.c * * Print packet filter status & statistics: ULTRIX version * * HISTORY: * 8 August 1989 Jeffrey Mogul DECWRL * - Revised for ULTRIX 4.0 version * A few new state bits; "hz" now read from kernel; name change; * slight format change for AllDescriptors/LINK-QUEUE * * 29 November 1988 Jeffrey Mogul DECWRL * - Revised for ULTRIX 3.0 version * Mostly this means that the state tables are dynamically * allocated * * 8 October 1985 Jeff Mogul Stanford * - Revised for 4.3 version of driver. * * 17 October 1984 Jeff Mogul Stanford * - Prints RecvCount field; this comes out as part of * the "Filters" listing, even though it should probably be * with the "AllDescriptors" list, because it fits better on * the output lines. * * 3 October 1984 Jeff Mogul Stanford * - Prints state of "enOneCopy", if present * * 17 February 1984 Jeff Mogul Stanford * - Fixes from "decvax!genrad!grkermit!masscomp!clyde!watmath!arhwhite" * to: * make "k" option work (using core dumps instead of kmem); * * 15 February 1984 Jeff Mogul Stanford * - Added printout of underlying device name * * 20 December 1983 Jeffrey Mogul Stanford * - added unit number options ("01234567") * * 2 December 1983 Jeffrey Mogul Stanford * - added printout of new endevp structure, new "p" flag * * Jeffrey Mogul Stanford 28 April 1983 * * Derived from: * static char *sccsid = "@(#)pstat.c 4.9 (Berkeley) 5/7/81"; * and from * modifications thereto by Mike Accetta @ CMU */#define mask(x) (x&0377)#ifdef old#define clear(x) ((int)(x)&0x7FFFFFFF)#else#define clear(x) (x)#endif old#include <stdio.h>#include <sys/param.h>#include <sys/socket.h>#include <sys/time.h>#include <net/pfilt.h>#include <net/pfiltdefs.h>#include <sys/vm.h>#include <machine/pte.h>#include <net/if.h>#include <nlist.h>char *fcore = "/dev/kmem";char *fnlist = "/vmunix";int fc;int hz;struct nlist nl[] = {#define SENSTATEPS (0) { "_enStatePs" },#define SENQELTS (1) { "_enQueueElts" },#define SENFREEQ (2) { "_enFreeq" },#define SENUNITS (3) { "_enUnits" },#define SENFREEQMIN (4) { "_enFreeqMin" },#define SENSCAVENGES (5) { "_enScavenges" },#define SENDEBUG (6) { "_enDebug" },#define SENXFREEQ (7) { "_enXfreeq" },#define SENALLOC (8) { "_enAllocCount" },#define SENETINFO (9) { "_enet_info" },#define X_SYSMAP (10) { "_Sysmap" },#define X_SYSSIZE (11) { "_Syssize" },#define SENONECOPY (12) { "_enOneCopy" },#define SENMAXMINORS (13) { "_enMaxMinors" },#define SENALLOCMAP (14) { "_enAllocMap" },#define SENDESCRIPTORS (15) { "_enAllDescriptors" },#define SENUNITMAP (16) { "_enUnitMap" },#define SENREORDERCOUNT (17) { "_enReorderCount" },#define SENSCAVDROPS (18) { "_enScavDrops" },#define SENPERPKTPROF (19) { "_enPerPktProf" },#define SENPKTCOUNT (20) { "_enPktCount" },#define SENPERFILTPROF (21) { "_enPerFiltProf" },#define SENFILTCOUNT (22) { "_enFiltCount" },#define SHZ (23) { "_hz" }, 0,};int kflg = 0;int Verbose = 0;int Counts = 0;int FreeStats = 0;int Descriptors = 0;int Filters = 0;int QueueElements = 0;int Parameters = 0;int UnitMask = 0;main (argc, argv)char **argv;{ register char *argp; int something = 0; char *progname=argv[0]; argc--, argv++; while (argc > 0 && **argv == '-') { argp = *argv++; argp++; argc--; while (*argp++) switch (argp[-1]) { case 'k': kflg++; fcore = "/vmcore"; break; case 'v': Verbose++; break; case 'c': Counts++; something++; break; case 's': FreeStats++; something++; break; case 'd': Descriptors++; something++; break; case 'f': Filters++; something++; break; case 'q': QueueElements++; something++; break; case 'p': Parameters++; something++; break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': UnitMask |= (1<<(argp[-1] - '0')); break; default: fprintf(stderr, "Usage: %s [-kvcsdfqp01234567] [nlist [core]]\n", progname); fprintf(stderr, "\t(c=Counts, s=FreeStats, d=Descriptors, f=filters, q=QueueElts,\n"); fprintf(stderr, "\t p=Parameters); 0-7 specifies unit\n"); exit(1); } } if (!something) { /* if none given then use all */ Counts = FreeStats = Descriptors = Filters = QueueElements = 1; Parameters = 1; } if (argc > 0) { /* different system image */ fnlist = argv[0]; argv++; argc--; } if (argc > 0) fcore = argv[0]; if (UnitMask == 0) /* no specific units, do them all */ UnitMask = 0xFFFFFFFF; if ((fc = open (fcore, 0)) < 0) { fprintf (stderr, "%s: cannot open %s\n", progname, fcore); exit (1); } nlist (fnlist, nl); if (nl[0].n_type == 0) { /* printf ("no namelist\n"); */ printf("PACKETFILTER option is not configured in %s\n", fnlist); exit (1); } hz = nl[SHZ].n_value; doenet ();}/* copied from enet./sys/net/enet.c */struct enet_info { struct ifnet *ifp;};#define NEN 8 /* enough for a good long while XXX */int enMaxMinors;doenet () { struct enPacket enQueueElts[ENPACKETS]; struct enQueue enFreeq; struct enState enStateData[NEN]; struct enState *enStatePs[NEN]; struct enet_info enet_info[NEN]; u_char enAllocMap[256]; u_char enUnitMap[256]; struct enOpenDescriptor *enAllDescriptors[256]; struct enOpenDescriptor ThisDescriptor; int enFreeqMin, enScavenges, enScavDrops, enDebug, enUnits, enOneCopy; int enAllocCount, enReorderCount; int enPktCount, enFiltCount; struct timeval enPerPktProf, enPerFiltProf; register loc; register struct enOpenDescriptor *op; register struct enPacket *p; register int i; register struct enState *enStatep; int unit; klseek (fc, (long) nl[SENUNITS].n_value, 0); read (fc, &enUnits, sizeof (enUnits)); klseek (fc, (long) nl[SENMAXMINORS].n_value, 0); read (fc, &enMaxMinors, sizeof (enMaxMinors)); klseek (fc, (long) nl[SENSTATEPS].n_value, 0); read (fc, enStatePs, enUnits * sizeof (enStatePs)); for (i = 0; i < enUnits; i++) { klseek (fc, (long) enStatePs[i], 0); read (fc, &(enStateData[i]), sizeof(struct enState)); } klseek (fc, (long) nl[SENALLOCMAP].n_value, 0); read (fc, enAllocMap, enMaxMinors * sizeof(u_char)); klseek (fc, (long) nl[SENUNITMAP].n_value, 0); read (fc, enUnitMap, enMaxMinors * sizeof(u_char)); klseek (fc, (long) nl[SENDESCRIPTORS].n_value, 0); read (fc, enAllDescriptors, enMaxMinors * sizeof(struct enOpenDescriptor *)); klseek (fc, (long) nl[SENETINFO].n_value, 0); read (fc, enet_info, enUnits * sizeof (struct enet_info)); klseek (fc, (long) nl[SENQELTS].n_value, 0); read (fc, enQueueElts, sizeof (enQueueElts)); klseek (fc, (long) nl[SENFREEQ].n_value, 0); read (fc, &enFreeq, sizeof (enFreeq)); klseek (fc, (long) nl[SENFREEQMIN].n_value, 0); read (fc, &enFreeqMin, sizeof (enFreeqMin)); klseek (fc, (long) nl[SENSCAVENGES].n_value, 0); read (fc, &enScavenges, sizeof (enScavenges)); klseek (fc, (long) nl[SENSCAVDROPS].n_value, 0); read (fc, &enScavDrops, sizeof (enScavDrops)); klseek (fc, (long) nl[SENDEBUG].n_value, 0); read (fc, &enDebug, sizeof (enDebug)); if (nl[SENALLOC].n_type) { klseek (fc, (long) nl[SENALLOC].n_value, 0); read (fc, &enAllocCount, sizeof (enAllocCount)); } if (nl[SENREORDERCOUNT].n_type) { klseek (fc, (long) nl[SENREORDERCOUNT].n_value, 0); read (fc, &enReorderCount, sizeof (enReorderCount)); } if (nl[SENONECOPY].n_type) { klseek (fc, (long) nl[SENONECOPY].n_value, 0); read (fc, &enOneCopy, sizeof (enOneCopy)); } else { enOneCopy = -1; } if (nl[SENPERPKTPROF].n_type) { klseek (fc, (long) nl[SENPERPKTPROF].n_value, 0); read (fc, &enPerPktProf, sizeof (enPerPktProf)); } if (nl[SENPKTCOUNT].n_type) { klseek (fc, (long) nl[SENPKTCOUNT].n_value, 0); read (fc, &enPktCount, sizeof (enPktCount)); } if (nl[SENPERFILTPROF].n_type) { klseek (fc, (long) nl[SENPERFILTPROF].n_value, 0); read (fc, &enPerFiltProf, sizeof (enPerFiltProf)); } if (nl[SENFILTCOUNT].n_type) { klseek (fc, (long) nl[SENFILTCOUNT].n_value, 0); read (fc, &enFiltCount, sizeof (enFiltCount)); } if (FreeStats) { printf ("Scavenges:\t%d\t (%d packets dropped)\n", enScavenges, enScavDrops); if (nl[SENALLOC].n_type) printf ("Allocated:\t%d\n", enAllocCount); printf ("Freeq(%x): %d (Min %d) [%x,%x]\n", (nl[SENFREEQ].n_value), enFreeq.enQ_NumQueued, enFreeqMin, (enFreeq.enQ_F), (enFreeq.enQ_B)); if (enOneCopy >= 0) printf("OneCopy:\t%d\n", enOneCopy); if (nl[SENREORDERCOUNT].n_type) printf ("Queue priority reorderings:\t%d\n", enReorderCount); for (i = 0; i < enMaxMinors; i++) if (enAllocMap[i]) enAllocCount++; printf("Space allocated for descriptors: %d bytes\n", enAllocCount * sizeof(struct enOpenDescriptor)); if (nl[SENPERPKTPROF].n_type && nl[SENPKTCOUNT].n_type) { if (enPktCount) printf("uSecs/packet:\t%.0f", ((enPerPktProf.tv_sec * 1000000.0) + enPerPktProf.tv_usec)/ (enPktCount + 0.0)); else printf("uSecs/packet:\tNo packets"); if (enFiltCount) printf("\t\t"); else printf("\n"); } if (nl[SENPERFILTPROF].n_type && nl[SENFILTCOUNT].n_type) { if (enFiltCount) printf("uSecs/filter execution:\t%.0f\n", ((enPerFiltProf.tv_sec * 1000000.0) + enPerFiltProf.tv_usec)/ (enFiltCount + 0.0)); else printf("uSecs/filter execution:\tNone executed\n"); if (enFiltCount && enPktCount) printf("Avg. filters executed/packet:\t%.2f\n", (enFiltCount + 0.0)/(enPktCount + 0.0)); } printf ("\n"); } for (unit = 0; unit < enUnits; unit++) { enStatep = &(enStateData[unit]); if ((UnitMask & (1<<unit)) == 0) /* skip this unit */ continue; if (enDesq.enQ_F == 0) /* probably not needed any more */ continue; if (Counts || Parameters || Descriptors || Filters) { printf ("\npf%d:\n\n", unit); } if (Counts) { printf ("Xcnt:\t\t%-8d\tRcnt:\t\t%-8d\n", enXcnt, enRcnt);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -