Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[wrt350n-kernel.git] / net / ipv4 / netfilter / arpt_mangle.c
blobb0eff469b37ebe5de4de8fa55c7995a19234112a
1 /* module that allows mangling of the arp payload */
2 #include <linux/module.h>
3 #include <linux/netfilter.h>
4 #include <linux/netfilter_arp/arpt_mangle.h>
5 #include <net/sock.h>
7 MODULE_LICENSE("GPL");
8 MODULE_AUTHOR("Bart De Schuymer <bdschuym@pandora.be>");
9 MODULE_DESCRIPTION("arptables arp payload mangle target");
11 static unsigned int
12 target(struct sk_buff *skb,
13 const struct net_device *in, const struct net_device *out,
14 unsigned int hooknum, const struct xt_target *target,
15 const void *targinfo)
17 const struct arpt_mangle *mangle = targinfo;
18 struct arphdr *arp;
19 unsigned char *arpptr;
20 int pln, hln;
22 <<<<<<< HEAD:net/ipv4/netfilter/arpt_mangle.c
23 if (skb_make_writable(skb, skb->len))
24 =======
25 if (!skb_make_writable(skb, skb->len))
26 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:net/ipv4/netfilter/arpt_mangle.c
27 return NF_DROP;
29 arp = arp_hdr(skb);
30 arpptr = skb_network_header(skb) + sizeof(*arp);
31 pln = arp->ar_pln;
32 hln = arp->ar_hln;
33 /* We assume that pln and hln were checked in the match */
34 if (mangle->flags & ARPT_MANGLE_SDEV) {
35 if (ARPT_DEV_ADDR_LEN_MAX < hln ||
36 (arpptr + hln > skb_tail_pointer(skb)))
37 return NF_DROP;
38 memcpy(arpptr, mangle->src_devaddr, hln);
40 arpptr += hln;
41 if (mangle->flags & ARPT_MANGLE_SIP) {
42 if (ARPT_MANGLE_ADDR_LEN_MAX < pln ||
43 (arpptr + pln > skb_tail_pointer(skb)))
44 return NF_DROP;
45 memcpy(arpptr, &mangle->u_s.src_ip, pln);
47 arpptr += pln;
48 if (mangle->flags & ARPT_MANGLE_TDEV) {
49 if (ARPT_DEV_ADDR_LEN_MAX < hln ||
50 (arpptr + hln > skb_tail_pointer(skb)))
51 return NF_DROP;
52 memcpy(arpptr, mangle->tgt_devaddr, hln);
54 arpptr += hln;
55 if (mangle->flags & ARPT_MANGLE_TIP) {
56 if (ARPT_MANGLE_ADDR_LEN_MAX < pln ||
57 (arpptr + pln > skb_tail_pointer(skb)))
58 return NF_DROP;
59 memcpy(arpptr, &mangle->u_t.tgt_ip, pln);
61 return mangle->target;
64 static bool
65 checkentry(const char *tablename, const void *e, const struct xt_target *target,
66 void *targinfo, unsigned int hook_mask)
68 const struct arpt_mangle *mangle = targinfo;
70 if (mangle->flags & ~ARPT_MANGLE_MASK ||
71 !(mangle->flags & ARPT_MANGLE_MASK))
72 return false;
74 if (mangle->target != NF_DROP && mangle->target != NF_ACCEPT &&
75 mangle->target != ARPT_CONTINUE)
76 return false;
77 return true;
80 static struct arpt_target arpt_mangle_reg __read_mostly = {
81 .name = "mangle",
82 .target = target,
83 .targetsize = sizeof(struct arpt_mangle),
84 .checkentry = checkentry,
85 .me = THIS_MODULE,
88 static int __init arpt_mangle_init(void)
90 if (arpt_register_target(&arpt_mangle_reg))
91 return -EINVAL;
93 return 0;
96 static void __exit arpt_mangle_fini(void)
98 arpt_unregister_target(&arpt_mangle_reg);
101 module_init(arpt_mangle_init);
102 module_exit(arpt_mangle_fini);