summaryrefslogtreecommitdiff
path: root/tools/ipftest.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/ipftest.c')
-rw-r--r--tools/ipftest.c414
1 files changed, 237 insertions, 177 deletions
diff --git a/tools/ipftest.c b/tools/ipftest.c
index 8343b2c3b27c1..495bdf4755594 100644
--- a/tools/ipftest.c
+++ b/tools/ipftest.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2002-2006 by Darren Reed.
+ * Copyright (C) 2012 by Darren Reed.
*
* See the IPFILTER.LICENCE file for details on licencing.
*/
@@ -10,24 +10,23 @@
#if !defined(lint)
static const char sccsid[] = "@(#)ipt.c 1.19 6/3/96 (C) 1993-2000 Darren Reed";
-static const char rcsid[] = "@(#)$Id: ipftest.c,v 1.44.2.13 2006/12/12 16:13:01 darrenr Exp $";
+static const char rcsid[] = "@(#)$Id$";
#endif
extern char *optarg;
-extern struct frentry *ipfilter[2][2];
-extern struct ipread snoop, etherf, tcpd, pcap, iptext, iphex;
+extern struct ipread pcap, iptext, iphex;
extern struct ifnet *get_unit __P((char *, int));
extern void init_ifp __P((void));
extern ipnat_t *natparse __P((char *, int));
-extern int fr_running;
extern hostmap_t **ipf_hm_maptable;
extern hostmap_t *ipf_hm_maplist;
-ipfmutex_t ipl_mutex, ipf_authmx, ipf_rw, ipf_stinsert;
+ipfmutex_t ipl_mutex, ipf_auth_mx, ipf_rw, ipf_stinsert;
ipfmutex_t ipf_nat_new, ipf_natio, ipf_timeoutlock;
ipfrwlock_t ipf_mutex, ipf_global, ipf_ipidfrag, ip_poolrw, ipf_frcache;
-ipfrwlock_t ipf_frag, ipf_state, ipf_nat, ipf_natfrag, ipf_auth, ipf_tokens;
-int opts = OPT_DONOTHING;
+ipfrwlock_t ipf_frag, ipf_state, ipf_nat, ipf_natfrag, ipf_authlk;
+ipfrwlock_t ipf_tokens;
+int opts = OPT_DONTOPEN;
int use_inet6 = 0;
int docksum = 0;
int pfil_delayed_copy = 0;
@@ -35,10 +34,10 @@ int main __P((int, char *[]));
int loadrules __P((char *, int));
int kmemcpy __P((char *, long, int));
int kstrncpy __P((char *, long, int n));
-void dumpnat __P((void));
-void dumpstate __P((void));
-void dumplookups __P((void));
-void dumpgroups __P((void));
+int blockreason;
+void dumpnat __P((void *));
+void dumpgroups __P((ipf_main_softc_t *));
+void dumprules __P((frentry_t *));
void drain_log __P((char *));
void fixv4sums __P((mb_t *, ip_t *));
@@ -70,18 +69,20 @@ static ioctlfunc_t iocfunctions[IPL_LOGSIZE] = { ipftestioctl,
ipscantestioctl,
ipooltestioctl,
NULL };
+static ipf_main_softc_t *softc = NULL;
-int main(argc,argv)
-int argc;
-char *argv[];
+int
+main(argc,argv)
+ int argc;
+ char *argv[];
{
char *datain, *iface, *ifname, *logout;
int fd, i, dir, c, loaded, dump, hlen;
struct in_addr sip;
struct ifnet *ifp;
struct ipread *r;
- mb_t mb, *m;
+ mb_t mb, *m, *n;
ip_t *ip;
m = &mb;
@@ -96,18 +97,20 @@ char *argv[];
sip.s_addr = 0;
ifname = "anon0";
- MUTEX_INIT(&ipf_rw, "ipf rw mutex");
- MUTEX_INIT(&ipf_timeoutlock, "ipf timeout lock");
- RWLOCK_INIT(&ipf_global, "ipf filter load/unload mutex");
- RWLOCK_INIT(&ipf_mutex, "ipf filter rwlock");
- RWLOCK_INIT(&ipf_ipidfrag, "ipf IP NAT-Frag rwlock");
- RWLOCK_INIT(&ipf_frcache, "ipf filter cache");
- RWLOCK_INIT(&ipf_tokens, "ipf token rwlock");
-
initparse();
- if (fr_initialise() == -1)
- abort();
- fr_running = 1;
+
+ ipf_load_all();
+
+ softc = ipf_create_all(NULL);
+ if (softc == NULL)
+ exit(1);
+
+ if (ipf_init_all(softc) == -1)
+ exit(1);
+
+ i = 1;
+ if (ipftestioctl(IPL_LOGIPF, SIOCFRENB, &i) != 0)
+ exit(1);
while ((c = getopt(argc, argv, "6bCdDF:i:I:l:N:P:or:RS:T:vxX")) != -1)
switch (c)
@@ -135,12 +138,6 @@ char *argv[];
case 'F' :
if (strcasecmp(optarg, "pcap") == 0)
r = &pcap;
- else if (strcasecmp(optarg, "etherfind") == 0)
- r = &etherf;
- else if (strcasecmp(optarg, "snoop") == 0)
- r = &snoop;
- else if (strcasecmp(optarg, "tcpdump") == 0)
- r = &tcpd;
else if (strcasecmp(optarg, "hex") == 0)
r = &iphex;
else if (strcasecmp(optarg, "text") == 0)
@@ -206,18 +203,21 @@ char *argv[];
else
fd = (*r->r_open)("-");
- if (fd < 0)
+ if (fd < 0) {
+ perror("error opening input");
exit(-1);
+ }
+
+ m->m_data = (char *)m->mb_buf;
+ while ((i = (*r->r_readip)(m, &iface, &dir)) > 0) {
- ip = MTOD(m, ip_t *);
- while ((i = (*r->r_readip)(MTOD(m, char *), sizeof(m->mb_buf),
- &iface, &dir)) > 0) {
if ((iface == NULL) || (*iface == '\0'))
iface = ifname;
+
+ ip = MTOD(m, ip_t *);
ifp = get_unit(iface, IP_V(ip));
- if (!use_inet6) {
- ip->ip_off = ntohs(ip->ip_off);
- ip->ip_len = ntohs(ip->ip_len);
+
+ if (IP_V(ip) == 4) {
if ((r->r_flags & R_DO_CKSUM) || docksum)
fixv4sums(m, ip);
hlen = IP_HL(ip) << 2;
@@ -229,9 +229,11 @@ char *argv[];
hlen = sizeof(ip6_t);
#endif
/* ipfr_slowtimer(); */
+ blockreason = 0;
m = &mb;
+ m->mb_ifp = ifp;
m->mb_len = i;
- i = fr_check(ip, hlen, ifp, dir, &m);
+ i = ipf_check(softc, ip, hlen, ifp, dir, &m);
if ((opts & OPT_NAT) == 0)
switch (i)
{
@@ -269,17 +271,24 @@ char *argv[];
(void)printf("recognised return %#x\n", i);
break;
}
- if (!use_inet6) {
- ip->ip_off = htons(ip->ip_off);
- ip->ip_len = htons(ip->ip_len);
- }
if (!(opts & OPT_BRIEF)) {
putchar(' ');
- printpacket(ip);
+ if (m != NULL)
+ printpacket(dir, m);
+ else
+ printpacket(dir, &mb);
printf("--------------");
- } else if ((opts & (OPT_BRIEF|OPT_NAT)) == (OPT_NAT|OPT_BRIEF))
- printpacket(ip);
+ } else if ((opts & (OPT_BRIEF|OPT_NAT)) ==
+ (OPT_NAT|OPT_BRIEF)) {
+ if (m != NULL)
+ printpacket(dir, m);
+ else
+ PRINTF("%d\n", blockreason);
+ }
+
+ ipf_state_flush(softc, 1, 0);
+
if (dir && (ifp != NULL) && IP_V(ip) && (m != NULL))
#if defined(__sgi) && (IRIX < 60500)
(*ifp->if_output)(ifp, (void *)m, NULL);
@@ -290,6 +299,13 @@ char *argv[];
(*ifp->if_output)(ifp, (void *)m, NULL, 0);
# endif
#endif
+
+ while ((m != NULL) && (m != &mb)) {
+ n = m->mb_next;
+ freembt(m);
+ m = n;
+ }
+
if ((opts & (OPT_BRIEF|OPT_NAT)) != (OPT_NAT|OPT_BRIEF))
putchar('\n');
dir = 0;
@@ -298,6 +314,7 @@ char *argv[];
iface = ifname;
}
m = &mb;
+ m->mb_data = (char *)m->mb_buf;
}
if (i != 0)
@@ -309,14 +326,25 @@ char *argv[];
}
if (dump == 1) {
- dumpnat();
- dumpstate();
- dumplookups();
- dumpgroups();
+ dumpnat(softc->ipf_nat_soft);
+ ipf_state_dump(softc, softc->ipf_state_soft);
+ ipf_lookup_dump(softc, softc->ipf_state_soft);
+ dumpgroups(softc);
}
- fr_deinitialise();
+ ipf_fini_all(softc);
+
+ ipf_destroy_all(softc);
+
+ ipf_unload_all();
+ ipf_mutex_clean();
+ ipf_rwlock_clean();
+
+ if (getenv("FINDLEAKS")) {
+ fflush(stdout);
+ abort();
+ }
return 0;
}
@@ -330,14 +358,15 @@ int ipftestioctl(int dev, ioctlcmd_t cmd, ...)
va_list ap;
int i;
+ dev = dev; /* gcc -Wextra */
va_start(ap, cmd);
data = va_arg(ap, caddr_t);
va_end(ap);
- i = iplioctl(IPL_LOGIPF, cmd, data, FWRITE|FREAD);
+ i = ipfioctl(softc, IPL_LOGIPF, cmd, data, FWRITE|FREAD);
if (opts & OPT_DEBUG)
- fprintf(stderr, "iplioctl(IPF,%#x,%p) = %d\n",
- (u_int)cmd, data, i);
+ fprintf(stderr, "ipfioctl(IPF,%#x,%p) = %d (%d)\n",
+ (u_int)cmd, data, i, softc->ipf_interror);
if (i != 0) {
errno = i;
return -1;
@@ -352,13 +381,14 @@ int ipnattestioctl(int dev, ioctlcmd_t cmd, ...)
va_list ap;
int i;
+ dev = dev; /* gcc -Wextra */
va_start(ap, cmd);
data = va_arg(ap, caddr_t);
va_end(ap);
- i = iplioctl(IPL_LOGNAT, cmd, data, FWRITE|FREAD);
+ i = ipfioctl(softc, IPL_LOGNAT, cmd, data, FWRITE|FREAD);
if (opts & OPT_DEBUG)
- fprintf(stderr, "iplioctl(NAT,%#x,%p) = %d\n",
+ fprintf(stderr, "ipfioctl(NAT,%#x,%p) = %d\n",
(u_int)cmd, data, i);
if (i != 0) {
errno = i;
@@ -374,13 +404,14 @@ int ipstatetestioctl(int dev, ioctlcmd_t cmd, ...)
va_list ap;
int i;
+ dev = dev; /* gcc -Wextra */
va_start(ap, cmd);
data = va_arg(ap, caddr_t);
va_end(ap);
- i = iplioctl(IPL_LOGSTATE, cmd, data, FWRITE|FREAD);
+ i = ipfioctl(softc, IPL_LOGSTATE, cmd, data, FWRITE|FREAD);
if ((opts & OPT_DEBUG) || (i != 0))
- fprintf(stderr, "iplioctl(STATE,%#x,%p) = %d\n",
+ fprintf(stderr, "ipfioctl(STATE,%#x,%p) = %d\n",
(u_int)cmd, data, i);
if (i != 0) {
errno = i;
@@ -396,13 +427,14 @@ int ipauthtestioctl(int dev, ioctlcmd_t cmd, ...)
va_list ap;
int i;
+ dev = dev; /* gcc -Wextra */
va_start(ap, cmd);
data = va_arg(ap, caddr_t);
va_end(ap);
- i = iplioctl(IPL_LOGAUTH, cmd, data, FWRITE|FREAD);
+ i = ipfioctl(softc, IPL_LOGAUTH, cmd, data, FWRITE|FREAD);
if ((opts & OPT_DEBUG) || (i != 0))
- fprintf(stderr, "iplioctl(AUTH,%#x,%p) = %d\n",
+ fprintf(stderr, "ipfioctl(AUTH,%#x,%p) = %d\n",
(u_int)cmd, data, i);
if (i != 0) {
errno = i;
@@ -418,13 +450,14 @@ int ipscantestioctl(int dev, ioctlcmd_t cmd, ...)
va_list ap;
int i;
+ dev = dev; /* gcc -Wextra */
va_start(ap, cmd);
data = va_arg(ap, caddr_t);
va_end(ap);
- i = iplioctl(IPL_LOGSCAN, cmd, data, FWRITE|FREAD);
+ i = ipfioctl(softc, IPL_LOGSCAN, cmd, data, FWRITE|FREAD);
if ((opts & OPT_DEBUG) || (i != 0))
- fprintf(stderr, "iplioctl(SCAN,%#x,%p) = %d\n",
+ fprintf(stderr, "ipfioctl(SCAN,%#x,%p) = %d\n",
(u_int)cmd, data, i);
if (i != 0) {
errno = i;
@@ -440,13 +473,14 @@ int ipsynctestioctl(int dev, ioctlcmd_t cmd, ...)
va_list ap;
int i;
+ dev = dev; /* gcc -Wextra */
va_start(ap, cmd);
data = va_arg(ap, caddr_t);
va_end(ap);
- i = iplioctl(IPL_LOGSYNC, cmd, data, FWRITE|FREAD);
+ i = ipfioctl(softc, IPL_LOGSYNC, cmd, data, FWRITE|FREAD);
if ((opts & OPT_DEBUG) || (i != 0))
- fprintf(stderr, "iplioctl(SYNC,%#x,%p) = %d\n",
+ fprintf(stderr, "ipfioctl(SYNC,%#x,%p) = %d\n",
(u_int)cmd, data, i);
if (i != 0) {
errno = i;
@@ -462,14 +496,15 @@ int ipooltestioctl(int dev, ioctlcmd_t cmd, ...)
va_list ap;
int i;
+ dev = dev; /* gcc -Wextra */
va_start(ap, cmd);
data = va_arg(ap, caddr_t);
va_end(ap);
- i = iplioctl(IPL_LOGLOOKUP, cmd, data, FWRITE|FREAD);
+ i = ipfioctl(softc, IPL_LOGLOOKUP, cmd, data, FWRITE|FREAD);
if ((opts & OPT_DEBUG) || (i != 0))
- fprintf(stderr, "iplioctl(POOL,%#x,%p) = %d\n",
- (u_int)cmd, data, i);
+ fprintf(stderr, "ipfioctl(POOL,%#x,%p) = %d (%d)\n",
+ (u_int)cmd, data, i, softc->ipf_interror);
if (i != 0) {
errno = i;
return -1;
@@ -478,15 +513,17 @@ int ipooltestioctl(int dev, ioctlcmd_t cmd, ...)
}
#else
int ipftestioctl(dev, cmd, data)
-dev_t dev;
-ioctlcmd_t cmd;
-void *data;
+ dev_t dev;
+ ioctlcmd_t cmd;
+ void *data;
{
int i;
- i = iplioctl(IPL_LOGIPF, cmd, data, FWRITE|FREAD);
+ dev = dev; /* gcc -Wextra */
+ i = ipfioctl(softc, IPL_LOGIPF, cmd, data, FWRITE|FREAD);
if ((opts & OPT_DEBUG) || (i != 0))
- fprintf(stderr, "iplioctl(IPF,%#x,%p) = %d\n", cmd, data, i);
+ fprintf(stderr, "ipfioctl(IPF,%#x,%p) = %d (%d)\n",
+ cmd, data, i, softc->ipf_interror);
if (i != 0) {
errno = i;
return -1;
@@ -496,15 +533,16 @@ void *data;
int ipnattestioctl(dev, cmd, data)
-dev_t dev;
-ioctlcmd_t cmd;
-void *data;
+ dev_t dev;
+ ioctlcmd_t cmd;
+ void *data;
{
int i;
- i = iplioctl(IPL_LOGNAT, cmd, data, FWRITE|FREAD);
+ dev = dev; /* gcc -Wextra */
+ i = ipfioctl(softc, IPL_LOGNAT, cmd, data, FWRITE|FREAD);
if ((opts & OPT_DEBUG) || (i != 0))
- fprintf(stderr, "iplioctl(NAT,%#x,%p) = %d\n", cmd, data, i);
+ fprintf(stderr, "ipfioctl(NAT,%#x,%p) = %d\n", cmd, data, i);
if (i != 0) {
errno = i;
return -1;
@@ -514,15 +552,16 @@ void *data;
int ipstatetestioctl(dev, cmd, data)
-dev_t dev;
-ioctlcmd_t cmd;
-void *data;
+ dev_t dev;
+ ioctlcmd_t cmd;
+ void *data;
{
int i;
- i = iplioctl(IPL_LOGSTATE, cmd, data, FWRITE|FREAD);
+ dev = dev; /* gcc -Wextra */
+ i = ipfioctl(softc, IPL_LOGSTATE, cmd, data, FWRITE|FREAD);
if ((opts & OPT_DEBUG) || (i != 0))
- fprintf(stderr, "iplioctl(STATE,%#x,%p) = %d\n", cmd, data, i);
+ fprintf(stderr, "ipfioctl(STATE,%#x,%p) = %d\n", cmd, data, i);
if (i != 0) {
errno = i;
return -1;
@@ -532,15 +571,16 @@ void *data;
int ipauthtestioctl(dev, cmd, data)
-dev_t dev;
-ioctlcmd_t cmd;
-void *data;
+ dev_t dev;
+ ioctlcmd_t cmd;
+ void *data;
{
int i;
- i = iplioctl(IPL_LOGAUTH, cmd, data, FWRITE|FREAD);
+ dev = dev; /* gcc -Wextra */
+ i = ipfioctl(softc, IPL_LOGAUTH, cmd, data, FWRITE|FREAD);
if ((opts & OPT_DEBUG) || (i != 0))
- fprintf(stderr, "iplioctl(AUTH,%#x,%p) = %d\n", cmd, data, i);
+ fprintf(stderr, "ipfioctl(AUTH,%#x,%p) = %d\n", cmd, data, i);
if (i != 0) {
errno = i;
return -1;
@@ -550,15 +590,16 @@ void *data;
int ipsynctestioctl(dev, cmd, data)
-dev_t dev;
-ioctlcmd_t cmd;
-void *data;
+ dev_t dev;
+ ioctlcmd_t cmd;
+ void *data;
{
int i;
- i = iplioctl(IPL_LOGSYNC, cmd, data, FWRITE|FREAD);
+ dev = dev; /* gcc -Wextra */
+ i = ipfioctl(softc, IPL_LOGSYNC, cmd, data, FWRITE|FREAD);
if ((opts & OPT_DEBUG) || (i != 0))
- fprintf(stderr, "iplioctl(SYNC,%#x,%p) = %d\n", cmd, data, i);
+ fprintf(stderr, "ipfioctl(SYNC,%#x,%p) = %d\n", cmd, data, i);
if (i != 0) {
errno = i;
return -1;
@@ -568,15 +609,16 @@ void *data;
int ipscantestioctl(dev, cmd, data)
-dev_t dev;
-ioctlcmd_t cmd;
-void *data;
+ dev_t dev;
+ ioctlcmd_t cmd;
+ void *data;
{
int i;
- i = iplioctl(IPL_LOGSCAN, cmd, data, FWRITE|FREAD);
+ dev = dev; /* gcc -Wextra */
+ i = ipfioctl(softc, IPL_LOGSCAN, cmd, data, FWRITE|FREAD);
if ((opts & OPT_DEBUG) || (i != 0))
- fprintf(stderr, "iplioctl(SCAN,%#x,%p) = %d\n", cmd, data, i);
+ fprintf(stderr, "ipfioctl(SCAN,%#x,%p) = %d\n", cmd, data, i);
if (i != 0) {
errno = i;
return -1;
@@ -586,15 +628,17 @@ void *data;
int ipooltestioctl(dev, cmd, data)
-dev_t dev;
-ioctlcmd_t cmd;
-void *data;
+ dev_t dev;
+ ioctlcmd_t cmd;
+ void *data;
{
int i;
- i = iplioctl(IPL_LOGLOOKUP, cmd, data, FWRITE|FREAD);
+ dev = dev; /* gcc -Wextra */
+ i = ipfioctl(softc, IPL_LOGLOOKUP, cmd, data, FWRITE|FREAD);
if (opts & OPT_DEBUG)
- fprintf(stderr, "iplioctl(POOL,%#x,%p) = %d\n", cmd, data, i);
+ fprintf(stderr, "ipfioctl(POOL,%#x,%p) = %d (%d)\n",
+ cmd, data, i, softc->ipf_interror);
if (i != 0) {
errno = i;
return -1;
@@ -605,9 +649,9 @@ void *data;
int kmemcpy(addr, offset, size)
-char *addr;
-long offset;
-int size;
+ char *addr;
+ long offset;
+ int size;
{
bcopy((char *)offset, addr, size);
return 0;
@@ -615,9 +659,9 @@ int size;
int kstrncpy(buf, pos, n)
-char *buf;
-long pos;
-int n;
+ char *buf;
+ long pos;
+ int n;
{
char *ptr;
@@ -632,100 +676,91 @@ int n;
/*
* Display the built up NAT table rules and mapping entries.
*/
-void dumpnat()
+void dumpnat(arg)
+ void *arg;
{
+ ipf_nat_softc_t *softn = arg;
hostmap_t *hm;
ipnat_t *ipn;
nat_t *nat;
printf("List of active MAP/Redirect filters:\n");
- for (ipn = nat_list; ipn != NULL; ipn = ipn->in_next)
+ for (ipn = softn->ipf_nat_list; ipn != NULL; ipn = ipn->in_next)
printnat(ipn, opts & (OPT_DEBUG|OPT_VERBOSE));
printf("\nList of active sessions:\n");
- for (nat = nat_instances; nat; nat = nat->nat_next) {
- printactivenat(nat, opts, 0, 0);
+ for (nat = softn->ipf_nat_instances; nat; nat = nat->nat_next) {
+ printactivenat(nat, opts, 0);
if (nat->nat_aps)
- printaps(nat->nat_aps, opts);
+ printf("\tproxy active\n");
}
printf("\nHostmap table:\n");
- for (hm = ipf_hm_maplist; hm != NULL; hm = hm->hm_next)
- printhostmap(hm, 0);
+ for (hm = softn->ipf_hm_maplist; hm != NULL; hm = hm->hm_next)
+ printhostmap(hm, hm->hm_hv);
}
-/*
- * Display the built up state table rules and mapping entries.
- */
-void dumpstate()
-{
- ipstate_t *ips;
-
- printf("List of active state sessions:\n");
- for (ips = ips_list; ips != NULL; )
- ips = printstate(ips, opts & (OPT_DEBUG|OPT_VERBOSE),
- fr_ticks);
-}
-
-
-void dumplookups()
-{
- iphtable_t *iph;
- ip_pool_t *ipl;
- int i;
-
- printf("List of configured pools\n");
- for (i = 0; i < IPL_LOGSIZE; i++)
- for (ipl = ip_pool_list[i]; ipl != NULL; ipl = ipl->ipo_next)
- printpool(ipl, bcopywrap, NULL, opts);
-
- printf("List of configured hash tables\n");
- for (i = 0; i < IPL_LOGSIZE; i++)
- for (iph = ipf_htables[i]; iph != NULL; iph = iph->iph_next)
- printhash(iph, bcopywrap, NULL, opts);
-}
-
-
-void dumpgroups()
+void dumpgroups(softc)
+ ipf_main_softc_t *softc;
{
frgroup_t *fg;
- frentry_t *fr;
int i;
printf("List of groups configured (set 0)\n");
for (i = 0; i < IPL_LOGSIZE; i++)
- for (fg = ipfgroups[i][0]; fg != NULL; fg = fg->fg_next) {
+ for (fg = softc->ipf_groups[i][0]; fg != NULL;
+ fg = fg->fg_next) {
printf("Dev.%d. Group %s Ref %d Flags %#x\n",
i, fg->fg_name, fg->fg_ref, fg->fg_flags);
- for (fr = fg->fg_start; fr != NULL; fr = fr->fr_next) {
-#ifdef USE_QUAD_T
- printf("%qu ",(unsigned long long)fr->fr_hits);
-#else
- printf("%ld ", fr->fr_hits);
-#endif
- printfr(fr, ipftestioctl);
- }
+ dumprules(fg->fg_start);
}
printf("List of groups configured (set 1)\n");
for (i = 0; i < IPL_LOGSIZE; i++)
- for (fg = ipfgroups[i][1]; fg != NULL; fg = fg->fg_next) {
+ for (fg = softc->ipf_groups[i][1]; fg != NULL;
+ fg = fg->fg_next) {
printf("Dev.%d. Group %s Ref %d Flags %#x\n",
i, fg->fg_name, fg->fg_ref, fg->fg_flags);
- for (fr = fg->fg_start; fr != NULL; fr = fr->fr_next) {
+ dumprules(fg->fg_start);
+ }
+
+ printf("Rules configured (set 0, in)\n");
+ dumprules(softc->ipf_rules[0][0]);
+ printf("Rules configured (set 0, out)\n");
+ dumprules(softc->ipf_rules[1][0]);
+ printf("Rules configured (set 1, in)\n");
+ dumprules(softc->ipf_rules[0][1]);
+ printf("Rules configured (set 1, out)\n");
+ dumprules(softc->ipf_rules[1][1]);
+
+ printf("Accounting rules configured (set 0, in)\n");
+ dumprules(softc->ipf_acct[0][0]);
+ printf("Accounting rules configured (set 0, out)\n");
+ dumprules(softc->ipf_acct[0][1]);
+ printf("Accounting rules configured (set 1, in)\n");
+ dumprules(softc->ipf_acct[1][0]);
+ printf("Accounting rules configured (set 1, out)\n");
+ dumprules(softc->ipf_acct[1][1]);
+}
+
+void dumprules(rulehead)
+ frentry_t *rulehead;
+{
+ frentry_t *fr;
+
+ for (fr = rulehead; fr != NULL; fr = fr->fr_next) {
#ifdef USE_QUAD_T
- printf("%qu ",(unsigned long long)fr->fr_hits);
+ printf("%"PRIu64" ",(unsigned long long)fr->fr_hits);
#else
- printf("%ld ", fr->fr_hits);
+ printf("%ld ", fr->fr_hits);
#endif
- printfr(fr, ipftestioctl);
- }
- }
+ printfr(fr, ipftestioctl);
+ }
}
void drain_log(filename)
-char *filename;
+ char *filename;
{
char buffer[DEFAULT_IPFLOGSIZE];
struct iovec iov;
@@ -751,7 +786,7 @@ char *filename;
uio.uio_resid = iov.iov_len;
resid = uio.uio_resid;
- if (ipflog_read(i, &uio) == 0) {
+ if (ipf_log_read(softc, i, &uio) == 0) {
/*
* If nothing was read then break out.
*/
@@ -767,18 +802,38 @@ char *filename;
void fixv4sums(m, ip)
-mb_t *m;
-ip_t *ip;
+ mb_t *m;
+ ip_t *ip;
{
- u_char *csump, *hdr;
+ u_char *csump, *hdr, p;
+ fr_info_t tmp;
+ int len;
- ip->ip_sum = 0;
- ip->ip_sum = ipf_cksum((u_short *)ip, IP_HL(ip) << 2);
+ p = 0;
+ len = 0;
+ bzero((char *)&tmp, sizeof(tmp));
csump = (u_char *)ip;
- csump += IP_HL(ip) << 2;
+ if (IP_V(ip) == 4) {
+ ip->ip_sum = 0;
+ ip->ip_sum = ipf_cksum((u_short *)ip, IP_HL(ip) << 2);
+ tmp.fin_hlen = IP_HL(ip) << 2;
+ csump += IP_HL(ip) << 2;
+ p = ip->ip_p;
+ len = ntohs(ip->ip_len);
+#ifdef USE_INET6
+ } else if (IP_V(ip) == 6) {
+ tmp.fin_hlen = sizeof(ip6_t);
+ csump += sizeof(ip6_t);
+ p = ((ip6_t *)ip)->ip6_nxt;
+ len = ntohs(((ip6_t *)ip)->ip6_plen);
+ len += sizeof(ip6_t);
+#endif
+ }
+ tmp.fin_plen = len;
+ tmp.fin_dlen = len - tmp.fin_hlen;
- switch (ip->ip_p)
+ switch (p)
{
case IPPROTO_TCP :
hdr = csump;
@@ -798,7 +853,12 @@ ip_t *ip;
break;
}
if (hdr != NULL) {
+ tmp.fin_m = m;
+ tmp.fin_mp = &m;
+ tmp.fin_dp = hdr;
+ tmp.fin_ip = ip;
+ tmp.fin_plen = len;
*csump = 0;
- *(u_short *)csump = fr_cksum(m, ip, ip->ip_p, hdr, ip->ip_len);
+ *(u_short *)csump = fr_cksum(&tmp, ip, p, hdr);
}
}