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