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>
8 MODULE_AUTHOR("Bart De Schuymer <bdschuym@pandora.be>");
9 MODULE_DESCRIPTION("arptables arp payload mangle target");
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,
17 const struct arpt_mangle *mangle = targinfo;
18 const struct arphdr *arp;
19 unsigned char *arpptr;
22 if (!skb_make_writable(skb, skb->len))
26 arpptr = skb_network_header(skb) + sizeof(*arp);
29 /* We assume that pln and hln were checked in the match */
30 if (mangle->flags & ARPT_MANGLE_SDEV) {
31 if (ARPT_DEV_ADDR_LEN_MAX < hln ||
32 (arpptr + hln > skb_tail_pointer(skb)))
34 memcpy(arpptr, mangle->src_devaddr, hln);
37 if (mangle->flags & ARPT_MANGLE_SIP) {
38 if (ARPT_MANGLE_ADDR_LEN_MAX < pln ||
39 (arpptr + pln > skb_tail_pointer(skb)))
41 memcpy(arpptr, &mangle->u_s.src_ip, pln);
44 if (mangle->flags & ARPT_MANGLE_TDEV) {
45 if (ARPT_DEV_ADDR_LEN_MAX < hln ||
46 (arpptr + hln > skb_tail_pointer(skb)))
48 memcpy(arpptr, mangle->tgt_devaddr, hln);
51 if (mangle->flags & ARPT_MANGLE_TIP) {
52 if (ARPT_MANGLE_ADDR_LEN_MAX < pln ||
53 (arpptr + pln > skb_tail_pointer(skb)))
55 memcpy(arpptr, &mangle->u_t.tgt_ip, pln);
57 return mangle->target;
61 checkentry(const char *tablename, const void *e, const struct xt_target *target,
62 void *targinfo, unsigned int hook_mask)
64 const struct arpt_mangle *mangle = targinfo;
66 if (mangle->flags & ~ARPT_MANGLE_MASK ||
67 !(mangle->flags & ARPT_MANGLE_MASK))
70 if (mangle->target != NF_DROP && mangle->target != NF_ACCEPT &&
71 mangle->target != ARPT_CONTINUE)
76 static struct xt_target arpt_mangle_reg __read_mostly = {
80 .targetsize = sizeof(struct arpt_mangle),
81 .checkentry = checkentry,
85 static int __init arpt_mangle_init(void)
87 return xt_register_target(&arpt_mangle_reg);
90 static void __exit arpt_mangle_fini(void)
92 xt_unregister_target(&arpt_mangle_reg);
95 module_init(arpt_mangle_init);
96 module_exit(arpt_mangle_fini);