Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * Packet matching code for ARP packets. | |
3 | * | |
4 | * Based heavily, if not almost entirely, upon ip_tables.c framework. | |
5 | * | |
6 | * Some ARP specific bits are: | |
7 | * | |
8 | * Copyright (C) 2002 David S. Miller (davem@redhat.com) | |
f229f6ce | 9 | * Copyright (C) 2006-2009 Patrick McHardy <kaber@trash.net> |
1da177e4 LT |
10 | * |
11 | */ | |
90e7d4ab | 12 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
1da177e4 LT |
13 | #include <linux/kernel.h> |
14 | #include <linux/skbuff.h> | |
15 | #include <linux/netdevice.h> | |
4fc268d2 | 16 | #include <linux/capability.h> |
1da177e4 LT |
17 | #include <linux/if_arp.h> |
18 | #include <linux/kmod.h> | |
19 | #include <linux/vmalloc.h> | |
20 | #include <linux/proc_fs.h> | |
21 | #include <linux/module.h> | |
22 | #include <linux/init.h> | |
57b47a53 | 23 | #include <linux/mutex.h> |
d6a2ba07 PM |
24 | #include <linux/err.h> |
25 | #include <net/compat.h> | |
79df341a | 26 | #include <net/sock.h> |
d6a2ba07 | 27 | #include <asm/uaccess.h> |
1da177e4 | 28 | |
2e4e6a17 | 29 | #include <linux/netfilter/x_tables.h> |
1da177e4 | 30 | #include <linux/netfilter_arp/arp_tables.h> |
e3eaa991 | 31 | #include "../../netfilter/xt_repldata.h" |
1da177e4 LT |
32 | |
33 | MODULE_LICENSE("GPL"); | |
34 | MODULE_AUTHOR("David S. Miller <davem@redhat.com>"); | |
35 | MODULE_DESCRIPTION("arptables core"); | |
36 | ||
37 | /*#define DEBUG_ARP_TABLES*/ | |
38 | /*#define DEBUG_ARP_TABLES_USER*/ | |
39 | ||
40 | #ifdef DEBUG_ARP_TABLES | |
09605cc1 | 41 | #define dprintf(format, args...) pr_debug(format, ## args) |
1da177e4 LT |
42 | #else |
43 | #define dprintf(format, args...) | |
44 | #endif | |
45 | ||
46 | #ifdef DEBUG_ARP_TABLES_USER | |
09605cc1 | 47 | #define duprintf(format, args...) pr_debug(format, ## args) |
1da177e4 LT |
48 | #else |
49 | #define duprintf(format, args...) | |
50 | #endif | |
51 | ||
52 | #ifdef CONFIG_NETFILTER_DEBUG | |
af567603 | 53 | #define ARP_NF_ASSERT(x) WARN_ON(!(x)) |
1da177e4 LT |
54 | #else |
55 | #define ARP_NF_ASSERT(x) | |
56 | #endif | |
1da177e4 | 57 | |
e3eaa991 JE |
58 | void *arpt_alloc_initial_table(const struct xt_table *info) |
59 | { | |
60 | return xt_alloc_initial_table(arpt, ARPT); | |
61 | } | |
62 | EXPORT_SYMBOL_GPL(arpt_alloc_initial_table); | |
63 | ||
1da177e4 | 64 | static inline int arp_devaddr_compare(const struct arpt_devaddr_info *ap, |
5452e425 | 65 | const char *hdr_addr, int len) |
1da177e4 LT |
66 | { |
67 | int i, ret; | |
68 | ||
69 | if (len > ARPT_DEV_ADDR_LEN_MAX) | |
70 | len = ARPT_DEV_ADDR_LEN_MAX; | |
71 | ||
72 | ret = 0; | |
73 | for (i = 0; i < len; i++) | |
74 | ret |= (hdr_addr[i] ^ ap->addr[i]) & ap->mask[i]; | |
75 | ||
a02cec21 | 76 | return ret != 0; |
1da177e4 LT |
77 | } |
78 | ||
ddc214c4 | 79 | /* |
25985edc | 80 | * Unfortunately, _b and _mask are not aligned to an int (or long int) |
ddc214c4 | 81 | * Some arches dont care, unrolling the loop is a win on them. |
35c7f6de | 82 | * For other arches, we only have a 16bit alignement. |
ddc214c4 ED |
83 | */ |
84 | static unsigned long ifname_compare(const char *_a, const char *_b, const char *_mask) | |
85 | { | |
86 | #ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS | |
b8dfe498 | 87 | unsigned long ret = ifname_compare_aligned(_a, _b, _mask); |
ddc214c4 ED |
88 | #else |
89 | unsigned long ret = 0; | |
35c7f6de ED |
90 | const u16 *a = (const u16 *)_a; |
91 | const u16 *b = (const u16 *)_b; | |
92 | const u16 *mask = (const u16 *)_mask; | |
ddc214c4 ED |
93 | int i; |
94 | ||
35c7f6de ED |
95 | for (i = 0; i < IFNAMSIZ/sizeof(u16); i++) |
96 | ret |= (a[i] ^ b[i]) & mask[i]; | |
ddc214c4 ED |
97 | #endif |
98 | return ret; | |
99 | } | |
100 | ||
1da177e4 LT |
101 | /* Returns whether packet matches rule or not. */ |
102 | static inline int arp_packet_match(const struct arphdr *arphdr, | |
103 | struct net_device *dev, | |
104 | const char *indev, | |
105 | const char *outdev, | |
106 | const struct arpt_arp *arpinfo) | |
107 | { | |
5452e425 JE |
108 | const char *arpptr = (char *)(arphdr + 1); |
109 | const char *src_devaddr, *tgt_devaddr; | |
59b8bfd8 | 110 | __be32 src_ipaddr, tgt_ipaddr; |
ddc214c4 | 111 | long ret; |
1da177e4 | 112 | |
e79ec50b | 113 | #define FWINV(bool, invflg) ((bool) ^ !!(arpinfo->invflags & (invflg))) |
1da177e4 LT |
114 | |
115 | if (FWINV((arphdr->ar_op & arpinfo->arpop_mask) != arpinfo->arpop, | |
116 | ARPT_INV_ARPOP)) { | |
117 | dprintf("ARP operation field mismatch.\n"); | |
118 | dprintf("ar_op: %04x info->arpop: %04x info->arpop_mask: %04x\n", | |
119 | arphdr->ar_op, arpinfo->arpop, arpinfo->arpop_mask); | |
120 | return 0; | |
121 | } | |
122 | ||
123 | if (FWINV((arphdr->ar_hrd & arpinfo->arhrd_mask) != arpinfo->arhrd, | |
124 | ARPT_INV_ARPHRD)) { | |
125 | dprintf("ARP hardware address format mismatch.\n"); | |
126 | dprintf("ar_hrd: %04x info->arhrd: %04x info->arhrd_mask: %04x\n", | |
127 | arphdr->ar_hrd, arpinfo->arhrd, arpinfo->arhrd_mask); | |
128 | return 0; | |
129 | } | |
130 | ||
131 | if (FWINV((arphdr->ar_pro & arpinfo->arpro_mask) != arpinfo->arpro, | |
132 | ARPT_INV_ARPPRO)) { | |
133 | dprintf("ARP protocol address format mismatch.\n"); | |
134 | dprintf("ar_pro: %04x info->arpro: %04x info->arpro_mask: %04x\n", | |
135 | arphdr->ar_pro, arpinfo->arpro, arpinfo->arpro_mask); | |
136 | return 0; | |
137 | } | |
138 | ||
139 | if (FWINV((arphdr->ar_hln & arpinfo->arhln_mask) != arpinfo->arhln, | |
140 | ARPT_INV_ARPHLN)) { | |
141 | dprintf("ARP hardware address length mismatch.\n"); | |
142 | dprintf("ar_hln: %02x info->arhln: %02x info->arhln_mask: %02x\n", | |
143 | arphdr->ar_hln, arpinfo->arhln, arpinfo->arhln_mask); | |
144 | return 0; | |
145 | } | |
146 | ||
147 | src_devaddr = arpptr; | |
148 | arpptr += dev->addr_len; | |
149 | memcpy(&src_ipaddr, arpptr, sizeof(u32)); | |
150 | arpptr += sizeof(u32); | |
151 | tgt_devaddr = arpptr; | |
152 | arpptr += dev->addr_len; | |
153 | memcpy(&tgt_ipaddr, arpptr, sizeof(u32)); | |
154 | ||
155 | if (FWINV(arp_devaddr_compare(&arpinfo->src_devaddr, src_devaddr, dev->addr_len), | |
156 | ARPT_INV_SRCDEVADDR) || | |
157 | FWINV(arp_devaddr_compare(&arpinfo->tgt_devaddr, tgt_devaddr, dev->addr_len), | |
158 | ARPT_INV_TGTDEVADDR)) { | |
159 | dprintf("Source or target device address mismatch.\n"); | |
160 | ||
161 | return 0; | |
162 | } | |
163 | ||
164 | if (FWINV((src_ipaddr & arpinfo->smsk.s_addr) != arpinfo->src.s_addr, | |
165 | ARPT_INV_SRCIP) || | |
166 | FWINV(((tgt_ipaddr & arpinfo->tmsk.s_addr) != arpinfo->tgt.s_addr), | |
167 | ARPT_INV_TGTIP)) { | |
168 | dprintf("Source or target IP address mismatch.\n"); | |
169 | ||
cffee385 HH |
170 | dprintf("SRC: %pI4. Mask: %pI4. Target: %pI4.%s\n", |
171 | &src_ipaddr, | |
172 | &arpinfo->smsk.s_addr, | |
173 | &arpinfo->src.s_addr, | |
1da177e4 | 174 | arpinfo->invflags & ARPT_INV_SRCIP ? " (INV)" : ""); |
cffee385 HH |
175 | dprintf("TGT: %pI4 Mask: %pI4 Target: %pI4.%s\n", |
176 | &tgt_ipaddr, | |
177 | &arpinfo->tmsk.s_addr, | |
178 | &arpinfo->tgt.s_addr, | |
1da177e4 LT |
179 | arpinfo->invflags & ARPT_INV_TGTIP ? " (INV)" : ""); |
180 | return 0; | |
181 | } | |
182 | ||
183 | /* Look for ifname matches. */ | |
ddc214c4 | 184 | ret = ifname_compare(indev, arpinfo->iniface, arpinfo->iniface_mask); |
1da177e4 LT |
185 | |
186 | if (FWINV(ret != 0, ARPT_INV_VIA_IN)) { | |
187 | dprintf("VIA in mismatch (%s vs %s).%s\n", | |
188 | indev, arpinfo->iniface, | |
27951a01 | 189 | arpinfo->invflags & ARPT_INV_VIA_IN ? " (INV)" : ""); |
1da177e4 LT |
190 | return 0; |
191 | } | |
192 | ||
ddc214c4 | 193 | ret = ifname_compare(outdev, arpinfo->outiface, arpinfo->outiface_mask); |
1da177e4 LT |
194 | |
195 | if (FWINV(ret != 0, ARPT_INV_VIA_OUT)) { | |
196 | dprintf("VIA out mismatch (%s vs %s).%s\n", | |
197 | outdev, arpinfo->outiface, | |
27951a01 | 198 | arpinfo->invflags & ARPT_INV_VIA_OUT ? " (INV)" : ""); |
1da177e4 LT |
199 | return 0; |
200 | } | |
201 | ||
202 | return 1; | |
e79ec50b | 203 | #undef FWINV |
1da177e4 LT |
204 | } |
205 | ||
206 | static inline int arp_checkentry(const struct arpt_arp *arp) | |
207 | { | |
208 | if (arp->flags & ~ARPT_F_MASK) { | |
209 | duprintf("Unknown flag bits set: %08X\n", | |
210 | arp->flags & ~ARPT_F_MASK); | |
211 | return 0; | |
212 | } | |
213 | if (arp->invflags & ~ARPT_INV_MASK) { | |
214 | duprintf("Unknown invflag bits set: %08X\n", | |
215 | arp->invflags & ~ARPT_INV_MASK); | |
216 | return 0; | |
217 | } | |
218 | ||
219 | return 1; | |
220 | } | |
221 | ||
7eb35586 | 222 | static unsigned int |
4b560b44 | 223 | arpt_error(struct sk_buff *skb, const struct xt_action_param *par) |
1da177e4 | 224 | { |
e87cc472 JP |
225 | net_err_ratelimited("arp_tables: error: '%s'\n", |
226 | (const char *)par->targinfo); | |
1da177e4 LT |
227 | |
228 | return NF_DROP; | |
229 | } | |
230 | ||
87a2e70d | 231 | static inline const struct xt_entry_target * |
d5d1baa1 JE |
232 | arpt_get_target_c(const struct arpt_entry *e) |
233 | { | |
234 | return arpt_get_target((struct arpt_entry *)e); | |
235 | } | |
236 | ||
237 | static inline struct arpt_entry * | |
238 | get_entry(const void *base, unsigned int offset) | |
1da177e4 LT |
239 | { |
240 | return (struct arpt_entry *)(base + offset); | |
241 | } | |
242 | ||
6c7941de | 243 | static inline |
98e86403 JE |
244 | struct arpt_entry *arpt_next_entry(const struct arpt_entry *entry) |
245 | { | |
246 | return (void *)entry + entry->next_offset; | |
247 | } | |
248 | ||
3db05fea | 249 | unsigned int arpt_do_table(struct sk_buff *skb, |
b85c3dc9 | 250 | const struct nf_hook_state *state, |
4abff077 | 251 | struct xt_table *table) |
1da177e4 | 252 | { |
6cb8ff3f | 253 | unsigned int hook = state->hook; |
ddc214c4 | 254 | static const char nulldevname[IFNAMSIZ] __attribute__((aligned(sizeof(long)))); |
1da177e4 | 255 | unsigned int verdict = NF_DROP; |
5452e425 | 256 | const struct arphdr *arp; |
3bd22997 | 257 | struct arpt_entry *e, **jumpstack; |
1da177e4 | 258 | const char *indev, *outdev; |
711bdde6 | 259 | const void *table_base; |
3bd22997 | 260 | unsigned int cpu, stackidx = 0; |
5452e425 | 261 | const struct xt_table_info *private; |
de74c169 | 262 | struct xt_action_param acpar; |
7f5c6d4f | 263 | unsigned int addend; |
1da177e4 | 264 | |
988b7050 | 265 | if (!pskb_may_pull(skb, arp_hdr_len(skb->dev))) |
1da177e4 LT |
266 | return NF_DROP; |
267 | ||
b85c3dc9 DM |
268 | indev = state->in ? state->in->name : nulldevname; |
269 | outdev = state->out ? state->out->name : nulldevname; | |
1da177e4 | 270 | |
7f5c6d4f ED |
271 | local_bh_disable(); |
272 | addend = xt_write_recseq_begin(); | |
942e4a2b | 273 | private = table->private; |
3bd22997 | 274 | cpu = smp_processor_id(); |
b416c144 WD |
275 | /* |
276 | * Ensure we load private-> members after we've fetched the base | |
277 | * pointer. | |
278 | */ | |
279 | smp_read_barrier_depends(); | |
482cfc31 | 280 | table_base = private->entries; |
3bd22997 | 281 | jumpstack = (struct arpt_entry **)private->jumpstack[cpu]; |
78454473 | 282 | |
7814b6ec FW |
283 | /* No TEE support for arptables, so no need to switch to alternate |
284 | * stack. All targets that reenter must return absolute verdicts. | |
285 | */ | |
2e4e6a17 | 286 | e = get_entry(table_base, private->hook_entry[hook]); |
1da177e4 | 287 | |
156c196f | 288 | acpar.net = state->net; |
b85c3dc9 DM |
289 | acpar.in = state->in; |
290 | acpar.out = state->out; | |
de74c169 JE |
291 | acpar.hooknum = hook; |
292 | acpar.family = NFPROTO_ARP; | |
b4ba2611 | 293 | acpar.hotdrop = false; |
7eb35586 | 294 | |
3db05fea | 295 | arp = arp_hdr(skb); |
1da177e4 | 296 | do { |
87a2e70d | 297 | const struct xt_entry_target *t; |
71ae0dff | 298 | struct xt_counters *counter; |
a1ff4ac8 JE |
299 | |
300 | if (!arp_packet_match(arp, skb->dev, indev, outdev, &e->arp)) { | |
301 | e = arpt_next_entry(e); | |
302 | continue; | |
303 | } | |
304 | ||
71ae0dff FW |
305 | counter = xt_get_this_cpu_counter(&e->counters); |
306 | ADD_COUNTER(*counter, arp_hdr_len(skb->dev), 1); | |
1da177e4 | 307 | |
d5d1baa1 | 308 | t = arpt_get_target_c(e); |
a1ff4ac8 JE |
309 | |
310 | /* Standard target? */ | |
311 | if (!t->u.kernel.target->target) { | |
312 | int v; | |
313 | ||
87a2e70d | 314 | v = ((struct xt_standard_target *)t)->verdict; |
a1ff4ac8 JE |
315 | if (v < 0) { |
316 | /* Pop from stack? */ | |
243bf6e2 | 317 | if (v != XT_RETURN) { |
95c96174 | 318 | verdict = (unsigned int)(-v) - 1; |
1da177e4 | 319 | break; |
a1ff4ac8 | 320 | } |
3bd22997 FW |
321 | if (stackidx == 0) { |
322 | e = get_entry(table_base, | |
323 | private->underflow[hook]); | |
324 | } else { | |
325 | e = jumpstack[--stackidx]; | |
326 | e = arpt_next_entry(e); | |
327 | } | |
a1ff4ac8 | 328 | continue; |
1da177e4 | 329 | } |
a1ff4ac8 JE |
330 | if (table_base + v |
331 | != arpt_next_entry(e)) { | |
3bd22997 | 332 | jumpstack[stackidx++] = e; |
a1ff4ac8 JE |
333 | } |
334 | ||
335 | e = get_entry(table_base, v); | |
7a6b1c46 | 336 | continue; |
1da177e4 | 337 | } |
7a6b1c46 | 338 | |
de74c169 JE |
339 | acpar.target = t->u.kernel.target; |
340 | acpar.targinfo = t->data; | |
341 | verdict = t->u.kernel.target->target(skb, &acpar); | |
7a6b1c46 JE |
342 | |
343 | /* Target might have changed stuff. */ | |
344 | arp = arp_hdr(skb); | |
345 | ||
243bf6e2 | 346 | if (verdict == XT_CONTINUE) |
7a6b1c46 JE |
347 | e = arpt_next_entry(e); |
348 | else | |
349 | /* Verdict */ | |
350 | break; | |
b4ba2611 | 351 | } while (!acpar.hotdrop); |
7f5c6d4f ED |
352 | xt_write_recseq_end(addend); |
353 | local_bh_enable(); | |
1da177e4 | 354 | |
b4ba2611 | 355 | if (acpar.hotdrop) |
1da177e4 LT |
356 | return NF_DROP; |
357 | else | |
358 | return verdict; | |
359 | } | |
360 | ||
1da177e4 | 361 | /* All zeroes == unconditional rule. */ |
54d83fc7 | 362 | static inline bool unconditional(const struct arpt_entry *e) |
1da177e4 | 363 | { |
47901dc2 | 364 | static const struct arpt_arp uncond; |
1da177e4 | 365 | |
54d83fc7 FW |
366 | return e->target_offset == sizeof(struct arpt_entry) && |
367 | memcmp(&e->arp, &uncond, sizeof(uncond)) == 0; | |
1da177e4 LT |
368 | } |
369 | ||
370 | /* Figures out from what hook each rule can be called: returns 0 if | |
371 | * there are loops. Puts hook bitmask in comefrom. | |
372 | */ | |
98dbbfc3 | 373 | static int mark_source_chains(const struct xt_table_info *newinfo, |
31836064 | 374 | unsigned int valid_hooks, void *entry0) |
1da177e4 LT |
375 | { |
376 | unsigned int hook; | |
377 | ||
378 | /* No recursion; use packet counter to save back ptrs (reset | |
379 | * to 0 as we leave), and comefrom to save source hook bitmask. | |
380 | */ | |
381 | for (hook = 0; hook < NF_ARP_NUMHOOKS; hook++) { | |
382 | unsigned int pos = newinfo->hook_entry[hook]; | |
383 | struct arpt_entry *e | |
31836064 | 384 | = (struct arpt_entry *)(entry0 + pos); |
1da177e4 LT |
385 | |
386 | if (!(valid_hooks & (1 << hook))) | |
387 | continue; | |
388 | ||
389 | /* Set initial back pointer. */ | |
390 | e->counters.pcnt = pos; | |
391 | ||
392 | for (;;) { | |
87a2e70d | 393 | const struct xt_standard_target *t |
d5d1baa1 | 394 | = (void *)arpt_get_target_c(e); |
e1b4b9f3 | 395 | int visited = e->comefrom & (1 << hook); |
1da177e4 LT |
396 | |
397 | if (e->comefrom & (1 << NF_ARP_NUMHOOKS)) { | |
654d0fbd | 398 | pr_notice("arptables: loop hook %u pos %u %08X.\n", |
1da177e4 LT |
399 | hook, pos, e->comefrom); |
400 | return 0; | |
401 | } | |
402 | e->comefrom | |
403 | |= ((1 << hook) | (1 << NF_ARP_NUMHOOKS)); | |
404 | ||
405 | /* Unconditional return/END. */ | |
54d83fc7 | 406 | if ((unconditional(e) && |
3666ed1c | 407 | (strcmp(t->target.u.user.name, |
243bf6e2 | 408 | XT_STANDARD_TARGET) == 0) && |
54d83fc7 | 409 | t->verdict < 0) || visited) { |
1da177e4 LT |
410 | unsigned int oldpos, size; |
411 | ||
1f9352ae | 412 | if ((strcmp(t->target.u.user.name, |
243bf6e2 | 413 | XT_STANDARD_TARGET) == 0) && |
1f9352ae | 414 | t->verdict < -NF_MAX_VERDICT - 1) { |
74c9c0c1 DM |
415 | duprintf("mark_source_chains: bad " |
416 | "negative verdict (%i)\n", | |
417 | t->verdict); | |
418 | return 0; | |
419 | } | |
420 | ||
1da177e4 LT |
421 | /* Return: backtrack through the last |
422 | * big jump. | |
423 | */ | |
424 | do { | |
425 | e->comefrom ^= (1<<NF_ARP_NUMHOOKS); | |
426 | oldpos = pos; | |
427 | pos = e->counters.pcnt; | |
428 | e->counters.pcnt = 0; | |
429 | ||
430 | /* We're at the start. */ | |
431 | if (pos == oldpos) | |
432 | goto next; | |
433 | ||
434 | e = (struct arpt_entry *) | |
31836064 | 435 | (entry0 + pos); |
1da177e4 LT |
436 | } while (oldpos == pos + e->next_offset); |
437 | ||
438 | /* Move along one */ | |
439 | size = e->next_offset; | |
440 | e = (struct arpt_entry *) | |
31836064 | 441 | (entry0 + pos + size); |
1da177e4 LT |
442 | e->counters.pcnt = pos; |
443 | pos += size; | |
444 | } else { | |
445 | int newpos = t->verdict; | |
446 | ||
447 | if (strcmp(t->target.u.user.name, | |
243bf6e2 | 448 | XT_STANDARD_TARGET) == 0 && |
3666ed1c | 449 | newpos >= 0) { |
74c9c0c1 DM |
450 | if (newpos > newinfo->size - |
451 | sizeof(struct arpt_entry)) { | |
452 | duprintf("mark_source_chains: " | |
453 | "bad verdict (%i)\n", | |
454 | newpos); | |
455 | return 0; | |
456 | } | |
457 | ||
1da177e4 LT |
458 | /* This a jump; chase it. */ |
459 | duprintf("Jump rule %u -> %u\n", | |
460 | pos, newpos); | |
461 | } else { | |
462 | /* ... this is a fallthru */ | |
463 | newpos = pos + e->next_offset; | |
464 | } | |
465 | e = (struct arpt_entry *) | |
31836064 | 466 | (entry0 + newpos); |
1da177e4 LT |
467 | e->counters.pcnt = pos; |
468 | pos = newpos; | |
469 | } | |
470 | } | |
19f0a602 | 471 | next: |
1da177e4 LT |
472 | duprintf("Finished chain %u\n", hook); |
473 | } | |
474 | return 1; | |
475 | } | |
476 | ||
bdf533de | 477 | static inline int check_entry(const struct arpt_entry *e) |
1da177e4 | 478 | { |
87a2e70d | 479 | const struct xt_entry_target *t; |
1da177e4 | 480 | |
bdf533de | 481 | if (!arp_checkentry(&e->arp)) |
1da177e4 | 482 | return -EINVAL; |
1da177e4 | 483 | |
87a2e70d | 484 | if (e->target_offset + sizeof(struct xt_entry_target) > e->next_offset) |
590bdf7f DM |
485 | return -EINVAL; |
486 | ||
d5d1baa1 | 487 | t = arpt_get_target_c(e); |
590bdf7f DM |
488 | if (e->target_offset + t->u.target_size > e->next_offset) |
489 | return -EINVAL; | |
490 | ||
fb5b6095 PM |
491 | return 0; |
492 | } | |
493 | ||
494 | static inline int check_target(struct arpt_entry *e, const char *name) | |
495 | { | |
87a2e70d | 496 | struct xt_entry_target *t = arpt_get_target(e); |
fb5b6095 | 497 | int ret; |
af5d6dc2 JE |
498 | struct xt_tgchk_param par = { |
499 | .table = name, | |
500 | .entryinfo = e, | |
501 | .target = t->u.kernel.target, | |
502 | .targinfo = t->data, | |
503 | .hook_mask = e->comefrom, | |
916a917d | 504 | .family = NFPROTO_ARP, |
af5d6dc2 JE |
505 | }; |
506 | ||
916a917d | 507 | ret = xt_check_target(&par, t->u.target_size - sizeof(*t), 0, false); |
367c6790 | 508 | if (ret < 0) { |
fb5b6095 PM |
509 | duprintf("arp_tables: check failed for `%s'.\n", |
510 | t->u.kernel.target->name); | |
367c6790 | 511 | return ret; |
fb5b6095 | 512 | } |
367c6790 | 513 | return 0; |
fb5b6095 PM |
514 | } |
515 | ||
516 | static inline int | |
0559518b | 517 | find_check_entry(struct arpt_entry *e, const char *name, unsigned int size) |
fb5b6095 | 518 | { |
87a2e70d | 519 | struct xt_entry_target *t; |
95eea855 | 520 | struct xt_target *target; |
fb5b6095 PM |
521 | int ret; |
522 | ||
71ae0dff FW |
523 | e->counters.pcnt = xt_percpu_counter_alloc(); |
524 | if (IS_ERR_VALUE(e->counters.pcnt)) | |
525 | return -ENOMEM; | |
526 | ||
fb5b6095 | 527 | t = arpt_get_target(e); |
d2a7b6ba JE |
528 | target = xt_request_find_target(NFPROTO_ARP, t->u.user.name, |
529 | t->u.user.revision); | |
530 | if (IS_ERR(target)) { | |
fb5b6095 | 531 | duprintf("find_check_entry: `%s' not found\n", t->u.user.name); |
d2a7b6ba | 532 | ret = PTR_ERR(target); |
1da177e4 LT |
533 | goto out; |
534 | } | |
1da177e4 | 535 | t->u.kernel.target = target; |
1da177e4 | 536 | |
fb5b6095 | 537 | ret = check_target(e, name); |
3cdc7c95 PM |
538 | if (ret) |
539 | goto err; | |
1da177e4 | 540 | return 0; |
3cdc7c95 PM |
541 | err: |
542 | module_put(t->u.kernel.target->me); | |
1da177e4 | 543 | out: |
71ae0dff FW |
544 | xt_percpu_counter_free(e->counters.pcnt); |
545 | ||
1da177e4 LT |
546 | return ret; |
547 | } | |
548 | ||
d5d1baa1 | 549 | static bool check_underflow(const struct arpt_entry *e) |
e2fe35c1 | 550 | { |
87a2e70d | 551 | const struct xt_entry_target *t; |
e2fe35c1 JE |
552 | unsigned int verdict; |
553 | ||
54d83fc7 | 554 | if (!unconditional(e)) |
e2fe35c1 | 555 | return false; |
d5d1baa1 | 556 | t = arpt_get_target_c(e); |
e2fe35c1 JE |
557 | if (strcmp(t->u.user.name, XT_STANDARD_TARGET) != 0) |
558 | return false; | |
87a2e70d | 559 | verdict = ((struct xt_standard_target *)t)->verdict; |
e2fe35c1 JE |
560 | verdict = -verdict - 1; |
561 | return verdict == NF_DROP || verdict == NF_ACCEPT; | |
562 | } | |
563 | ||
1da177e4 | 564 | static inline int check_entry_size_and_hooks(struct arpt_entry *e, |
2e4e6a17 | 565 | struct xt_table_info *newinfo, |
d5d1baa1 JE |
566 | const unsigned char *base, |
567 | const unsigned char *limit, | |
1da177e4 LT |
568 | const unsigned int *hook_entries, |
569 | const unsigned int *underflows, | |
0559518b | 570 | unsigned int valid_hooks) |
1da177e4 LT |
571 | { |
572 | unsigned int h; | |
bdf533de | 573 | int err; |
1da177e4 | 574 | |
3666ed1c | 575 | if ((unsigned long)e % __alignof__(struct arpt_entry) != 0 || |
6e94e0cf FW |
576 | (unsigned char *)e + sizeof(struct arpt_entry) >= limit || |
577 | (unsigned char *)e + e->next_offset > limit) { | |
1da177e4 LT |
578 | duprintf("Bad offset %p\n", e); |
579 | return -EINVAL; | |
580 | } | |
581 | ||
582 | if (e->next_offset | |
87a2e70d | 583 | < sizeof(struct arpt_entry) + sizeof(struct xt_entry_target)) { |
1da177e4 LT |
584 | duprintf("checking: element %p size %u\n", |
585 | e, e->next_offset); | |
586 | return -EINVAL; | |
587 | } | |
588 | ||
bdf533de FW |
589 | err = check_entry(e); |
590 | if (err) | |
591 | return err; | |
592 | ||
1da177e4 LT |
593 | /* Check hooks & underflows */ |
594 | for (h = 0; h < NF_ARP_NUMHOOKS; h++) { | |
a7d51738 JE |
595 | if (!(valid_hooks & (1 << h))) |
596 | continue; | |
1da177e4 LT |
597 | if ((unsigned char *)e - base == hook_entries[h]) |
598 | newinfo->hook_entry[h] = hook_entries[h]; | |
90e7d4ab | 599 | if ((unsigned char *)e - base == underflows[h]) { |
e2fe35c1 | 600 | if (!check_underflow(e)) { |
54d83fc7 FW |
601 | pr_debug("Underflows must be unconditional and " |
602 | "use the STANDARD target with " | |
603 | "ACCEPT/DROP\n"); | |
90e7d4ab JE |
604 | return -EINVAL; |
605 | } | |
1da177e4 | 606 | newinfo->underflow[h] = underflows[h]; |
90e7d4ab | 607 | } |
1da177e4 LT |
608 | } |
609 | ||
1da177e4 | 610 | /* Clear counters and comefrom */ |
2e4e6a17 | 611 | e->counters = ((struct xt_counters) { 0, 0 }); |
1da177e4 | 612 | e->comefrom = 0; |
1da177e4 LT |
613 | return 0; |
614 | } | |
615 | ||
0559518b | 616 | static inline void cleanup_entry(struct arpt_entry *e) |
1da177e4 | 617 | { |
a2df1648 | 618 | struct xt_tgdtor_param par; |
87a2e70d | 619 | struct xt_entry_target *t; |
1da177e4 | 620 | |
1da177e4 | 621 | t = arpt_get_target(e); |
a2df1648 JE |
622 | par.target = t->u.kernel.target; |
623 | par.targinfo = t->data; | |
916a917d | 624 | par.family = NFPROTO_ARP; |
a2df1648 JE |
625 | if (par.target->destroy != NULL) |
626 | par.target->destroy(&par); | |
627 | module_put(par.target->me); | |
71ae0dff | 628 | xt_percpu_counter_free(e->counters.pcnt); |
1da177e4 LT |
629 | } |
630 | ||
631 | /* Checks and translates the user-supplied table segment (held in | |
632 | * newinfo). | |
633 | */ | |
0f234214 | 634 | static int translate_table(struct xt_table_info *newinfo, void *entry0, |
6c28255b | 635 | const struct arpt_replace *repl) |
1da177e4 | 636 | { |
72b2b1dd | 637 | struct arpt_entry *iter; |
1da177e4 | 638 | unsigned int i; |
72b2b1dd | 639 | int ret = 0; |
1da177e4 | 640 | |
0f234214 JE |
641 | newinfo->size = repl->size; |
642 | newinfo->number = repl->num_entries; | |
1da177e4 LT |
643 | |
644 | /* Init all hooks to impossible value. */ | |
645 | for (i = 0; i < NF_ARP_NUMHOOKS; i++) { | |
646 | newinfo->hook_entry[i] = 0xFFFFFFFF; | |
647 | newinfo->underflow[i] = 0xFFFFFFFF; | |
648 | } | |
649 | ||
650 | duprintf("translate_table: size %u\n", newinfo->size); | |
651 | i = 0; | |
652 | ||
653 | /* Walk through entries, checking offsets. */ | |
72b2b1dd JE |
654 | xt_entry_foreach(iter, entry0, newinfo->size) { |
655 | ret = check_entry_size_and_hooks(iter, newinfo, entry0, | |
6b4ff2d7 JE |
656 | entry0 + repl->size, |
657 | repl->hook_entry, | |
658 | repl->underflow, | |
659 | repl->valid_hooks); | |
72b2b1dd JE |
660 | if (ret != 0) |
661 | break; | |
0559518b | 662 | ++i; |
98dbbfc3 FW |
663 | if (strcmp(arpt_get_target(iter)->u.user.name, |
664 | XT_ERROR_TARGET) == 0) | |
665 | ++newinfo->stacksize; | |
72b2b1dd | 666 | } |
1da177e4 LT |
667 | duprintf("translate_table: ARPT_ENTRY_ITERATE gives %d\n", ret); |
668 | if (ret != 0) | |
669 | return ret; | |
670 | ||
0f234214 | 671 | if (i != repl->num_entries) { |
1da177e4 | 672 | duprintf("translate_table: %u not %u entries\n", |
0f234214 | 673 | i, repl->num_entries); |
1da177e4 LT |
674 | return -EINVAL; |
675 | } | |
676 | ||
677 | /* Check hooks all assigned */ | |
678 | for (i = 0; i < NF_ARP_NUMHOOKS; i++) { | |
679 | /* Only hooks which are valid */ | |
0f234214 | 680 | if (!(repl->valid_hooks & (1 << i))) |
1da177e4 LT |
681 | continue; |
682 | if (newinfo->hook_entry[i] == 0xFFFFFFFF) { | |
683 | duprintf("Invalid hook entry %u %u\n", | |
0f234214 | 684 | i, repl->hook_entry[i]); |
1da177e4 LT |
685 | return -EINVAL; |
686 | } | |
687 | if (newinfo->underflow[i] == 0xFFFFFFFF) { | |
688 | duprintf("Invalid underflow %u %u\n", | |
0f234214 | 689 | i, repl->underflow[i]); |
1da177e4 LT |
690 | return -EINVAL; |
691 | } | |
692 | } | |
693 | ||
0f234214 | 694 | if (!mark_source_chains(newinfo, repl->valid_hooks, entry0)) { |
74c9c0c1 DM |
695 | duprintf("Looping hook\n"); |
696 | return -ELOOP; | |
697 | } | |
698 | ||
1da177e4 LT |
699 | /* Finally, each sanity check must pass */ |
700 | i = 0; | |
72b2b1dd | 701 | xt_entry_foreach(iter, entry0, newinfo->size) { |
0f234214 | 702 | ret = find_check_entry(iter, repl->name, repl->size); |
72b2b1dd JE |
703 | if (ret != 0) |
704 | break; | |
0559518b | 705 | ++i; |
72b2b1dd | 706 | } |
1da177e4 | 707 | |
74c9c0c1 | 708 | if (ret != 0) { |
0559518b JE |
709 | xt_entry_foreach(iter, entry0, newinfo->size) { |
710 | if (i-- == 0) | |
72b2b1dd | 711 | break; |
0559518b JE |
712 | cleanup_entry(iter); |
713 | } | |
74c9c0c1 | 714 | return ret; |
1da177e4 LT |
715 | } |
716 | ||
1da177e4 LT |
717 | return ret; |
718 | } | |
719 | ||
2e4e6a17 HW |
720 | static void get_counters(const struct xt_table_info *t, |
721 | struct xt_counters counters[]) | |
1da177e4 | 722 | { |
72b2b1dd | 723 | struct arpt_entry *iter; |
1da177e4 LT |
724 | unsigned int cpu; |
725 | unsigned int i; | |
726 | ||
6f912042 | 727 | for_each_possible_cpu(cpu) { |
7f5c6d4f | 728 | seqcount_t *s = &per_cpu(xt_recseq, cpu); |
83723d60 | 729 | |
1da177e4 | 730 | i = 0; |
482cfc31 | 731 | xt_entry_foreach(iter, t->entries, t->size) { |
71ae0dff | 732 | struct xt_counters *tmp; |
83723d60 ED |
733 | u64 bcnt, pcnt; |
734 | unsigned int start; | |
735 | ||
71ae0dff | 736 | tmp = xt_get_per_cpu_counter(&iter->counters, cpu); |
83723d60 | 737 | do { |
7f5c6d4f | 738 | start = read_seqcount_begin(s); |
71ae0dff FW |
739 | bcnt = tmp->bcnt; |
740 | pcnt = tmp->pcnt; | |
7f5c6d4f | 741 | } while (read_seqcount_retry(s, start)); |
83723d60 ED |
742 | |
743 | ADD_COUNTER(counters[i], bcnt, pcnt); | |
0559518b JE |
744 | ++i; |
745 | } | |
1da177e4 | 746 | } |
78454473 SH |
747 | } |
748 | ||
d5d1baa1 | 749 | static struct xt_counters *alloc_counters(const struct xt_table *table) |
1da177e4 | 750 | { |
27e2c26b | 751 | unsigned int countersize; |
2e4e6a17 | 752 | struct xt_counters *counters; |
d5d1baa1 | 753 | const struct xt_table_info *private = table->private; |
1da177e4 LT |
754 | |
755 | /* We need atomic snapshot of counters: rest doesn't change | |
756 | * (other than comefrom, which userspace doesn't care | |
757 | * about). | |
758 | */ | |
2e4e6a17 | 759 | countersize = sizeof(struct xt_counters) * private->number; |
83723d60 | 760 | counters = vzalloc(countersize); |
1da177e4 LT |
761 | |
762 | if (counters == NULL) | |
942e4a2b | 763 | return ERR_PTR(-ENOMEM); |
78454473 | 764 | |
942e4a2b | 765 | get_counters(private, counters); |
1da177e4 | 766 | |
27e2c26b PM |
767 | return counters; |
768 | } | |
769 | ||
770 | static int copy_entries_to_user(unsigned int total_size, | |
d5d1baa1 | 771 | const struct xt_table *table, |
27e2c26b PM |
772 | void __user *userptr) |
773 | { | |
774 | unsigned int off, num; | |
d5d1baa1 | 775 | const struct arpt_entry *e; |
27e2c26b | 776 | struct xt_counters *counters; |
4abff077 | 777 | struct xt_table_info *private = table->private; |
27e2c26b PM |
778 | int ret = 0; |
779 | void *loc_cpu_entry; | |
780 | ||
781 | counters = alloc_counters(table); | |
782 | if (IS_ERR(counters)) | |
783 | return PTR_ERR(counters); | |
784 | ||
482cfc31 | 785 | loc_cpu_entry = private->entries; |
31836064 ED |
786 | /* ... then copy entire thing ... */ |
787 | if (copy_to_user(userptr, loc_cpu_entry, total_size) != 0) { | |
1da177e4 LT |
788 | ret = -EFAULT; |
789 | goto free_counters; | |
790 | } | |
791 | ||
792 | /* FIXME: use iterator macros --RR */ | |
793 | /* ... then go back and fix counters and names */ | |
794 | for (off = 0, num = 0; off < total_size; off += e->next_offset, num++){ | |
87a2e70d | 795 | const struct xt_entry_target *t; |
1da177e4 | 796 | |
31836064 | 797 | e = (struct arpt_entry *)(loc_cpu_entry + off); |
1da177e4 LT |
798 | if (copy_to_user(userptr + off |
799 | + offsetof(struct arpt_entry, counters), | |
800 | &counters[num], | |
801 | sizeof(counters[num])) != 0) { | |
802 | ret = -EFAULT; | |
803 | goto free_counters; | |
804 | } | |
805 | ||
d5d1baa1 | 806 | t = arpt_get_target_c(e); |
1da177e4 | 807 | if (copy_to_user(userptr + off + e->target_offset |
87a2e70d | 808 | + offsetof(struct xt_entry_target, |
1da177e4 LT |
809 | u.user.name), |
810 | t->u.kernel.target->name, | |
811 | strlen(t->u.kernel.target->name)+1) != 0) { | |
812 | ret = -EFAULT; | |
813 | goto free_counters; | |
814 | } | |
815 | } | |
816 | ||
817 | free_counters: | |
818 | vfree(counters); | |
819 | return ret; | |
820 | } | |
821 | ||
d6a2ba07 | 822 | #ifdef CONFIG_COMPAT |
739674fb | 823 | static void compat_standard_from_user(void *dst, const void *src) |
d6a2ba07 PM |
824 | { |
825 | int v = *(compat_int_t *)src; | |
826 | ||
827 | if (v > 0) | |
ee999d8b | 828 | v += xt_compat_calc_jump(NFPROTO_ARP, v); |
d6a2ba07 PM |
829 | memcpy(dst, &v, sizeof(v)); |
830 | } | |
831 | ||
739674fb | 832 | static int compat_standard_to_user(void __user *dst, const void *src) |
d6a2ba07 PM |
833 | { |
834 | compat_int_t cv = *(int *)src; | |
835 | ||
836 | if (cv > 0) | |
ee999d8b | 837 | cv -= xt_compat_calc_jump(NFPROTO_ARP, cv); |
d6a2ba07 PM |
838 | return copy_to_user(dst, &cv, sizeof(cv)) ? -EFAULT : 0; |
839 | } | |
840 | ||
d5d1baa1 | 841 | static int compat_calc_entry(const struct arpt_entry *e, |
d6a2ba07 | 842 | const struct xt_table_info *info, |
d5d1baa1 | 843 | const void *base, struct xt_table_info *newinfo) |
d6a2ba07 | 844 | { |
87a2e70d | 845 | const struct xt_entry_target *t; |
d6a2ba07 PM |
846 | unsigned int entry_offset; |
847 | int off, i, ret; | |
848 | ||
849 | off = sizeof(struct arpt_entry) - sizeof(struct compat_arpt_entry); | |
850 | entry_offset = (void *)e - base; | |
851 | ||
d5d1baa1 | 852 | t = arpt_get_target_c(e); |
d6a2ba07 PM |
853 | off += xt_compat_target_offset(t->u.kernel.target); |
854 | newinfo->size -= off; | |
ee999d8b | 855 | ret = xt_compat_add_offset(NFPROTO_ARP, entry_offset, off); |
d6a2ba07 PM |
856 | if (ret) |
857 | return ret; | |
858 | ||
859 | for (i = 0; i < NF_ARP_NUMHOOKS; i++) { | |
860 | if (info->hook_entry[i] && | |
861 | (e < (struct arpt_entry *)(base + info->hook_entry[i]))) | |
862 | newinfo->hook_entry[i] -= off; | |
863 | if (info->underflow[i] && | |
864 | (e < (struct arpt_entry *)(base + info->underflow[i]))) | |
865 | newinfo->underflow[i] -= off; | |
866 | } | |
867 | return 0; | |
868 | } | |
869 | ||
870 | static int compat_table_info(const struct xt_table_info *info, | |
871 | struct xt_table_info *newinfo) | |
872 | { | |
72b2b1dd | 873 | struct arpt_entry *iter; |
711bdde6 | 874 | const void *loc_cpu_entry; |
0559518b | 875 | int ret; |
d6a2ba07 PM |
876 | |
877 | if (!newinfo || !info) | |
878 | return -EINVAL; | |
879 | ||
482cfc31 | 880 | /* we dont care about newinfo->entries */ |
d6a2ba07 PM |
881 | memcpy(newinfo, info, offsetof(struct xt_table_info, entries)); |
882 | newinfo->initial_entries = 0; | |
482cfc31 | 883 | loc_cpu_entry = info->entries; |
255d0dc3 | 884 | xt_compat_init_offsets(NFPROTO_ARP, info->number); |
72b2b1dd JE |
885 | xt_entry_foreach(iter, loc_cpu_entry, info->size) { |
886 | ret = compat_calc_entry(iter, info, loc_cpu_entry, newinfo); | |
887 | if (ret != 0) | |
0559518b | 888 | return ret; |
72b2b1dd | 889 | } |
0559518b | 890 | return 0; |
d6a2ba07 PM |
891 | } |
892 | #endif | |
893 | ||
d5d1baa1 | 894 | static int get_info(struct net *net, void __user *user, |
6c28255b | 895 | const int *len, int compat) |
41acd975 | 896 | { |
12b00c2c | 897 | char name[XT_TABLE_MAXNAMELEN]; |
4abff077 | 898 | struct xt_table *t; |
41acd975 PM |
899 | int ret; |
900 | ||
901 | if (*len != sizeof(struct arpt_getinfo)) { | |
902 | duprintf("length %u != %Zu\n", *len, | |
903 | sizeof(struct arpt_getinfo)); | |
904 | return -EINVAL; | |
905 | } | |
906 | ||
907 | if (copy_from_user(name, user, sizeof(name)) != 0) | |
908 | return -EFAULT; | |
909 | ||
12b00c2c | 910 | name[XT_TABLE_MAXNAMELEN-1] = '\0'; |
d6a2ba07 PM |
911 | #ifdef CONFIG_COMPAT |
912 | if (compat) | |
ee999d8b | 913 | xt_compat_lock(NFPROTO_ARP); |
d6a2ba07 | 914 | #endif |
ee999d8b | 915 | t = try_then_request_module(xt_find_table_lock(net, NFPROTO_ARP, name), |
41acd975 | 916 | "arptable_%s", name); |
0cc8d8df | 917 | if (!IS_ERR_OR_NULL(t)) { |
41acd975 | 918 | struct arpt_getinfo info; |
5452e425 | 919 | const struct xt_table_info *private = t->private; |
d6a2ba07 | 920 | #ifdef CONFIG_COMPAT |
14c7dbe0 AD |
921 | struct xt_table_info tmp; |
922 | ||
d6a2ba07 | 923 | if (compat) { |
d6a2ba07 | 924 | ret = compat_table_info(private, &tmp); |
ee999d8b | 925 | xt_compat_flush_offsets(NFPROTO_ARP); |
d6a2ba07 PM |
926 | private = &tmp; |
927 | } | |
928 | #endif | |
1a8b7a67 | 929 | memset(&info, 0, sizeof(info)); |
41acd975 PM |
930 | info.valid_hooks = t->valid_hooks; |
931 | memcpy(info.hook_entry, private->hook_entry, | |
932 | sizeof(info.hook_entry)); | |
933 | memcpy(info.underflow, private->underflow, | |
934 | sizeof(info.underflow)); | |
935 | info.num_entries = private->number; | |
936 | info.size = private->size; | |
937 | strcpy(info.name, name); | |
938 | ||
939 | if (copy_to_user(user, &info, *len) != 0) | |
940 | ret = -EFAULT; | |
941 | else | |
942 | ret = 0; | |
943 | xt_table_unlock(t); | |
944 | module_put(t->me); | |
945 | } else | |
946 | ret = t ? PTR_ERR(t) : -ENOENT; | |
d6a2ba07 PM |
947 | #ifdef CONFIG_COMPAT |
948 | if (compat) | |
ee999d8b | 949 | xt_compat_unlock(NFPROTO_ARP); |
d6a2ba07 | 950 | #endif |
41acd975 PM |
951 | return ret; |
952 | } | |
953 | ||
79df341a | 954 | static int get_entries(struct net *net, struct arpt_get_entries __user *uptr, |
d5d1baa1 | 955 | const int *len) |
1da177e4 LT |
956 | { |
957 | int ret; | |
11f6dff8 | 958 | struct arpt_get_entries get; |
4abff077 | 959 | struct xt_table *t; |
1da177e4 | 960 | |
11f6dff8 PM |
961 | if (*len < sizeof(get)) { |
962 | duprintf("get_entries: %u < %Zu\n", *len, sizeof(get)); | |
963 | return -EINVAL; | |
964 | } | |
965 | if (copy_from_user(&get, uptr, sizeof(get)) != 0) | |
966 | return -EFAULT; | |
967 | if (*len != sizeof(struct arpt_get_entries) + get.size) { | |
968 | duprintf("get_entries: %u != %Zu\n", *len, | |
969 | sizeof(struct arpt_get_entries) + get.size); | |
970 | return -EINVAL; | |
971 | } | |
b301f253 | 972 | get.name[sizeof(get.name) - 1] = '\0'; |
11f6dff8 | 973 | |
ee999d8b | 974 | t = xt_find_table_lock(net, NFPROTO_ARP, get.name); |
0cc8d8df | 975 | if (!IS_ERR_OR_NULL(t)) { |
5452e425 JE |
976 | const struct xt_table_info *private = t->private; |
977 | ||
1da177e4 | 978 | duprintf("t->private->number = %u\n", |
2e4e6a17 | 979 | private->number); |
11f6dff8 | 980 | if (get.size == private->size) |
2e4e6a17 | 981 | ret = copy_entries_to_user(private->size, |
1da177e4 LT |
982 | t, uptr->entrytable); |
983 | else { | |
984 | duprintf("get_entries: I've got %u not %u!\n", | |
11f6dff8 | 985 | private->size, get.size); |
544473c1 | 986 | ret = -EAGAIN; |
1da177e4 | 987 | } |
6b7d31fc | 988 | module_put(t->me); |
2e4e6a17 | 989 | xt_table_unlock(t); |
1da177e4 | 990 | } else |
6b7d31fc | 991 | ret = t ? PTR_ERR(t) : -ENOENT; |
1da177e4 LT |
992 | |
993 | return ret; | |
994 | } | |
995 | ||
79df341a AD |
996 | static int __do_replace(struct net *net, const char *name, |
997 | unsigned int valid_hooks, | |
d6a2ba07 PM |
998 | struct xt_table_info *newinfo, |
999 | unsigned int num_counters, | |
1000 | void __user *counters_ptr) | |
1da177e4 LT |
1001 | { |
1002 | int ret; | |
4abff077 | 1003 | struct xt_table *t; |
d6a2ba07 | 1004 | struct xt_table_info *oldinfo; |
2e4e6a17 | 1005 | struct xt_counters *counters; |
d6a2ba07 | 1006 | void *loc_cpu_old_entry; |
72b2b1dd | 1007 | struct arpt_entry *iter; |
1da177e4 | 1008 | |
d6a2ba07 | 1009 | ret = 0; |
83723d60 | 1010 | counters = vzalloc(num_counters * sizeof(struct xt_counters)); |
1da177e4 LT |
1011 | if (!counters) { |
1012 | ret = -ENOMEM; | |
d6a2ba07 | 1013 | goto out; |
1da177e4 | 1014 | } |
1da177e4 | 1015 | |
ee999d8b | 1016 | t = try_then_request_module(xt_find_table_lock(net, NFPROTO_ARP, name), |
d6a2ba07 | 1017 | "arptable_%s", name); |
0cc8d8df | 1018 | if (IS_ERR_OR_NULL(t)) { |
6b7d31fc | 1019 | ret = t ? PTR_ERR(t) : -ENOENT; |
1da177e4 | 1020 | goto free_newinfo_counters_untrans; |
6b7d31fc | 1021 | } |
1da177e4 LT |
1022 | |
1023 | /* You lied! */ | |
d6a2ba07 | 1024 | if (valid_hooks != t->valid_hooks) { |
1da177e4 | 1025 | duprintf("Valid hook crap: %08X vs %08X\n", |
d6a2ba07 | 1026 | valid_hooks, t->valid_hooks); |
1da177e4 | 1027 | ret = -EINVAL; |
6b7d31fc | 1028 | goto put_module; |
1da177e4 LT |
1029 | } |
1030 | ||
d6a2ba07 | 1031 | oldinfo = xt_replace_table(t, num_counters, newinfo, &ret); |
1da177e4 LT |
1032 | if (!oldinfo) |
1033 | goto put_module; | |
1034 | ||
1035 | /* Update module usage count based on number of rules */ | |
1036 | duprintf("do_replace: oldnum=%u, initnum=%u, newnum=%u\n", | |
1037 | oldinfo->number, oldinfo->initial_entries, newinfo->number); | |
e905a9ed YH |
1038 | if ((oldinfo->number > oldinfo->initial_entries) || |
1039 | (newinfo->number <= oldinfo->initial_entries)) | |
1da177e4 LT |
1040 | module_put(t->me); |
1041 | if ((oldinfo->number > oldinfo->initial_entries) && | |
1042 | (newinfo->number <= oldinfo->initial_entries)) | |
1043 | module_put(t->me); | |
1044 | ||
942e4a2b | 1045 | /* Get the old counters, and synchronize with replace */ |
1da177e4 | 1046 | get_counters(oldinfo, counters); |
942e4a2b | 1047 | |
1da177e4 | 1048 | /* Decrease module usage counts and free resource */ |
482cfc31 | 1049 | loc_cpu_old_entry = oldinfo->entries; |
72b2b1dd | 1050 | xt_entry_foreach(iter, loc_cpu_old_entry, oldinfo->size) |
0559518b | 1051 | cleanup_entry(iter); |
31836064 | 1052 | |
2e4e6a17 | 1053 | xt_free_table_info(oldinfo); |
d6a2ba07 | 1054 | if (copy_to_user(counters_ptr, counters, |
c58dd2dd TG |
1055 | sizeof(struct xt_counters) * num_counters) != 0) { |
1056 | /* Silent error, can't fail, new table is already in place */ | |
1057 | net_warn_ratelimited("arptables: counters copy to user failed while replacing table\n"); | |
1058 | } | |
1da177e4 | 1059 | vfree(counters); |
2e4e6a17 | 1060 | xt_table_unlock(t); |
1da177e4 LT |
1061 | return ret; |
1062 | ||
1063 | put_module: | |
1064 | module_put(t->me); | |
2e4e6a17 | 1065 | xt_table_unlock(t); |
1da177e4 | 1066 | free_newinfo_counters_untrans: |
1da177e4 | 1067 | vfree(counters); |
d6a2ba07 PM |
1068 | out: |
1069 | return ret; | |
1070 | } | |
1071 | ||
d5d1baa1 | 1072 | static int do_replace(struct net *net, const void __user *user, |
6c28255b | 1073 | unsigned int len) |
d6a2ba07 PM |
1074 | { |
1075 | int ret; | |
1076 | struct arpt_replace tmp; | |
1077 | struct xt_table_info *newinfo; | |
1078 | void *loc_cpu_entry; | |
72b2b1dd | 1079 | struct arpt_entry *iter; |
d6a2ba07 PM |
1080 | |
1081 | if (copy_from_user(&tmp, user, sizeof(tmp)) != 0) | |
1082 | return -EFAULT; | |
1083 | ||
1084 | /* overflow check */ | |
1085 | if (tmp.num_counters >= INT_MAX / sizeof(struct xt_counters)) | |
1086 | return -ENOMEM; | |
1086bbe9 DJ |
1087 | if (tmp.num_counters == 0) |
1088 | return -EINVAL; | |
1089 | ||
42eab94f | 1090 | tmp.name[sizeof(tmp.name)-1] = 0; |
d6a2ba07 PM |
1091 | |
1092 | newinfo = xt_alloc_table_info(tmp.size); | |
1093 | if (!newinfo) | |
1094 | return -ENOMEM; | |
1095 | ||
482cfc31 | 1096 | loc_cpu_entry = newinfo->entries; |
d6a2ba07 PM |
1097 | if (copy_from_user(loc_cpu_entry, user + sizeof(tmp), |
1098 | tmp.size) != 0) { | |
1099 | ret = -EFAULT; | |
1100 | goto free_newinfo; | |
1101 | } | |
1102 | ||
0f234214 | 1103 | ret = translate_table(newinfo, loc_cpu_entry, &tmp); |
d6a2ba07 PM |
1104 | if (ret != 0) |
1105 | goto free_newinfo; | |
1106 | ||
1107 | duprintf("arp_tables: Translated table\n"); | |
1108 | ||
79df341a | 1109 | ret = __do_replace(net, tmp.name, tmp.valid_hooks, newinfo, |
d6a2ba07 PM |
1110 | tmp.num_counters, tmp.counters); |
1111 | if (ret) | |
1112 | goto free_newinfo_untrans; | |
1113 | return 0; | |
1114 | ||
1115 | free_newinfo_untrans: | |
72b2b1dd | 1116 | xt_entry_foreach(iter, loc_cpu_entry, newinfo->size) |
0559518b | 1117 | cleanup_entry(iter); |
1da177e4 | 1118 | free_newinfo: |
2e4e6a17 | 1119 | xt_free_table_info(newinfo); |
1da177e4 LT |
1120 | return ret; |
1121 | } | |
1122 | ||
d5d1baa1 JE |
1123 | static int do_add_counters(struct net *net, const void __user *user, |
1124 | unsigned int len, int compat) | |
1da177e4 | 1125 | { |
482cfc31 | 1126 | unsigned int i; |
d6a2ba07 PM |
1127 | struct xt_counters_info tmp; |
1128 | struct xt_counters *paddc; | |
1129 | unsigned int num_counters; | |
5452e425 | 1130 | const char *name; |
d6a2ba07 PM |
1131 | int size; |
1132 | void *ptmp; | |
4abff077 | 1133 | struct xt_table *t; |
5452e425 | 1134 | const struct xt_table_info *private; |
6b7d31fc | 1135 | int ret = 0; |
72b2b1dd | 1136 | struct arpt_entry *iter; |
7f5c6d4f | 1137 | unsigned int addend; |
d6a2ba07 PM |
1138 | #ifdef CONFIG_COMPAT |
1139 | struct compat_xt_counters_info compat_tmp; | |
1da177e4 | 1140 | |
d6a2ba07 PM |
1141 | if (compat) { |
1142 | ptmp = &compat_tmp; | |
1143 | size = sizeof(struct compat_xt_counters_info); | |
1144 | } else | |
1145 | #endif | |
1146 | { | |
1147 | ptmp = &tmp; | |
1148 | size = sizeof(struct xt_counters_info); | |
1149 | } | |
1150 | ||
1151 | if (copy_from_user(ptmp, user, size) != 0) | |
1da177e4 LT |
1152 | return -EFAULT; |
1153 | ||
d6a2ba07 PM |
1154 | #ifdef CONFIG_COMPAT |
1155 | if (compat) { | |
1156 | num_counters = compat_tmp.num_counters; | |
1157 | name = compat_tmp.name; | |
1158 | } else | |
1159 | #endif | |
1160 | { | |
1161 | num_counters = tmp.num_counters; | |
1162 | name = tmp.name; | |
1163 | } | |
1164 | ||
1165 | if (len != size + num_counters * sizeof(struct xt_counters)) | |
1da177e4 LT |
1166 | return -EINVAL; |
1167 | ||
e12f8e29 | 1168 | paddc = vmalloc(len - size); |
1da177e4 LT |
1169 | if (!paddc) |
1170 | return -ENOMEM; | |
1171 | ||
d6a2ba07 | 1172 | if (copy_from_user(paddc, user + size, len - size) != 0) { |
1da177e4 LT |
1173 | ret = -EFAULT; |
1174 | goto free; | |
1175 | } | |
1176 | ||
ee999d8b | 1177 | t = xt_find_table_lock(net, NFPROTO_ARP, name); |
0cc8d8df | 1178 | if (IS_ERR_OR_NULL(t)) { |
6b7d31fc | 1179 | ret = t ? PTR_ERR(t) : -ENOENT; |
1da177e4 | 1180 | goto free; |
6b7d31fc | 1181 | } |
1da177e4 | 1182 | |
942e4a2b | 1183 | local_bh_disable(); |
2e4e6a17 | 1184 | private = t->private; |
d6a2ba07 | 1185 | if (private->number != num_counters) { |
1da177e4 LT |
1186 | ret = -EINVAL; |
1187 | goto unlock_up_free; | |
1188 | } | |
1189 | ||
1190 | i = 0; | |
482cfc31 | 1191 | |
7f5c6d4f | 1192 | addend = xt_write_recseq_begin(); |
482cfc31 | 1193 | xt_entry_foreach(iter, private->entries, private->size) { |
71ae0dff FW |
1194 | struct xt_counters *tmp; |
1195 | ||
1196 | tmp = xt_get_this_cpu_counter(&iter->counters); | |
1197 | ADD_COUNTER(*tmp, paddc[i].bcnt, paddc[i].pcnt); | |
0559518b JE |
1198 | ++i; |
1199 | } | |
7f5c6d4f | 1200 | xt_write_recseq_end(addend); |
1da177e4 | 1201 | unlock_up_free: |
942e4a2b | 1202 | local_bh_enable(); |
2e4e6a17 | 1203 | xt_table_unlock(t); |
6b7d31fc | 1204 | module_put(t->me); |
1da177e4 LT |
1205 | free: |
1206 | vfree(paddc); | |
1207 | ||
1208 | return ret; | |
1209 | } | |
1210 | ||
d6a2ba07 | 1211 | #ifdef CONFIG_COMPAT |
0559518b | 1212 | static inline void compat_release_entry(struct compat_arpt_entry *e) |
d6a2ba07 | 1213 | { |
87a2e70d | 1214 | struct xt_entry_target *t; |
d6a2ba07 | 1215 | |
d6a2ba07 PM |
1216 | t = compat_arpt_get_target(e); |
1217 | module_put(t->u.kernel.target->me); | |
d6a2ba07 PM |
1218 | } |
1219 | ||
1220 | static inline int | |
1221 | check_compat_entry_size_and_hooks(struct compat_arpt_entry *e, | |
1222 | struct xt_table_info *newinfo, | |
1223 | unsigned int *size, | |
d5d1baa1 JE |
1224 | const unsigned char *base, |
1225 | const unsigned char *limit, | |
1226 | const unsigned int *hook_entries, | |
1227 | const unsigned int *underflows, | |
d6a2ba07 PM |
1228 | const char *name) |
1229 | { | |
87a2e70d | 1230 | struct xt_entry_target *t; |
d6a2ba07 PM |
1231 | struct xt_target *target; |
1232 | unsigned int entry_offset; | |
1233 | int ret, off, h; | |
1234 | ||
1235 | duprintf("check_compat_entry_size_and_hooks %p\n", e); | |
3666ed1c | 1236 | if ((unsigned long)e % __alignof__(struct compat_arpt_entry) != 0 || |
6e94e0cf FW |
1237 | (unsigned char *)e + sizeof(struct compat_arpt_entry) >= limit || |
1238 | (unsigned char *)e + e->next_offset > limit) { | |
d6a2ba07 PM |
1239 | duprintf("Bad offset %p, limit = %p\n", e, limit); |
1240 | return -EINVAL; | |
1241 | } | |
1242 | ||
1243 | if (e->next_offset < sizeof(struct compat_arpt_entry) + | |
1244 | sizeof(struct compat_xt_entry_target)) { | |
1245 | duprintf("checking: element %p size %u\n", | |
1246 | e, e->next_offset); | |
1247 | return -EINVAL; | |
1248 | } | |
1249 | ||
1250 | /* For purposes of check_entry casting the compat entry is fine */ | |
bdf533de | 1251 | ret = check_entry((struct arpt_entry *)e); |
d6a2ba07 PM |
1252 | if (ret) |
1253 | return ret; | |
1254 | ||
1255 | off = sizeof(struct arpt_entry) - sizeof(struct compat_arpt_entry); | |
1256 | entry_offset = (void *)e - (void *)base; | |
1257 | ||
1258 | t = compat_arpt_get_target(e); | |
d2a7b6ba JE |
1259 | target = xt_request_find_target(NFPROTO_ARP, t->u.user.name, |
1260 | t->u.user.revision); | |
1261 | if (IS_ERR(target)) { | |
d6a2ba07 PM |
1262 | duprintf("check_compat_entry_size_and_hooks: `%s' not found\n", |
1263 | t->u.user.name); | |
d2a7b6ba | 1264 | ret = PTR_ERR(target); |
d6a2ba07 PM |
1265 | goto out; |
1266 | } | |
1267 | t->u.kernel.target = target; | |
1268 | ||
1269 | off += xt_compat_target_offset(target); | |
1270 | *size += off; | |
ee999d8b | 1271 | ret = xt_compat_add_offset(NFPROTO_ARP, entry_offset, off); |
d6a2ba07 PM |
1272 | if (ret) |
1273 | goto release_target; | |
1274 | ||
1275 | /* Check hooks & underflows */ | |
1276 | for (h = 0; h < NF_ARP_NUMHOOKS; h++) { | |
1277 | if ((unsigned char *)e - base == hook_entries[h]) | |
1278 | newinfo->hook_entry[h] = hook_entries[h]; | |
1279 | if ((unsigned char *)e - base == underflows[h]) | |
1280 | newinfo->underflow[h] = underflows[h]; | |
1281 | } | |
1282 | ||
1283 | /* Clear counters and comefrom */ | |
1284 | memset(&e->counters, 0, sizeof(e->counters)); | |
1285 | e->comefrom = 0; | |
d6a2ba07 PM |
1286 | return 0; |
1287 | ||
1288 | release_target: | |
1289 | module_put(t->u.kernel.target->me); | |
1290 | out: | |
1291 | return ret; | |
1292 | } | |
1293 | ||
1294 | static int | |
1295 | compat_copy_entry_from_user(struct compat_arpt_entry *e, void **dstptr, | |
1296 | unsigned int *size, const char *name, | |
1297 | struct xt_table_info *newinfo, unsigned char *base) | |
1298 | { | |
87a2e70d | 1299 | struct xt_entry_target *t; |
d6a2ba07 PM |
1300 | struct xt_target *target; |
1301 | struct arpt_entry *de; | |
1302 | unsigned int origsize; | |
1303 | int ret, h; | |
1304 | ||
1305 | ret = 0; | |
1306 | origsize = *size; | |
1307 | de = (struct arpt_entry *)*dstptr; | |
1308 | memcpy(de, e, sizeof(struct arpt_entry)); | |
1309 | memcpy(&de->counters, &e->counters, sizeof(e->counters)); | |
1310 | ||
1311 | *dstptr += sizeof(struct arpt_entry); | |
1312 | *size += sizeof(struct arpt_entry) - sizeof(struct compat_arpt_entry); | |
1313 | ||
1314 | de->target_offset = e->target_offset - (origsize - *size); | |
1315 | t = compat_arpt_get_target(e); | |
1316 | target = t->u.kernel.target; | |
1317 | xt_compat_target_from_user(t, dstptr, size); | |
1318 | ||
1319 | de->next_offset = e->next_offset - (origsize - *size); | |
1320 | for (h = 0; h < NF_ARP_NUMHOOKS; h++) { | |
1321 | if ((unsigned char *)de - base < newinfo->hook_entry[h]) | |
1322 | newinfo->hook_entry[h] -= origsize - *size; | |
1323 | if ((unsigned char *)de - base < newinfo->underflow[h]) | |
1324 | newinfo->underflow[h] -= origsize - *size; | |
1325 | } | |
1326 | return ret; | |
1327 | } | |
1328 | ||
d6a2ba07 PM |
1329 | static int translate_compat_table(const char *name, |
1330 | unsigned int valid_hooks, | |
1331 | struct xt_table_info **pinfo, | |
1332 | void **pentry0, | |
1333 | unsigned int total_size, | |
1334 | unsigned int number, | |
1335 | unsigned int *hook_entries, | |
1336 | unsigned int *underflows) | |
1337 | { | |
1338 | unsigned int i, j; | |
1339 | struct xt_table_info *newinfo, *info; | |
1340 | void *pos, *entry0, *entry1; | |
72b2b1dd JE |
1341 | struct compat_arpt_entry *iter0; |
1342 | struct arpt_entry *iter1; | |
d6a2ba07 | 1343 | unsigned int size; |
72b2b1dd | 1344 | int ret = 0; |
d6a2ba07 PM |
1345 | |
1346 | info = *pinfo; | |
1347 | entry0 = *pentry0; | |
1348 | size = total_size; | |
1349 | info->number = number; | |
1350 | ||
1351 | /* Init all hooks to impossible value. */ | |
1352 | for (i = 0; i < NF_ARP_NUMHOOKS; i++) { | |
1353 | info->hook_entry[i] = 0xFFFFFFFF; | |
1354 | info->underflow[i] = 0xFFFFFFFF; | |
1355 | } | |
1356 | ||
1357 | duprintf("translate_compat_table: size %u\n", info->size); | |
1358 | j = 0; | |
ee999d8b | 1359 | xt_compat_lock(NFPROTO_ARP); |
255d0dc3 | 1360 | xt_compat_init_offsets(NFPROTO_ARP, number); |
d6a2ba07 | 1361 | /* Walk through entries, checking offsets. */ |
72b2b1dd JE |
1362 | xt_entry_foreach(iter0, entry0, total_size) { |
1363 | ret = check_compat_entry_size_and_hooks(iter0, info, &size, | |
6b4ff2d7 JE |
1364 | entry0, |
1365 | entry0 + total_size, | |
1366 | hook_entries, | |
1367 | underflows, | |
1368 | name); | |
72b2b1dd | 1369 | if (ret != 0) |
0559518b JE |
1370 | goto out_unlock; |
1371 | ++j; | |
72b2b1dd | 1372 | } |
d6a2ba07 PM |
1373 | |
1374 | ret = -EINVAL; | |
1375 | if (j != number) { | |
1376 | duprintf("translate_compat_table: %u not %u entries\n", | |
1377 | j, number); | |
1378 | goto out_unlock; | |
1379 | } | |
1380 | ||
1381 | /* Check hooks all assigned */ | |
1382 | for (i = 0; i < NF_ARP_NUMHOOKS; i++) { | |
1383 | /* Only hooks which are valid */ | |
1384 | if (!(valid_hooks & (1 << i))) | |
1385 | continue; | |
1386 | if (info->hook_entry[i] == 0xFFFFFFFF) { | |
1387 | duprintf("Invalid hook entry %u %u\n", | |
1388 | i, hook_entries[i]); | |
1389 | goto out_unlock; | |
1390 | } | |
1391 | if (info->underflow[i] == 0xFFFFFFFF) { | |
1392 | duprintf("Invalid underflow %u %u\n", | |
1393 | i, underflows[i]); | |
1394 | goto out_unlock; | |
1395 | } | |
1396 | } | |
1397 | ||
1398 | ret = -ENOMEM; | |
1399 | newinfo = xt_alloc_table_info(size); | |
1400 | if (!newinfo) | |
1401 | goto out_unlock; | |
1402 | ||
1403 | newinfo->number = number; | |
1404 | for (i = 0; i < NF_ARP_NUMHOOKS; i++) { | |
1405 | newinfo->hook_entry[i] = info->hook_entry[i]; | |
1406 | newinfo->underflow[i] = info->underflow[i]; | |
1407 | } | |
482cfc31 | 1408 | entry1 = newinfo->entries; |
d6a2ba07 PM |
1409 | pos = entry1; |
1410 | size = total_size; | |
72b2b1dd | 1411 | xt_entry_foreach(iter0, entry0, total_size) { |
6b4ff2d7 JE |
1412 | ret = compat_copy_entry_from_user(iter0, &pos, &size, |
1413 | name, newinfo, entry1); | |
72b2b1dd JE |
1414 | if (ret != 0) |
1415 | break; | |
1416 | } | |
ee999d8b JE |
1417 | xt_compat_flush_offsets(NFPROTO_ARP); |
1418 | xt_compat_unlock(NFPROTO_ARP); | |
d6a2ba07 PM |
1419 | if (ret) |
1420 | goto free_newinfo; | |
1421 | ||
1422 | ret = -ELOOP; | |
1423 | if (!mark_source_chains(newinfo, valid_hooks, entry1)) | |
1424 | goto free_newinfo; | |
1425 | ||
1426 | i = 0; | |
72b2b1dd | 1427 | xt_entry_foreach(iter1, entry1, newinfo->size) { |
71ae0dff FW |
1428 | iter1->counters.pcnt = xt_percpu_counter_alloc(); |
1429 | if (IS_ERR_VALUE(iter1->counters.pcnt)) { | |
1430 | ret = -ENOMEM; | |
1431 | break; | |
1432 | } | |
1433 | ||
0559518b | 1434 | ret = check_target(iter1, name); |
71ae0dff FW |
1435 | if (ret != 0) { |
1436 | xt_percpu_counter_free(iter1->counters.pcnt); | |
72b2b1dd | 1437 | break; |
71ae0dff | 1438 | } |
0559518b | 1439 | ++i; |
98dbbfc3 FW |
1440 | if (strcmp(arpt_get_target(iter1)->u.user.name, |
1441 | XT_ERROR_TARGET) == 0) | |
1442 | ++newinfo->stacksize; | |
72b2b1dd | 1443 | } |
d6a2ba07 | 1444 | if (ret) { |
72b2b1dd JE |
1445 | /* |
1446 | * The first i matches need cleanup_entry (calls ->destroy) | |
1447 | * because they had called ->check already. The other j-i | |
1448 | * entries need only release. | |
1449 | */ | |
1450 | int skip = i; | |
d6a2ba07 | 1451 | j -= i; |
72b2b1dd JE |
1452 | xt_entry_foreach(iter0, entry0, newinfo->size) { |
1453 | if (skip-- > 0) | |
1454 | continue; | |
0559518b | 1455 | if (j-- == 0) |
72b2b1dd | 1456 | break; |
0559518b | 1457 | compat_release_entry(iter0); |
72b2b1dd | 1458 | } |
0559518b JE |
1459 | xt_entry_foreach(iter1, entry1, newinfo->size) { |
1460 | if (i-- == 0) | |
72b2b1dd | 1461 | break; |
0559518b JE |
1462 | cleanup_entry(iter1); |
1463 | } | |
d6a2ba07 PM |
1464 | xt_free_table_info(newinfo); |
1465 | return ret; | |
1466 | } | |
1467 | ||
d6a2ba07 PM |
1468 | *pinfo = newinfo; |
1469 | *pentry0 = entry1; | |
1470 | xt_free_table_info(info); | |
1471 | return 0; | |
1472 | ||
1473 | free_newinfo: | |
1474 | xt_free_table_info(newinfo); | |
1475 | out: | |
0559518b JE |
1476 | xt_entry_foreach(iter0, entry0, total_size) { |
1477 | if (j-- == 0) | |
72b2b1dd | 1478 | break; |
0559518b JE |
1479 | compat_release_entry(iter0); |
1480 | } | |
d6a2ba07 PM |
1481 | return ret; |
1482 | out_unlock: | |
ee999d8b JE |
1483 | xt_compat_flush_offsets(NFPROTO_ARP); |
1484 | xt_compat_unlock(NFPROTO_ARP); | |
d6a2ba07 PM |
1485 | goto out; |
1486 | } | |
1487 | ||
1488 | struct compat_arpt_replace { | |
12b00c2c | 1489 | char name[XT_TABLE_MAXNAMELEN]; |
d6a2ba07 PM |
1490 | u32 valid_hooks; |
1491 | u32 num_entries; | |
1492 | u32 size; | |
1493 | u32 hook_entry[NF_ARP_NUMHOOKS]; | |
1494 | u32 underflow[NF_ARP_NUMHOOKS]; | |
1495 | u32 num_counters; | |
1496 | compat_uptr_t counters; | |
1497 | struct compat_arpt_entry entries[0]; | |
1498 | }; | |
1499 | ||
79df341a AD |
1500 | static int compat_do_replace(struct net *net, void __user *user, |
1501 | unsigned int len) | |
d6a2ba07 PM |
1502 | { |
1503 | int ret; | |
1504 | struct compat_arpt_replace tmp; | |
1505 | struct xt_table_info *newinfo; | |
1506 | void *loc_cpu_entry; | |
72b2b1dd | 1507 | struct arpt_entry *iter; |
d6a2ba07 PM |
1508 | |
1509 | if (copy_from_user(&tmp, user, sizeof(tmp)) != 0) | |
1510 | return -EFAULT; | |
1511 | ||
1512 | /* overflow check */ | |
1513 | if (tmp.size >= INT_MAX / num_possible_cpus()) | |
1514 | return -ENOMEM; | |
1515 | if (tmp.num_counters >= INT_MAX / sizeof(struct xt_counters)) | |
1516 | return -ENOMEM; | |
1086bbe9 DJ |
1517 | if (tmp.num_counters == 0) |
1518 | return -EINVAL; | |
1519 | ||
42eab94f | 1520 | tmp.name[sizeof(tmp.name)-1] = 0; |
d6a2ba07 PM |
1521 | |
1522 | newinfo = xt_alloc_table_info(tmp.size); | |
1523 | if (!newinfo) | |
1524 | return -ENOMEM; | |
1525 | ||
482cfc31 | 1526 | loc_cpu_entry = newinfo->entries; |
d6a2ba07 PM |
1527 | if (copy_from_user(loc_cpu_entry, user + sizeof(tmp), tmp.size) != 0) { |
1528 | ret = -EFAULT; | |
1529 | goto free_newinfo; | |
1530 | } | |
1531 | ||
1532 | ret = translate_compat_table(tmp.name, tmp.valid_hooks, | |
1533 | &newinfo, &loc_cpu_entry, tmp.size, | |
1534 | tmp.num_entries, tmp.hook_entry, | |
1535 | tmp.underflow); | |
1536 | if (ret != 0) | |
1537 | goto free_newinfo; | |
1538 | ||
1539 | duprintf("compat_do_replace: Translated table\n"); | |
1540 | ||
79df341a | 1541 | ret = __do_replace(net, tmp.name, tmp.valid_hooks, newinfo, |
d6a2ba07 PM |
1542 | tmp.num_counters, compat_ptr(tmp.counters)); |
1543 | if (ret) | |
1544 | goto free_newinfo_untrans; | |
1545 | return 0; | |
1546 | ||
1547 | free_newinfo_untrans: | |
72b2b1dd | 1548 | xt_entry_foreach(iter, loc_cpu_entry, newinfo->size) |
0559518b | 1549 | cleanup_entry(iter); |
d6a2ba07 PM |
1550 | free_newinfo: |
1551 | xt_free_table_info(newinfo); | |
1552 | return ret; | |
1553 | } | |
1554 | ||
1555 | static int compat_do_arpt_set_ctl(struct sock *sk, int cmd, void __user *user, | |
1556 | unsigned int len) | |
1557 | { | |
1558 | int ret; | |
1559 | ||
52e804c6 | 1560 | if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN)) |
d6a2ba07 PM |
1561 | return -EPERM; |
1562 | ||
1563 | switch (cmd) { | |
1564 | case ARPT_SO_SET_REPLACE: | |
3b1e0a65 | 1565 | ret = compat_do_replace(sock_net(sk), user, len); |
d6a2ba07 PM |
1566 | break; |
1567 | ||
1568 | case ARPT_SO_SET_ADD_COUNTERS: | |
3b1e0a65 | 1569 | ret = do_add_counters(sock_net(sk), user, len, 1); |
d6a2ba07 PM |
1570 | break; |
1571 | ||
1572 | default: | |
1573 | duprintf("do_arpt_set_ctl: unknown request %i\n", cmd); | |
1574 | ret = -EINVAL; | |
1575 | } | |
1576 | ||
1577 | return ret; | |
1578 | } | |
1579 | ||
1580 | static int compat_copy_entry_to_user(struct arpt_entry *e, void __user **dstptr, | |
1581 | compat_uint_t *size, | |
1582 | struct xt_counters *counters, | |
0559518b | 1583 | unsigned int i) |
d6a2ba07 | 1584 | { |
87a2e70d | 1585 | struct xt_entry_target *t; |
d6a2ba07 PM |
1586 | struct compat_arpt_entry __user *ce; |
1587 | u_int16_t target_offset, next_offset; | |
1588 | compat_uint_t origsize; | |
1589 | int ret; | |
1590 | ||
d6a2ba07 PM |
1591 | origsize = *size; |
1592 | ce = (struct compat_arpt_entry __user *)*dstptr; | |
0559518b JE |
1593 | if (copy_to_user(ce, e, sizeof(struct arpt_entry)) != 0 || |
1594 | copy_to_user(&ce->counters, &counters[i], | |
1595 | sizeof(counters[i])) != 0) | |
1596 | return -EFAULT; | |
d6a2ba07 PM |
1597 | |
1598 | *dstptr += sizeof(struct compat_arpt_entry); | |
1599 | *size -= sizeof(struct arpt_entry) - sizeof(struct compat_arpt_entry); | |
1600 | ||
1601 | target_offset = e->target_offset - (origsize - *size); | |
1602 | ||
1603 | t = arpt_get_target(e); | |
1604 | ret = xt_compat_target_to_user(t, dstptr, size); | |
1605 | if (ret) | |
0559518b | 1606 | return ret; |
d6a2ba07 | 1607 | next_offset = e->next_offset - (origsize - *size); |
0559518b JE |
1608 | if (put_user(target_offset, &ce->target_offset) != 0 || |
1609 | put_user(next_offset, &ce->next_offset) != 0) | |
1610 | return -EFAULT; | |
d6a2ba07 | 1611 | return 0; |
d6a2ba07 PM |
1612 | } |
1613 | ||
1614 | static int compat_copy_entries_to_user(unsigned int total_size, | |
4abff077 | 1615 | struct xt_table *table, |
d6a2ba07 PM |
1616 | void __user *userptr) |
1617 | { | |
1618 | struct xt_counters *counters; | |
5452e425 | 1619 | const struct xt_table_info *private = table->private; |
d6a2ba07 PM |
1620 | void __user *pos; |
1621 | unsigned int size; | |
1622 | int ret = 0; | |
d6a2ba07 | 1623 | unsigned int i = 0; |
72b2b1dd | 1624 | struct arpt_entry *iter; |
d6a2ba07 PM |
1625 | |
1626 | counters = alloc_counters(table); | |
1627 | if (IS_ERR(counters)) | |
1628 | return PTR_ERR(counters); | |
1629 | ||
d6a2ba07 PM |
1630 | pos = userptr; |
1631 | size = total_size; | |
482cfc31 | 1632 | xt_entry_foreach(iter, private->entries, total_size) { |
72b2b1dd | 1633 | ret = compat_copy_entry_to_user(iter, &pos, |
6b4ff2d7 | 1634 | &size, counters, i++); |
72b2b1dd JE |
1635 | if (ret != 0) |
1636 | break; | |
1637 | } | |
d6a2ba07 PM |
1638 | vfree(counters); |
1639 | return ret; | |
1640 | } | |
1641 | ||
1642 | struct compat_arpt_get_entries { | |
12b00c2c | 1643 | char name[XT_TABLE_MAXNAMELEN]; |
d6a2ba07 PM |
1644 | compat_uint_t size; |
1645 | struct compat_arpt_entry entrytable[0]; | |
1646 | }; | |
1647 | ||
79df341a AD |
1648 | static int compat_get_entries(struct net *net, |
1649 | struct compat_arpt_get_entries __user *uptr, | |
d6a2ba07 PM |
1650 | int *len) |
1651 | { | |
1652 | int ret; | |
1653 | struct compat_arpt_get_entries get; | |
4abff077 | 1654 | struct xt_table *t; |
d6a2ba07 PM |
1655 | |
1656 | if (*len < sizeof(get)) { | |
1657 | duprintf("compat_get_entries: %u < %zu\n", *len, sizeof(get)); | |
1658 | return -EINVAL; | |
1659 | } | |
1660 | if (copy_from_user(&get, uptr, sizeof(get)) != 0) | |
1661 | return -EFAULT; | |
1662 | if (*len != sizeof(struct compat_arpt_get_entries) + get.size) { | |
1663 | duprintf("compat_get_entries: %u != %zu\n", | |
1664 | *len, sizeof(get) + get.size); | |
1665 | return -EINVAL; | |
1666 | } | |
b301f253 | 1667 | get.name[sizeof(get.name) - 1] = '\0'; |
d6a2ba07 | 1668 | |
ee999d8b JE |
1669 | xt_compat_lock(NFPROTO_ARP); |
1670 | t = xt_find_table_lock(net, NFPROTO_ARP, get.name); | |
0cc8d8df | 1671 | if (!IS_ERR_OR_NULL(t)) { |
5452e425 | 1672 | const struct xt_table_info *private = t->private; |
d6a2ba07 PM |
1673 | struct xt_table_info info; |
1674 | ||
1675 | duprintf("t->private->number = %u\n", private->number); | |
1676 | ret = compat_table_info(private, &info); | |
1677 | if (!ret && get.size == info.size) { | |
1678 | ret = compat_copy_entries_to_user(private->size, | |
1679 | t, uptr->entrytable); | |
1680 | } else if (!ret) { | |
1681 | duprintf("compat_get_entries: I've got %u not %u!\n", | |
1682 | private->size, get.size); | |
544473c1 | 1683 | ret = -EAGAIN; |
d6a2ba07 | 1684 | } |
ee999d8b | 1685 | xt_compat_flush_offsets(NFPROTO_ARP); |
d6a2ba07 PM |
1686 | module_put(t->me); |
1687 | xt_table_unlock(t); | |
1688 | } else | |
1689 | ret = t ? PTR_ERR(t) : -ENOENT; | |
1690 | ||
ee999d8b | 1691 | xt_compat_unlock(NFPROTO_ARP); |
d6a2ba07 PM |
1692 | return ret; |
1693 | } | |
1694 | ||
1695 | static int do_arpt_get_ctl(struct sock *, int, void __user *, int *); | |
1696 | ||
1697 | static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, | |
1698 | int *len) | |
1699 | { | |
1700 | int ret; | |
1701 | ||
52e804c6 | 1702 | if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN)) |
d6a2ba07 PM |
1703 | return -EPERM; |
1704 | ||
1705 | switch (cmd) { | |
1706 | case ARPT_SO_GET_INFO: | |
3b1e0a65 | 1707 | ret = get_info(sock_net(sk), user, len, 1); |
d6a2ba07 PM |
1708 | break; |
1709 | case ARPT_SO_GET_ENTRIES: | |
3b1e0a65 | 1710 | ret = compat_get_entries(sock_net(sk), user, len); |
d6a2ba07 PM |
1711 | break; |
1712 | default: | |
1713 | ret = do_arpt_get_ctl(sk, cmd, user, len); | |
1714 | } | |
1715 | return ret; | |
1716 | } | |
1717 | #endif | |
1718 | ||
1da177e4 LT |
1719 | static int do_arpt_set_ctl(struct sock *sk, int cmd, void __user *user, unsigned int len) |
1720 | { | |
1721 | int ret; | |
1722 | ||
52e804c6 | 1723 | if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN)) |
1da177e4 LT |
1724 | return -EPERM; |
1725 | ||
1726 | switch (cmd) { | |
1727 | case ARPT_SO_SET_REPLACE: | |
3b1e0a65 | 1728 | ret = do_replace(sock_net(sk), user, len); |
1da177e4 LT |
1729 | break; |
1730 | ||
1731 | case ARPT_SO_SET_ADD_COUNTERS: | |
3b1e0a65 | 1732 | ret = do_add_counters(sock_net(sk), user, len, 0); |
1da177e4 LT |
1733 | break; |
1734 | ||
1735 | default: | |
1736 | duprintf("do_arpt_set_ctl: unknown request %i\n", cmd); | |
1737 | ret = -EINVAL; | |
1738 | } | |
1739 | ||
1740 | return ret; | |
1741 | } | |
1742 | ||
1743 | static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len) | |
1744 | { | |
1745 | int ret; | |
1746 | ||
52e804c6 | 1747 | if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN)) |
1da177e4 LT |
1748 | return -EPERM; |
1749 | ||
1750 | switch (cmd) { | |
41acd975 | 1751 | case ARPT_SO_GET_INFO: |
3b1e0a65 | 1752 | ret = get_info(sock_net(sk), user, len, 0); |
41acd975 | 1753 | break; |
1da177e4 | 1754 | |
11f6dff8 | 1755 | case ARPT_SO_GET_ENTRIES: |
3b1e0a65 | 1756 | ret = get_entries(sock_net(sk), user, len); |
1da177e4 | 1757 | break; |
1da177e4 | 1758 | |
6b7d31fc | 1759 | case ARPT_SO_GET_REVISION_TARGET: { |
2e4e6a17 | 1760 | struct xt_get_revision rev; |
6b7d31fc HW |
1761 | |
1762 | if (*len != sizeof(rev)) { | |
1763 | ret = -EINVAL; | |
1764 | break; | |
1765 | } | |
1766 | if (copy_from_user(&rev, user, sizeof(rev)) != 0) { | |
1767 | ret = -EFAULT; | |
1768 | break; | |
1769 | } | |
42eab94f | 1770 | rev.name[sizeof(rev.name)-1] = 0; |
6b7d31fc | 1771 | |
ee999d8b | 1772 | try_then_request_module(xt_find_revision(NFPROTO_ARP, rev.name, |
2e4e6a17 | 1773 | rev.revision, 1, &ret), |
6b7d31fc HW |
1774 | "arpt_%s", rev.name); |
1775 | break; | |
1776 | } | |
1777 | ||
1da177e4 LT |
1778 | default: |
1779 | duprintf("do_arpt_get_ctl: unknown request %i\n", cmd); | |
1780 | ret = -EINVAL; | |
1781 | } | |
1782 | ||
1783 | return ret; | |
1784 | } | |
1785 | ||
b9e69e12 FW |
1786 | static void __arpt_unregister_table(struct xt_table *table) |
1787 | { | |
1788 | struct xt_table_info *private; | |
1789 | void *loc_cpu_entry; | |
1790 | struct module *table_owner = table->me; | |
1791 | struct arpt_entry *iter; | |
1792 | ||
1793 | private = xt_unregister_table(table); | |
1794 | ||
1795 | /* Decrease module usage counts and free resources */ | |
1796 | loc_cpu_entry = private->entries; | |
1797 | xt_entry_foreach(iter, loc_cpu_entry, private->size) | |
1798 | cleanup_entry(iter); | |
1799 | if (private->number > private->initial_entries) | |
1800 | module_put(table_owner); | |
1801 | xt_free_table_info(private); | |
1802 | } | |
1803 | ||
a67dd266 FW |
1804 | int arpt_register_table(struct net *net, |
1805 | const struct xt_table *table, | |
1806 | const struct arpt_replace *repl, | |
1807 | const struct nf_hook_ops *ops, | |
1808 | struct xt_table **res) | |
1da177e4 LT |
1809 | { |
1810 | int ret; | |
2e4e6a17 | 1811 | struct xt_table_info *newinfo; |
f3c5c1bf | 1812 | struct xt_table_info bootstrap = {0}; |
31836064 | 1813 | void *loc_cpu_entry; |
a98da11d | 1814 | struct xt_table *new_table; |
1da177e4 | 1815 | |
2e4e6a17 | 1816 | newinfo = xt_alloc_table_info(repl->size); |
a67dd266 FW |
1817 | if (!newinfo) |
1818 | return -ENOMEM; | |
31836064 | 1819 | |
482cfc31 | 1820 | loc_cpu_entry = newinfo->entries; |
31836064 | 1821 | memcpy(loc_cpu_entry, repl->entries, repl->size); |
1da177e4 | 1822 | |
0f234214 | 1823 | ret = translate_table(newinfo, loc_cpu_entry, repl); |
1da177e4 | 1824 | duprintf("arpt_register_table: translate table gives %d\n", ret); |
44d34e72 AD |
1825 | if (ret != 0) |
1826 | goto out_free; | |
1da177e4 | 1827 | |
79df341a | 1828 | new_table = xt_register_table(net, table, &bootstrap, newinfo); |
a98da11d | 1829 | if (IS_ERR(new_table)) { |
44d34e72 AD |
1830 | ret = PTR_ERR(new_table); |
1831 | goto out_free; | |
1da177e4 | 1832 | } |
a67dd266 | 1833 | |
b9e69e12 | 1834 | /* set res now, will see skbs right after nf_register_net_hooks */ |
a67dd266 FW |
1835 | WRITE_ONCE(*res, new_table); |
1836 | ||
b9e69e12 FW |
1837 | ret = nf_register_net_hooks(net, ops, hweight32(table->valid_hooks)); |
1838 | if (ret != 0) { | |
1839 | __arpt_unregister_table(new_table); | |
1840 | *res = NULL; | |
1841 | } | |
1842 | ||
a67dd266 | 1843 | return ret; |
1da177e4 | 1844 | |
44d34e72 AD |
1845 | out_free: |
1846 | xt_free_table_info(newinfo); | |
a67dd266 | 1847 | return ret; |
1da177e4 LT |
1848 | } |
1849 | ||
a67dd266 FW |
1850 | void arpt_unregister_table(struct net *net, struct xt_table *table, |
1851 | const struct nf_hook_ops *ops) | |
1da177e4 | 1852 | { |
b9e69e12 FW |
1853 | nf_unregister_net_hooks(net, ops, hweight32(table->valid_hooks)); |
1854 | __arpt_unregister_table(table); | |
1da177e4 LT |
1855 | } |
1856 | ||
1857 | /* The built-in targets: standard (NULL) and error. */ | |
4538506b JE |
1858 | static struct xt_target arpt_builtin_tg[] __read_mostly = { |
1859 | { | |
243bf6e2 | 1860 | .name = XT_STANDARD_TARGET, |
4538506b JE |
1861 | .targetsize = sizeof(int), |
1862 | .family = NFPROTO_ARP, | |
d6a2ba07 | 1863 | #ifdef CONFIG_COMPAT |
4538506b JE |
1864 | .compatsize = sizeof(compat_int_t), |
1865 | .compat_from_user = compat_standard_from_user, | |
1866 | .compat_to_user = compat_standard_to_user, | |
d6a2ba07 | 1867 | #endif |
4538506b JE |
1868 | }, |
1869 | { | |
243bf6e2 | 1870 | .name = XT_ERROR_TARGET, |
4538506b | 1871 | .target = arpt_error, |
12b00c2c | 1872 | .targetsize = XT_FUNCTION_MAXNAMELEN, |
4538506b JE |
1873 | .family = NFPROTO_ARP, |
1874 | }, | |
1da177e4 LT |
1875 | }; |
1876 | ||
1877 | static struct nf_sockopt_ops arpt_sockopts = { | |
1878 | .pf = PF_INET, | |
1879 | .set_optmin = ARPT_BASE_CTL, | |
1880 | .set_optmax = ARPT_SO_SET_MAX+1, | |
1881 | .set = do_arpt_set_ctl, | |
d6a2ba07 PM |
1882 | #ifdef CONFIG_COMPAT |
1883 | .compat_set = compat_do_arpt_set_ctl, | |
1884 | #endif | |
1da177e4 LT |
1885 | .get_optmin = ARPT_BASE_CTL, |
1886 | .get_optmax = ARPT_SO_GET_MAX+1, | |
1887 | .get = do_arpt_get_ctl, | |
d6a2ba07 PM |
1888 | #ifdef CONFIG_COMPAT |
1889 | .compat_get = compat_do_arpt_get_ctl, | |
1890 | #endif | |
16fcec35 | 1891 | .owner = THIS_MODULE, |
1da177e4 LT |
1892 | }; |
1893 | ||
3cb609d5 AD |
1894 | static int __net_init arp_tables_net_init(struct net *net) |
1895 | { | |
ee999d8b | 1896 | return xt_proto_init(net, NFPROTO_ARP); |
3cb609d5 AD |
1897 | } |
1898 | ||
1899 | static void __net_exit arp_tables_net_exit(struct net *net) | |
1900 | { | |
ee999d8b | 1901 | xt_proto_fini(net, NFPROTO_ARP); |
3cb609d5 AD |
1902 | } |
1903 | ||
1904 | static struct pernet_operations arp_tables_net_ops = { | |
1905 | .init = arp_tables_net_init, | |
1906 | .exit = arp_tables_net_exit, | |
1907 | }; | |
1908 | ||
65b4b4e8 | 1909 | static int __init arp_tables_init(void) |
1da177e4 LT |
1910 | { |
1911 | int ret; | |
1912 | ||
3cb609d5 | 1913 | ret = register_pernet_subsys(&arp_tables_net_ops); |
0eff66e6 PM |
1914 | if (ret < 0) |
1915 | goto err1; | |
2e4e6a17 | 1916 | |
25985edc | 1917 | /* No one else will be downing sem now, so we won't sleep */ |
4538506b | 1918 | ret = xt_register_targets(arpt_builtin_tg, ARRAY_SIZE(arpt_builtin_tg)); |
0eff66e6 PM |
1919 | if (ret < 0) |
1920 | goto err2; | |
1da177e4 LT |
1921 | |
1922 | /* Register setsockopt */ | |
1923 | ret = nf_register_sockopt(&arpt_sockopts); | |
0eff66e6 PM |
1924 | if (ret < 0) |
1925 | goto err4; | |
1da177e4 | 1926 | |
09605cc1 | 1927 | pr_info("arp_tables: (C) 2002 David S. Miller\n"); |
1da177e4 | 1928 | return 0; |
0eff66e6 PM |
1929 | |
1930 | err4: | |
4538506b | 1931 | xt_unregister_targets(arpt_builtin_tg, ARRAY_SIZE(arpt_builtin_tg)); |
0eff66e6 | 1932 | err2: |
3cb609d5 | 1933 | unregister_pernet_subsys(&arp_tables_net_ops); |
0eff66e6 PM |
1934 | err1: |
1935 | return ret; | |
1da177e4 LT |
1936 | } |
1937 | ||
65b4b4e8 | 1938 | static void __exit arp_tables_fini(void) |
1da177e4 LT |
1939 | { |
1940 | nf_unregister_sockopt(&arpt_sockopts); | |
4538506b | 1941 | xt_unregister_targets(arpt_builtin_tg, ARRAY_SIZE(arpt_builtin_tg)); |
3cb609d5 | 1942 | unregister_pernet_subsys(&arp_tables_net_ops); |
1da177e4 LT |
1943 | } |
1944 | ||
1945 | EXPORT_SYMBOL(arpt_register_table); | |
1946 | EXPORT_SYMBOL(arpt_unregister_table); | |
1947 | EXPORT_SYMBOL(arpt_do_table); | |
1da177e4 | 1948 | |
65b4b4e8 AM |
1949 | module_init(arp_tables_init); |
1950 | module_exit(arp_tables_fini); |