Rusty Russell | 79dee07 | 2000-05-02 16:45:16 +0000 | [diff] [blame] | 1 | /* 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 Boucher | 1afc3b6 | 2002-01-19 12:46:39 +0000 | [diff] [blame] | 19 | #include <unistd.h> |
Rusty Russell | 79dee07 | 2000-05-02 16:45:16 +0000 | [diff] [blame] | 20 | #include <arpa/inet.h> |
| 21 | |
| 22 | #ifdef DEBUG_CONNTRACK |
| 23 | #define inline |
| 24 | #endif |
| 25 | |
| 26 | #if !defined(__GLIBC__) || (__GLIBC__ < 2) |
| 27 | typedef 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 |
| 49 | #define TC_HANDLE_T ip6tc_handle_t |
| 50 | |
| 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 Blundell | 8c70090 | 2000-05-15 02:17:52 +0000 | [diff] [blame] | 64 | #define TC_FIRST_CHAIN ip6tc_first_chain |
Rusty Russell | 79dee07 | 2000-05-02 16:45:16 +0000 | [diff] [blame] | 65 | #define TC_NEXT_CHAIN ip6tc_next_chain |
Philip Blundell | 8c70090 | 2000-05-15 02:17:52 +0000 | [diff] [blame] | 66 | #define TC_FIRST_RULE ip6tc_first_rule |
| 67 | #define TC_NEXT_RULE ip6tc_next_rule |
Rusty Russell | 79dee07 | 2000-05-02 16:45:16 +0000 | [diff] [blame] | 68 | #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 |
| 74 | #define TC_DELETE_ENTRY ip6tc_delete_entry |
| 75 | #define TC_DELETE_NUM_ENTRY ip6tc_delete_num_entry |
| 76 | #define TC_CHECK_PACKET ip6tc_check_packet |
| 77 | #define TC_FLUSH_ENTRIES ip6tc_flush_entries |
| 78 | #define TC_ZERO_ENTRIES ip6tc_zero_entries |
Harald Welte | 1cef74d | 2001-01-05 15:22:59 +0000 | [diff] [blame] | 79 | #define TC_ZERO_COUNTER ip6tc_zero_counter |
| 80 | #define TC_READ_COUNTER ip6tc_read_counter |
| 81 | #define TC_SET_COUNTER ip6tc_set_counter |
Rusty Russell | 79dee07 | 2000-05-02 16:45:16 +0000 | [diff] [blame] | 82 | #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 |
| 89 | #define TC_COMMIT ip6tc_commit |
| 90 | #define TC_STRERROR ip6tc_strerror |
| 91 | |
| 92 | #define TC_AF AF_INET6 |
| 93 | #define TC_IPPROTO IPPROTO_IPV6 |
| 94 | |
| 95 | #define SO_SET_REPLACE IP6T_SO_SET_REPLACE |
| 96 | #define SO_SET_ADD_COUNTERS IP6T_SO_SET_ADD_COUNTERS |
| 97 | #define SO_GET_INFO IP6T_SO_GET_INFO |
| 98 | #define SO_GET_ENTRIES IP6T_SO_GET_ENTRIES |
| 99 | #define SO_GET_VERSION IP6T_SO_GET_VERSION |
| 100 | |
| 101 | #define STANDARD_TARGET IP6T_STANDARD_TARGET |
| 102 | #define LABEL_RETURN IP6TC_LABEL_RETURN |
| 103 | #define LABEL_ACCEPT IP6TC_LABEL_ACCEPT |
| 104 | #define LABEL_DROP IP6TC_LABEL_DROP |
Philip Blundell | 88eb835 | 2000-05-10 00:25:04 +0000 | [diff] [blame] | 105 | #define LABEL_QUEUE IP6TC_LABEL_QUEUE |
Rusty Russell | 79dee07 | 2000-05-02 16:45:16 +0000 | [diff] [blame] | 106 | |
| 107 | #define ALIGN IP6T_ALIGN |
| 108 | #define RETURN IP6T_RETURN |
| 109 | |
| 110 | #include "libiptc.c" |
| 111 | |
| 112 | #define BIT6(a, l) \ |
| 113 | (((a->in6_u.u6_addr32[(l) / 32]) >> ((l) & 31)) & 1) |
| 114 | |
| 115 | int |
| 116 | ipv6_prefix_length(const struct in6_addr *a) |
| 117 | { |
| 118 | int l, i; |
| 119 | for (l = 0; l < 128; l++) { |
| 120 | if (BIT6(a, l) == 0) |
| 121 | break; |
| 122 | } |
| 123 | for (i = l + 1; i < 128; i++) { |
| 124 | if (BIT6(a, i) == 1) |
| 125 | return -1; |
| 126 | } |
| 127 | return l; |
| 128 | } |
| 129 | |
| 130 | static int |
| 131 | dump_entry(struct ip6t_entry *e, const ip6tc_handle_t handle) |
| 132 | { |
| 133 | size_t i; |
| 134 | char buf[40]; |
| 135 | int len; |
| 136 | struct ip6t_entry_target *t; |
| 137 | |
| 138 | printf("Entry %u (%lu):\n", entry2index(handle, e), |
| 139 | entry2offset(handle, e)); |
| 140 | puts("SRC IP: "); |
| 141 | inet_ntop(AF_INET6, &e->ipv6.src, buf, sizeof buf); |
| 142 | puts(buf); |
| 143 | putchar('/'); |
| 144 | len = ipv6_prefix_length(&e->ipv6.smsk); |
| 145 | if (len != -1) |
| 146 | printf("%d", len); |
| 147 | else { |
| 148 | inet_ntop(AF_INET6, &e->ipv6.smsk, buf, sizeof buf); |
| 149 | puts(buf); |
| 150 | } |
| 151 | putchar('\n'); |
| 152 | |
| 153 | puts("DST IP: "); |
| 154 | inet_ntop(AF_INET6, &e->ipv6.dst, buf, sizeof buf); |
| 155 | puts(buf); |
| 156 | putchar('/'); |
| 157 | len = ipv6_prefix_length(&e->ipv6.dmsk); |
| 158 | if (len != -1) |
| 159 | printf("%d", len); |
| 160 | else { |
| 161 | inet_ntop(AF_INET6, &e->ipv6.dmsk, buf, sizeof buf); |
| 162 | puts(buf); |
| 163 | } |
| 164 | putchar('\n'); |
| 165 | |
| 166 | printf("Interface: `%s'/", e->ipv6.iniface); |
| 167 | for (i = 0; i < IFNAMSIZ; i++) |
| 168 | printf("%c", e->ipv6.iniface_mask[i] ? 'X' : '.'); |
| 169 | printf("to `%s'/", e->ipv6.outiface); |
| 170 | for (i = 0; i < IFNAMSIZ; i++) |
| 171 | printf("%c", e->ipv6.outiface_mask[i] ? 'X' : '.'); |
| 172 | printf("\nProtocol: %u\n", e->ipv6.proto); |
| 173 | if (e->ipv6.flags & IP6T_F_TOS) |
| 174 | printf("TOS: %u\n", e->ipv6.tos); |
| 175 | printf("Flags: %02X\n", e->ipv6.flags); |
| 176 | printf("Invflags: %02X\n", e->ipv6.invflags); |
| 177 | printf("Counters: %llu packets, %llu bytes\n", |
| 178 | e->counters.pcnt, e->counters.bcnt); |
| 179 | printf("Cache: %08X ", e->nfcache); |
| 180 | if (e->nfcache & NFC_ALTERED) printf("ALTERED "); |
| 181 | if (e->nfcache & NFC_UNKNOWN) printf("UNKNOWN "); |
| 182 | if (e->nfcache & NFC_IP6_SRC) printf("IP6_SRC "); |
| 183 | if (e->nfcache & NFC_IP6_DST) printf("IP6_DST "); |
| 184 | if (e->nfcache & NFC_IP6_IF_IN) printf("IP6_IF_IN "); |
| 185 | if (e->nfcache & NFC_IP6_IF_OUT) printf("IP6_IF_OUT "); |
| 186 | if (e->nfcache & NFC_IP6_TOS) printf("IP6_TOS "); |
| 187 | if (e->nfcache & NFC_IP6_PROTO) printf("IP6_PROTO "); |
| 188 | if (e->nfcache & NFC_IP6_OPTIONS) printf("IP6_OPTIONS "); |
| 189 | if (e->nfcache & NFC_IP6_TCPFLAGS) printf("IP6_TCPFLAGS "); |
| 190 | if (e->nfcache & NFC_IP6_SRC_PT) printf("IP6_SRC_PT "); |
| 191 | if (e->nfcache & NFC_IP6_DST_PT) printf("IP6_DST_PT "); |
| 192 | if (e->nfcache & NFC_IP6_PROTO_UNKNOWN) printf("IP6_PROTO_UNKNOWN "); |
| 193 | printf("\n"); |
| 194 | |
| 195 | IP6T_MATCH_ITERATE(e, print_match); |
| 196 | |
| 197 | t = ip6t_get_target(e); |
Philip Blundell | 88eb835 | 2000-05-10 00:25:04 +0000 | [diff] [blame] | 198 | printf("Target name: `%s' [%u]\n", t->u.user.name, t->u.target_size); |
| 199 | if (strcmp(t->u.user.name, IP6T_STANDARD_TARGET) == 0) { |
Rusty Russell | 79dee07 | 2000-05-02 16:45:16 +0000 | [diff] [blame] | 200 | int pos = *(int *)t->data; |
| 201 | if (pos < 0) |
| 202 | printf("verdict=%s\n", |
| 203 | pos == -NF_ACCEPT-1 ? "NF_ACCEPT" |
| 204 | : pos == -NF_DROP-1 ? "NF_DROP" |
| 205 | : pos == IP6T_RETURN ? "RETURN" |
| 206 | : "UNKNOWN"); |
| 207 | else |
| 208 | printf("verdict=%u\n", pos); |
Philip Blundell | 88eb835 | 2000-05-10 00:25:04 +0000 | [diff] [blame] | 209 | } else if (strcmp(t->u.user.name, IP6T_ERROR_TARGET) == 0) |
Rusty Russell | 79dee07 | 2000-05-02 16:45:16 +0000 | [diff] [blame] | 210 | printf("error=`%s'\n", t->data); |
| 211 | |
| 212 | printf("\n"); |
| 213 | return 0; |
| 214 | } |
| 215 | |
Philip Blundell | 88eb835 | 2000-05-10 00:25:04 +0000 | [diff] [blame] | 216 | static int |
| 217 | is_same(const STRUCT_ENTRY *a, const STRUCT_ENTRY *b, |
Rusty Russell | 79dee07 | 2000-05-02 16:45:16 +0000 | [diff] [blame] | 218 | unsigned char *matchmask) |
| 219 | { |
| 220 | unsigned int i; |
Philip Blundell | 88eb835 | 2000-05-10 00:25:04 +0000 | [diff] [blame] | 221 | STRUCT_ENTRY_TARGET *ta, *tb; |
Rusty Russell | 79dee07 | 2000-05-02 16:45:16 +0000 | [diff] [blame] | 222 | unsigned char *mptr; |
| 223 | |
| 224 | /* Always compare head structures: ignore mask here. */ |
| 225 | if (memcmp(&a->ipv6.src, &b->ipv6.src, sizeof(struct in6_addr)) |
| 226 | || memcmp(&a->ipv6.dst, &b->ipv6.dst, sizeof(struct in6_addr)) |
| 227 | || memcmp(&a->ipv6.smsk, &b->ipv6.smsk, sizeof(struct in6_addr)) |
| 228 | || memcmp(&a->ipv6.dmsk, &b->ipv6.dmsk, sizeof(struct in6_addr)) |
| 229 | || a->ipv6.proto != b->ipv6.proto |
| 230 | || a->ipv6.tos != b->ipv6.tos |
| 231 | || a->ipv6.flags != b->ipv6.flags |
| 232 | || a->ipv6.invflags != b->ipv6.invflags) |
| 233 | return 0; |
| 234 | |
| 235 | for (i = 0; i < IFNAMSIZ; i++) { |
| 236 | if (a->ipv6.iniface_mask[i] != b->ipv6.iniface_mask[i]) |
| 237 | return 0; |
| 238 | if ((a->ipv6.iniface[i] & a->ipv6.iniface_mask[i]) |
| 239 | != (b->ipv6.iniface[i] & b->ipv6.iniface_mask[i])) |
| 240 | return 0; |
| 241 | if (a->ipv6.outiface_mask[i] != b->ipv6.outiface_mask[i]) |
| 242 | return 0; |
| 243 | if ((a->ipv6.outiface[i] & a->ipv6.outiface_mask[i]) |
| 244 | != (b->ipv6.outiface[i] & b->ipv6.outiface_mask[i])) |
| 245 | return 0; |
| 246 | } |
| 247 | |
| 248 | if (a->nfcache != b->nfcache |
| 249 | || a->target_offset != b->target_offset |
| 250 | || a->next_offset != b->next_offset) |
| 251 | return 0; |
| 252 | |
Philip Blundell | 88eb835 | 2000-05-10 00:25:04 +0000 | [diff] [blame] | 253 | mptr = matchmask + sizeof(STRUCT_ENTRY); |
| 254 | if (IP6T_MATCH_ITERATE(a, match_different, a->elems, b->elems, &mptr)) |
Rusty Russell | 79dee07 | 2000-05-02 16:45:16 +0000 | [diff] [blame] | 255 | return 0; |
| 256 | |
Philip Blundell | 88eb835 | 2000-05-10 00:25:04 +0000 | [diff] [blame] | 257 | ta = GET_TARGET((STRUCT_ENTRY *)a); |
| 258 | tb = GET_TARGET((STRUCT_ENTRY *)b); |
| 259 | if (ta->u.target_size != tb->u.target_size) |
Rusty Russell | 79dee07 | 2000-05-02 16:45:16 +0000 | [diff] [blame] | 260 | return 0; |
Philip Blundell | 88eb835 | 2000-05-10 00:25:04 +0000 | [diff] [blame] | 261 | if (strcmp(ta->u.user.name, tb->u.user.name) != 0) |
Rusty Russell | 79dee07 | 2000-05-02 16:45:16 +0000 | [diff] [blame] | 262 | return 0; |
| 263 | mptr += sizeof(*ta); |
| 264 | |
| 265 | if (target_different(ta->data, tb->data, |
| 266 | ta->u.target_size - sizeof(*ta), mptr)) |
| 267 | return 0; |
| 268 | |
| 269 | return 1; |
| 270 | } |
Philip Blundell | 8c70090 | 2000-05-15 02:17:52 +0000 | [diff] [blame] | 271 | |
Rusty Russell | 5eed48a | 2000-06-02 20:12:24 +0000 | [diff] [blame] | 272 | /* All zeroes == unconditional rule. */ |
| 273 | static inline int |
| 274 | unconditional(const struct ip6t_ip6 *ipv6) |
| 275 | { |
| 276 | unsigned int i; |
| 277 | |
| 278 | for (i = 0; i < sizeof(*ipv6); i++) |
| 279 | if (((char *)ipv6)[i]) |
| 280 | break; |
| 281 | |
| 282 | return (i == sizeof(*ipv6)); |
| 283 | } |
| 284 | |
Harald Welte | 380ba5f | 2002-02-13 16:19:55 +0000 | [diff] [blame] | 285 | #ifdef IPTC_DEBUG |
Philip Blundell | 8c70090 | 2000-05-15 02:17:52 +0000 | [diff] [blame] | 286 | /* Do every conceivable sanity check on the handle */ |
| 287 | static void |
| 288 | do_check(TC_HANDLE_T h, unsigned int line) |
| 289 | { |
| 290 | unsigned int i, n; |
| 291 | unsigned int user_offset; /* Offset of first user chain */ |
| 292 | int was_return; |
| 293 | |
| 294 | assert(h->changed == 0 || h->changed == 1); |
| 295 | if (strcmp(h->info.name, "filter") == 0) { |
| 296 | assert(h->info.valid_hooks |
| 297 | == (1 << NF_IP6_LOCAL_IN |
| 298 | | 1 << NF_IP6_FORWARD |
| 299 | | 1 << NF_IP6_LOCAL_OUT)); |
| 300 | |
| 301 | /* Hooks should be first three */ |
| 302 | assert(h->info.hook_entry[NF_IP6_LOCAL_IN] == 0); |
| 303 | |
| 304 | n = get_chain_end(h, 0); |
| 305 | n += get_entry(h, n)->next_offset; |
| 306 | assert(h->info.hook_entry[NF_IP6_FORWARD] == n); |
| 307 | |
| 308 | n = get_chain_end(h, n); |
| 309 | n += get_entry(h, n)->next_offset; |
| 310 | assert(h->info.hook_entry[NF_IP6_LOCAL_OUT] == n); |
| 311 | |
| 312 | user_offset = h->info.hook_entry[NF_IP6_LOCAL_OUT]; |
| 313 | } else if (strcmp(h->info.name, "nat") == 0) { |
| 314 | assert(h->info.valid_hooks |
| 315 | == (1 << NF_IP6_PRE_ROUTING |
| 316 | | 1 << NF_IP6_POST_ROUTING |
| 317 | | 1 << NF_IP6_LOCAL_OUT)); |
| 318 | |
| 319 | assert(h->info.hook_entry[NF_IP6_PRE_ROUTING] == 0); |
| 320 | |
| 321 | n = get_chain_end(h, 0); |
| 322 | n += get_entry(h, n)->next_offset; |
| 323 | assert(h->info.hook_entry[NF_IP6_POST_ROUTING] == n); |
| 324 | |
| 325 | n = get_chain_end(h, n); |
| 326 | n += get_entry(h, n)->next_offset; |
| 327 | assert(h->info.hook_entry[NF_IP6_LOCAL_OUT] == n); |
| 328 | |
| 329 | user_offset = h->info.hook_entry[NF_IP6_LOCAL_OUT]; |
| 330 | } else if (strcmp(h->info.name, "mangle") == 0) { |
Harald Welte | 596707c | 2002-02-13 16:35:39 +0000 | [diff] [blame] | 331 | /* This code is getting ugly because linux < 2.4.18-pre6 had |
| 332 | * two mangle hooks, linux >= 2.4.18-pre6 has five mangle hooks |
| 333 | * */ |
| 334 | assert((h->info.valid_hooks & |
| 335 | ~(1 << NF_IP6_LOCAL_IN |
| 336 | | 1 << NF_IP6_FORWARD |
| 337 | | 1 << NF_IP6_POST_ROUTING)) |
Philip Blundell | 8c70090 | 2000-05-15 02:17:52 +0000 | [diff] [blame] | 338 | == (1 << NF_IP6_PRE_ROUTING |
Harald Welte | 596707c | 2002-02-13 16:35:39 +0000 | [diff] [blame] | 339 | | 1 << NF_IP6_LOCAL_OUT)); |
Philip Blundell | 8c70090 | 2000-05-15 02:17:52 +0000 | [diff] [blame] | 340 | |
Harald Welte | 380ba5f | 2002-02-13 16:19:55 +0000 | [diff] [blame] | 341 | /* Hooks should be first five */ |
Philip Blundell | 8c70090 | 2000-05-15 02:17:52 +0000 | [diff] [blame] | 342 | assert(h->info.hook_entry[NF_IP6_PRE_ROUTING] == 0); |
| 343 | |
| 344 | n = get_chain_end(h, 0); |
Harald Welte | 380ba5f | 2002-02-13 16:19:55 +0000 | [diff] [blame] | 345 | |
Harald Welte | a540b1b | 2002-02-13 22:42:52 +0000 | [diff] [blame^] | 346 | if (h->info.valid_hooks & (1 << NF_IP6_LOCAL_IN)) { |
Harald Welte | 596707c | 2002-02-13 16:35:39 +0000 | [diff] [blame] | 347 | n += get_entry(h, n)->next_offset; |
| 348 | assert(h->info.hook_entry[NF_IP6_LOCAL_IN] == n); |
| 349 | n = get_chain_end(h, n); |
| 350 | } |
Harald Welte | 380ba5f | 2002-02-13 16:19:55 +0000 | [diff] [blame] | 351 | |
Harald Welte | a540b1b | 2002-02-13 22:42:52 +0000 | [diff] [blame^] | 352 | if (h->info.valid_hooks & (1 << NF_IP6_FORWARD)) { |
Harald Welte | 596707c | 2002-02-13 16:35:39 +0000 | [diff] [blame] | 353 | n += get_entry(h, n)->next_offset; |
| 354 | assert(h->info.hook_entry[NF_IP6_FORWARD] == n); |
| 355 | n = get_chain_end(h, n); |
| 356 | } |
| 357 | |
Harald Welte | 380ba5f | 2002-02-13 16:19:55 +0000 | [diff] [blame] | 358 | n += get_entry(h, n)->next_offset; |
Philip Blundell | 8c70090 | 2000-05-15 02:17:52 +0000 | [diff] [blame] | 359 | assert(h->info.hook_entry[NF_IP6_LOCAL_OUT] == n); |
Harald Welte | 596707c | 2002-02-13 16:35:39 +0000 | [diff] [blame] | 360 | user_offset = h->info.hook_entry[NF_IP6_LOCAL_OUT]; |
Philip Blundell | 8c70090 | 2000-05-15 02:17:52 +0000 | [diff] [blame] | 361 | |
Harald Welte | a540b1b | 2002-02-13 22:42:52 +0000 | [diff] [blame^] | 362 | if (h->info.valid_hooks & (1 << NF_IP6_POST_ROUTING)) { |
Harald Welte | 596707c | 2002-02-13 16:35:39 +0000 | [diff] [blame] | 363 | n = get_chain_end(h, n); |
| 364 | n += get_entry(h, n)->next_offset; |
| 365 | assert(h->info.hook_entry[NF_IP6_POST_ROUTING] == n); |
| 366 | user_offset = h->info.hook_entry[NF_IP6_POST_ROUTING]; |
| 367 | } |
Harald Welte | a540b1b | 2002-02-13 22:42:52 +0000 | [diff] [blame^] | 368 | } else { |
| 369 | fprintf(stderr, "Unknown table `%s'\n", h->info.name); |
Philip Blundell | 8c70090 | 2000-05-15 02:17:52 +0000 | [diff] [blame] | 370 | abort(); |
Harald Welte | a540b1b | 2002-02-13 22:42:52 +0000 | [diff] [blame^] | 371 | } |
Philip Blundell | 8c70090 | 2000-05-15 02:17:52 +0000 | [diff] [blame] | 372 | |
| 373 | /* User chain == end of last builtin + policy entry */ |
| 374 | user_offset = get_chain_end(h, user_offset); |
| 375 | user_offset += get_entry(h, user_offset)->next_offset; |
| 376 | |
| 377 | /* Overflows should be end of entry chains, and unconditional |
| 378 | policy nodes. */ |
| 379 | for (i = 0; i < NUMHOOKS; i++) { |
| 380 | STRUCT_ENTRY *e; |
| 381 | STRUCT_STANDARD_TARGET *t; |
| 382 | |
| 383 | if (!(h->info.valid_hooks & (1 << i))) |
| 384 | continue; |
| 385 | assert(h->info.underflow[i] |
| 386 | == get_chain_end(h, h->info.hook_entry[i])); |
| 387 | |
| 388 | e = get_entry(h, get_chain_end(h, h->info.hook_entry[i])); |
Rusty Russell | 5eed48a | 2000-06-02 20:12:24 +0000 | [diff] [blame] | 389 | assert(unconditional(&e->ipv6)); |
Philip Blundell | 8c70090 | 2000-05-15 02:17:52 +0000 | [diff] [blame] | 390 | assert(e->target_offset == sizeof(*e)); |
| 391 | t = (STRUCT_STANDARD_TARGET *)GET_TARGET(e); |
Harald Welte | a540b1b | 2002-02-13 22:42:52 +0000 | [diff] [blame^] | 392 | printf("target_size=%u, align=%u\n", |
| 393 | t->target.u.target_size, ALIGN(sizeof(*t))); |
Philip Blundell | 8c70090 | 2000-05-15 02:17:52 +0000 | [diff] [blame] | 394 | assert(t->target.u.target_size == ALIGN(sizeof(*t))); |
| 395 | assert(e->next_offset == sizeof(*e) + ALIGN(sizeof(*t))); |
| 396 | |
| 397 | assert(strcmp(t->target.u.user.name, STANDARD_TARGET)==0); |
| 398 | assert(t->verdict == -NF_DROP-1 || t->verdict == -NF_ACCEPT-1); |
| 399 | |
| 400 | /* Hooks and underflows must be valid entries */ |
| 401 | entry2index(h, get_entry(h, h->info.hook_entry[i])); |
| 402 | entry2index(h, get_entry(h, h->info.underflow[i])); |
| 403 | } |
| 404 | |
| 405 | assert(h->info.size |
| 406 | >= h->info.num_entries * (sizeof(STRUCT_ENTRY) |
| 407 | +sizeof(STRUCT_STANDARD_TARGET))); |
| 408 | |
| 409 | assert(h->entries.size |
| 410 | >= (h->new_number |
| 411 | * (sizeof(STRUCT_ENTRY) |
| 412 | + sizeof(STRUCT_STANDARD_TARGET)))); |
| 413 | assert(strcmp(h->info.name, h->entries.name) == 0); |
| 414 | |
| 415 | i = 0; n = 0; |
| 416 | was_return = 0; |
| 417 | |
Rusty Russell | 5eed48a | 2000-06-02 20:12:24 +0000 | [diff] [blame] | 418 | #if 0 |
Philip Blundell | 8c70090 | 2000-05-15 02:17:52 +0000 | [diff] [blame] | 419 | /* Check all the entries. */ |
Harald Welte | a540b1b | 2002-02-13 22:42:52 +0000 | [diff] [blame^] | 420 | ENTRY_ITERATE(h->entries.entrytable, h->entries.size, |
Rusty Russell | 5eed48a | 2000-06-02 20:12:24 +0000 | [diff] [blame] | 421 | check_entry, &i, &n, user_offset, &was_return, h); |
Philip Blundell | 8c70090 | 2000-05-15 02:17:52 +0000 | [diff] [blame] | 422 | |
| 423 | assert(i == h->new_number); |
| 424 | assert(n == h->entries.size); |
| 425 | |
| 426 | /* Final entry must be error node */ |
| 427 | assert(strcmp(GET_TARGET(index2entry(h, h->new_number-1)) |
| 428 | ->u.user.name, |
| 429 | ERROR_TARGET) == 0); |
Rusty Russell | 5eed48a | 2000-06-02 20:12:24 +0000 | [diff] [blame] | 430 | #endif |
Philip Blundell | 8c70090 | 2000-05-15 02:17:52 +0000 | [diff] [blame] | 431 | } |
Harald Welte | 380ba5f | 2002-02-13 16:19:55 +0000 | [diff] [blame] | 432 | #endif /*IPTC_DEBUG*/ |