netfilter: move Ebtables to use Xtables
[linux-2.6/kvm.git] / net / bridge / netfilter / ebt_arpreply.c
blob8071b64af46f17524c386d6d2041cb49bf21b8d5
1 /*
2 * ebt_arpreply
4 * Authors:
5 * Grzegorz Borowiak <grzes@gnu.univ.gda.pl>
6 * Bart De Schuymer <bdschuym@pandora.be>
8 * August, 2003
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>
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)
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];
31 ap = skb_header_pointer(skb, 0, sizeof(_ah), &_ah);
32 if (ap == NULL)
33 return EBT_DROP;
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;
41 shp = skb_header_pointer(skb, sizeof(_ah), ETH_ALEN, &_sha);
42 if (shp == NULL)
43 return EBT_DROP;
45 siptr = skb_header_pointer(skb, sizeof(_ah) + ETH_ALEN,
46 sizeof(_sip), &_sip);
47 if (siptr == NULL)
48 return EBT_DROP;
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;
56 arp_send(ARPOP_REPLY, ETH_P_ARP, *siptr, (struct net_device *)in,
57 *diptr, shp, info->mac, shp);
59 return info->target;
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)
67 const struct ebt_arpreply_info *info = data;
68 const struct ebt_entry *e = entry;
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;
81 static struct xt_target ebt_arpreply_tg_reg __read_mostly = {
82 .name = "arpreply",
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,
91 static int __init ebt_arpreply_init(void)
93 return xt_register_target(&ebt_arpreply_tg_reg);
96 static void __exit ebt_arpreply_fini(void)
98 xt_unregister_target(&ebt_arpreply_tg_reg);
101 module_init(ebt_arpreply_init);
102 module_exit(ebt_arpreply_fini);
103 MODULE_DESCRIPTION("Ebtables: ARP reply target");
104 MODULE_LICENSE("GPL");