5 * Grzegorz Borowiak <grzes@gnu.univ.gda.pl>
6 * Bart De Schuymer <bdschuym@pandora.be>
12 #include <linux/netfilter_bridge/ebtables.h>
13 #include <linux/netfilter_bridge/ebt_arpreply.h>
14 #include <linux/if_arp.h>
16 #include <linux/module.h>
18 static int ebt_target_reply(struct sk_buff **pskb, unsigned int hooknr,
19 const struct net_device *in, const struct net_device *out,
20 const void *data, unsigned int datalen)
22 struct ebt_arpreply_info *info = (struct ebt_arpreply_info *)data;
25 unsigned char sha[ETH_ALEN];
26 struct sk_buff *skb = *pskb;
28 if (skb_copy_bits(skb, 0, &ah, sizeof(ah)))
31 if (ah.ar_op != __constant_htons(ARPOP_REQUEST) || ah.ar_hln != ETH_ALEN
32 || ah.ar_pro != __constant_htons(ETH_P_IP) || ah.ar_pln != 4)
35 if (skb_copy_bits(skb, sizeof(ah), &sha, ETH_ALEN))
38 if (skb_copy_bits(skb, sizeof(ah) + ETH_ALEN, &sip, sizeof(sip)))
41 if (skb_copy_bits(skb, sizeof(ah) + 2 * ETH_ALEN + sizeof(sip),
45 arp_send(ARPOP_REPLY, ETH_P_ARP, sip, (struct net_device *)in,
46 dip, sha, info->mac, sha);
51 static int ebt_target_reply_check(const char *tablename, unsigned int hookmask,
52 const struct ebt_entry *e, void *data, unsigned int datalen)
54 struct ebt_arpreply_info *info = (struct ebt_arpreply_info *)data;
56 if (datalen != EBT_ALIGN(sizeof(struct ebt_arpreply_info)))
58 if (BASE_CHAIN && info->target == EBT_RETURN)
60 if (e->ethproto != __constant_htons(ETH_P_ARP) ||
61 e->invflags & EBT_IPROTO)
64 if (strcmp(tablename, "nat") || hookmask & ~(1 << NF_BR_PRE_ROUTING))
69 static struct ebt_target reply_target =
71 .name = EBT_ARPREPLY_TARGET,
72 .target = ebt_target_reply,
73 .check = ebt_target_reply_check,
77 static int __init init(void)
79 return ebt_register_target(&reply_target);
82 static void __exit fini(void)
84 ebt_unregister_target(&reply_target);
89 MODULE_LICENSE("GPL");