blob: 070cf134a22f983c915c488a48b09d942e16fcce [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * ebt_arpreply
3 *
4 * Authors:
5 * Grzegorz Borowiak <grzes@gnu.univ.gda.pl>
6 * Bart De Schuymer <bdschuym@pandora.be>
7 *
8 * August, 2003
9 *
10 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/if_arp.h>
12#include <net/arp.h>
13#include <linux/module.h>
Jan Engelhardt18219d32008-10-08 11:35:13 +020014#include <linux/netfilter/x_tables.h>
15#include <linux/netfilter_bridge/ebtables.h>
16#include <linux/netfilter_bridge/ebt_arpreply.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
Jan Engelhardt2d06d4a2008-10-08 11:35:15 +020018static unsigned int
Jan Engelhardt4b560b42009-07-05 19:43:26 +020019ebt_arpreply_tg(struct sk_buff *skb, const struct xt_action_param *par)
Linus Torvalds1da177e2005-04-16 15:20:36 -070020{
Jan Engelhardt7eb35582008-10-08 11:35:19 +020021 const struct ebt_arpreply_info *info = par->targinfo;
Jan Engelhardtabfdf1c2008-01-31 03:59:24 -080022 const __be32 *siptr, *diptr;
23 __be32 _sip, _dip;
24 const struct arphdr *ap;
25 struct arphdr _ah;
26 const unsigned char *shp;
27 unsigned char _sha[ETH_ALEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
29 ap = skb_header_pointer(skb, 0, sizeof(_ah), &_ah);
30 if (ap == NULL)
31 return EBT_DROP;
32
33 if (ap->ar_op != htons(ARPOP_REQUEST) ||
34 ap->ar_hln != ETH_ALEN ||
35 ap->ar_pro != htons(ETH_P_IP) ||
36 ap->ar_pln != 4)
37 return EBT_CONTINUE;
38
39 shp = skb_header_pointer(skb, sizeof(_ah), ETH_ALEN, &_sha);
40 if (shp == NULL)
41 return EBT_DROP;
42
43 siptr = skb_header_pointer(skb, sizeof(_ah) + ETH_ALEN,
44 sizeof(_sip), &_sip);
45 if (siptr == NULL)
46 return EBT_DROP;
47
48 diptr = skb_header_pointer(skb,
49 sizeof(_ah) + 2 * ETH_ALEN + sizeof(_sip),
50 sizeof(_dip), &_dip);
51 if (diptr == NULL)
52 return EBT_DROP;
53
Jan Engelhardt7eb35582008-10-08 11:35:19 +020054 arp_send(ARPOP_REPLY, ETH_P_ARP, *siptr, (struct net_device *)par->in,
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +090055 *diptr, shp, info->mac, shp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
57 return info->target;
58}
59
Jan Engelhardt135367b2010-03-19 17:16:42 +010060static int ebt_arpreply_tg_check(const struct xt_tgchk_param *par)
Linus Torvalds1da177e2005-04-16 15:20:36 -070061{
Jan Engelhardtaf5d6dc2008-10-08 11:35:19 +020062 const struct ebt_arpreply_info *info = par->targinfo;
63 const struct ebt_entry *e = par->entryinfo;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 if (BASE_CHAIN && info->target == EBT_RETURN)
Jan Engelhardtd6b00a52010-03-25 16:34:45 +010066 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 if (e->ethproto != htons(ETH_P_ARP) ||
68 e->invflags & EBT_IPROTO)
Jan Engelhardtd6b00a52010-03-25 16:34:45 +010069 return -EINVAL;
70 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071}
72
Jan Engelhardt043ef462008-10-08 11:35:15 +020073static struct xt_target ebt_arpreply_tg_reg __read_mostly = {
74 .name = "arpreply",
Jan Engelhardt001a18d2008-10-08 11:35:14 +020075 .revision = 0,
76 .family = NFPROTO_BRIDGE,
Jan Engelhardtf2ff5252008-10-08 11:35:15 +020077 .table = "nat",
78 .hooks = (1 << NF_BR_NUMHOOKS) | (1 << NF_BR_PRE_ROUTING),
Jan Engelhardt2d06d4a2008-10-08 11:35:15 +020079 .target = ebt_arpreply_tg,
80 .checkentry = ebt_arpreply_tg_check,
Florian Westphalfc0e3df2010-02-15 18:16:26 +010081 .targetsize = sizeof(struct ebt_arpreply_info),
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 .me = THIS_MODULE,
83};
84
Andrew Morton65b4b4e2006-03-28 16:37:06 -080085static int __init ebt_arpreply_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070086{
Jan Engelhardt043ef462008-10-08 11:35:15 +020087 return xt_register_target(&ebt_arpreply_tg_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088}
89
Andrew Morton65b4b4e2006-03-28 16:37:06 -080090static void __exit ebt_arpreply_fini(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070091{
Jan Engelhardt043ef462008-10-08 11:35:15 +020092 xt_unregister_target(&ebt_arpreply_tg_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093}
94
Andrew Morton65b4b4e2006-03-28 16:37:06 -080095module_init(ebt_arpreply_init);
96module_exit(ebt_arpreply_fini);
Jan Engelhardtf776c4c2008-01-31 04:00:30 -080097MODULE_DESCRIPTION("Ebtables: ARP reply target");
Linus Torvalds1da177e2005-04-16 15:20:36 -070098MODULE_LICENSE("GPL");