4 * Copyright (C) 2012 by Darren Reed.
6 * See the IPFILTER.LICENCE file for details on licencing.
12 #include <sys/ioctl.h>
14 #include "netinet/ip_lookup.h"
15 #include "netinet/ip_htable.h"
19 load_hash(iphp, list, iocfunc)
30 if (pool_open() == -1)
33 for (n = 0, a = list; a != NULL; a = a->ipe_next)
36 bzero((char *)&iph, sizeof(iph));
38 op.iplo_type = IPLT_HASH;
39 op.iplo_unit = iphp->iph_unit;
40 strncpy(op.iplo_name, iphp->iph_name, sizeof(op.iplo_name));
41 if (*op.iplo_name == '\0')
42 op.iplo_arg = IPHASH_ANON;
43 op.iplo_size = sizeof(iph);
44 op.iplo_struct = &iph;
48 if (iphp->iph_size == 0)
51 size = iphp->iph_size;
52 if ((list == NULL) && (size == 1)) {
54 "WARNING: empty hash table %s, recommend setting %s\n",
55 iphp->iph_name, "size to match expected use");
62 if ((opts & OPT_REMOVE) == 0) {
63 if (pool_ioctl(iocfunc, SIOCLOOKUPADDTABLE, &op))
64 if ((opts & OPT_DONOTHING) == 0) {
65 return ipf_perror_fd(pool_fd(), iocfunc,
66 "add lookup hash table");
70 strncpy(iph.iph_name, op.iplo_name, sizeof(op.iplo_name));
71 strncpy(iphp->iph_name, op.iplo_name, sizeof(op.iplo_name));
73 if (opts & OPT_VERBOSE) {
74 iph.iph_table = calloc(size, sizeof(*iph.iph_table));
75 if (iph.iph_table == NULL) {
76 perror("calloc(size, sizeof(*iph.iph_table))");
80 printhash(&iph, bcopywrap, iph.iph_name, opts, NULL);
83 for (a = list; a != NULL; a = a->ipe_next) {
84 a->ipe_addr.in4_addr = htonl(a->ipe_addr.in4_addr);
85 a->ipe_mask.in4_addr = htonl(a->ipe_mask.in4_addr);
90 printf("Hash %s:\n", iph.iph_name);
92 for (a = list; a != NULL; a = a->ipe_next)
93 load_hashnode(iphp->iph_unit, iph.iph_name, a, 0, iocfunc);
95 if ((opts & OPT_REMOVE) != 0) {
96 if (pool_ioctl(iocfunc, SIOCLOOKUPDELTABLE, &op))
97 if ((opts & OPT_DONOTHING) == 0) {
98 return ipf_perror_fd(pool_fd(), iocfunc,
99 "delete lookup hash table");