Linux-2.6.12-rc2
[linux-flexiantxendom0-natty.git] / net / ipv4 / netfilter / ipt_realm.c
1 /* IP tables module for matching the routing realm
2  *
3  * $Id: ipt_realm.c,v 1.3 2004/03/05 13:25:40 laforge Exp $
4  *
5  * (C) 2003 by Sampsa Ranta <sampsa@netsonic.fi>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  */
11
12 #include <linux/module.h>
13 #include <linux/skbuff.h>
14 #include <linux/netdevice.h>
15 #include <net/route.h>
16
17 #include <linux/netfilter_ipv4/ipt_realm.h>
18 #include <linux/netfilter_ipv4/ip_tables.h>
19
20 MODULE_AUTHOR("Sampsa Ranta <sampsa@netsonic.fi>");
21 MODULE_LICENSE("GPL");
22 MODULE_DESCRIPTION("iptables realm match");
23
24 static int
25 match(const struct sk_buff *skb,
26       const struct net_device *in,
27       const struct net_device *out,
28       const void *matchinfo,
29       int offset,
30       int *hotdrop)
31 {
32         const struct ipt_realm_info *info = matchinfo;
33         struct dst_entry *dst = skb->dst;
34     
35         return (info->id == (dst->tclassid & info->mask)) ^ info->invert;
36 }
37
38 static int check(const char *tablename,
39                  const struct ipt_ip *ip,
40                  void *matchinfo,
41                  unsigned int matchsize,
42                  unsigned int hook_mask)
43 {
44         if (hook_mask
45             & ~((1 << NF_IP_POST_ROUTING) | (1 << NF_IP_FORWARD) |
46                 (1 << NF_IP_LOCAL_OUT) | (1 << NF_IP_LOCAL_IN))) {
47                 printk("ipt_realm: only valid for POST_ROUTING, LOCAL_OUT, "
48                        "LOCAL_IN or FORWARD.\n");
49                 return 0;
50         }
51         if (matchsize != IPT_ALIGN(sizeof(struct ipt_realm_info))) {
52                 printk("ipt_realm: invalid matchsize.\n");
53                 return 0;
54         }
55         return 1;
56 }
57
58 static struct ipt_match realm_match = {
59         .name           = "realm",
60         .match          = match, 
61         .checkentry     = check,
62         .me             = THIS_MODULE
63 };
64
65 static int __init init(void)
66 {
67         return ipt_register_match(&realm_match);
68 }
69
70 static void __exit fini(void)
71 {
72         ipt_unregister_match(&realm_match);
73 }
74
75 module_init(init);
76 module_exit(fini);