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.
10 #include <linux/module.h>
11 #include <linux/skbuff.h>
12 #include <linux/netfilter.h>
13 #include <net/netfilter/nf_conntrack.h>
14 #include <net/netfilter/nf_conntrack_core.h>
15 #include <net/netfilter/nf_conntrack_helper.h>
16 #include <linux/netfilter/x_tables.h>
17 #include <linux/netfilter/xt_helper.h>
19 MODULE_LICENSE("GPL");
20 MODULE_AUTHOR("Martin Josefsson <gandalf@netfilter.org>");
21 MODULE_DESCRIPTION("iptables helper match module");
22 MODULE_ALIAS("ipt_helper");
23 MODULE_ALIAS("ip6t_helper");
28 #define DEBUGP(format, args...)
32 match(const struct sk_buff *skb,
33 const struct net_device *in,
34 const struct net_device *out,
35 const struct xt_match *match,
36 const void *matchinfo,
41 const struct xt_helper_info *info = matchinfo;
43 struct nf_conn_help *master_help;
44 enum ip_conntrack_info ctinfo;
45 int ret = info->invert;
47 ct = nf_ct_get((struct sk_buff *)skb, &ctinfo);
49 DEBUGP("xt_helper: Eek! invalid conntrack?\n");
54 DEBUGP("xt_helper: conntrack %p has no master\n", ct);
58 read_lock_bh(&nf_conntrack_lock);
59 master_help = nfct_help(ct->master);
60 if (!master_help || !master_help->helper) {
61 DEBUGP("xt_helper: master ct %p has no helper\n",
66 DEBUGP("master's name = %s , info->name = %s\n",
67 ct->master->helper->name, info->name);
69 if (info->name[0] == '\0')
72 ret ^= !strncmp(master_help->helper->name, info->name,
73 strlen(master_help->helper->name));
75 read_unlock_bh(&nf_conntrack_lock);
79 static int check(const char *tablename,
81 const struct xt_match *match,
83 unsigned int hook_mask)
85 struct xt_helper_info *info = matchinfo;
87 if (nf_ct_l3proto_try_module_get(match->family) < 0) {
88 printk(KERN_WARNING "can't load conntrack support for "
89 "proto=%d\n", match->family);
92 info->name[29] = '\0';
97 destroy(const struct xt_match *match, void *matchinfo)
99 nf_ct_l3proto_module_put(match->family);
102 static struct xt_match xt_helper_match[] = {
109 .matchsize = sizeof(struct xt_helper_info),
118 .matchsize = sizeof(struct xt_helper_info),
123 static int __init xt_helper_init(void)
125 return xt_register_matches(xt_helper_match,
126 ARRAY_SIZE(xt_helper_match));
129 static void __exit xt_helper_fini(void)
131 xt_unregister_matches(xt_helper_match, ARRAY_SIZE(xt_helper_match));
134 module_init(xt_helper_init);
135 module_exit(xt_helper_fini);