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
;
20 struct nf_conn_timeout
{
21 struct nf_ct_timeout __rcu
*timeout
;
24 static inline unsigned int *
25 nf_ct_timeout_data(const struct nf_conn_timeout
*t
)
27 #ifdef CONFIG_NF_CONNTRACK_TIMEOUT
28 struct nf_ct_timeout
*timeout
;
30 timeout
= rcu_dereference(t
->timeout
);
34 return (unsigned int *)timeout
->data
;
41 struct nf_conn_timeout
*nf_ct_timeout_find(const struct nf_conn
*ct
)
43 #ifdef CONFIG_NF_CONNTRACK_TIMEOUT
44 return nf_ct_ext_find(ct
, NF_CT_EXT_TIMEOUT
);
51 struct nf_conn_timeout
*nf_ct_timeout_ext_add(struct nf_conn
*ct
,
52 struct nf_ct_timeout
*timeout
,
55 #ifdef CONFIG_NF_CONNTRACK_TIMEOUT
56 struct nf_conn_timeout
*timeout_ext
;
58 timeout_ext
= nf_ct_ext_add(ct
, NF_CT_EXT_TIMEOUT
, gfp
);
59 if (timeout_ext
== NULL
)
62 rcu_assign_pointer(timeout_ext
->timeout
, timeout
);
70 static inline unsigned int *nf_ct_timeout_lookup(const struct nf_conn
*ct
)
72 unsigned int *timeouts
= NULL
;
73 #ifdef CONFIG_NF_CONNTRACK_TIMEOUT
74 struct nf_conn_timeout
*timeout_ext
;
76 timeout_ext
= nf_ct_timeout_find(ct
);
78 timeouts
= nf_ct_timeout_data(timeout_ext
);
83 #ifdef CONFIG_NF_CONNTRACK_TIMEOUT
84 void nf_ct_untimeout(struct net
*net
, struct nf_ct_timeout
*timeout
);
85 int nf_ct_set_timeout(struct net
*net
, struct nf_conn
*ct
, u8 l3num
, u8 l4num
,
86 const char *timeout_name
);
87 void nf_ct_destroy_timeout(struct nf_conn
*ct
);
89 static inline int nf_ct_set_timeout(struct net
*net
, struct nf_conn
*ct
,
91 const char *timeout_name
)
96 static inline void nf_ct_destroy_timeout(struct nf_conn
*ct
)
100 #endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
102 #ifdef CONFIG_NF_CONNTRACK_TIMEOUT
103 struct nf_ct_timeout_hooks
{
104 struct nf_ct_timeout
*(*timeout_find_get
)(struct net
*net
, const char *name
);
105 void (*timeout_put
)(struct nf_ct_timeout
*timeout
);
108 extern const struct nf_ct_timeout_hooks __rcu
*nf_ct_timeout_hook
;
111 #endif /* _NF_CONNTRACK_TIMEOUT_H */