2005-04-16 22:20:36 +00:00
|
|
|
/* Kernel module to match MAC address parameters. */
|
|
|
|
|
|
|
|
/* (C) 1999-2001 Paul `Rusty' Russell
|
|
|
|
* (C) 2002-2004 Netfilter Core Team <coreteam@netfilter.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/skbuff.h>
|
2010-03-16 20:44:44 +00:00
|
|
|
#include <linux/if_arp.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/if_ether.h>
|
2006-01-10 00:01:43 +00:00
|
|
|
#include <linux/etherdevice.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
[NETFILTER] x_tables: Abstraction layer for {ip,ip6,arp}_tables
This monster-patch tries to do the best job for unifying the data
structures and backend interfaces for the three evil clones ip_tables,
ip6_tables and arp_tables. In an ideal world we would never have
allowed this kind of copy+paste programming... but well, our world
isn't (yet?) ideal.
o introduce a new x_tables module
o {ip,arp,ip6}_tables depend on this x_tables module
o registration functions for tables, matches and targets are only
wrappers around x_tables provided functions
o all matches/targets that are used from ip_tables and ip6_tables
are now implemented as xt_FOOBAR.c files and provide module aliases
to ipt_FOOBAR and ip6t_FOOBAR
o header files for xt_matches are in include/linux/netfilter/,
include/linux/netfilter_{ipv4,ipv6} contains compatibility wrappers
around the xt_FOOBAR.h headers
Based on this patchset we're going to further unify the code,
gradually getting rid of all the layer 3 specific assumptions.
Signed-off-by: Harald Welte <laforge@netfilter.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2006-01-12 21:30:04 +00:00
|
|
|
#include <linux/netfilter_ipv4.h>
|
2007-02-12 19:14:43 +00:00
|
|
|
#include <linux/netfilter_ipv6.h>
|
[NETFILTER] x_tables: Abstraction layer for {ip,ip6,arp}_tables
This monster-patch tries to do the best job for unifying the data
structures and backend interfaces for the three evil clones ip_tables,
ip6_tables and arp_tables. In an ideal world we would never have
allowed this kind of copy+paste programming... but well, our world
isn't (yet?) ideal.
o introduce a new x_tables module
o {ip,arp,ip6}_tables depend on this x_tables module
o registration functions for tables, matches and targets are only
wrappers around x_tables provided functions
o all matches/targets that are used from ip_tables and ip6_tables
are now implemented as xt_FOOBAR.c files and provide module aliases
to ipt_FOOBAR and ip6t_FOOBAR
o header files for xt_matches are in include/linux/netfilter/,
include/linux/netfilter_{ipv4,ipv6} contains compatibility wrappers
around the xt_FOOBAR.h headers
Based on this patchset we're going to further unify the code,
gradually getting rid of all the layer 3 specific assumptions.
Signed-off-by: Harald Welte <laforge@netfilter.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2006-01-12 21:30:04 +00:00
|
|
|
#include <linux/netfilter/xt_mac.h>
|
|
|
|
#include <linux/netfilter/x_tables.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>");
|
2008-01-15 07:42:28 +00:00
|
|
|
MODULE_DESCRIPTION("Xtables: MAC address match");
|
[NETFILTER] x_tables: Abstraction layer for {ip,ip6,arp}_tables
This monster-patch tries to do the best job for unifying the data
structures and backend interfaces for the three evil clones ip_tables,
ip6_tables and arp_tables. In an ideal world we would never have
allowed this kind of copy+paste programming... but well, our world
isn't (yet?) ideal.
o introduce a new x_tables module
o {ip,arp,ip6}_tables depend on this x_tables module
o registration functions for tables, matches and targets are only
wrappers around x_tables provided functions
o all matches/targets that are used from ip_tables and ip6_tables
are now implemented as xt_FOOBAR.c files and provide module aliases
to ipt_FOOBAR and ip6t_FOOBAR
o header files for xt_matches are in include/linux/netfilter/,
include/linux/netfilter_{ipv4,ipv6} contains compatibility wrappers
around the xt_FOOBAR.h headers
Based on this patchset we're going to further unify the code,
gradually getting rid of all the layer 3 specific assumptions.
Signed-off-by: Harald Welte <laforge@netfilter.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2006-01-12 21:30:04 +00:00
|
|
|
MODULE_ALIAS("ipt_mac");
|
|
|
|
MODULE_ALIAS("ip6t_mac");
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2009-07-05 17:43:26 +00:00
|
|
|
static bool mac_mt(const struct sk_buff *skb,
|
|
|
|
const struct xt_action_param *par)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2010-03-16 20:09:04 +00:00
|
|
|
const struct xt_mac_info *info = par->matchinfo;
|
|
|
|
bool ret;
|
|
|
|
|
2010-03-16 20:44:44 +00:00
|
|
|
if (skb->dev == NULL || skb->dev->type != ARPHRD_ETHER)
|
|
|
|
return false;
|
2010-03-16 20:09:04 +00:00
|
|
|
if (skb_mac_header(skb) < skb->head)
|
|
|
|
return false;
|
|
|
|
if (skb_mac_header(skb) + ETH_HLEN > skb->data)
|
|
|
|
return false;
|
|
|
|
ret = compare_ether_addr(eth_hdr(skb)->h_source, info->srcaddr) == 0;
|
|
|
|
ret ^= info->invert;
|
|
|
|
return ret;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2008-10-08 09:35:20 +00:00
|
|
|
static struct xt_match mac_mt_reg __read_mostly = {
|
|
|
|
.name = "mac",
|
|
|
|
.revision = 0,
|
|
|
|
.family = NFPROTO_UNSPEC,
|
|
|
|
.match = mac_mt,
|
|
|
|
.matchsize = sizeof(struct xt_mac_info),
|
|
|
|
.hooks = (1 << NF_INET_PRE_ROUTING) | (1 << NF_INET_LOCAL_IN) |
|
|
|
|
(1 << NF_INET_FORWARD),
|
|
|
|
.me = THIS_MODULE,
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
2007-12-05 07:24:03 +00:00
|
|
|
static int __init mac_mt_init(void)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-10-08 09:35:20 +00:00
|
|
|
return xt_register_match(&mac_mt_reg);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2007-12-05 07:24:03 +00:00
|
|
|
static void __exit mac_mt_exit(void)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-10-08 09:35:20 +00:00
|
|
|
xt_unregister_match(&mac_mt_reg);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2007-12-05 07:24:03 +00:00
|
|
|
module_init(mac_mt_init);
|
|
|
|
module_exit(mac_mt_exit);
|