2 * Packet matching code for ARP packets.
4 * Based heavily, if not almost entirely, upon ip_tables.c framework.
6 * Some ARP specific bits are:
8 * Copyright (C) 2002 David S. Miller (davem@redhat.com)
9 * Copyright (C) 2006-2009 Patrick McHardy <kaber@trash.net>
12 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13 #include <linux/kernel.h>
14 #include <linux/skbuff.h>
15 #include <linux/netdevice.h>
16 #include <linux/capability.h>
17 #include <linux/if_arp.h>
18 #include <linux/kmod.h>
19 #include <linux/vmalloc.h>
20 #include <linux/proc_fs.h>
21 #include <linux/module.h>
22 #include <linux/init.h>
23 #include <linux/mutex.h>
24 #include <linux/err.h>
25 #include <net/compat.h>
27 #include <asm/uaccess.h>
29 #include <linux/netfilter/x_tables.h>
30 #include <linux/netfilter_arp/arp_tables.h>
31 #include "../../netfilter/xt_repldata.h"
33 MODULE_LICENSE("GPL");
34 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
35 MODULE_DESCRIPTION("arptables core");
37 /*#define DEBUG_ARP_TABLES*/
38 /*#define DEBUG_ARP_TABLES_USER*/
40 #ifdef DEBUG_ARP_TABLES
41 #define dprintf(format, args...) printk(format , ## args)
43 #define dprintf(format, args...)
46 #ifdef DEBUG_ARP_TABLES_USER
47 #define duprintf(format, args...) printk(format , ## args)
49 #define duprintf(format, args...)
52 #ifdef CONFIG_NETFILTER_DEBUG
53 #define ARP_NF_ASSERT(x) WARN_ON(!(x))
55 #define ARP_NF_ASSERT(x)
58 void *arpt_alloc_initial_table(const struct xt_table *info)
60 return xt_alloc_initial_table(arpt, ARPT);
62 EXPORT_SYMBOL_GPL(arpt_alloc_initial_table);
64 static inline int arp_devaddr_compare(const struct arpt_devaddr_info *ap,
65 const char *hdr_addr, int len)
69 if (len > ARPT_DEV_ADDR_LEN_MAX)
70 len = ARPT_DEV_ADDR_LEN_MAX;
73 for (i = 0; i < len; i++)
74 ret |= (hdr_addr[i] ^ ap->addr[i]) & ap->mask[i];
80 * Unfortunately, _b and _mask are not aligned to an int (or long int)
81 * Some arches dont care, unrolling the loop is a win on them.
82 * For other arches, we only have a 16bit alignement.
84 static unsigned long ifname_compare(const char *_a, const char *_b, const char *_mask)
86 #ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
87 unsigned long ret = ifname_compare_aligned(_a, _b, _mask);
89 unsigned long ret = 0;
90 const u16 *a = (const u16 *)_a;
91 const u16 *b = (const u16 *)_b;
92 const u16 *mask = (const u16 *)_mask;
95 for (i = 0; i < IFNAMSIZ/sizeof(u16); i++)
96 ret |= (a[i] ^ b[i]) & mask[i];
101 /* Returns whether packet matches rule or not. */
102 static inline int arp_packet_match(const struct arphdr *arphdr,
103 struct net_device *dev,
106 const struct arpt_arp *arpinfo)
108 const char *arpptr = (char *)(arphdr + 1);
109 const char *src_devaddr, *tgt_devaddr;
110 __be32 src_ipaddr, tgt_ipaddr;
113 #define FWINV(bool, invflg) ((bool) ^ !!(arpinfo->invflags & (invflg)))
115 if (FWINV((arphdr->ar_op & arpinfo->arpop_mask) != arpinfo->arpop,
117 dprintf("ARP operation field mismatch.\n");
118 dprintf("ar_op: %04x info->arpop: %04x info->arpop_mask: %04x\n",
119 arphdr->ar_op, arpinfo->arpop, arpinfo->arpop_mask);
123 if (FWINV((arphdr->ar_hrd & arpinfo->arhrd_mask) != arpinfo->arhrd,
125 dprintf("ARP hardware address format mismatch.\n");
126 dprintf("ar_hrd: %04x info->arhrd: %04x info->arhrd_mask: %04x\n",
127 arphdr->ar_hrd, arpinfo->arhrd, arpinfo->arhrd_mask);
131 if (FWINV((arphdr->ar_pro & arpinfo->arpro_mask) != arpinfo->arpro,
133 dprintf("ARP protocol address format mismatch.\n");
134 dprintf("ar_pro: %04x info->arpro: %04x info->arpro_mask: %04x\n",
135 arphdr->ar_pro, arpinfo->arpro, arpinfo->arpro_mask);
139 if (FWINV((arphdr->ar_hln & arpinfo->arhln_mask) != arpinfo->arhln,
141 dprintf("ARP hardware address length mismatch.\n");
142 dprintf("ar_hln: %02x info->arhln: %02x info->arhln_mask: %02x\n",
143 arphdr->ar_hln, arpinfo->arhln, arpinfo->arhln_mask);
147 src_devaddr = arpptr;
148 arpptr += dev->addr_len;
149 memcpy(&src_ipaddr, arpptr, sizeof(u32));
150 arpptr += sizeof(u32);
151 tgt_devaddr = arpptr;
152 arpptr += dev->addr_len;
153 memcpy(&tgt_ipaddr, arpptr, sizeof(u32));
155 if (FWINV(arp_devaddr_compare(&arpinfo->src_devaddr, src_devaddr, dev->addr_len),
156 ARPT_INV_SRCDEVADDR) ||
157 FWINV(arp_devaddr_compare(&arpinfo->tgt_devaddr, tgt_devaddr, dev->addr_len),
158 ARPT_INV_TGTDEVADDR)) {
159 dprintf("Source or target device address mismatch.\n");
164 if (FWINV((src_ipaddr & arpinfo->smsk.s_addr) != arpinfo->src.s_addr,
166 FWINV(((tgt_ipaddr & arpinfo->tmsk.s_addr) != arpinfo->tgt.s_addr),
168 dprintf("Source or target IP address mismatch.\n");
170 dprintf("SRC: %pI4. Mask: %pI4. Target: %pI4.%s\n",
172 &arpinfo->smsk.s_addr,
173 &arpinfo->src.s_addr,
174 arpinfo->invflags & ARPT_INV_SRCIP ? " (INV)" : "");
175 dprintf("TGT: %pI4 Mask: %pI4 Target: %pI4.%s\n",
177 &arpinfo->tmsk.s_addr,
178 &arpinfo->tgt.s_addr,
179 arpinfo->invflags & ARPT_INV_TGTIP ? " (INV)" : "");
183 /* Look for ifname matches. */
184 ret = ifname_compare(indev, arpinfo->iniface, arpinfo->iniface_mask);
186 if (FWINV(ret != 0, ARPT_INV_VIA_IN)) {
187 dprintf("VIA in mismatch (%s vs %s).%s\n",
188 indev, arpinfo->iniface,
189 arpinfo->invflags&ARPT_INV_VIA_IN ?" (INV)":"");
193 ret = ifname_compare(outdev, arpinfo->outiface, arpinfo->outiface_mask);
195 if (FWINV(ret != 0, ARPT_INV_VIA_OUT)) {
196 dprintf("VIA out mismatch (%s vs %s).%s\n",
197 outdev, arpinfo->outiface,
198 arpinfo->invflags&ARPT_INV_VIA_OUT ?" (INV)":"");
206 static inline int arp_checkentry(const struct arpt_arp *arp)
208 if (arp->flags & ~ARPT_F_MASK) {
209 duprintf("Unknown flag bits set: %08X\n",
210 arp->flags & ~ARPT_F_MASK);
213 if (arp->invflags & ~ARPT_INV_MASK) {
214 duprintf("Unknown invflag bits set: %08X\n",
215 arp->invflags & ~ARPT_INV_MASK);
223 arpt_error(struct sk_buff *skb, const struct xt_action_param *par)
225 net_err_ratelimited("arp_tables: error: '%s'\n",
226 (const char *)par->targinfo);
231 static inline const struct xt_entry_target *
232 arpt_get_target_c(const struct arpt_entry *e)
234 return arpt_get_target((struct arpt_entry *)e);
237 static inline struct arpt_entry *
238 get_entry(const void *base, unsigned int offset)
240 return (struct arpt_entry *)(base + offset);
244 struct arpt_entry *arpt_next_entry(const struct arpt_entry *entry)
246 return (void *)entry + entry->next_offset;
249 unsigned int arpt_do_table(struct sk_buff *skb,
251 const struct nf_hook_state *state,
252 struct xt_table *table)
254 static const char nulldevname[IFNAMSIZ] __attribute__((aligned(sizeof(long))));
255 unsigned int verdict = NF_DROP;
256 const struct arphdr *arp;
257 struct arpt_entry *e, **jumpstack;
258 const char *indev, *outdev;
259 const void *table_base;
260 unsigned int cpu, stackidx = 0;
261 const struct xt_table_info *private;
262 struct xt_action_param acpar;
265 if (!pskb_may_pull(skb, arp_hdr_len(skb->dev)))
268 indev = state->in ? state->in->name : nulldevname;
269 outdev = state->out ? state->out->name : nulldevname;
272 addend = xt_write_recseq_begin();
273 private = table->private;
274 cpu = smp_processor_id();
276 * Ensure we load private-> members after we've fetched the base
279 smp_read_barrier_depends();
280 table_base = private->entries;
281 jumpstack = (struct arpt_entry **)private->jumpstack[cpu];
283 /* No TEE support for arptables, so no need to switch to alternate
284 * stack. All targets that reenter must return absolute verdicts.
286 e = get_entry(table_base, private->hook_entry[hook]);
288 acpar.in = state->in;
289 acpar.out = state->out;
290 acpar.hooknum = hook;
291 acpar.family = NFPROTO_ARP;
292 acpar.hotdrop = false;
296 const struct xt_entry_target *t;
297 struct xt_counters *counter;
299 if (!arp_packet_match(arp, skb->dev, indev, outdev, &e->arp)) {
300 e = arpt_next_entry(e);
304 counter = xt_get_this_cpu_counter(&e->counters);
305 ADD_COUNTER(*counter, arp_hdr_len(skb->dev), 1);
307 t = arpt_get_target_c(e);
309 /* Standard target? */
310 if (!t->u.kernel.target->target) {
313 v = ((struct xt_standard_target *)t)->verdict;
315 /* Pop from stack? */
316 if (v != XT_RETURN) {
317 verdict = (unsigned int)(-v) - 1;
321 e = get_entry(table_base,
322 private->underflow[hook]);
324 e = jumpstack[--stackidx];
325 e = arpt_next_entry(e);
330 != arpt_next_entry(e)) {
331 jumpstack[stackidx++] = e;
334 e = get_entry(table_base, v);
338 acpar.target = t->u.kernel.target;
339 acpar.targinfo = t->data;
340 verdict = t->u.kernel.target->target(skb, &acpar);
342 /* Target might have changed stuff. */
345 if (verdict == XT_CONTINUE)
346 e = arpt_next_entry(e);
350 } while (!acpar.hotdrop);
351 xt_write_recseq_end(addend);
360 /* All zeroes == unconditional rule. */
361 static inline bool unconditional(const struct arpt_arp *arp)
363 static const struct arpt_arp uncond;
365 return memcmp(arp, &uncond, sizeof(uncond)) == 0;
368 /* Figures out from what hook each rule can be called: returns 0 if
369 * there are loops. Puts hook bitmask in comefrom.
371 static int mark_source_chains(const struct xt_table_info *newinfo,
372 unsigned int valid_hooks, void *entry0)
376 /* No recursion; use packet counter to save back ptrs (reset
377 * to 0 as we leave), and comefrom to save source hook bitmask.
379 for (hook = 0; hook < NF_ARP_NUMHOOKS; hook++) {
380 unsigned int pos = newinfo->hook_entry[hook];
382 = (struct arpt_entry *)(entry0 + pos);
384 if (!(valid_hooks & (1 << hook)))
387 /* Set initial back pointer. */
388 e->counters.pcnt = pos;
391 const struct xt_standard_target *t
392 = (void *)arpt_get_target_c(e);
393 int visited = e->comefrom & (1 << hook);
395 if (e->comefrom & (1 << NF_ARP_NUMHOOKS)) {
396 pr_notice("arptables: loop hook %u pos %u %08X.\n",
397 hook, pos, e->comefrom);
401 |= ((1 << hook) | (1 << NF_ARP_NUMHOOKS));
403 /* Unconditional return/END. */
404 if ((e->target_offset == sizeof(struct arpt_entry) &&
405 (strcmp(t->target.u.user.name,
406 XT_STANDARD_TARGET) == 0) &&
407 t->verdict < 0 && unconditional(&e->arp)) ||
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) {
414 duprintf("mark_source_chains: bad "
415 "negative verdict (%i)\n",
420 /* Return: backtrack through the last
424 e->comefrom ^= (1<<NF_ARP_NUMHOOKS);
426 pos = e->counters.pcnt;
427 e->counters.pcnt = 0;
429 /* We're at the start. */
433 e = (struct arpt_entry *)
435 } while (oldpos == pos + e->next_offset);
438 size = e->next_offset;
439 e = (struct arpt_entry *)
440 (entry0 + pos + size);
441 e->counters.pcnt = pos;
444 int newpos = t->verdict;
446 if (strcmp(t->target.u.user.name,
447 XT_STANDARD_TARGET) == 0 &&
449 if (newpos > newinfo->size -
450 sizeof(struct arpt_entry)) {
451 duprintf("mark_source_chains: "
452 "bad verdict (%i)\n",
457 /* This a jump; chase it. */
458 duprintf("Jump rule %u -> %u\n",
461 /* ... this is a fallthru */
462 newpos = pos + e->next_offset;
464 e = (struct arpt_entry *)
466 e->counters.pcnt = pos;
471 duprintf("Finished chain %u\n", hook);
476 static inline int check_entry(const struct arpt_entry *e, const char *name)
478 const struct xt_entry_target *t;
480 if (!arp_checkentry(&e->arp)) {
481 duprintf("arp_tables: arp check failed %p %s.\n", e, name);
485 if (e->target_offset + sizeof(struct xt_entry_target) > e->next_offset)
488 t = arpt_get_target_c(e);
489 if (e->target_offset + t->u.target_size > e->next_offset)
495 static inline int check_target(struct arpt_entry *e, const char *name)
497 struct xt_entry_target *t = arpt_get_target(e);
499 struct xt_tgchk_param par = {
502 .target = t->u.kernel.target,
504 .hook_mask = e->comefrom,
505 .family = NFPROTO_ARP,
508 ret = xt_check_target(&par, t->u.target_size - sizeof(*t), 0, false);
510 duprintf("arp_tables: check failed for `%s'.\n",
511 t->u.kernel.target->name);
518 find_check_entry(struct arpt_entry *e, const char *name, unsigned int size)
520 struct xt_entry_target *t;
521 struct xt_target *target;
524 ret = check_entry(e, name);
528 e->counters.pcnt = xt_percpu_counter_alloc();
529 if (IS_ERR_VALUE(e->counters.pcnt))
532 t = arpt_get_target(e);
533 target = xt_request_find_target(NFPROTO_ARP, t->u.user.name,
535 if (IS_ERR(target)) {
536 duprintf("find_check_entry: `%s' not found\n", t->u.user.name);
537 ret = PTR_ERR(target);
540 t->u.kernel.target = target;
542 ret = check_target(e, name);
547 module_put(t->u.kernel.target->me);
549 xt_percpu_counter_free(e->counters.pcnt);
554 static bool check_underflow(const struct arpt_entry *e)
556 const struct xt_entry_target *t;
557 unsigned int verdict;
559 if (!unconditional(&e->arp))
561 t = arpt_get_target_c(e);
562 if (strcmp(t->u.user.name, XT_STANDARD_TARGET) != 0)
564 verdict = ((struct xt_standard_target *)t)->verdict;
565 verdict = -verdict - 1;
566 return verdict == NF_DROP || verdict == NF_ACCEPT;
569 static inline int check_entry_size_and_hooks(struct arpt_entry *e,
570 struct xt_table_info *newinfo,
571 const unsigned char *base,
572 const unsigned char *limit,
573 const unsigned int *hook_entries,
574 const unsigned int *underflows,
575 unsigned int valid_hooks)
579 if ((unsigned long)e % __alignof__(struct arpt_entry) != 0 ||
580 (unsigned char *)e + sizeof(struct arpt_entry) >= limit) {
581 duprintf("Bad offset %p\n", e);
586 < sizeof(struct arpt_entry) + sizeof(struct xt_entry_target)) {
587 duprintf("checking: element %p size %u\n",
592 /* Check hooks & underflows */
593 for (h = 0; h < NF_ARP_NUMHOOKS; h++) {
594 if (!(valid_hooks & (1 << h)))
596 if ((unsigned char *)e - base == hook_entries[h])
597 newinfo->hook_entry[h] = hook_entries[h];
598 if ((unsigned char *)e - base == underflows[h]) {
599 if (!check_underflow(e)) {
600 pr_err("Underflows must be unconditional and "
601 "use the STANDARD target with "
605 newinfo->underflow[h] = underflows[h];
609 /* Clear counters and comefrom */
610 e->counters = ((struct xt_counters) { 0, 0 });
615 static inline void cleanup_entry(struct arpt_entry *e)
617 struct xt_tgdtor_param par;
618 struct xt_entry_target *t;
620 t = arpt_get_target(e);
621 par.target = t->u.kernel.target;
622 par.targinfo = t->data;
623 par.family = NFPROTO_ARP;
624 if (par.target->destroy != NULL)
625 par.target->destroy(&par);
626 module_put(par.target->me);
627 xt_percpu_counter_free(e->counters.pcnt);
630 /* Checks and translates the user-supplied table segment (held in
633 static int translate_table(struct xt_table_info *newinfo, void *entry0,
634 const struct arpt_replace *repl)
636 struct arpt_entry *iter;
640 newinfo->size = repl->size;
641 newinfo->number = repl->num_entries;
643 /* Init all hooks to impossible value. */
644 for (i = 0; i < NF_ARP_NUMHOOKS; i++) {
645 newinfo->hook_entry[i] = 0xFFFFFFFF;
646 newinfo->underflow[i] = 0xFFFFFFFF;
649 duprintf("translate_table: size %u\n", newinfo->size);
652 /* Walk through entries, checking offsets. */
653 xt_entry_foreach(iter, entry0, newinfo->size) {
654 ret = check_entry_size_and_hooks(iter, newinfo, entry0,
662 if (strcmp(arpt_get_target(iter)->u.user.name,
663 XT_ERROR_TARGET) == 0)
664 ++newinfo->stacksize;
666 duprintf("translate_table: ARPT_ENTRY_ITERATE gives %d\n", ret);
670 if (i != repl->num_entries) {
671 duprintf("translate_table: %u not %u entries\n",
672 i, repl->num_entries);
676 /* Check hooks all assigned */
677 for (i = 0; i < NF_ARP_NUMHOOKS; i++) {
678 /* Only hooks which are valid */
679 if (!(repl->valid_hooks & (1 << i)))
681 if (newinfo->hook_entry[i] == 0xFFFFFFFF) {
682 duprintf("Invalid hook entry %u %u\n",
683 i, repl->hook_entry[i]);
686 if (newinfo->underflow[i] == 0xFFFFFFFF) {
687 duprintf("Invalid underflow %u %u\n",
688 i, repl->underflow[i]);
693 if (!mark_source_chains(newinfo, repl->valid_hooks, entry0)) {
694 duprintf("Looping hook\n");
698 /* Finally, each sanity check must pass */
700 xt_entry_foreach(iter, entry0, newinfo->size) {
701 ret = find_check_entry(iter, repl->name, repl->size);
708 xt_entry_foreach(iter, entry0, newinfo->size) {
719 static void get_counters(const struct xt_table_info *t,
720 struct xt_counters counters[])
722 struct arpt_entry *iter;
726 for_each_possible_cpu(cpu) {
727 seqcount_t *s = &per_cpu(xt_recseq, cpu);
730 xt_entry_foreach(iter, t->entries, t->size) {
731 struct xt_counters *tmp;
735 tmp = xt_get_per_cpu_counter(&iter->counters, cpu);
737 start = read_seqcount_begin(s);
740 } while (read_seqcount_retry(s, start));
742 ADD_COUNTER(counters[i], bcnt, pcnt);
748 static struct xt_counters *alloc_counters(const struct xt_table *table)
750 unsigned int countersize;
751 struct xt_counters *counters;
752 const struct xt_table_info *private = table->private;
754 /* We need atomic snapshot of counters: rest doesn't change
755 * (other than comefrom, which userspace doesn't care
758 countersize = sizeof(struct xt_counters) * private->number;
759 counters = vzalloc(countersize);
761 if (counters == NULL)
762 return ERR_PTR(-ENOMEM);
764 get_counters(private, counters);
769 static int copy_entries_to_user(unsigned int total_size,
770 const struct xt_table *table,
771 void __user *userptr)
773 unsigned int off, num;
774 const struct arpt_entry *e;
775 struct xt_counters *counters;
776 struct xt_table_info *private = table->private;
780 counters = alloc_counters(table);
781 if (IS_ERR(counters))
782 return PTR_ERR(counters);
784 loc_cpu_entry = private->entries;
785 /* ... then copy entire thing ... */
786 if (copy_to_user(userptr, loc_cpu_entry, total_size) != 0) {
791 /* FIXME: use iterator macros --RR */
792 /* ... then go back and fix counters and names */
793 for (off = 0, num = 0; off < total_size; off += e->next_offset, num++){
794 const struct xt_entry_target *t;
796 e = (struct arpt_entry *)(loc_cpu_entry + off);
797 if (copy_to_user(userptr + off
798 + offsetof(struct arpt_entry, counters),
800 sizeof(counters[num])) != 0) {
805 t = arpt_get_target_c(e);
806 if (copy_to_user(userptr + off + e->target_offset
807 + offsetof(struct xt_entry_target,
809 t->u.kernel.target->name,
810 strlen(t->u.kernel.target->name)+1) != 0) {
822 static void compat_standard_from_user(void *dst, const void *src)
824 int v = *(compat_int_t *)src;
827 v += xt_compat_calc_jump(NFPROTO_ARP, v);
828 memcpy(dst, &v, sizeof(v));
831 static int compat_standard_to_user(void __user *dst, const void *src)
833 compat_int_t cv = *(int *)src;
836 cv -= xt_compat_calc_jump(NFPROTO_ARP, cv);
837 return copy_to_user(dst, &cv, sizeof(cv)) ? -EFAULT : 0;
840 static int compat_calc_entry(const struct arpt_entry *e,
841 const struct xt_table_info *info,
842 const void *base, struct xt_table_info *newinfo)
844 const struct xt_entry_target *t;
845 unsigned int entry_offset;
848 off = sizeof(struct arpt_entry) - sizeof(struct compat_arpt_entry);
849 entry_offset = (void *)e - base;
851 t = arpt_get_target_c(e);
852 off += xt_compat_target_offset(t->u.kernel.target);
853 newinfo->size -= off;
854 ret = xt_compat_add_offset(NFPROTO_ARP, entry_offset, off);
858 for (i = 0; i < NF_ARP_NUMHOOKS; i++) {
859 if (info->hook_entry[i] &&
860 (e < (struct arpt_entry *)(base + info->hook_entry[i])))
861 newinfo->hook_entry[i] -= off;
862 if (info->underflow[i] &&
863 (e < (struct arpt_entry *)(base + info->underflow[i])))
864 newinfo->underflow[i] -= off;
869 static int compat_table_info(const struct xt_table_info *info,
870 struct xt_table_info *newinfo)
872 struct arpt_entry *iter;
873 const void *loc_cpu_entry;
876 if (!newinfo || !info)
879 /* we dont care about newinfo->entries */
880 memcpy(newinfo, info, offsetof(struct xt_table_info, entries));
881 newinfo->initial_entries = 0;
882 loc_cpu_entry = info->entries;
883 xt_compat_init_offsets(NFPROTO_ARP, info->number);
884 xt_entry_foreach(iter, loc_cpu_entry, info->size) {
885 ret = compat_calc_entry(iter, info, loc_cpu_entry, newinfo);
893 static int get_info(struct net *net, void __user *user,
894 const int *len, int compat)
896 char name[XT_TABLE_MAXNAMELEN];
900 if (*len != sizeof(struct arpt_getinfo)) {
901 duprintf("length %u != %Zu\n", *len,
902 sizeof(struct arpt_getinfo));
906 if (copy_from_user(name, user, sizeof(name)) != 0)
909 name[XT_TABLE_MAXNAMELEN-1] = '\0';
912 xt_compat_lock(NFPROTO_ARP);
914 t = try_then_request_module(xt_find_table_lock(net, NFPROTO_ARP, name),
915 "arptable_%s", name);
916 if (!IS_ERR_OR_NULL(t)) {
917 struct arpt_getinfo info;
918 const struct xt_table_info *private = t->private;
920 struct xt_table_info tmp;
923 ret = compat_table_info(private, &tmp);
924 xt_compat_flush_offsets(NFPROTO_ARP);
928 memset(&info, 0, sizeof(info));
929 info.valid_hooks = t->valid_hooks;
930 memcpy(info.hook_entry, private->hook_entry,
931 sizeof(info.hook_entry));
932 memcpy(info.underflow, private->underflow,
933 sizeof(info.underflow));
934 info.num_entries = private->number;
935 info.size = private->size;
936 strcpy(info.name, name);
938 if (copy_to_user(user, &info, *len) != 0)
945 ret = t ? PTR_ERR(t) : -ENOENT;
948 xt_compat_unlock(NFPROTO_ARP);
953 static int get_entries(struct net *net, struct arpt_get_entries __user *uptr,
957 struct arpt_get_entries get;
960 if (*len < sizeof(get)) {
961 duprintf("get_entries: %u < %Zu\n", *len, sizeof(get));
964 if (copy_from_user(&get, uptr, sizeof(get)) != 0)
966 if (*len != sizeof(struct arpt_get_entries) + get.size) {
967 duprintf("get_entries: %u != %Zu\n", *len,
968 sizeof(struct arpt_get_entries) + get.size);
972 t = xt_find_table_lock(net, NFPROTO_ARP, get.name);
973 if (!IS_ERR_OR_NULL(t)) {
974 const struct xt_table_info *private = t->private;
976 duprintf("t->private->number = %u\n",
978 if (get.size == private->size)
979 ret = copy_entries_to_user(private->size,
980 t, uptr->entrytable);
982 duprintf("get_entries: I've got %u not %u!\n",
983 private->size, get.size);
989 ret = t ? PTR_ERR(t) : -ENOENT;
994 static int __do_replace(struct net *net, const char *name,
995 unsigned int valid_hooks,
996 struct xt_table_info *newinfo,
997 unsigned int num_counters,
998 void __user *counters_ptr)
1002 struct xt_table_info *oldinfo;
1003 struct xt_counters *counters;
1004 void *loc_cpu_old_entry;
1005 struct arpt_entry *iter;
1008 counters = vzalloc(num_counters * sizeof(struct xt_counters));
1014 t = try_then_request_module(xt_find_table_lock(net, NFPROTO_ARP, name),
1015 "arptable_%s", name);
1016 if (IS_ERR_OR_NULL(t)) {
1017 ret = t ? PTR_ERR(t) : -ENOENT;
1018 goto free_newinfo_counters_untrans;
1022 if (valid_hooks != t->valid_hooks) {
1023 duprintf("Valid hook crap: %08X vs %08X\n",
1024 valid_hooks, t->valid_hooks);
1029 oldinfo = xt_replace_table(t, num_counters, newinfo, &ret);
1033 /* Update module usage count based on number of rules */
1034 duprintf("do_replace: oldnum=%u, initnum=%u, newnum=%u\n",
1035 oldinfo->number, oldinfo->initial_entries, newinfo->number);
1036 if ((oldinfo->number > oldinfo->initial_entries) ||
1037 (newinfo->number <= oldinfo->initial_entries))
1039 if ((oldinfo->number > oldinfo->initial_entries) &&
1040 (newinfo->number <= oldinfo->initial_entries))
1043 /* Get the old counters, and synchronize with replace */
1044 get_counters(oldinfo, counters);
1046 /* Decrease module usage counts and free resource */
1047 loc_cpu_old_entry = oldinfo->entries;
1048 xt_entry_foreach(iter, loc_cpu_old_entry, oldinfo->size)
1049 cleanup_entry(iter);
1051 xt_free_table_info(oldinfo);
1052 if (copy_to_user(counters_ptr, counters,
1053 sizeof(struct xt_counters) * num_counters) != 0) {
1054 /* Silent error, can't fail, new table is already in place */
1055 net_warn_ratelimited("arptables: counters copy to user failed while replacing table\n");
1064 free_newinfo_counters_untrans:
1070 static int do_replace(struct net *net, const void __user *user,
1074 struct arpt_replace tmp;
1075 struct xt_table_info *newinfo;
1076 void *loc_cpu_entry;
1077 struct arpt_entry *iter;
1079 if (copy_from_user(&tmp, user, sizeof(tmp)) != 0)
1082 /* overflow check */
1083 if (tmp.num_counters >= INT_MAX / sizeof(struct xt_counters))
1085 if (tmp.num_counters == 0)
1088 tmp.name[sizeof(tmp.name)-1] = 0;
1090 newinfo = xt_alloc_table_info(tmp.size);
1094 loc_cpu_entry = newinfo->entries;
1095 if (copy_from_user(loc_cpu_entry, user + sizeof(tmp),
1101 ret = translate_table(newinfo, loc_cpu_entry, &tmp);
1105 duprintf("arp_tables: Translated table\n");
1107 ret = __do_replace(net, tmp.name, tmp.valid_hooks, newinfo,
1108 tmp.num_counters, tmp.counters);
1110 goto free_newinfo_untrans;
1113 free_newinfo_untrans:
1114 xt_entry_foreach(iter, loc_cpu_entry, newinfo->size)
1115 cleanup_entry(iter);
1117 xt_free_table_info(newinfo);
1121 static int do_add_counters(struct net *net, const void __user *user,
1122 unsigned int len, int compat)
1125 struct xt_counters_info tmp;
1126 struct xt_counters *paddc;
1127 unsigned int num_counters;
1132 const struct xt_table_info *private;
1134 struct arpt_entry *iter;
1135 unsigned int addend;
1136 #ifdef CONFIG_COMPAT
1137 struct compat_xt_counters_info compat_tmp;
1141 size = sizeof(struct compat_xt_counters_info);
1146 size = sizeof(struct xt_counters_info);
1149 if (copy_from_user(ptmp, user, size) != 0)
1152 #ifdef CONFIG_COMPAT
1154 num_counters = compat_tmp.num_counters;
1155 name = compat_tmp.name;
1159 num_counters = tmp.num_counters;
1163 if (len != size + num_counters * sizeof(struct xt_counters))
1166 paddc = vmalloc(len - size);
1170 if (copy_from_user(paddc, user + size, len - size) != 0) {
1175 t = xt_find_table_lock(net, NFPROTO_ARP, name);
1176 if (IS_ERR_OR_NULL(t)) {
1177 ret = t ? PTR_ERR(t) : -ENOENT;
1182 private = t->private;
1183 if (private->number != num_counters) {
1185 goto unlock_up_free;
1190 addend = xt_write_recseq_begin();
1191 xt_entry_foreach(iter, private->entries, private->size) {
1192 struct xt_counters *tmp;
1194 tmp = xt_get_this_cpu_counter(&iter->counters);
1195 ADD_COUNTER(*tmp, paddc[i].bcnt, paddc[i].pcnt);
1198 xt_write_recseq_end(addend);
1209 #ifdef CONFIG_COMPAT
1210 static inline void compat_release_entry(struct compat_arpt_entry *e)
1212 struct xt_entry_target *t;
1214 t = compat_arpt_get_target(e);
1215 module_put(t->u.kernel.target->me);
1219 check_compat_entry_size_and_hooks(struct compat_arpt_entry *e,
1220 struct xt_table_info *newinfo,
1222 const unsigned char *base,
1223 const unsigned char *limit,
1224 const unsigned int *hook_entries,
1225 const unsigned int *underflows,
1228 struct xt_entry_target *t;
1229 struct xt_target *target;
1230 unsigned int entry_offset;
1233 duprintf("check_compat_entry_size_and_hooks %p\n", e);
1234 if ((unsigned long)e % __alignof__(struct compat_arpt_entry) != 0 ||
1235 (unsigned char *)e + sizeof(struct compat_arpt_entry) >= limit) {
1236 duprintf("Bad offset %p, limit = %p\n", e, limit);
1240 if (e->next_offset < sizeof(struct compat_arpt_entry) +
1241 sizeof(struct compat_xt_entry_target)) {
1242 duprintf("checking: element %p size %u\n",
1247 /* For purposes of check_entry casting the compat entry is fine */
1248 ret = check_entry((struct arpt_entry *)e, name);
1252 off = sizeof(struct arpt_entry) - sizeof(struct compat_arpt_entry);
1253 entry_offset = (void *)e - (void *)base;
1255 t = compat_arpt_get_target(e);
1256 target = xt_request_find_target(NFPROTO_ARP, t->u.user.name,
1257 t->u.user.revision);
1258 if (IS_ERR(target)) {
1259 duprintf("check_compat_entry_size_and_hooks: `%s' not found\n",
1261 ret = PTR_ERR(target);
1264 t->u.kernel.target = target;
1266 off += xt_compat_target_offset(target);
1268 ret = xt_compat_add_offset(NFPROTO_ARP, entry_offset, off);
1270 goto release_target;
1272 /* Check hooks & underflows */
1273 for (h = 0; h < NF_ARP_NUMHOOKS; h++) {
1274 if ((unsigned char *)e - base == hook_entries[h])
1275 newinfo->hook_entry[h] = hook_entries[h];
1276 if ((unsigned char *)e - base == underflows[h])
1277 newinfo->underflow[h] = underflows[h];
1280 /* Clear counters and comefrom */
1281 memset(&e->counters, 0, sizeof(e->counters));
1286 module_put(t->u.kernel.target->me);
1292 compat_copy_entry_from_user(struct compat_arpt_entry *e, void **dstptr,
1293 unsigned int *size, const char *name,
1294 struct xt_table_info *newinfo, unsigned char *base)
1296 struct xt_entry_target *t;
1297 struct xt_target *target;
1298 struct arpt_entry *de;
1299 unsigned int origsize;
1304 de = (struct arpt_entry *)*dstptr;
1305 memcpy(de, e, sizeof(struct arpt_entry));
1306 memcpy(&de->counters, &e->counters, sizeof(e->counters));
1308 *dstptr += sizeof(struct arpt_entry);
1309 *size += sizeof(struct arpt_entry) - sizeof(struct compat_arpt_entry);
1311 de->target_offset = e->target_offset - (origsize - *size);
1312 t = compat_arpt_get_target(e);
1313 target = t->u.kernel.target;
1314 xt_compat_target_from_user(t, dstptr, size);
1316 de->next_offset = e->next_offset - (origsize - *size);
1317 for (h = 0; h < NF_ARP_NUMHOOKS; h++) {
1318 if ((unsigned char *)de - base < newinfo->hook_entry[h])
1319 newinfo->hook_entry[h] -= origsize - *size;
1320 if ((unsigned char *)de - base < newinfo->underflow[h])
1321 newinfo->underflow[h] -= origsize - *size;
1326 static int translate_compat_table(const char *name,
1327 unsigned int valid_hooks,
1328 struct xt_table_info **pinfo,
1330 unsigned int total_size,
1331 unsigned int number,
1332 unsigned int *hook_entries,
1333 unsigned int *underflows)
1336 struct xt_table_info *newinfo, *info;
1337 void *pos, *entry0, *entry1;
1338 struct compat_arpt_entry *iter0;
1339 struct arpt_entry *iter1;
1346 info->number = number;
1348 /* Init all hooks to impossible value. */
1349 for (i = 0; i < NF_ARP_NUMHOOKS; i++) {
1350 info->hook_entry[i] = 0xFFFFFFFF;
1351 info->underflow[i] = 0xFFFFFFFF;
1354 duprintf("translate_compat_table: size %u\n", info->size);
1356 xt_compat_lock(NFPROTO_ARP);
1357 xt_compat_init_offsets(NFPROTO_ARP, number);
1358 /* Walk through entries, checking offsets. */
1359 xt_entry_foreach(iter0, entry0, total_size) {
1360 ret = check_compat_entry_size_and_hooks(iter0, info, &size,
1362 entry0 + total_size,
1373 duprintf("translate_compat_table: %u not %u entries\n",
1378 /* Check hooks all assigned */
1379 for (i = 0; i < NF_ARP_NUMHOOKS; i++) {
1380 /* Only hooks which are valid */
1381 if (!(valid_hooks & (1 << i)))
1383 if (info->hook_entry[i] == 0xFFFFFFFF) {
1384 duprintf("Invalid hook entry %u %u\n",
1385 i, hook_entries[i]);
1388 if (info->underflow[i] == 0xFFFFFFFF) {
1389 duprintf("Invalid underflow %u %u\n",
1396 newinfo = xt_alloc_table_info(size);
1400 newinfo->number = number;
1401 for (i = 0; i < NF_ARP_NUMHOOKS; i++) {
1402 newinfo->hook_entry[i] = info->hook_entry[i];
1403 newinfo->underflow[i] = info->underflow[i];
1405 entry1 = newinfo->entries;
1408 xt_entry_foreach(iter0, entry0, total_size) {
1409 ret = compat_copy_entry_from_user(iter0, &pos, &size,
1410 name, newinfo, entry1);
1414 xt_compat_flush_offsets(NFPROTO_ARP);
1415 xt_compat_unlock(NFPROTO_ARP);
1420 if (!mark_source_chains(newinfo, valid_hooks, entry1))
1424 xt_entry_foreach(iter1, entry1, newinfo->size) {
1425 iter1->counters.pcnt = xt_percpu_counter_alloc();
1426 if (IS_ERR_VALUE(iter1->counters.pcnt)) {
1431 ret = check_target(iter1, name);
1433 xt_percpu_counter_free(iter1->counters.pcnt);
1437 if (strcmp(arpt_get_target(iter1)->u.user.name,
1438 XT_ERROR_TARGET) == 0)
1439 ++newinfo->stacksize;
1443 * The first i matches need cleanup_entry (calls ->destroy)
1444 * because they had called ->check already. The other j-i
1445 * entries need only release.
1449 xt_entry_foreach(iter0, entry0, newinfo->size) {
1454 compat_release_entry(iter0);
1456 xt_entry_foreach(iter1, entry1, newinfo->size) {
1459 cleanup_entry(iter1);
1461 xt_free_table_info(newinfo);
1467 xt_free_table_info(info);
1471 xt_free_table_info(newinfo);
1473 xt_entry_foreach(iter0, entry0, total_size) {
1476 compat_release_entry(iter0);
1480 xt_compat_flush_offsets(NFPROTO_ARP);
1481 xt_compat_unlock(NFPROTO_ARP);
1485 struct compat_arpt_replace {
1486 char name[XT_TABLE_MAXNAMELEN];
1490 u32 hook_entry[NF_ARP_NUMHOOKS];
1491 u32 underflow[NF_ARP_NUMHOOKS];
1493 compat_uptr_t counters;
1494 struct compat_arpt_entry entries[0];
1497 static int compat_do_replace(struct net *net, void __user *user,
1501 struct compat_arpt_replace tmp;
1502 struct xt_table_info *newinfo;
1503 void *loc_cpu_entry;
1504 struct arpt_entry *iter;
1506 if (copy_from_user(&tmp, user, sizeof(tmp)) != 0)
1509 /* overflow check */
1510 if (tmp.size >= INT_MAX / num_possible_cpus())
1512 if (tmp.num_counters >= INT_MAX / sizeof(struct xt_counters))
1514 if (tmp.num_counters == 0)
1517 tmp.name[sizeof(tmp.name)-1] = 0;
1519 newinfo = xt_alloc_table_info(tmp.size);
1523 loc_cpu_entry = newinfo->entries;
1524 if (copy_from_user(loc_cpu_entry, user + sizeof(tmp), tmp.size) != 0) {
1529 ret = translate_compat_table(tmp.name, tmp.valid_hooks,
1530 &newinfo, &loc_cpu_entry, tmp.size,
1531 tmp.num_entries, tmp.hook_entry,
1536 duprintf("compat_do_replace: Translated table\n");
1538 ret = __do_replace(net, tmp.name, tmp.valid_hooks, newinfo,
1539 tmp.num_counters, compat_ptr(tmp.counters));
1541 goto free_newinfo_untrans;
1544 free_newinfo_untrans:
1545 xt_entry_foreach(iter, loc_cpu_entry, newinfo->size)
1546 cleanup_entry(iter);
1548 xt_free_table_info(newinfo);
1552 static int compat_do_arpt_set_ctl(struct sock *sk, int cmd, void __user *user,
1557 if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN))
1561 case ARPT_SO_SET_REPLACE:
1562 ret = compat_do_replace(sock_net(sk), user, len);
1565 case ARPT_SO_SET_ADD_COUNTERS:
1566 ret = do_add_counters(sock_net(sk), user, len, 1);
1570 duprintf("do_arpt_set_ctl: unknown request %i\n", cmd);
1577 static int compat_copy_entry_to_user(struct arpt_entry *e, void __user **dstptr,
1578 compat_uint_t *size,
1579 struct xt_counters *counters,
1582 struct xt_entry_target *t;
1583 struct compat_arpt_entry __user *ce;
1584 u_int16_t target_offset, next_offset;
1585 compat_uint_t origsize;
1589 ce = (struct compat_arpt_entry __user *)*dstptr;
1590 if (copy_to_user(ce, e, sizeof(struct arpt_entry)) != 0 ||
1591 copy_to_user(&ce->counters, &counters[i],
1592 sizeof(counters[i])) != 0)
1595 *dstptr += sizeof(struct compat_arpt_entry);
1596 *size -= sizeof(struct arpt_entry) - sizeof(struct compat_arpt_entry);
1598 target_offset = e->target_offset - (origsize - *size);
1600 t = arpt_get_target(e);
1601 ret = xt_compat_target_to_user(t, dstptr, size);
1604 next_offset = e->next_offset - (origsize - *size);
1605 if (put_user(target_offset, &ce->target_offset) != 0 ||
1606 put_user(next_offset, &ce->next_offset) != 0)
1611 static int compat_copy_entries_to_user(unsigned int total_size,
1612 struct xt_table *table,
1613 void __user *userptr)
1615 struct xt_counters *counters;
1616 const struct xt_table_info *private = table->private;
1621 struct arpt_entry *iter;
1623 counters = alloc_counters(table);
1624 if (IS_ERR(counters))
1625 return PTR_ERR(counters);
1629 xt_entry_foreach(iter, private->entries, total_size) {
1630 ret = compat_copy_entry_to_user(iter, &pos,
1631 &size, counters, i++);
1639 struct compat_arpt_get_entries {
1640 char name[XT_TABLE_MAXNAMELEN];
1642 struct compat_arpt_entry entrytable[0];
1645 static int compat_get_entries(struct net *net,
1646 struct compat_arpt_get_entries __user *uptr,
1650 struct compat_arpt_get_entries get;
1653 if (*len < sizeof(get)) {
1654 duprintf("compat_get_entries: %u < %zu\n", *len, sizeof(get));
1657 if (copy_from_user(&get, uptr, sizeof(get)) != 0)
1659 if (*len != sizeof(struct compat_arpt_get_entries) + get.size) {
1660 duprintf("compat_get_entries: %u != %zu\n",
1661 *len, sizeof(get) + get.size);
1665 xt_compat_lock(NFPROTO_ARP);
1666 t = xt_find_table_lock(net, NFPROTO_ARP, get.name);
1667 if (!IS_ERR_OR_NULL(t)) {
1668 const struct xt_table_info *private = t->private;
1669 struct xt_table_info info;
1671 duprintf("t->private->number = %u\n", private->number);
1672 ret = compat_table_info(private, &info);
1673 if (!ret && get.size == info.size) {
1674 ret = compat_copy_entries_to_user(private->size,
1675 t, uptr->entrytable);
1677 duprintf("compat_get_entries: I've got %u not %u!\n",
1678 private->size, get.size);
1681 xt_compat_flush_offsets(NFPROTO_ARP);
1685 ret = t ? PTR_ERR(t) : -ENOENT;
1687 xt_compat_unlock(NFPROTO_ARP);
1691 static int do_arpt_get_ctl(struct sock *, int, void __user *, int *);
1693 static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
1698 if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN))
1702 case ARPT_SO_GET_INFO:
1703 ret = get_info(sock_net(sk), user, len, 1);
1705 case ARPT_SO_GET_ENTRIES:
1706 ret = compat_get_entries(sock_net(sk), user, len);
1709 ret = do_arpt_get_ctl(sk, cmd, user, len);
1715 static int do_arpt_set_ctl(struct sock *sk, int cmd, void __user *user, unsigned int len)
1719 if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN))
1723 case ARPT_SO_SET_REPLACE:
1724 ret = do_replace(sock_net(sk), user, len);
1727 case ARPT_SO_SET_ADD_COUNTERS:
1728 ret = do_add_counters(sock_net(sk), user, len, 0);
1732 duprintf("do_arpt_set_ctl: unknown request %i\n", cmd);
1739 static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
1743 if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN))
1747 case ARPT_SO_GET_INFO:
1748 ret = get_info(sock_net(sk), user, len, 0);
1751 case ARPT_SO_GET_ENTRIES:
1752 ret = get_entries(sock_net(sk), user, len);
1755 case ARPT_SO_GET_REVISION_TARGET: {
1756 struct xt_get_revision rev;
1758 if (*len != sizeof(rev)) {
1762 if (copy_from_user(&rev, user, sizeof(rev)) != 0) {
1766 rev.name[sizeof(rev.name)-1] = 0;
1768 try_then_request_module(xt_find_revision(NFPROTO_ARP, rev.name,
1769 rev.revision, 1, &ret),
1770 "arpt_%s", rev.name);
1775 duprintf("do_arpt_get_ctl: unknown request %i\n", cmd);
1782 struct xt_table *arpt_register_table(struct net *net,
1783 const struct xt_table *table,
1784 const struct arpt_replace *repl)
1787 struct xt_table_info *newinfo;
1788 struct xt_table_info bootstrap = {0};
1789 void *loc_cpu_entry;
1790 struct xt_table *new_table;
1792 newinfo = xt_alloc_table_info(repl->size);
1798 loc_cpu_entry = newinfo->entries;
1799 memcpy(loc_cpu_entry, repl->entries, repl->size);
1801 ret = translate_table(newinfo, loc_cpu_entry, repl);
1802 duprintf("arpt_register_table: translate table gives %d\n", ret);
1806 new_table = xt_register_table(net, table, &bootstrap, newinfo);
1807 if (IS_ERR(new_table)) {
1808 ret = PTR_ERR(new_table);
1814 xt_free_table_info(newinfo);
1816 return ERR_PTR(ret);
1819 void arpt_unregister_table(struct xt_table *table)
1821 struct xt_table_info *private;
1822 void *loc_cpu_entry;
1823 struct module *table_owner = table->me;
1824 struct arpt_entry *iter;
1826 private = xt_unregister_table(table);
1828 /* Decrease module usage counts and free resources */
1829 loc_cpu_entry = private->entries;
1830 xt_entry_foreach(iter, loc_cpu_entry, private->size)
1831 cleanup_entry(iter);
1832 if (private->number > private->initial_entries)
1833 module_put(table_owner);
1834 xt_free_table_info(private);
1837 /* The built-in targets: standard (NULL) and error. */
1838 static struct xt_target arpt_builtin_tg[] __read_mostly = {
1840 .name = XT_STANDARD_TARGET,
1841 .targetsize = sizeof(int),
1842 .family = NFPROTO_ARP,
1843 #ifdef CONFIG_COMPAT
1844 .compatsize = sizeof(compat_int_t),
1845 .compat_from_user = compat_standard_from_user,
1846 .compat_to_user = compat_standard_to_user,
1850 .name = XT_ERROR_TARGET,
1851 .target = arpt_error,
1852 .targetsize = XT_FUNCTION_MAXNAMELEN,
1853 .family = NFPROTO_ARP,
1857 static struct nf_sockopt_ops arpt_sockopts = {
1859 .set_optmin = ARPT_BASE_CTL,
1860 .set_optmax = ARPT_SO_SET_MAX+1,
1861 .set = do_arpt_set_ctl,
1862 #ifdef CONFIG_COMPAT
1863 .compat_set = compat_do_arpt_set_ctl,
1865 .get_optmin = ARPT_BASE_CTL,
1866 .get_optmax = ARPT_SO_GET_MAX+1,
1867 .get = do_arpt_get_ctl,
1868 #ifdef CONFIG_COMPAT
1869 .compat_get = compat_do_arpt_get_ctl,
1871 .owner = THIS_MODULE,
1874 static int __net_init arp_tables_net_init(struct net *net)
1876 return xt_proto_init(net, NFPROTO_ARP);
1879 static void __net_exit arp_tables_net_exit(struct net *net)
1881 xt_proto_fini(net, NFPROTO_ARP);
1884 static struct pernet_operations arp_tables_net_ops = {
1885 .init = arp_tables_net_init,
1886 .exit = arp_tables_net_exit,
1889 static int __init arp_tables_init(void)
1893 ret = register_pernet_subsys(&arp_tables_net_ops);
1897 /* No one else will be downing sem now, so we won't sleep */
1898 ret = xt_register_targets(arpt_builtin_tg, ARRAY_SIZE(arpt_builtin_tg));
1902 /* Register setsockopt */
1903 ret = nf_register_sockopt(&arpt_sockopts);
1907 printk(KERN_INFO "arp_tables: (C) 2002 David S. Miller\n");
1911 xt_unregister_targets(arpt_builtin_tg, ARRAY_SIZE(arpt_builtin_tg));
1913 unregister_pernet_subsys(&arp_tables_net_ops);
1918 static void __exit arp_tables_fini(void)
1920 nf_unregister_sockopt(&arpt_sockopts);
1921 xt_unregister_targets(arpt_builtin_tg, ARRAY_SIZE(arpt_builtin_tg));
1922 unregister_pernet_subsys(&arp_tables_net_ops);
1925 EXPORT_SYMBOL(arpt_register_table);
1926 EXPORT_SYMBOL(arpt_unregister_table);
1927 EXPORT_SYMBOL(arpt_do_table);
1929 module_init(arp_tables_init);
1930 module_exit(arp_tables_fini);