Linux-2.6.12-rc2
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / net / ipv4 / netfilter / ipt_helper.c
blob33fdf364d3d37eab3b1e78f3586d21c4b990464b
1 /* iptables module to match on related connections */
2 /*
3 * (C) 2001 Martin Josefsson <gandalf@wlug.westbo.se>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * 19 Mar 2002 Harald Welte <laforge@gnumonks.org>:
10 * - Port to newnat infrastructure
13 #include <linux/module.h>
14 #include <linux/skbuff.h>
15 #include <linux/netfilter.h>
16 #include <linux/netfilter_ipv4/ip_conntrack.h>
17 #include <linux/netfilter_ipv4/ip_conntrack_core.h>
18 #include <linux/netfilter_ipv4/ip_conntrack_helper.h>
19 #include <linux/netfilter_ipv4/ip_tables.h>
20 #include <linux/netfilter_ipv4/ipt_helper.h>
22 MODULE_LICENSE("GPL");
23 MODULE_AUTHOR("Martin Josefsson <gandalf@netfilter.org>");
24 MODULE_DESCRIPTION("iptables helper match module");
26 #if 0
27 #define DEBUGP printk
28 #else
29 #define DEBUGP(format, args...)
30 #endif
32 static int
33 match(const struct sk_buff *skb,
34 const struct net_device *in,
35 const struct net_device *out,
36 const void *matchinfo,
37 int offset,
38 int *hotdrop)
40 const struct ipt_helper_info *info = matchinfo;
41 struct ip_conntrack *ct;
42 enum ip_conntrack_info ctinfo;
43 int ret = info->invert;
45 ct = ip_conntrack_get((struct sk_buff *)skb, &ctinfo);
46 if (!ct) {
47 DEBUGP("ipt_helper: Eek! invalid conntrack?\n");
48 return ret;
51 if (!ct->master) {
52 DEBUGP("ipt_helper: conntrack %p has no master\n", ct);
53 return ret;
56 READ_LOCK(&ip_conntrack_lock);
57 if (!ct->master->helper) {
58 DEBUGP("ipt_helper: master ct %p has no helper\n",
59 exp->expectant);
60 goto out_unlock;
63 DEBUGP("master's name = %s , info->name = %s\n",
64 ct->master->helper->name, info->name);
66 if (info->name[0] == '\0')
67 ret ^= 1;
68 else
69 ret ^= !strncmp(ct->master->helper->name, info->name,
70 strlen(ct->master->helper->name));
71 out_unlock:
72 READ_UNLOCK(&ip_conntrack_lock);
73 return ret;
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)
82 struct ipt_helper_info *info = matchinfo;
84 info->name[29] = '\0';
86 /* verify size */
87 if (matchsize != IPT_ALIGN(sizeof(struct ipt_helper_info)))
88 return 0;
90 return 1;
93 static struct ipt_match helper_match = {
94 .name = "helper",
95 .match = &match,
96 .checkentry = &check,
97 .me = THIS_MODULE,
100 static int __init init(void)
102 need_ip_conntrack();
103 return ipt_register_match(&helper_match);
106 static void __exit fini(void)
108 ipt_unregister_match(&helper_match);
111 module_init(init);
112 module_exit(fini);