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 #ifdef CONFIG_NF_CONNTRACK_TIMEOUT
59 extern int nf_conntrack_timeout_init(struct net *net);
60 extern void nf_conntrack_timeout_fini(struct net *net);
61 #else
nf_conntrack_timeout_init(struct net * net)62 static inline int nf_conntrack_timeout_init(struct net *net)
63 {
64         return 0;
65 }
66 
nf_conntrack_timeout_fini(struct net * net)67 static inline void nf_conntrack_timeout_fini(struct net *net)
68 {
69         return;
70 }
71 #endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
72 
73 #ifdef CONFIG_NF_CONNTRACK_TIMEOUT
74 extern struct ctnl_timeout *(*nf_ct_timeout_find_get_hook)(const char *name);
75 extern void (*nf_ct_timeout_put_hook)(struct ctnl_timeout *timeout);
76 #endif
77 
78 #endif /* _NF_CONNTRACK_TIMEOUT_H */
79