blob: 8071b64af46f17524c386d6d2041cb49bf21b8d5 [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
19ebt_arpreply_tg(struct sk_buff *skb, const struct net_device *in,
20 const struct net_device *out, unsigned int hook_nr,
21 const struct xt_target *target, const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -070022{
Jan Engelhardtabfdf1c2008-01-31 03:59:24 -080023 struct ebt_arpreply_info *info = (void *)data;
24 const __be32 *siptr, *diptr;
25 __be32 _sip, _dip;
26 const struct arphdr *ap;
27 struct arphdr _ah;
28 const unsigned char *shp;
29 unsigned char _sha[ETH_ALEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
31 ap = skb_header_pointer(skb, 0, sizeof(_ah), &_ah);
32 if (ap == NULL)
33 return EBT_DROP;
34
35 if (ap->ar_op != htons(ARPOP_REQUEST) ||
36 ap->ar_hln != ETH_ALEN ||
37 ap->ar_pro != htons(ETH_P_IP) ||
38 ap->ar_pln != 4)
39 return EBT_CONTINUE;
40
41 shp = skb_header_pointer(skb, sizeof(_ah), ETH_ALEN, &_sha);
42 if (shp == NULL)
43 return EBT_DROP;
44
45 siptr = skb_header_pointer(skb, sizeof(_ah) + ETH_ALEN,
46 sizeof(_sip), &_sip);
47 if (siptr == NULL)
48 return EBT_DROP;
49
50 diptr = skb_header_pointer(skb,
51 sizeof(_ah) + 2 * ETH_ALEN + sizeof(_sip),
52 sizeof(_dip), &_dip);
53 if (diptr == NULL)
54 return EBT_DROP;
55
56 arp_send(ARPOP_REPLY, ETH_P_ARP, *siptr, (struct net_device *)in,
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +090057 *diptr, shp, info->mac, shp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
59 return info->target;
60}
61
Jan Engelhardt2d06d4a2008-10-08 11:35:15 +020062static bool
63ebt_arpreply_tg_check(const char *tablename, const void *entry,
64 const struct xt_target *target, void *data,
65 unsigned int hookmask)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066{
Jan Engelhardtabfdf1c2008-01-31 03:59:24 -080067 const struct ebt_arpreply_info *info = data;
Jan Engelhardt2d06d4a2008-10-08 11:35:15 +020068 const struct ebt_entry *e = entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 if (BASE_CHAIN && info->target == EBT_RETURN)
Jan Engelhardt19eda872008-10-08 11:35:13 +020071 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 if (e->ethproto != htons(ETH_P_ARP) ||
73 e->invflags & EBT_IPROTO)
Jan Engelhardt19eda872008-10-08 11:35:13 +020074 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 CLEAR_BASE_CHAIN_BIT;
76 if (strcmp(tablename, "nat") || hookmask & ~(1 << NF_BR_PRE_ROUTING))
Jan Engelhardt19eda872008-10-08 11:35:13 +020077 return false;
78 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079}
80
Jan Engelhardt043ef462008-10-08 11:35:15 +020081static struct xt_target ebt_arpreply_tg_reg __read_mostly = {
82 .name = "arpreply",
Jan Engelhardt001a18d2008-10-08 11:35:14 +020083 .revision = 0,
84 .family = NFPROTO_BRIDGE,
Jan Engelhardt2d06d4a2008-10-08 11:35:15 +020085 .target = ebt_arpreply_tg,
86 .checkentry = ebt_arpreply_tg_check,
Jan Engelhardt18219d32008-10-08 11:35:13 +020087 .targetsize = XT_ALIGN(sizeof(struct ebt_arpreply_info)),
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 .me = THIS_MODULE,
89};
90
Andrew Morton65b4b4e2006-03-28 16:37:06 -080091static int __init ebt_arpreply_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070092{
Jan Engelhardt043ef462008-10-08 11:35:15 +020093 return xt_register_target(&ebt_arpreply_tg_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094}
95
Andrew Morton65b4b4e2006-03-28 16:37:06 -080096static void __exit ebt_arpreply_fini(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070097{
Jan Engelhardt043ef462008-10-08 11:35:15 +020098 xt_unregister_target(&ebt_arpreply_tg_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099}
100
Andrew Morton65b4b4e2006-03-28 16:37:06 -0800101module_init(ebt_arpreply_init);
102module_exit(ebt_arpreply_fini);
Jan Engelhardtf776c4c2008-01-31 04:00:30 -0800103MODULE_DESCRIPTION("Ebtables: ARP reply target");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104MODULE_LICENSE("GPL");