]> git.karo-electronics.de Git - mv-sheeva.git/blob - net/netfilter/xt_helper.c
netfilter: xtables: move extension arguments into compound structure (1/6)
[mv-sheeva.git] / net / netfilter / xt_helper.c
1 /* iptables module to match on related connections */
2 /*
3  * (C) 2001 Martin Josefsson <gandalf@wlug.westbo.se>
4  *
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.
8  */
9
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>
18
19 MODULE_LICENSE("GPL");
20 MODULE_AUTHOR("Martin Josefsson <gandalf@netfilter.org>");
21 MODULE_DESCRIPTION("Xtables: Related connection matching");
22 MODULE_ALIAS("ipt_helper");
23 MODULE_ALIAS("ip6t_helper");
24
25
26 static bool
27 helper_mt(const struct sk_buff *skb, const struct xt_match_param *par)
28 {
29         const struct xt_helper_info *info = par->matchinfo;
30         const struct nf_conn *ct;
31         const struct nf_conn_help *master_help;
32         const struct nf_conntrack_helper *helper;
33         enum ip_conntrack_info ctinfo;
34         bool ret = info->invert;
35
36         ct = nf_ct_get(skb, &ctinfo);
37         if (!ct || !ct->master)
38                 return ret;
39
40         master_help = nfct_help(ct->master);
41         if (!master_help)
42                 return ret;
43
44         /* rcu_read_lock()ed by nf_hook_slow */
45         helper = rcu_dereference(master_help->helper);
46         if (!helper)
47                 return ret;
48
49         if (info->name[0] == '\0')
50                 ret = !ret;
51         else
52                 ret ^= !strncmp(helper->name, info->name,
53                                 strlen(helper->name));
54         return ret;
55 }
56
57 static bool
58 helper_mt_check(const char *tablename, const void *inf,
59                 const struct xt_match *match, void *matchinfo,
60                 unsigned int hook_mask)
61 {
62         struct xt_helper_info *info = matchinfo;
63
64         if (nf_ct_l3proto_try_module_get(match->family) < 0) {
65                 printk(KERN_WARNING "can't load conntrack support for "
66                                     "proto=%u\n", match->family);
67                 return false;
68         }
69         info->name[29] = '\0';
70         return true;
71 }
72
73 static void helper_mt_destroy(const struct xt_match *match, void *matchinfo)
74 {
75         nf_ct_l3proto_module_put(match->family);
76 }
77
78 static struct xt_match helper_mt_reg[] __read_mostly = {
79         {
80                 .name           = "helper",
81                 .family         = NFPROTO_IPV4,
82                 .checkentry     = helper_mt_check,
83                 .match          = helper_mt,
84                 .destroy        = helper_mt_destroy,
85                 .matchsize      = sizeof(struct xt_helper_info),
86                 .me             = THIS_MODULE,
87         },
88         {
89                 .name           = "helper",
90                 .family         = NFPROTO_IPV6,
91                 .checkentry     = helper_mt_check,
92                 .match          = helper_mt,
93                 .destroy        = helper_mt_destroy,
94                 .matchsize      = sizeof(struct xt_helper_info),
95                 .me             = THIS_MODULE,
96         },
97 };
98
99 static int __init helper_mt_init(void)
100 {
101         return xt_register_matches(helper_mt_reg, ARRAY_SIZE(helper_mt_reg));
102 }
103
104 static void __exit helper_mt_exit(void)
105 {
106         xt_unregister_matches(helper_mt_reg, ARRAY_SIZE(helper_mt_reg));
107 }
108
109 module_init(helper_mt_init);
110 module_exit(helper_mt_exit);