blob: c1508cd598b75cf7fb5100c218a3b4ea67ba653a [file] [log] [blame]
Rusty Russell79dee072000-05-02 16:45:16 +00001/* Library which manipulates firewall rules. Version 0.1. */
2
3/* Architecture of firewall rules is as follows:
4 *
5 * Chains go INPUT, FORWARD, OUTPUT then user chains.
6 * Each user chain starts with an ERROR node.
7 * Every chain ends with an unconditional jump: a RETURN for user chains,
8 * and a POLICY for built-ins.
9 */
10
11/* (C)1999 Paul ``Rusty'' Russell - Placed under the GNU GPL (See
12 COPYING for details). */
13
14#include <assert.h>
15#include <string.h>
16#include <errno.h>
17#include <stdlib.h>
18#include <stdio.h>
Marc Boucher1afc3b62002-01-19 12:46:39 +000019#include <unistd.h>
Rusty Russell79dee072000-05-02 16:45:16 +000020#include <arpa/inet.h>
21
22#ifdef DEBUG_CONNTRACK
23#define inline
24#endif
25
26#if !defined(__GLIBC__) || (__GLIBC__ < 2)
27typedef unsigned int socklen_t;
28#endif
29
30#include "libiptc/libip6tc.h"
31
32#define HOOK_PRE_ROUTING NF_IP6_PRE_ROUTING
33#define HOOK_LOCAL_IN NF_IP6_LOCAL_IN
34#define HOOK_FORWARD NF_IP6_FORWARD
35#define HOOK_LOCAL_OUT NF_IP6_LOCAL_OUT
36#define HOOK_POST_ROUTING NF_IP6_POST_ROUTING
37
38#define STRUCT_ENTRY_TARGET struct ip6t_entry_target
39#define STRUCT_ENTRY struct ip6t_entry
40#define STRUCT_ENTRY_MATCH struct ip6t_entry_match
41#define STRUCT_GETINFO struct ip6t_getinfo
42#define STRUCT_GET_ENTRIES struct ip6t_get_entries
43#define STRUCT_COUNTERS struct ip6t_counters
44#define STRUCT_COUNTERS_INFO struct ip6t_counters_info
45#define STRUCT_STANDARD_TARGET struct ip6t_standard_target
46#define STRUCT_REPLACE struct ip6t_replace
47
48#define STRUCT_TC_HANDLE struct ip6tc_handle
Jan Engelhardtfd187312008-11-10 16:59:27 +010049#define xtc_handle ip6tc_handle
Rusty Russell79dee072000-05-02 16:45:16 +000050
51#define ENTRY_ITERATE IP6T_ENTRY_ITERATE
52#define TABLE_MAXNAMELEN IP6T_TABLE_MAXNAMELEN
53#define FUNCTION_MAXNAMELEN IP6T_FUNCTION_MAXNAMELEN
54
55#define GET_TARGET ip6t_get_target
56
57#define ERROR_TARGET IP6T_ERROR_TARGET
58#define NUMHOOKS NF_IP6_NUMHOOKS
59
60#define IPT_CHAINLABEL ip6t_chainlabel
61
62#define TC_DUMP_ENTRIES dump_entries6
63#define TC_IS_CHAIN ip6tc_is_chain
Philip Blundell8c700902000-05-15 02:17:52 +000064#define TC_FIRST_CHAIN ip6tc_first_chain
Rusty Russell79dee072000-05-02 16:45:16 +000065#define TC_NEXT_CHAIN ip6tc_next_chain
Philip Blundell8c700902000-05-15 02:17:52 +000066#define TC_FIRST_RULE ip6tc_first_rule
67#define TC_NEXT_RULE ip6tc_next_rule
Rusty Russell79dee072000-05-02 16:45:16 +000068#define TC_GET_TARGET ip6tc_get_target
69#define TC_BUILTIN ip6tc_builtin
70#define TC_GET_POLICY ip6tc_get_policy
71#define TC_INSERT_ENTRY ip6tc_insert_entry
72#define TC_REPLACE_ENTRY ip6tc_replace_entry
73#define TC_APPEND_ENTRY ip6tc_append_entry
Stefan Tomanekd59b9db2011-03-08 22:42:51 +010074#define TC_CHECK_ENTRY ip6tc_check_entry
Rusty Russell79dee072000-05-02 16:45:16 +000075#define TC_DELETE_ENTRY ip6tc_delete_entry
76#define TC_DELETE_NUM_ENTRY ip6tc_delete_num_entry
Rusty Russell79dee072000-05-02 16:45:16 +000077#define TC_FLUSH_ENTRIES ip6tc_flush_entries
78#define TC_ZERO_ENTRIES ip6tc_zero_entries
Harald Welte1cef74d2001-01-05 15:22:59 +000079#define TC_ZERO_COUNTER ip6tc_zero_counter
80#define TC_READ_COUNTER ip6tc_read_counter
81#define TC_SET_COUNTER ip6tc_set_counter
Rusty Russell79dee072000-05-02 16:45:16 +000082#define TC_CREATE_CHAIN ip6tc_create_chain
83#define TC_GET_REFERENCES ip6tc_get_references
84#define TC_DELETE_CHAIN ip6tc_delete_chain
85#define TC_RENAME_CHAIN ip6tc_rename_chain
86#define TC_SET_POLICY ip6tc_set_policy
87#define TC_GET_RAW_SOCKET ip6tc_get_raw_socket
88#define TC_INIT ip6tc_init
Martin Josefsson841e4ae2003-05-02 15:30:11 +000089#define TC_FREE ip6tc_free
Rusty Russell79dee072000-05-02 16:45:16 +000090#define TC_COMMIT ip6tc_commit
91#define TC_STRERROR ip6tc_strerror
Phil Oester70067292006-07-05 09:31:45 +000092#define TC_NUM_RULES ip6tc_num_rules
93#define TC_GET_RULE ip6tc_get_rule
Rusty Russell79dee072000-05-02 16:45:16 +000094
95#define TC_AF AF_INET6
96#define TC_IPPROTO IPPROTO_IPV6
97
98#define SO_SET_REPLACE IP6T_SO_SET_REPLACE
99#define SO_SET_ADD_COUNTERS IP6T_SO_SET_ADD_COUNTERS
100#define SO_GET_INFO IP6T_SO_GET_INFO
101#define SO_GET_ENTRIES IP6T_SO_GET_ENTRIES
102#define SO_GET_VERSION IP6T_SO_GET_VERSION
103
104#define STANDARD_TARGET IP6T_STANDARD_TARGET
105#define LABEL_RETURN IP6TC_LABEL_RETURN
106#define LABEL_ACCEPT IP6TC_LABEL_ACCEPT
107#define LABEL_DROP IP6TC_LABEL_DROP
Philip Blundell88eb8352000-05-10 00:25:04 +0000108#define LABEL_QUEUE IP6TC_LABEL_QUEUE
Rusty Russell79dee072000-05-02 16:45:16 +0000109
110#define ALIGN IP6T_ALIGN
111#define RETURN IP6T_RETURN
112
113#include "libiptc.c"
114
115#define BIT6(a, l) \
Yasuyuki Kozakai5a2208c2008-06-04 15:16:03 +0200116 ((ntohl(a->s6_addr32[(l) / 32]) >> (31 - ((l) & 31))) & 1)
Rusty Russell79dee072000-05-02 16:45:16 +0000117
118int
119ipv6_prefix_length(const struct in6_addr *a)
120{
121 int l, i;
122 for (l = 0; l < 128; l++) {
123 if (BIT6(a, l) == 0)
124 break;
125 }
126 for (i = l + 1; i < 128; i++) {
127 if (BIT6(a, i) == 1)
128 return -1;
129 }
130 return l;
131}
132
133static int
Jan Engelhardtfd187312008-11-10 16:59:27 +0100134dump_entry(struct ip6t_entry *e, struct ip6tc_handle *const handle)
Rusty Russell79dee072000-05-02 16:45:16 +0000135{
136 size_t i;
137 char buf[40];
138 int len;
139 struct ip6t_entry_target *t;
140
Harald Welteaae69be2004-08-29 23:32:14 +0000141 printf("Entry %u (%lu):\n", iptcb_entry2index(handle, e),
142 iptcb_entry2offset(handle, e));
Rusty Russell79dee072000-05-02 16:45:16 +0000143 puts("SRC IP: ");
144 inet_ntop(AF_INET6, &e->ipv6.src, buf, sizeof buf);
145 puts(buf);
146 putchar('/');
147 len = ipv6_prefix_length(&e->ipv6.smsk);
148 if (len != -1)
149 printf("%d", len);
150 else {
151 inet_ntop(AF_INET6, &e->ipv6.smsk, buf, sizeof buf);
152 puts(buf);
153 }
154 putchar('\n');
155
156 puts("DST IP: ");
157 inet_ntop(AF_INET6, &e->ipv6.dst, buf, sizeof buf);
158 puts(buf);
159 putchar('/');
160 len = ipv6_prefix_length(&e->ipv6.dmsk);
161 if (len != -1)
162 printf("%d", len);
163 else {
164 inet_ntop(AF_INET6, &e->ipv6.dmsk, buf, sizeof buf);
165 puts(buf);
166 }
167 putchar('\n');
168
169 printf("Interface: `%s'/", e->ipv6.iniface);
170 for (i = 0; i < IFNAMSIZ; i++)
171 printf("%c", e->ipv6.iniface_mask[i] ? 'X' : '.');
172 printf("to `%s'/", e->ipv6.outiface);
173 for (i = 0; i < IFNAMSIZ; i++)
174 printf("%c", e->ipv6.outiface_mask[i] ? 'X' : '.');
175 printf("\nProtocol: %u\n", e->ipv6.proto);
176 if (e->ipv6.flags & IP6T_F_TOS)
177 printf("TOS: %u\n", e->ipv6.tos);
178 printf("Flags: %02X\n", e->ipv6.flags);
179 printf("Invflags: %02X\n", e->ipv6.invflags);
180 printf("Counters: %llu packets, %llu bytes\n",
Martin Josefssona28d4952004-05-26 16:04:48 +0000181 (unsigned long long)e->counters.pcnt, (unsigned long long)e->counters.bcnt);
Peter Rileyea146a92007-09-02 13:09:07 +0000182 printf("Cache: %08X\n", e->nfcache);
Rusty Russell79dee072000-05-02 16:45:16 +0000183
184 IP6T_MATCH_ITERATE(e, print_match);
185
186 t = ip6t_get_target(e);
Philip Blundell88eb8352000-05-10 00:25:04 +0000187 printf("Target name: `%s' [%u]\n", t->u.user.name, t->u.target_size);
188 if (strcmp(t->u.user.name, IP6T_STANDARD_TARGET) == 0) {
Jan Engelhardt51651b62009-10-23 23:35:49 +0200189 const unsigned char *data = t->data;
190 int pos = *(const int *)data;
Rusty Russell79dee072000-05-02 16:45:16 +0000191 if (pos < 0)
192 printf("verdict=%s\n",
193 pos == -NF_ACCEPT-1 ? "NF_ACCEPT"
194 : pos == -NF_DROP-1 ? "NF_DROP"
195 : pos == IP6T_RETURN ? "RETURN"
196 : "UNKNOWN");
197 else
198 printf("verdict=%u\n", pos);
Philip Blundell88eb8352000-05-10 00:25:04 +0000199 } else if (strcmp(t->u.user.name, IP6T_ERROR_TARGET) == 0)
Rusty Russell79dee072000-05-02 16:45:16 +0000200 printf("error=`%s'\n", t->data);
201
202 printf("\n");
203 return 0;
204}
205
Rusty Russell733e54b2004-12-16 14:22:23 +0000206static unsigned char *
Philip Blundell88eb8352000-05-10 00:25:04 +0000207is_same(const STRUCT_ENTRY *a, const STRUCT_ENTRY *b,
Rusty Russell79dee072000-05-02 16:45:16 +0000208 unsigned char *matchmask)
209{
210 unsigned int i;
Rusty Russell79dee072000-05-02 16:45:16 +0000211 unsigned char *mptr;
212
213 /* Always compare head structures: ignore mask here. */
214 if (memcmp(&a->ipv6.src, &b->ipv6.src, sizeof(struct in6_addr))
215 || memcmp(&a->ipv6.dst, &b->ipv6.dst, sizeof(struct in6_addr))
216 || memcmp(&a->ipv6.smsk, &b->ipv6.smsk, sizeof(struct in6_addr))
217 || memcmp(&a->ipv6.dmsk, &b->ipv6.dmsk, sizeof(struct in6_addr))
218 || a->ipv6.proto != b->ipv6.proto
219 || a->ipv6.tos != b->ipv6.tos
220 || a->ipv6.flags != b->ipv6.flags
221 || a->ipv6.invflags != b->ipv6.invflags)
Rusty Russell733e54b2004-12-16 14:22:23 +0000222 return NULL;
Rusty Russell79dee072000-05-02 16:45:16 +0000223
224 for (i = 0; i < IFNAMSIZ; i++) {
225 if (a->ipv6.iniface_mask[i] != b->ipv6.iniface_mask[i])
Rusty Russell733e54b2004-12-16 14:22:23 +0000226 return NULL;
Rusty Russell79dee072000-05-02 16:45:16 +0000227 if ((a->ipv6.iniface[i] & a->ipv6.iniface_mask[i])
228 != (b->ipv6.iniface[i] & b->ipv6.iniface_mask[i]))
Rusty Russell733e54b2004-12-16 14:22:23 +0000229 return NULL;
Rusty Russell79dee072000-05-02 16:45:16 +0000230 if (a->ipv6.outiface_mask[i] != b->ipv6.outiface_mask[i])
Rusty Russell733e54b2004-12-16 14:22:23 +0000231 return NULL;
Rusty Russell79dee072000-05-02 16:45:16 +0000232 if ((a->ipv6.outiface[i] & a->ipv6.outiface_mask[i])
233 != (b->ipv6.outiface[i] & b->ipv6.outiface_mask[i]))
Rusty Russell733e54b2004-12-16 14:22:23 +0000234 return NULL;
Rusty Russell79dee072000-05-02 16:45:16 +0000235 }
236
Peter Rileyea146a92007-09-02 13:09:07 +0000237 if (a->target_offset != b->target_offset
Rusty Russell79dee072000-05-02 16:45:16 +0000238 || a->next_offset != b->next_offset)
Rusty Russell733e54b2004-12-16 14:22:23 +0000239 return NULL;
Rusty Russell79dee072000-05-02 16:45:16 +0000240
Philip Blundell88eb8352000-05-10 00:25:04 +0000241 mptr = matchmask + sizeof(STRUCT_ENTRY);
242 if (IP6T_MATCH_ITERATE(a, match_different, a->elems, b->elems, &mptr))
Rusty Russell733e54b2004-12-16 14:22:23 +0000243 return NULL;
Pablo Neira5ee88622005-06-23 08:51:18 +0000244 mptr += IP6T_ALIGN(sizeof(struct ip6t_entry_target));
Rusty Russell79dee072000-05-02 16:45:16 +0000245
Rusty Russell733e54b2004-12-16 14:22:23 +0000246 return mptr;
Rusty Russell79dee072000-05-02 16:45:16 +0000247}
Philip Blundell8c700902000-05-15 02:17:52 +0000248
Rusty Russell5eed48a2000-06-02 20:12:24 +0000249/* All zeroes == unconditional rule. */
250static inline int
251unconditional(const struct ip6t_ip6 *ipv6)
252{
253 unsigned int i;
254
255 for (i = 0; i < sizeof(*ipv6); i++)
256 if (((char *)ipv6)[i])
257 break;
258
259 return (i == sizeof(*ipv6));
260}
261
Harald Welte380ba5f2002-02-13 16:19:55 +0000262#ifdef IPTC_DEBUG
Philip Blundell8c700902000-05-15 02:17:52 +0000263/* Do every conceivable sanity check on the handle */
264static void
Jan Engelhardtfd187312008-11-10 16:59:27 +0100265do_check(struct xtc_handle *h, unsigned int line)
Philip Blundell8c700902000-05-15 02:17:52 +0000266{
267 unsigned int i, n;
268 unsigned int user_offset; /* Offset of first user chain */
269 int was_return;
270
271 assert(h->changed == 0 || h->changed == 1);
272 if (strcmp(h->info.name, "filter") == 0) {
273 assert(h->info.valid_hooks
274 == (1 << NF_IP6_LOCAL_IN
275 | 1 << NF_IP6_FORWARD
276 | 1 << NF_IP6_LOCAL_OUT));
277
278 /* Hooks should be first three */
279 assert(h->info.hook_entry[NF_IP6_LOCAL_IN] == 0);
280
281 n = get_chain_end(h, 0);
282 n += get_entry(h, n)->next_offset;
283 assert(h->info.hook_entry[NF_IP6_FORWARD] == n);
284
285 n = get_chain_end(h, n);
286 n += get_entry(h, n)->next_offset;
287 assert(h->info.hook_entry[NF_IP6_LOCAL_OUT] == n);
288
289 user_offset = h->info.hook_entry[NF_IP6_LOCAL_OUT];
290 } else if (strcmp(h->info.name, "nat") == 0) {
Harald Welte95df8e72002-02-13 23:13:23 +0000291 assert((h->info.valid_hooks
292 == (1 << NF_IP6_PRE_ROUTING
293 | 1 << NF_IP6_LOCAL_OUT
294 | 1 << NF_IP6_POST_ROUTING)) ||
295 (h->info.valid_hooks
296 == (1 << NF_IP6_PRE_ROUTING
297 | 1 << NF_IP6_LOCAL_IN
298 | 1 << NF_IP6_LOCAL_OUT
299 | 1 << NF_IP6_POST_ROUTING)));
Philip Blundell8c700902000-05-15 02:17:52 +0000300
301 assert(h->info.hook_entry[NF_IP6_PRE_ROUTING] == 0);
302
303 n = get_chain_end(h, 0);
Harald Welte95df8e72002-02-13 23:13:23 +0000304
Philip Blundell8c700902000-05-15 02:17:52 +0000305 n += get_entry(h, n)->next_offset;
306 assert(h->info.hook_entry[NF_IP6_POST_ROUTING] == n);
Philip Blundell8c700902000-05-15 02:17:52 +0000307 n = get_chain_end(h, n);
Harald Welte95df8e72002-02-13 23:13:23 +0000308
Philip Blundell8c700902000-05-15 02:17:52 +0000309 n += get_entry(h, n)->next_offset;
310 assert(h->info.hook_entry[NF_IP6_LOCAL_OUT] == n);
Philip Blundell8c700902000-05-15 02:17:52 +0000311 user_offset = h->info.hook_entry[NF_IP6_LOCAL_OUT];
Harald Welte95df8e72002-02-13 23:13:23 +0000312
313 if (h->info.valid_hooks & (1 << NF_IP6_LOCAL_IN)) {
314 n = get_chain_end(h, n);
315 n += get_entry(h, n)->next_offset;
316 assert(h->info.hook_entry[NF_IP6_LOCAL_IN] == n);
317 user_offset = h->info.hook_entry[NF_IP6_LOCAL_IN];
318 }
319
Philip Blundell8c700902000-05-15 02:17:52 +0000320 } else if (strcmp(h->info.name, "mangle") == 0) {
Harald Welte596707c2002-02-13 16:35:39 +0000321 /* This code is getting ugly because linux < 2.4.18-pre6 had
322 * two mangle hooks, linux >= 2.4.18-pre6 has five mangle hooks
323 * */
Harald Welte95df8e72002-02-13 23:13:23 +0000324 assert((h->info.valid_hooks
325 == (1 << NF_IP6_PRE_ROUTING
326 | 1 << NF_IP6_LOCAL_OUT)) ||
327 (h->info.valid_hooks
328 == (1 << NF_IP6_PRE_ROUTING
329 | 1 << NF_IP6_LOCAL_IN
330 | 1 << NF_IP6_FORWARD
331 | 1 << NF_IP6_LOCAL_OUT
332 | 1 << NF_IP6_POST_ROUTING)));
Philip Blundell8c700902000-05-15 02:17:52 +0000333
Harald Welte380ba5f2002-02-13 16:19:55 +0000334 /* Hooks should be first five */
Philip Blundell8c700902000-05-15 02:17:52 +0000335 assert(h->info.hook_entry[NF_IP6_PRE_ROUTING] == 0);
336
337 n = get_chain_end(h, 0);
Harald Welte380ba5f2002-02-13 16:19:55 +0000338
Harald Weltea540b1b2002-02-13 22:42:52 +0000339 if (h->info.valid_hooks & (1 << NF_IP6_LOCAL_IN)) {
Harald Welte596707c2002-02-13 16:35:39 +0000340 n += get_entry(h, n)->next_offset;
341 assert(h->info.hook_entry[NF_IP6_LOCAL_IN] == n);
342 n = get_chain_end(h, n);
343 }
Harald Welte380ba5f2002-02-13 16:19:55 +0000344
Harald Weltea540b1b2002-02-13 22:42:52 +0000345 if (h->info.valid_hooks & (1 << NF_IP6_FORWARD)) {
Harald Welte596707c2002-02-13 16:35:39 +0000346 n += get_entry(h, n)->next_offset;
347 assert(h->info.hook_entry[NF_IP6_FORWARD] == n);
348 n = get_chain_end(h, n);
349 }
350
Harald Welte380ba5f2002-02-13 16:19:55 +0000351 n += get_entry(h, n)->next_offset;
Philip Blundell8c700902000-05-15 02:17:52 +0000352 assert(h->info.hook_entry[NF_IP6_LOCAL_OUT] == n);
Harald Welte596707c2002-02-13 16:35:39 +0000353 user_offset = h->info.hook_entry[NF_IP6_LOCAL_OUT];
Philip Blundell8c700902000-05-15 02:17:52 +0000354
Harald Weltea540b1b2002-02-13 22:42:52 +0000355 if (h->info.valid_hooks & (1 << NF_IP6_POST_ROUTING)) {
Harald Welte596707c2002-02-13 16:35:39 +0000356 n = get_chain_end(h, n);
357 n += get_entry(h, n)->next_offset;
358 assert(h->info.hook_entry[NF_IP6_POST_ROUTING] == n);
359 user_offset = h->info.hook_entry[NF_IP6_POST_ROUTING];
360 }
Harald Welte50fceae2003-10-07 22:12:31 +0000361 } else if (strcmp(h->info.name, "raw") == 0) {
362 assert(h->info.valid_hooks
363 == (1 << NF_IP6_PRE_ROUTING
364 | 1 << NF_IP6_LOCAL_OUT));
365
366 /* Hooks should be first three */
367 assert(h->info.hook_entry[NF_IP6_PRE_ROUTING] == 0);
368
369 n = get_chain_end(h, n);
370 n += get_entry(h, n)->next_offset;
371 assert(h->info.hook_entry[NF_IP6_LOCAL_OUT] == n);
372
373 user_offset = h->info.hook_entry[NF_IP6_LOCAL_OUT];
Harald Weltea540b1b2002-02-13 22:42:52 +0000374 } else {
375 fprintf(stderr, "Unknown table `%s'\n", h->info.name);
Philip Blundell8c700902000-05-15 02:17:52 +0000376 abort();
Harald Weltea540b1b2002-02-13 22:42:52 +0000377 }
Philip Blundell8c700902000-05-15 02:17:52 +0000378
379 /* User chain == end of last builtin + policy entry */
380 user_offset = get_chain_end(h, user_offset);
381 user_offset += get_entry(h, user_offset)->next_offset;
382
383 /* Overflows should be end of entry chains, and unconditional
384 policy nodes. */
385 for (i = 0; i < NUMHOOKS; i++) {
386 STRUCT_ENTRY *e;
387 STRUCT_STANDARD_TARGET *t;
388
389 if (!(h->info.valid_hooks & (1 << i)))
390 continue;
391 assert(h->info.underflow[i]
392 == get_chain_end(h, h->info.hook_entry[i]));
393
394 e = get_entry(h, get_chain_end(h, h->info.hook_entry[i]));
Rusty Russell5eed48a2000-06-02 20:12:24 +0000395 assert(unconditional(&e->ipv6));
Philip Blundell8c700902000-05-15 02:17:52 +0000396 assert(e->target_offset == sizeof(*e));
397 t = (STRUCT_STANDARD_TARGET *)GET_TARGET(e);
Harald Weltea540b1b2002-02-13 22:42:52 +0000398 printf("target_size=%u, align=%u\n",
399 t->target.u.target_size, ALIGN(sizeof(*t)));
Philip Blundell8c700902000-05-15 02:17:52 +0000400 assert(t->target.u.target_size == ALIGN(sizeof(*t)));
401 assert(e->next_offset == sizeof(*e) + ALIGN(sizeof(*t)));
402
403 assert(strcmp(t->target.u.user.name, STANDARD_TARGET)==0);
404 assert(t->verdict == -NF_DROP-1 || t->verdict == -NF_ACCEPT-1);
405
406 /* Hooks and underflows must be valid entries */
Harald Welteaae69be2004-08-29 23:32:14 +0000407 iptcb_entry2index(h, get_entry(h, h->info.hook_entry[i]));
408 iptcb_entry2index(h, get_entry(h, h->info.underflow[i]));
Philip Blundell8c700902000-05-15 02:17:52 +0000409 }
410
411 assert(h->info.size
412 >= h->info.num_entries * (sizeof(STRUCT_ENTRY)
413 +sizeof(STRUCT_STANDARD_TARGET)));
414
415 assert(h->entries.size
416 >= (h->new_number
417 * (sizeof(STRUCT_ENTRY)
418 + sizeof(STRUCT_STANDARD_TARGET))));
419 assert(strcmp(h->info.name, h->entries.name) == 0);
420
421 i = 0; n = 0;
422 was_return = 0;
423
Rusty Russell5eed48a2000-06-02 20:12:24 +0000424#if 0
Philip Blundell8c700902000-05-15 02:17:52 +0000425 /* Check all the entries. */
Harald Weltea540b1b2002-02-13 22:42:52 +0000426 ENTRY_ITERATE(h->entries.entrytable, h->entries.size,
Rusty Russell5eed48a2000-06-02 20:12:24 +0000427 check_entry, &i, &n, user_offset, &was_return, h);
Philip Blundell8c700902000-05-15 02:17:52 +0000428
429 assert(i == h->new_number);
430 assert(n == h->entries.size);
431
432 /* Final entry must be error node */
433 assert(strcmp(GET_TARGET(index2entry(h, h->new_number-1))
434 ->u.user.name,
435 ERROR_TARGET) == 0);
Rusty Russell5eed48a2000-06-02 20:12:24 +0000436#endif
Philip Blundell8c700902000-05-15 02:17:52 +0000437}
Harald Welte380ba5f2002-02-13 16:19:55 +0000438#endif /*IPTC_DEBUG*/