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;
18 struct nf_conntrack_l4proto *l4proto;
19 char data[0];
20 };
21
22 struct nf_conn_timeout {
23 struct ctnl_timeout *timeout;
24 };
25
26 #define NF_CT_TIMEOUT_EXT_DATA(__t) (unsigned int *) &((__t)->timeout->data)
27
28 static inline
nf_ct_timeout_find(const struct nf_conn * ct)29 struct nf_conn_timeout *nf_ct_timeout_find(const struct nf_conn *ct)
30 {
31 #ifdef CONFIG_NF_CONNTRACK_TIMEOUT
32 return nf_ct_ext_find(ct, NF_CT_EXT_TIMEOUT);
33 #else
34 return NULL;
35 #endif
36 }
37
38 static inline
nf_ct_timeout_ext_add(struct nf_conn * ct,struct ctnl_timeout * timeout,gfp_t gfp)39 struct nf_conn_timeout *nf_ct_timeout_ext_add(struct nf_conn *ct,
40 struct ctnl_timeout *timeout,
41 gfp_t gfp)
42 {
43 #ifdef CONFIG_NF_CONNTRACK_TIMEOUT
44 struct nf_conn_timeout *timeout_ext;
45
46 timeout_ext = nf_ct_ext_add(ct, NF_CT_EXT_TIMEOUT, gfp);
47 if (timeout_ext == NULL)
48 return NULL;
49
50 timeout_ext->timeout = timeout;
51
52 return timeout_ext;
53 #else
54 return NULL;
55 #endif
56 };
57
58 static inline unsigned int *
nf_ct_timeout_lookup(struct net * net,struct nf_conn * ct,struct nf_conntrack_l4proto * l4proto)59 nf_ct_timeout_lookup(struct net *net, struct nf_conn *ct,
60 struct nf_conntrack_l4proto *l4proto)
61 {
62 #ifdef CONFIG_NF_CONNTRACK_TIMEOUT
63 struct nf_conn_timeout *timeout_ext;
64 unsigned int *timeouts;
65
66 timeout_ext = nf_ct_timeout_find(ct);
67 if (timeout_ext)
68 timeouts = NF_CT_TIMEOUT_EXT_DATA(timeout_ext);
69 else
70 timeouts = l4proto->get_timeouts(net);
71
72 return timeouts;
73 #else
74 return l4proto->get_timeouts(net);
75 #endif
76 }
77
78 #ifdef CONFIG_NF_CONNTRACK_TIMEOUT
79 extern int nf_conntrack_timeout_init(void);
80 extern void nf_conntrack_timeout_fini(void);
81 #else
nf_conntrack_timeout_init(void)82 static inline int nf_conntrack_timeout_init(void)
83 {
84 return 0;
85 }
86
nf_conntrack_timeout_fini(void)87 static inline void nf_conntrack_timeout_fini(void)
88 {
89 return;
90 }
91 #endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
92
93 #ifdef CONFIG_NF_CONNTRACK_TIMEOUT
94 extern struct ctnl_timeout *(*nf_ct_timeout_find_get_hook)(const char *name);
95 extern void (*nf_ct_timeout_put_hook)(struct ctnl_timeout *timeout);
96 #endif
97
98 #endif /* _NF_CONNTRACK_TIMEOUT_H */
99