Blame view
net/netfilter/xt_state.c
1.96 KB
1da177e4c Linux-2.6.12-rc2 |
1 2 3 |
/* Kernel module to match connection tracking information. */ /* (C) 1999-2001 Paul `Rusty' Russell |
2e4e6a17a [NETFILTER] x_tab... |
4 |
* (C) 2002-2005 Netfilter Core Team <coreteam@netfilter.org> |
1da177e4c Linux-2.6.12-rc2 |
5 6 7 8 9 10 11 12 |
* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */ #include <linux/module.h> #include <linux/skbuff.h> |
587aa6416 [NETFILTER]: Remo... |
13 |
#include <net/netfilter/nf_conntrack.h> |
2e4e6a17a [NETFILTER] x_tab... |
14 15 |
#include <linux/netfilter/x_tables.h> #include <linux/netfilter/xt_state.h> |
1da177e4c Linux-2.6.12-rc2 |
16 17 18 |
MODULE_LICENSE("GPL"); MODULE_AUTHOR("Rusty Russell <rusty@rustcorp.com.au>"); |
2e4e6a17a [NETFILTER] x_tab... |
19 20 21 |
MODULE_DESCRIPTION("ip[6]_tables connection tracking state match module"); MODULE_ALIAS("ipt_state"); MODULE_ALIAS("ip6t_state"); |
1da177e4c Linux-2.6.12-rc2 |
22 |
|
1d93a9cba [NETFILTER]: x_ta... |
23 |
static bool |
62fc80510 netfilter: xtable... |
24 |
state_mt(const struct sk_buff *skb, struct xt_action_param *par) |
1da177e4c Linux-2.6.12-rc2 |
25 |
{ |
f7108a20d netfilter: xtable... |
26 |
const struct xt_state_info *sinfo = par->matchinfo; |
1da177e4c Linux-2.6.12-rc2 |
27 28 |
enum ip_conntrack_info ctinfo; unsigned int statebit; |
5bfddbd46 netfilter: nf_con... |
29 |
struct nf_conn *ct = nf_ct_get(skb, &ctinfo); |
1da177e4c Linux-2.6.12-rc2 |
30 |
|
5bfddbd46 netfilter: nf_con... |
31 |
if (!ct) |
2e4e6a17a [NETFILTER] x_tab... |
32 |
statebit = XT_STATE_INVALID; |
5bfddbd46 netfilter: nf_con... |
33 34 35 36 37 38 |
else { if (nf_ct_is_untracked(ct)) statebit = XT_STATE_UNTRACKED; else statebit = XT_STATE_BIT(ctinfo); } |
1da177e4c Linux-2.6.12-rc2 |
39 40 |
return (sinfo->statemask & statebit); } |
b0f38452f netfilter: xtable... |
41 |
static int state_mt_check(const struct xt_mtchk_param *par) |
b9f78f9fc [NETFILTER]: nf_c... |
42 |
{ |
4a5a5c73b netfilter: xtable... |
43 44 45 |
int ret; ret = nf_ct_l3proto_try_module_get(par->family); |
f95c74e33 netfilter: xtable... |
46 |
if (ret < 0) |
8bee4bad0 netfilter: xt ext... |
47 48 49 |
pr_info("cannot load conntrack support for proto=%u ", par->family); |
f95c74e33 netfilter: xtable... |
50 |
return ret; |
b9f78f9fc [NETFILTER]: nf_c... |
51 |
} |
6be3d8598 netfilter: xtable... |
52 |
static void state_mt_destroy(const struct xt_mtdtor_param *par) |
b9f78f9fc [NETFILTER]: nf_c... |
53 |
{ |
aa5fa3185 netfilter: xtable... |
54 |
nf_ct_l3proto_module_put(par->family); |
b9f78f9fc [NETFILTER]: nf_c... |
55 |
} |
b44672889 netfilter: xtable... |
56 57 58 59 60 61 62 63 |
static struct xt_match state_mt_reg __read_mostly = { .name = "state", .family = NFPROTO_UNSPEC, .checkentry = state_mt_check, .match = state_mt, .destroy = state_mt_destroy, .matchsize = sizeof(struct xt_state_info), .me = THIS_MODULE, |
1da177e4c Linux-2.6.12-rc2 |
64 |
}; |
d3c5ee6d5 [NETFILTER]: x_ta... |
65 |
static int __init state_mt_init(void) |
1da177e4c Linux-2.6.12-rc2 |
66 |
{ |
b44672889 netfilter: xtable... |
67 |
return xt_register_match(&state_mt_reg); |
1da177e4c Linux-2.6.12-rc2 |
68 |
} |
d3c5ee6d5 [NETFILTER]: x_ta... |
69 |
static void __exit state_mt_exit(void) |
1da177e4c Linux-2.6.12-rc2 |
70 |
{ |
b44672889 netfilter: xtable... |
71 |
xt_unregister_match(&state_mt_reg); |
1da177e4c Linux-2.6.12-rc2 |
72 |
} |
d3c5ee6d5 [NETFILTER]: x_ta... |
73 74 |
module_init(state_mt_init); module_exit(state_mt_exit); |