1 /* iptables module to match on related connections */
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.
10 * - Port to newnat infrastructure
13 #include <linux/module.h>
14 #include <linux/skbuff.h>
15 #include <linux/netfilter.h>
16 #if defined(CONFIG_IP_NF_CONNTRACK) || defined(CONFIG_IP_NF_CONNTRACK_MODULE)
17 #include <linux/netfilter_ipv4/ip_conntrack.h>
18 #include <linux/netfilter_ipv4/ip_conntrack_core.h>
19 #include <linux/netfilter_ipv4/ip_conntrack_helper.h>
21 #include <net/netfilter/nf_conntrack.h>
22 #include <net/netfilter/nf_conntrack_core.h>
23 #include <net/netfilter/nf_conntrack_helper.h>
25 #include <linux/netfilter/x_tables.h>
26 #include <linux/netfilter/xt_helper.h>
28 MODULE_LICENSE("GPL");
30 MODULE_DESCRIPTION("iptables helper match module");
31 MODULE_ALIAS("ipt_helper");
32 MODULE_ALIAS("ip6t_helper");
37 #define DEBUGP(format, args...)
40 #if defined(CONFIG_IP_NF_CONNTRACK) || defined(CONFIG_IP_NF_CONNTRACK_MODULE)
42 match(const struct sk_buff *skb,
43 const struct net_device *in,
44 const struct net_device *out,
45 const void *matchinfo,
50 const struct xt_helper_info *info = matchinfo;
51 struct ip_conntrack *ct;
52 enum ip_conntrack_info ctinfo;
53 int ret = info->invert;
55 ct = ip_conntrack_get((struct sk_buff *)skb, &ctinfo);
57 DEBUGP("xt_helper: Eek! invalid conntrack?\n");
62 DEBUGP("xt_helper: conntrack %p has no master\n", ct);
66 read_lock_bh(&ip_conntrack_lock);
67 if (!ct->master->helper) {
68 DEBUGP("xt_helper: master ct %p has no helper\n",
73 DEBUGP("master's name = %s , info->name = %s\n",
74 ct->master->helper->name, info->name);
76 if (info->name[0] == '\0')
79 ret ^= !strncmp(ct->master->helper->name, info->name,
80 strlen(ct->master->helper->name));
82 read_unlock_bh(&ip_conntrack_lock);
86 #else /* CONFIG_IP_NF_CONNTRACK */
89 match(const struct sk_buff *skb,
90 const struct net_device *in,
91 const struct net_device *out,
92 const void *matchinfo,
97 const struct xt_helper_info *info = matchinfo;
99 enum ip_conntrack_info ctinfo;
100 int ret = info->invert;
102 ct = nf_ct_get((struct sk_buff *)skb, &ctinfo);
104 DEBUGP("xt_helper: Eek! invalid conntrack?\n");
109 DEBUGP("xt_helper: conntrack %p has no master\n", ct);
113 read_lock_bh(&nf_conntrack_lock);
114 if (!ct->master->helper) {
115 DEBUGP("xt_helper: master ct %p has no helper\n",
120 DEBUGP("master's name = %s , info->name = %s\n",
121 ct->master->helper->name, info->name);
123 if (info->name[0] == '\0')
126 ret ^= !strncmp(ct->master->helper->name, info->name,
127 strlen(ct->master->helper->name));
129 read_unlock_bh(&nf_conntrack_lock);
134 static int check(const char *tablename,
137 unsigned int matchsize,
138 unsigned int hook_mask)
140 struct xt_helper_info *info = matchinfo;
142 info->name[29] = '\0';
145 if (matchsize != XT_ALIGN(sizeof(struct xt_helper_info)))
151 static struct xt_match helper_match = {
154 .checkentry = &check,
157 static struct xt_match helper6_match = {
160 .checkentry = &check,
164 static int __init init(void)
169 ret = xt_register_match(AF_INET, &helper_match);
173 ret = xt_register_match(AF_INET6, &helper6_match);
175 xt_unregister_match(AF_INET, &helper_match);
180 static void __exit fini(void)
182 xt_unregister_match(AF_INET, &helper_match);
183 xt_unregister_match(AF_INET6, &helper6_match);