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)
12 #include <linux/kernel.h>
13 #include <linux/skbuff.h>
14 #include <linux/netdevice.h>
15 #include <linux/capability.h>
16 #include <linux/if_arp.h>
17 #include <linux/kmod.h>
18 #include <linux/vmalloc.h>
19 #include <linux/proc_fs.h>
20 #include <linux/module.h>
21 #include <linux/init.h>
22 #include <linux/mutex.h>
23 #include <linux/err.h>
24 #include <net/compat.h>
26 #include <asm/uaccess.h>
28 #include <linux/netfilter/x_tables.h>
29 #include <linux/netfilter_arp/arp_tables.h>
31 MODULE_LICENSE("GPL");
32 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
33 MODULE_DESCRIPTION("arptables core");
35 /*#define DEBUG_ARP_TABLES*/
36 /*#define DEBUG_ARP_TABLES_USER*/
38 #ifdef DEBUG_ARP_TABLES
39 #define dprintf(format, args...) printk(format , ## args)
41 #define dprintf(format, args...)
44 #ifdef DEBUG_ARP_TABLES_USER
45 #define duprintf(format, args...) printk(format , ## args)
47 #define duprintf(format, args...)
50 #ifdef CONFIG_NETFILTER_DEBUG
51 #define ARP_NF_ASSERT(x) \
54 printk("ARP_NF_ASSERT: %s:%s:%u\n", \
55 __func__, __FILE__, __LINE__); \
58 #define ARP_NF_ASSERT(x)
61 static inline int arp_devaddr_compare(const struct arpt_devaddr_info *ap,
62 const char *hdr_addr, int len)
66 if (len > ARPT_DEV_ADDR_LEN_MAX)
67 len = ARPT_DEV_ADDR_LEN_MAX;
70 for (i = 0; i < len; i++)
71 ret |= (hdr_addr[i] ^ ap->addr[i]) & ap->mask[i];
77 * Unfortunatly, _b and _mask are not aligned to an int (or long int)
78 * Some arches dont care, unrolling the loop is a win on them.
79 * For other arches, we only have a 16bit alignement.
81 static unsigned long ifname_compare(const char *_a, const char *_b, const char *_mask)
83 #ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
84 const unsigned long *a = (const unsigned long *)_a;
85 const unsigned long *b = (const unsigned long *)_b;
86 const unsigned long *mask = (const unsigned long *)_mask;
89 ret = (a[0] ^ b[0]) & mask[0];
90 if (IFNAMSIZ > sizeof(unsigned long))
91 ret |= (a[1] ^ b[1]) & mask[1];
92 if (IFNAMSIZ > 2 * sizeof(unsigned long))
93 ret |= (a[2] ^ b[2]) & mask[2];
94 if (IFNAMSIZ > 3 * sizeof(unsigned long))
95 ret |= (a[3] ^ b[3]) & mask[3];
96 BUILD_BUG_ON(IFNAMSIZ > 4 * sizeof(unsigned long));
98 unsigned long ret = 0;
99 const u16 *a = (const u16 *)_a;
100 const u16 *b = (const u16 *)_b;
101 const u16 *mask = (const u16 *)_mask;
104 for (i = 0; i < IFNAMSIZ/sizeof(u16); i++)
105 ret |= (a[i] ^ b[i]) & mask[i];
110 /* Returns whether packet matches rule or not. */
111 static inline int arp_packet_match(const struct arphdr *arphdr,
112 struct net_device *dev,
115 const struct arpt_arp *arpinfo)
117 const char *arpptr = (char *)(arphdr + 1);
118 const char *src_devaddr, *tgt_devaddr;
119 __be32 src_ipaddr, tgt_ipaddr;
122 #define FWINV(bool, invflg) ((bool) ^ !!(arpinfo->invflags & (invflg)))
124 if (FWINV((arphdr->ar_op & arpinfo->arpop_mask) != arpinfo->arpop,
126 dprintf("ARP operation field mismatch.\n");
127 dprintf("ar_op: %04x info->arpop: %04x info->arpop_mask: %04x\n",
128 arphdr->ar_op, arpinfo->arpop, arpinfo->arpop_mask);
132 if (FWINV((arphdr->ar_hrd & arpinfo->arhrd_mask) != arpinfo->arhrd,
134 dprintf("ARP hardware address format mismatch.\n");
135 dprintf("ar_hrd: %04x info->arhrd: %04x info->arhrd_mask: %04x\n",
136 arphdr->ar_hrd, arpinfo->arhrd, arpinfo->arhrd_mask);
140 if (FWINV((arphdr->ar_pro & arpinfo->arpro_mask) != arpinfo->arpro,
142 dprintf("ARP protocol address format mismatch.\n");
143 dprintf("ar_pro: %04x info->arpro: %04x info->arpro_mask: %04x\n",
144 arphdr->ar_pro, arpinfo->arpro, arpinfo->arpro_mask);
148 if (FWINV((arphdr->ar_hln & arpinfo->arhln_mask) != arpinfo->arhln,
150 dprintf("ARP hardware address length mismatch.\n");
151 dprintf("ar_hln: %02x info->arhln: %02x info->arhln_mask: %02x\n",
152 arphdr->ar_hln, arpinfo->arhln, arpinfo->arhln_mask);
156 src_devaddr = arpptr;
157 arpptr += dev->addr_len;
158 memcpy(&src_ipaddr, arpptr, sizeof(u32));
159 arpptr += sizeof(u32);
160 tgt_devaddr = arpptr;
161 arpptr += dev->addr_len;
162 memcpy(&tgt_ipaddr, arpptr, sizeof(u32));
164 if (FWINV(arp_devaddr_compare(&arpinfo->src_devaddr, src_devaddr, dev->addr_len),
165 ARPT_INV_SRCDEVADDR) ||
166 FWINV(arp_devaddr_compare(&arpinfo->tgt_devaddr, tgt_devaddr, dev->addr_len),
167 ARPT_INV_TGTDEVADDR)) {
168 dprintf("Source or target device address mismatch.\n");
173 if (FWINV((src_ipaddr & arpinfo->smsk.s_addr) != arpinfo->src.s_addr,
175 FWINV(((tgt_ipaddr & arpinfo->tmsk.s_addr) != arpinfo->tgt.s_addr),
177 dprintf("Source or target IP address mismatch.\n");
179 dprintf("SRC: %pI4. Mask: %pI4. Target: %pI4.%s\n",
181 &arpinfo->smsk.s_addr,
182 &arpinfo->src.s_addr,
183 arpinfo->invflags & ARPT_INV_SRCIP ? " (INV)" : "");
184 dprintf("TGT: %pI4 Mask: %pI4 Target: %pI4.%s\n",
186 &arpinfo->tmsk.s_addr,
187 &arpinfo->tgt.s_addr,
188 arpinfo->invflags & ARPT_INV_TGTIP ? " (INV)" : "");
192 /* Look for ifname matches. */
193 ret = ifname_compare(indev, arpinfo->iniface, arpinfo->iniface_mask);
195 if (FWINV(ret != 0, ARPT_INV_VIA_IN)) {
196 dprintf("VIA in mismatch (%s vs %s).%s\n",
197 indev, arpinfo->iniface,
198 arpinfo->invflags&ARPT_INV_VIA_IN ?" (INV)":"");
202 ret = ifname_compare(outdev, arpinfo->outiface, arpinfo->outiface_mask);
204 if (FWINV(ret != 0, ARPT_INV_VIA_OUT)) {
205 dprintf("VIA out mismatch (%s vs %s).%s\n",
206 outdev, arpinfo->outiface,
207 arpinfo->invflags&ARPT_INV_VIA_OUT ?" (INV)":"");
215 static inline int arp_checkentry(const struct arpt_arp *arp)
217 if (arp->flags & ~ARPT_F_MASK) {
218 duprintf("Unknown flag bits set: %08X\n",
219 arp->flags & ~ARPT_F_MASK);
222 if (arp->invflags & ~ARPT_INV_MASK) {
223 duprintf("Unknown invflag bits set: %08X\n",
224 arp->invflags & ~ARPT_INV_MASK);
232 arpt_error(struct sk_buff *skb, const struct xt_target_param *par)
235 printk("arp_tables: error: '%s'\n",
236 (const char *)par->targinfo);
241 static inline struct arpt_entry *get_entry(void *base, unsigned int offset)
243 return (struct arpt_entry *)(base + offset);
246 unsigned int arpt_do_table(struct sk_buff *skb,
248 const struct net_device *in,
249 const struct net_device *out,
250 struct xt_table *table)
252 static const char nulldevname[IFNAMSIZ] __attribute__((aligned(sizeof(long))));
253 unsigned int verdict = NF_DROP;
254 const struct arphdr *arp;
255 bool hotdrop = false;
256 struct arpt_entry *e, *back;
257 const char *indev, *outdev;
259 const struct xt_table_info *private;
260 struct xt_target_param tgpar;
262 if (!pskb_may_pull(skb, arp_hdr_len(skb->dev)))
265 indev = in ? in->name : nulldevname;
266 outdev = out ? out->name : nulldevname;
269 private = rcu_dereference(table->private);
270 table_base = rcu_dereference(private->entries[smp_processor_id()]);
272 e = get_entry(table_base, private->hook_entry[hook]);
273 back = get_entry(table_base, private->underflow[hook]);
277 tgpar.hooknum = hook;
278 tgpar.family = NFPROTO_ARP;
282 if (arp_packet_match(arp, skb->dev, indev, outdev, &e->arp)) {
283 struct arpt_entry_target *t;
286 hdr_len = sizeof(*arp) + (2 * sizeof(struct in_addr)) +
287 (2 * skb->dev->addr_len);
288 ADD_COUNTER(e->counters, hdr_len, 1);
290 t = arpt_get_target(e);
292 /* Standard target? */
293 if (!t->u.kernel.target->target) {
296 v = ((struct arpt_standard_target *)t)->verdict;
298 /* Pop from stack? */
299 if (v != ARPT_RETURN) {
300 verdict = (unsigned)(-v) - 1;
304 back = get_entry(table_base,
309 != (void *)e + e->next_offset) {
310 /* Save old back ptr in next entry */
311 struct arpt_entry *next
312 = (void *)e + e->next_offset;
314 (void *)back - table_base;
316 /* set back pointer to next entry */
320 e = get_entry(table_base, v);
322 /* Targets which reenter must return
325 tgpar.target = t->u.kernel.target;
326 tgpar.targinfo = t->data;
327 verdict = t->u.kernel.target->target(skb,
330 /* Target might have changed stuff. */
333 if (verdict == ARPT_CONTINUE)
334 e = (void *)e + e->next_offset;
340 e = (void *)e + e->next_offset;
352 /* All zeroes == unconditional rule. */
353 static inline int unconditional(const struct arpt_arp *arp)
357 for (i = 0; i < sizeof(*arp)/sizeof(__u32); i++)
358 if (((__u32 *)arp)[i])
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(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 arpt_standard_target *t
388 = (void *)arpt_get_target(e);
389 int visited = e->comefrom & (1 << hook);
391 if (e->comefrom & (1 << NF_ARP_NUMHOOKS)) {
392 printk("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 ARPT_STANDARD_TARGET) == 0)
404 && unconditional(&e->arp)) || visited) {
405 unsigned int oldpos, size;
407 if (t->verdict < -NF_MAX_VERDICT - 1) {
408 duprintf("mark_source_chains: bad "
409 "negative verdict (%i)\n",
414 /* Return: backtrack through the last
418 e->comefrom ^= (1<<NF_ARP_NUMHOOKS);
420 pos = e->counters.pcnt;
421 e->counters.pcnt = 0;
423 /* We're at the start. */
427 e = (struct arpt_entry *)
429 } while (oldpos == pos + e->next_offset);
432 size = e->next_offset;
433 e = (struct arpt_entry *)
434 (entry0 + pos + size);
435 e->counters.pcnt = pos;
438 int newpos = t->verdict;
440 if (strcmp(t->target.u.user.name,
441 ARPT_STANDARD_TARGET) == 0
443 if (newpos > newinfo->size -
444 sizeof(struct arpt_entry)) {
445 duprintf("mark_source_chains: "
446 "bad verdict (%i)\n",
451 /* This a jump; chase it. */
452 duprintf("Jump rule %u -> %u\n",
455 /* ... this is a fallthru */
456 newpos = pos + e->next_offset;
458 e = (struct arpt_entry *)
460 e->counters.pcnt = pos;
465 duprintf("Finished chain %u\n", hook);
470 static inline int check_entry(struct arpt_entry *e, const char *name)
472 const struct arpt_entry_target *t;
474 if (!arp_checkentry(&e->arp)) {
475 duprintf("arp_tables: arp check failed %p %s.\n", e, name);
479 if (e->target_offset + sizeof(struct arpt_entry_target) > e->next_offset)
482 t = arpt_get_target(e);
483 if (e->target_offset + t->u.target_size > e->next_offset)
489 static inline int check_target(struct arpt_entry *e, const char *name)
491 struct arpt_entry_target *t = arpt_get_target(e);
493 struct xt_tgchk_param par = {
496 .target = t->u.kernel.target,
498 .hook_mask = e->comefrom,
499 .family = NFPROTO_ARP,
502 ret = xt_check_target(&par, t->u.target_size - sizeof(*t), 0, false);
504 duprintf("arp_tables: check failed for `%s'.\n",
505 t->u.kernel.target->name);
512 find_check_entry(struct arpt_entry *e, const char *name, unsigned int size,
515 struct arpt_entry_target *t;
516 struct xt_target *target;
519 ret = check_entry(e, name);
523 t = arpt_get_target(e);
524 target = try_then_request_module(xt_find_target(NFPROTO_ARP,
527 "arpt_%s", t->u.user.name);
528 if (IS_ERR(target) || !target) {
529 duprintf("find_check_entry: `%s' not found\n", t->u.user.name);
530 ret = target ? PTR_ERR(target) : -ENOENT;
533 t->u.kernel.target = target;
535 ret = check_target(e, name);
542 module_put(t->u.kernel.target->me);
547 static inline int check_entry_size_and_hooks(struct arpt_entry *e,
548 struct xt_table_info *newinfo,
550 unsigned char *limit,
551 const unsigned int *hook_entries,
552 const unsigned int *underflows,
557 if ((unsigned long)e % __alignof__(struct arpt_entry) != 0
558 || (unsigned char *)e + sizeof(struct arpt_entry) >= limit) {
559 duprintf("Bad offset %p\n", e);
564 < sizeof(struct arpt_entry) + sizeof(struct arpt_entry_target)) {
565 duprintf("checking: element %p size %u\n",
570 /* Check hooks & underflows */
571 for (h = 0; h < NF_ARP_NUMHOOKS; h++) {
572 if ((unsigned char *)e - base == hook_entries[h])
573 newinfo->hook_entry[h] = hook_entries[h];
574 if ((unsigned char *)e - base == underflows[h])
575 newinfo->underflow[h] = underflows[h];
578 /* FIXME: underflows must be unconditional, standard verdicts
579 < 0 (not ARPT_RETURN). --RR */
581 /* Clear counters and comefrom */
582 e->counters = ((struct xt_counters) { 0, 0 });
589 static inline int cleanup_entry(struct arpt_entry *e, unsigned int *i)
591 struct xt_tgdtor_param par;
592 struct arpt_entry_target *t;
594 if (i && (*i)-- == 0)
597 t = arpt_get_target(e);
598 par.target = t->u.kernel.target;
599 par.targinfo = t->data;
600 par.family = NFPROTO_ARP;
601 if (par.target->destroy != NULL)
602 par.target->destroy(&par);
603 module_put(par.target->me);
607 /* Checks and translates the user-supplied table segment (held in
610 static int translate_table(const char *name,
611 unsigned int valid_hooks,
612 struct xt_table_info *newinfo,
616 const unsigned int *hook_entries,
617 const unsigned int *underflows)
622 newinfo->size = size;
623 newinfo->number = number;
625 /* Init all hooks to impossible value. */
626 for (i = 0; i < NF_ARP_NUMHOOKS; i++) {
627 newinfo->hook_entry[i] = 0xFFFFFFFF;
628 newinfo->underflow[i] = 0xFFFFFFFF;
631 duprintf("translate_table: size %u\n", newinfo->size);
634 /* Walk through entries, checking offsets. */
635 ret = ARPT_ENTRY_ITERATE(entry0, newinfo->size,
636 check_entry_size_and_hooks,
640 hook_entries, underflows, &i);
641 duprintf("translate_table: ARPT_ENTRY_ITERATE gives %d\n", ret);
646 duprintf("translate_table: %u not %u entries\n",
651 /* Check hooks all assigned */
652 for (i = 0; i < NF_ARP_NUMHOOKS; i++) {
653 /* Only hooks which are valid */
654 if (!(valid_hooks & (1 << i)))
656 if (newinfo->hook_entry[i] == 0xFFFFFFFF) {
657 duprintf("Invalid hook entry %u %u\n",
661 if (newinfo->underflow[i] == 0xFFFFFFFF) {
662 duprintf("Invalid underflow %u %u\n",
668 if (!mark_source_chains(newinfo, valid_hooks, entry0)) {
669 duprintf("Looping hook\n");
673 /* Finally, each sanity check must pass */
675 ret = ARPT_ENTRY_ITERATE(entry0, newinfo->size,
676 find_check_entry, name, size, &i);
679 ARPT_ENTRY_ITERATE(entry0, newinfo->size,
684 /* And one copy for every other CPU */
685 for_each_possible_cpu(i) {
686 if (newinfo->entries[i] && newinfo->entries[i] != entry0)
687 memcpy(newinfo->entries[i], entry0, newinfo->size);
694 static inline int add_entry_to_counter(const struct arpt_entry *e,
695 struct xt_counters total[],
698 ADD_COUNTER(total[*i], e->counters.bcnt, e->counters.pcnt);
704 static inline int set_entry_to_counter(const struct arpt_entry *e,
705 struct xt_counters total[],
708 SET_COUNTER(total[*i], e->counters.bcnt, e->counters.pcnt);
714 static void get_counters(const struct xt_table_info *t,
715 struct xt_counters counters[])
721 /* Instead of clearing (by a previous call to memset())
722 * the counters and using adds, we set the counters
723 * with data used by 'current' CPU
724 * We dont care about preemption here.
726 curcpu = raw_smp_processor_id();
729 ARPT_ENTRY_ITERATE(t->entries[curcpu],
731 set_entry_to_counter,
735 for_each_possible_cpu(cpu) {
739 ARPT_ENTRY_ITERATE(t->entries[cpu],
741 add_entry_to_counter,
748 /* We're lazy, and add to the first CPU; overflow works its fey magic
749 * and everything is OK. */
751 add_counter_to_entry(struct arpt_entry *e,
752 const struct xt_counters addme[],
755 ADD_COUNTER(e->counters, addme[*i].bcnt, addme[*i].pcnt);
761 /* Take values from counters and add them back onto the current cpu */
762 static void put_counters(struct xt_table_info *t,
763 const struct xt_counters counters[])
768 cpu = smp_processor_id();
770 ARPT_ENTRY_ITERATE(t->entries[cpu],
772 add_counter_to_entry,
779 zero_entry_counter(struct arpt_entry *e, void *arg)
781 e->counters.bcnt = 0;
782 e->counters.pcnt = 0;
787 clone_counters(struct xt_table_info *newinfo, const struct xt_table_info *info)
790 const void *loc_cpu_entry = info->entries[raw_smp_processor_id()];
792 memcpy(newinfo, info, offsetof(struct xt_table_info, entries));
793 for_each_possible_cpu(cpu) {
794 memcpy(newinfo->entries[cpu], loc_cpu_entry, info->size);
795 ARPT_ENTRY_ITERATE(newinfo->entries[cpu], newinfo->size,
796 zero_entry_counter, NULL);
800 static struct xt_counters *alloc_counters(struct xt_table *table)
802 unsigned int countersize;
803 struct xt_counters *counters;
804 struct xt_table_info *private = table->private;
805 struct xt_table_info *info;
807 /* We need atomic snapshot of counters: rest doesn't change
808 * (other than comefrom, which userspace doesn't care
811 countersize = sizeof(struct xt_counters) * private->number;
812 counters = vmalloc_node(countersize, numa_node_id());
814 if (counters == NULL)
817 info = xt_alloc_table_info(private->size);
821 clone_counters(info, private);
823 mutex_lock(&table->lock);
824 xt_table_entry_swap_rcu(private, info);
825 synchronize_net(); /* Wait until smoke has cleared */
827 get_counters(info, counters);
828 put_counters(private, counters);
829 mutex_unlock(&table->lock);
831 xt_free_table_info(info);
838 return ERR_PTR(-ENOMEM);
841 static int copy_entries_to_user(unsigned int total_size,
842 struct xt_table *table,
843 void __user *userptr)
845 unsigned int off, num;
846 struct arpt_entry *e;
847 struct xt_counters *counters;
848 struct xt_table_info *private = table->private;
852 counters = alloc_counters(table);
853 if (IS_ERR(counters))
854 return PTR_ERR(counters);
856 loc_cpu_entry = private->entries[raw_smp_processor_id()];
857 /* ... then copy entire thing ... */
858 if (copy_to_user(userptr, loc_cpu_entry, total_size) != 0) {
863 /* FIXME: use iterator macros --RR */
864 /* ... then go back and fix counters and names */
865 for (off = 0, num = 0; off < total_size; off += e->next_offset, num++){
866 struct arpt_entry_target *t;
868 e = (struct arpt_entry *)(loc_cpu_entry + off);
869 if (copy_to_user(userptr + off
870 + offsetof(struct arpt_entry, counters),
872 sizeof(counters[num])) != 0) {
877 t = arpt_get_target(e);
878 if (copy_to_user(userptr + off + e->target_offset
879 + offsetof(struct arpt_entry_target,
881 t->u.kernel.target->name,
882 strlen(t->u.kernel.target->name)+1) != 0) {
894 static void compat_standard_from_user(void *dst, void *src)
896 int v = *(compat_int_t *)src;
899 v += xt_compat_calc_jump(NFPROTO_ARP, v);
900 memcpy(dst, &v, sizeof(v));
903 static int compat_standard_to_user(void __user *dst, void *src)
905 compat_int_t cv = *(int *)src;
908 cv -= xt_compat_calc_jump(NFPROTO_ARP, cv);
909 return copy_to_user(dst, &cv, sizeof(cv)) ? -EFAULT : 0;
912 static int compat_calc_entry(struct arpt_entry *e,
913 const struct xt_table_info *info,
914 void *base, struct xt_table_info *newinfo)
916 struct arpt_entry_target *t;
917 unsigned int entry_offset;
920 off = sizeof(struct arpt_entry) - sizeof(struct compat_arpt_entry);
921 entry_offset = (void *)e - base;
923 t = arpt_get_target(e);
924 off += xt_compat_target_offset(t->u.kernel.target);
925 newinfo->size -= off;
926 ret = xt_compat_add_offset(NFPROTO_ARP, entry_offset, off);
930 for (i = 0; i < NF_ARP_NUMHOOKS; i++) {
931 if (info->hook_entry[i] &&
932 (e < (struct arpt_entry *)(base + info->hook_entry[i])))
933 newinfo->hook_entry[i] -= off;
934 if (info->underflow[i] &&
935 (e < (struct arpt_entry *)(base + info->underflow[i])))
936 newinfo->underflow[i] -= off;
941 static int compat_table_info(const struct xt_table_info *info,
942 struct xt_table_info *newinfo)
946 if (!newinfo || !info)
949 /* we dont care about newinfo->entries[] */
950 memcpy(newinfo, info, offsetof(struct xt_table_info, entries));
951 newinfo->initial_entries = 0;
952 loc_cpu_entry = info->entries[raw_smp_processor_id()];
953 return ARPT_ENTRY_ITERATE(loc_cpu_entry, info->size,
954 compat_calc_entry, info, loc_cpu_entry,
959 static int get_info(struct net *net, void __user *user, int *len, int compat)
961 char name[ARPT_TABLE_MAXNAMELEN];
965 if (*len != sizeof(struct arpt_getinfo)) {
966 duprintf("length %u != %Zu\n", *len,
967 sizeof(struct arpt_getinfo));
971 if (copy_from_user(name, user, sizeof(name)) != 0)
974 name[ARPT_TABLE_MAXNAMELEN-1] = '\0';
977 xt_compat_lock(NFPROTO_ARP);
979 t = try_then_request_module(xt_find_table_lock(net, NFPROTO_ARP, name),
980 "arptable_%s", name);
981 if (t && !IS_ERR(t)) {
982 struct arpt_getinfo info;
983 const struct xt_table_info *private = t->private;
987 struct xt_table_info tmp;
988 ret = compat_table_info(private, &tmp);
989 xt_compat_flush_offsets(NFPROTO_ARP);
993 info.valid_hooks = t->valid_hooks;
994 memcpy(info.hook_entry, private->hook_entry,
995 sizeof(info.hook_entry));
996 memcpy(info.underflow, private->underflow,
997 sizeof(info.underflow));
998 info.num_entries = private->number;
999 info.size = private->size;
1000 strcpy(info.name, name);
1002 if (copy_to_user(user, &info, *len) != 0)
1009 ret = t ? PTR_ERR(t) : -ENOENT;
1010 #ifdef CONFIG_COMPAT
1012 xt_compat_unlock(NFPROTO_ARP);
1017 static int get_entries(struct net *net, struct arpt_get_entries __user *uptr,
1021 struct arpt_get_entries get;
1024 if (*len < sizeof(get)) {
1025 duprintf("get_entries: %u < %Zu\n", *len, sizeof(get));
1028 if (copy_from_user(&get, uptr, sizeof(get)) != 0)
1030 if (*len != sizeof(struct arpt_get_entries) + get.size) {
1031 duprintf("get_entries: %u != %Zu\n", *len,
1032 sizeof(struct arpt_get_entries) + get.size);
1036 t = xt_find_table_lock(net, NFPROTO_ARP, get.name);
1037 if (t && !IS_ERR(t)) {
1038 const struct xt_table_info *private = t->private;
1040 duprintf("t->private->number = %u\n",
1042 if (get.size == private->size)
1043 ret = copy_entries_to_user(private->size,
1044 t, uptr->entrytable);
1046 duprintf("get_entries: I've got %u not %u!\n",
1047 private->size, get.size);
1053 ret = t ? PTR_ERR(t) : -ENOENT;
1058 static int __do_replace(struct net *net, const char *name,
1059 unsigned int valid_hooks,
1060 struct xt_table_info *newinfo,
1061 unsigned int num_counters,
1062 void __user *counters_ptr)
1066 struct xt_table_info *oldinfo;
1067 struct xt_counters *counters;
1068 void *loc_cpu_old_entry;
1071 counters = vmalloc_node(num_counters * sizeof(struct xt_counters),
1078 t = try_then_request_module(xt_find_table_lock(net, NFPROTO_ARP, name),
1079 "arptable_%s", name);
1080 if (!t || IS_ERR(t)) {
1081 ret = t ? PTR_ERR(t) : -ENOENT;
1082 goto free_newinfo_counters_untrans;
1086 if (valid_hooks != t->valid_hooks) {
1087 duprintf("Valid hook crap: %08X vs %08X\n",
1088 valid_hooks, t->valid_hooks);
1093 oldinfo = xt_replace_table(t, num_counters, newinfo, &ret);
1097 /* Update module usage count based on number of rules */
1098 duprintf("do_replace: oldnum=%u, initnum=%u, newnum=%u\n",
1099 oldinfo->number, oldinfo->initial_entries, newinfo->number);
1100 if ((oldinfo->number > oldinfo->initial_entries) ||
1101 (newinfo->number <= oldinfo->initial_entries))
1103 if ((oldinfo->number > oldinfo->initial_entries) &&
1104 (newinfo->number <= oldinfo->initial_entries))
1107 /* Get the old counters. */
1108 get_counters(oldinfo, counters);
1109 /* Decrease module usage counts and free resource */
1110 loc_cpu_old_entry = oldinfo->entries[raw_smp_processor_id()];
1111 ARPT_ENTRY_ITERATE(loc_cpu_old_entry, oldinfo->size, cleanup_entry,
1114 xt_free_table_info(oldinfo);
1115 if (copy_to_user(counters_ptr, counters,
1116 sizeof(struct xt_counters) * num_counters) != 0)
1125 free_newinfo_counters_untrans:
1131 static int do_replace(struct net *net, void __user *user, unsigned int len)
1134 struct arpt_replace tmp;
1135 struct xt_table_info *newinfo;
1136 void *loc_cpu_entry;
1138 if (copy_from_user(&tmp, user, sizeof(tmp)) != 0)
1141 /* overflow check */
1142 if (tmp.num_counters >= INT_MAX / sizeof(struct xt_counters))
1145 newinfo = xt_alloc_table_info(tmp.size);
1149 /* choose the copy that is on our node/cpu */
1150 loc_cpu_entry = newinfo->entries[raw_smp_processor_id()];
1151 if (copy_from_user(loc_cpu_entry, user + sizeof(tmp),
1157 ret = translate_table(tmp.name, tmp.valid_hooks,
1158 newinfo, loc_cpu_entry, tmp.size, tmp.num_entries,
1159 tmp.hook_entry, tmp.underflow);
1163 duprintf("arp_tables: Translated table\n");
1165 ret = __do_replace(net, tmp.name, tmp.valid_hooks, newinfo,
1166 tmp.num_counters, tmp.counters);
1168 goto free_newinfo_untrans;
1171 free_newinfo_untrans:
1172 ARPT_ENTRY_ITERATE(loc_cpu_entry, newinfo->size, cleanup_entry, NULL);
1174 xt_free_table_info(newinfo);
1178 static int do_add_counters(struct net *net, void __user *user, unsigned int len,
1182 struct xt_counters_info tmp;
1183 struct xt_counters *paddc;
1184 unsigned int num_counters;
1189 const struct xt_table_info *private;
1191 void *loc_cpu_entry;
1192 #ifdef CONFIG_COMPAT
1193 struct compat_xt_counters_info compat_tmp;
1197 size = sizeof(struct compat_xt_counters_info);
1202 size = sizeof(struct xt_counters_info);
1205 if (copy_from_user(ptmp, user, size) != 0)
1208 #ifdef CONFIG_COMPAT
1210 num_counters = compat_tmp.num_counters;
1211 name = compat_tmp.name;
1215 num_counters = tmp.num_counters;
1219 if (len != size + num_counters * sizeof(struct xt_counters))
1222 paddc = vmalloc_node(len - size, numa_node_id());
1226 if (copy_from_user(paddc, user + size, len - size) != 0) {
1231 t = xt_find_table_lock(net, NFPROTO_ARP, name);
1232 if (!t || IS_ERR(t)) {
1233 ret = t ? PTR_ERR(t) : -ENOENT;
1237 mutex_lock(&t->lock);
1238 private = t->private;
1239 if (private->number != num_counters) {
1241 goto unlock_up_free;
1246 /* Choose the copy that is on our node */
1247 loc_cpu_entry = private->entries[smp_processor_id()];
1248 ARPT_ENTRY_ITERATE(loc_cpu_entry,
1250 add_counter_to_entry,
1255 mutex_unlock(&t->lock);
1265 #ifdef CONFIG_COMPAT
1267 compat_release_entry(struct compat_arpt_entry *e, unsigned int *i)
1269 struct arpt_entry_target *t;
1271 if (i && (*i)-- == 0)
1274 t = compat_arpt_get_target(e);
1275 module_put(t->u.kernel.target->me);
1280 check_compat_entry_size_and_hooks(struct compat_arpt_entry *e,
1281 struct xt_table_info *newinfo,
1283 unsigned char *base,
1284 unsigned char *limit,
1285 unsigned int *hook_entries,
1286 unsigned int *underflows,
1290 struct arpt_entry_target *t;
1291 struct xt_target *target;
1292 unsigned int entry_offset;
1295 duprintf("check_compat_entry_size_and_hooks %p\n", e);
1296 if ((unsigned long)e % __alignof__(struct compat_arpt_entry) != 0
1297 || (unsigned char *)e + sizeof(struct compat_arpt_entry) >= limit) {
1298 duprintf("Bad offset %p, limit = %p\n", e, limit);
1302 if (e->next_offset < sizeof(struct compat_arpt_entry) +
1303 sizeof(struct compat_xt_entry_target)) {
1304 duprintf("checking: element %p size %u\n",
1309 /* For purposes of check_entry casting the compat entry is fine */
1310 ret = check_entry((struct arpt_entry *)e, name);
1314 off = sizeof(struct arpt_entry) - sizeof(struct compat_arpt_entry);
1315 entry_offset = (void *)e - (void *)base;
1317 t = compat_arpt_get_target(e);
1318 target = try_then_request_module(xt_find_target(NFPROTO_ARP,
1320 t->u.user.revision),
1321 "arpt_%s", t->u.user.name);
1322 if (IS_ERR(target) || !target) {
1323 duprintf("check_compat_entry_size_and_hooks: `%s' not found\n",
1325 ret = target ? PTR_ERR(target) : -ENOENT;
1328 t->u.kernel.target = target;
1330 off += xt_compat_target_offset(target);
1332 ret = xt_compat_add_offset(NFPROTO_ARP, entry_offset, off);
1334 goto release_target;
1336 /* Check hooks & underflows */
1337 for (h = 0; h < NF_ARP_NUMHOOKS; h++) {
1338 if ((unsigned char *)e - base == hook_entries[h])
1339 newinfo->hook_entry[h] = hook_entries[h];
1340 if ((unsigned char *)e - base == underflows[h])
1341 newinfo->underflow[h] = underflows[h];
1344 /* Clear counters and comefrom */
1345 memset(&e->counters, 0, sizeof(e->counters));
1352 module_put(t->u.kernel.target->me);
1358 compat_copy_entry_from_user(struct compat_arpt_entry *e, void **dstptr,
1359 unsigned int *size, const char *name,
1360 struct xt_table_info *newinfo, unsigned char *base)
1362 struct arpt_entry_target *t;
1363 struct xt_target *target;
1364 struct arpt_entry *de;
1365 unsigned int origsize;
1370 de = (struct arpt_entry *)*dstptr;
1371 memcpy(de, e, sizeof(struct arpt_entry));
1372 memcpy(&de->counters, &e->counters, sizeof(e->counters));
1374 *dstptr += sizeof(struct arpt_entry);
1375 *size += sizeof(struct arpt_entry) - sizeof(struct compat_arpt_entry);
1377 de->target_offset = e->target_offset - (origsize - *size);
1378 t = compat_arpt_get_target(e);
1379 target = t->u.kernel.target;
1380 xt_compat_target_from_user(t, dstptr, size);
1382 de->next_offset = e->next_offset - (origsize - *size);
1383 for (h = 0; h < NF_ARP_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 static inline int compat_check_entry(struct arpt_entry *e, const char *name,
1397 ret = check_target(e, name);
1405 static int translate_compat_table(const char *name,
1406 unsigned int valid_hooks,
1407 struct xt_table_info **pinfo,
1409 unsigned int total_size,
1410 unsigned int number,
1411 unsigned int *hook_entries,
1412 unsigned int *underflows)
1415 struct xt_table_info *newinfo, *info;
1416 void *pos, *entry0, *entry1;
1423 info->number = number;
1425 /* Init all hooks to impossible value. */
1426 for (i = 0; i < NF_ARP_NUMHOOKS; i++) {
1427 info->hook_entry[i] = 0xFFFFFFFF;
1428 info->underflow[i] = 0xFFFFFFFF;
1431 duprintf("translate_compat_table: size %u\n", info->size);
1433 xt_compat_lock(NFPROTO_ARP);
1434 /* Walk through entries, checking offsets. */
1435 ret = COMPAT_ARPT_ENTRY_ITERATE(entry0, total_size,
1436 check_compat_entry_size_and_hooks,
1437 info, &size, entry0,
1438 entry0 + total_size,
1439 hook_entries, underflows, &j, name);
1445 duprintf("translate_compat_table: %u not %u entries\n",
1450 /* Check hooks all assigned */
1451 for (i = 0; i < NF_ARP_NUMHOOKS; i++) {
1452 /* Only hooks which are valid */
1453 if (!(valid_hooks & (1 << i)))
1455 if (info->hook_entry[i] == 0xFFFFFFFF) {
1456 duprintf("Invalid hook entry %u %u\n",
1457 i, hook_entries[i]);
1460 if (info->underflow[i] == 0xFFFFFFFF) {
1461 duprintf("Invalid underflow %u %u\n",
1468 newinfo = xt_alloc_table_info(size);
1472 newinfo->number = number;
1473 for (i = 0; i < NF_ARP_NUMHOOKS; i++) {
1474 newinfo->hook_entry[i] = info->hook_entry[i];
1475 newinfo->underflow[i] = info->underflow[i];
1477 entry1 = newinfo->entries[raw_smp_processor_id()];
1480 ret = COMPAT_ARPT_ENTRY_ITERATE(entry0, total_size,
1481 compat_copy_entry_from_user,
1482 &pos, &size, name, newinfo, entry1);
1483 xt_compat_flush_offsets(NFPROTO_ARP);
1484 xt_compat_unlock(NFPROTO_ARP);
1489 if (!mark_source_chains(newinfo, valid_hooks, entry1))
1493 ret = ARPT_ENTRY_ITERATE(entry1, newinfo->size, compat_check_entry,
1497 COMPAT_ARPT_ENTRY_ITERATE_CONTINUE(entry0, newinfo->size, i,
1498 compat_release_entry, &j);
1499 ARPT_ENTRY_ITERATE(entry1, newinfo->size, cleanup_entry, &i);
1500 xt_free_table_info(newinfo);
1504 /* And one copy for every other CPU */
1505 for_each_possible_cpu(i)
1506 if (newinfo->entries[i] && newinfo->entries[i] != entry1)
1507 memcpy(newinfo->entries[i], entry1, newinfo->size);
1511 xt_free_table_info(info);
1515 xt_free_table_info(newinfo);
1517 COMPAT_ARPT_ENTRY_ITERATE(entry0, total_size, compat_release_entry, &j);
1520 xt_compat_flush_offsets(NFPROTO_ARP);
1521 xt_compat_unlock(NFPROTO_ARP);
1525 struct compat_arpt_replace {
1526 char name[ARPT_TABLE_MAXNAMELEN];
1530 u32 hook_entry[NF_ARP_NUMHOOKS];
1531 u32 underflow[NF_ARP_NUMHOOKS];
1533 compat_uptr_t counters;
1534 struct compat_arpt_entry entries[0];
1537 static int compat_do_replace(struct net *net, void __user *user,
1541 struct compat_arpt_replace tmp;
1542 struct xt_table_info *newinfo;
1543 void *loc_cpu_entry;
1545 if (copy_from_user(&tmp, user, sizeof(tmp)) != 0)
1548 /* overflow check */
1549 if (tmp.size >= INT_MAX / num_possible_cpus())
1551 if (tmp.num_counters >= INT_MAX / sizeof(struct xt_counters))
1554 newinfo = xt_alloc_table_info(tmp.size);
1558 /* choose the copy that is on our node/cpu */
1559 loc_cpu_entry = newinfo->entries[raw_smp_processor_id()];
1560 if (copy_from_user(loc_cpu_entry, user + sizeof(tmp), tmp.size) != 0) {
1565 ret = translate_compat_table(tmp.name, tmp.valid_hooks,
1566 &newinfo, &loc_cpu_entry, tmp.size,
1567 tmp.num_entries, tmp.hook_entry,
1572 duprintf("compat_do_replace: Translated table\n");
1574 ret = __do_replace(net, tmp.name, tmp.valid_hooks, newinfo,
1575 tmp.num_counters, compat_ptr(tmp.counters));
1577 goto free_newinfo_untrans;
1580 free_newinfo_untrans:
1581 ARPT_ENTRY_ITERATE(loc_cpu_entry, newinfo->size, cleanup_entry, NULL);
1583 xt_free_table_info(newinfo);
1587 static int compat_do_arpt_set_ctl(struct sock *sk, int cmd, void __user *user,
1592 if (!capable(CAP_NET_ADMIN))
1596 case ARPT_SO_SET_REPLACE:
1597 ret = compat_do_replace(sock_net(sk), user, len);
1600 case ARPT_SO_SET_ADD_COUNTERS:
1601 ret = do_add_counters(sock_net(sk), user, len, 1);
1605 duprintf("do_arpt_set_ctl: unknown request %i\n", cmd);
1612 static int compat_copy_entry_to_user(struct arpt_entry *e, void __user **dstptr,
1613 compat_uint_t *size,
1614 struct xt_counters *counters,
1617 struct arpt_entry_target *t;
1618 struct compat_arpt_entry __user *ce;
1619 u_int16_t target_offset, next_offset;
1620 compat_uint_t origsize;
1625 ce = (struct compat_arpt_entry __user *)*dstptr;
1626 if (copy_to_user(ce, e, sizeof(struct arpt_entry)))
1629 if (copy_to_user(&ce->counters, &counters[*i], sizeof(counters[*i])))
1632 *dstptr += sizeof(struct compat_arpt_entry);
1633 *size -= sizeof(struct arpt_entry) - sizeof(struct compat_arpt_entry);
1635 target_offset = e->target_offset - (origsize - *size);
1637 t = arpt_get_target(e);
1638 ret = xt_compat_target_to_user(t, dstptr, size);
1642 next_offset = e->next_offset - (origsize - *size);
1643 if (put_user(target_offset, &ce->target_offset))
1645 if (put_user(next_offset, &ce->next_offset))
1654 static int compat_copy_entries_to_user(unsigned int total_size,
1655 struct xt_table *table,
1656 void __user *userptr)
1658 struct xt_counters *counters;
1659 const struct xt_table_info *private = table->private;
1663 void *loc_cpu_entry;
1666 counters = alloc_counters(table);
1667 if (IS_ERR(counters))
1668 return PTR_ERR(counters);
1670 /* choose the copy on our node/cpu */
1671 loc_cpu_entry = private->entries[raw_smp_processor_id()];
1674 ret = ARPT_ENTRY_ITERATE(loc_cpu_entry, total_size,
1675 compat_copy_entry_to_user,
1676 &pos, &size, counters, &i);
1681 struct compat_arpt_get_entries {
1682 char name[ARPT_TABLE_MAXNAMELEN];
1684 struct compat_arpt_entry entrytable[0];
1687 static int compat_get_entries(struct net *net,
1688 struct compat_arpt_get_entries __user *uptr,
1692 struct compat_arpt_get_entries get;
1695 if (*len < sizeof(get)) {
1696 duprintf("compat_get_entries: %u < %zu\n", *len, sizeof(get));
1699 if (copy_from_user(&get, uptr, sizeof(get)) != 0)
1701 if (*len != sizeof(struct compat_arpt_get_entries) + get.size) {
1702 duprintf("compat_get_entries: %u != %zu\n",
1703 *len, sizeof(get) + get.size);
1707 xt_compat_lock(NFPROTO_ARP);
1708 t = xt_find_table_lock(net, NFPROTO_ARP, get.name);
1709 if (t && !IS_ERR(t)) {
1710 const struct xt_table_info *private = t->private;
1711 struct xt_table_info info;
1713 duprintf("t->private->number = %u\n", private->number);
1714 ret = compat_table_info(private, &info);
1715 if (!ret && get.size == info.size) {
1716 ret = compat_copy_entries_to_user(private->size,
1717 t, uptr->entrytable);
1719 duprintf("compat_get_entries: I've got %u not %u!\n",
1720 private->size, get.size);
1723 xt_compat_flush_offsets(NFPROTO_ARP);
1727 ret = t ? PTR_ERR(t) : -ENOENT;
1729 xt_compat_unlock(NFPROTO_ARP);
1733 static int do_arpt_get_ctl(struct sock *, int, void __user *, int *);
1735 static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
1740 if (!capable(CAP_NET_ADMIN))
1744 case ARPT_SO_GET_INFO:
1745 ret = get_info(sock_net(sk), user, len, 1);
1747 case ARPT_SO_GET_ENTRIES:
1748 ret = compat_get_entries(sock_net(sk), user, len);
1751 ret = do_arpt_get_ctl(sk, cmd, user, len);
1757 static int do_arpt_set_ctl(struct sock *sk, int cmd, void __user *user, unsigned int len)
1761 if (!capable(CAP_NET_ADMIN))
1765 case ARPT_SO_SET_REPLACE:
1766 ret = do_replace(sock_net(sk), user, len);
1769 case ARPT_SO_SET_ADD_COUNTERS:
1770 ret = do_add_counters(sock_net(sk), user, len, 0);
1774 duprintf("do_arpt_set_ctl: unknown request %i\n", cmd);
1781 static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
1785 if (!capable(CAP_NET_ADMIN))
1789 case ARPT_SO_GET_INFO:
1790 ret = get_info(sock_net(sk), user, len, 0);
1793 case ARPT_SO_GET_ENTRIES:
1794 ret = get_entries(sock_net(sk), user, len);
1797 case ARPT_SO_GET_REVISION_TARGET: {
1798 struct xt_get_revision rev;
1800 if (*len != sizeof(rev)) {
1804 if (copy_from_user(&rev, user, sizeof(rev)) != 0) {
1809 try_then_request_module(xt_find_revision(NFPROTO_ARP, rev.name,
1810 rev.revision, 1, &ret),
1811 "arpt_%s", rev.name);
1816 duprintf("do_arpt_get_ctl: unknown request %i\n", cmd);
1823 struct xt_table *arpt_register_table(struct net *net, struct xt_table *table,
1824 const struct arpt_replace *repl)
1827 struct xt_table_info *newinfo;
1828 struct xt_table_info bootstrap
1829 = { 0, 0, 0, { 0 }, { 0 }, { } };
1830 void *loc_cpu_entry;
1831 struct xt_table *new_table;
1833 newinfo = xt_alloc_table_info(repl->size);
1839 /* choose the copy on our node/cpu */
1840 loc_cpu_entry = newinfo->entries[raw_smp_processor_id()];
1841 memcpy(loc_cpu_entry, repl->entries, repl->size);
1843 ret = translate_table(table->name, table->valid_hooks,
1844 newinfo, loc_cpu_entry, repl->size,
1849 duprintf("arpt_register_table: translate table gives %d\n", ret);
1853 new_table = xt_register_table(net, table, &bootstrap, newinfo);
1854 if (IS_ERR(new_table)) {
1855 ret = PTR_ERR(new_table);
1861 xt_free_table_info(newinfo);
1863 return ERR_PTR(ret);
1866 void arpt_unregister_table(struct xt_table *table)
1868 struct xt_table_info *private;
1869 void *loc_cpu_entry;
1870 struct module *table_owner = table->me;
1872 private = xt_unregister_table(table);
1874 /* Decrease module usage counts and free resources */
1875 loc_cpu_entry = private->entries[raw_smp_processor_id()];
1876 ARPT_ENTRY_ITERATE(loc_cpu_entry, private->size,
1877 cleanup_entry, NULL);
1878 if (private->number > private->initial_entries)
1879 module_put(table_owner);
1880 xt_free_table_info(private);
1883 /* The built-in targets: standard (NULL) and error. */
1884 static struct xt_target arpt_standard_target __read_mostly = {
1885 .name = ARPT_STANDARD_TARGET,
1886 .targetsize = sizeof(int),
1887 .family = NFPROTO_ARP,
1888 #ifdef CONFIG_COMPAT
1889 .compatsize = sizeof(compat_int_t),
1890 .compat_from_user = compat_standard_from_user,
1891 .compat_to_user = compat_standard_to_user,
1895 static struct xt_target arpt_error_target __read_mostly = {
1896 .name = ARPT_ERROR_TARGET,
1897 .target = arpt_error,
1898 .targetsize = ARPT_FUNCTION_MAXNAMELEN,
1899 .family = NFPROTO_ARP,
1902 static struct nf_sockopt_ops arpt_sockopts = {
1904 .set_optmin = ARPT_BASE_CTL,
1905 .set_optmax = ARPT_SO_SET_MAX+1,
1906 .set = do_arpt_set_ctl,
1907 #ifdef CONFIG_COMPAT
1908 .compat_set = compat_do_arpt_set_ctl,
1910 .get_optmin = ARPT_BASE_CTL,
1911 .get_optmax = ARPT_SO_GET_MAX+1,
1912 .get = do_arpt_get_ctl,
1913 #ifdef CONFIG_COMPAT
1914 .compat_get = compat_do_arpt_get_ctl,
1916 .owner = THIS_MODULE,
1919 static int __net_init arp_tables_net_init(struct net *net)
1921 return xt_proto_init(net, NFPROTO_ARP);
1924 static void __net_exit arp_tables_net_exit(struct net *net)
1926 xt_proto_fini(net, NFPROTO_ARP);
1929 static struct pernet_operations arp_tables_net_ops = {
1930 .init = arp_tables_net_init,
1931 .exit = arp_tables_net_exit,
1934 static int __init arp_tables_init(void)
1938 ret = register_pernet_subsys(&arp_tables_net_ops);
1942 /* Noone else will be downing sem now, so we won't sleep */
1943 ret = xt_register_target(&arpt_standard_target);
1946 ret = xt_register_target(&arpt_error_target);
1950 /* Register setsockopt */
1951 ret = nf_register_sockopt(&arpt_sockopts);
1955 printk(KERN_INFO "arp_tables: (C) 2002 David S. Miller\n");
1959 xt_unregister_target(&arpt_error_target);
1961 xt_unregister_target(&arpt_standard_target);
1963 unregister_pernet_subsys(&arp_tables_net_ops);
1968 static void __exit arp_tables_fini(void)
1970 nf_unregister_sockopt(&arpt_sockopts);
1971 xt_unregister_target(&arpt_error_target);
1972 xt_unregister_target(&arpt_standard_target);
1973 unregister_pernet_subsys(&arp_tables_net_ops);
1976 EXPORT_SYMBOL(arpt_register_table);
1977 EXPORT_SYMBOL(arpt_unregister_table);
1978 EXPORT_SYMBOL(arpt_do_table);
1980 module_init(arp_tables_init);
1981 module_exit(arp_tables_fini);