1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _NF_CONNTRACK_TIMEOUT_H
3 #define _NF_CONNTRACK_TIMEOUT_H
5 #include <net/net_namespace.h>
6 #include <linux/netfilter/nf_conntrack_common.h>
7 #include <linux/netfilter/nf_conntrack_tuple_common.h>
8 #include <linux/refcount.h>
9 #include <net/netfilter/nf_conntrack.h>
10 #include <net/netfilter/nf_conntrack_extend.h>
12 #define CTNL_TIMEOUT_NAME_MAX 32
14 struct nf_ct_timeout {
16 const struct nf_conntrack_l4proto *l4proto;
21 struct list_head head;
22 struct rcu_head rcu_head;
24 char name[CTNL_TIMEOUT_NAME_MAX];
25 struct nf_ct_timeout timeout;
28 struct nf_conn_timeout {
29 struct nf_ct_timeout __rcu *timeout;
32 static inline unsigned int *
33 nf_ct_timeout_data(const struct nf_conn_timeout *t)
35 #ifdef CONFIG_NF_CONNTRACK_TIMEOUT
36 struct nf_ct_timeout *timeout;
38 timeout = rcu_dereference(t->timeout);
42 return (unsigned int *)timeout->data;
49 struct nf_conn_timeout *nf_ct_timeout_find(const struct nf_conn *ct)
51 #ifdef CONFIG_NF_CONNTRACK_TIMEOUT
52 return nf_ct_ext_find(ct, NF_CT_EXT_TIMEOUT);
59 struct nf_conn_timeout *nf_ct_timeout_ext_add(struct nf_conn *ct,
60 struct nf_ct_timeout *timeout,
63 #ifdef CONFIG_NF_CONNTRACK_TIMEOUT
64 struct nf_conn_timeout *timeout_ext;
66 timeout_ext = nf_ct_ext_add(ct, NF_CT_EXT_TIMEOUT, gfp);
67 if (timeout_ext == NULL)
70 rcu_assign_pointer(timeout_ext->timeout, timeout);
78 static inline unsigned int *nf_ct_timeout_lookup(const struct nf_conn *ct)
80 unsigned int *timeouts = NULL;
81 #ifdef CONFIG_NF_CONNTRACK_TIMEOUT
82 struct nf_conn_timeout *timeout_ext;
84 timeout_ext = nf_ct_timeout_find(ct);
86 timeouts = nf_ct_timeout_data(timeout_ext);
91 #ifdef CONFIG_NF_CONNTRACK_TIMEOUT
92 int nf_conntrack_timeout_init(void);
93 void nf_conntrack_timeout_fini(void);
94 void nf_ct_untimeout(struct net *net, struct nf_ct_timeout *timeout);
95 int nf_ct_set_timeout(struct net *net, struct nf_conn *ct, u8 l3num, u8 l4num,
96 const char *timeout_name);
97 void nf_ct_destroy_timeout(struct nf_conn *ct);
99 static inline int nf_conntrack_timeout_init(void)
104 static inline void nf_conntrack_timeout_fini(void)
109 static inline int nf_ct_set_timeout(struct net *net, struct nf_conn *ct,
111 const char *timeout_name)
116 static inline void nf_ct_destroy_timeout(struct nf_conn *ct)
120 #endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
122 #ifdef CONFIG_NF_CONNTRACK_TIMEOUT
123 extern struct nf_ct_timeout *(*nf_ct_timeout_find_get_hook)(struct net *net, const char *name);
124 extern void (*nf_ct_timeout_put_hook)(struct nf_ct_timeout *timeout);
127 #endif /* _NF_CONNTRACK_TIMEOUT_H */