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, const struct xt_target_param *par)
14 const struct arpt_mangle *mangle = par->targinfo;
15 const struct arphdr *arp;
16 unsigned char *arpptr;
19 if (!skb_make_writable(skb, skb->len))
23 arpptr = skb_network_header(skb) + sizeof(*arp);
26 /* We assume that pln and hln were checked in the match */
27 if (mangle->flags & ARPT_MANGLE_SDEV) {
28 if (ARPT_DEV_ADDR_LEN_MAX < hln ||
29 (arpptr + hln > skb_tail_pointer(skb)))
31 memcpy(arpptr, mangle->src_devaddr, hln);
34 if (mangle->flags & ARPT_MANGLE_SIP) {
35 if (ARPT_MANGLE_ADDR_LEN_MAX < pln ||
36 (arpptr + pln > skb_tail_pointer(skb)))
38 memcpy(arpptr, &mangle->u_s.src_ip, pln);
41 if (mangle->flags & ARPT_MANGLE_TDEV) {
42 if (ARPT_DEV_ADDR_LEN_MAX < hln ||
43 (arpptr + hln > skb_tail_pointer(skb)))
45 memcpy(arpptr, mangle->tgt_devaddr, hln);
48 if (mangle->flags & ARPT_MANGLE_TIP) {
49 if (ARPT_MANGLE_ADDR_LEN_MAX < pln ||
50 (arpptr + pln > skb_tail_pointer(skb)))
52 memcpy(arpptr, &mangle->u_t.tgt_ip, pln);
54 return mangle->target;
57 static bool checkentry(const struct xt_tgchk_param *par)
59 const struct arpt_mangle *mangle = par->targinfo;
61 if (mangle->flags & ~ARPT_MANGLE_MASK ||
62 !(mangle->flags & ARPT_MANGLE_MASK))
65 if (mangle->target != NF_DROP && mangle->target != NF_ACCEPT &&
66 mangle->target != ARPT_CONTINUE)
71 static struct xt_target arpt_mangle_reg __read_mostly = {
73 .family = NFPROTO_ARP,
75 .targetsize = sizeof(struct arpt_mangle),
76 .checkentry = checkentry,
80 static int __init arpt_mangle_init(void)
82 return xt_register_target(&arpt_mangle_reg);
85 static void __exit arpt_mangle_fini(void)
87 xt_unregister_target(&arpt_mangle_reg);
90 module_init(arpt_mangle_init);
91 module_exit(arpt_mangle_fini);