Blame view
net/netfilter/xt_state.c
1.82 KB
d2912cb15 treewide: Replace... |
1 |
// SPDX-License-Identifier: GPL-2.0-only |
1da177e4c Linux-2.6.12-rc2 |
2 3 4 |
/* Kernel module to match connection tracking information. */ /* (C) 1999-2001 Paul `Rusty' Russell |
2e4e6a17a [NETFILTER] x_tab... |
5 |
* (C) 2002-2005 Netfilter Core Team <coreteam@netfilter.org> |
1da177e4c Linux-2.6.12-rc2 |
6 7 8 9 |
*/ #include <linux/module.h> #include <linux/skbuff.h> |
587aa6416 [NETFILTER]: Remo... |
10 |
#include <net/netfilter/nf_conntrack.h> |
2e4e6a17a [NETFILTER] x_tab... |
11 12 |
#include <linux/netfilter/x_tables.h> #include <linux/netfilter/xt_state.h> |
1da177e4c Linux-2.6.12-rc2 |
13 14 15 |
MODULE_LICENSE("GPL"); MODULE_AUTHOR("Rusty Russell <rusty@rustcorp.com.au>"); |
2e4e6a17a [NETFILTER] x_tab... |
16 17 18 |
MODULE_DESCRIPTION("ip[6]_tables connection tracking state match module"); MODULE_ALIAS("ipt_state"); MODULE_ALIAS("ip6t_state"); |
1da177e4c Linux-2.6.12-rc2 |
19 |
|
1d93a9cba [NETFILTER]: x_ta... |
20 |
static bool |
62fc80510 netfilter: xtable... |
21 |
state_mt(const struct sk_buff *skb, struct xt_action_param *par) |
1da177e4c Linux-2.6.12-rc2 |
22 |
{ |
f7108a20d netfilter: xtable... |
23 |
const struct xt_state_info *sinfo = par->matchinfo; |
1da177e4c Linux-2.6.12-rc2 |
24 25 |
enum ip_conntrack_info ctinfo; unsigned int statebit; |
5bfddbd46 netfilter: nf_con... |
26 |
struct nf_conn *ct = nf_ct_get(skb, &ctinfo); |
1da177e4c Linux-2.6.12-rc2 |
27 |
|
cc41c84b7 netfilter: kill t... |
28 29 30 31 32 |
if (ct) statebit = XT_STATE_BIT(ctinfo); else if (ctinfo == IP_CT_UNTRACKED) statebit = XT_STATE_UNTRACKED; else |
2e4e6a17a [NETFILTER] x_tab... |
33 |
statebit = XT_STATE_INVALID; |
cc41c84b7 netfilter: kill t... |
34 |
|
1da177e4c Linux-2.6.12-rc2 |
35 36 |
return (sinfo->statemask & statebit); } |
b0f38452f netfilter: xtable... |
37 |
static int state_mt_check(const struct xt_mtchk_param *par) |
b9f78f9fc [NETFILTER]: nf_c... |
38 |
{ |
4a5a5c73b netfilter: xtable... |
39 |
int ret; |
ecb2421b5 netfilter: add an... |
40 |
ret = nf_ct_netns_get(par->net, par->family); |
f95c74e33 netfilter: xtable... |
41 |
if (ret < 0) |
b26066447 netfilter: x_tabl... |
42 43 44 |
pr_info_ratelimited("cannot load conntrack support for proto=%u ", par->family); |
f95c74e33 netfilter: xtable... |
45 |
return ret; |
b9f78f9fc [NETFILTER]: nf_c... |
46 |
} |
6be3d8598 netfilter: xtable... |
47 |
static void state_mt_destroy(const struct xt_mtdtor_param *par) |
b9f78f9fc [NETFILTER]: nf_c... |
48 |
{ |
ecb2421b5 netfilter: add an... |
49 |
nf_ct_netns_put(par->net, par->family); |
b9f78f9fc [NETFILTER]: nf_c... |
50 |
} |
b44672889 netfilter: xtable... |
51 52 53 54 55 56 57 58 |
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 |
59 |
}; |
d3c5ee6d5 [NETFILTER]: x_ta... |
60 |
static int __init state_mt_init(void) |
1da177e4c Linux-2.6.12-rc2 |
61 |
{ |
b44672889 netfilter: xtable... |
62 |
return xt_register_match(&state_mt_reg); |
1da177e4c Linux-2.6.12-rc2 |
63 |
} |
d3c5ee6d5 [NETFILTER]: x_ta... |
64 |
static void __exit state_mt_exit(void) |
1da177e4c Linux-2.6.12-rc2 |
65 |
{ |
b44672889 netfilter: xtable... |
66 |
xt_unregister_match(&state_mt_reg); |
1da177e4c Linux-2.6.12-rc2 |
67 |
} |
d3c5ee6d5 [NETFILTER]: x_ta... |
68 69 |
module_init(state_mt_init); module_exit(state_mt_exit); |