netfilter: xtables: move extension arguments into compound structure (4/6)
[linux-2.6-block.git] / net / bridge / netfilter / ebt_arpreply.c
CommitLineData
1da177e4
LT
1/*
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 */
1da177e4
LT
11#include <linux/if_arp.h>
12#include <net/arp.h>
13#include <linux/module.h>
18219d3f
JE
14#include <linux/netfilter/x_tables.h>
15#include <linux/netfilter_bridge/ebtables.h>
16#include <linux/netfilter_bridge/ebt_arpreply.h>
1da177e4 17
2d06d4a5 18static unsigned int
7eb35586 19ebt_arpreply_tg(struct sk_buff *skb, const struct xt_target_param *par)
1da177e4 20{
7eb35586 21 const struct ebt_arpreply_info *info = par->targinfo;
abfdf1c4
JE
22 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];
1da177e4
LT
28
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
7eb35586 54 arp_send(ARPOP_REPLY, ETH_P_ARP, *siptr, (struct net_device *)par->in,
9d6f229f 55 *diptr, shp, info->mac, shp);
1da177e4
LT
56
57 return info->target;
58}
59
2d06d4a5
JE
60static bool
61ebt_arpreply_tg_check(const char *tablename, const void *entry,
62 const struct xt_target *target, void *data,
63 unsigned int hookmask)
1da177e4 64{
abfdf1c4 65 const struct ebt_arpreply_info *info = data;
2d06d4a5 66 const struct ebt_entry *e = entry;
1da177e4 67
1da177e4 68 if (BASE_CHAIN && info->target == EBT_RETURN)
19eda879 69 return false;
1da177e4
LT
70 if (e->ethproto != htons(ETH_P_ARP) ||
71 e->invflags & EBT_IPROTO)
19eda879 72 return false;
1da177e4 73 CLEAR_BASE_CHAIN_BIT;
19eda879 74 return true;
1da177e4
LT
75}
76
043ef46c
JE
77static struct xt_target ebt_arpreply_tg_reg __read_mostly = {
78 .name = "arpreply",
001a18d3
JE
79 .revision = 0,
80 .family = NFPROTO_BRIDGE,
f2ff525c
JE
81 .table = "nat",
82 .hooks = (1 << NF_BR_NUMHOOKS) | (1 << NF_BR_PRE_ROUTING),
2d06d4a5
JE
83 .target = ebt_arpreply_tg,
84 .checkentry = ebt_arpreply_tg_check,
18219d3f 85 .targetsize = XT_ALIGN(sizeof(struct ebt_arpreply_info)),
1da177e4
LT
86 .me = THIS_MODULE,
87};
88
65b4b4e8 89static int __init ebt_arpreply_init(void)
1da177e4 90{
043ef46c 91 return xt_register_target(&ebt_arpreply_tg_reg);
1da177e4
LT
92}
93
65b4b4e8 94static void __exit ebt_arpreply_fini(void)
1da177e4 95{
043ef46c 96 xt_unregister_target(&ebt_arpreply_tg_reg);
1da177e4
LT
97}
98
65b4b4e8
AM
99module_init(ebt_arpreply_init);
100module_exit(ebt_arpreply_fini);
f776c4cd 101MODULE_DESCRIPTION("Ebtables: ARP reply target");
1da177e4 102MODULE_LICENSE("GPL");