2 * iptables module to match on related connections
3 * (c) 2001 Martin Josefsson <gandalf@wlug.westbo.se>
5 * Released under the terms of GNU GPLv2.
7 * 19 Mar 2002 Harald Welte <laforge@gnumonks.org>:
8 * - Port to newnat infrastructure
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>
19 MODULE_LICENSE("GPL");
24 #define DEBUGP(format, args...)
28 match(const struct sk_buff *skb,
29 const struct net_device *in,
30 const struct net_device *out,
31 const void *matchinfo,
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;
41 ct = ip_conntrack_get((struct sk_buff *)skb, &ctinfo);
43 DEBUGP("ipt_helper: Eek! invalid conntrack?\n");
48 DEBUGP("ipt_helper: conntrack %p has no master\n", ct);
53 READ_LOCK(&ip_conntrack_lock);
54 if (!exp->expectant) {
55 DEBUGP("ipt_helper: expectation %p without expectant !?!\n",
60 if (!exp->expectant->helper) {
61 DEBUGP("ipt_helper: master ct %p has no helper\n",
66 DEBUGP("master's name = %s , info->name = %s\n",
67 exp->expectant->helper->name, info->name);
69 ret = !strncmp(exp->expectant->helper->name, info->name,
70 strlen(exp->expectant->helper->name)) ^ info->invert;
72 READ_UNLOCK(&ip_conntrack_lock);
76 static int check(const char *tablename,
77 const struct ipt_ip *ip,
79 unsigned int matchsize,
80 unsigned int hook_mask)
82 struct ipt_helper_info *info = matchinfo;
84 info->name[29] = '\0';
87 if (matchsize != IPT_ALIGN(sizeof(struct ipt_helper_info)))
90 /* verify that we actually should match anything */
91 if ( strlen(info->name) == 0 )
97 static struct ipt_match helper_match = {
100 .checkentry = &check,
104 static int __init init(void)
107 return ipt_register_match(&helper_match);
110 static void __exit fini(void)
112 ipt_unregister_match(&helper_match);