]>
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); |
f24e230d FW |
442 | if (pos + size >= newinfo->size) |
443 | return 0; | |
1da177e4 LT |
444 | e->counters.pcnt = pos; |
445 | pos += size; | |
446 | } else { | |
447 | int newpos = t->verdict; | |
448 | ||
449 | if (strcmp(t->target.u.user.name, | |
243bf6e2 | 450 | XT_STANDARD_TARGET) == 0 && |
3666ed1c | 451 | newpos >= 0) { |
74c9c0c1 DM |
452 | if (newpos > newinfo->size - |
453 | sizeof(struct arpt_entry)) { | |
454 | duprintf("mark_source_chains: " | |
455 | "bad verdict (%i)\n", | |
456 | newpos); | |
457 | return 0; | |
458 | } | |
459 | ||
1da177e4 LT |
460 | /* This a jump; chase it. */ |
461 | duprintf("Jump rule %u -> %u\n", | |
462 | pos, newpos); | |
463 | } else { | |
464 | /* ... this is a fallthru */ | |
465 | newpos = pos + e->next_offset; | |
f24e230d FW |
466 | if (newpos >= newinfo->size) |
467 | return 0; | |
1da177e4 LT |
468 | } |
469 | e = (struct arpt_entry *) | |
31836064 | 470 | (entry0 + newpos); |
1da177e4 LT |
471 | e->counters.pcnt = pos; |
472 | pos = newpos; | |
473 | } | |
474 | } | |
19f0a602 | 475 | next: |
1da177e4 LT |
476 | duprintf("Finished chain %u\n", hook); |
477 | } | |
478 | return 1; | |
479 | } | |
480 | ||
bdf533de | 481 | static inline int check_entry(const struct arpt_entry *e) |
1da177e4 | 482 | { |
87a2e70d | 483 | const struct xt_entry_target *t; |
1da177e4 | 484 | |
bdf533de | 485 | if (!arp_checkentry(&e->arp)) |
1da177e4 | 486 | return -EINVAL; |
1da177e4 | 487 | |
87a2e70d | 488 | if (e->target_offset + sizeof(struct xt_entry_target) > e->next_offset) |
590bdf7f DM |
489 | return -EINVAL; |
490 | ||
d5d1baa1 | 491 | t = arpt_get_target_c(e); |
590bdf7f DM |
492 | if (e->target_offset + t->u.target_size > e->next_offset) |
493 | return -EINVAL; | |
494 | ||
fb5b6095 PM |
495 | return 0; |
496 | } | |
497 | ||
498 | static inline int check_target(struct arpt_entry *e, const char *name) | |
499 | { | |
87a2e70d | 500 | struct xt_entry_target *t = arpt_get_target(e); |
fb5b6095 | 501 | int ret; |
af5d6dc2 JE |
502 | struct xt_tgchk_param par = { |
503 | .table = name, | |
504 | .entryinfo = e, | |
505 | .target = t->u.kernel.target, | |
506 | .targinfo = t->data, | |
507 | .hook_mask = e->comefrom, | |
916a917d | 508 | .family = NFPROTO_ARP, |
af5d6dc2 JE |
509 | }; |
510 | ||
916a917d | 511 | ret = xt_check_target(&par, t->u.target_size - sizeof(*t), 0, false); |
367c6790 | 512 | if (ret < 0) { |
fb5b6095 PM |
513 | duprintf("arp_tables: check failed for `%s'.\n", |
514 | t->u.kernel.target->name); | |
367c6790 | 515 | return ret; |
fb5b6095 | 516 | } |
367c6790 | 517 | return 0; |
fb5b6095 PM |
518 | } |
519 | ||
520 | static inline int | |
0559518b | 521 | find_check_entry(struct arpt_entry *e, const char *name, unsigned int size) |
fb5b6095 | 522 | { |
87a2e70d | 523 | struct xt_entry_target *t; |
95eea855 | 524 | struct xt_target *target; |
fb5b6095 PM |
525 | int ret; |
526 | ||
71ae0dff FW |
527 | e->counters.pcnt = xt_percpu_counter_alloc(); |
528 | if (IS_ERR_VALUE(e->counters.pcnt)) | |
529 | return -ENOMEM; | |
530 | ||
fb5b6095 | 531 | t = arpt_get_target(e); |
d2a7b6ba JE |
532 | target = xt_request_find_target(NFPROTO_ARP, t->u.user.name, |
533 | t->u.user.revision); | |
534 | if (IS_ERR(target)) { | |
fb5b6095 | 535 | duprintf("find_check_entry: `%s' not found\n", t->u.user.name); |
d2a7b6ba | 536 | ret = PTR_ERR(target); |
1da177e4 LT |
537 | goto out; |
538 | } | |
1da177e4 | 539 | t->u.kernel.target = target; |
1da177e4 | 540 | |
fb5b6095 | 541 | ret = check_target(e, name); |
3cdc7c95 PM |
542 | if (ret) |
543 | goto err; | |
1da177e4 | 544 | return 0; |
3cdc7c95 PM |
545 | err: |
546 | module_put(t->u.kernel.target->me); | |
1da177e4 | 547 | out: |
71ae0dff FW |
548 | xt_percpu_counter_free(e->counters.pcnt); |
549 | ||
1da177e4 LT |
550 | return ret; |
551 | } | |
552 | ||
d5d1baa1 | 553 | static bool check_underflow(const struct arpt_entry *e) |
e2fe35c1 | 554 | { |
87a2e70d | 555 | const struct xt_entry_target *t; |
e2fe35c1 JE |
556 | unsigned int verdict; |
557 | ||
54d83fc7 | 558 | if (!unconditional(e)) |
e2fe35c1 | 559 | return false; |
d5d1baa1 | 560 | t = arpt_get_target_c(e); |
e2fe35c1 JE |
561 | if (strcmp(t->u.user.name, XT_STANDARD_TARGET) != 0) |
562 | return false; | |
87a2e70d | 563 | verdict = ((struct xt_standard_target *)t)->verdict; |
e2fe35c1 JE |
564 | verdict = -verdict - 1; |
565 | return verdict == NF_DROP || verdict == NF_ACCEPT; | |
566 | } | |
567 | ||
1da177e4 | 568 | static inline int check_entry_size_and_hooks(struct arpt_entry *e, |
2e4e6a17 | 569 | struct xt_table_info *newinfo, |
d5d1baa1 JE |
570 | const unsigned char *base, |
571 | const unsigned char *limit, | |
1da177e4 LT |
572 | const unsigned int *hook_entries, |
573 | const unsigned int *underflows, | |
0559518b | 574 | unsigned int valid_hooks) |
1da177e4 LT |
575 | { |
576 | unsigned int h; | |
bdf533de | 577 | int err; |
1da177e4 | 578 | |
3666ed1c | 579 | if ((unsigned long)e % __alignof__(struct arpt_entry) != 0 || |
6e94e0cf FW |
580 | (unsigned char *)e + sizeof(struct arpt_entry) >= limit || |
581 | (unsigned char *)e + e->next_offset > limit) { | |
1da177e4 LT |
582 | duprintf("Bad offset %p\n", e); |
583 | return -EINVAL; | |
584 | } | |
585 | ||
586 | if (e->next_offset | |
87a2e70d | 587 | < sizeof(struct arpt_entry) + sizeof(struct xt_entry_target)) { |
1da177e4 LT |
588 | duprintf("checking: element %p size %u\n", |
589 | e, e->next_offset); | |
590 | return -EINVAL; | |
591 | } | |
592 | ||
bdf533de FW |
593 | err = check_entry(e); |
594 | if (err) | |
595 | return err; | |
596 | ||
1da177e4 LT |
597 | /* Check hooks & underflows */ |
598 | for (h = 0; h < NF_ARP_NUMHOOKS; h++) { | |
a7d51738 JE |
599 | if (!(valid_hooks & (1 << h))) |
600 | continue; | |
1da177e4 LT |
601 | if ((unsigned char *)e - base == hook_entries[h]) |
602 | newinfo->hook_entry[h] = hook_entries[h]; | |
90e7d4ab | 603 | if ((unsigned char *)e - base == underflows[h]) { |
e2fe35c1 | 604 | if (!check_underflow(e)) { |
54d83fc7 FW |
605 | pr_debug("Underflows must be unconditional and " |
606 | "use the STANDARD target with " | |
607 | "ACCEPT/DROP\n"); | |
90e7d4ab JE |
608 | return -EINVAL; |
609 | } | |
1da177e4 | 610 | newinfo->underflow[h] = underflows[h]; |
90e7d4ab | 611 | } |
1da177e4 LT |
612 | } |
613 | ||
1da177e4 | 614 | /* Clear counters and comefrom */ |
2e4e6a17 | 615 | e->counters = ((struct xt_counters) { 0, 0 }); |
1da177e4 | 616 | e->comefrom = 0; |
1da177e4 LT |
617 | return 0; |
618 | } | |
619 | ||
0559518b | 620 | static inline void cleanup_entry(struct arpt_entry *e) |
1da177e4 | 621 | { |
a2df1648 | 622 | struct xt_tgdtor_param par; |
87a2e70d | 623 | struct xt_entry_target *t; |
1da177e4 | 624 | |
1da177e4 | 625 | t = arpt_get_target(e); |
a2df1648 JE |
626 | par.target = t->u.kernel.target; |
627 | par.targinfo = t->data; | |
916a917d | 628 | par.family = NFPROTO_ARP; |
a2df1648 JE |
629 | if (par.target->destroy != NULL) |
630 | par.target->destroy(&par); | |
631 | module_put(par.target->me); | |
71ae0dff | 632 | xt_percpu_counter_free(e->counters.pcnt); |
1da177e4 LT |
633 | } |
634 | ||
635 | /* Checks and translates the user-supplied table segment (held in | |
636 | * newinfo). | |
637 | */ | |
0f234214 | 638 | static int translate_table(struct xt_table_info *newinfo, void *entry0, |
6c28255b | 639 | const struct arpt_replace *repl) |
1da177e4 | 640 | { |
72b2b1dd | 641 | struct arpt_entry *iter; |
1da177e4 | 642 | unsigned int i; |
72b2b1dd | 643 | int ret = 0; |
1da177e4 | 644 | |
0f234214 JE |
645 | newinfo->size = repl->size; |
646 | newinfo->number = repl->num_entries; | |
1da177e4 LT |
647 | |
648 | /* Init all hooks to impossible value. */ | |
649 | for (i = 0; i < NF_ARP_NUMHOOKS; i++) { | |
650 | newinfo->hook_entry[i] = 0xFFFFFFFF; | |
651 | newinfo->underflow[i] = 0xFFFFFFFF; | |
652 | } | |
653 | ||
654 | duprintf("translate_table: size %u\n", newinfo->size); | |
655 | i = 0; | |
656 | ||
657 | /* Walk through entries, checking offsets. */ | |
72b2b1dd JE |
658 | xt_entry_foreach(iter, entry0, newinfo->size) { |
659 | ret = check_entry_size_and_hooks(iter, newinfo, entry0, | |
6b4ff2d7 JE |
660 | entry0 + repl->size, |
661 | repl->hook_entry, | |
662 | repl->underflow, | |
663 | repl->valid_hooks); | |
72b2b1dd JE |
664 | if (ret != 0) |
665 | break; | |
0559518b | 666 | ++i; |
98dbbfc3 FW |
667 | if (strcmp(arpt_get_target(iter)->u.user.name, |
668 | XT_ERROR_TARGET) == 0) | |
669 | ++newinfo->stacksize; | |
72b2b1dd | 670 | } |
1da177e4 LT |
671 | duprintf("translate_table: ARPT_ENTRY_ITERATE gives %d\n", ret); |
672 | if (ret != 0) | |
673 | return ret; | |
674 | ||
0f234214 | 675 | if (i != repl->num_entries) { |
1da177e4 | 676 | duprintf("translate_table: %u not %u entries\n", |
0f234214 | 677 | i, repl->num_entries); |
1da177e4 LT |
678 | return -EINVAL; |
679 | } | |
680 | ||
681 | /* Check hooks all assigned */ | |
682 | for (i = 0; i < NF_ARP_NUMHOOKS; i++) { | |
683 | /* Only hooks which are valid */ | |
0f234214 | 684 | if (!(repl->valid_hooks & (1 << i))) |
1da177e4 LT |
685 | continue; |
686 | if (newinfo->hook_entry[i] == 0xFFFFFFFF) { | |
687 | duprintf("Invalid hook entry %u %u\n", | |
0f234214 | 688 | i, repl->hook_entry[i]); |
1da177e4 LT |
689 | return -EINVAL; |
690 | } | |
691 | if (newinfo->underflow[i] == 0xFFFFFFFF) { | |
692 | duprintf("Invalid underflow %u %u\n", | |
0f234214 | 693 | i, repl->underflow[i]); |
1da177e4 LT |
694 | return -EINVAL; |
695 | } | |
696 | } | |
697 | ||
f24e230d | 698 | if (!mark_source_chains(newinfo, repl->valid_hooks, entry0)) |
74c9c0c1 | 699 | return -ELOOP; |
74c9c0c1 | 700 | |
1da177e4 LT |
701 | /* Finally, each sanity check must pass */ |
702 | i = 0; | |
72b2b1dd | 703 | xt_entry_foreach(iter, entry0, newinfo->size) { |
0f234214 | 704 | ret = find_check_entry(iter, repl->name, repl->size); |
72b2b1dd JE |
705 | if (ret != 0) |
706 | break; | |
0559518b | 707 | ++i; |
72b2b1dd | 708 | } |
1da177e4 | 709 | |
74c9c0c1 | 710 | if (ret != 0) { |
0559518b JE |
711 | xt_entry_foreach(iter, entry0, newinfo->size) { |
712 | if (i-- == 0) | |
72b2b1dd | 713 | break; |
0559518b JE |
714 | cleanup_entry(iter); |
715 | } | |
74c9c0c1 | 716 | return ret; |
1da177e4 LT |
717 | } |
718 | ||
1da177e4 LT |
719 | return ret; |
720 | } | |
721 | ||
2e4e6a17 HW |
722 | static void get_counters(const struct xt_table_info *t, |
723 | struct xt_counters counters[]) | |
1da177e4 | 724 | { |
72b2b1dd | 725 | struct arpt_entry *iter; |
1da177e4 LT |
726 | unsigned int cpu; |
727 | unsigned int i; | |
728 | ||
6f912042 | 729 | for_each_possible_cpu(cpu) { |
7f5c6d4f | 730 | seqcount_t *s = &per_cpu(xt_recseq, cpu); |
83723d60 | 731 | |
1da177e4 | 732 | i = 0; |
482cfc31 | 733 | xt_entry_foreach(iter, t->entries, t->size) { |
71ae0dff | 734 | struct xt_counters *tmp; |
83723d60 ED |
735 | u64 bcnt, pcnt; |
736 | unsigned int start; | |
737 | ||
71ae0dff | 738 | tmp = xt_get_per_cpu_counter(&iter->counters, cpu); |
83723d60 | 739 | do { |
7f5c6d4f | 740 | start = read_seqcount_begin(s); |
71ae0dff FW |
741 | bcnt = tmp->bcnt; |
742 | pcnt = tmp->pcnt; | |
7f5c6d4f | 743 | } while (read_seqcount_retry(s, start)); |
83723d60 ED |
744 | |
745 | ADD_COUNTER(counters[i], bcnt, pcnt); | |
0559518b JE |
746 | ++i; |
747 | } | |
1da177e4 | 748 | } |
78454473 SH |
749 | } |
750 | ||
d5d1baa1 | 751 | static struct xt_counters *alloc_counters(const struct xt_table *table) |
1da177e4 | 752 | { |
27e2c26b | 753 | unsigned int countersize; |
2e4e6a17 | 754 | struct xt_counters *counters; |
d5d1baa1 | 755 | const struct xt_table_info *private = table->private; |
1da177e4 LT |
756 | |
757 | /* We need atomic snapshot of counters: rest doesn't change | |
758 | * (other than comefrom, which userspace doesn't care | |
759 | * about). | |
760 | */ | |
2e4e6a17 | 761 | countersize = sizeof(struct xt_counters) * private->number; |
83723d60 | 762 | counters = vzalloc(countersize); |
1da177e4 LT |
763 | |
764 | if (counters == NULL) | |
942e4a2b | 765 | return ERR_PTR(-ENOMEM); |
78454473 | 766 | |
942e4a2b | 767 | get_counters(private, counters); |
1da177e4 | 768 | |
27e2c26b PM |
769 | return counters; |
770 | } | |
771 | ||
772 | static int copy_entries_to_user(unsigned int total_size, | |
d5d1baa1 | 773 | const struct xt_table *table, |
27e2c26b PM |
774 | void __user *userptr) |
775 | { | |
776 | unsigned int off, num; | |
d5d1baa1 | 777 | const struct arpt_entry *e; |
27e2c26b | 778 | struct xt_counters *counters; |
4abff077 | 779 | struct xt_table_info *private = table->private; |
27e2c26b PM |
780 | int ret = 0; |
781 | void *loc_cpu_entry; | |
782 | ||
783 | counters = alloc_counters(table); | |
784 | if (IS_ERR(counters)) | |
785 | return PTR_ERR(counters); | |
786 | ||
482cfc31 | 787 | loc_cpu_entry = private->entries; |
31836064 ED |
788 | /* ... then copy entire thing ... */ |
789 | if (copy_to_user(userptr, loc_cpu_entry, total_size) != 0) { | |
1da177e4 LT |
790 | ret = -EFAULT; |
791 | goto free_counters; | |
792 | } | |
793 | ||
794 | /* FIXME: use iterator macros --RR */ | |
795 | /* ... then go back and fix counters and names */ | |
796 | for (off = 0, num = 0; off < total_size; off += e->next_offset, num++){ | |
87a2e70d | 797 | const struct xt_entry_target *t; |
1da177e4 | 798 | |
31836064 | 799 | e = (struct arpt_entry *)(loc_cpu_entry + off); |
1da177e4 LT |
800 | if (copy_to_user(userptr + off |
801 | + offsetof(struct arpt_entry, counters), | |
802 | &counters[num], | |
803 | sizeof(counters[num])) != 0) { | |
804 | ret = -EFAULT; | |
805 | goto free_counters; | |
806 | } | |
807 | ||
d5d1baa1 | 808 | t = arpt_get_target_c(e); |
1da177e4 | 809 | if (copy_to_user(userptr + off + e->target_offset |
87a2e70d | 810 | + offsetof(struct xt_entry_target, |
1da177e4 LT |
811 | u.user.name), |
812 | t->u.kernel.target->name, | |
813 | strlen(t->u.kernel.target->name)+1) != 0) { | |
814 | ret = -EFAULT; | |
815 | goto free_counters; | |
816 | } | |
817 | } | |
818 | ||
819 | free_counters: | |
820 | vfree(counters); | |
821 | return ret; | |
822 | } | |
823 | ||
d6a2ba07 | 824 | #ifdef CONFIG_COMPAT |
739674fb | 825 | static void compat_standard_from_user(void *dst, const void *src) |
d6a2ba07 PM |
826 | { |
827 | int v = *(compat_int_t *)src; | |
828 | ||
829 | if (v > 0) | |
ee999d8b | 830 | v += xt_compat_calc_jump(NFPROTO_ARP, v); |
d6a2ba07 PM |
831 | memcpy(dst, &v, sizeof(v)); |
832 | } | |
833 | ||
739674fb | 834 | static int compat_standard_to_user(void __user *dst, const void *src) |
d6a2ba07 PM |
835 | { |
836 | compat_int_t cv = *(int *)src; | |
837 | ||
838 | if (cv > 0) | |
ee999d8b | 839 | cv -= xt_compat_calc_jump(NFPROTO_ARP, cv); |
d6a2ba07 PM |
840 | return copy_to_user(dst, &cv, sizeof(cv)) ? -EFAULT : 0; |
841 | } | |
842 | ||
d5d1baa1 | 843 | static int compat_calc_entry(const struct arpt_entry *e, |
d6a2ba07 | 844 | const struct xt_table_info *info, |
d5d1baa1 | 845 | const void *base, struct xt_table_info *newinfo) |
d6a2ba07 | 846 | { |
87a2e70d | 847 | const struct xt_entry_target *t; |
d6a2ba07 PM |
848 | unsigned int entry_offset; |
849 | int off, i, ret; | |
850 | ||
851 | off = sizeof(struct arpt_entry) - sizeof(struct compat_arpt_entry); | |
852 | entry_offset = (void *)e - base; | |
853 | ||
d5d1baa1 | 854 | t = arpt_get_target_c(e); |
d6a2ba07 PM |
855 | off += xt_compat_target_offset(t->u.kernel.target); |
856 | newinfo->size -= off; | |
ee999d8b | 857 | ret = xt_compat_add_offset(NFPROTO_ARP, entry_offset, off); |
d6a2ba07 PM |
858 | if (ret) |
859 | return ret; | |
860 | ||
861 | for (i = 0; i < NF_ARP_NUMHOOKS; i++) { | |
862 | if (info->hook_entry[i] && | |
863 | (e < (struct arpt_entry *)(base + info->hook_entry[i]))) | |
864 | newinfo->hook_entry[i] -= off; | |
865 | if (info->underflow[i] && | |
866 | (e < (struct arpt_entry *)(base + info->underflow[i]))) | |
867 | newinfo->underflow[i] -= off; | |
868 | } | |
869 | return 0; | |
870 | } | |
871 | ||
872 | static int compat_table_info(const struct xt_table_info *info, | |
873 | struct xt_table_info *newinfo) | |
874 | { | |
72b2b1dd | 875 | struct arpt_entry *iter; |
711bdde6 | 876 | const void *loc_cpu_entry; |
0559518b | 877 | int ret; |
d6a2ba07 PM |
878 | |
879 | if (!newinfo || !info) | |
880 | return -EINVAL; | |
881 | ||
482cfc31 | 882 | /* we dont care about newinfo->entries */ |
d6a2ba07 PM |
883 | memcpy(newinfo, info, offsetof(struct xt_table_info, entries)); |
884 | newinfo->initial_entries = 0; | |
482cfc31 | 885 | loc_cpu_entry = info->entries; |
255d0dc3 | 886 | xt_compat_init_offsets(NFPROTO_ARP, info->number); |
72b2b1dd JE |
887 | xt_entry_foreach(iter, loc_cpu_entry, info->size) { |
888 | ret = compat_calc_entry(iter, info, loc_cpu_entry, newinfo); | |
889 | if (ret != 0) | |
0559518b | 890 | return ret; |
72b2b1dd | 891 | } |
0559518b | 892 | return 0; |
d6a2ba07 PM |
893 | } |
894 | #endif | |
895 | ||
d5d1baa1 | 896 | static int get_info(struct net *net, void __user *user, |
6c28255b | 897 | const int *len, int compat) |
41acd975 | 898 | { |
12b00c2c | 899 | char name[XT_TABLE_MAXNAMELEN]; |
4abff077 | 900 | struct xt_table *t; |
41acd975 PM |
901 | int ret; |
902 | ||
903 | if (*len != sizeof(struct arpt_getinfo)) { | |
904 | duprintf("length %u != %Zu\n", *len, | |
905 | sizeof(struct arpt_getinfo)); | |
906 | return -EINVAL; | |
907 | } | |
908 | ||
909 | if (copy_from_user(name, user, sizeof(name)) != 0) | |
910 | return -EFAULT; | |
911 | ||
12b00c2c | 912 | name[XT_TABLE_MAXNAMELEN-1] = '\0'; |
d6a2ba07 PM |
913 | #ifdef CONFIG_COMPAT |
914 | if (compat) | |
ee999d8b | 915 | xt_compat_lock(NFPROTO_ARP); |
d6a2ba07 | 916 | #endif |
ee999d8b | 917 | t = try_then_request_module(xt_find_table_lock(net, NFPROTO_ARP, name), |
41acd975 | 918 | "arptable_%s", name); |
0cc8d8df | 919 | if (!IS_ERR_OR_NULL(t)) { |
41acd975 | 920 | struct arpt_getinfo info; |
5452e425 | 921 | const struct xt_table_info *private = t->private; |
d6a2ba07 | 922 | #ifdef CONFIG_COMPAT |
14c7dbe0 AD |
923 | struct xt_table_info tmp; |
924 | ||
d6a2ba07 | 925 | if (compat) { |
d6a2ba07 | 926 | ret = compat_table_info(private, &tmp); |
ee999d8b | 927 | xt_compat_flush_offsets(NFPROTO_ARP); |
d6a2ba07 PM |
928 | private = &tmp; |
929 | } | |
930 | #endif | |
1a8b7a67 | 931 | memset(&info, 0, sizeof(info)); |
41acd975 PM |
932 | info.valid_hooks = t->valid_hooks; |
933 | memcpy(info.hook_entry, private->hook_entry, | |
934 | sizeof(info.hook_entry)); | |
935 | memcpy(info.underflow, private->underflow, | |
936 | sizeof(info.underflow)); | |
937 | info.num_entries = private->number; | |
938 | info.size = private->size; | |
939 | strcpy(info.name, name); | |
940 | ||
941 | if (copy_to_user(user, &info, *len) != 0) | |
942 | ret = -EFAULT; | |
943 | else | |
944 | ret = 0; | |
945 | xt_table_unlock(t); | |
946 | module_put(t->me); | |
947 | } else | |
948 | ret = t ? PTR_ERR(t) : -ENOENT; | |
d6a2ba07 PM |
949 | #ifdef CONFIG_COMPAT |
950 | if (compat) | |
ee999d8b | 951 | xt_compat_unlock(NFPROTO_ARP); |
d6a2ba07 | 952 | #endif |
41acd975 PM |
953 | return ret; |
954 | } | |
955 | ||
79df341a | 956 | static int get_entries(struct net *net, struct arpt_get_entries __user *uptr, |
d5d1baa1 | 957 | const int *len) |
1da177e4 LT |
958 | { |
959 | int ret; | |
11f6dff8 | 960 | struct arpt_get_entries get; |
4abff077 | 961 | struct xt_table *t; |
1da177e4 | 962 | |
11f6dff8 PM |
963 | if (*len < sizeof(get)) { |
964 | duprintf("get_entries: %u < %Zu\n", *len, sizeof(get)); | |
965 | return -EINVAL; | |
966 | } | |
967 | if (copy_from_user(&get, uptr, sizeof(get)) != 0) | |
968 | return -EFAULT; | |
969 | if (*len != sizeof(struct arpt_get_entries) + get.size) { | |
970 | duprintf("get_entries: %u != %Zu\n", *len, | |
971 | sizeof(struct arpt_get_entries) + get.size); | |
972 | return -EINVAL; | |
973 | } | |
b301f253 | 974 | get.name[sizeof(get.name) - 1] = '\0'; |
11f6dff8 | 975 | |
ee999d8b | 976 | t = xt_find_table_lock(net, NFPROTO_ARP, get.name); |
0cc8d8df | 977 | if (!IS_ERR_OR_NULL(t)) { |
5452e425 JE |
978 | const struct xt_table_info *private = t->private; |
979 | ||
1da177e4 | 980 | duprintf("t->private->number = %u\n", |
2e4e6a17 | 981 | private->number); |
11f6dff8 | 982 | if (get.size == private->size) |
2e4e6a17 | 983 | ret = copy_entries_to_user(private->size, |
1da177e4 LT |
984 | t, uptr->entrytable); |
985 | else { | |
986 | duprintf("get_entries: I've got %u not %u!\n", | |
11f6dff8 | 987 | private->size, get.size); |
544473c1 | 988 | ret = -EAGAIN; |
1da177e4 | 989 | } |
6b7d31fc | 990 | module_put(t->me); |
2e4e6a17 | 991 | xt_table_unlock(t); |
1da177e4 | 992 | } else |
6b7d31fc | 993 | ret = t ? PTR_ERR(t) : -ENOENT; |
1da177e4 LT |
994 | |
995 | return ret; | |
996 | } | |
997 | ||
79df341a AD |
998 | static int __do_replace(struct net *net, const char *name, |
999 | unsigned int valid_hooks, | |
d6a2ba07 PM |
1000 | struct xt_table_info *newinfo, |
1001 | unsigned int num_counters, | |
1002 | void __user *counters_ptr) | |
1da177e4 LT |
1003 | { |
1004 | int ret; | |
4abff077 | 1005 | struct xt_table *t; |
d6a2ba07 | 1006 | struct xt_table_info *oldinfo; |
2e4e6a17 | 1007 | struct xt_counters *counters; |
d6a2ba07 | 1008 | void *loc_cpu_old_entry; |
72b2b1dd | 1009 | struct arpt_entry *iter; |
1da177e4 | 1010 | |
d6a2ba07 | 1011 | ret = 0; |
83723d60 | 1012 | counters = vzalloc(num_counters * sizeof(struct xt_counters)); |
1da177e4 LT |
1013 | if (!counters) { |
1014 | ret = -ENOMEM; | |
d6a2ba07 | 1015 | goto out; |
1da177e4 | 1016 | } |
1da177e4 | 1017 | |
ee999d8b | 1018 | t = try_then_request_module(xt_find_table_lock(net, NFPROTO_ARP, name), |
d6a2ba07 | 1019 | "arptable_%s", name); |
0cc8d8df | 1020 | if (IS_ERR_OR_NULL(t)) { |
6b7d31fc | 1021 | ret = t ? PTR_ERR(t) : -ENOENT; |
1da177e4 | 1022 | goto free_newinfo_counters_untrans; |
6b7d31fc | 1023 | } |
1da177e4 LT |
1024 | |
1025 | /* You lied! */ | |
d6a2ba07 | 1026 | if (valid_hooks != t->valid_hooks) { |
1da177e4 | 1027 | duprintf("Valid hook crap: %08X vs %08X\n", |
d6a2ba07 | 1028 | valid_hooks, t->valid_hooks); |
1da177e4 | 1029 | ret = -EINVAL; |
6b7d31fc | 1030 | goto put_module; |
1da177e4 LT |
1031 | } |
1032 | ||
d6a2ba07 | 1033 | oldinfo = xt_replace_table(t, num_counters, newinfo, &ret); |
1da177e4 LT |
1034 | if (!oldinfo) |
1035 | goto put_module; | |
1036 | ||
1037 | /* Update module usage count based on number of rules */ | |
1038 | duprintf("do_replace: oldnum=%u, initnum=%u, newnum=%u\n", | |
1039 | oldinfo->number, oldinfo->initial_entries, newinfo->number); | |
e905a9ed YH |
1040 | if ((oldinfo->number > oldinfo->initial_entries) || |
1041 | (newinfo->number <= oldinfo->initial_entries)) | |
1da177e4 LT |
1042 | module_put(t->me); |
1043 | if ((oldinfo->number > oldinfo->initial_entries) && | |
1044 | (newinfo->number <= oldinfo->initial_entries)) | |
1045 | module_put(t->me); | |
1046 | ||
942e4a2b | 1047 | /* Get the old counters, and synchronize with replace */ |
1da177e4 | 1048 | get_counters(oldinfo, counters); |
942e4a2b | 1049 | |
1da177e4 | 1050 | /* Decrease module usage counts and free resource */ |
482cfc31 | 1051 | loc_cpu_old_entry = oldinfo->entries; |
72b2b1dd | 1052 | xt_entry_foreach(iter, loc_cpu_old_entry, oldinfo->size) |
0559518b | 1053 | cleanup_entry(iter); |
31836064 | 1054 | |
2e4e6a17 | 1055 | xt_free_table_info(oldinfo); |
d6a2ba07 | 1056 | if (copy_to_user(counters_ptr, counters, |
c58dd2dd TG |
1057 | sizeof(struct xt_counters) * num_counters) != 0) { |
1058 | /* Silent error, can't fail, new table is already in place */ | |
1059 | net_warn_ratelimited("arptables: counters copy to user failed while replacing table\n"); | |
1060 | } | |
1da177e4 | 1061 | vfree(counters); |
2e4e6a17 | 1062 | xt_table_unlock(t); |
1da177e4 LT |
1063 | return ret; |
1064 | ||
1065 | put_module: | |
1066 | module_put(t->me); | |
2e4e6a17 | 1067 | xt_table_unlock(t); |
1da177e4 | 1068 | free_newinfo_counters_untrans: |
1da177e4 | 1069 | vfree(counters); |
d6a2ba07 PM |
1070 | out: |
1071 | return ret; | |
1072 | } | |
1073 | ||
d5d1baa1 | 1074 | static int do_replace(struct net *net, const void __user *user, |
6c28255b | 1075 | unsigned int len) |
d6a2ba07 PM |
1076 | { |
1077 | int ret; | |
1078 | struct arpt_replace tmp; | |
1079 | struct xt_table_info *newinfo; | |
1080 | void *loc_cpu_entry; | |
72b2b1dd | 1081 | struct arpt_entry *iter; |
d6a2ba07 PM |
1082 | |
1083 | if (copy_from_user(&tmp, user, sizeof(tmp)) != 0) | |
1084 | return -EFAULT; | |
1085 | ||
1086 | /* overflow check */ | |
1087 | if (tmp.num_counters >= INT_MAX / sizeof(struct xt_counters)) | |
1088 | return -ENOMEM; | |
1086bbe9 DJ |
1089 | if (tmp.num_counters == 0) |
1090 | return -EINVAL; | |
1091 | ||
42eab94f | 1092 | tmp.name[sizeof(tmp.name)-1] = 0; |
d6a2ba07 PM |
1093 | |
1094 | newinfo = xt_alloc_table_info(tmp.size); | |
1095 | if (!newinfo) | |
1096 | return -ENOMEM; | |
1097 | ||
482cfc31 | 1098 | loc_cpu_entry = newinfo->entries; |
d6a2ba07 PM |
1099 | if (copy_from_user(loc_cpu_entry, user + sizeof(tmp), |
1100 | tmp.size) != 0) { | |
1101 | ret = -EFAULT; | |
1102 | goto free_newinfo; | |
1103 | } | |
1104 | ||
0f234214 | 1105 | ret = translate_table(newinfo, loc_cpu_entry, &tmp); |
d6a2ba07 PM |
1106 | if (ret != 0) |
1107 | goto free_newinfo; | |
1108 | ||
1109 | duprintf("arp_tables: Translated table\n"); | |
1110 | ||
79df341a | 1111 | ret = __do_replace(net, tmp.name, tmp.valid_hooks, newinfo, |
d6a2ba07 PM |
1112 | tmp.num_counters, tmp.counters); |
1113 | if (ret) | |
1114 | goto free_newinfo_untrans; | |
1115 | return 0; | |
1116 | ||
1117 | free_newinfo_untrans: | |
72b2b1dd | 1118 | xt_entry_foreach(iter, loc_cpu_entry, newinfo->size) |
0559518b | 1119 | cleanup_entry(iter); |
1da177e4 | 1120 | free_newinfo: |
2e4e6a17 | 1121 | xt_free_table_info(newinfo); |
1da177e4 LT |
1122 | return ret; |
1123 | } | |
1124 | ||
d5d1baa1 JE |
1125 | static int do_add_counters(struct net *net, const void __user *user, |
1126 | unsigned int len, int compat) | |
1da177e4 | 1127 | { |
482cfc31 | 1128 | unsigned int i; |
d6a2ba07 PM |
1129 | struct xt_counters_info tmp; |
1130 | struct xt_counters *paddc; | |
1131 | unsigned int num_counters; | |
5452e425 | 1132 | const char *name; |
d6a2ba07 PM |
1133 | int size; |
1134 | void *ptmp; | |
4abff077 | 1135 | struct xt_table *t; |
5452e425 | 1136 | const struct xt_table_info *private; |
6b7d31fc | 1137 | int ret = 0; |
72b2b1dd | 1138 | struct arpt_entry *iter; |
7f5c6d4f | 1139 | unsigned int addend; |
d6a2ba07 PM |
1140 | #ifdef CONFIG_COMPAT |
1141 | struct compat_xt_counters_info compat_tmp; | |
1da177e4 | 1142 | |
d6a2ba07 PM |
1143 | if (compat) { |
1144 | ptmp = &compat_tmp; | |
1145 | size = sizeof(struct compat_xt_counters_info); | |
1146 | } else | |
1147 | #endif | |
1148 | { | |
1149 | ptmp = &tmp; | |
1150 | size = sizeof(struct xt_counters_info); | |
1151 | } | |
1152 | ||
1153 | if (copy_from_user(ptmp, user, size) != 0) | |
1da177e4 LT |
1154 | return -EFAULT; |
1155 | ||
d6a2ba07 PM |
1156 | #ifdef CONFIG_COMPAT |
1157 | if (compat) { | |
1158 | num_counters = compat_tmp.num_counters; | |
1159 | name = compat_tmp.name; | |
1160 | } else | |
1161 | #endif | |
1162 | { | |
1163 | num_counters = tmp.num_counters; | |
1164 | name = tmp.name; | |
1165 | } | |
1166 | ||
1167 | if (len != size + num_counters * sizeof(struct xt_counters)) | |
1da177e4 LT |
1168 | return -EINVAL; |
1169 | ||
e12f8e29 | 1170 | paddc = vmalloc(len - size); |
1da177e4 LT |
1171 | if (!paddc) |
1172 | return -ENOMEM; | |
1173 | ||
d6a2ba07 | 1174 | if (copy_from_user(paddc, user + size, len - size) != 0) { |
1da177e4 LT |
1175 | ret = -EFAULT; |
1176 | goto free; | |
1177 | } | |
1178 | ||
ee999d8b | 1179 | t = xt_find_table_lock(net, NFPROTO_ARP, name); |
0cc8d8df | 1180 | if (IS_ERR_OR_NULL(t)) { |
6b7d31fc | 1181 | ret = t ? PTR_ERR(t) : -ENOENT; |
1da177e4 | 1182 | goto free; |
6b7d31fc | 1183 | } |
1da177e4 | 1184 | |
942e4a2b | 1185 | local_bh_disable(); |
2e4e6a17 | 1186 | private = t->private; |
d6a2ba07 | 1187 | if (private->number != num_counters) { |
1da177e4 LT |
1188 | ret = -EINVAL; |
1189 | goto unlock_up_free; | |
1190 | } | |
1191 | ||
1192 | i = 0; | |
482cfc31 | 1193 | |
7f5c6d4f | 1194 | addend = xt_write_recseq_begin(); |
482cfc31 | 1195 | xt_entry_foreach(iter, private->entries, private->size) { |
71ae0dff FW |
1196 | struct xt_counters *tmp; |
1197 | ||
1198 | tmp = xt_get_this_cpu_counter(&iter->counters); | |
1199 | ADD_COUNTER(*tmp, paddc[i].bcnt, paddc[i].pcnt); | |
0559518b JE |
1200 | ++i; |
1201 | } | |
7f5c6d4f | 1202 | xt_write_recseq_end(addend); |
1da177e4 | 1203 | unlock_up_free: |
942e4a2b | 1204 | local_bh_enable(); |
2e4e6a17 | 1205 | xt_table_unlock(t); |
6b7d31fc | 1206 | module_put(t->me); |
1da177e4 LT |
1207 | free: |
1208 | vfree(paddc); | |
1209 | ||
1210 | return ret; | |
1211 | } | |
1212 | ||
d6a2ba07 | 1213 | #ifdef CONFIG_COMPAT |
0559518b | 1214 | static inline void compat_release_entry(struct compat_arpt_entry *e) |
d6a2ba07 | 1215 | { |
87a2e70d | 1216 | struct xt_entry_target *t; |
d6a2ba07 | 1217 | |
d6a2ba07 PM |
1218 | t = compat_arpt_get_target(e); |
1219 | module_put(t->u.kernel.target->me); | |
d6a2ba07 PM |
1220 | } |
1221 | ||
1222 | static inline int | |
1223 | check_compat_entry_size_and_hooks(struct compat_arpt_entry *e, | |
1224 | struct xt_table_info *newinfo, | |
1225 | unsigned int *size, | |
d5d1baa1 JE |
1226 | const unsigned char *base, |
1227 | const unsigned char *limit, | |
1228 | const unsigned int *hook_entries, | |
1229 | const unsigned int *underflows, | |
d6a2ba07 PM |
1230 | const char *name) |
1231 | { | |
87a2e70d | 1232 | struct xt_entry_target *t; |
d6a2ba07 PM |
1233 | struct xt_target *target; |
1234 | unsigned int entry_offset; | |
1235 | int ret, off, h; | |
1236 | ||
1237 | duprintf("check_compat_entry_size_and_hooks %p\n", e); | |
3666ed1c | 1238 | if ((unsigned long)e % __alignof__(struct compat_arpt_entry) != 0 || |
6e94e0cf FW |
1239 | (unsigned char *)e + sizeof(struct compat_arpt_entry) >= limit || |
1240 | (unsigned char *)e + e->next_offset > limit) { | |
d6a2ba07 PM |
1241 | duprintf("Bad offset %p, limit = %p\n", e, limit); |
1242 | return -EINVAL; | |
1243 | } | |
1244 | ||
1245 | if (e->next_offset < sizeof(struct compat_arpt_entry) + | |
1246 | sizeof(struct compat_xt_entry_target)) { | |
1247 | duprintf("checking: element %p size %u\n", | |
1248 | e, e->next_offset); | |
1249 | return -EINVAL; | |
1250 | } | |
1251 | ||
1252 | /* For purposes of check_entry casting the compat entry is fine */ | |
bdf533de | 1253 | ret = check_entry((struct arpt_entry *)e); |
d6a2ba07 PM |
1254 | if (ret) |
1255 | return ret; | |
1256 | ||
1257 | off = sizeof(struct arpt_entry) - sizeof(struct compat_arpt_entry); | |
1258 | entry_offset = (void *)e - (void *)base; | |
1259 | ||
1260 | t = compat_arpt_get_target(e); | |
d2a7b6ba JE |
1261 | target = xt_request_find_target(NFPROTO_ARP, t->u.user.name, |
1262 | t->u.user.revision); | |
1263 | if (IS_ERR(target)) { | |
d6a2ba07 PM |
1264 | duprintf("check_compat_entry_size_and_hooks: `%s' not found\n", |
1265 | t->u.user.name); | |
d2a7b6ba | 1266 | ret = PTR_ERR(target); |
d6a2ba07 PM |
1267 | goto out; |
1268 | } | |
1269 | t->u.kernel.target = target; | |
1270 | ||
1271 | off += xt_compat_target_offset(target); | |
1272 | *size += off; | |
ee999d8b | 1273 | ret = xt_compat_add_offset(NFPROTO_ARP, entry_offset, off); |
d6a2ba07 PM |
1274 | if (ret) |
1275 | goto release_target; | |
1276 | ||
1277 | /* Check hooks & underflows */ | |
1278 | for (h = 0; h < NF_ARP_NUMHOOKS; h++) { | |
1279 | if ((unsigned char *)e - base == hook_entries[h]) | |
1280 | newinfo->hook_entry[h] = hook_entries[h]; | |
1281 | if ((unsigned char *)e - base == underflows[h]) | |
1282 | newinfo->underflow[h] = underflows[h]; | |
1283 | } | |
1284 | ||
1285 | /* Clear counters and comefrom */ | |
1286 | memset(&e->counters, 0, sizeof(e->counters)); | |
1287 | e->comefrom = 0; | |
d6a2ba07 PM |
1288 | return 0; |
1289 | ||
1290 | release_target: | |
1291 | module_put(t->u.kernel.target->me); | |
1292 | out: | |
1293 | return ret; | |
1294 | } | |
1295 | ||
1296 | static int | |
1297 | compat_copy_entry_from_user(struct compat_arpt_entry *e, void **dstptr, | |
1298 | unsigned int *size, const char *name, | |
1299 | struct xt_table_info *newinfo, unsigned char *base) | |
1300 | { | |
87a2e70d | 1301 | struct xt_entry_target *t; |
d6a2ba07 PM |
1302 | struct xt_target *target; |
1303 | struct arpt_entry *de; | |
1304 | unsigned int origsize; | |
1305 | int ret, h; | |
1306 | ||
1307 | ret = 0; | |
1308 | origsize = *size; | |
1309 | de = (struct arpt_entry *)*dstptr; | |
1310 | memcpy(de, e, sizeof(struct arpt_entry)); | |
1311 | memcpy(&de->counters, &e->counters, sizeof(e->counters)); | |
1312 | ||
1313 | *dstptr += sizeof(struct arpt_entry); | |
1314 | *size += sizeof(struct arpt_entry) - sizeof(struct compat_arpt_entry); | |
1315 | ||
1316 | de->target_offset = e->target_offset - (origsize - *size); | |
1317 | t = compat_arpt_get_target(e); | |
1318 | target = t->u.kernel.target; | |
1319 | xt_compat_target_from_user(t, dstptr, size); | |
1320 | ||
1321 | de->next_offset = e->next_offset - (origsize - *size); | |
1322 | for (h = 0; h < NF_ARP_NUMHOOKS; h++) { | |
1323 | if ((unsigned char *)de - base < newinfo->hook_entry[h]) | |
1324 | newinfo->hook_entry[h] -= origsize - *size; | |
1325 | if ((unsigned char *)de - base < newinfo->underflow[h]) | |
1326 | newinfo->underflow[h] -= origsize - *size; | |
1327 | } | |
1328 | return ret; | |
1329 | } | |
1330 | ||
d6a2ba07 PM |
1331 | static int translate_compat_table(const char *name, |
1332 | unsigned int valid_hooks, | |
1333 | struct xt_table_info **pinfo, | |
1334 | void **pentry0, | |
1335 | unsigned int total_size, | |
1336 | unsigned int number, | |
1337 | unsigned int *hook_entries, | |
1338 | unsigned int *underflows) | |
1339 | { | |
1340 | unsigned int i, j; | |
1341 | struct xt_table_info *newinfo, *info; | |
1342 | void *pos, *entry0, *entry1; | |
72b2b1dd JE |
1343 | struct compat_arpt_entry *iter0; |
1344 | struct arpt_entry *iter1; | |
d6a2ba07 | 1345 | unsigned int size; |
72b2b1dd | 1346 | int ret = 0; |
d6a2ba07 PM |
1347 | |
1348 | info = *pinfo; | |
1349 | entry0 = *pentry0; | |
1350 | size = total_size; | |
1351 | info->number = number; | |
1352 | ||
1353 | /* Init all hooks to impossible value. */ | |
1354 | for (i = 0; i < NF_ARP_NUMHOOKS; i++) { | |
1355 | info->hook_entry[i] = 0xFFFFFFFF; | |
1356 | info->underflow[i] = 0xFFFFFFFF; | |
1357 | } | |
1358 | ||
1359 | duprintf("translate_compat_table: size %u\n", info->size); | |
1360 | j = 0; | |
ee999d8b | 1361 | xt_compat_lock(NFPROTO_ARP); |
255d0dc3 | 1362 | xt_compat_init_offsets(NFPROTO_ARP, number); |
d6a2ba07 | 1363 | /* Walk through entries, checking offsets. */ |
72b2b1dd JE |
1364 | xt_entry_foreach(iter0, entry0, total_size) { |
1365 | ret = check_compat_entry_size_and_hooks(iter0, info, &size, | |
6b4ff2d7 JE |
1366 | entry0, |
1367 | entry0 + total_size, | |
1368 | hook_entries, | |
1369 | underflows, | |
1370 | name); | |
72b2b1dd | 1371 | if (ret != 0) |
0559518b JE |
1372 | goto out_unlock; |
1373 | ++j; | |
72b2b1dd | 1374 | } |
d6a2ba07 PM |
1375 | |
1376 | ret = -EINVAL; | |
1377 | if (j != number) { | |
1378 | duprintf("translate_compat_table: %u not %u entries\n", | |
1379 | j, number); | |
1380 | goto out_unlock; | |
1381 | } | |
1382 | ||
1383 | /* Check hooks all assigned */ | |
1384 | for (i = 0; i < NF_ARP_NUMHOOKS; i++) { | |
1385 | /* Only hooks which are valid */ | |
1386 | if (!(valid_hooks & (1 << i))) | |
1387 | continue; | |
1388 | if (info->hook_entry[i] == 0xFFFFFFFF) { | |
1389 | duprintf("Invalid hook entry %u %u\n", | |
1390 | i, hook_entries[i]); | |
1391 | goto out_unlock; | |
1392 | } | |
1393 | if (info->underflow[i] == 0xFFFFFFFF) { | |
1394 | duprintf("Invalid underflow %u %u\n", | |
1395 | i, underflows[i]); | |
1396 | goto out_unlock; | |
1397 | } | |
1398 | } | |
1399 | ||
1400 | ret = -ENOMEM; | |
1401 | newinfo = xt_alloc_table_info(size); | |
1402 | if (!newinfo) | |
1403 | goto out_unlock; | |
1404 | ||
1405 | newinfo->number = number; | |
1406 | for (i = 0; i < NF_ARP_NUMHOOKS; i++) { | |
1407 | newinfo->hook_entry[i] = info->hook_entry[i]; | |
1408 | newinfo->underflow[i] = info->underflow[i]; | |
1409 | } | |
482cfc31 | 1410 | entry1 = newinfo->entries; |
d6a2ba07 PM |
1411 | pos = entry1; |
1412 | size = total_size; | |
72b2b1dd | 1413 | xt_entry_foreach(iter0, entry0, total_size) { |
6b4ff2d7 JE |
1414 | ret = compat_copy_entry_from_user(iter0, &pos, &size, |
1415 | name, newinfo, entry1); | |
72b2b1dd JE |
1416 | if (ret != 0) |
1417 | break; | |
1418 | } | |
ee999d8b JE |
1419 | xt_compat_flush_offsets(NFPROTO_ARP); |
1420 | xt_compat_unlock(NFPROTO_ARP); | |
d6a2ba07 PM |
1421 | if (ret) |
1422 | goto free_newinfo; | |
1423 | ||
1424 | ret = -ELOOP; | |
1425 | if (!mark_source_chains(newinfo, valid_hooks, entry1)) | |
1426 | goto free_newinfo; | |
1427 | ||
1428 | i = 0; | |
72b2b1dd | 1429 | xt_entry_foreach(iter1, entry1, newinfo->size) { |
71ae0dff FW |
1430 | iter1->counters.pcnt = xt_percpu_counter_alloc(); |
1431 | if (IS_ERR_VALUE(iter1->counters.pcnt)) { | |
1432 | ret = -ENOMEM; | |
1433 | break; | |
1434 | } | |
1435 | ||
0559518b | 1436 | ret = check_target(iter1, name); |
71ae0dff FW |
1437 | if (ret != 0) { |
1438 | xt_percpu_counter_free(iter1->counters.pcnt); | |
72b2b1dd | 1439 | break; |
71ae0dff | 1440 | } |
0559518b | 1441 | ++i; |
98dbbfc3 FW |
1442 | if (strcmp(arpt_get_target(iter1)->u.user.name, |
1443 | XT_ERROR_TARGET) == 0) | |
1444 | ++newinfo->stacksize; | |
72b2b1dd | 1445 | } |
d6a2ba07 | 1446 | if (ret) { |
72b2b1dd JE |
1447 | /* |
1448 | * The first i matches need cleanup_entry (calls ->destroy) | |
1449 | * because they had called ->check already. The other j-i | |
1450 | * entries need only release. | |
1451 | */ | |
1452 | int skip = i; | |
d6a2ba07 | 1453 | j -= i; |
72b2b1dd JE |
1454 | xt_entry_foreach(iter0, entry0, newinfo->size) { |
1455 | if (skip-- > 0) | |
1456 | continue; | |
0559518b | 1457 | if (j-- == 0) |
72b2b1dd | 1458 | break; |
0559518b | 1459 | compat_release_entry(iter0); |
72b2b1dd | 1460 | } |
0559518b JE |
1461 | xt_entry_foreach(iter1, entry1, newinfo->size) { |
1462 | if (i-- == 0) | |
72b2b1dd | 1463 | break; |
0559518b JE |
1464 | cleanup_entry(iter1); |
1465 | } | |
d6a2ba07 PM |
1466 | xt_free_table_info(newinfo); |
1467 | return ret; | |
1468 | } | |
1469 | ||
d6a2ba07 PM |
1470 | *pinfo = newinfo; |
1471 | *pentry0 = entry1; | |
1472 | xt_free_table_info(info); | |
1473 | return 0; | |
1474 | ||
1475 | free_newinfo: | |
1476 | xt_free_table_info(newinfo); | |
1477 | out: | |
0559518b JE |
1478 | xt_entry_foreach(iter0, entry0, total_size) { |
1479 | if (j-- == 0) | |
72b2b1dd | 1480 | break; |
0559518b JE |
1481 | compat_release_entry(iter0); |
1482 | } | |
d6a2ba07 PM |
1483 | return ret; |
1484 | out_unlock: | |
ee999d8b JE |
1485 | xt_compat_flush_offsets(NFPROTO_ARP); |
1486 | xt_compat_unlock(NFPROTO_ARP); | |
d6a2ba07 PM |
1487 | goto out; |
1488 | } | |
1489 | ||
1490 | struct compat_arpt_replace { | |
12b00c2c | 1491 | char name[XT_TABLE_MAXNAMELEN]; |
d6a2ba07 PM |
1492 | u32 valid_hooks; |
1493 | u32 num_entries; | |
1494 | u32 size; | |
1495 | u32 hook_entry[NF_ARP_NUMHOOKS]; | |
1496 | u32 underflow[NF_ARP_NUMHOOKS]; | |
1497 | u32 num_counters; | |
1498 | compat_uptr_t counters; | |
1499 | struct compat_arpt_entry entries[0]; | |
1500 | }; | |
1501 | ||
79df341a AD |
1502 | static int compat_do_replace(struct net *net, void __user *user, |
1503 | unsigned int len) | |
d6a2ba07 PM |
1504 | { |
1505 | int ret; | |
1506 | struct compat_arpt_replace tmp; | |
1507 | struct xt_table_info *newinfo; | |
1508 | void *loc_cpu_entry; | |
72b2b1dd | 1509 | struct arpt_entry *iter; |
d6a2ba07 PM |
1510 | |
1511 | if (copy_from_user(&tmp, user, sizeof(tmp)) != 0) | |
1512 | return -EFAULT; | |
1513 | ||
1514 | /* overflow check */ | |
1515 | if (tmp.size >= INT_MAX / num_possible_cpus()) | |
1516 | return -ENOMEM; | |
1517 | if (tmp.num_counters >= INT_MAX / sizeof(struct xt_counters)) | |
1518 | return -ENOMEM; | |
1086bbe9 DJ |
1519 | if (tmp.num_counters == 0) |
1520 | return -EINVAL; | |
1521 | ||
42eab94f | 1522 | tmp.name[sizeof(tmp.name)-1] = 0; |
d6a2ba07 PM |
1523 | |
1524 | newinfo = xt_alloc_table_info(tmp.size); | |
1525 | if (!newinfo) | |
1526 | return -ENOMEM; | |
1527 | ||
482cfc31 | 1528 | loc_cpu_entry = newinfo->entries; |
d6a2ba07 PM |
1529 | if (copy_from_user(loc_cpu_entry, user + sizeof(tmp), tmp.size) != 0) { |
1530 | ret = -EFAULT; | |
1531 | goto free_newinfo; | |
1532 | } | |
1533 | ||
1534 | ret = translate_compat_table(tmp.name, tmp.valid_hooks, | |
1535 | &newinfo, &loc_cpu_entry, tmp.size, | |
1536 | tmp.num_entries, tmp.hook_entry, | |
1537 | tmp.underflow); | |
1538 | if (ret != 0) | |
1539 | goto free_newinfo; | |
1540 | ||
1541 | duprintf("compat_do_replace: Translated table\n"); | |
1542 | ||
79df341a | 1543 | ret = __do_replace(net, tmp.name, tmp.valid_hooks, newinfo, |
d6a2ba07 PM |
1544 | tmp.num_counters, compat_ptr(tmp.counters)); |
1545 | if (ret) | |
1546 | goto free_newinfo_untrans; | |
1547 | return 0; | |
1548 | ||
1549 | free_newinfo_untrans: | |
72b2b1dd | 1550 | xt_entry_foreach(iter, loc_cpu_entry, newinfo->size) |
0559518b | 1551 | cleanup_entry(iter); |
d6a2ba07 PM |
1552 | free_newinfo: |
1553 | xt_free_table_info(newinfo); | |
1554 | return ret; | |
1555 | } | |
1556 | ||
1557 | static int compat_do_arpt_set_ctl(struct sock *sk, int cmd, void __user *user, | |
1558 | unsigned int len) | |
1559 | { | |
1560 | int ret; | |
1561 | ||
52e804c6 | 1562 | if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN)) |
d6a2ba07 PM |
1563 | return -EPERM; |
1564 | ||
1565 | switch (cmd) { | |
1566 | case ARPT_SO_SET_REPLACE: | |
3b1e0a65 | 1567 | ret = compat_do_replace(sock_net(sk), user, len); |
d6a2ba07 PM |
1568 | break; |
1569 | ||
1570 | case ARPT_SO_SET_ADD_COUNTERS: | |
3b1e0a65 | 1571 | ret = do_add_counters(sock_net(sk), user, len, 1); |
d6a2ba07 PM |
1572 | break; |
1573 | ||
1574 | default: | |
1575 | duprintf("do_arpt_set_ctl: unknown request %i\n", cmd); | |
1576 | ret = -EINVAL; | |
1577 | } | |
1578 | ||
1579 | return ret; | |
1580 | } | |
1581 | ||
1582 | static int compat_copy_entry_to_user(struct arpt_entry *e, void __user **dstptr, | |
1583 | compat_uint_t *size, | |
1584 | struct xt_counters *counters, | |
0559518b | 1585 | unsigned int i) |
d6a2ba07 | 1586 | { |
87a2e70d | 1587 | struct xt_entry_target *t; |
d6a2ba07 PM |
1588 | struct compat_arpt_entry __user *ce; |
1589 | u_int16_t target_offset, next_offset; | |
1590 | compat_uint_t origsize; | |
1591 | int ret; | |
1592 | ||
d6a2ba07 PM |
1593 | origsize = *size; |
1594 | ce = (struct compat_arpt_entry __user *)*dstptr; | |
0559518b JE |
1595 | if (copy_to_user(ce, e, sizeof(struct arpt_entry)) != 0 || |
1596 | copy_to_user(&ce->counters, &counters[i], | |
1597 | sizeof(counters[i])) != 0) | |
1598 | return -EFAULT; | |
d6a2ba07 PM |
1599 | |
1600 | *dstptr += sizeof(struct compat_arpt_entry); | |
1601 | *size -= sizeof(struct arpt_entry) - sizeof(struct compat_arpt_entry); | |
1602 | ||
1603 | target_offset = e->target_offset - (origsize - *size); | |
1604 | ||
1605 | t = arpt_get_target(e); | |
1606 | ret = xt_compat_target_to_user(t, dstptr, size); | |
1607 | if (ret) | |
0559518b | 1608 | return ret; |
d6a2ba07 | 1609 | next_offset = e->next_offset - (origsize - *size); |
0559518b JE |
1610 | if (put_user(target_offset, &ce->target_offset) != 0 || |
1611 | put_user(next_offset, &ce->next_offset) != 0) | |
1612 | return -EFAULT; | |
d6a2ba07 | 1613 | return 0; |
d6a2ba07 PM |
1614 | } |
1615 | ||
1616 | static int compat_copy_entries_to_user(unsigned int total_size, | |
4abff077 | 1617 | struct xt_table *table, |
d6a2ba07 PM |
1618 | void __user *userptr) |
1619 | { | |
1620 | struct xt_counters *counters; | |
5452e425 | 1621 | const struct xt_table_info *private = table->private; |
d6a2ba07 PM |
1622 | void __user *pos; |
1623 | unsigned int size; | |
1624 | int ret = 0; | |
d6a2ba07 | 1625 | unsigned int i = 0; |
72b2b1dd | 1626 | struct arpt_entry *iter; |
d6a2ba07 PM |
1627 | |
1628 | counters = alloc_counters(table); | |
1629 | if (IS_ERR(counters)) | |
1630 | return PTR_ERR(counters); | |
1631 | ||
d6a2ba07 PM |
1632 | pos = userptr; |
1633 | size = total_size; | |
482cfc31 | 1634 | xt_entry_foreach(iter, private->entries, total_size) { |
72b2b1dd | 1635 | ret = compat_copy_entry_to_user(iter, &pos, |
6b4ff2d7 | 1636 | &size, counters, i++); |
72b2b1dd JE |
1637 | if (ret != 0) |
1638 | break; | |
1639 | } | |
d6a2ba07 PM |
1640 | vfree(counters); |
1641 | return ret; | |
1642 | } | |
1643 | ||
1644 | struct compat_arpt_get_entries { | |
12b00c2c | 1645 | char name[XT_TABLE_MAXNAMELEN]; |
d6a2ba07 PM |
1646 | compat_uint_t size; |
1647 | struct compat_arpt_entry entrytable[0]; | |
1648 | }; | |
1649 | ||
79df341a AD |
1650 | static int compat_get_entries(struct net *net, |
1651 | struct compat_arpt_get_entries __user *uptr, | |
d6a2ba07 PM |
1652 | int *len) |
1653 | { | |
1654 | int ret; | |
1655 | struct compat_arpt_get_entries get; | |
4abff077 | 1656 | struct xt_table *t; |
d6a2ba07 PM |
1657 | |
1658 | if (*len < sizeof(get)) { | |
1659 | duprintf("compat_get_entries: %u < %zu\n", *len, sizeof(get)); | |
1660 | return -EINVAL; | |
1661 | } | |
1662 | if (copy_from_user(&get, uptr, sizeof(get)) != 0) | |
1663 | return -EFAULT; | |
1664 | if (*len != sizeof(struct compat_arpt_get_entries) + get.size) { | |
1665 | duprintf("compat_get_entries: %u != %zu\n", | |
1666 | *len, sizeof(get) + get.size); | |
1667 | return -EINVAL; | |
1668 | } | |
b301f253 | 1669 | get.name[sizeof(get.name) - 1] = '\0'; |
d6a2ba07 | 1670 | |
ee999d8b JE |
1671 | xt_compat_lock(NFPROTO_ARP); |
1672 | t = xt_find_table_lock(net, NFPROTO_ARP, get.name); | |
0cc8d8df | 1673 | if (!IS_ERR_OR_NULL(t)) { |
5452e425 | 1674 | const struct xt_table_info *private = t->private; |
d6a2ba07 PM |
1675 | struct xt_table_info info; |
1676 | ||
1677 | duprintf("t->private->number = %u\n", private->number); | |
1678 | ret = compat_table_info(private, &info); | |
1679 | if (!ret && get.size == info.size) { | |
1680 | ret = compat_copy_entries_to_user(private->size, | |
1681 | t, uptr->entrytable); | |
1682 | } else if (!ret) { | |
1683 | duprintf("compat_get_entries: I've got %u not %u!\n", | |
1684 | private->size, get.size); | |
544473c1 | 1685 | ret = -EAGAIN; |
d6a2ba07 | 1686 | } |
ee999d8b | 1687 | xt_compat_flush_offsets(NFPROTO_ARP); |
d6a2ba07 PM |
1688 | module_put(t->me); |
1689 | xt_table_unlock(t); | |
1690 | } else | |
1691 | ret = t ? PTR_ERR(t) : -ENOENT; | |
1692 | ||
ee999d8b | 1693 | xt_compat_unlock(NFPROTO_ARP); |
d6a2ba07 PM |
1694 | return ret; |
1695 | } | |
1696 | ||
1697 | static int do_arpt_get_ctl(struct sock *, int, void __user *, int *); | |
1698 | ||
1699 | static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, | |
1700 | int *len) | |
1701 | { | |
1702 | int ret; | |
1703 | ||
52e804c6 | 1704 | if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN)) |
d6a2ba07 PM |
1705 | return -EPERM; |
1706 | ||
1707 | switch (cmd) { | |
1708 | case ARPT_SO_GET_INFO: | |
3b1e0a65 | 1709 | ret = get_info(sock_net(sk), user, len, 1); |
d6a2ba07 PM |
1710 | break; |
1711 | case ARPT_SO_GET_ENTRIES: | |
3b1e0a65 | 1712 | ret = compat_get_entries(sock_net(sk), user, len); |
d6a2ba07 PM |
1713 | break; |
1714 | default: | |
1715 | ret = do_arpt_get_ctl(sk, cmd, user, len); | |
1716 | } | |
1717 | return ret; | |
1718 | } | |
1719 | #endif | |
1720 | ||
1da177e4 LT |
1721 | static int do_arpt_set_ctl(struct sock *sk, int cmd, void __user *user, unsigned int len) |
1722 | { | |
1723 | int ret; | |
1724 | ||
52e804c6 | 1725 | if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN)) |
1da177e4 LT |
1726 | return -EPERM; |
1727 | ||
1728 | switch (cmd) { | |
1729 | case ARPT_SO_SET_REPLACE: | |
3b1e0a65 | 1730 | ret = do_replace(sock_net(sk), user, len); |
1da177e4 LT |
1731 | break; |
1732 | ||
1733 | case ARPT_SO_SET_ADD_COUNTERS: | |
3b1e0a65 | 1734 | ret = do_add_counters(sock_net(sk), user, len, 0); |
1da177e4 LT |
1735 | break; |
1736 | ||
1737 | default: | |
1738 | duprintf("do_arpt_set_ctl: unknown request %i\n", cmd); | |
1739 | ret = -EINVAL; | |
1740 | } | |
1741 | ||
1742 | return ret; | |
1743 | } | |
1744 | ||
1745 | static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len) | |
1746 | { | |
1747 | int ret; | |
1748 | ||
52e804c6 | 1749 | if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN)) |
1da177e4 LT |
1750 | return -EPERM; |
1751 | ||
1752 | switch (cmd) { | |
41acd975 | 1753 | case ARPT_SO_GET_INFO: |
3b1e0a65 | 1754 | ret = get_info(sock_net(sk), user, len, 0); |
41acd975 | 1755 | break; |
1da177e4 | 1756 | |
11f6dff8 | 1757 | case ARPT_SO_GET_ENTRIES: |
3b1e0a65 | 1758 | ret = get_entries(sock_net(sk), user, len); |
1da177e4 | 1759 | break; |
1da177e4 | 1760 | |
6b7d31fc | 1761 | case ARPT_SO_GET_REVISION_TARGET: { |
2e4e6a17 | 1762 | struct xt_get_revision rev; |
6b7d31fc HW |
1763 | |
1764 | if (*len != sizeof(rev)) { | |
1765 | ret = -EINVAL; | |
1766 | break; | |
1767 | } | |
1768 | if (copy_from_user(&rev, user, sizeof(rev)) != 0) { | |
1769 | ret = -EFAULT; | |
1770 | break; | |
1771 | } | |
42eab94f | 1772 | rev.name[sizeof(rev.name)-1] = 0; |
6b7d31fc | 1773 | |
ee999d8b | 1774 | try_then_request_module(xt_find_revision(NFPROTO_ARP, rev.name, |
2e4e6a17 | 1775 | rev.revision, 1, &ret), |
6b7d31fc HW |
1776 | "arpt_%s", rev.name); |
1777 | break; | |
1778 | } | |
1779 | ||
1da177e4 LT |
1780 | default: |
1781 | duprintf("do_arpt_get_ctl: unknown request %i\n", cmd); | |
1782 | ret = -EINVAL; | |
1783 | } | |
1784 | ||
1785 | return ret; | |
1786 | } | |
1787 | ||
b9e69e12 FW |
1788 | static void __arpt_unregister_table(struct xt_table *table) |
1789 | { | |
1790 | struct xt_table_info *private; | |
1791 | void *loc_cpu_entry; | |
1792 | struct module *table_owner = table->me; | |
1793 | struct arpt_entry *iter; | |
1794 | ||
1795 | private = xt_unregister_table(table); | |
1796 | ||
1797 | /* Decrease module usage counts and free resources */ | |
1798 | loc_cpu_entry = private->entries; | |
1799 | xt_entry_foreach(iter, loc_cpu_entry, private->size) | |
1800 | cleanup_entry(iter); | |
1801 | if (private->number > private->initial_entries) | |
1802 | module_put(table_owner); | |
1803 | xt_free_table_info(private); | |
1804 | } | |
1805 | ||
a67dd266 FW |
1806 | int arpt_register_table(struct net *net, |
1807 | const struct xt_table *table, | |
1808 | const struct arpt_replace *repl, | |
1809 | const struct nf_hook_ops *ops, | |
1810 | struct xt_table **res) | |
1da177e4 LT |
1811 | { |
1812 | int ret; | |
2e4e6a17 | 1813 | struct xt_table_info *newinfo; |
f3c5c1bf | 1814 | struct xt_table_info bootstrap = {0}; |
31836064 | 1815 | void *loc_cpu_entry; |
a98da11d | 1816 | struct xt_table *new_table; |
1da177e4 | 1817 | |
2e4e6a17 | 1818 | newinfo = xt_alloc_table_info(repl->size); |
a67dd266 FW |
1819 | if (!newinfo) |
1820 | return -ENOMEM; | |
31836064 | 1821 | |
482cfc31 | 1822 | loc_cpu_entry = newinfo->entries; |
31836064 | 1823 | memcpy(loc_cpu_entry, repl->entries, repl->size); |
1da177e4 | 1824 | |
0f234214 | 1825 | ret = translate_table(newinfo, loc_cpu_entry, repl); |
1da177e4 | 1826 | duprintf("arpt_register_table: translate table gives %d\n", ret); |
44d34e72 AD |
1827 | if (ret != 0) |
1828 | goto out_free; | |
1da177e4 | 1829 | |
79df341a | 1830 | new_table = xt_register_table(net, table, &bootstrap, newinfo); |
a98da11d | 1831 | if (IS_ERR(new_table)) { |
44d34e72 AD |
1832 | ret = PTR_ERR(new_table); |
1833 | goto out_free; | |
1da177e4 | 1834 | } |
a67dd266 | 1835 | |
b9e69e12 | 1836 | /* set res now, will see skbs right after nf_register_net_hooks */ |
a67dd266 FW |
1837 | WRITE_ONCE(*res, new_table); |
1838 | ||
b9e69e12 FW |
1839 | ret = nf_register_net_hooks(net, ops, hweight32(table->valid_hooks)); |
1840 | if (ret != 0) { | |
1841 | __arpt_unregister_table(new_table); | |
1842 | *res = NULL; | |
1843 | } | |
1844 | ||
a67dd266 | 1845 | return ret; |
1da177e4 | 1846 | |
44d34e72 AD |
1847 | out_free: |
1848 | xt_free_table_info(newinfo); | |
a67dd266 | 1849 | return ret; |
1da177e4 LT |
1850 | } |
1851 | ||
a67dd266 FW |
1852 | void arpt_unregister_table(struct net *net, struct xt_table *table, |
1853 | const struct nf_hook_ops *ops) | |
1da177e4 | 1854 | { |
b9e69e12 FW |
1855 | nf_unregister_net_hooks(net, ops, hweight32(table->valid_hooks)); |
1856 | __arpt_unregister_table(table); | |
1da177e4 LT |
1857 | } |
1858 | ||
1859 | /* The built-in targets: standard (NULL) and error. */ | |
4538506b JE |
1860 | static struct xt_target arpt_builtin_tg[] __read_mostly = { |
1861 | { | |
243bf6e2 | 1862 | .name = XT_STANDARD_TARGET, |
4538506b JE |
1863 | .targetsize = sizeof(int), |
1864 | .family = NFPROTO_ARP, | |
d6a2ba07 | 1865 | #ifdef CONFIG_COMPAT |
4538506b JE |
1866 | .compatsize = sizeof(compat_int_t), |
1867 | .compat_from_user = compat_standard_from_user, | |
1868 | .compat_to_user = compat_standard_to_user, | |
d6a2ba07 | 1869 | #endif |
4538506b JE |
1870 | }, |
1871 | { | |
243bf6e2 | 1872 | .name = XT_ERROR_TARGET, |
4538506b | 1873 | .target = arpt_error, |
12b00c2c | 1874 | .targetsize = XT_FUNCTION_MAXNAMELEN, |
4538506b JE |
1875 | .family = NFPROTO_ARP, |
1876 | }, | |
1da177e4 LT |
1877 | }; |
1878 | ||
1879 | static struct nf_sockopt_ops arpt_sockopts = { | |
1880 | .pf = PF_INET, | |
1881 | .set_optmin = ARPT_BASE_CTL, | |
1882 | .set_optmax = ARPT_SO_SET_MAX+1, | |
1883 | .set = do_arpt_set_ctl, | |
d6a2ba07 PM |
1884 | #ifdef CONFIG_COMPAT |
1885 | .compat_set = compat_do_arpt_set_ctl, | |
1886 | #endif | |
1da177e4 LT |
1887 | .get_optmin = ARPT_BASE_CTL, |
1888 | .get_optmax = ARPT_SO_GET_MAX+1, | |
1889 | .get = do_arpt_get_ctl, | |
d6a2ba07 PM |
1890 | #ifdef CONFIG_COMPAT |
1891 | .compat_get = compat_do_arpt_get_ctl, | |
1892 | #endif | |
16fcec35 | 1893 | .owner = THIS_MODULE, |
1da177e4 LT |
1894 | }; |
1895 | ||
3cb609d5 AD |
1896 | static int __net_init arp_tables_net_init(struct net *net) |
1897 | { | |
ee999d8b | 1898 | return xt_proto_init(net, NFPROTO_ARP); |
3cb609d5 AD |
1899 | } |
1900 | ||
1901 | static void __net_exit arp_tables_net_exit(struct net *net) | |
1902 | { | |
ee999d8b | 1903 | xt_proto_fini(net, NFPROTO_ARP); |
3cb609d5 AD |
1904 | } |
1905 | ||
1906 | static struct pernet_operations arp_tables_net_ops = { | |
1907 | .init = arp_tables_net_init, | |
1908 | .exit = arp_tables_net_exit, | |
1909 | }; | |
1910 | ||
65b4b4e8 | 1911 | static int __init arp_tables_init(void) |
1da177e4 LT |
1912 | { |
1913 | int ret; | |
1914 | ||
3cb609d5 | 1915 | ret = register_pernet_subsys(&arp_tables_net_ops); |
0eff66e6 PM |
1916 | if (ret < 0) |
1917 | goto err1; | |
2e4e6a17 | 1918 | |
25985edc | 1919 | /* No one else will be downing sem now, so we won't sleep */ |
4538506b | 1920 | ret = xt_register_targets(arpt_builtin_tg, ARRAY_SIZE(arpt_builtin_tg)); |
0eff66e6 PM |
1921 | if (ret < 0) |
1922 | goto err2; | |
1da177e4 LT |
1923 | |
1924 | /* Register setsockopt */ | |
1925 | ret = nf_register_sockopt(&arpt_sockopts); | |
0eff66e6 PM |
1926 | if (ret < 0) |
1927 | goto err4; | |
1da177e4 | 1928 | |
09605cc1 | 1929 | pr_info("arp_tables: (C) 2002 David S. Miller\n"); |
1da177e4 | 1930 | return 0; |
0eff66e6 PM |
1931 | |
1932 | err4: | |
4538506b | 1933 | xt_unregister_targets(arpt_builtin_tg, ARRAY_SIZE(arpt_builtin_tg)); |
0eff66e6 | 1934 | err2: |
3cb609d5 | 1935 | unregister_pernet_subsys(&arp_tables_net_ops); |
0eff66e6 PM |
1936 | err1: |
1937 | return ret; | |
1da177e4 LT |
1938 | } |
1939 | ||
65b4b4e8 | 1940 | static void __exit arp_tables_fini(void) |
1da177e4 LT |
1941 | { |
1942 | nf_unregister_sockopt(&arpt_sockopts); | |
4538506b | 1943 | xt_unregister_targets(arpt_builtin_tg, ARRAY_SIZE(arpt_builtin_tg)); |
3cb609d5 | 1944 | unregister_pernet_subsys(&arp_tables_net_ops); |
1da177e4 LT |
1945 | } |
1946 | ||
1947 | EXPORT_SYMBOL(arpt_register_table); | |
1948 | EXPORT_SYMBOL(arpt_unregister_table); | |
1949 | EXPORT_SYMBOL(arpt_do_table); | |
1da177e4 | 1950 | |
65b4b4e8 AM |
1951 | module_init(arp_tables_init); |
1952 | module_exit(arp_tables_fini); |