1 /* module that allows mangling of the arp payload */
2 #include <linux/module.h>
3 #include <linux/netfilter_arp/arpt_mangle.h>
7 MODULE_AUTHOR("Bart De Schuymer <bdschuym@pandora.be>");
8 MODULE_DESCRIPTION("arptables arp payload mangle target");
11 target(struct sk_buff **pskb, const struct net_device *in,
12 const struct net_device *out, unsigned int hooknum, const void *targinfo,
15 const struct arpt_mangle *mangle = targinfo;
17 unsigned char *arpptr;
20 if (skb_shared(*pskb) || skb_cloned(*pskb)) {
23 nskb = skb_copy(*pskb, GFP_ATOMIC);
27 skb_set_owner_w(nskb, (*pskb)->sk);
32 arp = (*pskb)->nh.arph;
33 arpptr = (*pskb)->nh.raw + sizeof(*arp);
36 /* We assume that pln and hln were checked in the match */
37 if (mangle->flags & ARPT_MANGLE_SDEV) {
38 if (ARPT_DEV_ADDR_LEN_MAX < hln ||
39 (arpptr + hln > (**pskb).tail))
41 memcpy(arpptr, mangle->src_devaddr, hln);
44 if (mangle->flags & ARPT_MANGLE_SIP) {
45 if (ARPT_MANGLE_ADDR_LEN_MAX < pln ||
46 (arpptr + pln > (**pskb).tail))
48 memcpy(arpptr, &mangle->u_s.src_ip, pln);
51 if (mangle->flags & ARPT_MANGLE_TDEV) {
52 if (ARPT_DEV_ADDR_LEN_MAX < hln ||
53 (arpptr + hln > (**pskb).tail))
55 memcpy(arpptr, mangle->tgt_devaddr, hln);
58 if (mangle->flags & ARPT_MANGLE_TIP) {
59 if (ARPT_MANGLE_ADDR_LEN_MAX < pln ||
60 (arpptr + pln > (**pskb).tail))
62 memcpy(arpptr, &mangle->u_t.tgt_ip, pln);
64 return mangle->target;
68 checkentry(const char *tablename, const void *e, void *targinfo,
69 unsigned int targinfosize, unsigned int hook_mask)
71 const struct arpt_mangle *mangle = targinfo;
73 if (mangle->flags & ~ARPT_MANGLE_MASK ||
74 !(mangle->flags & ARPT_MANGLE_MASK))
77 if (mangle->target != NF_DROP && mangle->target != NF_ACCEPT &&
78 mangle->target != ARPT_CONTINUE)
83 static struct arpt_target arpt_mangle_reg
87 .checkentry = checkentry,
91 static int __init init(void)
93 if (arpt_register_target(&arpt_mangle_reg))
99 static void __exit fini(void)
101 arpt_unregister_target(&arpt_mangle_reg);