printdstl_live.c revision 1.1.1.2 1 1.1 christos /* $NetBSD: printdstl_live.c,v 1.1.1.2 2012/07/22 13:44:40 darrenr Exp $ */
2 1.1 christos
3 1.1 christos /*
4 1.1.1.2 darrenr * Copyright (C) 2012 by Darren Reed.
5 1.1 christos *
6 1.1 christos * See the IPFILTER.LICENCE file for details on licencing.
7 1.1 christos */
8 1.1 christos
9 1.1 christos #include <sys/ioctl.h>
10 1.1 christos #include "ipf.h"
11 1.1 christos #include "netinet/ipl.h"
12 1.1 christos
13 1.1 christos
14 1.1 christos /*
15 1.1 christos * Because the ipf_dstnode_t can vary in size because of the interface name,
16 1.1 christos * the size may be larger than just sizeof().
17 1.1 christos */
18 1.1 christos ippool_dst_t *
19 1.1 christos printdstl_live(d, fd, name, opts, fields)
20 1.1 christos ippool_dst_t *d;
21 1.1 christos int fd;
22 1.1 christos char *name;
23 1.1 christos int opts;
24 1.1 christos wordtab_t *fields;
25 1.1 christos {
26 1.1.1.2 darrenr ipf_dstnode_t *entry, *zero;
27 1.1 christos ipflookupiter_t iter;
28 1.1 christos int printed, last;
29 1.1 christos ipfobj_t obj;
30 1.1 christos
31 1.1 christos if ((name != NULL) && strncmp(name, d->ipld_name, FR_GROUPLEN))
32 1.1 christos return d->ipld_next;
33 1.1 christos
34 1.1 christos entry = calloc(1, sizeof(*entry) + 64);
35 1.1 christos if (entry == NULL)
36 1.1 christos return d->ipld_next;
37 1.1.1.2 darrenr zero = calloc(1, sizeof(*zero) + 64);
38 1.1.1.2 darrenr if (zero == NULL) {
39 1.1.1.2 darrenr free(entry);
40 1.1.1.2 darrenr return d->ipld_next;
41 1.1.1.2 darrenr }
42 1.1 christos
43 1.1 christos if (fields == NULL)
44 1.1 christos printdstlistdata(d, opts);
45 1.1 christos
46 1.1 christos if ((d->ipld_flags & IPHASH_DELETE) != 0)
47 1.1 christos PRINTF("# ");
48 1.1 christos
49 1.1 christos if ((opts & OPT_DEBUG) == 0)
50 1.1 christos PRINTF("\t{");
51 1.1 christos
52 1.1 christos obj.ipfo_rev = IPFILTER_VERSION;
53 1.1 christos obj.ipfo_type = IPFOBJ_LOOKUPITER;
54 1.1 christos obj.ipfo_ptr = &iter;
55 1.1 christos obj.ipfo_size = sizeof(iter);
56 1.1 christos
57 1.1 christos iter.ili_data = entry;
58 1.1 christos iter.ili_type = IPLT_DSTLIST;
59 1.1 christos iter.ili_otype = IPFLOOKUPITER_NODE;
60 1.1 christos iter.ili_ival = IPFGENITER_LOOKUP;
61 1.1 christos iter.ili_unit = d->ipld_unit;
62 1.1 christos strncpy(iter.ili_name, d->ipld_name, FR_GROUPLEN);
63 1.1 christos
64 1.1 christos last = 0;
65 1.1 christos printed = 0;
66 1.1 christos
67 1.1.1.2 darrenr while (!last && (ioctl(fd, SIOCLOOKUPITER, &obj) == 0)) {
68 1.1.1.2 darrenr if (entry->ipfd_next == NULL)
69 1.1.1.2 darrenr last = 1;
70 1.1.1.2 darrenr if (bcmp((char *)zero, (char *)entry, sizeof(*zero)) == 0)
71 1.1.1.2 darrenr break;
72 1.1.1.2 darrenr (void) printdstlistnode(entry, bcopywrap, opts, fields);
73 1.1 christos printed++;
74 1.1 christos }
75 1.1 christos
76 1.1.1.2 darrenr (void) ioctl(fd, SIOCIPFDELTOK, &iter.ili_key);
77 1.1.1.2 darrenr free(entry);
78 1.1.1.2 darrenr free(zero);
79 1.1 christos
80 1.1 christos if (printed == 0)
81 1.1 christos putchar(';');
82 1.1 christos
83 1.1 christos if ((opts & OPT_DEBUG) == 0)
84 1.1 christos PRINTF(" };\n");
85 1.1 christos return d->ipld_next;
86 1.1 christos }
87