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, *back;
258 const char *indev, *outdev;
260 const struct xt_table_info *private;
261 struct xt_action_param acpar;
264 if (!pskb_may_pull(skb, arp_hdr_len(skb->dev)))
267 indev = state->in ? state->in->name : nulldevname;
268 outdev = state->out ? state->out->name : nulldevname;
271 addend = xt_write_recseq_begin();
272 private = table->private;
274 * Ensure we load private-> members after we've fetched the base
277 smp_read_barrier_depends();
278 table_base = private->entries[smp_processor_id()];
280 e = get_entry(table_base, private->hook_entry[hook]);
281 back = get_entry(table_base, private->underflow[hook]);
283 acpar.in = state->in;
284 acpar.out = state->out;
285 acpar.hooknum = hook;
286 acpar.family = NFPROTO_ARP;
287 acpar.hotdrop = false;
291 const struct xt_entry_target *t;
293 if (!arp_packet_match(arp, skb->dev, indev, outdev, &e->arp)) {
294 e = arpt_next_entry(e);
298 ADD_COUNTER(e->counters, arp_hdr_len(skb->dev), 1);
300 t = arpt_get_target_c(e);
302 /* Standard target? */
303 if (!t->u.kernel.target->target) {
306 v = ((struct xt_standard_target *)t)->verdict;
308 /* Pop from stack? */
309 if (v != XT_RETURN) {
310 verdict = (unsigned int)(-v) - 1;
314 back = get_entry(table_base, back->comefrom);
318 != arpt_next_entry(e)) {
319 /* Save old back ptr in next entry */
320 struct arpt_entry *next = arpt_next_entry(e);
321 next->comefrom = (void *)back - table_base;
323 /* set back pointer to next entry */
327 e = get_entry(table_base, v);
331 /* Targets which reenter must return
334 acpar.target = t->u.kernel.target;
335 acpar.targinfo = t->data;
336 verdict = t->u.kernel.target->target(skb, &acpar);
338 /* Target might have changed stuff. */
341 if (verdict == XT_CONTINUE)
342 e = arpt_next_entry(e);
346 } while (!acpar.hotdrop);
347 xt_write_recseq_end(addend);
356 /* All zeroes == unconditional rule. */
357 static inline bool unconditional(const struct arpt_arp *arp)
359 static const struct arpt_arp uncond;
361 return memcmp(arp, &uncond, sizeof(uncond)) == 0;
364 /* Figures out from what hook each rule can be called: returns 0 if
365 * there are loops. Puts hook bitmask in comefrom.
367 static int mark_source_chains(const struct xt_table_info *newinfo,
368 unsigned int valid_hooks, void *entry0)
372 /* No recursion; use packet counter to save back ptrs (reset
373 * to 0 as we leave), and comefrom to save source hook bitmask.
375 for (hook = 0; hook < NF_ARP_NUMHOOKS; hook++) {
376 unsigned int pos = newinfo->hook_entry[hook];
378 = (struct arpt_entry *)(entry0 + pos);
380 if (!(valid_hooks & (1 << hook)))
383 /* Set initial back pointer. */
384 e->counters.pcnt = pos;
387 const struct xt_standard_target *t
388 = (void *)arpt_get_target_c(e);
389 int visited = e->comefrom & (1 << hook);
391 if (e->comefrom & (1 << NF_ARP_NUMHOOKS)) {
392 pr_notice("arptables: loop hook %u pos %u %08X.\n",
393 hook, pos, e->comefrom);
397 |= ((1 << hook) | (1 << NF_ARP_NUMHOOKS));
399 /* Unconditional return/END. */
400 if ((e->target_offset == sizeof(struct arpt_entry) &&
401 (strcmp(t->target.u.user.name,
402 XT_STANDARD_TARGET) == 0) &&
403 t->verdict < 0 && unconditional(&e->arp)) ||
405 unsigned int oldpos, size;
407 if ((strcmp(t->target.u.user.name,
408 XT_STANDARD_TARGET) == 0) &&
409 t->verdict < -NF_MAX_VERDICT - 1) {
410 duprintf("mark_source_chains: bad "
411 "negative verdict (%i)\n",
416 /* Return: backtrack through the last
420 e->comefrom ^= (1<<NF_ARP_NUMHOOKS);
422 pos = e->counters.pcnt;
423 e->counters.pcnt = 0;
425 /* We're at the start. */
429 e = (struct arpt_entry *)
431 } while (oldpos == pos + e->next_offset);
434 size = e->next_offset;
435 e = (struct arpt_entry *)
436 (entry0 + pos + size);
437 e->counters.pcnt = pos;
440 int newpos = t->verdict;
442 if (strcmp(t->target.u.user.name,
443 XT_STANDARD_TARGET) == 0 &&
445 if (newpos > newinfo->size -
446 sizeof(struct arpt_entry)) {
447 duprintf("mark_source_chains: "
448 "bad verdict (%i)\n",
453 /* This a jump; chase it. */
454 duprintf("Jump rule %u -> %u\n",
457 /* ... this is a fallthru */
458 newpos = pos + e->next_offset;
460 e = (struct arpt_entry *)
462 e->counters.pcnt = pos;
467 duprintf("Finished chain %u\n", hook);
472 static inline int check_entry(const struct arpt_entry *e, const char *name)
474 const struct xt_entry_target *t;
476 if (!arp_checkentry(&e->arp)) {
477 duprintf("arp_tables: arp check failed %p %s.\n", e, name);
481 if (e->target_offset + sizeof(struct xt_entry_target) > e->next_offset)
484 t = arpt_get_target_c(e);
485 if (e->target_offset + t->u.target_size > e->next_offset)
491 static inline int check_target(struct arpt_entry *e, const char *name)
493 struct xt_entry_target *t = arpt_get_target(e);
495 struct xt_tgchk_param par = {
498 .target = t->u.kernel.target,
500 .hook_mask = e->comefrom,
501 .family = NFPROTO_ARP,
504 ret = xt_check_target(&par, t->u.target_size - sizeof(*t), 0, false);
506 duprintf("arp_tables: check failed for `%s'.\n",
507 t->u.kernel.target->name);
514 find_check_entry(struct arpt_entry *e, const char *name, unsigned int size)
516 struct xt_entry_target *t;
517 struct xt_target *target;
520 ret = check_entry(e, name);
524 t = arpt_get_target(e);
525 target = xt_request_find_target(NFPROTO_ARP, t->u.user.name,
527 if (IS_ERR(target)) {
528 duprintf("find_check_entry: `%s' not found\n", t->u.user.name);
529 ret = PTR_ERR(target);
532 t->u.kernel.target = target;
534 ret = check_target(e, name);
539 module_put(t->u.kernel.target->me);
544 static bool check_underflow(const struct arpt_entry *e)
546 const struct xt_entry_target *t;
547 unsigned int verdict;
549 if (!unconditional(&e->arp))
551 t = arpt_get_target_c(e);
552 if (strcmp(t->u.user.name, XT_STANDARD_TARGET) != 0)
554 verdict = ((struct xt_standard_target *)t)->verdict;
555 verdict = -verdict - 1;
556 return verdict == NF_DROP || verdict == NF_ACCEPT;
559 static inline int check_entry_size_and_hooks(struct arpt_entry *e,
560 struct xt_table_info *newinfo,
561 const unsigned char *base,
562 const unsigned char *limit,
563 const unsigned int *hook_entries,
564 const unsigned int *underflows,
565 unsigned int valid_hooks)
569 if ((unsigned long)e % __alignof__(struct arpt_entry) != 0 ||
570 (unsigned char *)e + sizeof(struct arpt_entry) >= limit) {
571 duprintf("Bad offset %p\n", e);
576 < sizeof(struct arpt_entry) + sizeof(struct xt_entry_target)) {
577 duprintf("checking: element %p size %u\n",
582 /* Check hooks & underflows */
583 for (h = 0; h < NF_ARP_NUMHOOKS; h++) {
584 if (!(valid_hooks & (1 << h)))
586 if ((unsigned char *)e - base == hook_entries[h])
587 newinfo->hook_entry[h] = hook_entries[h];
588 if ((unsigned char *)e - base == underflows[h]) {
589 if (!check_underflow(e)) {
590 pr_err("Underflows must be unconditional and "
591 "use the STANDARD target with "
595 newinfo->underflow[h] = underflows[h];
599 /* Clear counters and comefrom */
600 e->counters = ((struct xt_counters) { 0, 0 });
605 static inline void cleanup_entry(struct arpt_entry *e)
607 struct xt_tgdtor_param par;
608 struct xt_entry_target *t;
610 t = arpt_get_target(e);
611 par.target = t->u.kernel.target;
612 par.targinfo = t->data;
613 par.family = NFPROTO_ARP;
614 if (par.target->destroy != NULL)
615 par.target->destroy(&par);
616 module_put(par.target->me);
619 /* Checks and translates the user-supplied table segment (held in
622 static int translate_table(struct xt_table_info *newinfo, void *entry0,
623 const struct arpt_replace *repl)
625 struct arpt_entry *iter;
629 newinfo->size = repl->size;
630 newinfo->number = repl->num_entries;
632 /* Init all hooks to impossible value. */
633 for (i = 0; i < NF_ARP_NUMHOOKS; i++) {
634 newinfo->hook_entry[i] = 0xFFFFFFFF;
635 newinfo->underflow[i] = 0xFFFFFFFF;
638 duprintf("translate_table: size %u\n", newinfo->size);
641 /* Walk through entries, checking offsets. */
642 xt_entry_foreach(iter, entry0, newinfo->size) {
643 ret = check_entry_size_and_hooks(iter, newinfo, entry0,
651 if (strcmp(arpt_get_target(iter)->u.user.name,
652 XT_ERROR_TARGET) == 0)
653 ++newinfo->stacksize;
655 duprintf("translate_table: ARPT_ENTRY_ITERATE gives %d\n", ret);
659 if (i != repl->num_entries) {
660 duprintf("translate_table: %u not %u entries\n",
661 i, repl->num_entries);
665 /* Check hooks all assigned */
666 for (i = 0; i < NF_ARP_NUMHOOKS; i++) {
667 /* Only hooks which are valid */
668 if (!(repl->valid_hooks & (1 << i)))
670 if (newinfo->hook_entry[i] == 0xFFFFFFFF) {
671 duprintf("Invalid hook entry %u %u\n",
672 i, repl->hook_entry[i]);
675 if (newinfo->underflow[i] == 0xFFFFFFFF) {
676 duprintf("Invalid underflow %u %u\n",
677 i, repl->underflow[i]);
682 if (!mark_source_chains(newinfo, repl->valid_hooks, entry0)) {
683 duprintf("Looping hook\n");
687 /* Finally, each sanity check must pass */
689 xt_entry_foreach(iter, entry0, newinfo->size) {
690 ret = find_check_entry(iter, repl->name, repl->size);
697 xt_entry_foreach(iter, entry0, newinfo->size) {
705 /* And one copy for every other CPU */
706 for_each_possible_cpu(i) {
707 if (newinfo->entries[i] && newinfo->entries[i] != entry0)
708 memcpy(newinfo->entries[i], entry0, newinfo->size);
714 static void get_counters(const struct xt_table_info *t,
715 struct xt_counters counters[])
717 struct arpt_entry *iter;
721 for_each_possible_cpu(cpu) {
722 seqcount_t *s = &per_cpu(xt_recseq, cpu);
725 xt_entry_foreach(iter, t->entries[cpu], t->size) {
730 start = read_seqcount_begin(s);
731 bcnt = iter->counters.bcnt;
732 pcnt = iter->counters.pcnt;
733 } while (read_seqcount_retry(s, start));
735 ADD_COUNTER(counters[i], bcnt, pcnt);
741 static struct xt_counters *alloc_counters(const struct xt_table *table)
743 unsigned int countersize;
744 struct xt_counters *counters;
745 const struct xt_table_info *private = table->private;
747 /* We need atomic snapshot of counters: rest doesn't change
748 * (other than comefrom, which userspace doesn't care
751 countersize = sizeof(struct xt_counters) * private->number;
752 counters = vzalloc(countersize);
754 if (counters == NULL)
755 return ERR_PTR(-ENOMEM);
757 get_counters(private, counters);
762 static int copy_entries_to_user(unsigned int total_size,
763 const struct xt_table *table,
764 void __user *userptr)
766 unsigned int off, num;
767 const struct arpt_entry *e;
768 struct xt_counters *counters;
769 struct xt_table_info *private = table->private;
773 counters = alloc_counters(table);
774 if (IS_ERR(counters))
775 return PTR_ERR(counters);
777 loc_cpu_entry = private->entries[raw_smp_processor_id()];
778 /* ... then copy entire thing ... */
779 if (copy_to_user(userptr, loc_cpu_entry, total_size) != 0) {
784 /* FIXME: use iterator macros --RR */
785 /* ... then go back and fix counters and names */
786 for (off = 0, num = 0; off < total_size; off += e->next_offset, num++){
787 const struct xt_entry_target *t;
789 e = (struct arpt_entry *)(loc_cpu_entry + off);
790 if (copy_to_user(userptr + off
791 + offsetof(struct arpt_entry, counters),
793 sizeof(counters[num])) != 0) {
798 t = arpt_get_target_c(e);
799 if (copy_to_user(userptr + off + e->target_offset
800 + offsetof(struct xt_entry_target,
802 t->u.kernel.target->name,
803 strlen(t->u.kernel.target->name)+1) != 0) {
815 static void compat_standard_from_user(void *dst, const void *src)
817 int v = *(compat_int_t *)src;
820 v += xt_compat_calc_jump(NFPROTO_ARP, v);
821 memcpy(dst, &v, sizeof(v));
824 static int compat_standard_to_user(void __user *dst, const void *src)
826 compat_int_t cv = *(int *)src;
829 cv -= xt_compat_calc_jump(NFPROTO_ARP, cv);
830 return copy_to_user(dst, &cv, sizeof(cv)) ? -EFAULT : 0;
833 static int compat_calc_entry(const struct arpt_entry *e,
834 const struct xt_table_info *info,
835 const void *base, struct xt_table_info *newinfo)
837 const struct xt_entry_target *t;
838 unsigned int entry_offset;
841 off = sizeof(struct arpt_entry) - sizeof(struct compat_arpt_entry);
842 entry_offset = (void *)e - base;
844 t = arpt_get_target_c(e);
845 off += xt_compat_target_offset(t->u.kernel.target);
846 newinfo->size -= off;
847 ret = xt_compat_add_offset(NFPROTO_ARP, entry_offset, off);
851 for (i = 0; i < NF_ARP_NUMHOOKS; i++) {
852 if (info->hook_entry[i] &&
853 (e < (struct arpt_entry *)(base + info->hook_entry[i])))
854 newinfo->hook_entry[i] -= off;
855 if (info->underflow[i] &&
856 (e < (struct arpt_entry *)(base + info->underflow[i])))
857 newinfo->underflow[i] -= off;
862 static int compat_table_info(const struct xt_table_info *info,
863 struct xt_table_info *newinfo)
865 struct arpt_entry *iter;
869 if (!newinfo || !info)
872 /* we dont care about newinfo->entries[] */
873 memcpy(newinfo, info, offsetof(struct xt_table_info, entries));
874 newinfo->initial_entries = 0;
875 loc_cpu_entry = info->entries[raw_smp_processor_id()];
876 xt_compat_init_offsets(NFPROTO_ARP, info->number);
877 xt_entry_foreach(iter, loc_cpu_entry, info->size) {
878 ret = compat_calc_entry(iter, info, loc_cpu_entry, newinfo);
886 static int get_info(struct net *net, void __user *user,
887 const int *len, int compat)
889 char name[XT_TABLE_MAXNAMELEN];
893 if (*len != sizeof(struct arpt_getinfo)) {
894 duprintf("length %u != %Zu\n", *len,
895 sizeof(struct arpt_getinfo));
899 if (copy_from_user(name, user, sizeof(name)) != 0)
902 name[XT_TABLE_MAXNAMELEN-1] = '\0';
905 xt_compat_lock(NFPROTO_ARP);
907 t = try_then_request_module(xt_find_table_lock(net, NFPROTO_ARP, name),
908 "arptable_%s", name);
909 if (!IS_ERR_OR_NULL(t)) {
910 struct arpt_getinfo info;
911 const struct xt_table_info *private = t->private;
913 struct xt_table_info tmp;
916 ret = compat_table_info(private, &tmp);
917 xt_compat_flush_offsets(NFPROTO_ARP);
921 memset(&info, 0, sizeof(info));
922 info.valid_hooks = t->valid_hooks;
923 memcpy(info.hook_entry, private->hook_entry,
924 sizeof(info.hook_entry));
925 memcpy(info.underflow, private->underflow,
926 sizeof(info.underflow));
927 info.num_entries = private->number;
928 info.size = private->size;
929 strcpy(info.name, name);
931 if (copy_to_user(user, &info, *len) != 0)
938 ret = t ? PTR_ERR(t) : -ENOENT;
941 xt_compat_unlock(NFPROTO_ARP);
946 static int get_entries(struct net *net, struct arpt_get_entries __user *uptr,
950 struct arpt_get_entries get;
953 if (*len < sizeof(get)) {
954 duprintf("get_entries: %u < %Zu\n", *len, sizeof(get));
957 if (copy_from_user(&get, uptr, sizeof(get)) != 0)
959 if (*len != sizeof(struct arpt_get_entries) + get.size) {
960 duprintf("get_entries: %u != %Zu\n", *len,
961 sizeof(struct arpt_get_entries) + get.size);
965 t = xt_find_table_lock(net, NFPROTO_ARP, get.name);
966 if (!IS_ERR_OR_NULL(t)) {
967 const struct xt_table_info *private = t->private;
969 duprintf("t->private->number = %u\n",
971 if (get.size == private->size)
972 ret = copy_entries_to_user(private->size,
973 t, uptr->entrytable);
975 duprintf("get_entries: I've got %u not %u!\n",
976 private->size, get.size);
982 ret = t ? PTR_ERR(t) : -ENOENT;
987 static int __do_replace(struct net *net, const char *name,
988 unsigned int valid_hooks,
989 struct xt_table_info *newinfo,
990 unsigned int num_counters,
991 void __user *counters_ptr)
995 struct xt_table_info *oldinfo;
996 struct xt_counters *counters;
997 void *loc_cpu_old_entry;
998 struct arpt_entry *iter;
1001 counters = vzalloc(num_counters * sizeof(struct xt_counters));
1007 t = try_then_request_module(xt_find_table_lock(net, NFPROTO_ARP, name),
1008 "arptable_%s", name);
1009 if (IS_ERR_OR_NULL(t)) {
1010 ret = t ? PTR_ERR(t) : -ENOENT;
1011 goto free_newinfo_counters_untrans;
1015 if (valid_hooks != t->valid_hooks) {
1016 duprintf("Valid hook crap: %08X vs %08X\n",
1017 valid_hooks, t->valid_hooks);
1022 oldinfo = xt_replace_table(t, num_counters, newinfo, &ret);
1026 /* Update module usage count based on number of rules */
1027 duprintf("do_replace: oldnum=%u, initnum=%u, newnum=%u\n",
1028 oldinfo->number, oldinfo->initial_entries, newinfo->number);
1029 if ((oldinfo->number > oldinfo->initial_entries) ||
1030 (newinfo->number <= oldinfo->initial_entries))
1032 if ((oldinfo->number > oldinfo->initial_entries) &&
1033 (newinfo->number <= oldinfo->initial_entries))
1036 /* Get the old counters, and synchronize with replace */
1037 get_counters(oldinfo, counters);
1039 /* Decrease module usage counts and free resource */
1040 loc_cpu_old_entry = oldinfo->entries[raw_smp_processor_id()];
1041 xt_entry_foreach(iter, loc_cpu_old_entry, oldinfo->size)
1042 cleanup_entry(iter);
1044 xt_free_table_info(oldinfo);
1045 if (copy_to_user(counters_ptr, counters,
1046 sizeof(struct xt_counters) * num_counters) != 0) {
1047 /* Silent error, can't fail, new table is already in place */
1048 net_warn_ratelimited("arptables: counters copy to user failed while replacing table\n");
1057 free_newinfo_counters_untrans:
1063 static int do_replace(struct net *net, const void __user *user,
1067 struct arpt_replace tmp;
1068 struct xt_table_info *newinfo;
1069 void *loc_cpu_entry;
1070 struct arpt_entry *iter;
1072 if (copy_from_user(&tmp, user, sizeof(tmp)) != 0)
1075 /* overflow check */
1076 if (tmp.num_counters >= INT_MAX / sizeof(struct xt_counters))
1078 tmp.name[sizeof(tmp.name)-1] = 0;
1080 newinfo = xt_alloc_table_info(tmp.size);
1084 /* choose the copy that is on our node/cpu */
1085 loc_cpu_entry = newinfo->entries[raw_smp_processor_id()];
1086 if (copy_from_user(loc_cpu_entry, user + sizeof(tmp),
1092 ret = translate_table(newinfo, loc_cpu_entry, &tmp);
1096 duprintf("arp_tables: Translated table\n");
1098 ret = __do_replace(net, tmp.name, tmp.valid_hooks, newinfo,
1099 tmp.num_counters, tmp.counters);
1101 goto free_newinfo_untrans;
1104 free_newinfo_untrans:
1105 xt_entry_foreach(iter, loc_cpu_entry, newinfo->size)
1106 cleanup_entry(iter);
1108 xt_free_table_info(newinfo);
1112 static int do_add_counters(struct net *net, const void __user *user,
1113 unsigned int len, int compat)
1115 unsigned int i, curcpu;
1116 struct xt_counters_info tmp;
1117 struct xt_counters *paddc;
1118 unsigned int num_counters;
1123 const struct xt_table_info *private;
1125 void *loc_cpu_entry;
1126 struct arpt_entry *iter;
1127 unsigned int addend;
1128 #ifdef CONFIG_COMPAT
1129 struct compat_xt_counters_info compat_tmp;
1133 size = sizeof(struct compat_xt_counters_info);
1138 size = sizeof(struct xt_counters_info);
1141 if (copy_from_user(ptmp, user, size) != 0)
1144 #ifdef CONFIG_COMPAT
1146 num_counters = compat_tmp.num_counters;
1147 name = compat_tmp.name;
1151 num_counters = tmp.num_counters;
1155 if (len != size + num_counters * sizeof(struct xt_counters))
1158 paddc = vmalloc(len - size);
1162 if (copy_from_user(paddc, user + size, len - size) != 0) {
1167 t = xt_find_table_lock(net, NFPROTO_ARP, name);
1168 if (IS_ERR_OR_NULL(t)) {
1169 ret = t ? PTR_ERR(t) : -ENOENT;
1174 private = t->private;
1175 if (private->number != num_counters) {
1177 goto unlock_up_free;
1181 /* Choose the copy that is on our node */
1182 curcpu = smp_processor_id();
1183 loc_cpu_entry = private->entries[curcpu];
1184 addend = xt_write_recseq_begin();
1185 xt_entry_foreach(iter, loc_cpu_entry, private->size) {
1186 ADD_COUNTER(iter->counters, paddc[i].bcnt, paddc[i].pcnt);
1189 xt_write_recseq_end(addend);
1200 #ifdef CONFIG_COMPAT
1201 static inline void compat_release_entry(struct compat_arpt_entry *e)
1203 struct xt_entry_target *t;
1205 t = compat_arpt_get_target(e);
1206 module_put(t->u.kernel.target->me);
1210 check_compat_entry_size_and_hooks(struct compat_arpt_entry *e,
1211 struct xt_table_info *newinfo,
1213 const unsigned char *base,
1214 const unsigned char *limit,
1215 const unsigned int *hook_entries,
1216 const unsigned int *underflows,
1219 struct xt_entry_target *t;
1220 struct xt_target *target;
1221 unsigned int entry_offset;
1224 duprintf("check_compat_entry_size_and_hooks %p\n", e);
1225 if ((unsigned long)e % __alignof__(struct compat_arpt_entry) != 0 ||
1226 (unsigned char *)e + sizeof(struct compat_arpt_entry) >= limit) {
1227 duprintf("Bad offset %p, limit = %p\n", e, limit);
1231 if (e->next_offset < sizeof(struct compat_arpt_entry) +
1232 sizeof(struct compat_xt_entry_target)) {
1233 duprintf("checking: element %p size %u\n",
1238 /* For purposes of check_entry casting the compat entry is fine */
1239 ret = check_entry((struct arpt_entry *)e, name);
1243 off = sizeof(struct arpt_entry) - sizeof(struct compat_arpt_entry);
1244 entry_offset = (void *)e - (void *)base;
1246 t = compat_arpt_get_target(e);
1247 target = xt_request_find_target(NFPROTO_ARP, t->u.user.name,
1248 t->u.user.revision);
1249 if (IS_ERR(target)) {
1250 duprintf("check_compat_entry_size_and_hooks: `%s' not found\n",
1252 ret = PTR_ERR(target);
1255 t->u.kernel.target = target;
1257 off += xt_compat_target_offset(target);
1259 ret = xt_compat_add_offset(NFPROTO_ARP, entry_offset, off);
1261 goto release_target;
1263 /* Check hooks & underflows */
1264 for (h = 0; h < NF_ARP_NUMHOOKS; h++) {
1265 if ((unsigned char *)e - base == hook_entries[h])
1266 newinfo->hook_entry[h] = hook_entries[h];
1267 if ((unsigned char *)e - base == underflows[h])
1268 newinfo->underflow[h] = underflows[h];
1271 /* Clear counters and comefrom */
1272 memset(&e->counters, 0, sizeof(e->counters));
1277 module_put(t->u.kernel.target->me);
1283 compat_copy_entry_from_user(struct compat_arpt_entry *e, void **dstptr,
1284 unsigned int *size, const char *name,
1285 struct xt_table_info *newinfo, unsigned char *base)
1287 struct xt_entry_target *t;
1288 struct xt_target *target;
1289 struct arpt_entry *de;
1290 unsigned int origsize;
1295 de = (struct arpt_entry *)*dstptr;
1296 memcpy(de, e, sizeof(struct arpt_entry));
1297 memcpy(&de->counters, &e->counters, sizeof(e->counters));
1299 *dstptr += sizeof(struct arpt_entry);
1300 *size += sizeof(struct arpt_entry) - sizeof(struct compat_arpt_entry);
1302 de->target_offset = e->target_offset - (origsize - *size);
1303 t = compat_arpt_get_target(e);
1304 target = t->u.kernel.target;
1305 xt_compat_target_from_user(t, dstptr, size);
1307 de->next_offset = e->next_offset - (origsize - *size);
1308 for (h = 0; h < NF_ARP_NUMHOOKS; h++) {
1309 if ((unsigned char *)de - base < newinfo->hook_entry[h])
1310 newinfo->hook_entry[h] -= origsize - *size;
1311 if ((unsigned char *)de - base < newinfo->underflow[h])
1312 newinfo->underflow[h] -= origsize - *size;
1317 static int translate_compat_table(const char *name,
1318 unsigned int valid_hooks,
1319 struct xt_table_info **pinfo,
1321 unsigned int total_size,
1322 unsigned int number,
1323 unsigned int *hook_entries,
1324 unsigned int *underflows)
1327 struct xt_table_info *newinfo, *info;
1328 void *pos, *entry0, *entry1;
1329 struct compat_arpt_entry *iter0;
1330 struct arpt_entry *iter1;
1337 info->number = number;
1339 /* Init all hooks to impossible value. */
1340 for (i = 0; i < NF_ARP_NUMHOOKS; i++) {
1341 info->hook_entry[i] = 0xFFFFFFFF;
1342 info->underflow[i] = 0xFFFFFFFF;
1345 duprintf("translate_compat_table: size %u\n", info->size);
1347 xt_compat_lock(NFPROTO_ARP);
1348 xt_compat_init_offsets(NFPROTO_ARP, number);
1349 /* Walk through entries, checking offsets. */
1350 xt_entry_foreach(iter0, entry0, total_size) {
1351 ret = check_compat_entry_size_and_hooks(iter0, info, &size,
1353 entry0 + total_size,
1364 duprintf("translate_compat_table: %u not %u entries\n",
1369 /* Check hooks all assigned */
1370 for (i = 0; i < NF_ARP_NUMHOOKS; i++) {
1371 /* Only hooks which are valid */
1372 if (!(valid_hooks & (1 << i)))
1374 if (info->hook_entry[i] == 0xFFFFFFFF) {
1375 duprintf("Invalid hook entry %u %u\n",
1376 i, hook_entries[i]);
1379 if (info->underflow[i] == 0xFFFFFFFF) {
1380 duprintf("Invalid underflow %u %u\n",
1387 newinfo = xt_alloc_table_info(size);
1391 newinfo->number = number;
1392 for (i = 0; i < NF_ARP_NUMHOOKS; i++) {
1393 newinfo->hook_entry[i] = info->hook_entry[i];
1394 newinfo->underflow[i] = info->underflow[i];
1396 entry1 = newinfo->entries[raw_smp_processor_id()];
1399 xt_entry_foreach(iter0, entry0, total_size) {
1400 ret = compat_copy_entry_from_user(iter0, &pos, &size,
1401 name, newinfo, entry1);
1405 xt_compat_flush_offsets(NFPROTO_ARP);
1406 xt_compat_unlock(NFPROTO_ARP);
1411 if (!mark_source_chains(newinfo, valid_hooks, entry1))
1415 xt_entry_foreach(iter1, entry1, newinfo->size) {
1416 ret = check_target(iter1, name);
1420 if (strcmp(arpt_get_target(iter1)->u.user.name,
1421 XT_ERROR_TARGET) == 0)
1422 ++newinfo->stacksize;
1426 * The first i matches need cleanup_entry (calls ->destroy)
1427 * because they had called ->check already. The other j-i
1428 * entries need only release.
1432 xt_entry_foreach(iter0, entry0, newinfo->size) {
1437 compat_release_entry(iter0);
1439 xt_entry_foreach(iter1, entry1, newinfo->size) {
1442 cleanup_entry(iter1);
1444 xt_free_table_info(newinfo);
1448 /* And one copy for every other CPU */
1449 for_each_possible_cpu(i)
1450 if (newinfo->entries[i] && newinfo->entries[i] != entry1)
1451 memcpy(newinfo->entries[i], entry1, newinfo->size);
1455 xt_free_table_info(info);
1459 xt_free_table_info(newinfo);
1461 xt_entry_foreach(iter0, entry0, total_size) {
1464 compat_release_entry(iter0);
1468 xt_compat_flush_offsets(NFPROTO_ARP);
1469 xt_compat_unlock(NFPROTO_ARP);
1473 struct compat_arpt_replace {
1474 char name[XT_TABLE_MAXNAMELEN];
1478 u32 hook_entry[NF_ARP_NUMHOOKS];
1479 u32 underflow[NF_ARP_NUMHOOKS];
1481 compat_uptr_t counters;
1482 struct compat_arpt_entry entries[0];
1485 static int compat_do_replace(struct net *net, void __user *user,
1489 struct compat_arpt_replace tmp;
1490 struct xt_table_info *newinfo;
1491 void *loc_cpu_entry;
1492 struct arpt_entry *iter;
1494 if (copy_from_user(&tmp, user, sizeof(tmp)) != 0)
1497 /* overflow check */
1498 if (tmp.size >= INT_MAX / num_possible_cpus())
1500 if (tmp.num_counters >= INT_MAX / sizeof(struct xt_counters))
1502 tmp.name[sizeof(tmp.name)-1] = 0;
1504 newinfo = xt_alloc_table_info(tmp.size);
1508 /* choose the copy that is on our node/cpu */
1509 loc_cpu_entry = newinfo->entries[raw_smp_processor_id()];
1510 if (copy_from_user(loc_cpu_entry, user + sizeof(tmp), tmp.size) != 0) {
1515 ret = translate_compat_table(tmp.name, tmp.valid_hooks,
1516 &newinfo, &loc_cpu_entry, tmp.size,
1517 tmp.num_entries, tmp.hook_entry,
1522 duprintf("compat_do_replace: Translated table\n");
1524 ret = __do_replace(net, tmp.name, tmp.valid_hooks, newinfo,
1525 tmp.num_counters, compat_ptr(tmp.counters));
1527 goto free_newinfo_untrans;
1530 free_newinfo_untrans:
1531 xt_entry_foreach(iter, loc_cpu_entry, newinfo->size)
1532 cleanup_entry(iter);
1534 xt_free_table_info(newinfo);
1538 static int compat_do_arpt_set_ctl(struct sock *sk, int cmd, void __user *user,
1543 if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN))
1547 case ARPT_SO_SET_REPLACE:
1548 ret = compat_do_replace(sock_net(sk), user, len);
1551 case ARPT_SO_SET_ADD_COUNTERS:
1552 ret = do_add_counters(sock_net(sk), user, len, 1);
1556 duprintf("do_arpt_set_ctl: unknown request %i\n", cmd);
1563 static int compat_copy_entry_to_user(struct arpt_entry *e, void __user **dstptr,
1564 compat_uint_t *size,
1565 struct xt_counters *counters,
1568 struct xt_entry_target *t;
1569 struct compat_arpt_entry __user *ce;
1570 u_int16_t target_offset, next_offset;
1571 compat_uint_t origsize;
1575 ce = (struct compat_arpt_entry __user *)*dstptr;
1576 if (copy_to_user(ce, e, sizeof(struct arpt_entry)) != 0 ||
1577 copy_to_user(&ce->counters, &counters[i],
1578 sizeof(counters[i])) != 0)
1581 *dstptr += sizeof(struct compat_arpt_entry);
1582 *size -= sizeof(struct arpt_entry) - sizeof(struct compat_arpt_entry);
1584 target_offset = e->target_offset - (origsize - *size);
1586 t = arpt_get_target(e);
1587 ret = xt_compat_target_to_user(t, dstptr, size);
1590 next_offset = e->next_offset - (origsize - *size);
1591 if (put_user(target_offset, &ce->target_offset) != 0 ||
1592 put_user(next_offset, &ce->next_offset) != 0)
1597 static int compat_copy_entries_to_user(unsigned int total_size,
1598 struct xt_table *table,
1599 void __user *userptr)
1601 struct xt_counters *counters;
1602 const struct xt_table_info *private = table->private;
1606 void *loc_cpu_entry;
1608 struct arpt_entry *iter;
1610 counters = alloc_counters(table);
1611 if (IS_ERR(counters))
1612 return PTR_ERR(counters);
1614 /* choose the copy on our node/cpu */
1615 loc_cpu_entry = private->entries[raw_smp_processor_id()];
1618 xt_entry_foreach(iter, loc_cpu_entry, total_size) {
1619 ret = compat_copy_entry_to_user(iter, &pos,
1620 &size, counters, i++);
1628 struct compat_arpt_get_entries {
1629 char name[XT_TABLE_MAXNAMELEN];
1631 struct compat_arpt_entry entrytable[0];
1634 static int compat_get_entries(struct net *net,
1635 struct compat_arpt_get_entries __user *uptr,
1639 struct compat_arpt_get_entries get;
1642 if (*len < sizeof(get)) {
1643 duprintf("compat_get_entries: %u < %zu\n", *len, sizeof(get));
1646 if (copy_from_user(&get, uptr, sizeof(get)) != 0)
1648 if (*len != sizeof(struct compat_arpt_get_entries) + get.size) {
1649 duprintf("compat_get_entries: %u != %zu\n",
1650 *len, sizeof(get) + get.size);
1654 xt_compat_lock(NFPROTO_ARP);
1655 t = xt_find_table_lock(net, NFPROTO_ARP, get.name);
1656 if (!IS_ERR_OR_NULL(t)) {
1657 const struct xt_table_info *private = t->private;
1658 struct xt_table_info info;
1660 duprintf("t->private->number = %u\n", private->number);
1661 ret = compat_table_info(private, &info);
1662 if (!ret && get.size == info.size) {
1663 ret = compat_copy_entries_to_user(private->size,
1664 t, uptr->entrytable);
1666 duprintf("compat_get_entries: I've got %u not %u!\n",
1667 private->size, get.size);
1670 xt_compat_flush_offsets(NFPROTO_ARP);
1674 ret = t ? PTR_ERR(t) : -ENOENT;
1676 xt_compat_unlock(NFPROTO_ARP);
1680 static int do_arpt_get_ctl(struct sock *, int, void __user *, int *);
1682 static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
1687 if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN))
1691 case ARPT_SO_GET_INFO:
1692 ret = get_info(sock_net(sk), user, len, 1);
1694 case ARPT_SO_GET_ENTRIES:
1695 ret = compat_get_entries(sock_net(sk), user, len);
1698 ret = do_arpt_get_ctl(sk, cmd, user, len);
1704 static int do_arpt_set_ctl(struct sock *sk, int cmd, void __user *user, unsigned int len)
1708 if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN))
1712 case ARPT_SO_SET_REPLACE:
1713 ret = do_replace(sock_net(sk), user, len);
1716 case ARPT_SO_SET_ADD_COUNTERS:
1717 ret = do_add_counters(sock_net(sk), user, len, 0);
1721 duprintf("do_arpt_set_ctl: unknown request %i\n", cmd);
1728 static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
1732 if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN))
1736 case ARPT_SO_GET_INFO:
1737 ret = get_info(sock_net(sk), user, len, 0);
1740 case ARPT_SO_GET_ENTRIES:
1741 ret = get_entries(sock_net(sk), user, len);
1744 case ARPT_SO_GET_REVISION_TARGET: {
1745 struct xt_get_revision rev;
1747 if (*len != sizeof(rev)) {
1751 if (copy_from_user(&rev, user, sizeof(rev)) != 0) {
1755 rev.name[sizeof(rev.name)-1] = 0;
1757 try_then_request_module(xt_find_revision(NFPROTO_ARP, rev.name,
1758 rev.revision, 1, &ret),
1759 "arpt_%s", rev.name);
1764 duprintf("do_arpt_get_ctl: unknown request %i\n", cmd);
1771 struct xt_table *arpt_register_table(struct net *net,
1772 const struct xt_table *table,
1773 const struct arpt_replace *repl)
1776 struct xt_table_info *newinfo;
1777 struct xt_table_info bootstrap = {0};
1778 void *loc_cpu_entry;
1779 struct xt_table *new_table;
1781 newinfo = xt_alloc_table_info(repl->size);
1787 /* choose the copy on our node/cpu */
1788 loc_cpu_entry = newinfo->entries[raw_smp_processor_id()];
1789 memcpy(loc_cpu_entry, repl->entries, repl->size);
1791 ret = translate_table(newinfo, loc_cpu_entry, repl);
1792 duprintf("arpt_register_table: translate table gives %d\n", ret);
1796 new_table = xt_register_table(net, table, &bootstrap, newinfo);
1797 if (IS_ERR(new_table)) {
1798 ret = PTR_ERR(new_table);
1804 xt_free_table_info(newinfo);
1806 return ERR_PTR(ret);
1809 void arpt_unregister_table(struct xt_table *table)
1811 struct xt_table_info *private;
1812 void *loc_cpu_entry;
1813 struct module *table_owner = table->me;
1814 struct arpt_entry *iter;
1816 private = xt_unregister_table(table);
1818 /* Decrease module usage counts and free resources */
1819 loc_cpu_entry = private->entries[raw_smp_processor_id()];
1820 xt_entry_foreach(iter, loc_cpu_entry, private->size)
1821 cleanup_entry(iter);
1822 if (private->number > private->initial_entries)
1823 module_put(table_owner);
1824 xt_free_table_info(private);
1827 /* The built-in targets: standard (NULL) and error. */
1828 static struct xt_target arpt_builtin_tg[] __read_mostly = {
1830 .name = XT_STANDARD_TARGET,
1831 .targetsize = sizeof(int),
1832 .family = NFPROTO_ARP,
1833 #ifdef CONFIG_COMPAT
1834 .compatsize = sizeof(compat_int_t),
1835 .compat_from_user = compat_standard_from_user,
1836 .compat_to_user = compat_standard_to_user,
1840 .name = XT_ERROR_TARGET,
1841 .target = arpt_error,
1842 .targetsize = XT_FUNCTION_MAXNAMELEN,
1843 .family = NFPROTO_ARP,
1847 static struct nf_sockopt_ops arpt_sockopts = {
1849 .set_optmin = ARPT_BASE_CTL,
1850 .set_optmax = ARPT_SO_SET_MAX+1,
1851 .set = do_arpt_set_ctl,
1852 #ifdef CONFIG_COMPAT
1853 .compat_set = compat_do_arpt_set_ctl,
1855 .get_optmin = ARPT_BASE_CTL,
1856 .get_optmax = ARPT_SO_GET_MAX+1,
1857 .get = do_arpt_get_ctl,
1858 #ifdef CONFIG_COMPAT
1859 .compat_get = compat_do_arpt_get_ctl,
1861 .owner = THIS_MODULE,
1864 static int __net_init arp_tables_net_init(struct net *net)
1866 return xt_proto_init(net, NFPROTO_ARP);
1869 static void __net_exit arp_tables_net_exit(struct net *net)
1871 xt_proto_fini(net, NFPROTO_ARP);
1874 static struct pernet_operations arp_tables_net_ops = {
1875 .init = arp_tables_net_init,
1876 .exit = arp_tables_net_exit,
1879 static int __init arp_tables_init(void)
1883 ret = register_pernet_subsys(&arp_tables_net_ops);
1887 /* No one else will be downing sem now, so we won't sleep */
1888 ret = xt_register_targets(arpt_builtin_tg, ARRAY_SIZE(arpt_builtin_tg));
1892 /* Register setsockopt */
1893 ret = nf_register_sockopt(&arpt_sockopts);
1897 printk(KERN_INFO "arp_tables: (C) 2002 David S. Miller\n");
1901 xt_unregister_targets(arpt_builtin_tg, ARRAY_SIZE(arpt_builtin_tg));
1903 unregister_pernet_subsys(&arp_tables_net_ops);
1908 static void __exit arp_tables_fini(void)
1910 nf_unregister_sockopt(&arpt_sockopts);
1911 xt_unregister_targets(arpt_builtin_tg, ARRAY_SIZE(arpt_builtin_tg));
1912 unregister_pernet_subsys(&arp_tables_net_ops);
1915 EXPORT_SYMBOL(arpt_register_table);
1916 EXPORT_SYMBOL(arpt_unregister_table);
1917 EXPORT_SYMBOL(arpt_do_table);
1919 module_init(arp_tables_init);
1920 module_exit(arp_tables_fini);