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,
12 const struct net_device *in, const struct net_device *out,
13 unsigned int hooknum, const struct xt_target *target,
16 const struct arpt_mangle *mangle = targinfo;
18 unsigned char *arpptr;
21 if (skb_shared(*pskb) || skb_cloned(*pskb)) {
24 nskb = skb_copy(*pskb, GFP_ATOMIC);
28 skb_set_owner_w(nskb, (*pskb)->sk);
34 arpptr = skb_network_header(*pskb) + sizeof(*arp);
37 /* We assume that pln and hln were checked in the match */
38 if (mangle->flags & ARPT_MANGLE_SDEV) {
39 if (ARPT_DEV_ADDR_LEN_MAX < hln ||
40 (arpptr + hln > skb_tail_pointer(*pskb)))
42 memcpy(arpptr, mangle->src_devaddr, hln);
45 if (mangle->flags & ARPT_MANGLE_SIP) {
46 if (ARPT_MANGLE_ADDR_LEN_MAX < pln ||
47 (arpptr + pln > skb_tail_pointer(*pskb)))
49 memcpy(arpptr, &mangle->u_s.src_ip, pln);
52 if (mangle->flags & ARPT_MANGLE_TDEV) {
53 if (ARPT_DEV_ADDR_LEN_MAX < hln ||
54 (arpptr + hln > skb_tail_pointer(*pskb)))
56 memcpy(arpptr, mangle->tgt_devaddr, hln);
59 if (mangle->flags & ARPT_MANGLE_TIP) {
60 if (ARPT_MANGLE_ADDR_LEN_MAX < pln ||
61 (arpptr + pln > skb_tail_pointer(*pskb)))
63 memcpy(arpptr, &mangle->u_t.tgt_ip, pln);
65 return mangle->target;
69 checkentry(const char *tablename, const void *e, const struct xt_target *target,
70 void *targinfo, unsigned int hook_mask)
72 const struct arpt_mangle *mangle = targinfo;
74 if (mangle->flags & ~ARPT_MANGLE_MASK ||
75 !(mangle->flags & ARPT_MANGLE_MASK))
78 if (mangle->target != NF_DROP && mangle->target != NF_ACCEPT &&
79 mangle->target != ARPT_CONTINUE)
84 static struct arpt_target arpt_mangle_reg __read_mostly = {
87 .targetsize = sizeof(struct arpt_mangle),
88 .checkentry = checkentry,
92 static int __init arpt_mangle_init(void)
94 if (arpt_register_target(&arpt_mangle_reg))
100 static void __exit arpt_mangle_fini(void)
102 arpt_unregister_target(&arpt_mangle_reg);
105 module_init(arpt_mangle_init);
106 module_exit(arpt_mangle_fini);