]> bbs.cooldavid.org Git - net-next-2.6.git/blame - net/netfilter/xt_mac.c
netfilter: xtables: substitute temporary defines by final name
[net-next-2.6.git] / net / netfilter / xt_mac.c
CommitLineData
1da177e4
LT
1/* Kernel module to match MAC address parameters. */
2
3/* (C) 1999-2001 Paul `Rusty' Russell
4 * (C) 2002-2004 Netfilter Core Team <coreteam@netfilter.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#include <linux/module.h>
12#include <linux/skbuff.h>
e5042a29 13#include <linux/if_arp.h>
1da177e4 14#include <linux/if_ether.h>
d3f4a687 15#include <linux/etherdevice.h>
1da177e4 16
2e4e6a17 17#include <linux/netfilter_ipv4.h>
891350c9 18#include <linux/netfilter_ipv6.h>
2e4e6a17
HW
19#include <linux/netfilter/xt_mac.h>
20#include <linux/netfilter/x_tables.h>
1da177e4
LT
21
22MODULE_LICENSE("GPL");
23MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>");
2ae15b64 24MODULE_DESCRIPTION("Xtables: MAC address match");
2e4e6a17
HW
25MODULE_ALIAS("ipt_mac");
26MODULE_ALIAS("ip6t_mac");
1da177e4 27
4b560b44
JE
28static bool mac_mt(const struct sk_buff *skb,
29 const struct xt_action_param *par)
1da177e4 30{
1d1c397d
JE
31 const struct xt_mac_info *info = par->matchinfo;
32 bool ret;
33
e5042a29
JE
34 if (skb->dev == NULL || skb->dev->type != ARPHRD_ETHER)
35 return false;
1d1c397d
JE
36 if (skb_mac_header(skb) < skb->head)
37 return false;
38 if (skb_mac_header(skb) + ETH_HLEN > skb->data)
39 return false;
40 ret = compare_ether_addr(eth_hdr(skb)->h_source, info->srcaddr) == 0;
41 ret ^= info->invert;
42 return ret;
1da177e4
LT
43}
44
ab4f21e6
JE
45static struct xt_match mac_mt_reg __read_mostly = {
46 .name = "mac",
47 .revision = 0,
48 .family = NFPROTO_UNSPEC,
49 .match = mac_mt,
50 .matchsize = sizeof(struct xt_mac_info),
51 .hooks = (1 << NF_INET_PRE_ROUTING) | (1 << NF_INET_LOCAL_IN) |
52 (1 << NF_INET_FORWARD),
53 .me = THIS_MODULE,
1da177e4
LT
54};
55
d3c5ee6d 56static int __init mac_mt_init(void)
1da177e4 57{
ab4f21e6 58 return xt_register_match(&mac_mt_reg);
1da177e4
LT
59}
60
d3c5ee6d 61static void __exit mac_mt_exit(void)
1da177e4 62{
ab4f21e6 63 xt_unregister_match(&mac_mt_reg);
1da177e4
LT
64}
65
d3c5ee6d
JE
66module_init(mac_mt_init);
67module_exit(mac_mt_exit);