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 unsigned long ret = ifname_compare_aligned(_a, _b, _mask);
86 unsigned long ret = 0;
87 const u16 *a = (const u16 *)_a;
88 const u16 *b = (const u16 *)_b;
89 const u16 *mask = (const u16 *)_mask;
92 for (i = 0; i < IFNAMSIZ/sizeof(u16); i++)
93 ret |= (a[i] ^ b[i]) & mask[i];
98 /* Returns whether packet matches rule or not. */
99 static inline int arp_packet_match(const struct arphdr *arphdr,
100 struct net_device *dev,
103 const struct arpt_arp *arpinfo)
105 const char *arpptr = (char *)(arphdr + 1);
106 const char *src_devaddr, *tgt_devaddr;
107 __be32 src_ipaddr, tgt_ipaddr;
110 #define FWINV(bool, invflg) ((bool) ^ !!(arpinfo->invflags & (invflg)))
112 if (FWINV((arphdr->ar_op & arpinfo->arpop_mask) != arpinfo->arpop,
114 dprintf("ARP operation field mismatch.\n");
115 dprintf("ar_op: %04x info->arpop: %04x info->arpop_mask: %04x\n",
116 arphdr->ar_op, arpinfo->arpop, arpinfo->arpop_mask);
120 if (FWINV((arphdr->ar_hrd & arpinfo->arhrd_mask) != arpinfo->arhrd,
122 dprintf("ARP hardware address format mismatch.\n");
123 dprintf("ar_hrd: %04x info->arhrd: %04x info->arhrd_mask: %04x\n",
124 arphdr->ar_hrd, arpinfo->arhrd, arpinfo->arhrd_mask);
128 if (FWINV((arphdr->ar_pro & arpinfo->arpro_mask) != arpinfo->arpro,
130 dprintf("ARP protocol address format mismatch.\n");
131 dprintf("ar_pro: %04x info->arpro: %04x info->arpro_mask: %04x\n",
132 arphdr->ar_pro, arpinfo->arpro, arpinfo->arpro_mask);
136 if (FWINV((arphdr->ar_hln & arpinfo->arhln_mask) != arpinfo->arhln,
138 dprintf("ARP hardware address length mismatch.\n");
139 dprintf("ar_hln: %02x info->arhln: %02x info->arhln_mask: %02x\n",
140 arphdr->ar_hln, arpinfo->arhln, arpinfo->arhln_mask);
144 src_devaddr = arpptr;
145 arpptr += dev->addr_len;
146 memcpy(&src_ipaddr, arpptr, sizeof(u32));
147 arpptr += sizeof(u32);
148 tgt_devaddr = arpptr;
149 arpptr += dev->addr_len;
150 memcpy(&tgt_ipaddr, arpptr, sizeof(u32));
152 if (FWINV(arp_devaddr_compare(&arpinfo->src_devaddr, src_devaddr, dev->addr_len),
153 ARPT_INV_SRCDEVADDR) ||
154 FWINV(arp_devaddr_compare(&arpinfo->tgt_devaddr, tgt_devaddr, dev->addr_len),
155 ARPT_INV_TGTDEVADDR)) {
156 dprintf("Source or target device address mismatch.\n");
161 if (FWINV((src_ipaddr & arpinfo->smsk.s_addr) != arpinfo->src.s_addr,
163 FWINV(((tgt_ipaddr & arpinfo->tmsk.s_addr) != arpinfo->tgt.s_addr),
165 dprintf("Source or target IP address mismatch.\n");
167 dprintf("SRC: %pI4. Mask: %pI4. Target: %pI4.%s\n",
169 &arpinfo->smsk.s_addr,
170 &arpinfo->src.s_addr,
171 arpinfo->invflags & ARPT_INV_SRCIP ? " (INV)" : "");
172 dprintf("TGT: %pI4 Mask: %pI4 Target: %pI4.%s\n",
174 &arpinfo->tmsk.s_addr,
175 &arpinfo->tgt.s_addr,
176 arpinfo->invflags & ARPT_INV_TGTIP ? " (INV)" : "");
180 /* Look for ifname matches. */
181 ret = ifname_compare(indev, arpinfo->iniface, arpinfo->iniface_mask);
183 if (FWINV(ret != 0, ARPT_INV_VIA_IN)) {
184 dprintf("VIA in mismatch (%s vs %s).%s\n",
185 indev, arpinfo->iniface,
186 arpinfo->invflags&ARPT_INV_VIA_IN ?" (INV)":"");
190 ret = ifname_compare(outdev, arpinfo->outiface, arpinfo->outiface_mask);
192 if (FWINV(ret != 0, ARPT_INV_VIA_OUT)) {
193 dprintf("VIA out mismatch (%s vs %s).%s\n",
194 outdev, arpinfo->outiface,
195 arpinfo->invflags&ARPT_INV_VIA_OUT ?" (INV)":"");
203 static inline int arp_checkentry(const struct arpt_arp *arp)
205 if (arp->flags & ~ARPT_F_MASK) {
206 duprintf("Unknown flag bits set: %08X\n",
207 arp->flags & ~ARPT_F_MASK);
210 if (arp->invflags & ~ARPT_INV_MASK) {
211 duprintf("Unknown invflag bits set: %08X\n",
212 arp->invflags & ~ARPT_INV_MASK);
220 arpt_error(struct sk_buff *skb, const struct xt_target_param *par)
223 printk("arp_tables: error: '%s'\n",
224 (const char *)par->targinfo);
229 static inline struct arpt_entry *get_entry(void *base, unsigned int offset)
231 return (struct arpt_entry *)(base + offset);
234 unsigned int arpt_do_table(struct sk_buff *skb,
236 const struct net_device *in,
237 const struct net_device *out,
238 struct xt_table *table)
240 static const char nulldevname[IFNAMSIZ] __attribute__((aligned(sizeof(long))));
241 unsigned int verdict = NF_DROP;
242 const struct arphdr *arp;
243 bool hotdrop = false;
244 struct arpt_entry *e, *back;
245 const char *indev, *outdev;
247 const struct xt_table_info *private;
248 struct xt_target_param tgpar;
250 if (!pskb_may_pull(skb, arp_hdr_len(skb->dev)))
253 indev = in ? in->name : nulldevname;
254 outdev = out ? out->name : nulldevname;
257 private = rcu_dereference(table->private);
258 table_base = rcu_dereference(private->entries[smp_processor_id()]);
260 e = get_entry(table_base, private->hook_entry[hook]);
261 back = get_entry(table_base, private->underflow[hook]);
265 tgpar.hooknum = hook;
266 tgpar.family = NFPROTO_ARP;
270 if (arp_packet_match(arp, skb->dev, indev, outdev, &e->arp)) {
271 struct arpt_entry_target *t;
274 hdr_len = sizeof(*arp) + (2 * sizeof(struct in_addr)) +
275 (2 * skb->dev->addr_len);
276 ADD_COUNTER(e->counters, hdr_len, 1);
278 t = arpt_get_target(e);
280 /* Standard target? */
281 if (!t->u.kernel.target->target) {
284 v = ((struct arpt_standard_target *)t)->verdict;
286 /* Pop from stack? */
287 if (v != ARPT_RETURN) {
288 verdict = (unsigned)(-v) - 1;
292 back = get_entry(table_base,
297 != (void *)e + e->next_offset) {
298 /* Save old back ptr in next entry */
299 struct arpt_entry *next
300 = (void *)e + e->next_offset;
302 (void *)back - table_base;
304 /* set back pointer to next entry */
308 e = get_entry(table_base, v);
310 /* Targets which reenter must return
313 tgpar.target = t->u.kernel.target;
314 tgpar.targinfo = t->data;
315 verdict = t->u.kernel.target->target(skb,
318 /* Target might have changed stuff. */
321 if (verdict == ARPT_CONTINUE)
322 e = (void *)e + e->next_offset;
328 e = (void *)e + e->next_offset;
332 rcu_read_unlock_bh();
340 /* All zeroes == unconditional rule. */
341 static inline int unconditional(const struct arpt_arp *arp)
345 for (i = 0; i < sizeof(*arp)/sizeof(__u32); i++)
346 if (((__u32 *)arp)[i])
352 /* Figures out from what hook each rule can be called: returns 0 if
353 * there are loops. Puts hook bitmask in comefrom.
355 static int mark_source_chains(struct xt_table_info *newinfo,
356 unsigned int valid_hooks, void *entry0)
360 /* No recursion; use packet counter to save back ptrs (reset
361 * to 0 as we leave), and comefrom to save source hook bitmask.
363 for (hook = 0; hook < NF_ARP_NUMHOOKS; hook++) {
364 unsigned int pos = newinfo->hook_entry[hook];
366 = (struct arpt_entry *)(entry0 + pos);
368 if (!(valid_hooks & (1 << hook)))
371 /* Set initial back pointer. */
372 e->counters.pcnt = pos;
375 const struct arpt_standard_target *t
376 = (void *)arpt_get_target(e);
377 int visited = e->comefrom & (1 << hook);
379 if (e->comefrom & (1 << NF_ARP_NUMHOOKS)) {
380 printk("arptables: loop hook %u pos %u %08X.\n",
381 hook, pos, e->comefrom);
385 |= ((1 << hook) | (1 << NF_ARP_NUMHOOKS));
387 /* Unconditional return/END. */
388 if ((e->target_offset == sizeof(struct arpt_entry)
389 && (strcmp(t->target.u.user.name,
390 ARPT_STANDARD_TARGET) == 0)
392 && unconditional(&e->arp)) || visited) {
393 unsigned int oldpos, size;
395 if ((strcmp(t->target.u.user.name,
396 ARPT_STANDARD_TARGET) == 0) &&
397 t->verdict < -NF_MAX_VERDICT - 1) {
398 duprintf("mark_source_chains: bad "
399 "negative verdict (%i)\n",
404 /* Return: backtrack through the last
408 e->comefrom ^= (1<<NF_ARP_NUMHOOKS);
410 pos = e->counters.pcnt;
411 e->counters.pcnt = 0;
413 /* We're at the start. */
417 e = (struct arpt_entry *)
419 } while (oldpos == pos + e->next_offset);
422 size = e->next_offset;
423 e = (struct arpt_entry *)
424 (entry0 + pos + size);
425 e->counters.pcnt = pos;
428 int newpos = t->verdict;
430 if (strcmp(t->target.u.user.name,
431 ARPT_STANDARD_TARGET) == 0
433 if (newpos > newinfo->size -
434 sizeof(struct arpt_entry)) {
435 duprintf("mark_source_chains: "
436 "bad verdict (%i)\n",
441 /* This a jump; chase it. */
442 duprintf("Jump rule %u -> %u\n",
445 /* ... this is a fallthru */
446 newpos = pos + e->next_offset;
448 e = (struct arpt_entry *)
450 e->counters.pcnt = pos;
455 duprintf("Finished chain %u\n", hook);
460 static inline int check_entry(struct arpt_entry *e, const char *name)
462 const struct arpt_entry_target *t;
464 if (!arp_checkentry(&e->arp)) {
465 duprintf("arp_tables: arp check failed %p %s.\n", e, name);
469 if (e->target_offset + sizeof(struct arpt_entry_target) > e->next_offset)
472 t = arpt_get_target(e);
473 if (e->target_offset + t->u.target_size > e->next_offset)
479 static inline int check_target(struct arpt_entry *e, const char *name)
481 struct arpt_entry_target *t = arpt_get_target(e);
483 struct xt_tgchk_param par = {
486 .target = t->u.kernel.target,
488 .hook_mask = e->comefrom,
489 .family = NFPROTO_ARP,
492 ret = xt_check_target(&par, t->u.target_size - sizeof(*t), 0, false);
494 duprintf("arp_tables: check failed for `%s'.\n",
495 t->u.kernel.target->name);
502 find_check_entry(struct arpt_entry *e, const char *name, unsigned int size,
505 struct arpt_entry_target *t;
506 struct xt_target *target;
509 ret = check_entry(e, name);
513 t = arpt_get_target(e);
514 target = try_then_request_module(xt_find_target(NFPROTO_ARP,
517 "arpt_%s", t->u.user.name);
518 if (IS_ERR(target) || !target) {
519 duprintf("find_check_entry: `%s' not found\n", t->u.user.name);
520 ret = target ? PTR_ERR(target) : -ENOENT;
523 t->u.kernel.target = target;
525 ret = check_target(e, name);
532 module_put(t->u.kernel.target->me);
537 static inline int check_entry_size_and_hooks(struct arpt_entry *e,
538 struct xt_table_info *newinfo,
540 unsigned char *limit,
541 const unsigned int *hook_entries,
542 const unsigned int *underflows,
547 if ((unsigned long)e % __alignof__(struct arpt_entry) != 0
548 || (unsigned char *)e + sizeof(struct arpt_entry) >= limit) {
549 duprintf("Bad offset %p\n", e);
554 < sizeof(struct arpt_entry) + sizeof(struct arpt_entry_target)) {
555 duprintf("checking: element %p size %u\n",
560 /* Check hooks & underflows */
561 for (h = 0; h < NF_ARP_NUMHOOKS; h++) {
562 if ((unsigned char *)e - base == hook_entries[h])
563 newinfo->hook_entry[h] = hook_entries[h];
564 if ((unsigned char *)e - base == underflows[h])
565 newinfo->underflow[h] = underflows[h];
568 /* FIXME: underflows must be unconditional, standard verdicts
569 < 0 (not ARPT_RETURN). --RR */
571 /* Clear counters and comefrom */
572 e->counters = ((struct xt_counters) { 0, 0 });
579 static inline int cleanup_entry(struct arpt_entry *e, unsigned int *i)
581 struct xt_tgdtor_param par;
582 struct arpt_entry_target *t;
584 if (i && (*i)-- == 0)
587 t = arpt_get_target(e);
588 par.target = t->u.kernel.target;
589 par.targinfo = t->data;
590 par.family = NFPROTO_ARP;
591 if (par.target->destroy != NULL)
592 par.target->destroy(&par);
593 module_put(par.target->me);
597 /* Checks and translates the user-supplied table segment (held in
600 static int translate_table(const char *name,
601 unsigned int valid_hooks,
602 struct xt_table_info *newinfo,
606 const unsigned int *hook_entries,
607 const unsigned int *underflows)
612 newinfo->size = size;
613 newinfo->number = number;
615 /* Init all hooks to impossible value. */
616 for (i = 0; i < NF_ARP_NUMHOOKS; i++) {
617 newinfo->hook_entry[i] = 0xFFFFFFFF;
618 newinfo->underflow[i] = 0xFFFFFFFF;
621 duprintf("translate_table: size %u\n", newinfo->size);
624 /* Walk through entries, checking offsets. */
625 ret = ARPT_ENTRY_ITERATE(entry0, newinfo->size,
626 check_entry_size_and_hooks,
630 hook_entries, underflows, &i);
631 duprintf("translate_table: ARPT_ENTRY_ITERATE gives %d\n", ret);
636 duprintf("translate_table: %u not %u entries\n",
641 /* Check hooks all assigned */
642 for (i = 0; i < NF_ARP_NUMHOOKS; i++) {
643 /* Only hooks which are valid */
644 if (!(valid_hooks & (1 << i)))
646 if (newinfo->hook_entry[i] == 0xFFFFFFFF) {
647 duprintf("Invalid hook entry %u %u\n",
651 if (newinfo->underflow[i] == 0xFFFFFFFF) {
652 duprintf("Invalid underflow %u %u\n",
658 if (!mark_source_chains(newinfo, valid_hooks, entry0)) {
659 duprintf("Looping hook\n");
663 /* Finally, each sanity check must pass */
665 ret = ARPT_ENTRY_ITERATE(entry0, newinfo->size,
666 find_check_entry, name, size, &i);
669 ARPT_ENTRY_ITERATE(entry0, newinfo->size,
674 /* And one copy for every other CPU */
675 for_each_possible_cpu(i) {
676 if (newinfo->entries[i] && newinfo->entries[i] != entry0)
677 memcpy(newinfo->entries[i], entry0, newinfo->size);
684 static inline int add_entry_to_counter(const struct arpt_entry *e,
685 struct xt_counters total[],
688 ADD_COUNTER(total[*i], e->counters.bcnt, e->counters.pcnt);
694 static inline int set_entry_to_counter(const struct arpt_entry *e,
695 struct xt_counters total[],
698 SET_COUNTER(total[*i], e->counters.bcnt, e->counters.pcnt);
704 static void get_counters(const struct xt_table_info *t,
705 struct xt_counters counters[])
711 /* Instead of clearing (by a previous call to memset())
712 * the counters and using adds, we set the counters
713 * with data used by 'current' CPU
714 * We dont care about preemption here.
716 curcpu = raw_smp_processor_id();
719 ARPT_ENTRY_ITERATE(t->entries[curcpu],
721 set_entry_to_counter,
725 for_each_possible_cpu(cpu) {
729 ARPT_ENTRY_ITERATE(t->entries[cpu],
731 add_entry_to_counter,
738 /* We're lazy, and add to the first CPU; overflow works its fey magic
739 * and everything is OK. */
741 add_counter_to_entry(struct arpt_entry *e,
742 const struct xt_counters addme[],
745 ADD_COUNTER(e->counters, addme[*i].bcnt, addme[*i].pcnt);
751 /* Take values from counters and add them back onto the current cpu */
752 static void put_counters(struct xt_table_info *t,
753 const struct xt_counters counters[])
758 cpu = smp_processor_id();
760 ARPT_ENTRY_ITERATE(t->entries[cpu],
762 add_counter_to_entry,
769 zero_entry_counter(struct arpt_entry *e, void *arg)
771 e->counters.bcnt = 0;
772 e->counters.pcnt = 0;
777 clone_counters(struct xt_table_info *newinfo, const struct xt_table_info *info)
780 const void *loc_cpu_entry = info->entries[raw_smp_processor_id()];
782 memcpy(newinfo, info, offsetof(struct xt_table_info, entries));
783 for_each_possible_cpu(cpu) {
784 memcpy(newinfo->entries[cpu], loc_cpu_entry, info->size);
785 ARPT_ENTRY_ITERATE(newinfo->entries[cpu], newinfo->size,
786 zero_entry_counter, NULL);
790 static struct xt_counters *alloc_counters(struct xt_table *table)
792 unsigned int countersize;
793 struct xt_counters *counters;
794 struct xt_table_info *private = table->private;
795 struct xt_table_info *info;
797 /* We need atomic snapshot of counters: rest doesn't change
798 * (other than comefrom, which userspace doesn't care
801 countersize = sizeof(struct xt_counters) * private->number;
802 counters = vmalloc_node(countersize, numa_node_id());
804 if (counters == NULL)
807 info = xt_alloc_table_info(private->size);
811 clone_counters(info, private);
813 mutex_lock(&table->lock);
814 xt_table_entry_swap_rcu(private, info);
815 synchronize_net(); /* Wait until smoke has cleared */
817 get_counters(info, counters);
818 put_counters(private, counters);
819 mutex_unlock(&table->lock);
821 xt_free_table_info(info);
828 return ERR_PTR(-ENOMEM);
831 static int copy_entries_to_user(unsigned int total_size,
832 struct xt_table *table,
833 void __user *userptr)
835 unsigned int off, num;
836 struct arpt_entry *e;
837 struct xt_counters *counters;
838 struct xt_table_info *private = table->private;
842 counters = alloc_counters(table);
843 if (IS_ERR(counters))
844 return PTR_ERR(counters);
846 loc_cpu_entry = private->entries[raw_smp_processor_id()];
847 /* ... then copy entire thing ... */
848 if (copy_to_user(userptr, loc_cpu_entry, total_size) != 0) {
853 /* FIXME: use iterator macros --RR */
854 /* ... then go back and fix counters and names */
855 for (off = 0, num = 0; off < total_size; off += e->next_offset, num++){
856 struct arpt_entry_target *t;
858 e = (struct arpt_entry *)(loc_cpu_entry + off);
859 if (copy_to_user(userptr + off
860 + offsetof(struct arpt_entry, counters),
862 sizeof(counters[num])) != 0) {
867 t = arpt_get_target(e);
868 if (copy_to_user(userptr + off + e->target_offset
869 + offsetof(struct arpt_entry_target,
871 t->u.kernel.target->name,
872 strlen(t->u.kernel.target->name)+1) != 0) {
884 static void compat_standard_from_user(void *dst, void *src)
886 int v = *(compat_int_t *)src;
889 v += xt_compat_calc_jump(NFPROTO_ARP, v);
890 memcpy(dst, &v, sizeof(v));
893 static int compat_standard_to_user(void __user *dst, void *src)
895 compat_int_t cv = *(int *)src;
898 cv -= xt_compat_calc_jump(NFPROTO_ARP, cv);
899 return copy_to_user(dst, &cv, sizeof(cv)) ? -EFAULT : 0;
902 static int compat_calc_entry(struct arpt_entry *e,
903 const struct xt_table_info *info,
904 void *base, struct xt_table_info *newinfo)
906 struct arpt_entry_target *t;
907 unsigned int entry_offset;
910 off = sizeof(struct arpt_entry) - sizeof(struct compat_arpt_entry);
911 entry_offset = (void *)e - base;
913 t = arpt_get_target(e);
914 off += xt_compat_target_offset(t->u.kernel.target);
915 newinfo->size -= off;
916 ret = xt_compat_add_offset(NFPROTO_ARP, entry_offset, off);
920 for (i = 0; i < NF_ARP_NUMHOOKS; i++) {
921 if (info->hook_entry[i] &&
922 (e < (struct arpt_entry *)(base + info->hook_entry[i])))
923 newinfo->hook_entry[i] -= off;
924 if (info->underflow[i] &&
925 (e < (struct arpt_entry *)(base + info->underflow[i])))
926 newinfo->underflow[i] -= off;
931 static int compat_table_info(const struct xt_table_info *info,
932 struct xt_table_info *newinfo)
936 if (!newinfo || !info)
939 /* we dont care about newinfo->entries[] */
940 memcpy(newinfo, info, offsetof(struct xt_table_info, entries));
941 newinfo->initial_entries = 0;
942 loc_cpu_entry = info->entries[raw_smp_processor_id()];
943 return ARPT_ENTRY_ITERATE(loc_cpu_entry, info->size,
944 compat_calc_entry, info, loc_cpu_entry,
949 static int get_info(struct net *net, void __user *user, int *len, int compat)
951 char name[ARPT_TABLE_MAXNAMELEN];
955 if (*len != sizeof(struct arpt_getinfo)) {
956 duprintf("length %u != %Zu\n", *len,
957 sizeof(struct arpt_getinfo));
961 if (copy_from_user(name, user, sizeof(name)) != 0)
964 name[ARPT_TABLE_MAXNAMELEN-1] = '\0';
967 xt_compat_lock(NFPROTO_ARP);
969 t = try_then_request_module(xt_find_table_lock(net, NFPROTO_ARP, name),
970 "arptable_%s", name);
971 if (t && !IS_ERR(t)) {
972 struct arpt_getinfo info;
973 const struct xt_table_info *private = t->private;
977 struct xt_table_info tmp;
978 ret = compat_table_info(private, &tmp);
979 xt_compat_flush_offsets(NFPROTO_ARP);
983 info.valid_hooks = t->valid_hooks;
984 memcpy(info.hook_entry, private->hook_entry,
985 sizeof(info.hook_entry));
986 memcpy(info.underflow, private->underflow,
987 sizeof(info.underflow));
988 info.num_entries = private->number;
989 info.size = private->size;
990 strcpy(info.name, name);
992 if (copy_to_user(user, &info, *len) != 0)
999 ret = t ? PTR_ERR(t) : -ENOENT;
1000 #ifdef CONFIG_COMPAT
1002 xt_compat_unlock(NFPROTO_ARP);
1007 static int get_entries(struct net *net, struct arpt_get_entries __user *uptr,
1011 struct arpt_get_entries get;
1014 if (*len < sizeof(get)) {
1015 duprintf("get_entries: %u < %Zu\n", *len, sizeof(get));
1018 if (copy_from_user(&get, uptr, sizeof(get)) != 0)
1020 if (*len != sizeof(struct arpt_get_entries) + get.size) {
1021 duprintf("get_entries: %u != %Zu\n", *len,
1022 sizeof(struct arpt_get_entries) + get.size);
1026 t = xt_find_table_lock(net, NFPROTO_ARP, get.name);
1027 if (t && !IS_ERR(t)) {
1028 const struct xt_table_info *private = t->private;
1030 duprintf("t->private->number = %u\n",
1032 if (get.size == private->size)
1033 ret = copy_entries_to_user(private->size,
1034 t, uptr->entrytable);
1036 duprintf("get_entries: I've got %u not %u!\n",
1037 private->size, get.size);
1043 ret = t ? PTR_ERR(t) : -ENOENT;
1048 static int __do_replace(struct net *net, const char *name,
1049 unsigned int valid_hooks,
1050 struct xt_table_info *newinfo,
1051 unsigned int num_counters,
1052 void __user *counters_ptr)
1056 struct xt_table_info *oldinfo;
1057 struct xt_counters *counters;
1058 void *loc_cpu_old_entry;
1061 counters = vmalloc_node(num_counters * sizeof(struct xt_counters),
1068 t = try_then_request_module(xt_find_table_lock(net, NFPROTO_ARP, name),
1069 "arptable_%s", name);
1070 if (!t || IS_ERR(t)) {
1071 ret = t ? PTR_ERR(t) : -ENOENT;
1072 goto free_newinfo_counters_untrans;
1076 if (valid_hooks != t->valid_hooks) {
1077 duprintf("Valid hook crap: %08X vs %08X\n",
1078 valid_hooks, t->valid_hooks);
1083 oldinfo = xt_replace_table(t, num_counters, newinfo, &ret);
1087 /* Update module usage count based on number of rules */
1088 duprintf("do_replace: oldnum=%u, initnum=%u, newnum=%u\n",
1089 oldinfo->number, oldinfo->initial_entries, newinfo->number);
1090 if ((oldinfo->number > oldinfo->initial_entries) ||
1091 (newinfo->number <= oldinfo->initial_entries))
1093 if ((oldinfo->number > oldinfo->initial_entries) &&
1094 (newinfo->number <= oldinfo->initial_entries))
1097 /* Get the old counters. */
1098 get_counters(oldinfo, counters);
1099 /* Decrease module usage counts and free resource */
1100 loc_cpu_old_entry = oldinfo->entries[raw_smp_processor_id()];
1101 ARPT_ENTRY_ITERATE(loc_cpu_old_entry, oldinfo->size, cleanup_entry,
1104 xt_free_table_info(oldinfo);
1105 if (copy_to_user(counters_ptr, counters,
1106 sizeof(struct xt_counters) * num_counters) != 0)
1115 free_newinfo_counters_untrans:
1121 static int do_replace(struct net *net, void __user *user, unsigned int len)
1124 struct arpt_replace tmp;
1125 struct xt_table_info *newinfo;
1126 void *loc_cpu_entry;
1128 if (copy_from_user(&tmp, user, sizeof(tmp)) != 0)
1131 /* overflow check */
1132 if (tmp.num_counters >= INT_MAX / sizeof(struct xt_counters))
1135 newinfo = xt_alloc_table_info(tmp.size);
1139 /* choose the copy that is on our node/cpu */
1140 loc_cpu_entry = newinfo->entries[raw_smp_processor_id()];
1141 if (copy_from_user(loc_cpu_entry, user + sizeof(tmp),
1147 ret = translate_table(tmp.name, tmp.valid_hooks,
1148 newinfo, loc_cpu_entry, tmp.size, tmp.num_entries,
1149 tmp.hook_entry, tmp.underflow);
1153 duprintf("arp_tables: Translated table\n");
1155 ret = __do_replace(net, tmp.name, tmp.valid_hooks, newinfo,
1156 tmp.num_counters, tmp.counters);
1158 goto free_newinfo_untrans;
1161 free_newinfo_untrans:
1162 ARPT_ENTRY_ITERATE(loc_cpu_entry, newinfo->size, cleanup_entry, NULL);
1164 xt_free_table_info(newinfo);
1168 static int do_add_counters(struct net *net, void __user *user, unsigned int len,
1172 struct xt_counters_info tmp;
1173 struct xt_counters *paddc;
1174 unsigned int num_counters;
1179 const struct xt_table_info *private;
1181 void *loc_cpu_entry;
1182 #ifdef CONFIG_COMPAT
1183 struct compat_xt_counters_info compat_tmp;
1187 size = sizeof(struct compat_xt_counters_info);
1192 size = sizeof(struct xt_counters_info);
1195 if (copy_from_user(ptmp, user, size) != 0)
1198 #ifdef CONFIG_COMPAT
1200 num_counters = compat_tmp.num_counters;
1201 name = compat_tmp.name;
1205 num_counters = tmp.num_counters;
1209 if (len != size + num_counters * sizeof(struct xt_counters))
1212 paddc = vmalloc_node(len - size, numa_node_id());
1216 if (copy_from_user(paddc, user + size, len - size) != 0) {
1221 t = xt_find_table_lock(net, NFPROTO_ARP, name);
1222 if (!t || IS_ERR(t)) {
1223 ret = t ? PTR_ERR(t) : -ENOENT;
1227 mutex_lock(&t->lock);
1228 private = t->private;
1229 if (private->number != num_counters) {
1231 goto unlock_up_free;
1236 /* Choose the copy that is on our node */
1237 loc_cpu_entry = private->entries[smp_processor_id()];
1238 ARPT_ENTRY_ITERATE(loc_cpu_entry,
1240 add_counter_to_entry,
1245 mutex_unlock(&t->lock);
1255 #ifdef CONFIG_COMPAT
1257 compat_release_entry(struct compat_arpt_entry *e, unsigned int *i)
1259 struct arpt_entry_target *t;
1261 if (i && (*i)-- == 0)
1264 t = compat_arpt_get_target(e);
1265 module_put(t->u.kernel.target->me);
1270 check_compat_entry_size_and_hooks(struct compat_arpt_entry *e,
1271 struct xt_table_info *newinfo,
1273 unsigned char *base,
1274 unsigned char *limit,
1275 unsigned int *hook_entries,
1276 unsigned int *underflows,
1280 struct arpt_entry_target *t;
1281 struct xt_target *target;
1282 unsigned int entry_offset;
1285 duprintf("check_compat_entry_size_and_hooks %p\n", e);
1286 if ((unsigned long)e % __alignof__(struct compat_arpt_entry) != 0
1287 || (unsigned char *)e + sizeof(struct compat_arpt_entry) >= limit) {
1288 duprintf("Bad offset %p, limit = %p\n", e, limit);
1292 if (e->next_offset < sizeof(struct compat_arpt_entry) +
1293 sizeof(struct compat_xt_entry_target)) {
1294 duprintf("checking: element %p size %u\n",
1299 /* For purposes of check_entry casting the compat entry is fine */
1300 ret = check_entry((struct arpt_entry *)e, name);
1304 off = sizeof(struct arpt_entry) - sizeof(struct compat_arpt_entry);
1305 entry_offset = (void *)e - (void *)base;
1307 t = compat_arpt_get_target(e);
1308 target = try_then_request_module(xt_find_target(NFPROTO_ARP,
1310 t->u.user.revision),
1311 "arpt_%s", t->u.user.name);
1312 if (IS_ERR(target) || !target) {
1313 duprintf("check_compat_entry_size_and_hooks: `%s' not found\n",
1315 ret = target ? PTR_ERR(target) : -ENOENT;
1318 t->u.kernel.target = target;
1320 off += xt_compat_target_offset(target);
1322 ret = xt_compat_add_offset(NFPROTO_ARP, entry_offset, off);
1324 goto release_target;
1326 /* Check hooks & underflows */
1327 for (h = 0; h < NF_ARP_NUMHOOKS; h++) {
1328 if ((unsigned char *)e - base == hook_entries[h])
1329 newinfo->hook_entry[h] = hook_entries[h];
1330 if ((unsigned char *)e - base == underflows[h])
1331 newinfo->underflow[h] = underflows[h];
1334 /* Clear counters and comefrom */
1335 memset(&e->counters, 0, sizeof(e->counters));
1342 module_put(t->u.kernel.target->me);
1348 compat_copy_entry_from_user(struct compat_arpt_entry *e, void **dstptr,
1349 unsigned int *size, const char *name,
1350 struct xt_table_info *newinfo, unsigned char *base)
1352 struct arpt_entry_target *t;
1353 struct xt_target *target;
1354 struct arpt_entry *de;
1355 unsigned int origsize;
1360 de = (struct arpt_entry *)*dstptr;
1361 memcpy(de, e, sizeof(struct arpt_entry));
1362 memcpy(&de->counters, &e->counters, sizeof(e->counters));
1364 *dstptr += sizeof(struct arpt_entry);
1365 *size += sizeof(struct arpt_entry) - sizeof(struct compat_arpt_entry);
1367 de->target_offset = e->target_offset - (origsize - *size);
1368 t = compat_arpt_get_target(e);
1369 target = t->u.kernel.target;
1370 xt_compat_target_from_user(t, dstptr, size);
1372 de->next_offset = e->next_offset - (origsize - *size);
1373 for (h = 0; h < NF_ARP_NUMHOOKS; h++) {
1374 if ((unsigned char *)de - base < newinfo->hook_entry[h])
1375 newinfo->hook_entry[h] -= origsize - *size;
1376 if ((unsigned char *)de - base < newinfo->underflow[h])
1377 newinfo->underflow[h] -= origsize - *size;
1382 static inline int compat_check_entry(struct arpt_entry *e, const char *name,
1387 ret = check_target(e, name);
1395 static int translate_compat_table(const char *name,
1396 unsigned int valid_hooks,
1397 struct xt_table_info **pinfo,
1399 unsigned int total_size,
1400 unsigned int number,
1401 unsigned int *hook_entries,
1402 unsigned int *underflows)
1405 struct xt_table_info *newinfo, *info;
1406 void *pos, *entry0, *entry1;
1413 info->number = number;
1415 /* Init all hooks to impossible value. */
1416 for (i = 0; i < NF_ARP_NUMHOOKS; i++) {
1417 info->hook_entry[i] = 0xFFFFFFFF;
1418 info->underflow[i] = 0xFFFFFFFF;
1421 duprintf("translate_compat_table: size %u\n", info->size);
1423 xt_compat_lock(NFPROTO_ARP);
1424 /* Walk through entries, checking offsets. */
1425 ret = COMPAT_ARPT_ENTRY_ITERATE(entry0, total_size,
1426 check_compat_entry_size_and_hooks,
1427 info, &size, entry0,
1428 entry0 + total_size,
1429 hook_entries, underflows, &j, name);
1435 duprintf("translate_compat_table: %u not %u entries\n",
1440 /* Check hooks all assigned */
1441 for (i = 0; i < NF_ARP_NUMHOOKS; i++) {
1442 /* Only hooks which are valid */
1443 if (!(valid_hooks & (1 << i)))
1445 if (info->hook_entry[i] == 0xFFFFFFFF) {
1446 duprintf("Invalid hook entry %u %u\n",
1447 i, hook_entries[i]);
1450 if (info->underflow[i] == 0xFFFFFFFF) {
1451 duprintf("Invalid underflow %u %u\n",
1458 newinfo = xt_alloc_table_info(size);
1462 newinfo->number = number;
1463 for (i = 0; i < NF_ARP_NUMHOOKS; i++) {
1464 newinfo->hook_entry[i] = info->hook_entry[i];
1465 newinfo->underflow[i] = info->underflow[i];
1467 entry1 = newinfo->entries[raw_smp_processor_id()];
1470 ret = COMPAT_ARPT_ENTRY_ITERATE(entry0, total_size,
1471 compat_copy_entry_from_user,
1472 &pos, &size, name, newinfo, entry1);
1473 xt_compat_flush_offsets(NFPROTO_ARP);
1474 xt_compat_unlock(NFPROTO_ARP);
1479 if (!mark_source_chains(newinfo, valid_hooks, entry1))
1483 ret = ARPT_ENTRY_ITERATE(entry1, newinfo->size, compat_check_entry,
1487 COMPAT_ARPT_ENTRY_ITERATE_CONTINUE(entry0, newinfo->size, i,
1488 compat_release_entry, &j);
1489 ARPT_ENTRY_ITERATE(entry1, newinfo->size, cleanup_entry, &i);
1490 xt_free_table_info(newinfo);
1494 /* And one copy for every other CPU */
1495 for_each_possible_cpu(i)
1496 if (newinfo->entries[i] && newinfo->entries[i] != entry1)
1497 memcpy(newinfo->entries[i], entry1, newinfo->size);
1501 xt_free_table_info(info);
1505 xt_free_table_info(newinfo);
1507 COMPAT_ARPT_ENTRY_ITERATE(entry0, total_size, compat_release_entry, &j);
1510 xt_compat_flush_offsets(NFPROTO_ARP);
1511 xt_compat_unlock(NFPROTO_ARP);
1515 struct compat_arpt_replace {
1516 char name[ARPT_TABLE_MAXNAMELEN];
1520 u32 hook_entry[NF_ARP_NUMHOOKS];
1521 u32 underflow[NF_ARP_NUMHOOKS];
1523 compat_uptr_t counters;
1524 struct compat_arpt_entry entries[0];
1527 static int compat_do_replace(struct net *net, void __user *user,
1531 struct compat_arpt_replace tmp;
1532 struct xt_table_info *newinfo;
1533 void *loc_cpu_entry;
1535 if (copy_from_user(&tmp, user, sizeof(tmp)) != 0)
1538 /* overflow check */
1539 if (tmp.size >= INT_MAX / num_possible_cpus())
1541 if (tmp.num_counters >= INT_MAX / sizeof(struct xt_counters))
1544 newinfo = xt_alloc_table_info(tmp.size);
1548 /* choose the copy that is on our node/cpu */
1549 loc_cpu_entry = newinfo->entries[raw_smp_processor_id()];
1550 if (copy_from_user(loc_cpu_entry, user + sizeof(tmp), tmp.size) != 0) {
1555 ret = translate_compat_table(tmp.name, tmp.valid_hooks,
1556 &newinfo, &loc_cpu_entry, tmp.size,
1557 tmp.num_entries, tmp.hook_entry,
1562 duprintf("compat_do_replace: Translated table\n");
1564 ret = __do_replace(net, tmp.name, tmp.valid_hooks, newinfo,
1565 tmp.num_counters, compat_ptr(tmp.counters));
1567 goto free_newinfo_untrans;
1570 free_newinfo_untrans:
1571 ARPT_ENTRY_ITERATE(loc_cpu_entry, newinfo->size, cleanup_entry, NULL);
1573 xt_free_table_info(newinfo);
1577 static int compat_do_arpt_set_ctl(struct sock *sk, int cmd, void __user *user,
1582 if (!capable(CAP_NET_ADMIN))
1586 case ARPT_SO_SET_REPLACE:
1587 ret = compat_do_replace(sock_net(sk), user, len);
1590 case ARPT_SO_SET_ADD_COUNTERS:
1591 ret = do_add_counters(sock_net(sk), user, len, 1);
1595 duprintf("do_arpt_set_ctl: unknown request %i\n", cmd);
1602 static int compat_copy_entry_to_user(struct arpt_entry *e, void __user **dstptr,
1603 compat_uint_t *size,
1604 struct xt_counters *counters,
1607 struct arpt_entry_target *t;
1608 struct compat_arpt_entry __user *ce;
1609 u_int16_t target_offset, next_offset;
1610 compat_uint_t origsize;
1615 ce = (struct compat_arpt_entry __user *)*dstptr;
1616 if (copy_to_user(ce, e, sizeof(struct arpt_entry)))
1619 if (copy_to_user(&ce->counters, &counters[*i], sizeof(counters[*i])))
1622 *dstptr += sizeof(struct compat_arpt_entry);
1623 *size -= sizeof(struct arpt_entry) - sizeof(struct compat_arpt_entry);
1625 target_offset = e->target_offset - (origsize - *size);
1627 t = arpt_get_target(e);
1628 ret = xt_compat_target_to_user(t, dstptr, size);
1632 next_offset = e->next_offset - (origsize - *size);
1633 if (put_user(target_offset, &ce->target_offset))
1635 if (put_user(next_offset, &ce->next_offset))
1644 static int compat_copy_entries_to_user(unsigned int total_size,
1645 struct xt_table *table,
1646 void __user *userptr)
1648 struct xt_counters *counters;
1649 const struct xt_table_info *private = table->private;
1653 void *loc_cpu_entry;
1656 counters = alloc_counters(table);
1657 if (IS_ERR(counters))
1658 return PTR_ERR(counters);
1660 /* choose the copy on our node/cpu */
1661 loc_cpu_entry = private->entries[raw_smp_processor_id()];
1664 ret = ARPT_ENTRY_ITERATE(loc_cpu_entry, total_size,
1665 compat_copy_entry_to_user,
1666 &pos, &size, counters, &i);
1671 struct compat_arpt_get_entries {
1672 char name[ARPT_TABLE_MAXNAMELEN];
1674 struct compat_arpt_entry entrytable[0];
1677 static int compat_get_entries(struct net *net,
1678 struct compat_arpt_get_entries __user *uptr,
1682 struct compat_arpt_get_entries get;
1685 if (*len < sizeof(get)) {
1686 duprintf("compat_get_entries: %u < %zu\n", *len, sizeof(get));
1689 if (copy_from_user(&get, uptr, sizeof(get)) != 0)
1691 if (*len != sizeof(struct compat_arpt_get_entries) + get.size) {
1692 duprintf("compat_get_entries: %u != %zu\n",
1693 *len, sizeof(get) + get.size);
1697 xt_compat_lock(NFPROTO_ARP);
1698 t = xt_find_table_lock(net, NFPROTO_ARP, get.name);
1699 if (t && !IS_ERR(t)) {
1700 const struct xt_table_info *private = t->private;
1701 struct xt_table_info info;
1703 duprintf("t->private->number = %u\n", private->number);
1704 ret = compat_table_info(private, &info);
1705 if (!ret && get.size == info.size) {
1706 ret = compat_copy_entries_to_user(private->size,
1707 t, uptr->entrytable);
1709 duprintf("compat_get_entries: I've got %u not %u!\n",
1710 private->size, get.size);
1713 xt_compat_flush_offsets(NFPROTO_ARP);
1717 ret = t ? PTR_ERR(t) : -ENOENT;
1719 xt_compat_unlock(NFPROTO_ARP);
1723 static int do_arpt_get_ctl(struct sock *, int, void __user *, int *);
1725 static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
1730 if (!capable(CAP_NET_ADMIN))
1734 case ARPT_SO_GET_INFO:
1735 ret = get_info(sock_net(sk), user, len, 1);
1737 case ARPT_SO_GET_ENTRIES:
1738 ret = compat_get_entries(sock_net(sk), user, len);
1741 ret = do_arpt_get_ctl(sk, cmd, user, len);
1747 static int do_arpt_set_ctl(struct sock *sk, int cmd, void __user *user, unsigned int len)
1751 if (!capable(CAP_NET_ADMIN))
1755 case ARPT_SO_SET_REPLACE:
1756 ret = do_replace(sock_net(sk), user, len);
1759 case ARPT_SO_SET_ADD_COUNTERS:
1760 ret = do_add_counters(sock_net(sk), user, len, 0);
1764 duprintf("do_arpt_set_ctl: unknown request %i\n", cmd);
1771 static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
1775 if (!capable(CAP_NET_ADMIN))
1779 case ARPT_SO_GET_INFO:
1780 ret = get_info(sock_net(sk), user, len, 0);
1783 case ARPT_SO_GET_ENTRIES:
1784 ret = get_entries(sock_net(sk), user, len);
1787 case ARPT_SO_GET_REVISION_TARGET: {
1788 struct xt_get_revision rev;
1790 if (*len != sizeof(rev)) {
1794 if (copy_from_user(&rev, user, sizeof(rev)) != 0) {
1799 try_then_request_module(xt_find_revision(NFPROTO_ARP, rev.name,
1800 rev.revision, 1, &ret),
1801 "arpt_%s", rev.name);
1806 duprintf("do_arpt_get_ctl: unknown request %i\n", cmd);
1813 struct xt_table *arpt_register_table(struct net *net, struct xt_table *table,
1814 const struct arpt_replace *repl)
1817 struct xt_table_info *newinfo;
1818 struct xt_table_info bootstrap
1819 = { 0, 0, 0, { 0 }, { 0 }, { } };
1820 void *loc_cpu_entry;
1821 struct xt_table *new_table;
1823 newinfo = xt_alloc_table_info(repl->size);
1829 /* choose the copy on our node/cpu */
1830 loc_cpu_entry = newinfo->entries[raw_smp_processor_id()];
1831 memcpy(loc_cpu_entry, repl->entries, repl->size);
1833 ret = translate_table(table->name, table->valid_hooks,
1834 newinfo, loc_cpu_entry, repl->size,
1839 duprintf("arpt_register_table: translate table gives %d\n", ret);
1843 new_table = xt_register_table(net, table, &bootstrap, newinfo);
1844 if (IS_ERR(new_table)) {
1845 ret = PTR_ERR(new_table);
1851 xt_free_table_info(newinfo);
1853 return ERR_PTR(ret);
1856 void arpt_unregister_table(struct xt_table *table)
1858 struct xt_table_info *private;
1859 void *loc_cpu_entry;
1860 struct module *table_owner = table->me;
1862 private = xt_unregister_table(table);
1864 /* Decrease module usage counts and free resources */
1865 loc_cpu_entry = private->entries[raw_smp_processor_id()];
1866 ARPT_ENTRY_ITERATE(loc_cpu_entry, private->size,
1867 cleanup_entry, NULL);
1868 if (private->number > private->initial_entries)
1869 module_put(table_owner);
1870 xt_free_table_info(private);
1873 /* The built-in targets: standard (NULL) and error. */
1874 static struct xt_target arpt_standard_target __read_mostly = {
1875 .name = ARPT_STANDARD_TARGET,
1876 .targetsize = sizeof(int),
1877 .family = NFPROTO_ARP,
1878 #ifdef CONFIG_COMPAT
1879 .compatsize = sizeof(compat_int_t),
1880 .compat_from_user = compat_standard_from_user,
1881 .compat_to_user = compat_standard_to_user,
1885 static struct xt_target arpt_error_target __read_mostly = {
1886 .name = ARPT_ERROR_TARGET,
1887 .target = arpt_error,
1888 .targetsize = ARPT_FUNCTION_MAXNAMELEN,
1889 .family = NFPROTO_ARP,
1892 static struct nf_sockopt_ops arpt_sockopts = {
1894 .set_optmin = ARPT_BASE_CTL,
1895 .set_optmax = ARPT_SO_SET_MAX+1,
1896 .set = do_arpt_set_ctl,
1897 #ifdef CONFIG_COMPAT
1898 .compat_set = compat_do_arpt_set_ctl,
1900 .get_optmin = ARPT_BASE_CTL,
1901 .get_optmax = ARPT_SO_GET_MAX+1,
1902 .get = do_arpt_get_ctl,
1903 #ifdef CONFIG_COMPAT
1904 .compat_get = compat_do_arpt_get_ctl,
1906 .owner = THIS_MODULE,
1909 static int __net_init arp_tables_net_init(struct net *net)
1911 return xt_proto_init(net, NFPROTO_ARP);
1914 static void __net_exit arp_tables_net_exit(struct net *net)
1916 xt_proto_fini(net, NFPROTO_ARP);
1919 static struct pernet_operations arp_tables_net_ops = {
1920 .init = arp_tables_net_init,
1921 .exit = arp_tables_net_exit,
1924 static int __init arp_tables_init(void)
1928 ret = register_pernet_subsys(&arp_tables_net_ops);
1932 /* Noone else will be downing sem now, so we won't sleep */
1933 ret = xt_register_target(&arpt_standard_target);
1936 ret = xt_register_target(&arpt_error_target);
1940 /* Register setsockopt */
1941 ret = nf_register_sockopt(&arpt_sockopts);
1945 printk(KERN_INFO "arp_tables: (C) 2002 David S. Miller\n");
1949 xt_unregister_target(&arpt_error_target);
1951 xt_unregister_target(&arpt_standard_target);
1953 unregister_pernet_subsys(&arp_tables_net_ops);
1958 static void __exit arp_tables_fini(void)
1960 nf_unregister_sockopt(&arpt_sockopts);
1961 xt_unregister_target(&arpt_error_target);
1962 xt_unregister_target(&arpt_standard_target);
1963 unregister_pernet_subsys(&arp_tables_net_ops);
1966 EXPORT_SYMBOL(arpt_register_table);
1967 EXPORT_SYMBOL(arpt_unregister_table);
1968 EXPORT_SYMBOL(arpt_do_table);
1970 module_init(arp_tables_init);
1971 module_exit(arp_tables_fini);