1 /* iptables module to match on related connections */
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");
29 #define DEBUGP(format, args...)
33 match(const struct sk_buff *skb,
34 const struct net_device *in,
35 const struct net_device *out,
36 const void *matchinfo,
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);
47 DEBUGP("ipt_helper: Eek! invalid conntrack?\n");
52 DEBUGP("ipt_helper: conntrack %p has no master\n", ct);
56 READ_LOCK(&ip_conntrack_lock);
57 if (!ct->master->helper) {
58 DEBUGP("ipt_helper: master ct %p has no helper\n",
63 DEBUGP("master's name = %s , info->name = %s\n",
64 ct->master->helper->name, info->name);
66 if (info->name[0] == '\0')
69 ret ^= !strncmp(ct->master->helper->name, info->name,
70 strlen(ct->master->helper->name));
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)))
93 static struct ipt_match helper_match = {
100 static int __init init(void)
103 return ipt_register_match(&helper_match);
106 static void __exit fini(void)
108 ipt_unregister_match(&helper_match);