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.
80 static unsigned long ifname_compare(const char *_a, const char *_b, const char *_mask)
82 #ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
83 const unsigned long *a = (const unsigned long *)_a;
84 const unsigned long *b = (const unsigned long *)_b;
85 const unsigned long *mask = (const unsigned long *)_mask;
88 ret = (a[0] ^ b[0]) & mask[0];
89 if (IFNAMSIZ > sizeof(unsigned long))
90 ret |= (a[1] ^ b[1]) & mask[1];
91 if (IFNAMSIZ > 2 * sizeof(unsigned long))
92 ret |= (a[2] ^ b[2]) & mask[2];
93 if (IFNAMSIZ > 3 * sizeof(unsigned long))
94 ret |= (a[3] ^ b[3]) & mask[3];
95 BUILD_BUG_ON(IFNAMSIZ > 4 * sizeof(unsigned long));
97 unsigned long ret = 0;
100 for (i = 0; i < IFNAMSIZ; i++)
101 ret |= (_a[i] ^ _b[i]) & _mask[i];
106 /* Returns whether packet matches rule or not. */
107 static inline int arp_packet_match(const struct arphdr *arphdr,
108 struct net_device *dev,
111 const struct arpt_arp *arpinfo)
113 const char *arpptr = (char *)(arphdr + 1);
114 const char *src_devaddr, *tgt_devaddr;
115 __be32 src_ipaddr, tgt_ipaddr;
118 #define FWINV(bool, invflg) ((bool) ^ !!(arpinfo->invflags & (invflg)))
120 if (FWINV((arphdr->ar_op & arpinfo->arpop_mask) != arpinfo->arpop,
122 dprintf("ARP operation field mismatch.\n");
123 dprintf("ar_op: %04x info->arpop: %04x info->arpop_mask: %04x\n",
124 arphdr->ar_op, arpinfo->arpop, arpinfo->arpop_mask);
128 if (FWINV((arphdr->ar_hrd & arpinfo->arhrd_mask) != arpinfo->arhrd,
130 dprintf("ARP hardware address format mismatch.\n");
131 dprintf("ar_hrd: %04x info->arhrd: %04x info->arhrd_mask: %04x\n",
132 arphdr->ar_hrd, arpinfo->arhrd, arpinfo->arhrd_mask);
136 if (FWINV((arphdr->ar_pro & arpinfo->arpro_mask) != arpinfo->arpro,
138 dprintf("ARP protocol address format mismatch.\n");
139 dprintf("ar_pro: %04x info->arpro: %04x info->arpro_mask: %04x\n",
140 arphdr->ar_pro, arpinfo->arpro, arpinfo->arpro_mask);
144 if (FWINV((arphdr->ar_hln & arpinfo->arhln_mask) != arpinfo->arhln,
146 dprintf("ARP hardware address length mismatch.\n");
147 dprintf("ar_hln: %02x info->arhln: %02x info->arhln_mask: %02x\n",
148 arphdr->ar_hln, arpinfo->arhln, arpinfo->arhln_mask);
152 src_devaddr = arpptr;
153 arpptr += dev->addr_len;
154 memcpy(&src_ipaddr, arpptr, sizeof(u32));
155 arpptr += sizeof(u32);
156 tgt_devaddr = arpptr;
157 arpptr += dev->addr_len;
158 memcpy(&tgt_ipaddr, arpptr, sizeof(u32));
160 if (FWINV(arp_devaddr_compare(&arpinfo->src_devaddr, src_devaddr, dev->addr_len),
161 ARPT_INV_SRCDEVADDR) ||
162 FWINV(arp_devaddr_compare(&arpinfo->tgt_devaddr, tgt_devaddr, dev->addr_len),
163 ARPT_INV_TGTDEVADDR)) {
164 dprintf("Source or target device address mismatch.\n");
169 if (FWINV((src_ipaddr & arpinfo->smsk.s_addr) != arpinfo->src.s_addr,
171 FWINV(((tgt_ipaddr & arpinfo->tmsk.s_addr) != arpinfo->tgt.s_addr),
173 dprintf("Source or target IP address mismatch.\n");
175 dprintf("SRC: %pI4. Mask: %pI4. Target: %pI4.%s\n",
177 &arpinfo->smsk.s_addr,
178 &arpinfo->src.s_addr,
179 arpinfo->invflags & ARPT_INV_SRCIP ? " (INV)" : "");
180 dprintf("TGT: %pI4 Mask: %pI4 Target: %pI4.%s\n",
182 &arpinfo->tmsk.s_addr,
183 &arpinfo->tgt.s_addr,
184 arpinfo->invflags & ARPT_INV_TGTIP ? " (INV)" : "");
188 /* Look for ifname matches. */
189 ret = ifname_compare(indev, arpinfo->iniface, arpinfo->iniface_mask);
191 if (FWINV(ret != 0, ARPT_INV_VIA_IN)) {
192 dprintf("VIA in mismatch (%s vs %s).%s\n",
193 indev, arpinfo->iniface,
194 arpinfo->invflags&ARPT_INV_VIA_IN ?" (INV)":"");
198 ret = ifname_compare(outdev, arpinfo->outiface, arpinfo->outiface_mask);
200 if (FWINV(ret != 0, ARPT_INV_VIA_OUT)) {
201 dprintf("VIA out mismatch (%s vs %s).%s\n",
202 outdev, arpinfo->outiface,
203 arpinfo->invflags&ARPT_INV_VIA_OUT ?" (INV)":"");
211 static inline int arp_checkentry(const struct arpt_arp *arp)
213 if (arp->flags & ~ARPT_F_MASK) {
214 duprintf("Unknown flag bits set: %08X\n",
215 arp->flags & ~ARPT_F_MASK);
218 if (arp->invflags & ~ARPT_INV_MASK) {
219 duprintf("Unknown invflag bits set: %08X\n",
220 arp->invflags & ~ARPT_INV_MASK);
228 arpt_error(struct sk_buff *skb, const struct xt_target_param *par)
231 printk("arp_tables: error: '%s'\n",
232 (const char *)par->targinfo);
237 static inline struct arpt_entry *get_entry(void *base, unsigned int offset)
239 return (struct arpt_entry *)(base + offset);
242 unsigned int arpt_do_table(struct sk_buff *skb,
244 const struct net_device *in,
245 const struct net_device *out,
246 struct xt_table *table)
248 static const char nulldevname[IFNAMSIZ] __attribute__((aligned(sizeof(long))));
249 unsigned int verdict = NF_DROP;
250 const struct arphdr *arp;
251 bool hotdrop = false;
252 struct arpt_entry *e, *back;
253 const char *indev, *outdev;
255 const struct xt_table_info *private;
256 struct xt_target_param tgpar;
258 if (!pskb_may_pull(skb, arp_hdr_len(skb->dev)))
261 indev = in ? in->name : nulldevname;
262 outdev = out ? out->name : nulldevname;
265 private = rcu_dereference(table->private);
266 table_base = rcu_dereference(private->entries[smp_processor_id()]);
268 e = get_entry(table_base, private->hook_entry[hook]);
269 back = get_entry(table_base, private->underflow[hook]);
273 tgpar.hooknum = hook;
274 tgpar.family = NFPROTO_ARP;
278 if (arp_packet_match(arp, skb->dev, indev, outdev, &e->arp)) {
279 struct arpt_entry_target *t;
282 hdr_len = sizeof(*arp) + (2 * sizeof(struct in_addr)) +
283 (2 * skb->dev->addr_len);
284 ADD_COUNTER(e->counters, hdr_len, 1);
286 t = arpt_get_target(e);
288 /* Standard target? */
289 if (!t->u.kernel.target->target) {
292 v = ((struct arpt_standard_target *)t)->verdict;
294 /* Pop from stack? */
295 if (v != ARPT_RETURN) {
296 verdict = (unsigned)(-v) - 1;
300 back = get_entry(table_base,
305 != (void *)e + e->next_offset) {
306 /* Save old back ptr in next entry */
307 struct arpt_entry *next
308 = (void *)e + e->next_offset;
310 (void *)back - table_base;
312 /* set back pointer to next entry */
316 e = get_entry(table_base, v);
318 /* Targets which reenter must return
321 tgpar.target = t->u.kernel.target;
322 tgpar.targinfo = t->data;
323 verdict = t->u.kernel.target->target(skb,
326 /* Target might have changed stuff. */
329 if (verdict == ARPT_CONTINUE)
330 e = (void *)e + e->next_offset;
336 e = (void *)e + e->next_offset;
348 /* All zeroes == unconditional rule. */
349 static inline int unconditional(const struct arpt_arp *arp)
353 for (i = 0; i < sizeof(*arp)/sizeof(__u32); i++)
354 if (((__u32 *)arp)[i])
360 /* Figures out from what hook each rule can be called: returns 0 if
361 * there are loops. Puts hook bitmask in comefrom.
363 static int mark_source_chains(struct xt_table_info *newinfo,
364 unsigned int valid_hooks, void *entry0)
368 /* No recursion; use packet counter to save back ptrs (reset
369 * to 0 as we leave), and comefrom to save source hook bitmask.
371 for (hook = 0; hook < NF_ARP_NUMHOOKS; hook++) {
372 unsigned int pos = newinfo->hook_entry[hook];
374 = (struct arpt_entry *)(entry0 + pos);
376 if (!(valid_hooks & (1 << hook)))
379 /* Set initial back pointer. */
380 e->counters.pcnt = pos;
383 const struct arpt_standard_target *t
384 = (void *)arpt_get_target(e);
385 int visited = e->comefrom & (1 << hook);
387 if (e->comefrom & (1 << NF_ARP_NUMHOOKS)) {
388 printk("arptables: loop hook %u pos %u %08X.\n",
389 hook, pos, e->comefrom);
393 |= ((1 << hook) | (1 << NF_ARP_NUMHOOKS));
395 /* Unconditional return/END. */
396 if ((e->target_offset == sizeof(struct arpt_entry)
397 && (strcmp(t->target.u.user.name,
398 ARPT_STANDARD_TARGET) == 0)
400 && unconditional(&e->arp)) || visited) {
401 unsigned int oldpos, size;
403 if (t->verdict < -NF_MAX_VERDICT - 1) {
404 duprintf("mark_source_chains: bad "
405 "negative verdict (%i)\n",
410 /* Return: backtrack through the last
414 e->comefrom ^= (1<<NF_ARP_NUMHOOKS);
416 pos = e->counters.pcnt;
417 e->counters.pcnt = 0;
419 /* We're at the start. */
423 e = (struct arpt_entry *)
425 } while (oldpos == pos + e->next_offset);
428 size = e->next_offset;
429 e = (struct arpt_entry *)
430 (entry0 + pos + size);
431 e->counters.pcnt = pos;
434 int newpos = t->verdict;
436 if (strcmp(t->target.u.user.name,
437 ARPT_STANDARD_TARGET) == 0
439 if (newpos > newinfo->size -
440 sizeof(struct arpt_entry)) {
441 duprintf("mark_source_chains: "
442 "bad verdict (%i)\n",
447 /* This a jump; chase it. */
448 duprintf("Jump rule %u -> %u\n",
451 /* ... this is a fallthru */
452 newpos = pos + e->next_offset;
454 e = (struct arpt_entry *)
456 e->counters.pcnt = pos;
461 duprintf("Finished chain %u\n", hook);
466 static inline int check_entry(struct arpt_entry *e, const char *name)
468 const struct arpt_entry_target *t;
470 if (!arp_checkentry(&e->arp)) {
471 duprintf("arp_tables: arp check failed %p %s.\n", e, name);
475 if (e->target_offset + sizeof(struct arpt_entry_target) > e->next_offset)
478 t = arpt_get_target(e);
479 if (e->target_offset + t->u.target_size > e->next_offset)
485 static inline int check_target(struct arpt_entry *e, const char *name)
487 struct arpt_entry_target *t = arpt_get_target(e);
489 struct xt_tgchk_param par = {
492 .target = t->u.kernel.target,
494 .hook_mask = e->comefrom,
495 .family = NFPROTO_ARP,
498 ret = xt_check_target(&par, t->u.target_size - sizeof(*t), 0, false);
500 duprintf("arp_tables: check failed for `%s'.\n",
501 t->u.kernel.target->name);
508 find_check_entry(struct arpt_entry *e, const char *name, unsigned int size,
511 struct arpt_entry_target *t;
512 struct xt_target *target;
515 ret = check_entry(e, name);
519 t = arpt_get_target(e);
520 target = try_then_request_module(xt_find_target(NFPROTO_ARP,
523 "arpt_%s", t->u.user.name);
524 if (IS_ERR(target) || !target) {
525 duprintf("find_check_entry: `%s' not found\n", t->u.user.name);
526 ret = target ? PTR_ERR(target) : -ENOENT;
529 t->u.kernel.target = target;
531 ret = check_target(e, name);
538 module_put(t->u.kernel.target->me);
543 static inline int check_entry_size_and_hooks(struct arpt_entry *e,
544 struct xt_table_info *newinfo,
546 unsigned char *limit,
547 const unsigned int *hook_entries,
548 const unsigned int *underflows,
553 if ((unsigned long)e % __alignof__(struct arpt_entry) != 0
554 || (unsigned char *)e + sizeof(struct arpt_entry) >= limit) {
555 duprintf("Bad offset %p\n", e);
560 < sizeof(struct arpt_entry) + sizeof(struct arpt_entry_target)) {
561 duprintf("checking: element %p size %u\n",
566 /* Check hooks & underflows */
567 for (h = 0; h < NF_ARP_NUMHOOKS; h++) {
568 if ((unsigned char *)e - base == hook_entries[h])
569 newinfo->hook_entry[h] = hook_entries[h];
570 if ((unsigned char *)e - base == underflows[h])
571 newinfo->underflow[h] = underflows[h];
574 /* FIXME: underflows must be unconditional, standard verdicts
575 < 0 (not ARPT_RETURN). --RR */
577 /* Clear counters and comefrom */
578 e->counters = ((struct xt_counters) { 0, 0 });
585 static inline int cleanup_entry(struct arpt_entry *e, unsigned int *i)
587 struct xt_tgdtor_param par;
588 struct arpt_entry_target *t;
590 if (i && (*i)-- == 0)
593 t = arpt_get_target(e);
594 par.target = t->u.kernel.target;
595 par.targinfo = t->data;
596 par.family = NFPROTO_ARP;
597 if (par.target->destroy != NULL)
598 par.target->destroy(&par);
599 module_put(par.target->me);
603 /* Checks and translates the user-supplied table segment (held in
606 static int translate_table(const char *name,
607 unsigned int valid_hooks,
608 struct xt_table_info *newinfo,
612 const unsigned int *hook_entries,
613 const unsigned int *underflows)
618 newinfo->size = size;
619 newinfo->number = number;
621 /* Init all hooks to impossible value. */
622 for (i = 0; i < NF_ARP_NUMHOOKS; i++) {
623 newinfo->hook_entry[i] = 0xFFFFFFFF;
624 newinfo->underflow[i] = 0xFFFFFFFF;
627 duprintf("translate_table: size %u\n", newinfo->size);
630 /* Walk through entries, checking offsets. */
631 ret = ARPT_ENTRY_ITERATE(entry0, newinfo->size,
632 check_entry_size_and_hooks,
636 hook_entries, underflows, &i);
637 duprintf("translate_table: ARPT_ENTRY_ITERATE gives %d\n", ret);
642 duprintf("translate_table: %u not %u entries\n",
647 /* Check hooks all assigned */
648 for (i = 0; i < NF_ARP_NUMHOOKS; i++) {
649 /* Only hooks which are valid */
650 if (!(valid_hooks & (1 << i)))
652 if (newinfo->hook_entry[i] == 0xFFFFFFFF) {
653 duprintf("Invalid hook entry %u %u\n",
657 if (newinfo->underflow[i] == 0xFFFFFFFF) {
658 duprintf("Invalid underflow %u %u\n",
664 if (!mark_source_chains(newinfo, valid_hooks, entry0)) {
665 duprintf("Looping hook\n");
669 /* Finally, each sanity check must pass */
671 ret = ARPT_ENTRY_ITERATE(entry0, newinfo->size,
672 find_check_entry, name, size, &i);
675 ARPT_ENTRY_ITERATE(entry0, newinfo->size,
680 /* And one copy for every other CPU */
681 for_each_possible_cpu(i) {
682 if (newinfo->entries[i] && newinfo->entries[i] != entry0)
683 memcpy(newinfo->entries[i], entry0, newinfo->size);
690 static inline int add_entry_to_counter(const struct arpt_entry *e,
691 struct xt_counters total[],
694 ADD_COUNTER(total[*i], e->counters.bcnt, e->counters.pcnt);
700 static inline int set_entry_to_counter(const struct arpt_entry *e,
701 struct xt_counters total[],
704 SET_COUNTER(total[*i], e->counters.bcnt, e->counters.pcnt);
710 static void get_counters(const struct xt_table_info *t,
711 struct xt_counters counters[])
717 /* Instead of clearing (by a previous call to memset())
718 * the counters and using adds, we set the counters
719 * with data used by 'current' CPU
720 * We dont care about preemption here.
722 curcpu = raw_smp_processor_id();
725 ARPT_ENTRY_ITERATE(t->entries[curcpu],
727 set_entry_to_counter,
731 for_each_possible_cpu(cpu) {
735 ARPT_ENTRY_ITERATE(t->entries[cpu],
737 add_entry_to_counter,
744 /* We're lazy, and add to the first CPU; overflow works its fey magic
745 * and everything is OK. */
747 add_counter_to_entry(struct arpt_entry *e,
748 const struct xt_counters addme[],
751 ADD_COUNTER(e->counters, addme[*i].bcnt, addme[*i].pcnt);
757 /* Take values from counters and add them back onto the current cpu */
758 static void put_counters(struct xt_table_info *t,
759 const struct xt_counters counters[])
764 cpu = smp_processor_id();
766 ARPT_ENTRY_ITERATE(t->entries[cpu],
768 add_counter_to_entry,
775 zero_entry_counter(struct arpt_entry *e, void *arg)
777 e->counters.bcnt = 0;
778 e->counters.pcnt = 0;
783 clone_counters(struct xt_table_info *newinfo, const struct xt_table_info *info)
786 const void *loc_cpu_entry = info->entries[raw_smp_processor_id()];
788 memcpy(newinfo, info, offsetof(struct xt_table_info, entries));
789 for_each_possible_cpu(cpu) {
790 memcpy(newinfo->entries[cpu], loc_cpu_entry, info->size);
791 ARPT_ENTRY_ITERATE(newinfo->entries[cpu], newinfo->size,
792 zero_entry_counter, NULL);
796 static struct xt_counters *alloc_counters(struct xt_table *table)
798 unsigned int countersize;
799 struct xt_counters *counters;
800 struct xt_table_info *private = table->private;
801 struct xt_table_info *info;
803 /* We need atomic snapshot of counters: rest doesn't change
804 * (other than comefrom, which userspace doesn't care
807 countersize = sizeof(struct xt_counters) * private->number;
808 counters = vmalloc_node(countersize, numa_node_id());
810 if (counters == NULL)
813 info = xt_alloc_table_info(private->size);
817 clone_counters(info, private);
819 mutex_lock(&table->lock);
820 xt_table_entry_swap_rcu(private, info);
821 synchronize_net(); /* Wait until smoke has cleared */
823 get_counters(info, counters);
824 put_counters(private, counters);
825 mutex_unlock(&table->lock);
827 xt_free_table_info(info);
834 return ERR_PTR(-ENOMEM);
837 static int copy_entries_to_user(unsigned int total_size,
838 struct xt_table *table,
839 void __user *userptr)
841 unsigned int off, num;
842 struct arpt_entry *e;
843 struct xt_counters *counters;
844 struct xt_table_info *private = table->private;
848 counters = alloc_counters(table);
849 if (IS_ERR(counters))
850 return PTR_ERR(counters);
852 loc_cpu_entry = private->entries[raw_smp_processor_id()];
853 /* ... then copy entire thing ... */
854 if (copy_to_user(userptr, loc_cpu_entry, total_size) != 0) {
859 /* FIXME: use iterator macros --RR */
860 /* ... then go back and fix counters and names */
861 for (off = 0, num = 0; off < total_size; off += e->next_offset, num++){
862 struct arpt_entry_target *t;
864 e = (struct arpt_entry *)(loc_cpu_entry + off);
865 if (copy_to_user(userptr + off
866 + offsetof(struct arpt_entry, counters),
868 sizeof(counters[num])) != 0) {
873 t = arpt_get_target(e);
874 if (copy_to_user(userptr + off + e->target_offset
875 + offsetof(struct arpt_entry_target,
877 t->u.kernel.target->name,
878 strlen(t->u.kernel.target->name)+1) != 0) {
890 static void compat_standard_from_user(void *dst, void *src)
892 int v = *(compat_int_t *)src;
895 v += xt_compat_calc_jump(NFPROTO_ARP, v);
896 memcpy(dst, &v, sizeof(v));
899 static int compat_standard_to_user(void __user *dst, void *src)
901 compat_int_t cv = *(int *)src;
904 cv -= xt_compat_calc_jump(NFPROTO_ARP, cv);
905 return copy_to_user(dst, &cv, sizeof(cv)) ? -EFAULT : 0;
908 static int compat_calc_entry(struct arpt_entry *e,
909 const struct xt_table_info *info,
910 void *base, struct xt_table_info *newinfo)
912 struct arpt_entry_target *t;
913 unsigned int entry_offset;
916 off = sizeof(struct arpt_entry) - sizeof(struct compat_arpt_entry);
917 entry_offset = (void *)e - base;
919 t = arpt_get_target(e);
920 off += xt_compat_target_offset(t->u.kernel.target);
921 newinfo->size -= off;
922 ret = xt_compat_add_offset(NFPROTO_ARP, entry_offset, off);
926 for (i = 0; i < NF_ARP_NUMHOOKS; i++) {
927 if (info->hook_entry[i] &&
928 (e < (struct arpt_entry *)(base + info->hook_entry[i])))
929 newinfo->hook_entry[i] -= off;
930 if (info->underflow[i] &&
931 (e < (struct arpt_entry *)(base + info->underflow[i])))
932 newinfo->underflow[i] -= off;
937 static int compat_table_info(const struct xt_table_info *info,
938 struct xt_table_info *newinfo)
942 if (!newinfo || !info)
945 /* we dont care about newinfo->entries[] */
946 memcpy(newinfo, info, offsetof(struct xt_table_info, entries));
947 newinfo->initial_entries = 0;
948 loc_cpu_entry = info->entries[raw_smp_processor_id()];
949 return ARPT_ENTRY_ITERATE(loc_cpu_entry, info->size,
950 compat_calc_entry, info, loc_cpu_entry,
955 static int get_info(struct net *net, void __user *user, int *len, int compat)
957 char name[ARPT_TABLE_MAXNAMELEN];
961 if (*len != sizeof(struct arpt_getinfo)) {
962 duprintf("length %u != %Zu\n", *len,
963 sizeof(struct arpt_getinfo));
967 if (copy_from_user(name, user, sizeof(name)) != 0)
970 name[ARPT_TABLE_MAXNAMELEN-1] = '\0';
973 xt_compat_lock(NFPROTO_ARP);
975 t = try_then_request_module(xt_find_table_lock(net, NFPROTO_ARP, name),
976 "arptable_%s", name);
977 if (t && !IS_ERR(t)) {
978 struct arpt_getinfo info;
979 const struct xt_table_info *private = t->private;
983 struct xt_table_info tmp;
984 ret = compat_table_info(private, &tmp);
985 xt_compat_flush_offsets(NFPROTO_ARP);
989 info.valid_hooks = t->valid_hooks;
990 memcpy(info.hook_entry, private->hook_entry,
991 sizeof(info.hook_entry));
992 memcpy(info.underflow, private->underflow,
993 sizeof(info.underflow));
994 info.num_entries = private->number;
995 info.size = private->size;
996 strcpy(info.name, name);
998 if (copy_to_user(user, &info, *len) != 0)
1005 ret = t ? PTR_ERR(t) : -ENOENT;
1006 #ifdef CONFIG_COMPAT
1008 xt_compat_unlock(NFPROTO_ARP);
1013 static int get_entries(struct net *net, struct arpt_get_entries __user *uptr,
1017 struct arpt_get_entries get;
1020 if (*len < sizeof(get)) {
1021 duprintf("get_entries: %u < %Zu\n", *len, sizeof(get));
1024 if (copy_from_user(&get, uptr, sizeof(get)) != 0)
1026 if (*len != sizeof(struct arpt_get_entries) + get.size) {
1027 duprintf("get_entries: %u != %Zu\n", *len,
1028 sizeof(struct arpt_get_entries) + get.size);
1032 t = xt_find_table_lock(net, NFPROTO_ARP, get.name);
1033 if (t && !IS_ERR(t)) {
1034 const struct xt_table_info *private = t->private;
1036 duprintf("t->private->number = %u\n",
1038 if (get.size == private->size)
1039 ret = copy_entries_to_user(private->size,
1040 t, uptr->entrytable);
1042 duprintf("get_entries: I've got %u not %u!\n",
1043 private->size, get.size);
1049 ret = t ? PTR_ERR(t) : -ENOENT;
1054 static int __do_replace(struct net *net, const char *name,
1055 unsigned int valid_hooks,
1056 struct xt_table_info *newinfo,
1057 unsigned int num_counters,
1058 void __user *counters_ptr)
1062 struct xt_table_info *oldinfo;
1063 struct xt_counters *counters;
1064 void *loc_cpu_old_entry;
1067 counters = vmalloc_node(num_counters * sizeof(struct xt_counters),
1074 t = try_then_request_module(xt_find_table_lock(net, NFPROTO_ARP, name),
1075 "arptable_%s", name);
1076 if (!t || IS_ERR(t)) {
1077 ret = t ? PTR_ERR(t) : -ENOENT;
1078 goto free_newinfo_counters_untrans;
1082 if (valid_hooks != t->valid_hooks) {
1083 duprintf("Valid hook crap: %08X vs %08X\n",
1084 valid_hooks, t->valid_hooks);
1089 oldinfo = xt_replace_table(t, num_counters, newinfo, &ret);
1093 /* Update module usage count based on number of rules */
1094 duprintf("do_replace: oldnum=%u, initnum=%u, newnum=%u\n",
1095 oldinfo->number, oldinfo->initial_entries, newinfo->number);
1096 if ((oldinfo->number > oldinfo->initial_entries) ||
1097 (newinfo->number <= oldinfo->initial_entries))
1099 if ((oldinfo->number > oldinfo->initial_entries) &&
1100 (newinfo->number <= oldinfo->initial_entries))
1103 /* Get the old counters. */
1104 get_counters(oldinfo, counters);
1105 /* Decrease module usage counts and free resource */
1106 loc_cpu_old_entry = oldinfo->entries[raw_smp_processor_id()];
1107 ARPT_ENTRY_ITERATE(loc_cpu_old_entry, oldinfo->size, cleanup_entry,
1110 xt_free_table_info(oldinfo);
1111 if (copy_to_user(counters_ptr, counters,
1112 sizeof(struct xt_counters) * num_counters) != 0)
1121 free_newinfo_counters_untrans:
1127 static int do_replace(struct net *net, void __user *user, unsigned int len)
1130 struct arpt_replace tmp;
1131 struct xt_table_info *newinfo;
1132 void *loc_cpu_entry;
1134 if (copy_from_user(&tmp, user, sizeof(tmp)) != 0)
1137 /* overflow check */
1138 if (tmp.num_counters >= INT_MAX / sizeof(struct xt_counters))
1141 newinfo = xt_alloc_table_info(tmp.size);
1145 /* choose the copy that is on our node/cpu */
1146 loc_cpu_entry = newinfo->entries[raw_smp_processor_id()];
1147 if (copy_from_user(loc_cpu_entry, user + sizeof(tmp),
1153 ret = translate_table(tmp.name, tmp.valid_hooks,
1154 newinfo, loc_cpu_entry, tmp.size, tmp.num_entries,
1155 tmp.hook_entry, tmp.underflow);
1159 duprintf("arp_tables: Translated table\n");
1161 ret = __do_replace(net, tmp.name, tmp.valid_hooks, newinfo,
1162 tmp.num_counters, tmp.counters);
1164 goto free_newinfo_untrans;
1167 free_newinfo_untrans:
1168 ARPT_ENTRY_ITERATE(loc_cpu_entry, newinfo->size, cleanup_entry, NULL);
1170 xt_free_table_info(newinfo);
1174 static int do_add_counters(struct net *net, void __user *user, unsigned int len,
1178 struct xt_counters_info tmp;
1179 struct xt_counters *paddc;
1180 unsigned int num_counters;
1185 const struct xt_table_info *private;
1187 void *loc_cpu_entry;
1188 #ifdef CONFIG_COMPAT
1189 struct compat_xt_counters_info compat_tmp;
1193 size = sizeof(struct compat_xt_counters_info);
1198 size = sizeof(struct xt_counters_info);
1201 if (copy_from_user(ptmp, user, size) != 0)
1204 #ifdef CONFIG_COMPAT
1206 num_counters = compat_tmp.num_counters;
1207 name = compat_tmp.name;
1211 num_counters = tmp.num_counters;
1215 if (len != size + num_counters * sizeof(struct xt_counters))
1218 paddc = vmalloc_node(len - size, numa_node_id());
1222 if (copy_from_user(paddc, user + size, len - size) != 0) {
1227 t = xt_find_table_lock(net, NFPROTO_ARP, name);
1228 if (!t || IS_ERR(t)) {
1229 ret = t ? PTR_ERR(t) : -ENOENT;
1233 mutex_lock(&t->lock);
1234 private = t->private;
1235 if (private->number != num_counters) {
1237 goto unlock_up_free;
1242 /* Choose the copy that is on our node */
1243 loc_cpu_entry = private->entries[smp_processor_id()];
1244 ARPT_ENTRY_ITERATE(loc_cpu_entry,
1246 add_counter_to_entry,
1251 mutex_unlock(&t->lock);
1261 #ifdef CONFIG_COMPAT
1263 compat_release_entry(struct compat_arpt_entry *e, unsigned int *i)
1265 struct arpt_entry_target *t;
1267 if (i && (*i)-- == 0)
1270 t = compat_arpt_get_target(e);
1271 module_put(t->u.kernel.target->me);
1276 check_compat_entry_size_and_hooks(struct compat_arpt_entry *e,
1277 struct xt_table_info *newinfo,
1279 unsigned char *base,
1280 unsigned char *limit,
1281 unsigned int *hook_entries,
1282 unsigned int *underflows,
1286 struct arpt_entry_target *t;
1287 struct xt_target *target;
1288 unsigned int entry_offset;
1291 duprintf("check_compat_entry_size_and_hooks %p\n", e);
1292 if ((unsigned long)e % __alignof__(struct compat_arpt_entry) != 0
1293 || (unsigned char *)e + sizeof(struct compat_arpt_entry) >= limit) {
1294 duprintf("Bad offset %p, limit = %p\n", e, limit);
1298 if (e->next_offset < sizeof(struct compat_arpt_entry) +
1299 sizeof(struct compat_xt_entry_target)) {
1300 duprintf("checking: element %p size %u\n",
1305 /* For purposes of check_entry casting the compat entry is fine */
1306 ret = check_entry((struct arpt_entry *)e, name);
1310 off = sizeof(struct arpt_entry) - sizeof(struct compat_arpt_entry);
1311 entry_offset = (void *)e - (void *)base;
1313 t = compat_arpt_get_target(e);
1314 target = try_then_request_module(xt_find_target(NFPROTO_ARP,
1316 t->u.user.revision),
1317 "arpt_%s", t->u.user.name);
1318 if (IS_ERR(target) || !target) {
1319 duprintf("check_compat_entry_size_and_hooks: `%s' not found\n",
1321 ret = target ? PTR_ERR(target) : -ENOENT;
1324 t->u.kernel.target = target;
1326 off += xt_compat_target_offset(target);
1328 ret = xt_compat_add_offset(NFPROTO_ARP, entry_offset, off);
1330 goto release_target;
1332 /* Check hooks & underflows */
1333 for (h = 0; h < NF_ARP_NUMHOOKS; h++) {
1334 if ((unsigned char *)e - base == hook_entries[h])
1335 newinfo->hook_entry[h] = hook_entries[h];
1336 if ((unsigned char *)e - base == underflows[h])
1337 newinfo->underflow[h] = underflows[h];
1340 /* Clear counters and comefrom */
1341 memset(&e->counters, 0, sizeof(e->counters));
1348 module_put(t->u.kernel.target->me);
1354 compat_copy_entry_from_user(struct compat_arpt_entry *e, void **dstptr,
1355 unsigned int *size, const char *name,
1356 struct xt_table_info *newinfo, unsigned char *base)
1358 struct arpt_entry_target *t;
1359 struct xt_target *target;
1360 struct arpt_entry *de;
1361 unsigned int origsize;
1366 de = (struct arpt_entry *)*dstptr;
1367 memcpy(de, e, sizeof(struct arpt_entry));
1368 memcpy(&de->counters, &e->counters, sizeof(e->counters));
1370 *dstptr += sizeof(struct arpt_entry);
1371 *size += sizeof(struct arpt_entry) - sizeof(struct compat_arpt_entry);
1373 de->target_offset = e->target_offset - (origsize - *size);
1374 t = compat_arpt_get_target(e);
1375 target = t->u.kernel.target;
1376 xt_compat_target_from_user(t, dstptr, size);
1378 de->next_offset = e->next_offset - (origsize - *size);
1379 for (h = 0; h < NF_ARP_NUMHOOKS; h++) {
1380 if ((unsigned char *)de - base < newinfo->hook_entry[h])
1381 newinfo->hook_entry[h] -= origsize - *size;
1382 if ((unsigned char *)de - base < newinfo->underflow[h])
1383 newinfo->underflow[h] -= origsize - *size;
1388 static inline int compat_check_entry(struct arpt_entry *e, const char *name,
1393 ret = check_target(e, name);
1401 static int translate_compat_table(const char *name,
1402 unsigned int valid_hooks,
1403 struct xt_table_info **pinfo,
1405 unsigned int total_size,
1406 unsigned int number,
1407 unsigned int *hook_entries,
1408 unsigned int *underflows)
1411 struct xt_table_info *newinfo, *info;
1412 void *pos, *entry0, *entry1;
1419 info->number = number;
1421 /* Init all hooks to impossible value. */
1422 for (i = 0; i < NF_ARP_NUMHOOKS; i++) {
1423 info->hook_entry[i] = 0xFFFFFFFF;
1424 info->underflow[i] = 0xFFFFFFFF;
1427 duprintf("translate_compat_table: size %u\n", info->size);
1429 xt_compat_lock(NFPROTO_ARP);
1430 /* Walk through entries, checking offsets. */
1431 ret = COMPAT_ARPT_ENTRY_ITERATE(entry0, total_size,
1432 check_compat_entry_size_and_hooks,
1433 info, &size, entry0,
1434 entry0 + total_size,
1435 hook_entries, underflows, &j, name);
1441 duprintf("translate_compat_table: %u not %u entries\n",
1446 /* Check hooks all assigned */
1447 for (i = 0; i < NF_ARP_NUMHOOKS; i++) {
1448 /* Only hooks which are valid */
1449 if (!(valid_hooks & (1 << i)))
1451 if (info->hook_entry[i] == 0xFFFFFFFF) {
1452 duprintf("Invalid hook entry %u %u\n",
1453 i, hook_entries[i]);
1456 if (info->underflow[i] == 0xFFFFFFFF) {
1457 duprintf("Invalid underflow %u %u\n",
1464 newinfo = xt_alloc_table_info(size);
1468 newinfo->number = number;
1469 for (i = 0; i < NF_ARP_NUMHOOKS; i++) {
1470 newinfo->hook_entry[i] = info->hook_entry[i];
1471 newinfo->underflow[i] = info->underflow[i];
1473 entry1 = newinfo->entries[raw_smp_processor_id()];
1476 ret = COMPAT_ARPT_ENTRY_ITERATE(entry0, total_size,
1477 compat_copy_entry_from_user,
1478 &pos, &size, name, newinfo, entry1);
1479 xt_compat_flush_offsets(NFPROTO_ARP);
1480 xt_compat_unlock(NFPROTO_ARP);
1485 if (!mark_source_chains(newinfo, valid_hooks, entry1))
1489 ret = ARPT_ENTRY_ITERATE(entry1, newinfo->size, compat_check_entry,
1493 COMPAT_ARPT_ENTRY_ITERATE_CONTINUE(entry0, newinfo->size, i,
1494 compat_release_entry, &j);
1495 ARPT_ENTRY_ITERATE(entry1, newinfo->size, cleanup_entry, &i);
1496 xt_free_table_info(newinfo);
1500 /* And one copy for every other CPU */
1501 for_each_possible_cpu(i)
1502 if (newinfo->entries[i] && newinfo->entries[i] != entry1)
1503 memcpy(newinfo->entries[i], entry1, newinfo->size);
1507 xt_free_table_info(info);
1511 xt_free_table_info(newinfo);
1513 COMPAT_ARPT_ENTRY_ITERATE(entry0, total_size, compat_release_entry, &j);
1516 xt_compat_flush_offsets(NFPROTO_ARP);
1517 xt_compat_unlock(NFPROTO_ARP);
1521 struct compat_arpt_replace {
1522 char name[ARPT_TABLE_MAXNAMELEN];
1526 u32 hook_entry[NF_ARP_NUMHOOKS];
1527 u32 underflow[NF_ARP_NUMHOOKS];
1529 compat_uptr_t counters;
1530 struct compat_arpt_entry entries[0];
1533 static int compat_do_replace(struct net *net, void __user *user,
1537 struct compat_arpt_replace tmp;
1538 struct xt_table_info *newinfo;
1539 void *loc_cpu_entry;
1541 if (copy_from_user(&tmp, user, sizeof(tmp)) != 0)
1544 /* overflow check */
1545 if (tmp.size >= INT_MAX / num_possible_cpus())
1547 if (tmp.num_counters >= INT_MAX / sizeof(struct xt_counters))
1550 newinfo = xt_alloc_table_info(tmp.size);
1554 /* choose the copy that is on our node/cpu */
1555 loc_cpu_entry = newinfo->entries[raw_smp_processor_id()];
1556 if (copy_from_user(loc_cpu_entry, user + sizeof(tmp), tmp.size) != 0) {
1561 ret = translate_compat_table(tmp.name, tmp.valid_hooks,
1562 &newinfo, &loc_cpu_entry, tmp.size,
1563 tmp.num_entries, tmp.hook_entry,
1568 duprintf("compat_do_replace: Translated table\n");
1570 ret = __do_replace(net, tmp.name, tmp.valid_hooks, newinfo,
1571 tmp.num_counters, compat_ptr(tmp.counters));
1573 goto free_newinfo_untrans;
1576 free_newinfo_untrans:
1577 ARPT_ENTRY_ITERATE(loc_cpu_entry, newinfo->size, cleanup_entry, NULL);
1579 xt_free_table_info(newinfo);
1583 static int compat_do_arpt_set_ctl(struct sock *sk, int cmd, void __user *user,
1588 if (!capable(CAP_NET_ADMIN))
1592 case ARPT_SO_SET_REPLACE:
1593 ret = compat_do_replace(sock_net(sk), user, len);
1596 case ARPT_SO_SET_ADD_COUNTERS:
1597 ret = do_add_counters(sock_net(sk), user, len, 1);
1601 duprintf("do_arpt_set_ctl: unknown request %i\n", cmd);
1608 static int compat_copy_entry_to_user(struct arpt_entry *e, void __user **dstptr,
1609 compat_uint_t *size,
1610 struct xt_counters *counters,
1613 struct arpt_entry_target *t;
1614 struct compat_arpt_entry __user *ce;
1615 u_int16_t target_offset, next_offset;
1616 compat_uint_t origsize;
1621 ce = (struct compat_arpt_entry __user *)*dstptr;
1622 if (copy_to_user(ce, e, sizeof(struct arpt_entry)))
1625 if (copy_to_user(&ce->counters, &counters[*i], sizeof(counters[*i])))
1628 *dstptr += sizeof(struct compat_arpt_entry);
1629 *size -= sizeof(struct arpt_entry) - sizeof(struct compat_arpt_entry);
1631 target_offset = e->target_offset - (origsize - *size);
1633 t = arpt_get_target(e);
1634 ret = xt_compat_target_to_user(t, dstptr, size);
1638 next_offset = e->next_offset - (origsize - *size);
1639 if (put_user(target_offset, &ce->target_offset))
1641 if (put_user(next_offset, &ce->next_offset))
1650 static int compat_copy_entries_to_user(unsigned int total_size,
1651 struct xt_table *table,
1652 void __user *userptr)
1654 struct xt_counters *counters;
1655 const struct xt_table_info *private = table->private;
1659 void *loc_cpu_entry;
1662 counters = alloc_counters(table);
1663 if (IS_ERR(counters))
1664 return PTR_ERR(counters);
1666 /* choose the copy on our node/cpu */
1667 loc_cpu_entry = private->entries[raw_smp_processor_id()];
1670 ret = ARPT_ENTRY_ITERATE(loc_cpu_entry, total_size,
1671 compat_copy_entry_to_user,
1672 &pos, &size, counters, &i);
1677 struct compat_arpt_get_entries {
1678 char name[ARPT_TABLE_MAXNAMELEN];
1680 struct compat_arpt_entry entrytable[0];
1683 static int compat_get_entries(struct net *net,
1684 struct compat_arpt_get_entries __user *uptr,
1688 struct compat_arpt_get_entries get;
1691 if (*len < sizeof(get)) {
1692 duprintf("compat_get_entries: %u < %zu\n", *len, sizeof(get));
1695 if (copy_from_user(&get, uptr, sizeof(get)) != 0)
1697 if (*len != sizeof(struct compat_arpt_get_entries) + get.size) {
1698 duprintf("compat_get_entries: %u != %zu\n",
1699 *len, sizeof(get) + get.size);
1703 xt_compat_lock(NFPROTO_ARP);
1704 t = xt_find_table_lock(net, NFPROTO_ARP, get.name);
1705 if (t && !IS_ERR(t)) {
1706 const struct xt_table_info *private = t->private;
1707 struct xt_table_info info;
1709 duprintf("t->private->number = %u\n", private->number);
1710 ret = compat_table_info(private, &info);
1711 if (!ret && get.size == info.size) {
1712 ret = compat_copy_entries_to_user(private->size,
1713 t, uptr->entrytable);
1715 duprintf("compat_get_entries: I've got %u not %u!\n",
1716 private->size, get.size);
1719 xt_compat_flush_offsets(NFPROTO_ARP);
1723 ret = t ? PTR_ERR(t) : -ENOENT;
1725 xt_compat_unlock(NFPROTO_ARP);
1729 static int do_arpt_get_ctl(struct sock *, int, void __user *, int *);
1731 static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
1736 if (!capable(CAP_NET_ADMIN))
1740 case ARPT_SO_GET_INFO:
1741 ret = get_info(sock_net(sk), user, len, 1);
1743 case ARPT_SO_GET_ENTRIES:
1744 ret = compat_get_entries(sock_net(sk), user, len);
1747 ret = do_arpt_get_ctl(sk, cmd, user, len);
1753 static int do_arpt_set_ctl(struct sock *sk, int cmd, void __user *user, unsigned int len)
1757 if (!capable(CAP_NET_ADMIN))
1761 case ARPT_SO_SET_REPLACE:
1762 ret = do_replace(sock_net(sk), user, len);
1765 case ARPT_SO_SET_ADD_COUNTERS:
1766 ret = do_add_counters(sock_net(sk), user, len, 0);
1770 duprintf("do_arpt_set_ctl: unknown request %i\n", cmd);
1777 static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
1781 if (!capable(CAP_NET_ADMIN))
1785 case ARPT_SO_GET_INFO:
1786 ret = get_info(sock_net(sk), user, len, 0);
1789 case ARPT_SO_GET_ENTRIES:
1790 ret = get_entries(sock_net(sk), user, len);
1793 case ARPT_SO_GET_REVISION_TARGET: {
1794 struct xt_get_revision rev;
1796 if (*len != sizeof(rev)) {
1800 if (copy_from_user(&rev, user, sizeof(rev)) != 0) {
1805 try_then_request_module(xt_find_revision(NFPROTO_ARP, rev.name,
1806 rev.revision, 1, &ret),
1807 "arpt_%s", rev.name);
1812 duprintf("do_arpt_get_ctl: unknown request %i\n", cmd);
1819 struct xt_table *arpt_register_table(struct net *net, struct xt_table *table,
1820 const struct arpt_replace *repl)
1823 struct xt_table_info *newinfo;
1824 struct xt_table_info bootstrap
1825 = { 0, 0, 0, { 0 }, { 0 }, { } };
1826 void *loc_cpu_entry;
1827 struct xt_table *new_table;
1829 newinfo = xt_alloc_table_info(repl->size);
1835 /* choose the copy on our node/cpu */
1836 loc_cpu_entry = newinfo->entries[raw_smp_processor_id()];
1837 memcpy(loc_cpu_entry, repl->entries, repl->size);
1839 ret = translate_table(table->name, table->valid_hooks,
1840 newinfo, loc_cpu_entry, repl->size,
1845 duprintf("arpt_register_table: translate table gives %d\n", ret);
1849 new_table = xt_register_table(net, table, &bootstrap, newinfo);
1850 if (IS_ERR(new_table)) {
1851 ret = PTR_ERR(new_table);
1857 xt_free_table_info(newinfo);
1859 return ERR_PTR(ret);
1862 void arpt_unregister_table(struct xt_table *table)
1864 struct xt_table_info *private;
1865 void *loc_cpu_entry;
1866 struct module *table_owner = table->me;
1868 private = xt_unregister_table(table);
1870 /* Decrease module usage counts and free resources */
1871 loc_cpu_entry = private->entries[raw_smp_processor_id()];
1872 ARPT_ENTRY_ITERATE(loc_cpu_entry, private->size,
1873 cleanup_entry, NULL);
1874 if (private->number > private->initial_entries)
1875 module_put(table_owner);
1876 xt_free_table_info(private);
1879 /* The built-in targets: standard (NULL) and error. */
1880 static struct xt_target arpt_standard_target __read_mostly = {
1881 .name = ARPT_STANDARD_TARGET,
1882 .targetsize = sizeof(int),
1883 .family = NFPROTO_ARP,
1884 #ifdef CONFIG_COMPAT
1885 .compatsize = sizeof(compat_int_t),
1886 .compat_from_user = compat_standard_from_user,
1887 .compat_to_user = compat_standard_to_user,
1891 static struct xt_target arpt_error_target __read_mostly = {
1892 .name = ARPT_ERROR_TARGET,
1893 .target = arpt_error,
1894 .targetsize = ARPT_FUNCTION_MAXNAMELEN,
1895 .family = NFPROTO_ARP,
1898 static struct nf_sockopt_ops arpt_sockopts = {
1900 .set_optmin = ARPT_BASE_CTL,
1901 .set_optmax = ARPT_SO_SET_MAX+1,
1902 .set = do_arpt_set_ctl,
1903 #ifdef CONFIG_COMPAT
1904 .compat_set = compat_do_arpt_set_ctl,
1906 .get_optmin = ARPT_BASE_CTL,
1907 .get_optmax = ARPT_SO_GET_MAX+1,
1908 .get = do_arpt_get_ctl,
1909 #ifdef CONFIG_COMPAT
1910 .compat_get = compat_do_arpt_get_ctl,
1912 .owner = THIS_MODULE,
1915 static int __net_init arp_tables_net_init(struct net *net)
1917 return xt_proto_init(net, NFPROTO_ARP);
1920 static void __net_exit arp_tables_net_exit(struct net *net)
1922 xt_proto_fini(net, NFPROTO_ARP);
1925 static struct pernet_operations arp_tables_net_ops = {
1926 .init = arp_tables_net_init,
1927 .exit = arp_tables_net_exit,
1930 static int __init arp_tables_init(void)
1934 ret = register_pernet_subsys(&arp_tables_net_ops);
1938 /* Noone else will be downing sem now, so we won't sleep */
1939 ret = xt_register_target(&arpt_standard_target);
1942 ret = xt_register_target(&arpt_error_target);
1946 /* Register setsockopt */
1947 ret = nf_register_sockopt(&arpt_sockopts);
1951 printk(KERN_INFO "arp_tables: (C) 2002 David S. Miller\n");
1955 xt_unregister_target(&arpt_error_target);
1957 xt_unregister_target(&arpt_standard_target);
1959 unregister_pernet_subsys(&arp_tables_net_ops);
1964 static void __exit arp_tables_fini(void)
1966 nf_unregister_sockopt(&arpt_sockopts);
1967 xt_unregister_target(&arpt_error_target);
1968 xt_unregister_target(&arpt_standard_target);
1969 unregister_pernet_subsys(&arp_tables_net_ops);
1972 EXPORT_SYMBOL(arpt_register_table);
1973 EXPORT_SYMBOL(arpt_unregister_table);
1974 EXPORT_SYMBOL(arpt_do_table);
1976 module_init(arp_tables_init);
1977 module_exit(arp_tables_fini);