Linux-2.6.12-rc2
[linux-flexiantxendom0-natty.git] / net / ipv4 / netfilter / ipt_pkttype.c
1 /* (C) 1999-2001 Michal Ludvig <michal@logix.cz>
2  *
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License version 2 as
5  * published by the Free Software Foundation.
6  */
7
8 #include <linux/module.h>
9 #include <linux/skbuff.h>
10 #include <linux/if_ether.h>
11 #include <linux/if_packet.h>
12
13 #include <linux/netfilter_ipv4/ipt_pkttype.h>
14 #include <linux/netfilter_ipv4/ip_tables.h>
15
16 MODULE_LICENSE("GPL");
17 MODULE_AUTHOR("Michal Ludvig <michal@logix.cz>");
18 MODULE_DESCRIPTION("IP tables match to match on linklayer packet type");
19
20 static int match(const struct sk_buff *skb,
21       const struct net_device *in,
22       const struct net_device *out,
23       const void *matchinfo,
24       int offset,
25       int *hotdrop)
26 {
27     const struct ipt_pkttype_info *info = matchinfo;
28
29     return (skb->pkt_type == info->pkttype) ^ info->invert;
30 }
31
32 static int checkentry(const char *tablename,
33                    const struct ipt_ip *ip,
34                    void *matchinfo,
35                    unsigned int matchsize,
36                    unsigned int hook_mask)
37 {
38 /*
39         if (hook_mask
40             & ~((1 << NF_IP_PRE_ROUTING) | (1 << NF_IP_LOCAL_IN)
41                 | (1 << NF_IP_FORWARD))) {
42                 printk("ipt_pkttype: only valid for PRE_ROUTING, LOCAL_IN or FORWARD.\n");
43                 return 0;
44         }
45 */
46         if (matchsize != IPT_ALIGN(sizeof(struct ipt_pkttype_info)))
47                 return 0;
48
49         return 1;
50 }
51
52 static struct ipt_match pkttype_match = {
53         .name           = "pkttype",
54         .match          = &match,
55         .checkentry     = &checkentry,
56         .me             = THIS_MODULE,
57 };
58
59 static int __init init(void)
60 {
61         return ipt_register_match(&pkttype_match);
62 }
63
64 static void __exit fini(void)
65 {
66         ipt_unregister_match(&pkttype_match);
67 }
68
69 module_init(init);
70 module_exit(fini);