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 /*
13 * Because the ipf_dstnode_t can vary in size because of the interface name,
14 * the size may be larger than just sizeof().
15 */
16 ippool_dst_t *
printdstl_live(ippool_dst_t * d,int fd,char * name,int opts,wordtab_t * fields)17 printdstl_live( ippool_dst_t *d, int fd, char *name, int opts,
18 wordtab_t *fields)
19 {
20 ipf_dstnode_t *entry, *zero;
21 ipflookupiter_t iter;
22 int printed, last;
23 ipfobj_t obj;
24
25 if ((name != NULL) && strncmp(name, d->ipld_name, FR_GROUPLEN))
26 return (d->ipld_next);
27
28 entry = calloc(1, sizeof(*entry) + 64);
29 if (entry == NULL)
30 return (d->ipld_next);
31 zero = calloc(1, sizeof(*zero) + 64);
32 if (zero == NULL) {
33 free(entry);
34 return (d->ipld_next);
35 }
36
37 if (fields == NULL)
38 printdstlistdata(d, opts);
39
40 if ((d->ipld_flags & IPHASH_DELETE) != 0)
41 PRINTF("# ");
42
43 if (opts & OPT_SAVEOUT)
44 PRINTF("{\n");
45
46 if ((opts & OPT_DEBUG) == 0)
47 PRINTF("\t{");
48
49 obj.ipfo_rev = IPFILTER_VERSION;
50 obj.ipfo_type = IPFOBJ_LOOKUPITER;
51 obj.ipfo_ptr = &iter;
52 obj.ipfo_size = sizeof(iter);
53
54 iter.ili_data = entry;
55 iter.ili_type = IPLT_DSTLIST;
56 iter.ili_otype = IPFLOOKUPITER_NODE;
57 iter.ili_ival = IPFGENITER_LOOKUP;
58 iter.ili_unit = d->ipld_unit;
59 strncpy(iter.ili_name, d->ipld_name, FR_GROUPLEN);
60
61 last = 0;
62 printed = 0;
63
64 while (!last && (ioctl(fd, SIOCLOOKUPITER, &obj) == 0)) {
65 if (entry->ipfd_next == NULL)
66 last = 1;
67 if (bcmp((char *)zero, (char *)entry, sizeof(*zero)) == 0)
68 break;
69 (void) printdstlistnode(entry, bcopywrap, opts, fields);
70 printed++;
71 }
72
73 (void) ioctl(fd, SIOCIPFDELTOK, &iter.ili_key);
74 free(entry);
75 free(zero);
76
77 if (printed == 0)
78 putchar(';');
79
80 if ((opts & OPT_DEBUG) == 0)
81 PRINTF(" };\n");
82 return (d->ipld_next);
83 }
84