]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
dd705072 PNA |
2 | #ifndef _NF_CONNTRACK_TIMEOUT_H |
3 | #define _NF_CONNTRACK_TIMEOUT_H | |
4 | ||
5 | #include <net/net_namespace.h> | |
6 | #include <linux/netfilter/nf_conntrack_common.h> | |
7 | #include <linux/netfilter/nf_conntrack_tuple_common.h> | |
b54ab92b | 8 | #include <linux/refcount.h> |
dd705072 PNA |
9 | #include <net/netfilter/nf_conntrack.h> |
10 | #include <net/netfilter/nf_conntrack_extend.h> | |
11 | ||
12 | #define CTNL_TIMEOUT_NAME_MAX 32 | |
13 | ||
14 | struct ctnl_timeout { | |
15 | struct list_head head; | |
16 | struct rcu_head rcu_head; | |
b54ab92b | 17 | refcount_t refcnt; |
dd705072 PNA |
18 | char name[CTNL_TIMEOUT_NAME_MAX]; |
19 | __u16 l3num; | |
b3480fe0 | 20 | const struct nf_conntrack_l4proto *l4proto; |
dd705072 PNA |
21 | char data[0]; |
22 | }; | |
23 | ||
24 | struct nf_conn_timeout { | |
ae2d708e | 25 | struct ctnl_timeout __rcu *timeout; |
dd705072 PNA |
26 | }; |
27 | ||
ae2d708e PNA |
28 | static inline unsigned int * |
29 | nf_ct_timeout_data(struct nf_conn_timeout *t) | |
30 | { | |
31 | struct ctnl_timeout *timeout; | |
32 | ||
33 | timeout = rcu_dereference(t->timeout); | |
34 | if (timeout == NULL) | |
35 | return NULL; | |
36 | ||
37 | return (unsigned int *)timeout->data; | |
38 | } | |
dd705072 PNA |
39 | |
40 | static inline | |
41 | struct nf_conn_timeout *nf_ct_timeout_find(const struct nf_conn *ct) | |
42 | { | |
43 | #ifdef CONFIG_NF_CONNTRACK_TIMEOUT | |
44 | return nf_ct_ext_find(ct, NF_CT_EXT_TIMEOUT); | |
45 | #else | |
46 | return NULL; | |
47 | #endif | |
48 | } | |
49 | ||
50 | static inline | |
51 | struct nf_conn_timeout *nf_ct_timeout_ext_add(struct nf_conn *ct, | |
52 | struct ctnl_timeout *timeout, | |
53 | gfp_t gfp) | |
54 | { | |
55 | #ifdef CONFIG_NF_CONNTRACK_TIMEOUT | |
56 | struct nf_conn_timeout *timeout_ext; | |
57 | ||
58 | timeout_ext = nf_ct_ext_add(ct, NF_CT_EXT_TIMEOUT, gfp); | |
59 | if (timeout_ext == NULL) | |
60 | return NULL; | |
61 | ||
ae2d708e | 62 | rcu_assign_pointer(timeout_ext->timeout, timeout); |
dd705072 PNA |
63 | |
64 | return timeout_ext; | |
65 | #else | |
66 | return NULL; | |
67 | #endif | |
68 | }; | |
69 | ||
84b5ee93 PNA |
70 | static inline unsigned int * |
71 | nf_ct_timeout_lookup(struct net *net, struct nf_conn *ct, | |
2a04aabf | 72 | const struct nf_conntrack_l4proto *l4proto) |
84b5ee93 PNA |
73 | { |
74 | #ifdef CONFIG_NF_CONNTRACK_TIMEOUT | |
75 | struct nf_conn_timeout *timeout_ext; | |
76 | unsigned int *timeouts; | |
77 | ||
78 | timeout_ext = nf_ct_timeout_find(ct); | |
ae2d708e PNA |
79 | if (timeout_ext) { |
80 | timeouts = nf_ct_timeout_data(timeout_ext); | |
81 | if (unlikely(!timeouts)) | |
82 | timeouts = l4proto->get_timeouts(net); | |
83 | } else { | |
84b5ee93 | 84 | timeouts = l4proto->get_timeouts(net); |
ae2d708e | 85 | } |
84b5ee93 PNA |
86 | |
87 | return timeouts; | |
88 | #else | |
89 | return l4proto->get_timeouts(net); | |
90 | #endif | |
91 | } | |
92 | ||
dd705072 | 93 | #ifdef CONFIG_NF_CONNTRACK_TIMEOUT |
4e77be46 JP |
94 | int nf_conntrack_timeout_init(void); |
95 | void nf_conntrack_timeout_fini(void); | |
dd705072 | 96 | #else |
8684094c | 97 | static inline int nf_conntrack_timeout_init(void) |
dd705072 PNA |
98 | { |
99 | return 0; | |
100 | } | |
101 | ||
8684094c | 102 | static inline void nf_conntrack_timeout_fini(void) |
dd705072 PNA |
103 | { |
104 | return; | |
105 | } | |
106 | #endif /* CONFIG_NF_CONNTRACK_TIMEOUT */ | |
107 | ||
108 | #ifdef CONFIG_NF_CONNTRACK_TIMEOUT | |
19576c94 | 109 | extern struct ctnl_timeout *(*nf_ct_timeout_find_get_hook)(struct net *net, const char *name); |
dd705072 PNA |
110 | extern void (*nf_ct_timeout_put_hook)(struct ctnl_timeout *timeout); |
111 | #endif | |
112 | ||
113 | #endif /* _NF_CONNTRACK_TIMEOUT_H */ |