1 /*
2 * Copyright (C) 2012 by Darren Reed.
3 *
4 * See the IPFILTER.LICENCE file for details on licencing.
5 */
6
7 #include <sys/ioctl.h>
8 #include "ipf.h"
9 #include "netinet/ipl.h"
10
11
12 iphtable_t *
printhash_live(iphtable_t * hp,int fd,char * name,int opts,wordtab_t * fields)13 printhash_live(iphtable_t *hp, int fd, char *name, int opts, wordtab_t *fields)
14 {
15 iphtent_t entry, zero;
16 ipflookupiter_t iter;
17 int last, printed;
18 ipfobj_t obj;
19
20 if ((name != NULL) && strncmp(name, hp->iph_name, FR_GROUPLEN))
21 return (hp->iph_next);
22
23 if (fields == NULL)
24 printhashdata(hp, opts);
25
26 if ((hp->iph_flags & IPHASH_DELETE) != 0)
27 PRINTF("# ");
28
29 if (opts & OPT_SAVEOUT)
30 PRINTF("{\n");
31 else if ((opts & OPT_DEBUG) == 0)
32 PRINTF("\t{");
33
34 obj.ipfo_rev = IPFILTER_VERSION;
35 obj.ipfo_type = IPFOBJ_LOOKUPITER;
36 obj.ipfo_ptr = &iter;
37 obj.ipfo_size = sizeof(iter);
38
39 iter.ili_data = &entry;
40 iter.ili_type = IPLT_HASH;
41 iter.ili_otype = IPFLOOKUPITER_NODE;
42 iter.ili_ival = IPFGENITER_LOOKUP;
43 iter.ili_unit = hp->iph_unit;
44 strncpy(iter.ili_name, hp->iph_name, FR_GROUPLEN);
45
46 last = 0;
47 printed = 0;
48 bzero((char *)&zero, sizeof(zero));
49
50 while (!last && (ioctl(fd, SIOCLOOKUPITER, &obj) == 0)) {
51 if (entry.ipe_next == NULL)
52 last = 1;
53 if (bcmp(&zero, &entry, sizeof(zero)) == 0)
54 break;
55 if (opts & OPT_SAVEOUT)
56 PRINTF("\t");
57 (void) printhashnode(hp, &entry, bcopywrap, opts, fields);
58 printed++;
59 }
60 if (last == 0)
61 ipferror(fd, "walking hash nodes");
62
63 if (printed == 0)
64 putchar(';');
65
66 if ((opts & OPT_DEBUG) == 0 || (opts & OPT_SAVEOUT))
67 PRINTF(" };\n");
68
69 (void) ioctl(fd,SIOCIPFDELTOK, &iter.ili_key);
70
71 return (hp->iph_next);
72 }
73