Commit | Line | Data |
---|---|---|
09c434b8 | 1 | // SPDX-License-Identifier: GPL-2.0-only |
1da177e4 LT |
2 | /* |
3 | * ebt_arpreply | |
4 | * | |
5 | * Authors: | |
6 | * Grzegorz Borowiak <grzes@gnu.univ.gda.pl> | |
7 | * Bart De Schuymer <bdschuym@pandora.be> | |
8 | * | |
9 | * August, 2003 | |
10 | * | |
11 | */ | |
1da177e4 LT |
12 | #include <linux/if_arp.h> |
13 | #include <net/arp.h> | |
14 | #include <linux/module.h> | |
18219d3f JE |
15 | #include <linux/netfilter/x_tables.h> |
16 | #include <linux/netfilter_bridge/ebtables.h> | |
17 | #include <linux/netfilter_bridge/ebt_arpreply.h> | |
1da177e4 | 18 | |
2d06d4a5 | 19 | static unsigned int |
4b560b44 | 20 | ebt_arpreply_tg(struct sk_buff *skb, const struct xt_action_param *par) |
1da177e4 | 21 | { |
7eb35586 | 22 | const struct ebt_arpreply_info *info = par->targinfo; |
abfdf1c4 JE |
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]; | |
1da177e4 LT |
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 | ||
613dbd95 PNA |
55 | arp_send(ARPOP_REPLY, ETH_P_ARP, *siptr, |
56 | (struct net_device *)xt_in(par), | |
9d6f229f | 57 | *diptr, shp, info->mac, shp); |
1da177e4 LT |
58 | |
59 | return info->target; | |
60 | } | |
61 | ||
135367b8 | 62 | static int ebt_arpreply_tg_check(const struct xt_tgchk_param *par) |
1da177e4 | 63 | { |
af5d6dc2 JE |
64 | const struct ebt_arpreply_info *info = par->targinfo; |
65 | const struct ebt_entry *e = par->entryinfo; | |
1da177e4 | 66 | |
1da177e4 | 67 | if (BASE_CHAIN && info->target == EBT_RETURN) |
d6b00a53 | 68 | return -EINVAL; |
1da177e4 LT |
69 | if (e->ethproto != htons(ETH_P_ARP) || |
70 | e->invflags & EBT_IPROTO) | |
d6b00a53 | 71 | return -EINVAL; |
c953d635 GF |
72 | if (ebt_invalid_target(info->target)) |
73 | return -EINVAL; | |
74 | ||
d6b00a53 | 75 | return 0; |
1da177e4 LT |
76 | } |
77 | ||
043ef46c JE |
78 | static struct xt_target ebt_arpreply_tg_reg __read_mostly = { |
79 | .name = "arpreply", | |
001a18d3 JE |
80 | .revision = 0, |
81 | .family = NFPROTO_BRIDGE, | |
f2ff525c JE |
82 | .table = "nat", |
83 | .hooks = (1 << NF_BR_NUMHOOKS) | (1 << NF_BR_PRE_ROUTING), | |
2d06d4a5 JE |
84 | .target = ebt_arpreply_tg, |
85 | .checkentry = ebt_arpreply_tg_check, | |
fc0e3df4 | 86 | .targetsize = sizeof(struct ebt_arpreply_info), |
1da177e4 LT |
87 | .me = THIS_MODULE, |
88 | }; | |
89 | ||
65b4b4e8 | 90 | static int __init ebt_arpreply_init(void) |
1da177e4 | 91 | { |
043ef46c | 92 | return xt_register_target(&ebt_arpreply_tg_reg); |
1da177e4 LT |
93 | } |
94 | ||
65b4b4e8 | 95 | static void __exit ebt_arpreply_fini(void) |
1da177e4 | 96 | { |
043ef46c | 97 | xt_unregister_target(&ebt_arpreply_tg_reg); |
1da177e4 LT |
98 | } |
99 | ||
65b4b4e8 AM |
100 | module_init(ebt_arpreply_init); |
101 | module_exit(ebt_arpreply_fini); | |
f776c4cd | 102 | MODULE_DESCRIPTION("Ebtables: ARP reply target"); |
1da177e4 | 103 | MODULE_LICENSE("GPL"); |