blob: b75f8fdc3afe5c245b2f608614ff07e091ab0252 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Packet matching code.
3 *
4 * Copyright (C) 1999 Paul `Rusty' Russell & Michael J. Neuling
Harald Welte6b7d31f2005-10-26 09:34:24 +02005 * Copyright (C) 2000-2005 Netfilter Core Team <coreteam@netfilter.org>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * 19 Jan 2002 Harald Welte <laforge@gnumonks.org>
12 * - increase module usage count as soon as we have rules inside
13 * a table
14 * 06 Jun 2002 Andras Kis-Szabo <kisza@sch.bme.hu>
15 * - new extension header parser code
Harald Welte2e4e6a12006-01-12 13:30:04 -080016 * 15 Oct 2005 Harald Welte <laforge@netfilter.org>
17 * - Unification of {ip,ip6}_tables into x_tables
18 * - Removed tcp and udp code, since it's not ipv6 specific
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 */
Randy Dunlap4fc268d2006-01-11 12:17:47 -080020
21#include <linux/capability.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/config.h>
Arnaldo Carvalho de Melo14c85022005-12-27 02:43:12 -020023#include <linux/in.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <linux/skbuff.h>
25#include <linux/kmod.h>
26#include <linux/vmalloc.h>
27#include <linux/netdevice.h>
28#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/icmpv6.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <net/ipv6.h>
31#include <asm/uaccess.h>
32#include <asm/semaphore.h>
33#include <linux/proc_fs.h>
David S. Millerc8923c62005-10-13 14:41:23 -070034#include <linux/cpumask.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
36#include <linux/netfilter_ipv6/ip6_tables.h>
Harald Welte2e4e6a12006-01-12 13:30:04 -080037#include <linux/netfilter/x_tables.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
39MODULE_LICENSE("GPL");
40MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>");
41MODULE_DESCRIPTION("IPv6 packet filter");
42
43#define IPV6_HDR_LEN (sizeof(struct ipv6hdr))
44#define IPV6_OPTHDR_LEN (sizeof(struct ipv6_opt_hdr))
45
46/*#define DEBUG_IP_FIREWALL*/
47/*#define DEBUG_ALLOW_ALL*/ /* Useful for remote debugging */
48/*#define DEBUG_IP_FIREWALL_USER*/
49
50#ifdef DEBUG_IP_FIREWALL
51#define dprintf(format, args...) printk(format , ## args)
52#else
53#define dprintf(format, args...)
54#endif
55
56#ifdef DEBUG_IP_FIREWALL_USER
57#define duprintf(format, args...) printk(format , ## args)
58#else
59#define duprintf(format, args...)
60#endif
61
62#ifdef CONFIG_NETFILTER_DEBUG
63#define IP_NF_ASSERT(x) \
64do { \
65 if (!(x)) \
66 printk("IP_NF_ASSERT: %s:%s:%u\n", \
67 __FUNCTION__, __FILE__, __LINE__); \
68} while(0)
69#else
70#define IP_NF_ASSERT(x)
71#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
Linus Torvalds1da177e2005-04-16 15:20:36 -070074#include <linux/netfilter_ipv4/listhelp.h>
75
76#if 0
77/* All the better to debug you with... */
78#define static
79#define inline
80#endif
81
Harald Welte6b7d31f2005-10-26 09:34:24 +020082/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 We keep a set of rules for each CPU, so we can avoid write-locking
Harald Welte6b7d31f2005-10-26 09:34:24 +020084 them in the softirq when updating the counters and therefore
85 only need to read-lock in the softirq; doing a write_lock_bh() in user
86 context stops packets coming through and allows user context to read
87 the counters or update the rules.
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 Hence the start of any table is given by get_table() below. */
90
Linus Torvalds1da177e2005-04-16 15:20:36 -070091#if 0
92#define down(x) do { printk("DOWN:%u:" #x "\n", __LINE__); down(x); } while(0)
93#define down_interruptible(x) ({ int __r; printk("DOWNi:%u:" #x "\n", __LINE__); __r = down_interruptible(x); if (__r != 0) printk("ABORT-DOWNi:%u\n", __LINE__); __r; })
94#define up(x) do { printk("UP:%u:" #x "\n", __LINE__); up(x); } while(0)
95#endif
96
Patrick McHardy22dea562006-01-05 12:21:34 -080097int
98ip6_masked_addrcmp(const struct in6_addr *addr1, const struct in6_addr *mask,
99 const struct in6_addr *addr2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100{
101 int i;
102 for( i = 0; i < 16; i++){
Patrick McHardy22dea562006-01-05 12:21:34 -0800103 if((addr1->s6_addr[i] & mask->s6_addr[i]) !=
104 (addr2->s6_addr[i] & mask->s6_addr[i]))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 return 1;
106 }
107 return 0;
108}
109
110/* Check for an extension */
111int
112ip6t_ext_hdr(u8 nexthdr)
113{
114 return ( (nexthdr == IPPROTO_HOPOPTS) ||
115 (nexthdr == IPPROTO_ROUTING) ||
116 (nexthdr == IPPROTO_FRAGMENT) ||
117 (nexthdr == IPPROTO_ESP) ||
118 (nexthdr == IPPROTO_AH) ||
119 (nexthdr == IPPROTO_NONE) ||
120 (nexthdr == IPPROTO_DSTOPTS) );
121}
122
123/* Returns whether matches rule or not. */
124static inline int
125ip6_packet_match(const struct sk_buff *skb,
126 const char *indev,
127 const char *outdev,
128 const struct ip6t_ip6 *ip6info,
129 unsigned int *protoff,
130 int *fragoff)
131{
132 size_t i;
133 unsigned long ret;
134 const struct ipv6hdr *ipv6 = skb->nh.ipv6h;
135
136#define FWINV(bool,invflg) ((bool) ^ !!(ip6info->invflags & invflg))
137
Patrick McHardy22dea562006-01-05 12:21:34 -0800138 if (FWINV(ip6_masked_addrcmp(&ipv6->saddr, &ip6info->smsk,
139 &ip6info->src), IP6T_INV_SRCIP)
140 || FWINV(ip6_masked_addrcmp(&ipv6->daddr, &ip6info->dmsk,
141 &ip6info->dst), IP6T_INV_DSTIP)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 dprintf("Source or dest mismatch.\n");
143/*
144 dprintf("SRC: %u. Mask: %u. Target: %u.%s\n", ip->saddr,
145 ipinfo->smsk.s_addr, ipinfo->src.s_addr,
146 ipinfo->invflags & IP6T_INV_SRCIP ? " (INV)" : "");
147 dprintf("DST: %u. Mask: %u. Target: %u.%s\n", ip->daddr,
148 ipinfo->dmsk.s_addr, ipinfo->dst.s_addr,
149 ipinfo->invflags & IP6T_INV_DSTIP ? " (INV)" : "");*/
150 return 0;
151 }
152
153 /* Look for ifname matches; this should unroll nicely. */
154 for (i = 0, ret = 0; i < IFNAMSIZ/sizeof(unsigned long); i++) {
155 ret |= (((const unsigned long *)indev)[i]
156 ^ ((const unsigned long *)ip6info->iniface)[i])
157 & ((const unsigned long *)ip6info->iniface_mask)[i];
158 }
159
160 if (FWINV(ret != 0, IP6T_INV_VIA_IN)) {
161 dprintf("VIA in mismatch (%s vs %s).%s\n",
162 indev, ip6info->iniface,
163 ip6info->invflags&IP6T_INV_VIA_IN ?" (INV)":"");
164 return 0;
165 }
166
167 for (i = 0, ret = 0; i < IFNAMSIZ/sizeof(unsigned long); i++) {
168 ret |= (((const unsigned long *)outdev)[i]
169 ^ ((const unsigned long *)ip6info->outiface)[i])
170 & ((const unsigned long *)ip6info->outiface_mask)[i];
171 }
172
173 if (FWINV(ret != 0, IP6T_INV_VIA_OUT)) {
174 dprintf("VIA out mismatch (%s vs %s).%s\n",
175 outdev, ip6info->outiface,
176 ip6info->invflags&IP6T_INV_VIA_OUT ?" (INV)":"");
177 return 0;
178 }
179
180/* ... might want to do something with class and flowlabel here ... */
181
182 /* look for the desired protocol header */
183 if((ip6info->flags & IP6T_F_PROTO)) {
Patrick McHardyb777e0c2006-01-05 12:21:16 -0800184 int protohdr;
185 unsigned short _frag_off;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186
Patrick McHardyb777e0c2006-01-05 12:21:16 -0800187 protohdr = ipv6_find_hdr(skb, protoff, -1, &_frag_off);
188 if (protohdr < 0)
189 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
Patrick McHardyb777e0c2006-01-05 12:21:16 -0800191 *fragoff = _frag_off;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
193 dprintf("Packet protocol %hi ?= %s%hi.\n",
Patrick McHardyb777e0c2006-01-05 12:21:16 -0800194 protohdr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 ip6info->invflags & IP6T_INV_PROTO ? "!":"",
196 ip6info->proto);
197
Patrick McHardyb777e0c2006-01-05 12:21:16 -0800198 if (ip6info->proto == protohdr) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 if(ip6info->invflags & IP6T_INV_PROTO) {
200 return 0;
201 }
202 return 1;
203 }
204
205 /* We need match for the '-p all', too! */
206 if ((ip6info->proto != 0) &&
207 !(ip6info->invflags & IP6T_INV_PROTO))
208 return 0;
209 }
210 return 1;
211}
212
213/* should be ip6 safe */
214static inline int
215ip6_checkentry(const struct ip6t_ip6 *ipv6)
216{
217 if (ipv6->flags & ~IP6T_F_MASK) {
218 duprintf("Unknown flag bits set: %08X\n",
219 ipv6->flags & ~IP6T_F_MASK);
220 return 0;
221 }
222 if (ipv6->invflags & ~IP6T_INV_MASK) {
223 duprintf("Unknown invflag bits set: %08X\n",
224 ipv6->invflags & ~IP6T_INV_MASK);
225 return 0;
226 }
227 return 1;
228}
229
230static unsigned int
231ip6t_error(struct sk_buff **pskb,
232 const struct net_device *in,
233 const struct net_device *out,
234 unsigned int hooknum,
Patrick McHardyc4986732006-03-20 18:02:56 -0800235 const struct xt_target *target,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 const void *targinfo,
237 void *userinfo)
238{
239 if (net_ratelimit())
240 printk("ip6_tables: error: `%s'\n", (char *)targinfo);
241
242 return NF_DROP;
243}
244
245static inline
246int do_match(struct ip6t_entry_match *m,
247 const struct sk_buff *skb,
248 const struct net_device *in,
249 const struct net_device *out,
250 int offset,
251 unsigned int protoff,
252 int *hotdrop)
253{
254 /* Stop iteration if it doesn't match */
Patrick McHardy1c524832006-03-20 18:02:15 -0800255 if (!m->u.kernel.match->match(skb, in, out, m->u.kernel.match, m->data,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 offset, protoff, hotdrop))
257 return 1;
258 else
259 return 0;
260}
261
262static inline struct ip6t_entry *
263get_entry(void *base, unsigned int offset)
264{
265 return (struct ip6t_entry *)(base + offset);
266}
267
268/* Returns one of the generic firewall policies, like NF_ACCEPT. */
269unsigned int
270ip6t_do_table(struct sk_buff **pskb,
271 unsigned int hook,
272 const struct net_device *in,
273 const struct net_device *out,
Harald Welte2e4e6a12006-01-12 13:30:04 -0800274 struct xt_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 void *userdata)
276{
Harald Welte6b7d31f2005-10-26 09:34:24 +0200277 static const char nulldevname[IFNAMSIZ] __attribute__((aligned(sizeof(long))));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 int offset = 0;
279 unsigned int protoff = 0;
280 int hotdrop = 0;
281 /* Initializing verdict to NF_DROP keeps gcc happy. */
282 unsigned int verdict = NF_DROP;
283 const char *indev, *outdev;
284 void *table_base;
285 struct ip6t_entry *e, *back;
Harald Welte2e4e6a12006-01-12 13:30:04 -0800286 struct xt_table_info *private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
288 /* Initialization */
289 indev = in ? in->name : nulldevname;
290 outdev = out ? out->name : nulldevname;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 /* We handle fragments by dealing with the first fragment as
292 * if it was a normal packet. All other fragments are treated
293 * normally, except that they will NEVER match rules that ask
294 * things we don't know, ie. tcp syn flag or ports). If the
295 * rule is also a fragment-specific rule, non-fragments won't
296 * match it. */
297
298 read_lock_bh(&table->lock);
Harald Welte2e4e6a12006-01-12 13:30:04 -0800299 private = table->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 IP_NF_ASSERT(table->valid_hooks & (1 << hook));
Harald Welte2e4e6a12006-01-12 13:30:04 -0800301 table_base = (void *)private->entries[smp_processor_id()];
302 e = get_entry(table_base, private->hook_entry[hook]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
304#ifdef CONFIG_NETFILTER_DEBUG
305 /* Check noone else using our table */
306 if (((struct ip6t_entry *)table_base)->comefrom != 0xdead57ac
307 && ((struct ip6t_entry *)table_base)->comefrom != 0xeeeeeeec) {
308 printk("ASSERT: CPU #%u, %s comefrom(%p) = %X\n",
309 smp_processor_id(),
310 table->name,
311 &((struct ip6t_entry *)table_base)->comefrom,
312 ((struct ip6t_entry *)table_base)->comefrom);
313 }
314 ((struct ip6t_entry *)table_base)->comefrom = 0x57acc001;
315#endif
316
317 /* For return from builtin chain */
Harald Welte2e4e6a12006-01-12 13:30:04 -0800318 back = get_entry(table_base, private->underflow[hook]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319
320 do {
321 IP_NF_ASSERT(e);
322 IP_NF_ASSERT(back);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 if (ip6_packet_match(*pskb, indev, outdev, &e->ipv6,
324 &protoff, &offset)) {
325 struct ip6t_entry_target *t;
326
327 if (IP6T_MATCH_ITERATE(e, do_match,
328 *pskb, in, out,
329 offset, protoff, &hotdrop) != 0)
330 goto no_match;
331
332 ADD_COUNTER(e->counters,
333 ntohs((*pskb)->nh.ipv6h->payload_len)
334 + IPV6_HDR_LEN,
335 1);
336
337 t = ip6t_get_target(e);
338 IP_NF_ASSERT(t->u.kernel.target);
339 /* Standard target? */
340 if (!t->u.kernel.target->target) {
341 int v;
342
343 v = ((struct ip6t_standard_target *)t)->verdict;
344 if (v < 0) {
345 /* Pop from stack? */
346 if (v != IP6T_RETURN) {
347 verdict = (unsigned)(-v) - 1;
348 break;
349 }
350 e = back;
351 back = get_entry(table_base,
352 back->comefrom);
353 continue;
354 }
Patrick McHardy05465342005-08-21 23:31:43 -0700355 if (table_base + v != (void *)e + e->next_offset
356 && !(e->ipv6.flags & IP6T_F_GOTO)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 /* Save old back ptr in next entry */
358 struct ip6t_entry *next
359 = (void *)e + e->next_offset;
360 next->comefrom
361 = (void *)back - table_base;
362 /* set back pointer to next entry */
363 back = next;
364 }
365
366 e = get_entry(table_base, v);
367 } else {
368 /* Targets which reenter must return
369 abs. verdicts */
370#ifdef CONFIG_NETFILTER_DEBUG
371 ((struct ip6t_entry *)table_base)->comefrom
372 = 0xeeeeeeec;
373#endif
374 verdict = t->u.kernel.target->target(pskb,
375 in, out,
376 hook,
Patrick McHardy1c524832006-03-20 18:02:15 -0800377 t->u.kernel.target,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 t->data,
379 userdata);
380
381#ifdef CONFIG_NETFILTER_DEBUG
382 if (((struct ip6t_entry *)table_base)->comefrom
383 != 0xeeeeeeec
384 && verdict == IP6T_CONTINUE) {
385 printk("Target %s reentered!\n",
386 t->u.kernel.target->name);
387 verdict = NF_DROP;
388 }
389 ((struct ip6t_entry *)table_base)->comefrom
390 = 0x57acc001;
391#endif
392 if (verdict == IP6T_CONTINUE)
393 e = (void *)e + e->next_offset;
394 else
395 /* Verdict */
396 break;
397 }
398 } else {
399
400 no_match:
401 e = (void *)e + e->next_offset;
402 }
403 } while (!hotdrop);
404
405#ifdef CONFIG_NETFILTER_DEBUG
406 ((struct ip6t_entry *)table_base)->comefrom = 0xdead57ac;
407#endif
408 read_unlock_bh(&table->lock);
409
410#ifdef DEBUG_ALLOW_ALL
411 return NF_ACCEPT;
412#else
413 if (hotdrop)
414 return NF_DROP;
415 else return verdict;
416#endif
417}
418
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419/* All zeroes == unconditional rule. */
420static inline int
421unconditional(const struct ip6t_ip6 *ipv6)
422{
423 unsigned int i;
424
425 for (i = 0; i < sizeof(*ipv6); i++)
426 if (((char *)ipv6)[i])
427 break;
428
429 return (i == sizeof(*ipv6));
430}
431
432/* Figures out from what hook each rule can be called: returns 0 if
433 there are loops. Puts hook bitmask in comefrom. */
434static int
Harald Welte2e4e6a12006-01-12 13:30:04 -0800435mark_source_chains(struct xt_table_info *newinfo,
Eric Dumazet31836062005-12-13 23:13:48 -0800436 unsigned int valid_hooks, void *entry0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437{
438 unsigned int hook;
439
440 /* No recursion; use packet counter to save back ptrs (reset
441 to 0 as we leave), and comefrom to save source hook bitmask */
442 for (hook = 0; hook < NF_IP6_NUMHOOKS; hook++) {
443 unsigned int pos = newinfo->hook_entry[hook];
444 struct ip6t_entry *e
Eric Dumazet31836062005-12-13 23:13:48 -0800445 = (struct ip6t_entry *)(entry0 + pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
447 if (!(valid_hooks & (1 << hook)))
448 continue;
449
450 /* Set initial back pointer. */
451 e->counters.pcnt = pos;
452
453 for (;;) {
454 struct ip6t_standard_target *t
455 = (void *)ip6t_get_target(e);
456
457 if (e->comefrom & (1 << NF_IP6_NUMHOOKS)) {
458 printk("iptables: loop hook %u pos %u %08X.\n",
459 hook, pos, e->comefrom);
460 return 0;
461 }
462 e->comefrom
463 |= ((1 << hook) | (1 << NF_IP6_NUMHOOKS));
464
465 /* Unconditional return/END. */
466 if (e->target_offset == sizeof(struct ip6t_entry)
467 && (strcmp(t->target.u.user.name,
468 IP6T_STANDARD_TARGET) == 0)
469 && t->verdict < 0
470 && unconditional(&e->ipv6)) {
471 unsigned int oldpos, size;
472
473 /* Return: backtrack through the last
474 big jump. */
475 do {
476 e->comefrom ^= (1<<NF_IP6_NUMHOOKS);
477#ifdef DEBUG_IP_FIREWALL_USER
478 if (e->comefrom
479 & (1 << NF_IP6_NUMHOOKS)) {
480 duprintf("Back unset "
481 "on hook %u "
482 "rule %u\n",
483 hook, pos);
484 }
485#endif
486 oldpos = pos;
487 pos = e->counters.pcnt;
488 e->counters.pcnt = 0;
489
490 /* We're at the start. */
491 if (pos == oldpos)
492 goto next;
493
494 e = (struct ip6t_entry *)
Eric Dumazet31836062005-12-13 23:13:48 -0800495 (entry0 + pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 } while (oldpos == pos + e->next_offset);
497
498 /* Move along one */
499 size = e->next_offset;
500 e = (struct ip6t_entry *)
Eric Dumazet31836062005-12-13 23:13:48 -0800501 (entry0 + pos + size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 e->counters.pcnt = pos;
503 pos += size;
504 } else {
505 int newpos = t->verdict;
506
507 if (strcmp(t->target.u.user.name,
508 IP6T_STANDARD_TARGET) == 0
509 && newpos >= 0) {
510 /* This a jump; chase it. */
511 duprintf("Jump rule %u -> %u\n",
512 pos, newpos);
513 } else {
514 /* ... this is a fallthru */
515 newpos = pos + e->next_offset;
516 }
517 e = (struct ip6t_entry *)
Eric Dumazet31836062005-12-13 23:13:48 -0800518 (entry0 + newpos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 e->counters.pcnt = pos;
520 pos = newpos;
521 }
522 }
523 next:
524 duprintf("Finished chain %u\n", hook);
525 }
526 return 1;
527}
528
529static inline int
530cleanup_match(struct ip6t_entry_match *m, unsigned int *i)
531{
532 if (i && (*i)-- == 0)
533 return 1;
534
535 if (m->u.kernel.match->destroy)
Patrick McHardy1c524832006-03-20 18:02:15 -0800536 m->u.kernel.match->destroy(m->u.kernel.match, m->data,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 m->u.match_size - sizeof(*m));
538 module_put(m->u.kernel.match->me);
539 return 0;
540}
541
542static inline int
543standard_check(const struct ip6t_entry_target *t,
544 unsigned int max_offset)
545{
546 struct ip6t_standard_target *targ = (void *)t;
547
548 /* Check standard info. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 if (targ->verdict >= 0
550 && targ->verdict > max_offset - sizeof(struct ip6t_entry)) {
551 duprintf("ip6t_standard_check: bad verdict (%i)\n",
552 targ->verdict);
553 return 0;
554 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 if (targ->verdict < -NF_MAX_VERDICT - 1) {
556 duprintf("ip6t_standard_check: bad negative verdict (%i)\n",
557 targ->verdict);
558 return 0;
559 }
560 return 1;
561}
562
563static inline int
564check_match(struct ip6t_entry_match *m,
565 const char *name,
566 const struct ip6t_ip6 *ipv6,
567 unsigned int hookmask,
568 unsigned int *i)
569{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 struct ip6t_match *match;
Patrick McHardy3cdc7c92006-03-20 18:00:36 -0800571 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572
Harald Welte2e4e6a12006-01-12 13:30:04 -0800573 match = try_then_request_module(xt_find_match(AF_INET6, m->u.user.name,
574 m->u.user.revision),
Harald Welte6b7d31f2005-10-26 09:34:24 +0200575 "ip6t_%s", m->u.user.name);
576 if (IS_ERR(match) || !match) {
Harald Welte2e4e6a12006-01-12 13:30:04 -0800577 duprintf("check_match: `%s' not found\n", m->u.user.name);
Harald Welte6b7d31f2005-10-26 09:34:24 +0200578 return match ? PTR_ERR(match) : -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 }
580 m->u.kernel.match = match;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581
Patrick McHardy3cdc7c92006-03-20 18:00:36 -0800582 ret = xt_check_match(match, AF_INET6, m->u.match_size - sizeof(*m),
583 name, hookmask, ipv6->proto,
584 ipv6->invflags & IP6T_INV_PROTO);
585 if (ret)
586 goto err;
587
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 if (m->u.kernel.match->checkentry
Patrick McHardy1c524832006-03-20 18:02:15 -0800589 && !m->u.kernel.match->checkentry(name, ipv6, match, m->data,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 m->u.match_size - sizeof(*m),
591 hookmask)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 duprintf("ip_tables: check failed for `%s'.\n",
593 m->u.kernel.match->name);
Patrick McHardy3cdc7c92006-03-20 18:00:36 -0800594 ret = -EINVAL;
595 goto err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 }
597
598 (*i)++;
599 return 0;
Patrick McHardy3cdc7c92006-03-20 18:00:36 -0800600err:
601 module_put(m->u.kernel.match->me);
602 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603}
604
605static struct ip6t_target ip6t_standard_target;
606
607static inline int
608check_entry(struct ip6t_entry *e, const char *name, unsigned int size,
609 unsigned int *i)
610{
611 struct ip6t_entry_target *t;
612 struct ip6t_target *target;
613 int ret;
614 unsigned int j;
615
616 if (!ip6_checkentry(&e->ipv6)) {
617 duprintf("ip_tables: ip check failed %p %s.\n", e, name);
618 return -EINVAL;
619 }
620
621 j = 0;
622 ret = IP6T_MATCH_ITERATE(e, check_match, name, &e->ipv6, e->comefrom, &j);
623 if (ret != 0)
624 goto cleanup_matches;
625
626 t = ip6t_get_target(e);
Harald Welte2e4e6a12006-01-12 13:30:04 -0800627 target = try_then_request_module(xt_find_target(AF_INET6,
628 t->u.user.name,
629 t->u.user.revision),
Harald Welte6b7d31f2005-10-26 09:34:24 +0200630 "ip6t_%s", t->u.user.name);
631 if (IS_ERR(target) || !target) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 duprintf("check_entry: `%s' not found\n", t->u.user.name);
Harald Welte6b7d31f2005-10-26 09:34:24 +0200633 ret = target ? PTR_ERR(target) : -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 goto cleanup_matches;
635 }
636 t->u.kernel.target = target;
Harald Welte6b7d31f2005-10-26 09:34:24 +0200637
Patrick McHardy3cdc7c92006-03-20 18:00:36 -0800638 ret = xt_check_target(target, AF_INET6, t->u.target_size - sizeof(*t),
639 name, e->comefrom, e->ipv6.proto,
640 e->ipv6.invflags & IP6T_INV_PROTO);
641 if (ret)
642 goto err;
643
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 if (t->u.kernel.target == &ip6t_standard_target) {
645 if (!standard_check(t, size)) {
646 ret = -EINVAL;
647 goto cleanup_matches;
648 }
649 } else if (t->u.kernel.target->checkentry
Patrick McHardy1c524832006-03-20 18:02:15 -0800650 && !t->u.kernel.target->checkentry(name, e, target, t->data,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 t->u.target_size
652 - sizeof(*t),
653 e->comefrom)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 duprintf("ip_tables: check failed for `%s'.\n",
655 t->u.kernel.target->name);
656 ret = -EINVAL;
Patrick McHardy3cdc7c92006-03-20 18:00:36 -0800657 goto err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 }
659
660 (*i)++;
661 return 0;
Patrick McHardy3cdc7c92006-03-20 18:00:36 -0800662 err:
663 module_put(t->u.kernel.target->me);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 cleanup_matches:
665 IP6T_MATCH_ITERATE(e, cleanup_match, &j);
666 return ret;
667}
668
669static inline int
670check_entry_size_and_hooks(struct ip6t_entry *e,
Harald Welte2e4e6a12006-01-12 13:30:04 -0800671 struct xt_table_info *newinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 unsigned char *base,
673 unsigned char *limit,
674 const unsigned int *hook_entries,
675 const unsigned int *underflows,
676 unsigned int *i)
677{
678 unsigned int h;
679
680 if ((unsigned long)e % __alignof__(struct ip6t_entry) != 0
681 || (unsigned char *)e + sizeof(struct ip6t_entry) >= limit) {
682 duprintf("Bad offset %p\n", e);
683 return -EINVAL;
684 }
685
686 if (e->next_offset
687 < sizeof(struct ip6t_entry) + sizeof(struct ip6t_entry_target)) {
688 duprintf("checking: element %p size %u\n",
689 e, e->next_offset);
690 return -EINVAL;
691 }
692
693 /* Check hooks & underflows */
694 for (h = 0; h < NF_IP6_NUMHOOKS; h++) {
695 if ((unsigned char *)e - base == hook_entries[h])
696 newinfo->hook_entry[h] = hook_entries[h];
697 if ((unsigned char *)e - base == underflows[h])
698 newinfo->underflow[h] = underflows[h];
699 }
700
701 /* FIXME: underflows must be unconditional, standard verdicts
702 < 0 (not IP6T_RETURN). --RR */
703
704 /* Clear counters and comefrom */
Harald Welte2e4e6a12006-01-12 13:30:04 -0800705 e->counters = ((struct xt_counters) { 0, 0 });
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 e->comefrom = 0;
707
708 (*i)++;
709 return 0;
710}
711
712static inline int
713cleanup_entry(struct ip6t_entry *e, unsigned int *i)
714{
715 struct ip6t_entry_target *t;
716
717 if (i && (*i)-- == 0)
718 return 1;
719
720 /* Cleanup all matches */
721 IP6T_MATCH_ITERATE(e, cleanup_match, NULL);
722 t = ip6t_get_target(e);
723 if (t->u.kernel.target->destroy)
Patrick McHardy1c524832006-03-20 18:02:15 -0800724 t->u.kernel.target->destroy(t->u.kernel.target, t->data,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 t->u.target_size - sizeof(*t));
726 module_put(t->u.kernel.target->me);
727 return 0;
728}
729
730/* Checks and translates the user-supplied table segment (held in
731 newinfo) */
732static int
733translate_table(const char *name,
734 unsigned int valid_hooks,
Harald Welte2e4e6a12006-01-12 13:30:04 -0800735 struct xt_table_info *newinfo,
Eric Dumazet31836062005-12-13 23:13:48 -0800736 void *entry0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 unsigned int size,
738 unsigned int number,
739 const unsigned int *hook_entries,
740 const unsigned int *underflows)
741{
742 unsigned int i;
743 int ret;
744
745 newinfo->size = size;
746 newinfo->number = number;
747
748 /* Init all hooks to impossible value. */
749 for (i = 0; i < NF_IP6_NUMHOOKS; i++) {
750 newinfo->hook_entry[i] = 0xFFFFFFFF;
751 newinfo->underflow[i] = 0xFFFFFFFF;
752 }
753
754 duprintf("translate_table: size %u\n", newinfo->size);
755 i = 0;
756 /* Walk through entries, checking offsets. */
Eric Dumazet31836062005-12-13 23:13:48 -0800757 ret = IP6T_ENTRY_ITERATE(entry0, newinfo->size,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 check_entry_size_and_hooks,
759 newinfo,
Eric Dumazet31836062005-12-13 23:13:48 -0800760 entry0,
761 entry0 + size,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 hook_entries, underflows, &i);
763 if (ret != 0)
764 return ret;
765
766 if (i != number) {
767 duprintf("translate_table: %u not %u entries\n",
768 i, number);
769 return -EINVAL;
770 }
771
772 /* Check hooks all assigned */
773 for (i = 0; i < NF_IP6_NUMHOOKS; i++) {
774 /* Only hooks which are valid */
775 if (!(valid_hooks & (1 << i)))
776 continue;
777 if (newinfo->hook_entry[i] == 0xFFFFFFFF) {
778 duprintf("Invalid hook entry %u %u\n",
779 i, hook_entries[i]);
780 return -EINVAL;
781 }
782 if (newinfo->underflow[i] == 0xFFFFFFFF) {
783 duprintf("Invalid underflow %u %u\n",
784 i, underflows[i]);
785 return -EINVAL;
786 }
787 }
788
Eric Dumazet31836062005-12-13 23:13:48 -0800789 if (!mark_source_chains(newinfo, valid_hooks, entry0))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 return -ELOOP;
791
792 /* Finally, each sanity check must pass */
793 i = 0;
Eric Dumazet31836062005-12-13 23:13:48 -0800794 ret = IP6T_ENTRY_ITERATE(entry0, newinfo->size,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 check_entry, name, size, &i);
796
797 if (ret != 0) {
Eric Dumazet31836062005-12-13 23:13:48 -0800798 IP6T_ENTRY_ITERATE(entry0, newinfo->size,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 cleanup_entry, &i);
800 return ret;
801 }
802
803 /* And one copy for every other CPU */
David S. Millerc8923c62005-10-13 14:41:23 -0700804 for_each_cpu(i) {
Eric Dumazet31836062005-12-13 23:13:48 -0800805 if (newinfo->entries[i] && newinfo->entries[i] != entry0)
806 memcpy(newinfo->entries[i], entry0, newinfo->size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 }
808
809 return ret;
810}
811
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812/* Gets counters. */
813static inline int
814add_entry_to_counter(const struct ip6t_entry *e,
Harald Welte2e4e6a12006-01-12 13:30:04 -0800815 struct xt_counters total[],
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 unsigned int *i)
817{
818 ADD_COUNTER(total[*i], e->counters.bcnt, e->counters.pcnt);
819
820 (*i)++;
821 return 0;
822}
823
Eric Dumazet31836062005-12-13 23:13:48 -0800824static inline int
825set_entry_to_counter(const struct ip6t_entry *e,
826 struct ip6t_counters total[],
827 unsigned int *i)
828{
829 SET_COUNTER(total[*i], e->counters.bcnt, e->counters.pcnt);
830
831 (*i)++;
832 return 0;
833}
834
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835static void
Harald Welte2e4e6a12006-01-12 13:30:04 -0800836get_counters(const struct xt_table_info *t,
837 struct xt_counters counters[])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838{
839 unsigned int cpu;
840 unsigned int i;
Eric Dumazet31836062005-12-13 23:13:48 -0800841 unsigned int curcpu;
842
843 /* Instead of clearing (by a previous call to memset())
844 * the counters and using adds, we set the counters
845 * with data used by 'current' CPU
846 * We dont care about preemption here.
847 */
848 curcpu = raw_smp_processor_id();
849
850 i = 0;
851 IP6T_ENTRY_ITERATE(t->entries[curcpu],
852 t->size,
853 set_entry_to_counter,
854 counters,
855 &i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856
David S. Millerc8923c62005-10-13 14:41:23 -0700857 for_each_cpu(cpu) {
Eric Dumazet31836062005-12-13 23:13:48 -0800858 if (cpu == curcpu)
859 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 i = 0;
Eric Dumazet31836062005-12-13 23:13:48 -0800861 IP6T_ENTRY_ITERATE(t->entries[cpu],
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 t->size,
863 add_entry_to_counter,
864 counters,
865 &i);
866 }
867}
868
869static int
870copy_entries_to_user(unsigned int total_size,
Harald Welte2e4e6a12006-01-12 13:30:04 -0800871 struct xt_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 void __user *userptr)
873{
874 unsigned int off, num, countersize;
875 struct ip6t_entry *e;
Harald Welte2e4e6a12006-01-12 13:30:04 -0800876 struct xt_counters *counters;
877 struct xt_table_info *private = table->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 int ret = 0;
Eric Dumazet31836062005-12-13 23:13:48 -0800879 void *loc_cpu_entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880
881 /* We need atomic snapshot of counters: rest doesn't change
882 (other than comefrom, which userspace doesn't care
883 about). */
Harald Welte2e4e6a12006-01-12 13:30:04 -0800884 countersize = sizeof(struct xt_counters) * private->number;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 counters = vmalloc(countersize);
886
887 if (counters == NULL)
888 return -ENOMEM;
889
890 /* First, sum counters... */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 write_lock_bh(&table->lock);
Harald Welte2e4e6a12006-01-12 13:30:04 -0800892 get_counters(private, counters);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 write_unlock_bh(&table->lock);
894
Eric Dumazet31836062005-12-13 23:13:48 -0800895 /* choose the copy that is on ourc node/cpu */
Harald Welte2e4e6a12006-01-12 13:30:04 -0800896 loc_cpu_entry = private->entries[raw_smp_processor_id()];
Eric Dumazet31836062005-12-13 23:13:48 -0800897 if (copy_to_user(userptr, loc_cpu_entry, total_size) != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 ret = -EFAULT;
899 goto free_counters;
900 }
901
902 /* FIXME: use iterator macros --RR */
903 /* ... then go back and fix counters and names */
904 for (off = 0, num = 0; off < total_size; off += e->next_offset, num++){
905 unsigned int i;
906 struct ip6t_entry_match *m;
907 struct ip6t_entry_target *t;
908
Eric Dumazet31836062005-12-13 23:13:48 -0800909 e = (struct ip6t_entry *)(loc_cpu_entry + off);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 if (copy_to_user(userptr + off
911 + offsetof(struct ip6t_entry, counters),
912 &counters[num],
913 sizeof(counters[num])) != 0) {
914 ret = -EFAULT;
915 goto free_counters;
916 }
917
918 for (i = sizeof(struct ip6t_entry);
919 i < e->target_offset;
920 i += m->u.match_size) {
921 m = (void *)e + i;
922
923 if (copy_to_user(userptr + off + i
924 + offsetof(struct ip6t_entry_match,
925 u.user.name),
926 m->u.kernel.match->name,
927 strlen(m->u.kernel.match->name)+1)
928 != 0) {
929 ret = -EFAULT;
930 goto free_counters;
931 }
932 }
933
934 t = ip6t_get_target(e);
935 if (copy_to_user(userptr + off + e->target_offset
936 + offsetof(struct ip6t_entry_target,
937 u.user.name),
938 t->u.kernel.target->name,
939 strlen(t->u.kernel.target->name)+1) != 0) {
940 ret = -EFAULT;
941 goto free_counters;
942 }
943 }
944
945 free_counters:
946 vfree(counters);
947 return ret;
948}
949
950static int
951get_entries(const struct ip6t_get_entries *entries,
952 struct ip6t_get_entries __user *uptr)
953{
954 int ret;
Harald Welte2e4e6a12006-01-12 13:30:04 -0800955 struct xt_table *t;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956
Harald Welte2e4e6a12006-01-12 13:30:04 -0800957 t = xt_find_table_lock(AF_INET6, entries->name);
Harald Welte6b7d31f2005-10-26 09:34:24 +0200958 if (t && !IS_ERR(t)) {
Harald Welte2e4e6a12006-01-12 13:30:04 -0800959 struct xt_table_info *private = t->private;
960 duprintf("t->private->number = %u\n", private->number);
961 if (entries->size == private->size)
962 ret = copy_entries_to_user(private->size,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 t, uptr->entrytable);
964 else {
965 duprintf("get_entries: I've got %u not %u!\n",
Harald Welte2e4e6a12006-01-12 13:30:04 -0800966 private->size, entries->size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 ret = -EINVAL;
968 }
Harald Welte6b7d31f2005-10-26 09:34:24 +0200969 module_put(t->me);
Harald Welte2e4e6a12006-01-12 13:30:04 -0800970 xt_table_unlock(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 } else
Harald Welte6b7d31f2005-10-26 09:34:24 +0200972 ret = t ? PTR_ERR(t) : -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973
974 return ret;
975}
976
977static int
978do_replace(void __user *user, unsigned int len)
979{
980 int ret;
981 struct ip6t_replace tmp;
Harald Welte2e4e6a12006-01-12 13:30:04 -0800982 struct xt_table *t;
983 struct xt_table_info *newinfo, *oldinfo;
984 struct xt_counters *counters;
Eric Dumazet31836062005-12-13 23:13:48 -0800985 void *loc_cpu_entry, *loc_cpu_old_entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986
987 if (copy_from_user(&tmp, user, sizeof(tmp)) != 0)
988 return -EFAULT;
989
Kirill Korotaevee4bb812006-02-04 02:16:56 -0800990 /* overflow check */
991 if (tmp.size >= (INT_MAX - sizeof(struct xt_table_info)) / NR_CPUS -
992 SMP_CACHE_BYTES)
993 return -ENOMEM;
994 if (tmp.num_counters >= INT_MAX / sizeof(struct xt_counters))
995 return -ENOMEM;
996
Harald Welte2e4e6a12006-01-12 13:30:04 -0800997 newinfo = xt_alloc_table_info(tmp.size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 if (!newinfo)
999 return -ENOMEM;
1000
Eric Dumazet31836062005-12-13 23:13:48 -08001001 /* choose the copy that is on our node/cpu */
1002 loc_cpu_entry = newinfo->entries[raw_smp_processor_id()];
1003 if (copy_from_user(loc_cpu_entry, user + sizeof(tmp),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 tmp.size) != 0) {
1005 ret = -EFAULT;
1006 goto free_newinfo;
1007 }
1008
Harald Welte2e4e6a12006-01-12 13:30:04 -08001009 counters = vmalloc(tmp.num_counters * sizeof(struct xt_counters));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 if (!counters) {
1011 ret = -ENOMEM;
1012 goto free_newinfo;
1013 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014
1015 ret = translate_table(tmp.name, tmp.valid_hooks,
Eric Dumazet31836062005-12-13 23:13:48 -08001016 newinfo, loc_cpu_entry, tmp.size, tmp.num_entries,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 tmp.hook_entry, tmp.underflow);
1018 if (ret != 0)
1019 goto free_newinfo_counters;
1020
1021 duprintf("ip_tables: Translated table\n");
1022
Harald Welte2e4e6a12006-01-12 13:30:04 -08001023 t = try_then_request_module(xt_find_table_lock(AF_INET6, tmp.name),
Harald Welte6b7d31f2005-10-26 09:34:24 +02001024 "ip6table_%s", tmp.name);
1025 if (!t || IS_ERR(t)) {
1026 ret = t ? PTR_ERR(t) : -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 goto free_newinfo_counters_untrans;
Harald Welte6b7d31f2005-10-26 09:34:24 +02001028 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029
1030 /* You lied! */
1031 if (tmp.valid_hooks != t->valid_hooks) {
1032 duprintf("Valid hook crap: %08X vs %08X\n",
1033 tmp.valid_hooks, t->valid_hooks);
1034 ret = -EINVAL;
Harald Welte6b7d31f2005-10-26 09:34:24 +02001035 goto put_module;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 }
1037
Harald Welte2e4e6a12006-01-12 13:30:04 -08001038 oldinfo = xt_replace_table(t, tmp.num_counters, newinfo, &ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 if (!oldinfo)
1040 goto put_module;
1041
1042 /* Update module usage count based on number of rules */
1043 duprintf("do_replace: oldnum=%u, initnum=%u, newnum=%u\n",
1044 oldinfo->number, oldinfo->initial_entries, newinfo->number);
1045 if ((oldinfo->number > oldinfo->initial_entries) ||
1046 (newinfo->number <= oldinfo->initial_entries))
1047 module_put(t->me);
1048 if ((oldinfo->number > oldinfo->initial_entries) &&
1049 (newinfo->number <= oldinfo->initial_entries))
1050 module_put(t->me);
1051
1052 /* Get the old counters. */
1053 get_counters(oldinfo, counters);
1054 /* Decrease module usage counts and free resource */
Eric Dumazet31836062005-12-13 23:13:48 -08001055 loc_cpu_old_entry = oldinfo->entries[raw_smp_processor_id()];
1056 IP6T_ENTRY_ITERATE(loc_cpu_old_entry, oldinfo->size, cleanup_entry,NULL);
Harald Welte2e4e6a12006-01-12 13:30:04 -08001057 xt_free_table_info(oldinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 if (copy_to_user(tmp.counters, counters,
Harald Welte2e4e6a12006-01-12 13:30:04 -08001059 sizeof(struct xt_counters) * tmp.num_counters) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 ret = -EFAULT;
1061 vfree(counters);
Harald Welte2e4e6a12006-01-12 13:30:04 -08001062 xt_table_unlock(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 return ret;
1064
1065 put_module:
1066 module_put(t->me);
Harald Welte2e4e6a12006-01-12 13:30:04 -08001067 xt_table_unlock(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 free_newinfo_counters_untrans:
Eric Dumazet31836062005-12-13 23:13:48 -08001069 IP6T_ENTRY_ITERATE(loc_cpu_entry, newinfo->size, cleanup_entry,NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 free_newinfo_counters:
1071 vfree(counters);
1072 free_newinfo:
Harald Welte2e4e6a12006-01-12 13:30:04 -08001073 xt_free_table_info(newinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 return ret;
1075}
1076
1077/* We're lazy, and add to the first CPU; overflow works its fey magic
1078 * and everything is OK. */
1079static inline int
1080add_counter_to_entry(struct ip6t_entry *e,
Harald Welte2e4e6a12006-01-12 13:30:04 -08001081 const struct xt_counters addme[],
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 unsigned int *i)
1083{
1084#if 0
1085 duprintf("add_counter: Entry %u %lu/%lu + %lu/%lu\n",
1086 *i,
1087 (long unsigned int)e->counters.pcnt,
1088 (long unsigned int)e->counters.bcnt,
1089 (long unsigned int)addme[*i].pcnt,
1090 (long unsigned int)addme[*i].bcnt);
1091#endif
1092
1093 ADD_COUNTER(e->counters, addme[*i].bcnt, addme[*i].pcnt);
1094
1095 (*i)++;
1096 return 0;
1097}
1098
1099static int
1100do_add_counters(void __user *user, unsigned int len)
1101{
1102 unsigned int i;
Harald Welte2e4e6a12006-01-12 13:30:04 -08001103 struct xt_counters_info tmp, *paddc;
1104 struct xt_table_info *private;
1105 struct xt_table *t;
Harald Welte6b7d31f2005-10-26 09:34:24 +02001106 int ret = 0;
Eric Dumazet31836062005-12-13 23:13:48 -08001107 void *loc_cpu_entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108
1109 if (copy_from_user(&tmp, user, sizeof(tmp)) != 0)
1110 return -EFAULT;
1111
Harald Welte2e4e6a12006-01-12 13:30:04 -08001112 if (len != sizeof(tmp) + tmp.num_counters*sizeof(struct xt_counters))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113 return -EINVAL;
1114
1115 paddc = vmalloc(len);
1116 if (!paddc)
1117 return -ENOMEM;
1118
1119 if (copy_from_user(paddc, user, len) != 0) {
1120 ret = -EFAULT;
1121 goto free;
1122 }
1123
Harald Welte2e4e6a12006-01-12 13:30:04 -08001124 t = xt_find_table_lock(AF_INET6, tmp.name);
Harald Welte6b7d31f2005-10-26 09:34:24 +02001125 if (!t || IS_ERR(t)) {
1126 ret = t ? PTR_ERR(t) : -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 goto free;
Harald Welte6b7d31f2005-10-26 09:34:24 +02001128 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129
1130 write_lock_bh(&t->lock);
Harald Welte2e4e6a12006-01-12 13:30:04 -08001131 private = t->private;
1132 if (private->number != paddc->num_counters) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 ret = -EINVAL;
1134 goto unlock_up_free;
1135 }
1136
1137 i = 0;
Eric Dumazet31836062005-12-13 23:13:48 -08001138 /* Choose the copy that is on our node */
Harald Welte2e4e6a12006-01-12 13:30:04 -08001139 loc_cpu_entry = private->entries[smp_processor_id()];
Eric Dumazet31836062005-12-13 23:13:48 -08001140 IP6T_ENTRY_ITERATE(loc_cpu_entry,
Harald Welte2e4e6a12006-01-12 13:30:04 -08001141 private->size,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 add_counter_to_entry,
1143 paddc->counters,
1144 &i);
1145 unlock_up_free:
1146 write_unlock_bh(&t->lock);
Harald Welte2e4e6a12006-01-12 13:30:04 -08001147 xt_table_unlock(t);
Harald Welte6b7d31f2005-10-26 09:34:24 +02001148 module_put(t->me);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 free:
1150 vfree(paddc);
1151
1152 return ret;
1153}
1154
1155static int
1156do_ip6t_set_ctl(struct sock *sk, int cmd, void __user *user, unsigned int len)
1157{
1158 int ret;
1159
1160 if (!capable(CAP_NET_ADMIN))
1161 return -EPERM;
1162
1163 switch (cmd) {
1164 case IP6T_SO_SET_REPLACE:
1165 ret = do_replace(user, len);
1166 break;
1167
1168 case IP6T_SO_SET_ADD_COUNTERS:
1169 ret = do_add_counters(user, len);
1170 break;
1171
1172 default:
1173 duprintf("do_ip6t_set_ctl: unknown request %i\n", cmd);
1174 ret = -EINVAL;
1175 }
1176
1177 return ret;
1178}
1179
1180static int
1181do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
1182{
1183 int ret;
1184
1185 if (!capable(CAP_NET_ADMIN))
1186 return -EPERM;
1187
1188 switch (cmd) {
1189 case IP6T_SO_GET_INFO: {
1190 char name[IP6T_TABLE_MAXNAMELEN];
Harald Welte2e4e6a12006-01-12 13:30:04 -08001191 struct xt_table *t;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192
1193 if (*len != sizeof(struct ip6t_getinfo)) {
1194 duprintf("length %u != %u\n", *len,
1195 sizeof(struct ip6t_getinfo));
1196 ret = -EINVAL;
1197 break;
1198 }
1199
1200 if (copy_from_user(name, user, sizeof(name)) != 0) {
1201 ret = -EFAULT;
1202 break;
1203 }
1204 name[IP6T_TABLE_MAXNAMELEN-1] = '\0';
Harald Welte6b7d31f2005-10-26 09:34:24 +02001205
Harald Welte2e4e6a12006-01-12 13:30:04 -08001206 t = try_then_request_module(xt_find_table_lock(AF_INET6, name),
Harald Welte6b7d31f2005-10-26 09:34:24 +02001207 "ip6table_%s", name);
1208 if (t && !IS_ERR(t)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 struct ip6t_getinfo info;
Harald Welte2e4e6a12006-01-12 13:30:04 -08001210 struct xt_table_info *private = t->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211
1212 info.valid_hooks = t->valid_hooks;
Harald Welte2e4e6a12006-01-12 13:30:04 -08001213 memcpy(info.hook_entry, private->hook_entry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214 sizeof(info.hook_entry));
Harald Welte2e4e6a12006-01-12 13:30:04 -08001215 memcpy(info.underflow, private->underflow,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 sizeof(info.underflow));
Harald Welte2e4e6a12006-01-12 13:30:04 -08001217 info.num_entries = private->number;
1218 info.size = private->size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 memcpy(info.name, name, sizeof(info.name));
1220
1221 if (copy_to_user(user, &info, *len) != 0)
1222 ret = -EFAULT;
1223 else
1224 ret = 0;
Harald Welte2e4e6a12006-01-12 13:30:04 -08001225 xt_table_unlock(t);
Harald Welte6b7d31f2005-10-26 09:34:24 +02001226 module_put(t->me);
1227 } else
1228 ret = t ? PTR_ERR(t) : -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229 }
1230 break;
1231
1232 case IP6T_SO_GET_ENTRIES: {
1233 struct ip6t_get_entries get;
1234
1235 if (*len < sizeof(get)) {
1236 duprintf("get_entries: %u < %u\n", *len, sizeof(get));
1237 ret = -EINVAL;
1238 } else if (copy_from_user(&get, user, sizeof(get)) != 0) {
1239 ret = -EFAULT;
1240 } else if (*len != sizeof(struct ip6t_get_entries) + get.size) {
1241 duprintf("get_entries: %u != %u\n", *len,
1242 sizeof(struct ip6t_get_entries) + get.size);
1243 ret = -EINVAL;
1244 } else
1245 ret = get_entries(&get, user);
1246 break;
1247 }
1248
Harald Welte6b7d31f2005-10-26 09:34:24 +02001249 case IP6T_SO_GET_REVISION_MATCH:
1250 case IP6T_SO_GET_REVISION_TARGET: {
1251 struct ip6t_get_revision rev;
Harald Welte2e4e6a12006-01-12 13:30:04 -08001252 int target;
Harald Welte6b7d31f2005-10-26 09:34:24 +02001253
1254 if (*len != sizeof(rev)) {
1255 ret = -EINVAL;
1256 break;
1257 }
1258 if (copy_from_user(&rev, user, sizeof(rev)) != 0) {
1259 ret = -EFAULT;
1260 break;
1261 }
1262
1263 if (cmd == IP6T_SO_GET_REVISION_TARGET)
Harald Welte2e4e6a12006-01-12 13:30:04 -08001264 target = 1;
Harald Welte6b7d31f2005-10-26 09:34:24 +02001265 else
Harald Welte2e4e6a12006-01-12 13:30:04 -08001266 target = 0;
Harald Welte6b7d31f2005-10-26 09:34:24 +02001267
Harald Welte2e4e6a12006-01-12 13:30:04 -08001268 try_then_request_module(xt_find_revision(AF_INET6, rev.name,
1269 rev.revision,
1270 target, &ret),
Harald Welte6b7d31f2005-10-26 09:34:24 +02001271 "ip6t_%s", rev.name);
1272 break;
1273 }
1274
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 default:
1276 duprintf("do_ip6t_get_ctl: unknown request %i\n", cmd);
1277 ret = -EINVAL;
1278 }
1279
1280 return ret;
1281}
1282
Harald Welte2e4e6a12006-01-12 13:30:04 -08001283int ip6t_register_table(struct xt_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 const struct ip6t_replace *repl)
1285{
1286 int ret;
Harald Welte2e4e6a12006-01-12 13:30:04 -08001287 struct xt_table_info *newinfo;
1288 static struct xt_table_info bootstrap
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289 = { 0, 0, 0, { 0 }, { 0 }, { } };
Eric Dumazet31836062005-12-13 23:13:48 -08001290 void *loc_cpu_entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291
Harald Welte2e4e6a12006-01-12 13:30:04 -08001292 newinfo = xt_alloc_table_info(repl->size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293 if (!newinfo)
1294 return -ENOMEM;
1295
Eric Dumazet31836062005-12-13 23:13:48 -08001296 /* choose the copy on our node/cpu */
1297 loc_cpu_entry = newinfo->entries[raw_smp_processor_id()];
1298 memcpy(loc_cpu_entry, repl->entries, repl->size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299
1300 ret = translate_table(table->name, table->valid_hooks,
Eric Dumazet31836062005-12-13 23:13:48 -08001301 newinfo, loc_cpu_entry, repl->size,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302 repl->num_entries,
1303 repl->hook_entry,
1304 repl->underflow);
1305 if (ret != 0) {
Harald Welte2e4e6a12006-01-12 13:30:04 -08001306 xt_free_table_info(newinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 return ret;
1308 }
1309
Harald Welte2e4e6a12006-01-12 13:30:04 -08001310 if (xt_register_table(table, &bootstrap, newinfo) != 0) {
1311 xt_free_table_info(newinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 return ret;
1313 }
1314
Harald Welte2e4e6a12006-01-12 13:30:04 -08001315 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316}
1317
Harald Welte2e4e6a12006-01-12 13:30:04 -08001318void ip6t_unregister_table(struct xt_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319{
Harald Welte2e4e6a12006-01-12 13:30:04 -08001320 struct xt_table_info *private;
Eric Dumazet31836062005-12-13 23:13:48 -08001321 void *loc_cpu_entry;
1322
Harald Welte2e4e6a12006-01-12 13:30:04 -08001323 private = xt_unregister_table(table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324
1325 /* Decrease module usage counts and free resources */
Harald Welte2e4e6a12006-01-12 13:30:04 -08001326 loc_cpu_entry = private->entries[raw_smp_processor_id()];
1327 IP6T_ENTRY_ITERATE(loc_cpu_entry, private->size, cleanup_entry, NULL);
1328 xt_free_table_info(private);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329}
1330
1331/* Returns 1 if the type and code is matched by the range, 0 otherwise */
1332static inline int
1333icmp6_type_code_match(u_int8_t test_type, u_int8_t min_code, u_int8_t max_code,
1334 u_int8_t type, u_int8_t code,
1335 int invert)
1336{
1337 return (type == test_type && code >= min_code && code <= max_code)
1338 ^ invert;
1339}
1340
1341static int
1342icmp6_match(const struct sk_buff *skb,
1343 const struct net_device *in,
1344 const struct net_device *out,
Patrick McHardyc4986732006-03-20 18:02:56 -08001345 const struct xt_match *match,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 const void *matchinfo,
1347 int offset,
1348 unsigned int protoff,
1349 int *hotdrop)
1350{
1351 struct icmp6hdr _icmp, *ic;
1352 const struct ip6t_icmp *icmpinfo = matchinfo;
1353
1354 /* Must not be a fragment. */
1355 if (offset)
1356 return 0;
1357
1358 ic = skb_header_pointer(skb, protoff, sizeof(_icmp), &_icmp);
1359 if (ic == NULL) {
1360 /* We've been asked to examine this packet, and we
1361 can't. Hence, no choice but to drop. */
1362 duprintf("Dropping evil ICMP tinygram.\n");
1363 *hotdrop = 1;
1364 return 0;
1365 }
1366
1367 return icmp6_type_code_match(icmpinfo->type,
1368 icmpinfo->code[0],
1369 icmpinfo->code[1],
1370 ic->icmp6_type, ic->icmp6_code,
1371 !!(icmpinfo->invflags&IP6T_ICMP_INV));
1372}
1373
1374/* Called when user tries to insert an entry of this type. */
1375static int
1376icmp6_checkentry(const char *tablename,
Harald Welte2e4e6a12006-01-12 13:30:04 -08001377 const void *entry,
Patrick McHardyc4986732006-03-20 18:02:56 -08001378 const struct xt_match *match,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 void *matchinfo,
1380 unsigned int matchsize,
1381 unsigned int hook_mask)
1382{
1383 const struct ip6t_icmp *icmpinfo = matchinfo;
1384
Patrick McHardy7f939712006-03-20 18:01:43 -08001385 /* Must specify no unknown invflags */
1386 return !(icmpinfo->invflags & ~IP6T_ICMP_INV);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387}
1388
1389/* The built-in targets: standard (NULL) and error. */
1390static struct ip6t_target ip6t_standard_target = {
1391 .name = IP6T_STANDARD_TARGET,
Patrick McHardy7f939712006-03-20 18:01:43 -08001392 .targetsize = sizeof(int),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393};
1394
1395static struct ip6t_target ip6t_error_target = {
1396 .name = IP6T_ERROR_TARGET,
1397 .target = ip6t_error,
Patrick McHardy7f939712006-03-20 18:01:43 -08001398 .targetsize = IP6T_FUNCTION_MAXNAMELEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399};
1400
1401static struct nf_sockopt_ops ip6t_sockopts = {
1402 .pf = PF_INET6,
1403 .set_optmin = IP6T_BASE_CTL,
1404 .set_optmax = IP6T_SO_SET_MAX+1,
1405 .set = do_ip6t_set_ctl,
1406 .get_optmin = IP6T_BASE_CTL,
1407 .get_optmax = IP6T_SO_GET_MAX+1,
1408 .get = do_ip6t_get_ctl,
1409};
1410
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411static struct ip6t_match icmp6_matchstruct = {
1412 .name = "icmp6",
1413 .match = &icmp6_match,
Patrick McHardy7f939712006-03-20 18:01:43 -08001414 .matchsize = sizeof(struct ip6t_icmp),
1415 .checkentry = icmp6_checkentry,
1416 .proto = IPPROTO_ICMPV6,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417};
1418
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419static int __init init(void)
1420{
1421 int ret;
1422
Harald Welte2e4e6a12006-01-12 13:30:04 -08001423 xt_proto_init(AF_INET6);
1424
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 /* Noone else will be downing sem now, so we won't sleep */
Harald Welte2e4e6a12006-01-12 13:30:04 -08001426 xt_register_target(AF_INET6, &ip6t_standard_target);
1427 xt_register_target(AF_INET6, &ip6t_error_target);
1428 xt_register_match(AF_INET6, &icmp6_matchstruct);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429
1430 /* Register setsockopt */
1431 ret = nf_register_sockopt(&ip6t_sockopts);
1432 if (ret < 0) {
1433 duprintf("Unable to register sockopts.\n");
Harald Welte2e4e6a12006-01-12 13:30:04 -08001434 xt_proto_fini(AF_INET6);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 return ret;
1436 }
1437
Harald Welte2e4e6a12006-01-12 13:30:04 -08001438 printk("ip6_tables: (C) 2000-2006 Netfilter Core Team\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 return 0;
1440}
1441
1442static void __exit fini(void)
1443{
1444 nf_unregister_sockopt(&ip6t_sockopts);
Harald Welte2e4e6a12006-01-12 13:30:04 -08001445 xt_unregister_match(AF_INET6, &icmp6_matchstruct);
1446 xt_unregister_target(AF_INET6, &ip6t_error_target);
1447 xt_unregister_target(AF_INET6, &ip6t_standard_target);
1448 xt_proto_fini(AF_INET6);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449}
1450
Yasuyuki Kozakaie674d0f2005-09-19 15:34:40 -07001451/*
Patrick McHardyb777e0c2006-01-05 12:21:16 -08001452 * find the offset to specified header or the protocol number of last header
1453 * if target < 0. "last header" is transport protocol header, ESP, or
1454 * "No next header".
Yasuyuki Kozakaie674d0f2005-09-19 15:34:40 -07001455 *
Patrick McHardyb777e0c2006-01-05 12:21:16 -08001456 * If target header is found, its offset is set in *offset and return protocol
1457 * number. Otherwise, return -1.
1458 *
1459 * Note that non-1st fragment is special case that "the protocol number
1460 * of last header" is "next header" field in Fragment header. In this case,
1461 * *offset is meaningless and fragment offset is stored in *fragoff if fragoff
1462 * isn't NULL.
1463 *
Yasuyuki Kozakaie674d0f2005-09-19 15:34:40 -07001464 */
Patrick McHardyb777e0c2006-01-05 12:21:16 -08001465int ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset,
1466 int target, unsigned short *fragoff)
Yasuyuki Kozakaie674d0f2005-09-19 15:34:40 -07001467{
1468 unsigned int start = (u8*)(skb->nh.ipv6h + 1) - skb->data;
1469 u8 nexthdr = skb->nh.ipv6h->nexthdr;
1470 unsigned int len = skb->len - start;
1471
Patrick McHardyb777e0c2006-01-05 12:21:16 -08001472 if (fragoff)
1473 *fragoff = 0;
1474
Yasuyuki Kozakaie674d0f2005-09-19 15:34:40 -07001475 while (nexthdr != target) {
1476 struct ipv6_opt_hdr _hdr, *hp;
1477 unsigned int hdrlen;
1478
Patrick McHardyb777e0c2006-01-05 12:21:16 -08001479 if ((!ipv6_ext_hdr(nexthdr)) || nexthdr == NEXTHDR_NONE) {
1480 if (target < 0)
1481 break;
Yasuyuki Kozakaie674d0f2005-09-19 15:34:40 -07001482 return -1;
Patrick McHardyb777e0c2006-01-05 12:21:16 -08001483 }
1484
Yasuyuki Kozakaie674d0f2005-09-19 15:34:40 -07001485 hp = skb_header_pointer(skb, start, sizeof(_hdr), &_hdr);
1486 if (hp == NULL)
1487 return -1;
1488 if (nexthdr == NEXTHDR_FRAGMENT) {
1489 unsigned short _frag_off, *fp;
1490 fp = skb_header_pointer(skb,
1491 start+offsetof(struct frag_hdr,
1492 frag_off),
1493 sizeof(_frag_off),
1494 &_frag_off);
1495 if (fp == NULL)
1496 return -1;
1497
Patrick McHardyb777e0c2006-01-05 12:21:16 -08001498 _frag_off = ntohs(*fp) & ~0x7;
1499 if (_frag_off) {
1500 if (target < 0 &&
1501 ((!ipv6_ext_hdr(hp->nexthdr)) ||
1502 nexthdr == NEXTHDR_NONE)) {
1503 if (fragoff)
1504 *fragoff = _frag_off;
1505 return hp->nexthdr;
1506 }
Yasuyuki Kozakaie674d0f2005-09-19 15:34:40 -07001507 return -1;
Patrick McHardyb777e0c2006-01-05 12:21:16 -08001508 }
Yasuyuki Kozakaie674d0f2005-09-19 15:34:40 -07001509 hdrlen = 8;
1510 } else if (nexthdr == NEXTHDR_AUTH)
1511 hdrlen = (hp->hdrlen + 2) << 2;
1512 else
1513 hdrlen = ipv6_optlen(hp);
1514
1515 nexthdr = hp->nexthdr;
1516 len -= hdrlen;
1517 start += hdrlen;
1518 }
1519
1520 *offset = start;
Patrick McHardyb777e0c2006-01-05 12:21:16 -08001521 return nexthdr;
Yasuyuki Kozakaie674d0f2005-09-19 15:34:40 -07001522}
1523
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524EXPORT_SYMBOL(ip6t_register_table);
1525EXPORT_SYMBOL(ip6t_unregister_table);
1526EXPORT_SYMBOL(ip6t_do_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527EXPORT_SYMBOL(ip6t_ext_hdr);
Yasuyuki Kozakaie674d0f2005-09-19 15:34:40 -07001528EXPORT_SYMBOL(ipv6_find_hdr);
Patrick McHardy22dea562006-01-05 12:21:34 -08001529EXPORT_SYMBOL(ip6_masked_addrcmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530
1531module_init(init);
1532module_exit(fini);