]> git.ipfire.org Git - thirdparty/kernel/linux.git/blob - include/net/netfilter/nf_conntrack_timeout.h
Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/shli/md
[thirdparty/kernel/linux.git] / include / net / netfilter / nf_conntrack_timeout.h
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 <linux/refcount.h>
8 #include <net/netfilter/nf_conntrack.h>
9 #include <net/netfilter/nf_conntrack_extend.h>
10
11 #define CTNL_TIMEOUT_NAME_MAX 32
12
13 struct ctnl_timeout {
14 struct list_head head;
15 struct rcu_head rcu_head;
16 refcount_t refcnt;
17 char name[CTNL_TIMEOUT_NAME_MAX];
18 __u16 l3num;
19 const struct nf_conntrack_l4proto *l4proto;
20 char data[0];
21 };
22
23 struct nf_conn_timeout {
24 struct ctnl_timeout __rcu *timeout;
25 };
26
27 static inline unsigned int *
28 nf_ct_timeout_data(struct nf_conn_timeout *t)
29 {
30 struct ctnl_timeout *timeout;
31
32 timeout = rcu_dereference(t->timeout);
33 if (timeout == NULL)
34 return NULL;
35
36 return (unsigned int *)timeout->data;
37 }
38
39 static inline
40 struct nf_conn_timeout *nf_ct_timeout_find(const struct nf_conn *ct)
41 {
42 #ifdef CONFIG_NF_CONNTRACK_TIMEOUT
43 return nf_ct_ext_find(ct, NF_CT_EXT_TIMEOUT);
44 #else
45 return NULL;
46 #endif
47 }
48
49 static inline
50 struct nf_conn_timeout *nf_ct_timeout_ext_add(struct nf_conn *ct,
51 struct ctnl_timeout *timeout,
52 gfp_t gfp)
53 {
54 #ifdef CONFIG_NF_CONNTRACK_TIMEOUT
55 struct nf_conn_timeout *timeout_ext;
56
57 timeout_ext = nf_ct_ext_add(ct, NF_CT_EXT_TIMEOUT, gfp);
58 if (timeout_ext == NULL)
59 return NULL;
60
61 rcu_assign_pointer(timeout_ext->timeout, timeout);
62
63 return timeout_ext;
64 #else
65 return NULL;
66 #endif
67 };
68
69 static inline unsigned int *
70 nf_ct_timeout_lookup(struct net *net, struct nf_conn *ct,
71 const struct nf_conntrack_l4proto *l4proto)
72 {
73 #ifdef CONFIG_NF_CONNTRACK_TIMEOUT
74 struct nf_conn_timeout *timeout_ext;
75 unsigned int *timeouts;
76
77 timeout_ext = nf_ct_timeout_find(ct);
78 if (timeout_ext) {
79 timeouts = nf_ct_timeout_data(timeout_ext);
80 if (unlikely(!timeouts))
81 timeouts = l4proto->get_timeouts(net);
82 } else {
83 timeouts = l4proto->get_timeouts(net);
84 }
85
86 return timeouts;
87 #else
88 return l4proto->get_timeouts(net);
89 #endif
90 }
91
92 #ifdef CONFIG_NF_CONNTRACK_TIMEOUT
93 int nf_conntrack_timeout_init(void);
94 void nf_conntrack_timeout_fini(void);
95 #else
96 static inline int nf_conntrack_timeout_init(void)
97 {
98 return 0;
99 }
100
101 static inline void nf_conntrack_timeout_fini(void)
102 {
103 return;
104 }
105 #endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
106
107 #ifdef CONFIG_NF_CONNTRACK_TIMEOUT
108 extern struct ctnl_timeout *(*nf_ct_timeout_find_get_hook)(struct net *net, const char *name);
109 extern void (*nf_ct_timeout_put_hook)(struct ctnl_timeout *timeout);
110 #endif
111
112 #endif /* _NF_CONNTRACK_TIMEOUT_H */