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
12 #include <linux/netfilter_bridge/ebtables.h>
13 #include <linux/netfilter_bridge/ebt_arpreply.h>
14 #include <linux/if_arp.h>
15 #include <net/arp.h>
16 #include <linux/module.h>
17
18 static int ebt_target_reply(struct sk_buff *skb, unsigned int hooknr,
19 const struct net_device *in, const struct net_device *out,
20 const void *data, unsigned int datalen)
21 {
22 struct ebt_arpreply_info *info = (void *)data;
23 const __be32 *siptr, *diptr;
24 __be32 _sip, _dip;
25 const struct arphdr *ap;
26 struct arphdr _ah;
27 const unsigned char *shp;
28 unsigned char _sha[ETH_ALEN];
29
30 ap = skb_header_pointer(skb, 0, sizeof(_ah), &_ah);
31 if (ap == NULL)
32 return EBT_DROP;
33
34 if (ap->ar_op != htons(ARPOP_REQUEST) ||
35 ap->ar_hln != ETH_ALEN ||
36 ap->ar_pro != htons(ETH_P_IP) ||
37 ap->ar_pln != 4)
38 return EBT_CONTINUE;
39
40 shp = skb_header_pointer(skb, sizeof(_ah), ETH_ALEN, &_sha);
41 if (shp == NULL)
42 return EBT_DROP;
43
44 siptr = skb_header_pointer(skb, sizeof(_ah) + ETH_ALEN,
45 sizeof(_sip), &_sip);
46 if (siptr == NULL)
47 return EBT_DROP;
48
49 diptr = skb_header_pointer(skb,
50 sizeof(_ah) + 2 * ETH_ALEN + sizeof(_sip),
51 sizeof(_dip), &_dip);
52 if (diptr == NULL)
53 return EBT_DROP;
54
55 arp_send(ARPOP_REPLY, ETH_P_ARP, *siptr, (struct net_device *)in,
56 *diptr, shp, info->mac, shp);
57
58 return info->target;
59 }
60
61 static int ebt_target_reply_check(const char *tablename, unsigned int hookmask,
62 const struct ebt_entry *e, void *data, unsigned int datalen)
63 {
64 const struct ebt_arpreply_info *info = data;
65
66 if (datalen != EBT_ALIGN(sizeof(struct ebt_arpreply_info)))
67 return -EINVAL;
68 if (BASE_CHAIN && info->target == EBT_RETURN)
69 return -EINVAL;
70 if (e->ethproto != htons(ETH_P_ARP) ||
71 e->invflags & EBT_IPROTO)
72 return -EINVAL;
73 CLEAR_BASE_CHAIN_BIT;
74 if (strcmp(tablename, "nat") || hookmask & ~(1 << NF_BR_PRE_ROUTING))
75 return -EINVAL;
76 return 0;
77 }
78
79 static struct ebt_target reply_target __read_mostly = {
80 .name = EBT_ARPREPLY_TARGET,
81 .target = ebt_target_reply,
82 .check = ebt_target_reply_check,
83 .me = THIS_MODULE,
84 };
85
86 static int __init ebt_arpreply_init(void)
87 {
88 return ebt_register_target(&reply_target);
89 }
90
91 static void __exit ebt_arpreply_fini(void)
92 {
93 ebt_unregister_target(&reply_target);
94 }
95
96 module_init(ebt_arpreply_init);
97 module_exit(ebt_arpreply_fini);
98 MODULE_DESCRIPTION("Ebtables: ARP reply target");
99 MODULE_LICENSE("GPL");
100
|
This page was automatically generated by the
LXR engine.
|