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 <net/netfilter/nf_conntrack.h>
17 #include <net/netfilter/nf_conntrack_core.h>
18 #include <net/netfilter/nf_conntrack_helper.h>
19 #include <linux/netfilter/x_tables.h>
20 #include <linux/netfilter/xt_helper.h>
22 MODULE_LICENSE("GPL");
23 MODULE_AUTHOR("Martin Josefsson <gandalf@netfilter.org>");
24 MODULE_DESCRIPTION("iptables helper match module");
25 MODULE_ALIAS("ipt_helper");
26 MODULE_ALIAS("ip6t_helper");
31 #define DEBUGP(format, args...)
35 match(const struct sk_buff *skb,
36 const struct net_device *in,
37 const struct net_device *out,
38 const struct xt_match *match,
39 const void *matchinfo,
44 const struct xt_helper_info *info = matchinfo;
46 struct nf_conn_help *master_help;
47 enum ip_conntrack_info ctinfo;
48 int ret = info->invert;
50 ct = nf_ct_get((struct sk_buff *)skb, &ctinfo);
52 DEBUGP("xt_helper: Eek! invalid conntrack?\n");
57 DEBUGP("xt_helper: conntrack %p has no master\n", ct);
61 read_lock_bh(&nf_conntrack_lock);
62 master_help = nfct_help(ct->master);
63 if (!master_help || !master_help->helper) {
64 DEBUGP("xt_helper: master ct %p has no helper\n",
69 DEBUGP("master's name = %s , info->name = %s\n",
70 ct->master->helper->name, info->name);
72 if (info->name[0] == '\0')
75 ret ^= !strncmp(master_help->helper->name, info->name,
76 strlen(master_help->helper->name));
78 read_unlock_bh(&nf_conntrack_lock);
82 static int check(const char *tablename,
84 const struct xt_match *match,
86 unsigned int hook_mask)
88 struct xt_helper_info *info = matchinfo;
90 if (nf_ct_l3proto_try_module_get(match->family) < 0) {
91 printk(KERN_WARNING "can't load conntrack support for "
92 "proto=%d\n", match->family);
95 info->name[29] = '\0';
100 destroy(const struct xt_match *match, void *matchinfo)
102 nf_ct_l3proto_module_put(match->family);
105 static struct xt_match xt_helper_match[] = {
112 .matchsize = sizeof(struct xt_helper_info),
121 .matchsize = sizeof(struct xt_helper_info),
126 static int __init xt_helper_init(void)
128 return xt_register_matches(xt_helper_match,
129 ARRAY_SIZE(xt_helper_match));
132 static void __exit xt_helper_fini(void)
134 xt_unregister_matches(xt_helper_match, ARRAY_SIZE(xt_helper_match));
137 module_init(xt_helper_init);
138 module_exit(xt_helper_fini);