diff options
author | Kjell Wooding <kjell@cvs.openbsd.org> | 2001-01-30 04:27:59 +0000 |
---|---|---|
committer | Kjell Wooding <kjell@cvs.openbsd.org> | 2001-01-30 04:27:59 +0000 |
commit | 179da94f00485297271ab125a979af18d674333a (patch) | |
tree | a78d5b596205a14059ec7419a6041b5eefe3f267 | |
parent | 1a1e454b4bba88f2fa856f317639c83249c18974 (diff) |
reimplement whacked ipfstat changes
-rw-r--r-- | sbin/ipfstat/fils.c | 210 | ||||
-rw-r--r-- | sbin/ipfstat/kmem.c | 14 | ||||
-rw-r--r-- | sbin/ipfstat/kmem.h | 7 |
3 files changed, 123 insertions, 108 deletions
diff --git a/sbin/ipfstat/fils.c b/sbin/ipfstat/fils.c index cbf412089c3..c39f91e862c 100644 --- a/sbin/ipfstat/fils.c +++ b/sbin/ipfstat/fils.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fils.c,v 1.23 2001/01/17 05:01:00 fgsch Exp $ */ +/* $OpenBSD: fils.c,v 1.24 2001/01/30 04:27:58 kjell Exp $ */ /* * Copyright (C) 1993-2000 by Darren Reed. @@ -49,7 +49,7 @@ # include <netinet/ip_var.h> # include <netinet/tcp_fsm.h> #endif -#include <netinet/ip_compat.h> +#include <netinet/ip_fil_compat.h> #include <netinet/ip_fil.h> #include "ipf.h" #include <netinet/ip_proxy.h> @@ -70,10 +70,6 @@ static const char sccsid[] = "@(#)fils.c 1.21 4/20/96 (C) 1993-2000 Darren Reed" static const char rcsid[] = "@(#)$IPFilter: fils.c,v 2.21.2.7 2000/12/02 00:13:56 darrenr Exp $"; #endif -extern char *optarg; - -#define PRINTF (void)printf -#define FPRINTF (void)fprintf #define F_IN 0 #define F_OUT 1 #define F_AC 2 @@ -110,6 +106,8 @@ typedef struct statetop { } statetop_t; #endif +char *nlistf = NULL, *memf = NULL; + extern int main __P((int, char *[])); static void showstats __P((int, friostat_t *)); static void showfrstates __P((int, ipfrstat_t *)); @@ -158,9 +156,11 @@ static void Usage(name) char *name; { #ifdef USE_INET6 - fprintf(stderr, "Usage: %s [-6aAfhIinosv] [-d <device>]\n", name); + fprintf(stderr, + "Usage: %s [-6aAfhIinosv] [-d <device>] [-M core]\n", name); #else - fprintf(stderr, "Usage: %s [-aAfhIinosv] [-d <device>]\n", name); + fprintf(stderr, + "Usage: %s [-aAfhIinosv] [-d <device>] [-M core]\n", name); #endif fprintf(stderr, " %s -t [-S source address] [-D destination address] [-P protocol] [-T refreshtime] [-C] [-d <device>]\n", name); exit(1); @@ -192,13 +192,7 @@ char *argv[]; saddr.s_addr = INADDR_ANY; /* default any source addr */ daddr.s_addr = INADDR_ANY; /* default any dest addr */ - if (openkmem() == -1) - exit(-1); - - (void)setuid(getuid()); - (void)setgid(getgid()); - - while ((c = getopt(argc, argv, "6aACfghIilnostvd:D:P:S:T:")) != -1) + while ((c = getopt(argc, argv, "6aACfghIilnostvd:M:D:P:S:T:")) != -1) { switch (c) { @@ -244,6 +238,9 @@ char *argv[]; case 'n' : opts |= OPT_SHOWLINENO; break; + case 'M' : + memf = optarg; + break; case 'o' : opts |= OPT_OUTQUE|OPT_SHOWLIST; break; @@ -291,6 +288,17 @@ char *argv[]; } } + if (nlistf != NULL || memf != NULL) { + (void)setuid(getuid()); + (void)setgid(getgid()); + } + + if (openkmem(nlistf, memf) == -1) + exit(-1); + + (void)setuid(getuid()); + (void)setgid(getgid()); + if ((fd = open(device, O_RDONLY)) < 0) { perror("open"); exit(-1); @@ -323,7 +331,7 @@ char *argv[]; } if (opts & OPT_VERBOSE) - PRINTF("opts %#x name %s\n", opts, name ? name : "<>"); + printf("opts %#x name %s\n", opts, name ? name : "<>"); if ((opts & OPT_AUTHSTATS) && (ioctl(fd, SIOCATHST, &frauthstp) == -1)) { @@ -371,72 +379,72 @@ struct friostat *fp; perror("ioctl(SIOCGETFF)"); #if SOLARIS - PRINTF("dropped packets:\tin %lu\tout %lu\n", + printf("dropped packets:\tin %lu\tout %lu\n", fp->f_st[0].fr_drop, fp->f_st[1].fr_drop); - PRINTF("non-data packets:\tin %lu\tout %lu\n", + printf("non-data packets:\tin %lu\tout %lu\n", fp->f_st[0].fr_notdata, fp->f_st[1].fr_notdata); - PRINTF("no-data packets:\tin %lu\tout %lu\n", + printf("no-data packets:\tin %lu\tout %lu\n", fp->f_st[0].fr_nodata, fp->f_st[1].fr_nodata); - PRINTF("non-ip packets:\t\tin %lu\tout %lu\n", + printf("non-ip packets:\t\tin %lu\tout %lu\n", fp->f_st[0].fr_notip, fp->f_st[1].fr_notip); - PRINTF(" bad packets:\t\tin %lu\tout %lu\n", + printf(" bad packets:\t\tin %lu\tout %lu\n", fp->f_st[0].fr_bad, fp->f_st[1].fr_bad); - PRINTF("copied messages:\tin %lu\tout %lu\n", + printf("copied messages:\tin %lu\tout %lu\n", fp->f_st[0].fr_copy, fp->f_st[1].fr_copy); #endif #ifdef USE_INET6 - PRINTF(" IPv6 packets:\t\tin %lu out %lu\n", + printf(" IPv6 packets:\t\tin %lu out %lu\n", fp->f_st[0].fr_ipv6[0], fp->f_st[0].fr_ipv6[1]); #endif - PRINTF(" input packets:\t\tblocked %lu passed %lu nomatch %lu", + printf(" input packets:\t\tblocked %lu passed %lu nomatch %lu", fp->f_st[0].fr_block, fp->f_st[0].fr_pass, fp->f_st[0].fr_nom); - PRINTF(" counted %lu short %lu\n", + printf(" counted %lu short %lu\n", fp->f_st[0].fr_acct, fp->f_st[0].fr_short); - PRINTF("output packets:\t\tblocked %lu passed %lu nomatch %lu", + printf("output packets:\t\tblocked %lu passed %lu nomatch %lu", fp->f_st[1].fr_block, fp->f_st[1].fr_pass, fp->f_st[1].fr_nom); - PRINTF(" counted %lu short %lu\n", + printf(" counted %lu short %lu\n", fp->f_st[1].fr_acct, fp->f_st[1].fr_short); - PRINTF(" input packets logged:\tblocked %lu passed %lu\n", + printf(" input packets logged:\tblocked %lu passed %lu\n", fp->f_st[0].fr_bpkl, fp->f_st[0].fr_ppkl); - PRINTF("output packets logged:\tblocked %lu passed %lu\n", + printf("output packets logged:\tblocked %lu passed %lu\n", fp->f_st[1].fr_bpkl, fp->f_st[1].fr_ppkl); - PRINTF(" packets logged:\tinput %lu output %lu\n", + printf(" packets logged:\tinput %lu output %lu\n", fp->f_st[0].fr_pkl, fp->f_st[1].fr_pkl); - PRINTF(" log failures:\t\tinput %lu output %lu\n", + printf(" log failures:\t\tinput %lu output %lu\n", fp->f_st[0].fr_skip, fp->f_st[1].fr_skip); - PRINTF("fragment state(in):\tkept %lu\tlost %lu\n", + printf("fragment state(in):\tkept %lu\tlost %lu\n", fp->f_st[0].fr_nfr, fp->f_st[0].fr_bnfr); - PRINTF("fragment state(out):\tkept %lu\tlost %lu\n", + printf("fragment state(out):\tkept %lu\tlost %lu\n", fp->f_st[1].fr_nfr, fp->f_st[1].fr_bnfr); - PRINTF("packet state(in):\tkept %lu\tlost %lu\n", + printf("packet state(in):\tkept %lu\tlost %lu\n", fp->f_st[0].fr_ads, fp->f_st[0].fr_bads); - PRINTF("packet state(out):\tkept %lu\tlost %lu\n", + printf("packet state(out):\tkept %lu\tlost %lu\n", fp->f_st[1].fr_ads, fp->f_st[1].fr_bads); - PRINTF("ICMP replies:\t%lu\tTCP RSTs sent:\t%lu\n", + printf("ICMP replies:\t%lu\tTCP RSTs sent:\t%lu\n", fp->f_st[0].fr_ret, fp->f_st[1].fr_ret); - PRINTF("Invalid source(in):\t%lu\n", fp->f_st[0].fr_badsrc); - PRINTF("Result cache hits(in):\t%lu\t(out):\t%lu\n", + printf("Invalid source(in):\t%lu\n", fp->f_st[0].fr_badsrc); + printf("Result cache hits(in):\t%lu\t(out):\t%lu\n", fp->f_st[0].fr_chit, fp->f_st[1].fr_chit); - PRINTF("IN Pullups succeeded:\t%lu\tfailed:\t%lu\n", + printf("IN Pullups succeeded:\t%lu\tfailed:\t%lu\n", fp->f_st[0].fr_pull[0], fp->f_st[0].fr_pull[1]); - PRINTF("OUT Pullups succeeded:\t%lu\tfailed:\t%lu\n", + printf("OUT Pullups succeeded:\t%lu\tfailed:\t%lu\n", fp->f_st[1].fr_pull[0], fp->f_st[1].fr_pull[1]); - PRINTF("Fastroute successes:\t%lu\tfailures:\t%lu\n", + printf("Fastroute successes:\t%lu\tfailures:\t%lu\n", fp->f_froute[0], fp->f_froute[1]); - PRINTF("TCP cksum fails(in):\t%lu\t(out):\t%lu\n", + printf("TCP cksum fails(in):\t%lu\t(out):\t%lu\n", fp->f_st[0].fr_tcpbad, fp->f_st[1].fr_tcpbad); - PRINTF("Packet log flags set: (%#x)\n", frf); + printf("Packet log flags set: (%#x)\n", frf); if (frf & FF_LOGPASS) - PRINTF("\tpackets passed through filter\n"); + printf("\tpackets passed through filter\n"); if (frf & FF_LOGBLOCK) - PRINTF("\tpackets blocked by filter\n"); + printf("\tpackets blocked by filter\n"); if (frf & FF_LOGNOMATCH) - PRINTF("\tpackets not matched by filter\n"); + printf("\tpackets not matched by filter\n"); if (!frf) - PRINTF("\tnone\n"); + printf("\tnone\n"); } @@ -456,18 +464,18 @@ frentry_t *fp; fp->fr_flags |= FR_OUTQUE; if (opts & (OPT_HITS|OPT_VERBOSE)) #ifdef USE_QUAD_T - PRINTF("%qu ", (unsigned long long) fp->fr_hits); + printf("%qu ", (unsigned long long) fp->fr_hits); #else - PRINTF("%lu ", fp->fr_hits); + printf("%lu ", fp->fr_hits); #endif if (opts & (OPT_ACCNT|OPT_VERBOSE)) #ifdef USE_QUAD_T - PRINTF("%qu ", (unsigned long long) fp->fr_bytes); + printf("%qu ", (unsigned long long) fp->fr_bytes); #else - PRINTF("%lu ", fp->fr_bytes); + printf("%lu ", fp->fr_bytes); #endif if (opts & OPT_SHOWLINENO) - PRINTF("@%d ", n); + printf("@%d ", n); printfr(fp); if (opts & OPT_VERBOSE) binprint(fp); @@ -497,7 +505,7 @@ struct friostat *fiop; } else if (opts & OPT_INQUE) fp = (struct frentry *)fiop->f_acctin[set]; else { - FPRINTF(stderr, "No -i or -o given with -a\n"); + fprintf(stderr, "No -i or -o given with -a\n"); return; } } else { @@ -520,12 +528,12 @@ struct friostat *fiop; return; } if (opts & OPT_VERBOSE) - FPRINTF(stderr, "showlist:opts %#x i %d\n", opts, i); + fprintf(stderr, "showlist:opts %#x i %d\n", opts, i); if (opts & OPT_VERBOSE) - PRINTF("fp %p set %d\n", fp, set); + printf("fp %p set %d\n", fp, set); if (!fp) { - FPRINTF(stderr, "empty list for %s%s\n", + fprintf(stderr, "empty list for %s%s\n", (opts & OPT_INACTIVE) ? "inactive " : "", filters[i]); return; } @@ -540,13 +548,13 @@ ips_stat_t *ipsp; ipstate_t *istab[IPSTATE_SIZE], ips; if (!(opts & OPT_SHOWLIST)) { - PRINTF("IP states added:\n\t%lu TCP\n\t%lu UDP\n\t%lu ICMP\n", + printf("IP states added:\n\t%lu TCP\n\t%lu UDP\n\t%lu ICMP\n", ipsp->iss_tcp, ipsp->iss_udp, ipsp->iss_icmp); - PRINTF("\t%lu hits\n\t%lu misses\n", ipsp->iss_hits, + printf("\t%lu hits\n\t%lu misses\n", ipsp->iss_hits, ipsp->iss_miss); - PRINTF("\t%lu maximum\n\t%lu no memory\n\t%lu bkts in use\n", + printf("\t%lu maximum\n\t%lu no memory\n\t%lu bkts in use\n", ipsp->iss_max, ipsp->iss_nomem, ipsp->iss_inuse); - PRINTF("\t%lu active\n\t%lu expired\n\t%lu closed\n", + printf("\t%lu active\n\t%lu expired\n\t%lu closed\n", ipsp->iss_active, ipsp->iss_expire, ipsp->iss_fin); return; } @@ -558,106 +566,106 @@ ips_stat_t *ipsp; if (kmemcpy((char *)&ips, (u_long)ipsp->iss_list, sizeof(ips))) break; ipsp->iss_list = ips.is_next; - PRINTF("%s -> ", hostname(ips.is_v, &ips.is_src.in4)); - PRINTF("%s ttl %ld pass %#x pr %d state %d/%d\n", + printf("%s -> ", hostname(ips.is_v, &ips.is_src.in4)); + printf("%s ttl %ld pass %#x pr %d state %d/%d\n", hostname(ips.is_v, &ips.is_dst.in4), ips.is_age, ips.is_pass, ips.is_p, ips.is_state[0], ips.is_state[1]); #ifdef USE_QUAD_T - PRINTF("\tpkts %qu bytes %qu", + printf("\tpkts %qu bytes %qu", (unsigned long long) ips.is_pkts, (unsigned long long) ips.is_bytes); #else - PRINTF("\tpkts %ld bytes %ld", ips.is_pkts, ips.is_bytes); + printf("\tpkts %ld bytes %ld", ips.is_pkts, ips.is_bytes); #endif if (ips.is_p == IPPROTO_TCP) #if defined(NetBSD) && (NetBSD >= 199905) && (NetBSD < 1991011) || \ (__FreeBSD_version >= 220000) || defined(__OpenBSD__) - PRINTF("\t%hu -> %hu %x:%x %hu:%hu", + printf("\t%hu -> %hu %x:%x %hu:%hu", ntohs(ips.is_sport), ntohs(ips.is_dport), ips.is_send, ips.is_dend, ips.is_maxswin, ips.is_maxdwin); #else - PRINTF("\t%hu -> %hu %x:%x %hu:%hu", + printf("\t%hu -> %hu %x:%x %hu:%hu", ntohs(ips.is_sport), ntohs(ips.is_dport), ips.is_send, ips.is_dend, ips.is_maxswin, ips.is_maxdwin); #endif else if (ips.is_p == IPPROTO_UDP) - PRINTF(" %hu -> %hu", ntohs(ips.is_sport), + printf(" %hu -> %hu", ntohs(ips.is_sport), ntohs(ips.is_dport)); else if (ips.is_p == IPPROTO_ICMP #ifdef USE_INET6 || ips.is_p == IPPROTO_ICMPV6 #endif ) - PRINTF(" %hu %hu %d", ips.is_icmp.ics_id, + printf(" %hu %hu %d", ips.is_icmp.ics_id, ips.is_icmp.ics_seq, ips.is_icmp.ics_type); - PRINTF("\n\t"); + printf("\n\t"); if (ips.is_pass & FR_PASS) { - PRINTF("pass"); + printf("pass"); } else if (ips.is_pass & FR_BLOCK) { - PRINTF("block"); + printf("block"); switch (ips.is_pass & FR_RETMASK) { case FR_RETICMP : - PRINTF(" return-icmp"); + printf(" return-icmp"); break; case FR_FAKEICMP : - PRINTF(" return-icmp-as-dest"); + printf(" return-icmp-as-dest"); break; case FR_RETRST : - PRINTF(" return-rst"); + printf(" return-rst"); break; default : break; } } else if ((ips.is_pass & FR_LOGMASK) == FR_LOG) { - PRINTF("log"); + printf("log"); if (ips.is_pass & FR_LOGBODY) - PRINTF(" body"); + printf(" body"); if (ips.is_pass & FR_LOGFIRST) - PRINTF(" first"); + printf(" first"); } else if (ips.is_pass & FR_ACCOUNT) - PRINTF("count"); + printf("count"); if (ips.is_pass & FR_OUTQUE) - PRINTF(" out"); + printf(" out"); else - PRINTF(" in"); + printf(" in"); if ((ips.is_pass & FR_LOG) != 0) { - PRINTF(" log"); + printf(" log"); if (ips.is_pass & FR_LOGBODY) - PRINTF(" body"); + printf(" body"); if (ips.is_pass & FR_LOGFIRST) - PRINTF(" first"); + printf(" first"); if (ips.is_pass & FR_LOGORBLOCK) - PRINTF(" or-block"); + printf(" or-block"); } if (ips.is_pass & FR_QUICK) - PRINTF(" quick"); + printf(" quick"); if (ips.is_pass & FR_KEEPFRAG) - PRINTF(" keep frags"); + printf(" keep frags"); /* a given; no? */ if (ips.is_pass & FR_KEEPSTATE) - PRINTF(" keep state"); - PRINTF("\tIPv%d", ips.is_v); - PRINTF("\n"); + printf(" keep state"); + printf("\tIPv%d", ips.is_v); + printf("\n"); - PRINTF("\tpkt_flags & %x(%x) = %x,\t", + printf("\tpkt_flags & %x(%x) = %x,\t", ips.is_flags & 0xf, ips.is_flags, ips.is_flags >> 4); - PRINTF("\tpkt_options & %x = %x\n", ips.is_optmsk, + printf("\tpkt_options & %x = %x\n", ips.is_optmsk, ips.is_opt); - PRINTF("\tpkt_security & %x = %x, pkt_auth & %x = %x\n", + printf("\tpkt_security & %x = %x, pkt_auth & %x = %x\n", ips.is_secmsk, ips.is_sec, ips.is_authmsk, ips.is_auth); - PRINTF("interfaces: in %s[%p] ", + printf("interfaces: in %s[%p] ", get_ifname(ips.is_ifpin), ips.is_ifpin); - PRINTF("out %s[%p]\n", + printf("out %s[%p]\n", get_ifname(ips.is_ifpout), ips.is_ifpout); } } @@ -974,11 +982,11 @@ ipfrstat_t *ifsp; frentry_t fr; int i; - PRINTF("IP fragment states:\n\t%lu new\n\t%lu expired\n\t%lu hits\n", + printf("IP fragment states:\n\t%lu new\n\t%lu expired\n\t%lu hits\n", ifsp->ifs_new, ifsp->ifs_expire, ifsp->ifs_hits); - PRINTF("\t%lu no memory\n\t%lu already exist\n", + printf("\t%lu no memory\n\t%lu already exist\n", ifsp->ifs_nomem, ifsp->ifs_exists); - PRINTF("\t%lu inuse\n", ifsp->ifs_inuse); + printf("\t%lu inuse\n", ifsp->ifs_inuse); if (kmemcpy((char *)ipfrtab, (u_long)ifsp->ifs_table, sizeof(ipfrtab))) return; for (i = 0; i < IPFT_SIZE; i++) @@ -986,11 +994,11 @@ ipfrstat_t *ifsp; if (kmemcpy((char *)&ifr, (u_long)ipfrtab[i], sizeof(ifr)) == -1) break; - PRINTF("%s -> ", hostname(4, &ifr.ipfr_src)); + printf("%s -> ", hostname(4, &ifr.ipfr_src)); if (kmemcpy((char *)&fr, (u_long)ifr.ipfr_rule, sizeof(fr)) == -1) break; - PRINTF("%s %d %d %d %#02x = %#x\n", + printf("%s %d %d %d %#02x = %#x\n", hostname(4, &ifr.ipfr_dst), ifr.ipfr_id, ifr.ipfr_ttl, ifr.ipfr_p, ifr.ipfr_tos, fr.fr_flags); @@ -1003,11 +1011,11 @@ ipfrstat_t *ifsp; if (kmemcpy((char *)&ifr, (u_long)ipfrtab[i], sizeof(ifr)) == -1) break; - PRINTF("NAT: %s -> ", hostname(4, &ifr.ipfr_src)); + printf("NAT: %s -> ", hostname(4, &ifr.ipfr_src)); if (kmemcpy((char *)&fr, (u_long)ifr.ipfr_rule, sizeof(fr)) == -1) break; - PRINTF("%s %d %d %d %#02x = %#x\n", + printf("%s %d %d %d %#02x = %#x\n", hostname(4, &ifr.ipfr_dst), ifr.ipfr_id, ifr.ipfr_ttl, ifr.ipfr_p, ifr.ipfr_tos, fr.fr_flags); diff --git a/sbin/ipfstat/kmem.c b/sbin/ipfstat/kmem.c index 7674d78999d..543da82be64 100644 --- a/sbin/ipfstat/kmem.c +++ b/sbin/ipfstat/kmem.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kmem.c,v 1.16 2001/01/17 05:01:00 fgsch Exp $ */ +/* $OpenBSD: kmem.c,v 1.17 2001/01/30 04:27:58 kjell Exp $ */ /* * Copyright (C) 1993-2000 by Darren Reed. @@ -27,9 +27,13 @@ static const char rcsid[] = "@(#)$IPFilter: kmem.c,v 2.2 2000/03/13 22:10:25 dar static int kmemfd = -1; -int openkmem() +int openkmem(nlistf, memf) +char *nlistf, *memf; { - if ((kmemfd = open(KMEM,O_RDONLY)) == -1) + if (memf == NULL) + memf = KMEM; + + if ((kmemfd = open(memf,O_RDONLY)) == -1) { perror("kmeminit:open"); return -1; @@ -47,7 +51,7 @@ register int n; if (!n) return 0; if (kmemfd == -1) - if (openkmem() == -1) + if (openkmem(nlistf, memf) == -1) return -1; if (lseek(kmemfd, pos, 0) == -1) { @@ -78,7 +82,7 @@ register int n; if (!n) return 0; if (kmemfd == -1) - if (openkmem() == -1) + if (openkmem(nlistf, memf) == -1) return -1; if (lseek(kmemfd, pos, 0) == -1) { diff --git a/sbin/ipfstat/kmem.h b/sbin/ipfstat/kmem.h index 61b4ad24de4..29625d8f478 100644 --- a/sbin/ipfstat/kmem.h +++ b/sbin/ipfstat/kmem.h @@ -1,4 +1,4 @@ -/* $OpenBSD: kmem.h,v 1.13 2001/01/17 05:01:01 fgsch Exp $ */ +/* $OpenBSD: kmem.h,v 1.14 2001/01/30 04:27:58 kjell Exp $ */ /* * Copyright (C) 1993-2000 by Darren Reed. @@ -19,7 +19,7 @@ # define __P(x) () # endif #endif -extern int openkmem __P((void)); +extern int openkmem __P((char *, char *)); extern int kmemcpy __P((char *, long, int)); extern int kstrncpy __P((char *, long, int)); @@ -27,6 +27,9 @@ extern int kstrncpy __P((char *, long, int)); # include <paths.h> #endif +extern char *nlistf; +extern char *memf; + #ifdef _PATH_KMEM # define KMEM _PATH_KMEM #else |