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, unsigned int hooknum, const struct net_device *in,
12 const struct net_device *out, const void *targinfo, void *userinfo)
14 const struct arpt_mangle *mangle = targinfo;
16 unsigned char *arpptr;
19 if (skb_shared(*pskb) || skb_cloned(*pskb)) {
22 nskb = skb_copy(*pskb, GFP_ATOMIC);
26 skb_set_owner_w(nskb, (*pskb)->sk);
31 arp = (*pskb)->nh.arph;
32 arpptr = (*pskb)->nh.raw + sizeof(*arp);
35 /* We assume that pln and hln were checked in the match */
36 if (mangle->flags & ARPT_MANGLE_SDEV) {
37 if (ARPT_DEV_ADDR_LEN_MAX < hln ||
38 (arpptr + hln > (**pskb).tail))
40 memcpy(arpptr, mangle->src_devaddr, hln);
43 if (mangle->flags & ARPT_MANGLE_SIP) {
44 if (ARPT_MANGLE_ADDR_LEN_MAX < pln ||
45 (arpptr + pln > (**pskb).tail))
47 memcpy(arpptr, &mangle->u_s.src_ip, pln);
50 if (mangle->flags & ARPT_MANGLE_TDEV) {
51 if (ARPT_DEV_ADDR_LEN_MAX < hln ||
52 (arpptr + hln > (**pskb).tail))
54 memcpy(arpptr, mangle->tgt_devaddr, hln);
57 if (mangle->flags & ARPT_MANGLE_TIP) {
58 if (ARPT_MANGLE_ADDR_LEN_MAX < pln ||
59 (arpptr + pln > (**pskb).tail))
61 memcpy(arpptr, &mangle->u_t.tgt_ip, pln);
63 return mangle->target;
67 checkentry(const char *tablename, const struct arpt_entry *e, void *targinfo,
68 unsigned int targinfosize, unsigned int hook_mask)
70 const struct arpt_mangle *mangle = targinfo;
72 if (mangle->flags & ~ARPT_MANGLE_MASK ||
73 !(mangle->flags & ARPT_MANGLE_MASK))
76 if (mangle->target != NF_DROP && mangle->target != NF_ACCEPT &&
77 mangle->target != ARPT_CONTINUE)
82 static struct arpt_target arpt_mangle_reg
86 .checkentry = checkentry,
90 static int __init init(void)
92 if (arpt_register_target(&arpt_mangle_reg))
98 static void __exit fini(void)
100 arpt_unregister_target(&arpt_mangle_reg);