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.
12 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13 #include <linux/cache.h>
14 #include <linux/capability.h>
15 #include <linux/skbuff.h>
16 #include <linux/kmod.h>
17 #include <linux/vmalloc.h>
18 #include <linux/netdevice.h>
19 #include <linux/module.h>
20 #include <linux/icmp.h>
22 #include <net/compat.h>
23 #include <linux/uaccess.h>
24 #include <linux/mutex.h>
25 #include <linux/proc_fs.h>
26 #include <linux/err.h>
27 #include <linux/cpumask.h>
29 #include <linux/netfilter/x_tables.h>
30 #include <linux/netfilter_ipv4/ip_tables.h>
31 #include <net/netfilter/nf_log.h>
32 #include "../../netfilter/xt_repldata.h"
34 MODULE_LICENSE("GPL");
35 MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>");
36 MODULE_DESCRIPTION("IPv4 packet filter");
38 #ifdef CONFIG_NETFILTER_DEBUG
39 #define IP_NF_ASSERT(x) WARN_ON(!(x))
41 #define IP_NF_ASSERT(x)
44 void *ipt_alloc_initial_table(const struct xt_table *info)
46 return xt_alloc_initial_table(ipt, IPT);
48 EXPORT_SYMBOL_GPL(ipt_alloc_initial_table);
50 /* Returns whether matches rule or not. */
51 /* Performance critical - called for every packet */
53 ip_packet_match(const struct iphdr *ip,
56 const struct ipt_ip *ipinfo,
61 if (NF_INVF(ipinfo, IPT_INV_SRCIP,
62 (ip->saddr & ipinfo->smsk.s_addr) != ipinfo->src.s_addr) ||
63 NF_INVF(ipinfo, IPT_INV_DSTIP,
64 (ip->daddr & ipinfo->dmsk.s_addr) != ipinfo->dst.s_addr))
67 ret = ifname_compare_aligned(indev, ipinfo->iniface, ipinfo->iniface_mask);
69 if (NF_INVF(ipinfo, IPT_INV_VIA_IN, ret != 0))
72 ret = ifname_compare_aligned(outdev, ipinfo->outiface, ipinfo->outiface_mask);
74 if (NF_INVF(ipinfo, IPT_INV_VIA_OUT, ret != 0))
77 /* Check specific protocol */
79 NF_INVF(ipinfo, IPT_INV_PROTO, ip->protocol != ipinfo->proto))
82 /* If we have a fragment rule but the packet is not a fragment
83 * then we return zero */
84 if (NF_INVF(ipinfo, IPT_INV_FRAG,
85 (ipinfo->flags & IPT_F_FRAG) && !isfrag))
92 ip_checkentry(const struct ipt_ip *ip)
94 if (ip->flags & ~IPT_F_MASK)
96 if (ip->invflags & ~IPT_INV_MASK)
102 ipt_error(struct sk_buff *skb, const struct xt_action_param *par)
104 net_info_ratelimited("error: `%s'\n", (const char *)par->targinfo);
109 /* Performance critical */
110 static inline struct ipt_entry *
111 get_entry(const void *base, unsigned int offset)
113 return (struct ipt_entry *)(base + offset);
116 /* All zeroes == unconditional rule. */
117 /* Mildly perf critical (only if packet tracing is on) */
118 static inline bool unconditional(const struct ipt_entry *e)
120 static const struct ipt_ip uncond;
122 return e->target_offset == sizeof(struct ipt_entry) &&
123 memcmp(&e->ip, &uncond, sizeof(uncond)) == 0;
126 /* for const-correctness */
127 static inline const struct xt_entry_target *
128 ipt_get_target_c(const struct ipt_entry *e)
130 return ipt_get_target((struct ipt_entry *)e);
133 #if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
134 static const char *const hooknames[] = {
135 [NF_INET_PRE_ROUTING] = "PREROUTING",
136 [NF_INET_LOCAL_IN] = "INPUT",
137 [NF_INET_FORWARD] = "FORWARD",
138 [NF_INET_LOCAL_OUT] = "OUTPUT",
139 [NF_INET_POST_ROUTING] = "POSTROUTING",
142 enum nf_ip_trace_comments {
143 NF_IP_TRACE_COMMENT_RULE,
144 NF_IP_TRACE_COMMENT_RETURN,
145 NF_IP_TRACE_COMMENT_POLICY,
148 static const char *const comments[] = {
149 [NF_IP_TRACE_COMMENT_RULE] = "rule",
150 [NF_IP_TRACE_COMMENT_RETURN] = "return",
151 [NF_IP_TRACE_COMMENT_POLICY] = "policy",
154 static struct nf_loginfo trace_loginfo = {
155 .type = NF_LOG_TYPE_LOG,
159 .logflags = NF_LOG_DEFAULT_MASK,
164 /* Mildly perf critical (only if packet tracing is on) */
166 get_chainname_rulenum(const struct ipt_entry *s, const struct ipt_entry *e,
167 const char *hookname, const char **chainname,
168 const char **comment, unsigned int *rulenum)
170 const struct xt_standard_target *t = (void *)ipt_get_target_c(s);
172 if (strcmp(t->target.u.kernel.target->name, XT_ERROR_TARGET) == 0) {
173 /* Head of user chain: ERROR target with chainname */
174 *chainname = t->target.data;
179 if (unconditional(s) &&
180 strcmp(t->target.u.kernel.target->name,
181 XT_STANDARD_TARGET) == 0 &&
183 /* Tail of chains: STANDARD target (return/policy) */
184 *comment = *chainname == hookname
185 ? comments[NF_IP_TRACE_COMMENT_POLICY]
186 : comments[NF_IP_TRACE_COMMENT_RETURN];
195 static void trace_packet(struct net *net,
196 const struct sk_buff *skb,
198 const struct net_device *in,
199 const struct net_device *out,
200 const char *tablename,
201 const struct xt_table_info *private,
202 const struct ipt_entry *e)
204 const struct ipt_entry *root;
205 const char *hookname, *chainname, *comment;
206 const struct ipt_entry *iter;
207 unsigned int rulenum = 0;
209 root = get_entry(private->entries, private->hook_entry[hook]);
211 hookname = chainname = hooknames[hook];
212 comment = comments[NF_IP_TRACE_COMMENT_RULE];
214 xt_entry_foreach(iter, root, private->size - private->hook_entry[hook])
215 if (get_chainname_rulenum(iter, e, hookname,
216 &chainname, &comment, &rulenum) != 0)
219 nf_log_trace(net, AF_INET, hook, skb, in, out, &trace_loginfo,
220 "TRACE: %s:%s:%s:%u ",
221 tablename, chainname, comment, rulenum);
226 struct ipt_entry *ipt_next_entry(const struct ipt_entry *entry)
228 return (void *)entry + entry->next_offset;
231 /* Returns one of the generic firewall policies, like NF_ACCEPT. */
233 ipt_do_table(struct sk_buff *skb,
234 const struct nf_hook_state *state,
235 struct xt_table *table)
237 unsigned int hook = state->hook;
238 static const char nulldevname[IFNAMSIZ] __attribute__((aligned(sizeof(long))));
239 const struct iphdr *ip;
240 /* Initializing verdict to NF_DROP keeps gcc happy. */
241 unsigned int verdict = NF_DROP;
242 const char *indev, *outdev;
243 const void *table_base;
244 struct ipt_entry *e, **jumpstack;
245 unsigned int stackidx, cpu;
246 const struct xt_table_info *private;
247 struct xt_action_param acpar;
253 indev = state->in ? state->in->name : nulldevname;
254 outdev = state->out ? state->out->name : nulldevname;
255 /* We handle fragments by dealing with the first fragment as
256 * if it was a normal packet. All other fragments are treated
257 * normally, except that they will NEVER match rules that ask
258 * things we don't know, ie. tcp syn flag or ports). If the
259 * rule is also a fragment-specific rule, non-fragments won't
261 acpar.fragoff = ntohs(ip->frag_off) & IP_OFFSET;
262 acpar.thoff = ip_hdrlen(skb);
263 acpar.hotdrop = false;
266 IP_NF_ASSERT(table->valid_hooks & (1 << hook));
268 addend = xt_write_recseq_begin();
269 private = table->private;
270 cpu = smp_processor_id();
272 * Ensure we load private-> members after we've fetched the base
275 smp_read_barrier_depends();
276 table_base = private->entries;
277 jumpstack = (struct ipt_entry **)private->jumpstack[cpu];
279 /* Switch to alternate jumpstack if we're being invoked via TEE.
280 * TEE issues XT_CONTINUE verdict on original skb so we must not
281 * clobber the jumpstack.
283 * For recursion via REJECT or SYNPROXY the stack will be clobbered
284 * but it is no problem since absolute verdict is issued by these.
286 if (static_key_false(&xt_tee_enabled))
287 jumpstack += private->stacksize * __this_cpu_read(nf_skb_duplicated);
289 e = get_entry(table_base, private->hook_entry[hook]);
292 const struct xt_entry_target *t;
293 const struct xt_entry_match *ematch;
294 struct xt_counters *counter;
297 if (!ip_packet_match(ip, indev, outdev,
298 &e->ip, acpar.fragoff)) {
300 e = ipt_next_entry(e);
304 xt_ematch_foreach(ematch, e) {
305 acpar.match = ematch->u.kernel.match;
306 acpar.matchinfo = ematch->data;
307 if (!acpar.match->match(skb, &acpar))
311 counter = xt_get_this_cpu_counter(&e->counters);
312 ADD_COUNTER(*counter, skb->len, 1);
314 t = ipt_get_target(e);
315 IP_NF_ASSERT(t->u.kernel.target);
317 #if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
318 /* The packet is traced: log it */
319 if (unlikely(skb->nf_trace))
320 trace_packet(state->net, skb, hook, state->in,
321 state->out, table->name, private, e);
323 /* Standard target? */
324 if (!t->u.kernel.target->target) {
327 v = ((struct xt_standard_target *)t)->verdict;
329 /* Pop from stack? */
330 if (v != XT_RETURN) {
331 verdict = (unsigned int)(-v) - 1;
335 e = get_entry(table_base,
336 private->underflow[hook]);
338 e = jumpstack[--stackidx];
339 e = ipt_next_entry(e);
343 if (table_base + v != ipt_next_entry(e) &&
344 !(e->ip.flags & IPT_F_GOTO))
345 jumpstack[stackidx++] = e;
347 e = get_entry(table_base, v);
351 acpar.target = t->u.kernel.target;
352 acpar.targinfo = t->data;
354 verdict = t->u.kernel.target->target(skb, &acpar);
355 if (verdict == XT_CONTINUE) {
356 /* Target might have changed stuff. */
358 e = ipt_next_entry(e);
363 } while (!acpar.hotdrop);
365 xt_write_recseq_end(addend);
373 /* Figures out from what hook each rule can be called: returns 0 if
374 there are loops. Puts hook bitmask in comefrom. */
376 mark_source_chains(const struct xt_table_info *newinfo,
377 unsigned int valid_hooks, void *entry0,
378 unsigned int *offsets)
382 /* No recursion; use packet counter to save back ptrs (reset
383 to 0 as we leave), and comefrom to save source hook bitmask */
384 for (hook = 0; hook < NF_INET_NUMHOOKS; hook++) {
385 unsigned int pos = newinfo->hook_entry[hook];
386 struct ipt_entry *e = entry0 + pos;
388 if (!(valid_hooks & (1 << hook)))
391 /* Set initial back pointer. */
392 e->counters.pcnt = pos;
395 const struct xt_standard_target *t
396 = (void *)ipt_get_target_c(e);
397 int visited = e->comefrom & (1 << hook);
399 if (e->comefrom & (1 << NF_INET_NUMHOOKS))
402 e->comefrom |= ((1 << hook) | (1 << NF_INET_NUMHOOKS));
404 /* Unconditional return/END. */
405 if ((unconditional(e) &&
406 (strcmp(t->target.u.user.name,
407 XT_STANDARD_TARGET) == 0) &&
408 t->verdict < 0) || visited) {
409 unsigned int oldpos, size;
411 if ((strcmp(t->target.u.user.name,
412 XT_STANDARD_TARGET) == 0) &&
413 t->verdict < -NF_MAX_VERDICT - 1)
416 /* Return: backtrack through the last
419 e->comefrom ^= (1<<NF_INET_NUMHOOKS);
421 pos = e->counters.pcnt;
422 e->counters.pcnt = 0;
424 /* We're at the start. */
429 } while (oldpos == pos + e->next_offset);
432 size = e->next_offset;
433 e = entry0 + pos + size;
434 if (pos + size >= newinfo->size)
436 e->counters.pcnt = pos;
439 int newpos = t->verdict;
441 if (strcmp(t->target.u.user.name,
442 XT_STANDARD_TARGET) == 0 &&
444 /* This a jump; chase it. */
445 if (!xt_find_jump_offset(offsets, newpos,
450 /* ... this is a fallthru */
451 newpos = pos + e->next_offset;
452 if (newpos >= newinfo->size)
456 e->counters.pcnt = pos;
465 static void cleanup_match(struct xt_entry_match *m, struct net *net)
467 struct xt_mtdtor_param par;
470 par.match = m->u.kernel.match;
471 par.matchinfo = m->data;
472 par.family = NFPROTO_IPV4;
473 if (par.match->destroy != NULL)
474 par.match->destroy(&par);
475 module_put(par.match->me);
479 check_match(struct xt_entry_match *m, struct xt_mtchk_param *par)
481 const struct ipt_ip *ip = par->entryinfo;
483 par->match = m->u.kernel.match;
484 par->matchinfo = m->data;
486 return xt_check_match(par, m->u.match_size - sizeof(*m),
487 ip->proto, ip->invflags & IPT_INV_PROTO);
491 find_check_match(struct xt_entry_match *m, struct xt_mtchk_param *par)
493 struct xt_match *match;
496 match = xt_request_find_match(NFPROTO_IPV4, m->u.user.name,
499 return PTR_ERR(match);
500 m->u.kernel.match = match;
502 ret = check_match(m, par);
508 module_put(m->u.kernel.match->me);
512 static int check_target(struct ipt_entry *e, struct net *net, const char *name)
514 struct xt_entry_target *t = ipt_get_target(e);
515 struct xt_tgchk_param par = {
519 .target = t->u.kernel.target,
521 .hook_mask = e->comefrom,
522 .family = NFPROTO_IPV4,
525 return xt_check_target(&par, t->u.target_size - sizeof(*t),
526 e->ip.proto, e->ip.invflags & IPT_INV_PROTO);
530 find_check_entry(struct ipt_entry *e, struct net *net, const char *name,
532 struct xt_percpu_counter_alloc_state *alloc_state)
534 struct xt_entry_target *t;
535 struct xt_target *target;
538 struct xt_mtchk_param mtpar;
539 struct xt_entry_match *ematch;
541 if (!xt_percpu_counter_alloc(alloc_state, &e->counters))
547 mtpar.entryinfo = &e->ip;
548 mtpar.hook_mask = e->comefrom;
549 mtpar.family = NFPROTO_IPV4;
550 xt_ematch_foreach(ematch, e) {
551 ret = find_check_match(ematch, &mtpar);
553 goto cleanup_matches;
557 t = ipt_get_target(e);
558 target = xt_request_find_target(NFPROTO_IPV4, t->u.user.name,
560 if (IS_ERR(target)) {
561 ret = PTR_ERR(target);
562 goto cleanup_matches;
564 t->u.kernel.target = target;
566 ret = check_target(e, net, name);
572 module_put(t->u.kernel.target->me);
574 xt_ematch_foreach(ematch, e) {
577 cleanup_match(ematch, net);
580 xt_percpu_counter_free(&e->counters);
585 static bool check_underflow(const struct ipt_entry *e)
587 const struct xt_entry_target *t;
588 unsigned int verdict;
590 if (!unconditional(e))
592 t = ipt_get_target_c(e);
593 if (strcmp(t->u.user.name, XT_STANDARD_TARGET) != 0)
595 verdict = ((struct xt_standard_target *)t)->verdict;
596 verdict = -verdict - 1;
597 return verdict == NF_DROP || verdict == NF_ACCEPT;
601 check_entry_size_and_hooks(struct ipt_entry *e,
602 struct xt_table_info *newinfo,
603 const unsigned char *base,
604 const unsigned char *limit,
605 const unsigned int *hook_entries,
606 const unsigned int *underflows,
607 unsigned int valid_hooks)
612 if ((unsigned long)e % __alignof__(struct ipt_entry) != 0 ||
613 (unsigned char *)e + sizeof(struct ipt_entry) >= limit ||
614 (unsigned char *)e + e->next_offset > limit)
618 < sizeof(struct ipt_entry) + sizeof(struct xt_entry_target))
621 if (!ip_checkentry(&e->ip))
624 err = xt_check_entry_offsets(e, e->elems, e->target_offset,
629 /* Check hooks & underflows */
630 for (h = 0; h < NF_INET_NUMHOOKS; h++) {
631 if (!(valid_hooks & (1 << h)))
633 if ((unsigned char *)e - base == hook_entries[h])
634 newinfo->hook_entry[h] = hook_entries[h];
635 if ((unsigned char *)e - base == underflows[h]) {
636 if (!check_underflow(e))
639 newinfo->underflow[h] = underflows[h];
643 /* Clear counters and comefrom */
644 e->counters = ((struct xt_counters) { 0, 0 });
650 cleanup_entry(struct ipt_entry *e, struct net *net)
652 struct xt_tgdtor_param par;
653 struct xt_entry_target *t;
654 struct xt_entry_match *ematch;
656 /* Cleanup all matches */
657 xt_ematch_foreach(ematch, e)
658 cleanup_match(ematch, net);
659 t = ipt_get_target(e);
662 par.target = t->u.kernel.target;
663 par.targinfo = t->data;
664 par.family = NFPROTO_IPV4;
665 if (par.target->destroy != NULL)
666 par.target->destroy(&par);
667 module_put(par.target->me);
668 xt_percpu_counter_free(&e->counters);
671 /* Checks and translates the user-supplied table segment (held in
674 translate_table(struct net *net, struct xt_table_info *newinfo, void *entry0,
675 const struct ipt_replace *repl)
677 struct xt_percpu_counter_alloc_state alloc_state = { 0 };
678 struct ipt_entry *iter;
679 unsigned int *offsets;
683 newinfo->size = repl->size;
684 newinfo->number = repl->num_entries;
686 /* Init all hooks to impossible value. */
687 for (i = 0; i < NF_INET_NUMHOOKS; i++) {
688 newinfo->hook_entry[i] = 0xFFFFFFFF;
689 newinfo->underflow[i] = 0xFFFFFFFF;
692 offsets = xt_alloc_entry_offsets(newinfo->number);
696 /* Walk through entries, checking offsets. */
697 xt_entry_foreach(iter, entry0, newinfo->size) {
698 ret = check_entry_size_and_hooks(iter, newinfo, entry0,
705 if (i < repl->num_entries)
706 offsets[i] = (void *)iter - entry0;
708 if (strcmp(ipt_get_target(iter)->u.user.name,
709 XT_ERROR_TARGET) == 0)
710 ++newinfo->stacksize;
714 if (i != repl->num_entries)
717 /* Check hooks all assigned */
718 for (i = 0; i < NF_INET_NUMHOOKS; i++) {
719 /* Only hooks which are valid */
720 if (!(repl->valid_hooks & (1 << i)))
722 if (newinfo->hook_entry[i] == 0xFFFFFFFF)
724 if (newinfo->underflow[i] == 0xFFFFFFFF)
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 ipt_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);
784 ++i; /* macro does multi eval of i */
789 static struct xt_counters *alloc_counters(const struct xt_table *table)
791 unsigned int countersize;
792 struct xt_counters *counters;
793 const struct xt_table_info *private = table->private;
795 /* We need atomic snapshot of counters: rest doesn't change
796 (other than comefrom, which userspace doesn't care
798 countersize = sizeof(struct xt_counters) * private->number;
799 counters = vzalloc(countersize);
801 if (counters == NULL)
802 return ERR_PTR(-ENOMEM);
804 get_counters(private, counters);
810 copy_entries_to_user(unsigned int total_size,
811 const struct xt_table *table,
812 void __user *userptr)
814 unsigned int off, num;
815 const struct ipt_entry *e;
816 struct xt_counters *counters;
817 const struct xt_table_info *private = table->private;
819 const void *loc_cpu_entry;
821 counters = alloc_counters(table);
822 if (IS_ERR(counters))
823 return PTR_ERR(counters);
825 loc_cpu_entry = private->entries;
827 /* FIXME: use iterator macros --RR */
828 /* ... then go back and fix counters and names */
829 for (off = 0, num = 0; off < total_size; off += e->next_offset, num++){
831 const struct xt_entry_match *m;
832 const struct xt_entry_target *t;
834 e = loc_cpu_entry + off;
835 if (copy_to_user(userptr + off, e, sizeof(*e))) {
839 if (copy_to_user(userptr + off
840 + offsetof(struct ipt_entry, counters),
842 sizeof(counters[num])) != 0) {
847 for (i = sizeof(struct ipt_entry);
848 i < e->target_offset;
849 i += m->u.match_size) {
852 if (xt_match_to_user(m, userptr + off + i)) {
858 t = ipt_get_target_c(e);
859 if (xt_target_to_user(t, userptr + off + e->target_offset)) {
871 static void compat_standard_from_user(void *dst, const void *src)
873 int v = *(compat_int_t *)src;
876 v += xt_compat_calc_jump(AF_INET, v);
877 memcpy(dst, &v, sizeof(v));
880 static int compat_standard_to_user(void __user *dst, const void *src)
882 compat_int_t cv = *(int *)src;
885 cv -= xt_compat_calc_jump(AF_INET, cv);
886 return copy_to_user(dst, &cv, sizeof(cv)) ? -EFAULT : 0;
889 static int compat_calc_entry(const struct ipt_entry *e,
890 const struct xt_table_info *info,
891 const void *base, struct xt_table_info *newinfo)
893 const struct xt_entry_match *ematch;
894 const struct xt_entry_target *t;
895 unsigned int entry_offset;
898 off = sizeof(struct ipt_entry) - sizeof(struct compat_ipt_entry);
899 entry_offset = (void *)e - base;
900 xt_ematch_foreach(ematch, e)
901 off += xt_compat_match_offset(ematch->u.kernel.match);
902 t = ipt_get_target_c(e);
903 off += xt_compat_target_offset(t->u.kernel.target);
904 newinfo->size -= off;
905 ret = xt_compat_add_offset(AF_INET, entry_offset, off);
909 for (i = 0; i < NF_INET_NUMHOOKS; i++) {
910 if (info->hook_entry[i] &&
911 (e < (struct ipt_entry *)(base + info->hook_entry[i])))
912 newinfo->hook_entry[i] -= off;
913 if (info->underflow[i] &&
914 (e < (struct ipt_entry *)(base + info->underflow[i])))
915 newinfo->underflow[i] -= off;
920 static int compat_table_info(const struct xt_table_info *info,
921 struct xt_table_info *newinfo)
923 struct ipt_entry *iter;
924 const void *loc_cpu_entry;
927 if (!newinfo || !info)
930 /* we dont care about newinfo->entries */
931 memcpy(newinfo, info, offsetof(struct xt_table_info, entries));
932 newinfo->initial_entries = 0;
933 loc_cpu_entry = info->entries;
934 xt_compat_init_offsets(AF_INET, info->number);
935 xt_entry_foreach(iter, loc_cpu_entry, info->size) {
936 ret = compat_calc_entry(iter, info, loc_cpu_entry, newinfo);
944 static int get_info(struct net *net, void __user *user,
945 const int *len, int compat)
947 char name[XT_TABLE_MAXNAMELEN];
951 if (*len != sizeof(struct ipt_getinfo))
954 if (copy_from_user(name, user, sizeof(name)) != 0)
957 name[XT_TABLE_MAXNAMELEN-1] = '\0';
960 xt_compat_lock(AF_INET);
962 t = try_then_request_module(xt_find_table_lock(net, AF_INET, name),
965 struct ipt_getinfo info;
966 const struct xt_table_info *private = t->private;
968 struct xt_table_info tmp;
971 ret = compat_table_info(private, &tmp);
972 xt_compat_flush_offsets(AF_INET);
976 memset(&info, 0, sizeof(info));
977 info.valid_hooks = t->valid_hooks;
978 memcpy(info.hook_entry, private->hook_entry,
979 sizeof(info.hook_entry));
980 memcpy(info.underflow, private->underflow,
981 sizeof(info.underflow));
982 info.num_entries = private->number;
983 info.size = private->size;
984 strcpy(info.name, name);
986 if (copy_to_user(user, &info, *len) != 0)
997 xt_compat_unlock(AF_INET);
1003 get_entries(struct net *net, struct ipt_get_entries __user *uptr,
1007 struct ipt_get_entries get;
1010 if (*len < sizeof(get))
1012 if (copy_from_user(&get, uptr, sizeof(get)) != 0)
1014 if (*len != sizeof(struct ipt_get_entries) + get.size)
1016 get.name[sizeof(get.name) - 1] = '\0';
1018 t = xt_find_table_lock(net, AF_INET, get.name);
1020 const struct xt_table_info *private = t->private;
1021 if (get.size == private->size)
1022 ret = copy_entries_to_user(private->size,
1023 t, uptr->entrytable);
1036 __do_replace(struct net *net, const char *name, unsigned int valid_hooks,
1037 struct xt_table_info *newinfo, unsigned int num_counters,
1038 void __user *counters_ptr)
1042 struct xt_table_info *oldinfo;
1043 struct xt_counters *counters;
1044 struct ipt_entry *iter;
1047 counters = vzalloc(num_counters * sizeof(struct xt_counters));
1053 t = try_then_request_module(xt_find_table_lock(net, AF_INET, name),
1054 "iptable_%s", name);
1057 goto free_newinfo_counters_untrans;
1061 if (valid_hooks != t->valid_hooks) {
1066 oldinfo = xt_replace_table(t, num_counters, newinfo, &ret);
1070 /* Update module usage count based on number of rules */
1071 if ((oldinfo->number > oldinfo->initial_entries) ||
1072 (newinfo->number <= oldinfo->initial_entries))
1074 if ((oldinfo->number > oldinfo->initial_entries) &&
1075 (newinfo->number <= oldinfo->initial_entries))
1078 /* Get the old counters, and synchronize with replace */
1079 get_counters(oldinfo, counters);
1081 /* Decrease module usage counts and free resource */
1082 xt_entry_foreach(iter, oldinfo->entries, oldinfo->size)
1083 cleanup_entry(iter, net);
1085 xt_free_table_info(oldinfo);
1086 if (copy_to_user(counters_ptr, counters,
1087 sizeof(struct xt_counters) * num_counters) != 0) {
1088 /* Silent error, can't fail, new table is already in place */
1089 net_warn_ratelimited("iptables: counters copy to user failed while replacing table\n");
1098 free_newinfo_counters_untrans:
1105 do_replace(struct net *net, const void __user *user, unsigned int len)
1108 struct ipt_replace tmp;
1109 struct xt_table_info *newinfo;
1110 void *loc_cpu_entry;
1111 struct ipt_entry *iter;
1113 if (copy_from_user(&tmp, user, sizeof(tmp)) != 0)
1116 /* overflow check */
1117 if (tmp.num_counters >= INT_MAX / sizeof(struct xt_counters))
1119 if (tmp.num_counters == 0)
1122 tmp.name[sizeof(tmp.name)-1] = 0;
1124 newinfo = xt_alloc_table_info(tmp.size);
1128 loc_cpu_entry = newinfo->entries;
1129 if (copy_from_user(loc_cpu_entry, user + sizeof(tmp),
1135 ret = translate_table(net, newinfo, loc_cpu_entry, &tmp);
1139 ret = __do_replace(net, tmp.name, tmp.valid_hooks, newinfo,
1140 tmp.num_counters, tmp.counters);
1142 goto free_newinfo_untrans;
1145 free_newinfo_untrans:
1146 xt_entry_foreach(iter, loc_cpu_entry, newinfo->size)
1147 cleanup_entry(iter, net);
1149 xt_free_table_info(newinfo);
1154 do_add_counters(struct net *net, const void __user *user,
1155 unsigned int len, int compat)
1158 struct xt_counters_info tmp;
1159 struct xt_counters *paddc;
1161 const struct xt_table_info *private;
1163 struct ipt_entry *iter;
1164 unsigned int addend;
1166 paddc = xt_copy_counters_from_user(user, len, &tmp, compat);
1168 return PTR_ERR(paddc);
1170 t = xt_find_table_lock(net, AF_INET, tmp.name);
1177 private = t->private;
1178 if (private->number != tmp.num_counters) {
1180 goto unlock_up_free;
1184 addend = xt_write_recseq_begin();
1185 xt_entry_foreach(iter, private->entries, private->size) {
1186 struct xt_counters *tmp;
1188 tmp = xt_get_this_cpu_counter(&iter->counters);
1189 ADD_COUNTER(*tmp, paddc[i].bcnt, paddc[i].pcnt);
1192 xt_write_recseq_end(addend);
1203 #ifdef CONFIG_COMPAT
1204 struct compat_ipt_replace {
1205 char name[XT_TABLE_MAXNAMELEN];
1209 u32 hook_entry[NF_INET_NUMHOOKS];
1210 u32 underflow[NF_INET_NUMHOOKS];
1212 compat_uptr_t counters; /* struct xt_counters * */
1213 struct compat_ipt_entry entries[0];
1217 compat_copy_entry_to_user(struct ipt_entry *e, void __user **dstptr,
1218 unsigned int *size, struct xt_counters *counters,
1221 struct xt_entry_target *t;
1222 struct compat_ipt_entry __user *ce;
1223 u_int16_t target_offset, next_offset;
1224 compat_uint_t origsize;
1225 const struct xt_entry_match *ematch;
1230 if (copy_to_user(ce, e, sizeof(struct ipt_entry)) != 0 ||
1231 copy_to_user(&ce->counters, &counters[i],
1232 sizeof(counters[i])) != 0)
1235 *dstptr += sizeof(struct compat_ipt_entry);
1236 *size -= sizeof(struct ipt_entry) - sizeof(struct compat_ipt_entry);
1238 xt_ematch_foreach(ematch, e) {
1239 ret = xt_compat_match_to_user(ematch, dstptr, size);
1243 target_offset = e->target_offset - (origsize - *size);
1244 t = ipt_get_target(e);
1245 ret = xt_compat_target_to_user(t, dstptr, size);
1248 next_offset = e->next_offset - (origsize - *size);
1249 if (put_user(target_offset, &ce->target_offset) != 0 ||
1250 put_user(next_offset, &ce->next_offset) != 0)
1256 compat_find_calc_match(struct xt_entry_match *m,
1257 const struct ipt_ip *ip,
1260 struct xt_match *match;
1262 match = xt_request_find_match(NFPROTO_IPV4, m->u.user.name,
1263 m->u.user.revision);
1265 return PTR_ERR(match);
1267 m->u.kernel.match = match;
1268 *size += xt_compat_match_offset(match);
1272 static void compat_release_entry(struct compat_ipt_entry *e)
1274 struct xt_entry_target *t;
1275 struct xt_entry_match *ematch;
1277 /* Cleanup all matches */
1278 xt_ematch_foreach(ematch, e)
1279 module_put(ematch->u.kernel.match->me);
1280 t = compat_ipt_get_target(e);
1281 module_put(t->u.kernel.target->me);
1285 check_compat_entry_size_and_hooks(struct compat_ipt_entry *e,
1286 struct xt_table_info *newinfo,
1288 const unsigned char *base,
1289 const unsigned char *limit)
1291 struct xt_entry_match *ematch;
1292 struct xt_entry_target *t;
1293 struct xt_target *target;
1294 unsigned int entry_offset;
1298 if ((unsigned long)e % __alignof__(struct compat_ipt_entry) != 0 ||
1299 (unsigned char *)e + sizeof(struct compat_ipt_entry) >= limit ||
1300 (unsigned char *)e + e->next_offset > limit)
1303 if (e->next_offset < sizeof(struct compat_ipt_entry) +
1304 sizeof(struct compat_xt_entry_target))
1307 if (!ip_checkentry(&e->ip))
1310 ret = xt_compat_check_entry_offsets(e, e->elems,
1311 e->target_offset, e->next_offset);
1315 off = sizeof(struct ipt_entry) - sizeof(struct compat_ipt_entry);
1316 entry_offset = (void *)e - (void *)base;
1318 xt_ematch_foreach(ematch, e) {
1319 ret = compat_find_calc_match(ematch, &e->ip, &off);
1321 goto release_matches;
1325 t = compat_ipt_get_target(e);
1326 target = xt_request_find_target(NFPROTO_IPV4, t->u.user.name,
1327 t->u.user.revision);
1328 if (IS_ERR(target)) {
1329 ret = PTR_ERR(target);
1330 goto release_matches;
1332 t->u.kernel.target = target;
1334 off += xt_compat_target_offset(target);
1336 ret = xt_compat_add_offset(AF_INET, entry_offset, off);
1343 module_put(t->u.kernel.target->me);
1345 xt_ematch_foreach(ematch, e) {
1348 module_put(ematch->u.kernel.match->me);
1354 compat_copy_entry_from_user(struct compat_ipt_entry *e, void **dstptr,
1356 struct xt_table_info *newinfo, unsigned char *base)
1358 struct xt_entry_target *t;
1359 struct xt_target *target;
1360 struct ipt_entry *de;
1361 unsigned int origsize;
1363 struct xt_entry_match *ematch;
1367 memcpy(de, e, sizeof(struct ipt_entry));
1368 memcpy(&de->counters, &e->counters, sizeof(e->counters));
1370 *dstptr += sizeof(struct ipt_entry);
1371 *size += sizeof(struct ipt_entry) - sizeof(struct compat_ipt_entry);
1373 xt_ematch_foreach(ematch, e)
1374 xt_compat_match_from_user(ematch, dstptr, size);
1376 de->target_offset = e->target_offset - (origsize - *size);
1377 t = compat_ipt_get_target(e);
1378 target = t->u.kernel.target;
1379 xt_compat_target_from_user(t, dstptr, size);
1381 de->next_offset = e->next_offset - (origsize - *size);
1383 for (h = 0; h < NF_INET_NUMHOOKS; h++) {
1384 if ((unsigned char *)de - base < newinfo->hook_entry[h])
1385 newinfo->hook_entry[h] -= origsize - *size;
1386 if ((unsigned char *)de - base < newinfo->underflow[h])
1387 newinfo->underflow[h] -= origsize - *size;
1392 translate_compat_table(struct net *net,
1393 struct xt_table_info **pinfo,
1395 const struct compat_ipt_replace *compatr)
1398 struct xt_table_info *newinfo, *info;
1399 void *pos, *entry0, *entry1;
1400 struct compat_ipt_entry *iter0;
1401 struct ipt_replace repl;
1407 size = compatr->size;
1408 info->number = compatr->num_entries;
1411 xt_compat_lock(AF_INET);
1412 xt_compat_init_offsets(AF_INET, compatr->num_entries);
1413 /* Walk through entries, checking offsets. */
1414 xt_entry_foreach(iter0, entry0, compatr->size) {
1415 ret = check_compat_entry_size_and_hooks(iter0, info, &size,
1417 entry0 + compatr->size);
1424 if (j != compatr->num_entries)
1428 newinfo = xt_alloc_table_info(size);
1432 newinfo->number = compatr->num_entries;
1433 for (i = 0; i < NF_INET_NUMHOOKS; i++) {
1434 newinfo->hook_entry[i] = compatr->hook_entry[i];
1435 newinfo->underflow[i] = compatr->underflow[i];
1437 entry1 = newinfo->entries;
1439 size = compatr->size;
1440 xt_entry_foreach(iter0, entry0, compatr->size)
1441 compat_copy_entry_from_user(iter0, &pos, &size,
1444 /* all module references in entry0 are now gone.
1445 * entry1/newinfo contains a 64bit ruleset that looks exactly as
1446 * generated by 64bit userspace.
1448 * Call standard translate_table() to validate all hook_entrys,
1449 * underflows, check for loops, etc.
1451 xt_compat_flush_offsets(AF_INET);
1452 xt_compat_unlock(AF_INET);
1454 memcpy(&repl, compatr, sizeof(*compatr));
1456 for (i = 0; i < NF_INET_NUMHOOKS; i++) {
1457 repl.hook_entry[i] = newinfo->hook_entry[i];
1458 repl.underflow[i] = newinfo->underflow[i];
1461 repl.num_counters = 0;
1462 repl.counters = NULL;
1463 repl.size = newinfo->size;
1464 ret = translate_table(net, newinfo, entry1, &repl);
1470 xt_free_table_info(info);
1474 xt_free_table_info(newinfo);
1477 xt_compat_flush_offsets(AF_INET);
1478 xt_compat_unlock(AF_INET);
1479 xt_entry_foreach(iter0, entry0, compatr->size) {
1482 compat_release_entry(iter0);
1488 compat_do_replace(struct net *net, void __user *user, unsigned int len)
1491 struct compat_ipt_replace tmp;
1492 struct xt_table_info *newinfo;
1493 void *loc_cpu_entry;
1494 struct ipt_entry *iter;
1496 if (copy_from_user(&tmp, user, sizeof(tmp)) != 0)
1499 /* overflow check */
1500 if (tmp.num_counters >= INT_MAX / sizeof(struct xt_counters))
1502 if (tmp.num_counters == 0)
1505 tmp.name[sizeof(tmp.name)-1] = 0;
1507 newinfo = xt_alloc_table_info(tmp.size);
1511 loc_cpu_entry = newinfo->entries;
1512 if (copy_from_user(loc_cpu_entry, user + sizeof(tmp),
1518 ret = translate_compat_table(net, &newinfo, &loc_cpu_entry, &tmp);
1522 ret = __do_replace(net, tmp.name, tmp.valid_hooks, newinfo,
1523 tmp.num_counters, compat_ptr(tmp.counters));
1525 goto free_newinfo_untrans;
1528 free_newinfo_untrans:
1529 xt_entry_foreach(iter, loc_cpu_entry, newinfo->size)
1530 cleanup_entry(iter, net);
1532 xt_free_table_info(newinfo);
1537 compat_do_ipt_set_ctl(struct sock *sk, int cmd, void __user *user,
1542 if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN))
1546 case IPT_SO_SET_REPLACE:
1547 ret = compat_do_replace(sock_net(sk), user, len);
1550 case IPT_SO_SET_ADD_COUNTERS:
1551 ret = do_add_counters(sock_net(sk), user, len, 1);
1561 struct compat_ipt_get_entries {
1562 char name[XT_TABLE_MAXNAMELEN];
1564 struct compat_ipt_entry entrytable[0];
1568 compat_copy_entries_to_user(unsigned int total_size, struct xt_table *table,
1569 void __user *userptr)
1571 struct xt_counters *counters;
1572 const struct xt_table_info *private = table->private;
1577 struct ipt_entry *iter;
1579 counters = alloc_counters(table);
1580 if (IS_ERR(counters))
1581 return PTR_ERR(counters);
1585 xt_entry_foreach(iter, private->entries, total_size) {
1586 ret = compat_copy_entry_to_user(iter, &pos,
1587 &size, counters, i++);
1597 compat_get_entries(struct net *net, struct compat_ipt_get_entries __user *uptr,
1601 struct compat_ipt_get_entries get;
1604 if (*len < sizeof(get))
1607 if (copy_from_user(&get, uptr, sizeof(get)) != 0)
1610 if (*len != sizeof(struct compat_ipt_get_entries) + get.size)
1613 get.name[sizeof(get.name) - 1] = '\0';
1615 xt_compat_lock(AF_INET);
1616 t = xt_find_table_lock(net, AF_INET, get.name);
1618 const struct xt_table_info *private = t->private;
1619 struct xt_table_info info;
1620 ret = compat_table_info(private, &info);
1621 if (!ret && get.size == info.size)
1622 ret = compat_copy_entries_to_user(private->size,
1623 t, uptr->entrytable);
1627 xt_compat_flush_offsets(AF_INET);
1633 xt_compat_unlock(AF_INET);
1637 static int do_ipt_get_ctl(struct sock *, int, void __user *, int *);
1640 compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
1644 if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN))
1648 case IPT_SO_GET_INFO:
1649 ret = get_info(sock_net(sk), user, len, 1);
1651 case IPT_SO_GET_ENTRIES:
1652 ret = compat_get_entries(sock_net(sk), user, len);
1655 ret = do_ipt_get_ctl(sk, cmd, user, len);
1662 do_ipt_set_ctl(struct sock *sk, int cmd, void __user *user, unsigned int len)
1666 if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN))
1670 case IPT_SO_SET_REPLACE:
1671 ret = do_replace(sock_net(sk), user, len);
1674 case IPT_SO_SET_ADD_COUNTERS:
1675 ret = do_add_counters(sock_net(sk), user, len, 0);
1686 do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
1690 if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN))
1694 case IPT_SO_GET_INFO:
1695 ret = get_info(sock_net(sk), user, len, 0);
1698 case IPT_SO_GET_ENTRIES:
1699 ret = get_entries(sock_net(sk), user, len);
1702 case IPT_SO_GET_REVISION_MATCH:
1703 case IPT_SO_GET_REVISION_TARGET: {
1704 struct xt_get_revision rev;
1707 if (*len != sizeof(rev)) {
1711 if (copy_from_user(&rev, user, sizeof(rev)) != 0) {
1715 rev.name[sizeof(rev.name)-1] = 0;
1717 if (cmd == IPT_SO_GET_REVISION_TARGET)
1722 try_then_request_module(xt_find_revision(AF_INET, rev.name,
1725 "ipt_%s", rev.name);
1736 static void __ipt_unregister_table(struct net *net, struct xt_table *table)
1738 struct xt_table_info *private;
1739 void *loc_cpu_entry;
1740 struct module *table_owner = table->me;
1741 struct ipt_entry *iter;
1743 private = xt_unregister_table(table);
1745 /* Decrease module usage counts and free resources */
1746 loc_cpu_entry = private->entries;
1747 xt_entry_foreach(iter, loc_cpu_entry, private->size)
1748 cleanup_entry(iter, net);
1749 if (private->number > private->initial_entries)
1750 module_put(table_owner);
1751 xt_free_table_info(private);
1754 int ipt_register_table(struct net *net, const struct xt_table *table,
1755 const struct ipt_replace *repl,
1756 const struct nf_hook_ops *ops, struct xt_table **res)
1759 struct xt_table_info *newinfo;
1760 struct xt_table_info bootstrap = {0};
1761 void *loc_cpu_entry;
1762 struct xt_table *new_table;
1764 newinfo = xt_alloc_table_info(repl->size);
1768 loc_cpu_entry = newinfo->entries;
1769 memcpy(loc_cpu_entry, repl->entries, repl->size);
1771 ret = translate_table(net, newinfo, loc_cpu_entry, repl);
1775 new_table = xt_register_table(net, table, &bootstrap, newinfo);
1776 if (IS_ERR(new_table)) {
1777 ret = PTR_ERR(new_table);
1781 /* set res now, will see skbs right after nf_register_net_hooks */
1782 WRITE_ONCE(*res, new_table);
1784 ret = nf_register_net_hooks(net, ops, hweight32(table->valid_hooks));
1786 __ipt_unregister_table(net, new_table);
1793 xt_free_table_info(newinfo);
1797 void ipt_unregister_table(struct net *net, struct xt_table *table,
1798 const struct nf_hook_ops *ops)
1800 nf_unregister_net_hooks(net, ops, hweight32(table->valid_hooks));
1801 __ipt_unregister_table(net, table);
1804 /* Returns 1 if the type and code is matched by the range, 0 otherwise */
1806 icmp_type_code_match(u_int8_t test_type, u_int8_t min_code, u_int8_t max_code,
1807 u_int8_t type, u_int8_t code,
1810 return ((test_type == 0xFF) ||
1811 (type == test_type && code >= min_code && code <= max_code))
1816 icmp_match(const struct sk_buff *skb, struct xt_action_param *par)
1818 const struct icmphdr *ic;
1819 struct icmphdr _icmph;
1820 const struct ipt_icmp *icmpinfo = par->matchinfo;
1822 /* Must not be a fragment. */
1823 if (par->fragoff != 0)
1826 ic = skb_header_pointer(skb, par->thoff, sizeof(_icmph), &_icmph);
1828 /* We've been asked to examine this packet, and we
1829 * can't. Hence, no choice but to drop.
1831 par->hotdrop = true;
1835 return icmp_type_code_match(icmpinfo->type,
1839 !!(icmpinfo->invflags&IPT_ICMP_INV));
1842 static int icmp_checkentry(const struct xt_mtchk_param *par)
1844 const struct ipt_icmp *icmpinfo = par->matchinfo;
1846 /* Must specify no unknown invflags */
1847 return (icmpinfo->invflags & ~IPT_ICMP_INV) ? -EINVAL : 0;
1850 static struct xt_target ipt_builtin_tg[] __read_mostly = {
1852 .name = XT_STANDARD_TARGET,
1853 .targetsize = sizeof(int),
1854 .family = NFPROTO_IPV4,
1855 #ifdef CONFIG_COMPAT
1856 .compatsize = sizeof(compat_int_t),
1857 .compat_from_user = compat_standard_from_user,
1858 .compat_to_user = compat_standard_to_user,
1862 .name = XT_ERROR_TARGET,
1863 .target = ipt_error,
1864 .targetsize = XT_FUNCTION_MAXNAMELEN,
1865 .family = NFPROTO_IPV4,
1869 static struct nf_sockopt_ops ipt_sockopts = {
1871 .set_optmin = IPT_BASE_CTL,
1872 .set_optmax = IPT_SO_SET_MAX+1,
1873 .set = do_ipt_set_ctl,
1874 #ifdef CONFIG_COMPAT
1875 .compat_set = compat_do_ipt_set_ctl,
1877 .get_optmin = IPT_BASE_CTL,
1878 .get_optmax = IPT_SO_GET_MAX+1,
1879 .get = do_ipt_get_ctl,
1880 #ifdef CONFIG_COMPAT
1881 .compat_get = compat_do_ipt_get_ctl,
1883 .owner = THIS_MODULE,
1886 static struct xt_match ipt_builtin_mt[] __read_mostly = {
1889 .match = icmp_match,
1890 .matchsize = sizeof(struct ipt_icmp),
1891 .checkentry = icmp_checkentry,
1892 .proto = IPPROTO_ICMP,
1893 .family = NFPROTO_IPV4,
1897 static int __net_init ip_tables_net_init(struct net *net)
1899 return xt_proto_init(net, NFPROTO_IPV4);
1902 static void __net_exit ip_tables_net_exit(struct net *net)
1904 xt_proto_fini(net, NFPROTO_IPV4);
1907 static struct pernet_operations ip_tables_net_ops = {
1908 .init = ip_tables_net_init,
1909 .exit = ip_tables_net_exit,
1912 static int __init ip_tables_init(void)
1916 ret = register_pernet_subsys(&ip_tables_net_ops);
1920 /* No one else will be downing sem now, so we won't sleep */
1921 ret = xt_register_targets(ipt_builtin_tg, ARRAY_SIZE(ipt_builtin_tg));
1924 ret = xt_register_matches(ipt_builtin_mt, ARRAY_SIZE(ipt_builtin_mt));
1928 /* Register setsockopt */
1929 ret = nf_register_sockopt(&ipt_sockopts);
1933 pr_info("(C) 2000-2006 Netfilter Core Team\n");
1937 xt_unregister_matches(ipt_builtin_mt, ARRAY_SIZE(ipt_builtin_mt));
1939 xt_unregister_targets(ipt_builtin_tg, ARRAY_SIZE(ipt_builtin_tg));
1941 unregister_pernet_subsys(&ip_tables_net_ops);
1946 static void __exit ip_tables_fini(void)
1948 nf_unregister_sockopt(&ipt_sockopts);
1950 xt_unregister_matches(ipt_builtin_mt, ARRAY_SIZE(ipt_builtin_mt));
1951 xt_unregister_targets(ipt_builtin_tg, ARRAY_SIZE(ipt_builtin_tg));
1952 unregister_pernet_subsys(&ip_tables_net_ops);
1955 EXPORT_SYMBOL(ipt_register_table);
1956 EXPORT_SYMBOL(ipt_unregister_table);
1957 EXPORT_SYMBOL(ipt_do_table);
1958 module_init(ip_tables_init);
1959 module_exit(ip_tables_fini);