0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include <linux/if_arp.h>
0013 #include <net/arp.h>
0014 #include <linux/module.h>
0015 #include <linux/netfilter/x_tables.h>
0016 #include <linux/netfilter_bridge/ebtables.h>
0017 #include <linux/netfilter_bridge/ebt_arpreply.h>
0018
0019 static unsigned int
0020 ebt_arpreply_tg(struct sk_buff *skb, const struct xt_action_param *par)
0021 {
0022 const struct ebt_arpreply_info *info = par->targinfo;
0023 const __be32 *siptr, *diptr;
0024 __be32 _sip, _dip;
0025 const struct arphdr *ap;
0026 struct arphdr _ah;
0027 const unsigned char *shp;
0028 unsigned char _sha[ETH_ALEN];
0029
0030 ap = skb_header_pointer(skb, 0, sizeof(_ah), &_ah);
0031 if (ap == NULL)
0032 return EBT_DROP;
0033
0034 if (ap->ar_op != htons(ARPOP_REQUEST) ||
0035 ap->ar_hln != ETH_ALEN ||
0036 ap->ar_pro != htons(ETH_P_IP) ||
0037 ap->ar_pln != 4)
0038 return EBT_CONTINUE;
0039
0040 shp = skb_header_pointer(skb, sizeof(_ah), ETH_ALEN, &_sha);
0041 if (shp == NULL)
0042 return EBT_DROP;
0043
0044 siptr = skb_header_pointer(skb, sizeof(_ah) + ETH_ALEN,
0045 sizeof(_sip), &_sip);
0046 if (siptr == NULL)
0047 return EBT_DROP;
0048
0049 diptr = skb_header_pointer(skb,
0050 sizeof(_ah) + 2 * ETH_ALEN + sizeof(_sip),
0051 sizeof(_dip), &_dip);
0052 if (diptr == NULL)
0053 return EBT_DROP;
0054
0055 arp_send(ARPOP_REPLY, ETH_P_ARP, *siptr,
0056 (struct net_device *)xt_in(par),
0057 *diptr, shp, info->mac, shp);
0058
0059 return info->target;
0060 }
0061
0062 static int ebt_arpreply_tg_check(const struct xt_tgchk_param *par)
0063 {
0064 const struct ebt_arpreply_info *info = par->targinfo;
0065 const struct ebt_entry *e = par->entryinfo;
0066
0067 if (BASE_CHAIN && info->target == EBT_RETURN)
0068 return -EINVAL;
0069 if (e->ethproto != htons(ETH_P_ARP) ||
0070 e->invflags & EBT_IPROTO)
0071 return -EINVAL;
0072 if (ebt_invalid_target(info->target))
0073 return -EINVAL;
0074
0075 return 0;
0076 }
0077
0078 static struct xt_target ebt_arpreply_tg_reg __read_mostly = {
0079 .name = "arpreply",
0080 .revision = 0,
0081 .family = NFPROTO_BRIDGE,
0082 .table = "nat",
0083 .hooks = (1 << NF_BR_NUMHOOKS) | (1 << NF_BR_PRE_ROUTING),
0084 .target = ebt_arpreply_tg,
0085 .checkentry = ebt_arpreply_tg_check,
0086 .targetsize = sizeof(struct ebt_arpreply_info),
0087 .me = THIS_MODULE,
0088 };
0089
0090 static int __init ebt_arpreply_init(void)
0091 {
0092 return xt_register_target(&ebt_arpreply_tg_reg);
0093 }
0094
0095 static void __exit ebt_arpreply_fini(void)
0096 {
0097 xt_unregister_target(&ebt_arpreply_tg_reg);
0098 }
0099
0100 module_init(ebt_arpreply_init);
0101 module_exit(ebt_arpreply_fini);
0102 MODULE_DESCRIPTION("Ebtables: ARP reply target");
0103 MODULE_LICENSE("GPL");