2 * Packet matching code.
4 * Copyright (C) 1999 Paul `Rusty' Russell & Michael J. Neuling
5 * Copyright (C) 2000-2005 Netfilter Core Team <coreteam@netfilter.org>
6 * Copyright (c) 2006-2010 Patrick McHardy <kaber@trash.net>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
13 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15 #include <linux/kernel.h>
16 #include <linux/capability.h>
18 #include <linux/skbuff.h>
19 #include <linux/kmod.h>
20 #include <linux/vmalloc.h>
21 #include <linux/netdevice.h>
22 #include <linux/module.h>
23 #include <linux/poison.h>
24 #include <linux/icmpv6.h>
26 #include <net/compat.h>
27 #include <linux/uaccess.h>
28 #include <linux/mutex.h>
29 #include <linux/proc_fs.h>
30 #include <linux/err.h>
31 #include <linux/cpumask.h>
33 #include <linux/netfilter_ipv6/ip6_tables.h>
34 #include <linux/netfilter/x_tables.h>
35 #include <net/netfilter/nf_log.h>
36 #include "../../netfilter/xt_repldata.h"
38 MODULE_LICENSE("GPL");
39 MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>");
40 MODULE_DESCRIPTION("IPv6 packet filter");
42 void *ip6t_alloc_initial_table(const struct xt_table *info)
44 return xt_alloc_initial_table(ip6t, IP6T);
46 EXPORT_SYMBOL_GPL(ip6t_alloc_initial_table);
48 /* Returns whether matches rule or not. */
49 /* Performance critical - called for every packet */
51 ip6_packet_match(const struct sk_buff *skb,
54 const struct ip6t_ip6 *ip6info,
55 unsigned int *protoff,
56 int *fragoff, bool *hotdrop)
59 const struct ipv6hdr *ipv6 = ipv6_hdr(skb);
61 if (NF_INVF(ip6info, IP6T_INV_SRCIP,
62 ipv6_masked_addr_cmp(&ipv6->saddr, &ip6info->smsk,
64 NF_INVF(ip6info, IP6T_INV_DSTIP,
65 ipv6_masked_addr_cmp(&ipv6->daddr, &ip6info->dmsk,
69 ret = ifname_compare_aligned(indev, ip6info->iniface, ip6info->iniface_mask);
71 if (NF_INVF(ip6info, IP6T_INV_VIA_IN, ret != 0))
74 ret = ifname_compare_aligned(outdev, ip6info->outiface, ip6info->outiface_mask);
76 if (NF_INVF(ip6info, IP6T_INV_VIA_OUT, ret != 0))
79 /* ... might want to do something with class and flowlabel here ... */
81 /* look for the desired protocol header */
82 if (ip6info->flags & IP6T_F_PROTO) {
84 unsigned short _frag_off;
86 protohdr = ipv6_find_hdr(skb, protoff, -1, &_frag_off, NULL);
94 if (ip6info->proto == protohdr) {
95 if (ip6info->invflags & IP6T_INV_PROTO)
101 /* We need match for the '-p all', too! */
102 if ((ip6info->proto != 0) &&
103 !(ip6info->invflags & IP6T_INV_PROTO))
109 /* should be ip6 safe */
111 ip6_checkentry(const struct ip6t_ip6 *ipv6)
113 if (ipv6->flags & ~IP6T_F_MASK)
115 if (ipv6->invflags & ~IP6T_INV_MASK)
122 ip6t_error(struct sk_buff *skb, const struct xt_action_param *par)
124 net_info_ratelimited("error: `%s'\n", (const char *)par->targinfo);
129 static inline struct ip6t_entry *
130 get_entry(const void *base, unsigned int offset)
132 return (struct ip6t_entry *)(base + offset);
135 /* All zeroes == unconditional rule. */
136 /* Mildly perf critical (only if packet tracing is on) */
137 static inline bool unconditional(const struct ip6t_entry *e)
139 static const struct ip6t_ip6 uncond;
141 return e->target_offset == sizeof(struct ip6t_entry) &&
142 memcmp(&e->ipv6, &uncond, sizeof(uncond)) == 0;
145 static inline const struct xt_entry_target *
146 ip6t_get_target_c(const struct ip6t_entry *e)
148 return ip6t_get_target((struct ip6t_entry *)e);
151 #if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
152 /* This cries for unification! */
153 static const char *const hooknames[] = {
154 [NF_INET_PRE_ROUTING] = "PREROUTING",
155 [NF_INET_LOCAL_IN] = "INPUT",
156 [NF_INET_FORWARD] = "FORWARD",
157 [NF_INET_LOCAL_OUT] = "OUTPUT",
158 [NF_INET_POST_ROUTING] = "POSTROUTING",
161 enum nf_ip_trace_comments {
162 NF_IP6_TRACE_COMMENT_RULE,
163 NF_IP6_TRACE_COMMENT_RETURN,
164 NF_IP6_TRACE_COMMENT_POLICY,
167 static const char *const comments[] = {
168 [NF_IP6_TRACE_COMMENT_RULE] = "rule",
169 [NF_IP6_TRACE_COMMENT_RETURN] = "return",
170 [NF_IP6_TRACE_COMMENT_POLICY] = "policy",
173 static const struct nf_loginfo trace_loginfo = {
174 .type = NF_LOG_TYPE_LOG,
177 .level = LOGLEVEL_WARNING,
178 .logflags = NF_LOG_DEFAULT_MASK,
183 /* Mildly perf critical (only if packet tracing is on) */
185 get_chainname_rulenum(const struct ip6t_entry *s, const struct ip6t_entry *e,
186 const char *hookname, const char **chainname,
187 const char **comment, unsigned int *rulenum)
189 const struct xt_standard_target *t = (void *)ip6t_get_target_c(s);
191 if (strcmp(t->target.u.kernel.target->name, XT_ERROR_TARGET) == 0) {
192 /* Head of user chain: ERROR target with chainname */
193 *chainname = t->target.data;
198 if (unconditional(s) &&
199 strcmp(t->target.u.kernel.target->name,
200 XT_STANDARD_TARGET) == 0 &&
202 /* Tail of chains: STANDARD target (return/policy) */
203 *comment = *chainname == hookname
204 ? comments[NF_IP6_TRACE_COMMENT_POLICY]
205 : comments[NF_IP6_TRACE_COMMENT_RETURN];
214 static void trace_packet(struct net *net,
215 const struct sk_buff *skb,
217 const struct net_device *in,
218 const struct net_device *out,
219 const char *tablename,
220 const struct xt_table_info *private,
221 const struct ip6t_entry *e)
223 const struct ip6t_entry *root;
224 const char *hookname, *chainname, *comment;
225 const struct ip6t_entry *iter;
226 unsigned int rulenum = 0;
228 root = get_entry(private->entries, private->hook_entry[hook]);
230 hookname = chainname = hooknames[hook];
231 comment = comments[NF_IP6_TRACE_COMMENT_RULE];
233 xt_entry_foreach(iter, root, private->size - private->hook_entry[hook])
234 if (get_chainname_rulenum(iter, e, hookname,
235 &chainname, &comment, &rulenum) != 0)
238 nf_log_trace(net, AF_INET6, hook, skb, in, out, &trace_loginfo,
239 "TRACE: %s:%s:%s:%u ",
240 tablename, chainname, comment, rulenum);
244 static inline struct ip6t_entry *
245 ip6t_next_entry(const struct ip6t_entry *entry)
247 return (void *)entry + entry->next_offset;
250 /* Returns one of the generic firewall policies, like NF_ACCEPT. */
252 ip6t_do_table(struct sk_buff *skb,
253 const struct nf_hook_state *state,
254 struct xt_table *table)
256 unsigned int hook = state->hook;
257 static const char nulldevname[IFNAMSIZ] __attribute__((aligned(sizeof(long))));
258 /* Initializing verdict to NF_DROP keeps gcc happy. */
259 unsigned int verdict = NF_DROP;
260 const char *indev, *outdev;
261 const void *table_base;
262 struct ip6t_entry *e, **jumpstack;
263 unsigned int stackidx, cpu;
264 const struct xt_table_info *private;
265 struct xt_action_param acpar;
270 indev = state->in ? state->in->name : nulldevname;
271 outdev = state->out ? state->out->name : nulldevname;
272 /* We handle fragments by dealing with the first fragment as
273 * if it was a normal packet. All other fragments are treated
274 * normally, except that they will NEVER match rules that ask
275 * things we don't know, ie. tcp syn flag or ports). If the
276 * rule is also a fragment-specific rule, non-fragments won't
278 acpar.hotdrop = false;
281 WARN_ON(!(table->valid_hooks & (1 << hook)));
284 addend = xt_write_recseq_begin();
285 private = READ_ONCE(table->private); /* Address dependency. */
286 cpu = smp_processor_id();
287 table_base = private->entries;
288 jumpstack = (struct ip6t_entry **)private->jumpstack[cpu];
290 /* Switch to alternate jumpstack if we're being invoked via TEE.
291 * TEE issues XT_CONTINUE verdict on original skb so we must not
292 * clobber the jumpstack.
294 * For recursion via REJECT or SYNPROXY the stack will be clobbered
295 * but it is no problem since absolute verdict is issued by these.
297 if (static_key_false(&xt_tee_enabled))
298 jumpstack += private->stacksize * __this_cpu_read(nf_skb_duplicated);
300 e = get_entry(table_base, private->hook_entry[hook]);
303 const struct xt_entry_target *t;
304 const struct xt_entry_match *ematch;
305 struct xt_counters *counter;
309 if (!ip6_packet_match(skb, indev, outdev, &e->ipv6,
310 &acpar.thoff, &acpar.fragoff, &acpar.hotdrop)) {
312 e = ip6t_next_entry(e);
316 xt_ematch_foreach(ematch, e) {
317 acpar.match = ematch->u.kernel.match;
318 acpar.matchinfo = ematch->data;
319 if (!acpar.match->match(skb, &acpar))
323 counter = xt_get_this_cpu_counter(&e->counters);
324 ADD_COUNTER(*counter, skb->len, 1);
326 t = ip6t_get_target_c(e);
327 WARN_ON(!t->u.kernel.target);
329 #if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
330 /* The packet is traced: log it */
331 if (unlikely(skb->nf_trace))
332 trace_packet(state->net, skb, hook, state->in,
333 state->out, table->name, private, e);
335 /* Standard target? */
336 if (!t->u.kernel.target->target) {
339 v = ((struct xt_standard_target *)t)->verdict;
341 /* Pop from stack? */
342 if (v != XT_RETURN) {
343 verdict = (unsigned int)(-v) - 1;
347 e = get_entry(table_base,
348 private->underflow[hook]);
350 e = ip6t_next_entry(jumpstack[--stackidx]);
353 if (table_base + v != ip6t_next_entry(e) &&
354 !(e->ipv6.flags & IP6T_F_GOTO)) {
355 if (unlikely(stackidx >= private->stacksize)) {
359 jumpstack[stackidx++] = e;
362 e = get_entry(table_base, v);
366 acpar.target = t->u.kernel.target;
367 acpar.targinfo = t->data;
369 verdict = t->u.kernel.target->target(skb, &acpar);
370 if (verdict == XT_CONTINUE)
371 e = ip6t_next_entry(e);
375 } while (!acpar.hotdrop);
377 xt_write_recseq_end(addend);
385 /* Figures out from what hook each rule can be called: returns 0 if
386 there are loops. Puts hook bitmask in comefrom. */
388 mark_source_chains(const struct xt_table_info *newinfo,
389 unsigned int valid_hooks, void *entry0,
390 unsigned int *offsets)
394 /* No recursion; use packet counter to save back ptrs (reset
395 to 0 as we leave), and comefrom to save source hook bitmask */
396 for (hook = 0; hook < NF_INET_NUMHOOKS; hook++) {
397 unsigned int pos = newinfo->hook_entry[hook];
398 struct ip6t_entry *e = entry0 + pos;
400 if (!(valid_hooks & (1 << hook)))
403 /* Set initial back pointer. */
404 e->counters.pcnt = pos;
407 const struct xt_standard_target *t
408 = (void *)ip6t_get_target_c(e);
409 int visited = e->comefrom & (1 << hook);
411 if (e->comefrom & (1 << NF_INET_NUMHOOKS))
414 e->comefrom |= ((1 << hook) | (1 << NF_INET_NUMHOOKS));
416 /* Unconditional return/END. */
417 if ((unconditional(e) &&
418 (strcmp(t->target.u.user.name,
419 XT_STANDARD_TARGET) == 0) &&
420 t->verdict < 0) || visited) {
421 unsigned int oldpos, size;
423 if ((strcmp(t->target.u.user.name,
424 XT_STANDARD_TARGET) == 0) &&
425 t->verdict < -NF_MAX_VERDICT - 1)
428 /* Return: backtrack through the last
431 e->comefrom ^= (1<<NF_INET_NUMHOOKS);
433 pos = e->counters.pcnt;
434 e->counters.pcnt = 0;
436 /* We're at the start. */
441 } while (oldpos == pos + e->next_offset);
444 size = e->next_offset;
445 e = entry0 + pos + size;
446 if (pos + size >= newinfo->size)
448 e->counters.pcnt = pos;
451 int newpos = t->verdict;
453 if (strcmp(t->target.u.user.name,
454 XT_STANDARD_TARGET) == 0 &&
456 /* This a jump; chase it. */
457 if (!xt_find_jump_offset(offsets, newpos,
461 /* ... this is a fallthru */
462 newpos = pos + e->next_offset;
463 if (newpos >= newinfo->size)
467 e->counters.pcnt = pos;
476 static void cleanup_match(struct xt_entry_match *m, struct net *net)
478 struct xt_mtdtor_param par;
481 par.match = m->u.kernel.match;
482 par.matchinfo = m->data;
483 par.family = NFPROTO_IPV6;
484 if (par.match->destroy != NULL)
485 par.match->destroy(&par);
486 module_put(par.match->me);
489 static int check_match(struct xt_entry_match *m, struct xt_mtchk_param *par)
491 const struct ip6t_ip6 *ipv6 = par->entryinfo;
493 par->match = m->u.kernel.match;
494 par->matchinfo = m->data;
496 return xt_check_match(par, m->u.match_size - sizeof(*m),
497 ipv6->proto, ipv6->invflags & IP6T_INV_PROTO);
501 find_check_match(struct xt_entry_match *m, struct xt_mtchk_param *par)
503 struct xt_match *match;
506 match = xt_request_find_match(NFPROTO_IPV6, m->u.user.name,
509 return PTR_ERR(match);
511 m->u.kernel.match = match;
513 ret = check_match(m, par);
519 module_put(m->u.kernel.match->me);
523 static int check_target(struct ip6t_entry *e, struct net *net, const char *name)
525 struct xt_entry_target *t = ip6t_get_target(e);
526 struct xt_tgchk_param par = {
530 .target = t->u.kernel.target,
532 .hook_mask = e->comefrom,
533 .family = NFPROTO_IPV6,
536 t = ip6t_get_target(e);
537 return xt_check_target(&par, t->u.target_size - sizeof(*t),
539 e->ipv6.invflags & IP6T_INV_PROTO);
543 find_check_entry(struct ip6t_entry *e, struct net *net, const char *name,
545 struct xt_percpu_counter_alloc_state *alloc_state)
547 struct xt_entry_target *t;
548 struct xt_target *target;
551 struct xt_mtchk_param mtpar;
552 struct xt_entry_match *ematch;
554 if (!xt_percpu_counter_alloc(alloc_state, &e->counters))
560 mtpar.entryinfo = &e->ipv6;
561 mtpar.hook_mask = e->comefrom;
562 mtpar.family = NFPROTO_IPV6;
563 xt_ematch_foreach(ematch, e) {
564 ret = find_check_match(ematch, &mtpar);
566 goto cleanup_matches;
570 t = ip6t_get_target(e);
571 target = xt_request_find_target(NFPROTO_IPV6, t->u.user.name,
573 if (IS_ERR(target)) {
574 ret = PTR_ERR(target);
575 goto cleanup_matches;
577 t->u.kernel.target = target;
579 ret = check_target(e, net, name);
584 module_put(t->u.kernel.target->me);
586 xt_ematch_foreach(ematch, e) {
589 cleanup_match(ematch, net);
592 xt_percpu_counter_free(&e->counters);
597 static bool check_underflow(const struct ip6t_entry *e)
599 const struct xt_entry_target *t;
600 unsigned int verdict;
602 if (!unconditional(e))
604 t = ip6t_get_target_c(e);
605 if (strcmp(t->u.user.name, XT_STANDARD_TARGET) != 0)
607 verdict = ((struct xt_standard_target *)t)->verdict;
608 verdict = -verdict - 1;
609 return verdict == NF_DROP || verdict == NF_ACCEPT;
613 check_entry_size_and_hooks(struct ip6t_entry *e,
614 struct xt_table_info *newinfo,
615 const unsigned char *base,
616 const unsigned char *limit,
617 const unsigned int *hook_entries,
618 const unsigned int *underflows,
619 unsigned int valid_hooks)
624 if ((unsigned long)e % __alignof__(struct ip6t_entry) != 0 ||
625 (unsigned char *)e + sizeof(struct ip6t_entry) >= limit ||
626 (unsigned char *)e + e->next_offset > limit)
630 < sizeof(struct ip6t_entry) + sizeof(struct xt_entry_target))
633 if (!ip6_checkentry(&e->ipv6))
636 err = xt_check_entry_offsets(e, e->elems, e->target_offset,
641 /* Check hooks & underflows */
642 for (h = 0; h < NF_INET_NUMHOOKS; h++) {
643 if (!(valid_hooks & (1 << h)))
645 if ((unsigned char *)e - base == hook_entries[h])
646 newinfo->hook_entry[h] = hook_entries[h];
647 if ((unsigned char *)e - base == underflows[h]) {
648 if (!check_underflow(e))
651 newinfo->underflow[h] = underflows[h];
655 /* Clear counters and comefrom */
656 e->counters = ((struct xt_counters) { 0, 0 });
661 static void cleanup_entry(struct ip6t_entry *e, struct net *net)
663 struct xt_tgdtor_param par;
664 struct xt_entry_target *t;
665 struct xt_entry_match *ematch;
667 /* Cleanup all matches */
668 xt_ematch_foreach(ematch, e)
669 cleanup_match(ematch, net);
670 t = ip6t_get_target(e);
673 par.target = t->u.kernel.target;
674 par.targinfo = t->data;
675 par.family = NFPROTO_IPV6;
676 if (par.target->destroy != NULL)
677 par.target->destroy(&par);
678 module_put(par.target->me);
679 xt_percpu_counter_free(&e->counters);
682 /* Checks and translates the user-supplied table segment (held in
685 translate_table(struct net *net, struct xt_table_info *newinfo, void *entry0,
686 const struct ip6t_replace *repl)
688 struct xt_percpu_counter_alloc_state alloc_state = { 0 };
689 struct ip6t_entry *iter;
690 unsigned int *offsets;
694 newinfo->size = repl->size;
695 newinfo->number = repl->num_entries;
697 /* Init all hooks to impossible value. */
698 for (i = 0; i < NF_INET_NUMHOOKS; i++) {
699 newinfo->hook_entry[i] = 0xFFFFFFFF;
700 newinfo->underflow[i] = 0xFFFFFFFF;
703 offsets = xt_alloc_entry_offsets(newinfo->number);
707 /* Walk through entries, checking offsets. */
708 xt_entry_foreach(iter, entry0, newinfo->size) {
709 ret = check_entry_size_and_hooks(iter, newinfo, entry0,
716 if (i < repl->num_entries)
717 offsets[i] = (void *)iter - entry0;
719 if (strcmp(ip6t_get_target(iter)->u.user.name,
720 XT_ERROR_TARGET) == 0)
721 ++newinfo->stacksize;
725 if (i != repl->num_entries)
728 /* Check hooks all assigned */
729 for (i = 0; i < NF_INET_NUMHOOKS; i++) {
730 /* Only hooks which are valid */
731 if (!(repl->valid_hooks & (1 << i)))
733 if (newinfo->hook_entry[i] == 0xFFFFFFFF)
735 if (newinfo->underflow[i] == 0xFFFFFFFF)
739 if (!mark_source_chains(newinfo, repl->valid_hooks, entry0, offsets)) {
745 /* Finally, each sanity check must pass */
747 xt_entry_foreach(iter, entry0, newinfo->size) {
748 ret = find_check_entry(iter, net, repl->name, repl->size,
756 xt_entry_foreach(iter, entry0, newinfo->size) {
759 cleanup_entry(iter, net);
771 get_counters(const struct xt_table_info *t,
772 struct xt_counters counters[])
774 struct ip6t_entry *iter;
778 for_each_possible_cpu(cpu) {
779 seqcount_t *s = &per_cpu(xt_recseq, cpu);
782 xt_entry_foreach(iter, t->entries, t->size) {
783 struct xt_counters *tmp;
787 tmp = xt_get_per_cpu_counter(&iter->counters, cpu);
789 start = read_seqcount_begin(s);
792 } while (read_seqcount_retry(s, start));
794 ADD_COUNTER(counters[i], bcnt, pcnt);
801 static void get_old_counters(const struct xt_table_info *t,
802 struct xt_counters counters[])
804 struct ip6t_entry *iter;
807 for_each_possible_cpu(cpu) {
809 xt_entry_foreach(iter, t->entries, t->size) {
810 const struct xt_counters *tmp;
812 tmp = xt_get_per_cpu_counter(&iter->counters, cpu);
813 ADD_COUNTER(counters[i], tmp->bcnt, tmp->pcnt);
820 static struct xt_counters *alloc_counters(const struct xt_table *table)
822 unsigned int countersize;
823 struct xt_counters *counters;
824 const struct xt_table_info *private = table->private;
826 /* We need atomic snapshot of counters: rest doesn't change
827 (other than comefrom, which userspace doesn't care
829 countersize = sizeof(struct xt_counters) * private->number;
830 counters = vzalloc(countersize);
832 if (counters == NULL)
833 return ERR_PTR(-ENOMEM);
835 get_counters(private, counters);
841 copy_entries_to_user(unsigned int total_size,
842 const struct xt_table *table,
843 void __user *userptr)
845 unsigned int off, num;
846 const struct ip6t_entry *e;
847 struct xt_counters *counters;
848 const struct xt_table_info *private = table->private;
850 const void *loc_cpu_entry;
852 counters = alloc_counters(table);
853 if (IS_ERR(counters))
854 return PTR_ERR(counters);
856 loc_cpu_entry = private->entries;
858 /* FIXME: use iterator macros --RR */
859 /* ... then go back and fix counters and names */
860 for (off = 0, num = 0; off < total_size; off += e->next_offset, num++){
862 const struct xt_entry_match *m;
863 const struct xt_entry_target *t;
865 e = loc_cpu_entry + off;
866 if (copy_to_user(userptr + off, e, sizeof(*e))) {
870 if (copy_to_user(userptr + off
871 + offsetof(struct ip6t_entry, counters),
873 sizeof(counters[num])) != 0) {
878 for (i = sizeof(struct ip6t_entry);
879 i < e->target_offset;
880 i += m->u.match_size) {
883 if (xt_match_to_user(m, userptr + off + i)) {
889 t = ip6t_get_target_c(e);
890 if (xt_target_to_user(t, userptr + off + e->target_offset)) {
902 static void compat_standard_from_user(void *dst, const void *src)
904 int v = *(compat_int_t *)src;
907 v += xt_compat_calc_jump(AF_INET6, v);
908 memcpy(dst, &v, sizeof(v));
911 static int compat_standard_to_user(void __user *dst, const void *src)
913 compat_int_t cv = *(int *)src;
916 cv -= xt_compat_calc_jump(AF_INET6, cv);
917 return copy_to_user(dst, &cv, sizeof(cv)) ? -EFAULT : 0;
920 static int compat_calc_entry(const struct ip6t_entry *e,
921 const struct xt_table_info *info,
922 const void *base, struct xt_table_info *newinfo)
924 const struct xt_entry_match *ematch;
925 const struct xt_entry_target *t;
926 unsigned int entry_offset;
929 off = sizeof(struct ip6t_entry) - sizeof(struct compat_ip6t_entry);
930 entry_offset = (void *)e - base;
931 xt_ematch_foreach(ematch, e)
932 off += xt_compat_match_offset(ematch->u.kernel.match);
933 t = ip6t_get_target_c(e);
934 off += xt_compat_target_offset(t->u.kernel.target);
935 newinfo->size -= off;
936 ret = xt_compat_add_offset(AF_INET6, entry_offset, off);
940 for (i = 0; i < NF_INET_NUMHOOKS; i++) {
941 if (info->hook_entry[i] &&
942 (e < (struct ip6t_entry *)(base + info->hook_entry[i])))
943 newinfo->hook_entry[i] -= off;
944 if (info->underflow[i] &&
945 (e < (struct ip6t_entry *)(base + info->underflow[i])))
946 newinfo->underflow[i] -= off;
951 static int compat_table_info(const struct xt_table_info *info,
952 struct xt_table_info *newinfo)
954 struct ip6t_entry *iter;
955 const void *loc_cpu_entry;
958 if (!newinfo || !info)
961 /* we dont care about newinfo->entries */
962 memcpy(newinfo, info, offsetof(struct xt_table_info, entries));
963 newinfo->initial_entries = 0;
964 loc_cpu_entry = info->entries;
965 xt_compat_init_offsets(AF_INET6, info->number);
966 xt_entry_foreach(iter, loc_cpu_entry, info->size) {
967 ret = compat_calc_entry(iter, info, loc_cpu_entry, newinfo);
975 static int get_info(struct net *net, void __user *user,
976 const int *len, int compat)
978 char name[XT_TABLE_MAXNAMELEN];
982 if (*len != sizeof(struct ip6t_getinfo))
985 if (copy_from_user(name, user, sizeof(name)) != 0)
988 name[XT_TABLE_MAXNAMELEN-1] = '\0';
991 xt_compat_lock(AF_INET6);
993 t = xt_request_find_table_lock(net, AF_INET6, name);
995 struct ip6t_getinfo info;
996 const struct xt_table_info *private = t->private;
998 struct xt_table_info tmp;
1001 ret = compat_table_info(private, &tmp);
1002 xt_compat_flush_offsets(AF_INET6);
1006 memset(&info, 0, sizeof(info));
1007 info.valid_hooks = t->valid_hooks;
1008 memcpy(info.hook_entry, private->hook_entry,
1009 sizeof(info.hook_entry));
1010 memcpy(info.underflow, private->underflow,
1011 sizeof(info.underflow));
1012 info.num_entries = private->number;
1013 info.size = private->size;
1014 strcpy(info.name, name);
1016 if (copy_to_user(user, &info, *len) != 0)
1025 #ifdef CONFIG_COMPAT
1027 xt_compat_unlock(AF_INET6);
1033 get_entries(struct net *net, struct ip6t_get_entries __user *uptr,
1037 struct ip6t_get_entries get;
1040 if (*len < sizeof(get))
1042 if (copy_from_user(&get, uptr, sizeof(get)) != 0)
1044 if (*len != sizeof(struct ip6t_get_entries) + get.size)
1047 get.name[sizeof(get.name) - 1] = '\0';
1049 t = xt_find_table_lock(net, AF_INET6, get.name);
1051 struct xt_table_info *private = t->private;
1052 if (get.size == private->size)
1053 ret = copy_entries_to_user(private->size,
1054 t, uptr->entrytable);
1067 __do_replace(struct net *net, const char *name, unsigned int valid_hooks,
1068 struct xt_table_info *newinfo, unsigned int num_counters,
1069 void __user *counters_ptr)
1073 struct xt_table_info *oldinfo;
1074 struct xt_counters *counters;
1075 struct ip6t_entry *iter;
1078 counters = vzalloc(num_counters * sizeof(struct xt_counters));
1084 t = xt_request_find_table_lock(net, AF_INET6, name);
1087 goto free_newinfo_counters_untrans;
1091 if (valid_hooks != t->valid_hooks) {
1096 oldinfo = xt_replace_table(t, num_counters, newinfo, &ret);
1100 /* Update module usage count based on number of rules */
1101 if ((oldinfo->number > oldinfo->initial_entries) ||
1102 (newinfo->number <= oldinfo->initial_entries))
1104 if ((oldinfo->number > oldinfo->initial_entries) &&
1105 (newinfo->number <= oldinfo->initial_entries))
1108 get_old_counters(oldinfo, counters);
1110 /* Decrease module usage counts and free resource */
1111 xt_entry_foreach(iter, oldinfo->entries, oldinfo->size)
1112 cleanup_entry(iter, net);
1114 xt_free_table_info(oldinfo);
1115 if (copy_to_user(counters_ptr, counters,
1116 sizeof(struct xt_counters) * num_counters) != 0) {
1117 /* Silent error, can't fail, new table is already in place */
1118 net_warn_ratelimited("ip6tables: counters copy to user failed while replacing table\n");
1127 free_newinfo_counters_untrans:
1134 do_replace(struct net *net, const void __user *user, unsigned int len)
1137 struct ip6t_replace tmp;
1138 struct xt_table_info *newinfo;
1139 void *loc_cpu_entry;
1140 struct ip6t_entry *iter;
1142 if (copy_from_user(&tmp, user, sizeof(tmp)) != 0)
1145 /* overflow check */
1146 if (tmp.num_counters >= INT_MAX / sizeof(struct xt_counters))
1148 if (tmp.num_counters == 0)
1151 tmp.name[sizeof(tmp.name)-1] = 0;
1153 newinfo = xt_alloc_table_info(tmp.size);
1157 loc_cpu_entry = newinfo->entries;
1158 if (copy_from_user(loc_cpu_entry, user + sizeof(tmp),
1164 ret = translate_table(net, newinfo, loc_cpu_entry, &tmp);
1168 ret = __do_replace(net, tmp.name, tmp.valid_hooks, newinfo,
1169 tmp.num_counters, tmp.counters);
1171 goto free_newinfo_untrans;
1174 free_newinfo_untrans:
1175 xt_entry_foreach(iter, loc_cpu_entry, newinfo->size)
1176 cleanup_entry(iter, net);
1178 xt_free_table_info(newinfo);
1183 do_add_counters(struct net *net, const void __user *user, unsigned int len,
1187 struct xt_counters_info tmp;
1188 struct xt_counters *paddc;
1190 const struct xt_table_info *private;
1192 struct ip6t_entry *iter;
1193 unsigned int addend;
1195 paddc = xt_copy_counters_from_user(user, len, &tmp, compat);
1197 return PTR_ERR(paddc);
1198 t = xt_find_table_lock(net, AF_INET6, tmp.name);
1205 private = t->private;
1206 if (private->number != tmp.num_counters) {
1208 goto unlock_up_free;
1212 addend = xt_write_recseq_begin();
1213 xt_entry_foreach(iter, private->entries, private->size) {
1214 struct xt_counters *tmp;
1216 tmp = xt_get_this_cpu_counter(&iter->counters);
1217 ADD_COUNTER(*tmp, paddc[i].bcnt, paddc[i].pcnt);
1220 xt_write_recseq_end(addend);
1231 #ifdef CONFIG_COMPAT
1232 struct compat_ip6t_replace {
1233 char name[XT_TABLE_MAXNAMELEN];
1237 u32 hook_entry[NF_INET_NUMHOOKS];
1238 u32 underflow[NF_INET_NUMHOOKS];
1240 compat_uptr_t counters; /* struct xt_counters * */
1241 struct compat_ip6t_entry entries[0];
1245 compat_copy_entry_to_user(struct ip6t_entry *e, void __user **dstptr,
1246 unsigned int *size, struct xt_counters *counters,
1249 struct xt_entry_target *t;
1250 struct compat_ip6t_entry __user *ce;
1251 u_int16_t target_offset, next_offset;
1252 compat_uint_t origsize;
1253 const struct xt_entry_match *ematch;
1258 if (copy_to_user(ce, e, sizeof(struct ip6t_entry)) != 0 ||
1259 copy_to_user(&ce->counters, &counters[i],
1260 sizeof(counters[i])) != 0)
1263 *dstptr += sizeof(struct compat_ip6t_entry);
1264 *size -= sizeof(struct ip6t_entry) - sizeof(struct compat_ip6t_entry);
1266 xt_ematch_foreach(ematch, e) {
1267 ret = xt_compat_match_to_user(ematch, dstptr, size);
1271 target_offset = e->target_offset - (origsize - *size);
1272 t = ip6t_get_target(e);
1273 ret = xt_compat_target_to_user(t, dstptr, size);
1276 next_offset = e->next_offset - (origsize - *size);
1277 if (put_user(target_offset, &ce->target_offset) != 0 ||
1278 put_user(next_offset, &ce->next_offset) != 0)
1284 compat_find_calc_match(struct xt_entry_match *m,
1285 const struct ip6t_ip6 *ipv6,
1288 struct xt_match *match;
1290 match = xt_request_find_match(NFPROTO_IPV6, m->u.user.name,
1291 m->u.user.revision);
1293 return PTR_ERR(match);
1295 m->u.kernel.match = match;
1296 *size += xt_compat_match_offset(match);
1300 static void compat_release_entry(struct compat_ip6t_entry *e)
1302 struct xt_entry_target *t;
1303 struct xt_entry_match *ematch;
1305 /* Cleanup all matches */
1306 xt_ematch_foreach(ematch, e)
1307 module_put(ematch->u.kernel.match->me);
1308 t = compat_ip6t_get_target(e);
1309 module_put(t->u.kernel.target->me);
1313 check_compat_entry_size_and_hooks(struct compat_ip6t_entry *e,
1314 struct xt_table_info *newinfo,
1316 const unsigned char *base,
1317 const unsigned char *limit)
1319 struct xt_entry_match *ematch;
1320 struct xt_entry_target *t;
1321 struct xt_target *target;
1322 unsigned int entry_offset;
1326 if ((unsigned long)e % __alignof__(struct compat_ip6t_entry) != 0 ||
1327 (unsigned char *)e + sizeof(struct compat_ip6t_entry) >= limit ||
1328 (unsigned char *)e + e->next_offset > limit)
1331 if (e->next_offset < sizeof(struct compat_ip6t_entry) +
1332 sizeof(struct compat_xt_entry_target))
1335 if (!ip6_checkentry(&e->ipv6))
1338 ret = xt_compat_check_entry_offsets(e, e->elems,
1339 e->target_offset, e->next_offset);
1343 off = sizeof(struct ip6t_entry) - sizeof(struct compat_ip6t_entry);
1344 entry_offset = (void *)e - (void *)base;
1346 xt_ematch_foreach(ematch, e) {
1347 ret = compat_find_calc_match(ematch, &e->ipv6, &off);
1349 goto release_matches;
1353 t = compat_ip6t_get_target(e);
1354 target = xt_request_find_target(NFPROTO_IPV6, t->u.user.name,
1355 t->u.user.revision);
1356 if (IS_ERR(target)) {
1357 ret = PTR_ERR(target);
1358 goto release_matches;
1360 t->u.kernel.target = target;
1362 off += xt_compat_target_offset(target);
1364 ret = xt_compat_add_offset(AF_INET6, entry_offset, off);
1371 module_put(t->u.kernel.target->me);
1373 xt_ematch_foreach(ematch, e) {
1376 module_put(ematch->u.kernel.match->me);
1382 compat_copy_entry_from_user(struct compat_ip6t_entry *e, void **dstptr,
1384 struct xt_table_info *newinfo, unsigned char *base)
1386 struct xt_entry_target *t;
1387 struct ip6t_entry *de;
1388 unsigned int origsize;
1390 struct xt_entry_match *ematch;
1394 memcpy(de, e, sizeof(struct ip6t_entry));
1395 memcpy(&de->counters, &e->counters, sizeof(e->counters));
1397 *dstptr += sizeof(struct ip6t_entry);
1398 *size += sizeof(struct ip6t_entry) - sizeof(struct compat_ip6t_entry);
1400 xt_ematch_foreach(ematch, e)
1401 xt_compat_match_from_user(ematch, dstptr, size);
1403 de->target_offset = e->target_offset - (origsize - *size);
1404 t = compat_ip6t_get_target(e);
1405 xt_compat_target_from_user(t, dstptr, size);
1407 de->next_offset = e->next_offset - (origsize - *size);
1408 for (h = 0; h < NF_INET_NUMHOOKS; h++) {
1409 if ((unsigned char *)de - base < newinfo->hook_entry[h])
1410 newinfo->hook_entry[h] -= origsize - *size;
1411 if ((unsigned char *)de - base < newinfo->underflow[h])
1412 newinfo->underflow[h] -= origsize - *size;
1417 translate_compat_table(struct net *net,
1418 struct xt_table_info **pinfo,
1420 const struct compat_ip6t_replace *compatr)
1423 struct xt_table_info *newinfo, *info;
1424 void *pos, *entry0, *entry1;
1425 struct compat_ip6t_entry *iter0;
1426 struct ip6t_replace repl;
1432 size = compatr->size;
1433 info->number = compatr->num_entries;
1436 xt_compat_lock(AF_INET6);
1437 xt_compat_init_offsets(AF_INET6, compatr->num_entries);
1438 /* Walk through entries, checking offsets. */
1439 xt_entry_foreach(iter0, entry0, compatr->size) {
1440 ret = check_compat_entry_size_and_hooks(iter0, info, &size,
1442 entry0 + compatr->size);
1449 if (j != compatr->num_entries)
1453 newinfo = xt_alloc_table_info(size);
1457 newinfo->number = compatr->num_entries;
1458 for (i = 0; i < NF_INET_NUMHOOKS; i++) {
1459 newinfo->hook_entry[i] = compatr->hook_entry[i];
1460 newinfo->underflow[i] = compatr->underflow[i];
1462 entry1 = newinfo->entries;
1464 size = compatr->size;
1465 xt_entry_foreach(iter0, entry0, compatr->size)
1466 compat_copy_entry_from_user(iter0, &pos, &size,
1469 /* all module references in entry0 are now gone. */
1470 xt_compat_flush_offsets(AF_INET6);
1471 xt_compat_unlock(AF_INET6);
1473 memcpy(&repl, compatr, sizeof(*compatr));
1475 for (i = 0; i < NF_INET_NUMHOOKS; i++) {
1476 repl.hook_entry[i] = newinfo->hook_entry[i];
1477 repl.underflow[i] = newinfo->underflow[i];
1480 repl.num_counters = 0;
1481 repl.counters = NULL;
1482 repl.size = newinfo->size;
1483 ret = translate_table(net, newinfo, entry1, &repl);
1489 xt_free_table_info(info);
1493 xt_free_table_info(newinfo);
1496 xt_compat_flush_offsets(AF_INET6);
1497 xt_compat_unlock(AF_INET6);
1498 xt_entry_foreach(iter0, entry0, compatr->size) {
1501 compat_release_entry(iter0);
1507 compat_do_replace(struct net *net, void __user *user, unsigned int len)
1510 struct compat_ip6t_replace tmp;
1511 struct xt_table_info *newinfo;
1512 void *loc_cpu_entry;
1513 struct ip6t_entry *iter;
1515 if (copy_from_user(&tmp, user, sizeof(tmp)) != 0)
1518 /* overflow check */
1519 if (tmp.num_counters >= INT_MAX / sizeof(struct xt_counters))
1521 if (tmp.num_counters == 0)
1524 tmp.name[sizeof(tmp.name)-1] = 0;
1526 newinfo = xt_alloc_table_info(tmp.size);
1530 loc_cpu_entry = newinfo->entries;
1531 if (copy_from_user(loc_cpu_entry, user + sizeof(tmp),
1537 ret = translate_compat_table(net, &newinfo, &loc_cpu_entry, &tmp);
1541 ret = __do_replace(net, tmp.name, tmp.valid_hooks, newinfo,
1542 tmp.num_counters, compat_ptr(tmp.counters));
1544 goto free_newinfo_untrans;
1547 free_newinfo_untrans:
1548 xt_entry_foreach(iter, loc_cpu_entry, newinfo->size)
1549 cleanup_entry(iter, net);
1551 xt_free_table_info(newinfo);
1556 compat_do_ip6t_set_ctl(struct sock *sk, int cmd, void __user *user,
1561 if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN))
1565 case IP6T_SO_SET_REPLACE:
1566 ret = compat_do_replace(sock_net(sk), user, len);
1569 case IP6T_SO_SET_ADD_COUNTERS:
1570 ret = do_add_counters(sock_net(sk), user, len, 1);
1580 struct compat_ip6t_get_entries {
1581 char name[XT_TABLE_MAXNAMELEN];
1583 struct compat_ip6t_entry entrytable[0];
1587 compat_copy_entries_to_user(unsigned int total_size, struct xt_table *table,
1588 void __user *userptr)
1590 struct xt_counters *counters;
1591 const struct xt_table_info *private = table->private;
1596 struct ip6t_entry *iter;
1598 counters = alloc_counters(table);
1599 if (IS_ERR(counters))
1600 return PTR_ERR(counters);
1604 xt_entry_foreach(iter, private->entries, total_size) {
1605 ret = compat_copy_entry_to_user(iter, &pos,
1606 &size, counters, i++);
1616 compat_get_entries(struct net *net, struct compat_ip6t_get_entries __user *uptr,
1620 struct compat_ip6t_get_entries get;
1623 if (*len < sizeof(get))
1626 if (copy_from_user(&get, uptr, sizeof(get)) != 0)
1629 if (*len != sizeof(struct compat_ip6t_get_entries) + get.size)
1632 get.name[sizeof(get.name) - 1] = '\0';
1634 xt_compat_lock(AF_INET6);
1635 t = xt_find_table_lock(net, AF_INET6, get.name);
1637 const struct xt_table_info *private = t->private;
1638 struct xt_table_info info;
1639 ret = compat_table_info(private, &info);
1640 if (!ret && get.size == info.size)
1641 ret = compat_copy_entries_to_user(private->size,
1642 t, uptr->entrytable);
1646 xt_compat_flush_offsets(AF_INET6);
1652 xt_compat_unlock(AF_INET6);
1656 static int do_ip6t_get_ctl(struct sock *, int, void __user *, int *);
1659 compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
1663 if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN))
1667 case IP6T_SO_GET_INFO:
1668 ret = get_info(sock_net(sk), user, len, 1);
1670 case IP6T_SO_GET_ENTRIES:
1671 ret = compat_get_entries(sock_net(sk), user, len);
1674 ret = do_ip6t_get_ctl(sk, cmd, user, len);
1681 do_ip6t_set_ctl(struct sock *sk, int cmd, void __user *user, unsigned int len)
1685 if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN))
1689 case IP6T_SO_SET_REPLACE:
1690 ret = do_replace(sock_net(sk), user, len);
1693 case IP6T_SO_SET_ADD_COUNTERS:
1694 ret = do_add_counters(sock_net(sk), user, len, 0);
1705 do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
1709 if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN))
1713 case IP6T_SO_GET_INFO:
1714 ret = get_info(sock_net(sk), user, len, 0);
1717 case IP6T_SO_GET_ENTRIES:
1718 ret = get_entries(sock_net(sk), user, len);
1721 case IP6T_SO_GET_REVISION_MATCH:
1722 case IP6T_SO_GET_REVISION_TARGET: {
1723 struct xt_get_revision rev;
1726 if (*len != sizeof(rev)) {
1730 if (copy_from_user(&rev, user, sizeof(rev)) != 0) {
1734 rev.name[sizeof(rev.name)-1] = 0;
1736 if (cmd == IP6T_SO_GET_REVISION_TARGET)
1741 try_then_request_module(xt_find_revision(AF_INET6, rev.name,
1744 "ip6t_%s", rev.name);
1755 static void __ip6t_unregister_table(struct net *net, struct xt_table *table)
1757 struct xt_table_info *private;
1758 void *loc_cpu_entry;
1759 struct module *table_owner = table->me;
1760 struct ip6t_entry *iter;
1762 private = xt_unregister_table(table);
1764 /* Decrease module usage counts and free resources */
1765 loc_cpu_entry = private->entries;
1766 xt_entry_foreach(iter, loc_cpu_entry, private->size)
1767 cleanup_entry(iter, net);
1768 if (private->number > private->initial_entries)
1769 module_put(table_owner);
1770 xt_free_table_info(private);
1773 int ip6t_register_table(struct net *net, const struct xt_table *table,
1774 const struct ip6t_replace *repl,
1775 const struct nf_hook_ops *ops,
1776 struct xt_table **res)
1779 struct xt_table_info *newinfo;
1780 struct xt_table_info bootstrap = {0};
1781 void *loc_cpu_entry;
1782 struct xt_table *new_table;
1784 newinfo = xt_alloc_table_info(repl->size);
1788 loc_cpu_entry = newinfo->entries;
1789 memcpy(loc_cpu_entry, repl->entries, repl->size);
1791 ret = translate_table(net, newinfo, loc_cpu_entry, repl);
1795 new_table = xt_register_table(net, table, &bootstrap, newinfo);
1796 if (IS_ERR(new_table)) {
1797 ret = PTR_ERR(new_table);
1801 /* set res now, will see skbs right after nf_register_net_hooks */
1802 WRITE_ONCE(*res, new_table);
1804 ret = nf_register_net_hooks(net, ops, hweight32(table->valid_hooks));
1806 __ip6t_unregister_table(net, new_table);
1813 xt_free_table_info(newinfo);
1817 void ip6t_unregister_table(struct net *net, struct xt_table *table,
1818 const struct nf_hook_ops *ops)
1820 nf_unregister_net_hooks(net, ops, hweight32(table->valid_hooks));
1821 __ip6t_unregister_table(net, table);
1824 /* Returns 1 if the type and code is matched by the range, 0 otherwise */
1826 icmp6_type_code_match(u_int8_t test_type, u_int8_t min_code, u_int8_t max_code,
1827 u_int8_t type, u_int8_t code,
1830 return (type == test_type && code >= min_code && code <= max_code)
1835 icmp6_match(const struct sk_buff *skb, struct xt_action_param *par)
1837 const struct icmp6hdr *ic;
1838 struct icmp6hdr _icmph;
1839 const struct ip6t_icmp *icmpinfo = par->matchinfo;
1841 /* Must not be a fragment. */
1842 if (par->fragoff != 0)
1845 ic = skb_header_pointer(skb, par->thoff, sizeof(_icmph), &_icmph);
1847 /* We've been asked to examine this packet, and we
1848 * can't. Hence, no choice but to drop.
1850 par->hotdrop = true;
1854 return icmp6_type_code_match(icmpinfo->type,
1857 ic->icmp6_type, ic->icmp6_code,
1858 !!(icmpinfo->invflags&IP6T_ICMP_INV));
1861 /* Called when user tries to insert an entry of this type. */
1862 static int icmp6_checkentry(const struct xt_mtchk_param *par)
1864 const struct ip6t_icmp *icmpinfo = par->matchinfo;
1866 /* Must specify no unknown invflags */
1867 return (icmpinfo->invflags & ~IP6T_ICMP_INV) ? -EINVAL : 0;
1870 /* The built-in targets: standard (NULL) and error. */
1871 static struct xt_target ip6t_builtin_tg[] __read_mostly = {
1873 .name = XT_STANDARD_TARGET,
1874 .targetsize = sizeof(int),
1875 .family = NFPROTO_IPV6,
1876 #ifdef CONFIG_COMPAT
1877 .compatsize = sizeof(compat_int_t),
1878 .compat_from_user = compat_standard_from_user,
1879 .compat_to_user = compat_standard_to_user,
1883 .name = XT_ERROR_TARGET,
1884 .target = ip6t_error,
1885 .targetsize = XT_FUNCTION_MAXNAMELEN,
1886 .family = NFPROTO_IPV6,
1890 static struct nf_sockopt_ops ip6t_sockopts = {
1892 .set_optmin = IP6T_BASE_CTL,
1893 .set_optmax = IP6T_SO_SET_MAX+1,
1894 .set = do_ip6t_set_ctl,
1895 #ifdef CONFIG_COMPAT
1896 .compat_set = compat_do_ip6t_set_ctl,
1898 .get_optmin = IP6T_BASE_CTL,
1899 .get_optmax = IP6T_SO_GET_MAX+1,
1900 .get = do_ip6t_get_ctl,
1901 #ifdef CONFIG_COMPAT
1902 .compat_get = compat_do_ip6t_get_ctl,
1904 .owner = THIS_MODULE,
1907 static struct xt_match ip6t_builtin_mt[] __read_mostly = {
1910 .match = icmp6_match,
1911 .matchsize = sizeof(struct ip6t_icmp),
1912 .checkentry = icmp6_checkentry,
1913 .proto = IPPROTO_ICMPV6,
1914 .family = NFPROTO_IPV6,
1918 static int __net_init ip6_tables_net_init(struct net *net)
1920 return xt_proto_init(net, NFPROTO_IPV6);
1923 static void __net_exit ip6_tables_net_exit(struct net *net)
1925 xt_proto_fini(net, NFPROTO_IPV6);
1928 static struct pernet_operations ip6_tables_net_ops = {
1929 .init = ip6_tables_net_init,
1930 .exit = ip6_tables_net_exit,
1933 static int __init ip6_tables_init(void)
1937 ret = register_pernet_subsys(&ip6_tables_net_ops);
1941 /* No one else will be downing sem now, so we won't sleep */
1942 ret = xt_register_targets(ip6t_builtin_tg, ARRAY_SIZE(ip6t_builtin_tg));
1945 ret = xt_register_matches(ip6t_builtin_mt, ARRAY_SIZE(ip6t_builtin_mt));
1949 /* Register setsockopt */
1950 ret = nf_register_sockopt(&ip6t_sockopts);
1957 xt_unregister_matches(ip6t_builtin_mt, ARRAY_SIZE(ip6t_builtin_mt));
1959 xt_unregister_targets(ip6t_builtin_tg, ARRAY_SIZE(ip6t_builtin_tg));
1961 unregister_pernet_subsys(&ip6_tables_net_ops);
1966 static void __exit ip6_tables_fini(void)
1968 nf_unregister_sockopt(&ip6t_sockopts);
1970 xt_unregister_matches(ip6t_builtin_mt, ARRAY_SIZE(ip6t_builtin_mt));
1971 xt_unregister_targets(ip6t_builtin_tg, ARRAY_SIZE(ip6t_builtin_tg));
1972 unregister_pernet_subsys(&ip6_tables_net_ops);
1975 EXPORT_SYMBOL(ip6t_register_table);
1976 EXPORT_SYMBOL(ip6t_unregister_table);
1977 EXPORT_SYMBOL(ip6t_do_table);
1979 module_init(ip6_tables_init);
1980 module_exit(ip6_tables_fini);