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");
41 MODULE_ALIAS("ip6t_icmp6");
43 void *ip6t_alloc_initial_table(const struct xt_table *info)
45 return xt_alloc_initial_table(ip6t, IP6T);
47 EXPORT_SYMBOL_GPL(ip6t_alloc_initial_table);
49 /* Returns whether matches rule or not. */
50 /* Performance critical - called for every packet */
52 ip6_packet_match(const struct sk_buff *skb,
55 const struct ip6t_ip6 *ip6info,
56 unsigned int *protoff,
57 int *fragoff, bool *hotdrop)
60 const struct ipv6hdr *ipv6 = ipv6_hdr(skb);
62 if (NF_INVF(ip6info, IP6T_INV_SRCIP,
63 ipv6_masked_addr_cmp(&ipv6->saddr, &ip6info->smsk,
65 NF_INVF(ip6info, IP6T_INV_DSTIP,
66 ipv6_masked_addr_cmp(&ipv6->daddr, &ip6info->dmsk,
70 ret = ifname_compare_aligned(indev, ip6info->iniface, ip6info->iniface_mask);
72 if (NF_INVF(ip6info, IP6T_INV_VIA_IN, ret != 0))
75 ret = ifname_compare_aligned(outdev, ip6info->outiface, ip6info->outiface_mask);
77 if (NF_INVF(ip6info, IP6T_INV_VIA_OUT, ret != 0))
80 /* ... might want to do something with class and flowlabel here ... */
82 /* look for the desired protocol header */
83 if (ip6info->flags & IP6T_F_PROTO) {
85 unsigned short _frag_off;
87 protohdr = ipv6_find_hdr(skb, protoff, -1, &_frag_off, NULL);
95 if (ip6info->proto == protohdr) {
96 if (ip6info->invflags & IP6T_INV_PROTO)
102 /* We need match for the '-p all', too! */
103 if ((ip6info->proto != 0) &&
104 !(ip6info->invflags & IP6T_INV_PROTO))
110 /* should be ip6 safe */
112 ip6_checkentry(const struct ip6t_ip6 *ipv6)
114 if (ipv6->flags & ~IP6T_F_MASK)
116 if (ipv6->invflags & ~IP6T_INV_MASK)
123 ip6t_error(struct sk_buff *skb, const struct xt_action_param *par)
125 net_info_ratelimited("error: `%s'\n", (const char *)par->targinfo);
130 static inline struct ip6t_entry *
131 get_entry(const void *base, unsigned int offset)
133 return (struct ip6t_entry *)(base + offset);
136 /* All zeroes == unconditional rule. */
137 /* Mildly perf critical (only if packet tracing is on) */
138 static inline bool unconditional(const struct ip6t_entry *e)
140 static const struct ip6t_ip6 uncond;
142 return e->target_offset == sizeof(struct ip6t_entry) &&
143 memcmp(&e->ipv6, &uncond, sizeof(uncond)) == 0;
146 static inline const struct xt_entry_target *
147 ip6t_get_target_c(const struct ip6t_entry *e)
149 return ip6t_get_target((struct ip6t_entry *)e);
152 #if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
153 /* This cries for unification! */
154 static const char *const hooknames[] = {
155 [NF_INET_PRE_ROUTING] = "PREROUTING",
156 [NF_INET_LOCAL_IN] = "INPUT",
157 [NF_INET_FORWARD] = "FORWARD",
158 [NF_INET_LOCAL_OUT] = "OUTPUT",
159 [NF_INET_POST_ROUTING] = "POSTROUTING",
162 enum nf_ip_trace_comments {
163 NF_IP6_TRACE_COMMENT_RULE,
164 NF_IP6_TRACE_COMMENT_RETURN,
165 NF_IP6_TRACE_COMMENT_POLICY,
168 static const char *const comments[] = {
169 [NF_IP6_TRACE_COMMENT_RULE] = "rule",
170 [NF_IP6_TRACE_COMMENT_RETURN] = "return",
171 [NF_IP6_TRACE_COMMENT_POLICY] = "policy",
174 static const struct nf_loginfo trace_loginfo = {
175 .type = NF_LOG_TYPE_LOG,
178 .level = LOGLEVEL_WARNING,
179 .logflags = NF_LOG_DEFAULT_MASK,
184 /* Mildly perf critical (only if packet tracing is on) */
186 get_chainname_rulenum(const struct ip6t_entry *s, const struct ip6t_entry *e,
187 const char *hookname, const char **chainname,
188 const char **comment, unsigned int *rulenum)
190 const struct xt_standard_target *t = (void *)ip6t_get_target_c(s);
192 if (strcmp(t->target.u.kernel.target->name, XT_ERROR_TARGET) == 0) {
193 /* Head of user chain: ERROR target with chainname */
194 *chainname = t->target.data;
199 if (unconditional(s) &&
200 strcmp(t->target.u.kernel.target->name,
201 XT_STANDARD_TARGET) == 0 &&
203 /* Tail of chains: STANDARD target (return/policy) */
204 *comment = *chainname == hookname
205 ? comments[NF_IP6_TRACE_COMMENT_POLICY]
206 : comments[NF_IP6_TRACE_COMMENT_RETURN];
215 static void trace_packet(struct net *net,
216 const struct sk_buff *skb,
218 const struct net_device *in,
219 const struct net_device *out,
220 const char *tablename,
221 const struct xt_table_info *private,
222 const struct ip6t_entry *e)
224 const struct ip6t_entry *root;
225 const char *hookname, *chainname, *comment;
226 const struct ip6t_entry *iter;
227 unsigned int rulenum = 0;
229 root = get_entry(private->entries, private->hook_entry[hook]);
231 hookname = chainname = hooknames[hook];
232 comment = comments[NF_IP6_TRACE_COMMENT_RULE];
234 xt_entry_foreach(iter, root, private->size - private->hook_entry[hook])
235 if (get_chainname_rulenum(iter, e, hookname,
236 &chainname, &comment, &rulenum) != 0)
239 nf_log_trace(net, AF_INET6, hook, skb, in, out, &trace_loginfo,
240 "TRACE: %s:%s:%s:%u ",
241 tablename, chainname, comment, rulenum);
245 static inline struct ip6t_entry *
246 ip6t_next_entry(const struct ip6t_entry *entry)
248 return (void *)entry + entry->next_offset;
251 /* Returns one of the generic firewall policies, like NF_ACCEPT. */
253 ip6t_do_table(struct sk_buff *skb,
254 const struct nf_hook_state *state,
255 struct xt_table *table)
257 unsigned int hook = state->hook;
258 static const char nulldevname[IFNAMSIZ] __attribute__((aligned(sizeof(long))));
259 /* Initializing verdict to NF_DROP keeps gcc happy. */
260 unsigned int verdict = NF_DROP;
261 const char *indev, *outdev;
262 const void *table_base;
263 struct ip6t_entry *e, **jumpstack;
264 unsigned int stackidx, cpu;
265 const struct xt_table_info *private;
266 struct xt_action_param acpar;
271 indev = state->in ? state->in->name : nulldevname;
272 outdev = state->out ? state->out->name : nulldevname;
273 /* We handle fragments by dealing with the first fragment as
274 * if it was a normal packet. All other fragments are treated
275 * normally, except that they will NEVER match rules that ask
276 * things we don't know, ie. tcp syn flag or ports). If the
277 * rule is also a fragment-specific rule, non-fragments won't
279 acpar.hotdrop = false;
282 WARN_ON(!(table->valid_hooks & (1 << hook)));
285 addend = xt_write_recseq_begin();
286 private = READ_ONCE(table->private); /* Address dependency. */
287 cpu = smp_processor_id();
288 table_base = private->entries;
289 jumpstack = (struct ip6t_entry **)private->jumpstack[cpu];
291 /* Switch to alternate jumpstack if we're being invoked via TEE.
292 * TEE issues XT_CONTINUE verdict on original skb so we must not
293 * clobber the jumpstack.
295 * For recursion via REJECT or SYNPROXY the stack will be clobbered
296 * but it is no problem since absolute verdict is issued by these.
298 if (static_key_false(&xt_tee_enabled))
299 jumpstack += private->stacksize * __this_cpu_read(nf_skb_duplicated);
301 e = get_entry(table_base, private->hook_entry[hook]);
304 const struct xt_entry_target *t;
305 const struct xt_entry_match *ematch;
306 struct xt_counters *counter;
310 if (!ip6_packet_match(skb, indev, outdev, &e->ipv6,
311 &acpar.thoff, &acpar.fragoff, &acpar.hotdrop)) {
313 e = ip6t_next_entry(e);
317 xt_ematch_foreach(ematch, e) {
318 acpar.match = ematch->u.kernel.match;
319 acpar.matchinfo = ematch->data;
320 if (!acpar.match->match(skb, &acpar))
324 counter = xt_get_this_cpu_counter(&e->counters);
325 ADD_COUNTER(*counter, skb->len, 1);
327 t = ip6t_get_target_c(e);
328 WARN_ON(!t->u.kernel.target);
330 #if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
331 /* The packet is traced: log it */
332 if (unlikely(skb->nf_trace))
333 trace_packet(state->net, skb, hook, state->in,
334 state->out, table->name, private, e);
336 /* Standard target? */
337 if (!t->u.kernel.target->target) {
340 v = ((struct xt_standard_target *)t)->verdict;
342 /* Pop from stack? */
343 if (v != XT_RETURN) {
344 verdict = (unsigned int)(-v) - 1;
348 e = get_entry(table_base,
349 private->underflow[hook]);
351 e = ip6t_next_entry(jumpstack[--stackidx]);
354 if (table_base + v != ip6t_next_entry(e) &&
355 !(e->ipv6.flags & IP6T_F_GOTO)) {
356 if (unlikely(stackidx >= private->stacksize)) {
360 jumpstack[stackidx++] = e;
363 e = get_entry(table_base, v);
367 acpar.target = t->u.kernel.target;
368 acpar.targinfo = t->data;
370 verdict = t->u.kernel.target->target(skb, &acpar);
371 if (verdict == XT_CONTINUE)
372 e = ip6t_next_entry(e);
376 } while (!acpar.hotdrop);
378 xt_write_recseq_end(addend);
386 /* Figures out from what hook each rule can be called: returns 0 if
387 there are loops. Puts hook bitmask in comefrom. */
389 mark_source_chains(const struct xt_table_info *newinfo,
390 unsigned int valid_hooks, void *entry0,
391 unsigned int *offsets)
395 /* No recursion; use packet counter to save back ptrs (reset
396 to 0 as we leave), and comefrom to save source hook bitmask */
397 for (hook = 0; hook < NF_INET_NUMHOOKS; hook++) {
398 unsigned int pos = newinfo->hook_entry[hook];
399 struct ip6t_entry *e = entry0 + pos;
401 if (!(valid_hooks & (1 << hook)))
404 /* Set initial back pointer. */
405 e->counters.pcnt = pos;
408 const struct xt_standard_target *t
409 = (void *)ip6t_get_target_c(e);
410 int visited = e->comefrom & (1 << hook);
412 if (e->comefrom & (1 << NF_INET_NUMHOOKS))
415 e->comefrom |= ((1 << hook) | (1 << NF_INET_NUMHOOKS));
417 /* Unconditional return/END. */
418 if ((unconditional(e) &&
419 (strcmp(t->target.u.user.name,
420 XT_STANDARD_TARGET) == 0) &&
421 t->verdict < 0) || visited) {
422 unsigned int oldpos, size;
424 /* Return: backtrack through the last
427 e->comefrom ^= (1<<NF_INET_NUMHOOKS);
429 pos = e->counters.pcnt;
430 e->counters.pcnt = 0;
432 /* We're at the start. */
437 } while (oldpos == pos + e->next_offset);
440 size = e->next_offset;
441 e = entry0 + pos + size;
442 if (pos + size >= newinfo->size)
444 e->counters.pcnt = pos;
447 int newpos = t->verdict;
449 if (strcmp(t->target.u.user.name,
450 XT_STANDARD_TARGET) == 0 &&
452 /* This a jump; chase it. */
453 if (!xt_find_jump_offset(offsets, newpos,
457 /* ... this is a fallthru */
458 newpos = pos + e->next_offset;
459 if (newpos >= newinfo->size)
463 e->counters.pcnt = pos;
472 static void cleanup_match(struct xt_entry_match *m, struct net *net)
474 struct xt_mtdtor_param par;
477 par.match = m->u.kernel.match;
478 par.matchinfo = m->data;
479 par.family = NFPROTO_IPV6;
480 if (par.match->destroy != NULL)
481 par.match->destroy(&par);
482 module_put(par.match->me);
485 static int check_match(struct xt_entry_match *m, struct xt_mtchk_param *par)
487 const struct ip6t_ip6 *ipv6 = par->entryinfo;
489 par->match = m->u.kernel.match;
490 par->matchinfo = m->data;
492 return xt_check_match(par, m->u.match_size - sizeof(*m),
493 ipv6->proto, ipv6->invflags & IP6T_INV_PROTO);
497 find_check_match(struct xt_entry_match *m, struct xt_mtchk_param *par)
499 struct xt_match *match;
502 match = xt_request_find_match(NFPROTO_IPV6, m->u.user.name,
505 return PTR_ERR(match);
507 m->u.kernel.match = match;
509 ret = check_match(m, par);
515 module_put(m->u.kernel.match->me);
519 static int check_target(struct ip6t_entry *e, struct net *net, const char *name)
521 struct xt_entry_target *t = ip6t_get_target(e);
522 struct xt_tgchk_param par = {
526 .target = t->u.kernel.target,
528 .hook_mask = e->comefrom,
529 .family = NFPROTO_IPV6,
532 return xt_check_target(&par, t->u.target_size - sizeof(*t),
534 e->ipv6.invflags & IP6T_INV_PROTO);
538 find_check_entry(struct ip6t_entry *e, struct net *net, const char *name,
540 struct xt_percpu_counter_alloc_state *alloc_state)
542 struct xt_entry_target *t;
543 struct xt_target *target;
546 struct xt_mtchk_param mtpar;
547 struct xt_entry_match *ematch;
549 if (!xt_percpu_counter_alloc(alloc_state, &e->counters))
553 memset(&mtpar, 0, sizeof(mtpar));
556 mtpar.entryinfo = &e->ipv6;
557 mtpar.hook_mask = e->comefrom;
558 mtpar.family = NFPROTO_IPV6;
559 xt_ematch_foreach(ematch, e) {
560 ret = find_check_match(ematch, &mtpar);
562 goto cleanup_matches;
566 t = ip6t_get_target(e);
567 target = xt_request_find_target(NFPROTO_IPV6, t->u.user.name,
569 if (IS_ERR(target)) {
570 ret = PTR_ERR(target);
571 goto cleanup_matches;
573 t->u.kernel.target = target;
575 ret = check_target(e, net, name);
580 module_put(t->u.kernel.target->me);
582 xt_ematch_foreach(ematch, e) {
585 cleanup_match(ematch, net);
588 xt_percpu_counter_free(&e->counters);
593 static bool check_underflow(const struct ip6t_entry *e)
595 const struct xt_entry_target *t;
596 unsigned int verdict;
598 if (!unconditional(e))
600 t = ip6t_get_target_c(e);
601 if (strcmp(t->u.user.name, XT_STANDARD_TARGET) != 0)
603 verdict = ((struct xt_standard_target *)t)->verdict;
604 verdict = -verdict - 1;
605 return verdict == NF_DROP || verdict == NF_ACCEPT;
609 check_entry_size_and_hooks(struct ip6t_entry *e,
610 struct xt_table_info *newinfo,
611 const unsigned char *base,
612 const unsigned char *limit,
613 const unsigned int *hook_entries,
614 const unsigned int *underflows,
615 unsigned int valid_hooks)
620 if ((unsigned long)e % __alignof__(struct ip6t_entry) != 0 ||
621 (unsigned char *)e + sizeof(struct ip6t_entry) >= limit ||
622 (unsigned char *)e + e->next_offset > limit)
626 < sizeof(struct ip6t_entry) + sizeof(struct xt_entry_target))
629 if (!ip6_checkentry(&e->ipv6))
632 err = xt_check_entry_offsets(e, e->elems, e->target_offset,
637 /* Check hooks & underflows */
638 for (h = 0; h < NF_INET_NUMHOOKS; h++) {
639 if (!(valid_hooks & (1 << h)))
641 if ((unsigned char *)e - base == hook_entries[h])
642 newinfo->hook_entry[h] = hook_entries[h];
643 if ((unsigned char *)e - base == underflows[h]) {
644 if (!check_underflow(e))
647 newinfo->underflow[h] = underflows[h];
651 /* Clear counters and comefrom */
652 e->counters = ((struct xt_counters) { 0, 0 });
657 static void cleanup_entry(struct ip6t_entry *e, struct net *net)
659 struct xt_tgdtor_param par;
660 struct xt_entry_target *t;
661 struct xt_entry_match *ematch;
663 /* Cleanup all matches */
664 xt_ematch_foreach(ematch, e)
665 cleanup_match(ematch, net);
666 t = ip6t_get_target(e);
669 par.target = t->u.kernel.target;
670 par.targinfo = t->data;
671 par.family = NFPROTO_IPV6;
672 if (par.target->destroy != NULL)
673 par.target->destroy(&par);
674 module_put(par.target->me);
675 xt_percpu_counter_free(&e->counters);
678 /* Checks and translates the user-supplied table segment (held in
681 translate_table(struct net *net, struct xt_table_info *newinfo, void *entry0,
682 const struct ip6t_replace *repl)
684 struct xt_percpu_counter_alloc_state alloc_state = { 0 };
685 struct ip6t_entry *iter;
686 unsigned int *offsets;
690 newinfo->size = repl->size;
691 newinfo->number = repl->num_entries;
693 /* Init all hooks to impossible value. */
694 for (i = 0; i < NF_INET_NUMHOOKS; i++) {
695 newinfo->hook_entry[i] = 0xFFFFFFFF;
696 newinfo->underflow[i] = 0xFFFFFFFF;
699 offsets = xt_alloc_entry_offsets(newinfo->number);
703 /* Walk through entries, checking offsets. */
704 xt_entry_foreach(iter, entry0, newinfo->size) {
705 ret = check_entry_size_and_hooks(iter, newinfo, entry0,
712 if (i < repl->num_entries)
713 offsets[i] = (void *)iter - entry0;
715 if (strcmp(ip6t_get_target(iter)->u.user.name,
716 XT_ERROR_TARGET) == 0)
717 ++newinfo->stacksize;
721 if (i != repl->num_entries)
724 ret = xt_check_table_hooks(newinfo, repl->valid_hooks);
728 if (!mark_source_chains(newinfo, repl->valid_hooks, entry0, offsets)) {
734 /* Finally, each sanity check must pass */
736 xt_entry_foreach(iter, entry0, newinfo->size) {
737 ret = find_check_entry(iter, net, repl->name, repl->size,
745 xt_entry_foreach(iter, entry0, newinfo->size) {
748 cleanup_entry(iter, net);
760 get_counters(const struct xt_table_info *t,
761 struct xt_counters counters[])
763 struct ip6t_entry *iter;
767 for_each_possible_cpu(cpu) {
768 seqcount_t *s = &per_cpu(xt_recseq, cpu);
771 xt_entry_foreach(iter, t->entries, t->size) {
772 struct xt_counters *tmp;
776 tmp = xt_get_per_cpu_counter(&iter->counters, cpu);
778 start = read_seqcount_begin(s);
781 } while (read_seqcount_retry(s, start));
783 ADD_COUNTER(counters[i], bcnt, pcnt);
790 static void get_old_counters(const struct xt_table_info *t,
791 struct xt_counters counters[])
793 struct ip6t_entry *iter;
796 for_each_possible_cpu(cpu) {
798 xt_entry_foreach(iter, t->entries, t->size) {
799 const struct xt_counters *tmp;
801 tmp = xt_get_per_cpu_counter(&iter->counters, cpu);
802 ADD_COUNTER(counters[i], tmp->bcnt, tmp->pcnt);
809 static struct xt_counters *alloc_counters(const struct xt_table *table)
811 unsigned int countersize;
812 struct xt_counters *counters;
813 const struct xt_table_info *private = table->private;
815 /* We need atomic snapshot of counters: rest doesn't change
816 (other than comefrom, which userspace doesn't care
818 countersize = sizeof(struct xt_counters) * private->number;
819 counters = vzalloc(countersize);
821 if (counters == NULL)
822 return ERR_PTR(-ENOMEM);
824 get_counters(private, counters);
830 copy_entries_to_user(unsigned int total_size,
831 const struct xt_table *table,
832 void __user *userptr)
834 unsigned int off, num;
835 const struct ip6t_entry *e;
836 struct xt_counters *counters;
837 const struct xt_table_info *private = table->private;
839 const void *loc_cpu_entry;
841 counters = alloc_counters(table);
842 if (IS_ERR(counters))
843 return PTR_ERR(counters);
845 loc_cpu_entry = private->entries;
847 /* FIXME: use iterator macros --RR */
848 /* ... then go back and fix counters and names */
849 for (off = 0, num = 0; off < total_size; off += e->next_offset, num++){
851 const struct xt_entry_match *m;
852 const struct xt_entry_target *t;
854 e = loc_cpu_entry + off;
855 if (copy_to_user(userptr + off, e, sizeof(*e))) {
859 if (copy_to_user(userptr + off
860 + offsetof(struct ip6t_entry, counters),
862 sizeof(counters[num])) != 0) {
867 for (i = sizeof(struct ip6t_entry);
868 i < e->target_offset;
869 i += m->u.match_size) {
872 if (xt_match_to_user(m, userptr + off + i)) {
878 t = ip6t_get_target_c(e);
879 if (xt_target_to_user(t, userptr + off + e->target_offset)) {
891 static void compat_standard_from_user(void *dst, const void *src)
893 int v = *(compat_int_t *)src;
896 v += xt_compat_calc_jump(AF_INET6, v);
897 memcpy(dst, &v, sizeof(v));
900 static int compat_standard_to_user(void __user *dst, const void *src)
902 compat_int_t cv = *(int *)src;
905 cv -= xt_compat_calc_jump(AF_INET6, cv);
906 return copy_to_user(dst, &cv, sizeof(cv)) ? -EFAULT : 0;
909 static int compat_calc_entry(const struct ip6t_entry *e,
910 const struct xt_table_info *info,
911 const void *base, struct xt_table_info *newinfo)
913 const struct xt_entry_match *ematch;
914 const struct xt_entry_target *t;
915 unsigned int entry_offset;
918 off = sizeof(struct ip6t_entry) - sizeof(struct compat_ip6t_entry);
919 entry_offset = (void *)e - base;
920 xt_ematch_foreach(ematch, e)
921 off += xt_compat_match_offset(ematch->u.kernel.match);
922 t = ip6t_get_target_c(e);
923 off += xt_compat_target_offset(t->u.kernel.target);
924 newinfo->size -= off;
925 ret = xt_compat_add_offset(AF_INET6, entry_offset, off);
929 for (i = 0; i < NF_INET_NUMHOOKS; i++) {
930 if (info->hook_entry[i] &&
931 (e < (struct ip6t_entry *)(base + info->hook_entry[i])))
932 newinfo->hook_entry[i] -= off;
933 if (info->underflow[i] &&
934 (e < (struct ip6t_entry *)(base + info->underflow[i])))
935 newinfo->underflow[i] -= off;
940 static int compat_table_info(const struct xt_table_info *info,
941 struct xt_table_info *newinfo)
943 struct ip6t_entry *iter;
944 const void *loc_cpu_entry;
947 if (!newinfo || !info)
950 /* we dont care about newinfo->entries */
951 memcpy(newinfo, info, offsetof(struct xt_table_info, entries));
952 newinfo->initial_entries = 0;
953 loc_cpu_entry = info->entries;
954 ret = xt_compat_init_offsets(AF_INET6, info->number);
957 xt_entry_foreach(iter, loc_cpu_entry, info->size) {
958 ret = compat_calc_entry(iter, info, loc_cpu_entry, newinfo);
966 static int get_info(struct net *net, void __user *user,
967 const int *len, int compat)
969 char name[XT_TABLE_MAXNAMELEN];
973 if (*len != sizeof(struct ip6t_getinfo))
976 if (copy_from_user(name, user, sizeof(name)) != 0)
979 name[XT_TABLE_MAXNAMELEN-1] = '\0';
982 xt_compat_lock(AF_INET6);
984 t = xt_request_find_table_lock(net, AF_INET6, name);
986 struct ip6t_getinfo info;
987 const struct xt_table_info *private = t->private;
989 struct xt_table_info tmp;
992 ret = compat_table_info(private, &tmp);
993 xt_compat_flush_offsets(AF_INET6);
997 memset(&info, 0, sizeof(info));
998 info.valid_hooks = t->valid_hooks;
999 memcpy(info.hook_entry, private->hook_entry,
1000 sizeof(info.hook_entry));
1001 memcpy(info.underflow, private->underflow,
1002 sizeof(info.underflow));
1003 info.num_entries = private->number;
1004 info.size = private->size;
1005 strcpy(info.name, name);
1007 if (copy_to_user(user, &info, *len) != 0)
1016 #ifdef CONFIG_COMPAT
1018 xt_compat_unlock(AF_INET6);
1024 get_entries(struct net *net, struct ip6t_get_entries __user *uptr,
1028 struct ip6t_get_entries get;
1031 if (*len < sizeof(get))
1033 if (copy_from_user(&get, uptr, sizeof(get)) != 0)
1035 if (*len != sizeof(struct ip6t_get_entries) + get.size)
1038 get.name[sizeof(get.name) - 1] = '\0';
1040 t = xt_find_table_lock(net, AF_INET6, get.name);
1042 struct xt_table_info *private = t->private;
1043 if (get.size == private->size)
1044 ret = copy_entries_to_user(private->size,
1045 t, uptr->entrytable);
1058 __do_replace(struct net *net, const char *name, unsigned int valid_hooks,
1059 struct xt_table_info *newinfo, unsigned int num_counters,
1060 void __user *counters_ptr)
1064 struct xt_table_info *oldinfo;
1065 struct xt_counters *counters;
1066 struct ip6t_entry *iter;
1069 counters = xt_counters_alloc(num_counters);
1075 t = xt_request_find_table_lock(net, AF_INET6, name);
1078 goto free_newinfo_counters_untrans;
1082 if (valid_hooks != t->valid_hooks) {
1087 oldinfo = xt_replace_table(t, num_counters, newinfo, &ret);
1091 /* Update module usage count based on number of rules */
1092 if ((oldinfo->number > oldinfo->initial_entries) ||
1093 (newinfo->number <= oldinfo->initial_entries))
1095 if ((oldinfo->number > oldinfo->initial_entries) &&
1096 (newinfo->number <= oldinfo->initial_entries))
1101 get_old_counters(oldinfo, counters);
1103 /* Decrease module usage counts and free resource */
1104 xt_entry_foreach(iter, oldinfo->entries, oldinfo->size)
1105 cleanup_entry(iter, net);
1107 xt_free_table_info(oldinfo);
1108 if (copy_to_user(counters_ptr, counters,
1109 sizeof(struct xt_counters) * num_counters) != 0) {
1110 /* Silent error, can't fail, new table is already in place */
1111 net_warn_ratelimited("ip6tables: counters copy to user failed while replacing table\n");
1119 free_newinfo_counters_untrans:
1126 do_replace(struct net *net, const void __user *user, unsigned int len)
1129 struct ip6t_replace tmp;
1130 struct xt_table_info *newinfo;
1131 void *loc_cpu_entry;
1132 struct ip6t_entry *iter;
1134 if (copy_from_user(&tmp, user, sizeof(tmp)) != 0)
1137 /* overflow check */
1138 if (tmp.num_counters >= INT_MAX / sizeof(struct xt_counters))
1140 if (tmp.num_counters == 0)
1143 tmp.name[sizeof(tmp.name)-1] = 0;
1145 newinfo = xt_alloc_table_info(tmp.size);
1149 loc_cpu_entry = newinfo->entries;
1150 if (copy_from_user(loc_cpu_entry, user + sizeof(tmp),
1156 ret = translate_table(net, newinfo, loc_cpu_entry, &tmp);
1160 ret = __do_replace(net, tmp.name, tmp.valid_hooks, newinfo,
1161 tmp.num_counters, tmp.counters);
1163 goto free_newinfo_untrans;
1166 free_newinfo_untrans:
1167 xt_entry_foreach(iter, loc_cpu_entry, newinfo->size)
1168 cleanup_entry(iter, net);
1170 xt_free_table_info(newinfo);
1175 do_add_counters(struct net *net, const void __user *user, unsigned int len,
1179 struct xt_counters_info tmp;
1180 struct xt_counters *paddc;
1182 const struct xt_table_info *private;
1184 struct ip6t_entry *iter;
1185 unsigned int addend;
1187 paddc = xt_copy_counters_from_user(user, len, &tmp, compat);
1189 return PTR_ERR(paddc);
1190 t = xt_find_table_lock(net, AF_INET6, tmp.name);
1197 private = t->private;
1198 if (private->number != tmp.num_counters) {
1200 goto unlock_up_free;
1204 addend = xt_write_recseq_begin();
1205 xt_entry_foreach(iter, private->entries, private->size) {
1206 struct xt_counters *tmp;
1208 tmp = xt_get_this_cpu_counter(&iter->counters);
1209 ADD_COUNTER(*tmp, paddc[i].bcnt, paddc[i].pcnt);
1212 xt_write_recseq_end(addend);
1223 #ifdef CONFIG_COMPAT
1224 struct compat_ip6t_replace {
1225 char name[XT_TABLE_MAXNAMELEN];
1229 u32 hook_entry[NF_INET_NUMHOOKS];
1230 u32 underflow[NF_INET_NUMHOOKS];
1232 compat_uptr_t counters; /* struct xt_counters * */
1233 struct compat_ip6t_entry entries[0];
1237 compat_copy_entry_to_user(struct ip6t_entry *e, void __user **dstptr,
1238 unsigned int *size, struct xt_counters *counters,
1241 struct xt_entry_target *t;
1242 struct compat_ip6t_entry __user *ce;
1243 u_int16_t target_offset, next_offset;
1244 compat_uint_t origsize;
1245 const struct xt_entry_match *ematch;
1250 if (copy_to_user(ce, e, sizeof(struct ip6t_entry)) != 0 ||
1251 copy_to_user(&ce->counters, &counters[i],
1252 sizeof(counters[i])) != 0)
1255 *dstptr += sizeof(struct compat_ip6t_entry);
1256 *size -= sizeof(struct ip6t_entry) - sizeof(struct compat_ip6t_entry);
1258 xt_ematch_foreach(ematch, e) {
1259 ret = xt_compat_match_to_user(ematch, dstptr, size);
1263 target_offset = e->target_offset - (origsize - *size);
1264 t = ip6t_get_target(e);
1265 ret = xt_compat_target_to_user(t, dstptr, size);
1268 next_offset = e->next_offset - (origsize - *size);
1269 if (put_user(target_offset, &ce->target_offset) != 0 ||
1270 put_user(next_offset, &ce->next_offset) != 0)
1276 compat_find_calc_match(struct xt_entry_match *m,
1277 const struct ip6t_ip6 *ipv6,
1280 struct xt_match *match;
1282 match = xt_request_find_match(NFPROTO_IPV6, m->u.user.name,
1283 m->u.user.revision);
1285 return PTR_ERR(match);
1287 m->u.kernel.match = match;
1288 *size += xt_compat_match_offset(match);
1292 static void compat_release_entry(struct compat_ip6t_entry *e)
1294 struct xt_entry_target *t;
1295 struct xt_entry_match *ematch;
1297 /* Cleanup all matches */
1298 xt_ematch_foreach(ematch, e)
1299 module_put(ematch->u.kernel.match->me);
1300 t = compat_ip6t_get_target(e);
1301 module_put(t->u.kernel.target->me);
1305 check_compat_entry_size_and_hooks(struct compat_ip6t_entry *e,
1306 struct xt_table_info *newinfo,
1308 const unsigned char *base,
1309 const unsigned char *limit)
1311 struct xt_entry_match *ematch;
1312 struct xt_entry_target *t;
1313 struct xt_target *target;
1314 unsigned int entry_offset;
1318 if ((unsigned long)e % __alignof__(struct compat_ip6t_entry) != 0 ||
1319 (unsigned char *)e + sizeof(struct compat_ip6t_entry) >= limit ||
1320 (unsigned char *)e + e->next_offset > limit)
1323 if (e->next_offset < sizeof(struct compat_ip6t_entry) +
1324 sizeof(struct compat_xt_entry_target))
1327 if (!ip6_checkentry(&e->ipv6))
1330 ret = xt_compat_check_entry_offsets(e, e->elems,
1331 e->target_offset, e->next_offset);
1335 off = sizeof(struct ip6t_entry) - sizeof(struct compat_ip6t_entry);
1336 entry_offset = (void *)e - (void *)base;
1338 xt_ematch_foreach(ematch, e) {
1339 ret = compat_find_calc_match(ematch, &e->ipv6, &off);
1341 goto release_matches;
1345 t = compat_ip6t_get_target(e);
1346 target = xt_request_find_target(NFPROTO_IPV6, t->u.user.name,
1347 t->u.user.revision);
1348 if (IS_ERR(target)) {
1349 ret = PTR_ERR(target);
1350 goto release_matches;
1352 t->u.kernel.target = target;
1354 off += xt_compat_target_offset(target);
1356 ret = xt_compat_add_offset(AF_INET6, entry_offset, off);
1363 module_put(t->u.kernel.target->me);
1365 xt_ematch_foreach(ematch, e) {
1368 module_put(ematch->u.kernel.match->me);
1374 compat_copy_entry_from_user(struct compat_ip6t_entry *e, void **dstptr,
1376 struct xt_table_info *newinfo, unsigned char *base)
1378 struct xt_entry_target *t;
1379 struct ip6t_entry *de;
1380 unsigned int origsize;
1382 struct xt_entry_match *ematch;
1386 memcpy(de, e, sizeof(struct ip6t_entry));
1387 memcpy(&de->counters, &e->counters, sizeof(e->counters));
1389 *dstptr += sizeof(struct ip6t_entry);
1390 *size += sizeof(struct ip6t_entry) - sizeof(struct compat_ip6t_entry);
1392 xt_ematch_foreach(ematch, e)
1393 xt_compat_match_from_user(ematch, dstptr, size);
1395 de->target_offset = e->target_offset - (origsize - *size);
1396 t = compat_ip6t_get_target(e);
1397 xt_compat_target_from_user(t, dstptr, size);
1399 de->next_offset = e->next_offset - (origsize - *size);
1400 for (h = 0; h < NF_INET_NUMHOOKS; h++) {
1401 if ((unsigned char *)de - base < newinfo->hook_entry[h])
1402 newinfo->hook_entry[h] -= origsize - *size;
1403 if ((unsigned char *)de - base < newinfo->underflow[h])
1404 newinfo->underflow[h] -= origsize - *size;
1409 translate_compat_table(struct net *net,
1410 struct xt_table_info **pinfo,
1412 const struct compat_ip6t_replace *compatr)
1415 struct xt_table_info *newinfo, *info;
1416 void *pos, *entry0, *entry1;
1417 struct compat_ip6t_entry *iter0;
1418 struct ip6t_replace repl;
1424 size = compatr->size;
1425 info->number = compatr->num_entries;
1428 xt_compat_lock(AF_INET6);
1429 ret = xt_compat_init_offsets(AF_INET6, compatr->num_entries);
1432 /* Walk through entries, checking offsets. */
1433 xt_entry_foreach(iter0, entry0, compatr->size) {
1434 ret = check_compat_entry_size_and_hooks(iter0, info, &size,
1436 entry0 + compatr->size);
1443 if (j != compatr->num_entries)
1447 newinfo = xt_alloc_table_info(size);
1451 newinfo->number = compatr->num_entries;
1452 for (i = 0; i < NF_INET_NUMHOOKS; i++) {
1453 newinfo->hook_entry[i] = compatr->hook_entry[i];
1454 newinfo->underflow[i] = compatr->underflow[i];
1456 entry1 = newinfo->entries;
1458 size = compatr->size;
1459 xt_entry_foreach(iter0, entry0, compatr->size)
1460 compat_copy_entry_from_user(iter0, &pos, &size,
1463 /* all module references in entry0 are now gone. */
1464 xt_compat_flush_offsets(AF_INET6);
1465 xt_compat_unlock(AF_INET6);
1467 memcpy(&repl, compatr, sizeof(*compatr));
1469 for (i = 0; i < NF_INET_NUMHOOKS; i++) {
1470 repl.hook_entry[i] = newinfo->hook_entry[i];
1471 repl.underflow[i] = newinfo->underflow[i];
1474 repl.num_counters = 0;
1475 repl.counters = NULL;
1476 repl.size = newinfo->size;
1477 ret = translate_table(net, newinfo, entry1, &repl);
1483 xt_free_table_info(info);
1487 xt_free_table_info(newinfo);
1490 xt_compat_flush_offsets(AF_INET6);
1491 xt_compat_unlock(AF_INET6);
1492 xt_entry_foreach(iter0, entry0, compatr->size) {
1495 compat_release_entry(iter0);
1501 compat_do_replace(struct net *net, void __user *user, unsigned int len)
1504 struct compat_ip6t_replace tmp;
1505 struct xt_table_info *newinfo;
1506 void *loc_cpu_entry;
1507 struct ip6t_entry *iter;
1509 if (copy_from_user(&tmp, user, sizeof(tmp)) != 0)
1512 /* overflow check */
1513 if (tmp.num_counters >= INT_MAX / sizeof(struct xt_counters))
1515 if (tmp.num_counters == 0)
1518 tmp.name[sizeof(tmp.name)-1] = 0;
1520 newinfo = xt_alloc_table_info(tmp.size);
1524 loc_cpu_entry = newinfo->entries;
1525 if (copy_from_user(loc_cpu_entry, user + sizeof(tmp),
1531 ret = translate_compat_table(net, &newinfo, &loc_cpu_entry, &tmp);
1535 ret = __do_replace(net, tmp.name, tmp.valid_hooks, newinfo,
1536 tmp.num_counters, compat_ptr(tmp.counters));
1538 goto free_newinfo_untrans;
1541 free_newinfo_untrans:
1542 xt_entry_foreach(iter, loc_cpu_entry, newinfo->size)
1543 cleanup_entry(iter, net);
1545 xt_free_table_info(newinfo);
1550 compat_do_ip6t_set_ctl(struct sock *sk, int cmd, void __user *user,
1555 if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN))
1559 case IP6T_SO_SET_REPLACE:
1560 ret = compat_do_replace(sock_net(sk), user, len);
1563 case IP6T_SO_SET_ADD_COUNTERS:
1564 ret = do_add_counters(sock_net(sk), user, len, 1);
1574 struct compat_ip6t_get_entries {
1575 char name[XT_TABLE_MAXNAMELEN];
1577 struct compat_ip6t_entry entrytable[0];
1581 compat_copy_entries_to_user(unsigned int total_size, struct xt_table *table,
1582 void __user *userptr)
1584 struct xt_counters *counters;
1585 const struct xt_table_info *private = table->private;
1590 struct ip6t_entry *iter;
1592 counters = alloc_counters(table);
1593 if (IS_ERR(counters))
1594 return PTR_ERR(counters);
1598 xt_entry_foreach(iter, private->entries, total_size) {
1599 ret = compat_copy_entry_to_user(iter, &pos,
1600 &size, counters, i++);
1610 compat_get_entries(struct net *net, struct compat_ip6t_get_entries __user *uptr,
1614 struct compat_ip6t_get_entries get;
1617 if (*len < sizeof(get))
1620 if (copy_from_user(&get, uptr, sizeof(get)) != 0)
1623 if (*len != sizeof(struct compat_ip6t_get_entries) + get.size)
1626 get.name[sizeof(get.name) - 1] = '\0';
1628 xt_compat_lock(AF_INET6);
1629 t = xt_find_table_lock(net, AF_INET6, get.name);
1631 const struct xt_table_info *private = t->private;
1632 struct xt_table_info info;
1633 ret = compat_table_info(private, &info);
1634 if (!ret && get.size == info.size)
1635 ret = compat_copy_entries_to_user(private->size,
1636 t, uptr->entrytable);
1640 xt_compat_flush_offsets(AF_INET6);
1646 xt_compat_unlock(AF_INET6);
1650 static int do_ip6t_get_ctl(struct sock *, int, void __user *, int *);
1653 compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
1657 if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN))
1661 case IP6T_SO_GET_INFO:
1662 ret = get_info(sock_net(sk), user, len, 1);
1664 case IP6T_SO_GET_ENTRIES:
1665 ret = compat_get_entries(sock_net(sk), user, len);
1668 ret = do_ip6t_get_ctl(sk, cmd, user, len);
1675 do_ip6t_set_ctl(struct sock *sk, int cmd, void __user *user, unsigned int len)
1679 if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN))
1683 case IP6T_SO_SET_REPLACE:
1684 ret = do_replace(sock_net(sk), user, len);
1687 case IP6T_SO_SET_ADD_COUNTERS:
1688 ret = do_add_counters(sock_net(sk), user, len, 0);
1699 do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
1703 if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN))
1707 case IP6T_SO_GET_INFO:
1708 ret = get_info(sock_net(sk), user, len, 0);
1711 case IP6T_SO_GET_ENTRIES:
1712 ret = get_entries(sock_net(sk), user, len);
1715 case IP6T_SO_GET_REVISION_MATCH:
1716 case IP6T_SO_GET_REVISION_TARGET: {
1717 struct xt_get_revision rev;
1720 if (*len != sizeof(rev)) {
1724 if (copy_from_user(&rev, user, sizeof(rev)) != 0) {
1728 rev.name[sizeof(rev.name)-1] = 0;
1730 if (cmd == IP6T_SO_GET_REVISION_TARGET)
1735 try_then_request_module(xt_find_revision(AF_INET6, rev.name,
1738 "ip6t_%s", rev.name);
1749 static void __ip6t_unregister_table(struct net *net, struct xt_table *table)
1751 struct xt_table_info *private;
1752 void *loc_cpu_entry;
1753 struct module *table_owner = table->me;
1754 struct ip6t_entry *iter;
1756 private = xt_unregister_table(table);
1758 /* Decrease module usage counts and free resources */
1759 loc_cpu_entry = private->entries;
1760 xt_entry_foreach(iter, loc_cpu_entry, private->size)
1761 cleanup_entry(iter, net);
1762 if (private->number > private->initial_entries)
1763 module_put(table_owner);
1764 xt_free_table_info(private);
1767 int ip6t_register_table(struct net *net, const struct xt_table *table,
1768 const struct ip6t_replace *repl,
1769 const struct nf_hook_ops *ops,
1770 struct xt_table **res)
1773 struct xt_table_info *newinfo;
1774 struct xt_table_info bootstrap = {0};
1775 void *loc_cpu_entry;
1776 struct xt_table *new_table;
1778 newinfo = xt_alloc_table_info(repl->size);
1782 loc_cpu_entry = newinfo->entries;
1783 memcpy(loc_cpu_entry, repl->entries, repl->size);
1785 ret = translate_table(net, newinfo, loc_cpu_entry, repl);
1789 new_table = xt_register_table(net, table, &bootstrap, newinfo);
1790 if (IS_ERR(new_table)) {
1791 ret = PTR_ERR(new_table);
1795 /* set res now, will see skbs right after nf_register_net_hooks */
1796 WRITE_ONCE(*res, new_table);
1800 ret = nf_register_net_hooks(net, ops, hweight32(table->valid_hooks));
1802 __ip6t_unregister_table(net, new_table);
1809 xt_free_table_info(newinfo);
1813 void ip6t_unregister_table(struct net *net, struct xt_table *table,
1814 const struct nf_hook_ops *ops)
1817 nf_unregister_net_hooks(net, ops, hweight32(table->valid_hooks));
1818 __ip6t_unregister_table(net, table);
1821 /* Returns 1 if the type and code is matched by the range, 0 otherwise */
1823 icmp6_type_code_match(u_int8_t test_type, u_int8_t min_code, u_int8_t max_code,
1824 u_int8_t type, u_int8_t code,
1827 return (type == test_type && code >= min_code && code <= max_code)
1832 icmp6_match(const struct sk_buff *skb, struct xt_action_param *par)
1834 const struct icmp6hdr *ic;
1835 struct icmp6hdr _icmph;
1836 const struct ip6t_icmp *icmpinfo = par->matchinfo;
1838 /* Must not be a fragment. */
1839 if (par->fragoff != 0)
1842 ic = skb_header_pointer(skb, par->thoff, sizeof(_icmph), &_icmph);
1844 /* We've been asked to examine this packet, and we
1845 * can't. Hence, no choice but to drop.
1847 par->hotdrop = true;
1851 return icmp6_type_code_match(icmpinfo->type,
1854 ic->icmp6_type, ic->icmp6_code,
1855 !!(icmpinfo->invflags&IP6T_ICMP_INV));
1858 /* Called when user tries to insert an entry of this type. */
1859 static int icmp6_checkentry(const struct xt_mtchk_param *par)
1861 const struct ip6t_icmp *icmpinfo = par->matchinfo;
1863 /* Must specify no unknown invflags */
1864 return (icmpinfo->invflags & ~IP6T_ICMP_INV) ? -EINVAL : 0;
1867 /* The built-in targets: standard (NULL) and error. */
1868 static struct xt_target ip6t_builtin_tg[] __read_mostly = {
1870 .name = XT_STANDARD_TARGET,
1871 .targetsize = sizeof(int),
1872 .family = NFPROTO_IPV6,
1873 #ifdef CONFIG_COMPAT
1874 .compatsize = sizeof(compat_int_t),
1875 .compat_from_user = compat_standard_from_user,
1876 .compat_to_user = compat_standard_to_user,
1880 .name = XT_ERROR_TARGET,
1881 .target = ip6t_error,
1882 .targetsize = XT_FUNCTION_MAXNAMELEN,
1883 .family = NFPROTO_IPV6,
1887 static struct nf_sockopt_ops ip6t_sockopts = {
1889 .set_optmin = IP6T_BASE_CTL,
1890 .set_optmax = IP6T_SO_SET_MAX+1,
1891 .set = do_ip6t_set_ctl,
1892 #ifdef CONFIG_COMPAT
1893 .compat_set = compat_do_ip6t_set_ctl,
1895 .get_optmin = IP6T_BASE_CTL,
1896 .get_optmax = IP6T_SO_GET_MAX+1,
1897 .get = do_ip6t_get_ctl,
1898 #ifdef CONFIG_COMPAT
1899 .compat_get = compat_do_ip6t_get_ctl,
1901 .owner = THIS_MODULE,
1904 static struct xt_match ip6t_builtin_mt[] __read_mostly = {
1907 .match = icmp6_match,
1908 .matchsize = sizeof(struct ip6t_icmp),
1909 .checkentry = icmp6_checkentry,
1910 .proto = IPPROTO_ICMPV6,
1911 .family = NFPROTO_IPV6,
1916 static int __net_init ip6_tables_net_init(struct net *net)
1918 return xt_proto_init(net, NFPROTO_IPV6);
1921 static void __net_exit ip6_tables_net_exit(struct net *net)
1923 xt_proto_fini(net, NFPROTO_IPV6);
1926 static struct pernet_operations ip6_tables_net_ops = {
1927 .init = ip6_tables_net_init,
1928 .exit = ip6_tables_net_exit,
1931 static int __init ip6_tables_init(void)
1935 ret = register_pernet_subsys(&ip6_tables_net_ops);
1939 /* No one else will be downing sem now, so we won't sleep */
1940 ret = xt_register_targets(ip6t_builtin_tg, ARRAY_SIZE(ip6t_builtin_tg));
1943 ret = xt_register_matches(ip6t_builtin_mt, ARRAY_SIZE(ip6t_builtin_mt));
1947 /* Register setsockopt */
1948 ret = nf_register_sockopt(&ip6t_sockopts);
1955 xt_unregister_matches(ip6t_builtin_mt, ARRAY_SIZE(ip6t_builtin_mt));
1957 xt_unregister_targets(ip6t_builtin_tg, ARRAY_SIZE(ip6t_builtin_tg));
1959 unregister_pernet_subsys(&ip6_tables_net_ops);
1964 static void __exit ip6_tables_fini(void)
1966 nf_unregister_sockopt(&ip6t_sockopts);
1968 xt_unregister_matches(ip6t_builtin_mt, ARRAY_SIZE(ip6t_builtin_mt));
1969 xt_unregister_targets(ip6t_builtin_tg, ARRAY_SIZE(ip6t_builtin_tg));
1970 unregister_pernet_subsys(&ip6_tables_net_ops);
1973 EXPORT_SYMBOL(ip6t_register_table);
1974 EXPORT_SYMBOL(ip6t_unregister_table);
1975 EXPORT_SYMBOL(ip6t_do_table);
1977 module_init(ip6_tables_init);
1978 module_exit(ip6_tables_fini);