netfilter: change Ebtables function signatures to match Xtables's
[safe/jmp/linux-2.6] / net / bridge / netfilter / ebt_arpreply.c
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  */
11 #include <linux/if_arp.h>
12 #include <net/arp.h>
13 #include <linux/module.h>
14 #include <linux/netfilter/x_tables.h>
15 #include <linux/netfilter_bridge/ebtables.h>
16 #include <linux/netfilter_bridge/ebt_arpreply.h>
17
18 static unsigned int
19 ebt_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)
22 {
23         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];
30
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,
57                  *diptr, shp, info->mac, shp);
58
59         return info->target;
60 }
61
62 static bool
63 ebt_arpreply_tg_check(const char *tablename, const void *entry,
64                       const struct xt_target *target, void *data,
65                       unsigned int hookmask)
66 {
67         const struct ebt_arpreply_info *info = data;
68         const struct ebt_entry *e = entry;
69
70         if (BASE_CHAIN && info->target == EBT_RETURN)
71                 return false;
72         if (e->ethproto != htons(ETH_P_ARP) ||
73             e->invflags & EBT_IPROTO)
74                 return false;
75         CLEAR_BASE_CHAIN_BIT;
76         if (strcmp(tablename, "nat") || hookmask & ~(1 << NF_BR_PRE_ROUTING))
77                 return false;
78         return true;
79 }
80
81 static struct ebt_target reply_target __read_mostly = {
82         .name           = EBT_ARPREPLY_TARGET,
83         .revision       = 0,
84         .family         = NFPROTO_BRIDGE,
85         .target         = ebt_arpreply_tg,
86         .checkentry     = ebt_arpreply_tg_check,
87         .targetsize     = XT_ALIGN(sizeof(struct ebt_arpreply_info)),
88         .me             = THIS_MODULE,
89 };
90
91 static int __init ebt_arpreply_init(void)
92 {
93         return ebt_register_target(&reply_target);
94 }
95
96 static void __exit ebt_arpreply_fini(void)
97 {
98         ebt_unregister_target(&reply_target);
99 }
100
101 module_init(ebt_arpreply_init);
102 module_exit(ebt_arpreply_fini);
103 MODULE_DESCRIPTION("Ebtables: ARP reply target");
104 MODULE_LICENSE("GPL");