]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* iptables module to match on related connections */ |
2 | /* | |
3 | * (C) 2001 Martin Josefsson <[email protected]> | |
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. | |
1da177e4 | 8 | */ |
8bee4bad | 9 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
1da177e4 LT |
10 | #include <linux/module.h> |
11 | #include <linux/skbuff.h> | |
12 | #include <linux/netfilter.h> | |
9fb9cbb1 YK |
13 | #include <net/netfilter/nf_conntrack.h> |
14 | #include <net/netfilter/nf_conntrack_core.h> | |
15 | #include <net/netfilter/nf_conntrack_helper.h> | |
2e4e6a17 HW |
16 | #include <linux/netfilter/x_tables.h> |
17 | #include <linux/netfilter/xt_helper.h> | |
1da177e4 LT |
18 | |
19 | MODULE_LICENSE("GPL"); | |
20 | MODULE_AUTHOR("Martin Josefsson <[email protected]>"); | |
2ae15b64 | 21 | MODULE_DESCRIPTION("Xtables: Related connection matching"); |
2e4e6a17 HW |
22 | MODULE_ALIAS("ipt_helper"); |
23 | MODULE_ALIAS("ip6t_helper"); | |
1da177e4 | 24 | |
1da177e4 | 25 | |
1d93a9cb | 26 | static bool |
62fc8051 | 27 | helper_mt(const struct sk_buff *skb, struct xt_action_param *par) |
9fb9cbb1 | 28 | { |
f7108a20 | 29 | const struct xt_helper_info *info = par->matchinfo; |
a47362a2 JE |
30 | const struct nf_conn *ct; |
31 | const struct nf_conn_help *master_help; | |
342b7e3c | 32 | const struct nf_conntrack_helper *helper; |
9fb9cbb1 | 33 | enum ip_conntrack_info ctinfo; |
1d93a9cb | 34 | bool ret = info->invert; |
601e68e1 | 35 | |
a47362a2 | 36 | ct = nf_ct_get(skb, &ctinfo); |
342b7e3c | 37 | if (!ct || !ct->master) |
9fb9cbb1 | 38 | return ret; |
9fb9cbb1 | 39 | |
dc808fe2 | 40 | master_help = nfct_help(ct->master); |
342b7e3c PM |
41 | if (!master_help) |
42 | return ret; | |
9fb9cbb1 | 43 | |
e2361cb9 | 44 | /* rcu_read_lock()ed by nf_hook_thresh */ |
342b7e3c PM |
45 | helper = rcu_dereference(master_help->helper); |
46 | if (!helper) | |
47 | return ret; | |
9fb9cbb1 YK |
48 | |
49 | if (info->name[0] == '\0') | |
1d93a9cb | 50 | ret = !ret; |
9fb9cbb1 | 51 | else |
0ff4d77b JE |
52 | ret ^= !strncmp(helper->name, info->name, |
53 | strlen(helper->name)); | |
9fb9cbb1 YK |
54 | return ret; |
55 | } | |
9fb9cbb1 | 56 | |
b0f38452 | 57 | static int helper_mt_check(const struct xt_mtchk_param *par) |
1da177e4 | 58 | { |
9b4fce7a | 59 | struct xt_helper_info *info = par->matchinfo; |
4a5a5c73 | 60 | int ret; |
1da177e4 | 61 | |
ecb2421b | 62 | ret = nf_ct_netns_get(par->net, par->family); |
4a5a5c73 | 63 | if (ret < 0) { |
b2606644 FW |
64 | pr_info_ratelimited("cannot load conntrack support for proto=%u\n", |
65 | par->family); | |
4a5a5c73 | 66 | return ret; |
b9f78f9f | 67 | } |
b9d80f83 | 68 | info->name[sizeof(info->name) - 1] = '\0'; |
bd414ee6 | 69 | return 0; |
1da177e4 LT |
70 | } |
71 | ||
6be3d859 | 72 | static void helper_mt_destroy(const struct xt_mtdtor_param *par) |
b9f78f9f | 73 | { |
ecb2421b | 74 | nf_ct_netns_put(par->net, par->family); |
b9f78f9f PNA |
75 | } |
76 | ||
92f3b2b1 JE |
77 | static struct xt_match helper_mt_reg __read_mostly = { |
78 | .name = "helper", | |
79 | .revision = 0, | |
80 | .family = NFPROTO_UNSPEC, | |
81 | .checkentry = helper_mt_check, | |
82 | .match = helper_mt, | |
83 | .destroy = helper_mt_destroy, | |
84 | .matchsize = sizeof(struct xt_helper_info), | |
85 | .me = THIS_MODULE, | |
1da177e4 LT |
86 | }; |
87 | ||
d3c5ee6d | 88 | static int __init helper_mt_init(void) |
1da177e4 | 89 | { |
92f3b2b1 | 90 | return xt_register_match(&helper_mt_reg); |
1da177e4 LT |
91 | } |
92 | ||
d3c5ee6d | 93 | static void __exit helper_mt_exit(void) |
1da177e4 | 94 | { |
92f3b2b1 | 95 | xt_unregister_match(&helper_mt_reg); |
1da177e4 LT |
96 | } |
97 | ||
d3c5ee6d JE |
98 | module_init(helper_mt_init); |
99 | module_exit(helper_mt_exit); |