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 #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");
29 MODULE_AUTHOR("Martin Josefsson <gandalf@netfilter.org>");
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 struct xt_match
*match
,
46 const void *matchinfo
,
51 const struct xt_helper_info
*info
= matchinfo
;
52 struct ip_conntrack
*ct
;
53 enum ip_conntrack_info ctinfo
;
54 int ret
= info
->invert
;
56 ct
= ip_conntrack_get((struct sk_buff
*)skb
, &ctinfo
);
58 DEBUGP("xt_helper: Eek! invalid conntrack?\n");
63 DEBUGP("xt_helper: conntrack %p has no master\n", ct
);
67 read_lock_bh(&ip_conntrack_lock
);
68 if (!ct
->master
->helper
) {
69 DEBUGP("xt_helper: master ct %p has no helper\n",
74 DEBUGP("master's name = %s , info->name = %s\n",
75 ct
->master
->helper
->name
, info
->name
);
77 if (info
->name
[0] == '\0')
80 ret
^= !strncmp(ct
->master
->helper
->name
, info
->name
,
81 strlen(ct
->master
->helper
->name
));
83 read_unlock_bh(&ip_conntrack_lock
);
87 #else /* CONFIG_IP_NF_CONNTRACK */
90 match(const struct sk_buff
*skb
,
91 const struct net_device
*in
,
92 const struct net_device
*out
,
93 const struct xt_match
*match
,
94 const void *matchinfo
,
99 const struct xt_helper_info
*info
= matchinfo
;
101 struct nf_conn_help
*master_help
;
102 enum ip_conntrack_info ctinfo
;
103 int ret
= info
->invert
;
105 ct
= nf_ct_get((struct sk_buff
*)skb
, &ctinfo
);
107 DEBUGP("xt_helper: Eek! invalid conntrack?\n");
112 DEBUGP("xt_helper: conntrack %p has no master\n", ct
);
116 read_lock_bh(&nf_conntrack_lock
);
117 master_help
= nfct_help(ct
->master
);
118 if (!master_help
|| !master_help
->helper
) {
119 DEBUGP("xt_helper: master ct %p has no helper\n",
124 DEBUGP("master's name = %s , info->name = %s\n",
125 ct
->master
->helper
->name
, info
->name
);
127 if (info
->name
[0] == '\0')
130 ret
^= !strncmp(master_help
->helper
->name
, info
->name
,
131 strlen(master_help
->helper
->name
));
133 read_unlock_bh(&nf_conntrack_lock
);
138 static int check(const char *tablename
,
140 const struct xt_match
*match
,
142 unsigned int hook_mask
)
144 struct xt_helper_info
*info
= matchinfo
;
146 #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
147 if (nf_ct_l3proto_try_module_get(match
->family
) < 0) {
148 printk(KERN_WARNING
"can't load nf_conntrack support for "
149 "proto=%d\n", match
->family
);
153 info
->name
[29] = '\0';
158 destroy(const struct xt_match
*match
, void *matchinfo
)
160 #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
161 nf_ct_l3proto_module_put(match
->family
);
165 static struct xt_match xt_helper_match
[] = {
172 .matchsize
= sizeof(struct xt_helper_info
),
181 .matchsize
= sizeof(struct xt_helper_info
),
186 static int __init
xt_helper_init(void)
189 return xt_register_matches(xt_helper_match
,
190 ARRAY_SIZE(xt_helper_match
));
193 static void __exit
xt_helper_fini(void)
195 xt_unregister_matches(xt_helper_match
, ARRAY_SIZE(xt_helper_match
));
198 module_init(xt_helper_init
);
199 module_exit(xt_helper_fini
);