2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* ebt_arp
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Bart De Schuymer <bdschuym@pandora.be>
|
|
|
|
* Tim Gardner <timg@tpi.com>
|
|
|
|
*
|
|
|
|
* April, 2002
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include <linux/if_arp.h>
|
|
|
|
#include <linux/if_ether.h>
|
|
|
|
#include <linux/module.h>
|
2008-10-08 11:35:13 +02:00
|
|
|
#include <linux/netfilter/x_tables.h>
|
|
|
|
#include <linux/netfilter_bridge/ebtables.h>
|
|
|
|
#include <linux/netfilter_bridge/ebt_arp.h>
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2008-10-08 11:35:15 +02:00
|
|
|
static bool
|
2009-07-07 20:42:08 +02:00
|
|
|
ebt_arp_mt(const struct sk_buff *skb, struct xt_action_param *par)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2008-10-08 11:35:18 +02:00
|
|
|
const struct ebt_arp_info *info = par->matchinfo;
|
2008-01-31 12:59:24 +01:00
|
|
|
const struct arphdr *ah;
|
|
|
|
struct arphdr _arph;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
ah = skb_header_pointer(skb, 0, sizeof(_arph), &_arph);
|
|
|
|
if (ah == NULL)
|
2008-10-08 11:35:13 +02:00
|
|
|
return false;
|
2005-04-17 00:20:36 +02:00
|
|
|
if (info->bitmask & EBT_ARP_OPCODE && FWINV(info->opcode !=
|
|
|
|
ah->ar_op, EBT_ARP_OPCODE))
|
2008-10-08 11:35:13 +02:00
|
|
|
return false;
|
2005-04-17 00:20:36 +02:00
|
|
|
if (info->bitmask & EBT_ARP_HTYPE && FWINV(info->htype !=
|
|
|
|
ah->ar_hrd, EBT_ARP_HTYPE))
|
2008-10-08 11:35:13 +02:00
|
|
|
return false;
|
2005-04-17 00:20:36 +02:00
|
|
|
if (info->bitmask & EBT_ARP_PTYPE && FWINV(info->ptype !=
|
|
|
|
ah->ar_pro, EBT_ARP_PTYPE))
|
2008-10-08 11:35:13 +02:00
|
|
|
return false;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2007-11-06 05:59:47 +01:00
|
|
|
if (info->bitmask & (EBT_ARP_SRC_IP | EBT_ARP_DST_IP | EBT_ARP_GRAT)) {
|
2008-01-31 12:59:24 +01:00
|
|
|
const __be32 *sap, *dap;
|
|
|
|
__be32 saddr, daddr;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2007-04-13 07:15:06 +02:00
|
|
|
if (ah->ar_pln != sizeof(__be32) || ah->ar_pro != htons(ETH_P_IP))
|
2008-10-08 11:35:13 +02:00
|
|
|
return false;
|
2007-04-13 07:15:06 +02:00
|
|
|
sap = skb_header_pointer(skb, sizeof(struct arphdr) +
|
|
|
|
ah->ar_hln, sizeof(saddr),
|
|
|
|
&saddr);
|
|
|
|
if (sap == NULL)
|
2008-10-08 11:35:13 +02:00
|
|
|
return false;
|
2007-04-13 07:15:06 +02:00
|
|
|
dap = skb_header_pointer(skb, sizeof(struct arphdr) +
|
|
|
|
2*ah->ar_hln+sizeof(saddr),
|
|
|
|
sizeof(daddr), &daddr);
|
|
|
|
if (dap == NULL)
|
2008-10-08 11:35:13 +02:00
|
|
|
return false;
|
2007-04-13 07:15:06 +02:00
|
|
|
if (info->bitmask & EBT_ARP_SRC_IP &&
|
|
|
|
FWINV(info->saddr != (*sap & info->smsk), EBT_ARP_SRC_IP))
|
2008-10-08 11:35:13 +02:00
|
|
|
return false;
|
2007-04-13 07:15:06 +02:00
|
|
|
if (info->bitmask & EBT_ARP_DST_IP &&
|
|
|
|
FWINV(info->daddr != (*dap & info->dmsk), EBT_ARP_DST_IP))
|
2008-10-08 11:35:13 +02:00
|
|
|
return false;
|
2007-04-13 07:15:06 +02:00
|
|
|
if (info->bitmask & EBT_ARP_GRAT &&
|
|
|
|
FWINV(*dap != *sap, EBT_ARP_GRAT))
|
2008-10-08 11:35:13 +02:00
|
|
|
return false;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (info->bitmask & (EBT_ARP_SRC_MAC | EBT_ARP_DST_MAC)) {
|
2008-01-31 12:59:24 +01:00
|
|
|
const unsigned char *mp;
|
|
|
|
unsigned char _mac[ETH_ALEN];
|
2005-04-17 00:20:36 +02:00
|
|
|
uint8_t verdict, i;
|
|
|
|
|
2007-04-13 07:15:06 +02:00
|
|
|
if (ah->ar_hln != ETH_ALEN || ah->ar_hrd != htons(ARPHRD_ETHER))
|
2008-10-08 11:35:13 +02:00
|
|
|
return false;
|
2005-04-17 00:20:36 +02:00
|
|
|
if (info->bitmask & EBT_ARP_SRC_MAC) {
|
|
|
|
mp = skb_header_pointer(skb, sizeof(struct arphdr),
|
|
|
|
sizeof(_mac), &_mac);
|
|
|
|
if (mp == NULL)
|
2008-10-08 11:35:13 +02:00
|
|
|
return false;
|
2005-04-17 00:20:36 +02:00
|
|
|
verdict = 0;
|
|
|
|
for (i = 0; i < 6; i++)
|
|
|
|
verdict |= (mp[i] ^ info->smaddr[i]) &
|
|
|
|
info->smmsk[i];
|
|
|
|
if (FWINV(verdict != 0, EBT_ARP_SRC_MAC))
|
2008-10-08 11:35:13 +02:00
|
|
|
return false;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (info->bitmask & EBT_ARP_DST_MAC) {
|
|
|
|
mp = skb_header_pointer(skb, sizeof(struct arphdr) +
|
|
|
|
ah->ar_hln + ah->ar_pln,
|
|
|
|
sizeof(_mac), &_mac);
|
|
|
|
if (mp == NULL)
|
2008-10-08 11:35:13 +02:00
|
|
|
return false;
|
2005-04-17 00:20:36 +02:00
|
|
|
verdict = 0;
|
|
|
|
for (i = 0; i < 6; i++)
|
|
|
|
verdict |= (mp[i] ^ info->dmaddr[i]) &
|
|
|
|
info->dmmsk[i];
|
|
|
|
if (FWINV(verdict != 0, EBT_ARP_DST_MAC))
|
2008-10-08 11:35:13 +02:00
|
|
|
return false;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-08 11:35:13 +02:00
|
|
|
return true;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
2010-03-19 17:16:42 +01:00
|
|
|
static int ebt_arp_mt_check(const struct xt_mtchk_param *par)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2008-10-08 11:35:18 +02:00
|
|
|
const struct ebt_arp_info *info = par->matchinfo;
|
|
|
|
const struct ebt_entry *e = par->entryinfo;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
if ((e->ethproto != htons(ETH_P_ARP) &&
|
|
|
|
e->ethproto != htons(ETH_P_RARP)) ||
|
|
|
|
e->invflags & EBT_IPROTO)
|
2010-03-23 16:35:56 +01:00
|
|
|
return -EINVAL;
|
2005-04-17 00:20:36 +02:00
|
|
|
if (info->bitmask & ~EBT_ARP_MASK || info->invflags & ~EBT_ARP_MASK)
|
2010-03-23 16:35:56 +01:00
|
|
|
return -EINVAL;
|
|
|
|
return 0;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
2008-10-08 11:35:15 +02:00
|
|
|
static struct xt_match ebt_arp_mt_reg __read_mostly = {
|
|
|
|
.name = "arp",
|
2008-10-08 11:35:14 +02:00
|
|
|
.revision = 0,
|
|
|
|
.family = NFPROTO_BRIDGE,
|
2008-10-08 11:35:15 +02:00
|
|
|
.match = ebt_arp_mt,
|
|
|
|
.checkentry = ebt_arp_mt_check,
|
2010-02-15 18:16:26 +01:00
|
|
|
.matchsize = sizeof(struct ebt_arp_info),
|
2005-04-17 00:20:36 +02:00
|
|
|
.me = THIS_MODULE,
|
|
|
|
};
|
|
|
|
|
2006-03-29 02:37:06 +02:00
|
|
|
static int __init ebt_arp_init(void)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2008-10-08 11:35:15 +02:00
|
|
|
return xt_register_match(&ebt_arp_mt_reg);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
2006-03-29 02:37:06 +02:00
|
|
|
static void __exit ebt_arp_fini(void)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2008-10-08 11:35:15 +02:00
|
|
|
xt_unregister_match(&ebt_arp_mt_reg);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
2006-03-29 02:37:06 +02:00
|
|
|
module_init(ebt_arp_init);
|
|
|
|
module_exit(ebt_arp_fini);
|
2008-01-31 13:00:30 +01:00
|
|
|
MODULE_DESCRIPTION("Ebtables: ARP protocol packet match");
|
2005-04-17 00:20:36 +02:00
|
|
|
MODULE_LICENSE("GPL");
|