commented early_printk patch because of rejects.
[linux-flexiantxendom0-3.2.10.git] / net / ipv4 / netfilter / ipt_helper.c
1 /*
2  * iptables module to match on related connections
3  *   (c) 2001 Martin Josefsson <gandalf@wlug.westbo.se>
4  *
5  * Released under the terms of GNU GPLv2.
6  *
7  *   19 Mar 2002 Harald Welte <laforge@gnumonks.org>:
8  *               - Port to newnat infrastructure
9  */
10 #include <linux/module.h>
11 #include <linux/skbuff.h>
12 #include <linux/netfilter.h>
13 #include <linux/netfilter_ipv4/ip_conntrack.h>
14 #include <linux/netfilter_ipv4/ip_conntrack_core.h>
15 #include <linux/netfilter_ipv4/ip_conntrack_helper.h>
16 #include <linux/netfilter_ipv4/ip_tables.h>
17 #include <linux/netfilter_ipv4/ipt_helper.h>
18
19 MODULE_LICENSE("GPL");
20
21 #if 0
22 #define DEBUGP printk
23 #else
24 #define DEBUGP(format, args...)
25 #endif
26
27 static int
28 match(const struct sk_buff *skb,
29       const struct net_device *in,
30       const struct net_device *out,
31       const void *matchinfo,
32       int offset,
33       int *hotdrop)
34 {
35         const struct ipt_helper_info *info = matchinfo;
36         struct ip_conntrack_expect *exp;
37         struct ip_conntrack *ct;
38         enum ip_conntrack_info ctinfo;
39         int ret = 0;
40         
41         ct = ip_conntrack_get((struct sk_buff *)skb, &ctinfo);
42         if (!ct) {
43                 DEBUGP("ipt_helper: Eek! invalid conntrack?\n");
44                 return 0;
45         }
46
47         if (!ct->master) {
48                 DEBUGP("ipt_helper: conntrack %p has no master\n", ct);
49                 return 0;
50         }
51
52         exp = ct->master;
53         READ_LOCK(&ip_conntrack_lock);
54         if (!exp->expectant) {
55                 DEBUGP("ipt_helper: expectation %p without expectant !?!\n", 
56                         exp);
57                 goto out_unlock;
58         }
59
60         if (!exp->expectant->helper) {
61                 DEBUGP("ipt_helper: master ct %p has no helper\n", 
62                         exp->expectant);
63                 goto out_unlock;
64         }
65
66         DEBUGP("master's name = %s , info->name = %s\n", 
67                 exp->expectant->helper->name, info->name);
68
69         ret = !strncmp(exp->expectant->helper->name, info->name, 
70                        strlen(exp->expectant->helper->name)) ^ info->invert;
71 out_unlock:
72         READ_UNLOCK(&ip_conntrack_lock);
73         return ret;
74 }
75
76 static int check(const char *tablename,
77                  const struct ipt_ip *ip,
78                  void *matchinfo,
79                  unsigned int matchsize,
80                  unsigned int hook_mask)
81 {
82         struct ipt_helper_info *info = matchinfo;
83
84         info->name[29] = '\0';
85
86         /* verify size */
87         if (matchsize != IPT_ALIGN(sizeof(struct ipt_helper_info)))
88                 return 0;
89
90         /* verify that we actually should match anything */
91         if ( strlen(info->name) == 0 )
92                 return 0;
93         
94         return 1;
95 }
96
97 static struct ipt_match helper_match = {
98         .name           = "helper",
99         .match          = &match,
100         .checkentry     = &check,
101         .me             = THIS_MODULE,
102 };
103
104 static int __init init(void)
105 {
106         need_ip_conntrack();
107         return ipt_register_match(&helper_match);
108 }
109
110 static void __exit fini(void)
111 {
112         ipt_unregister_match(&helper_match);
113 }
114
115 module_init(init);
116 module_exit(fini);
117