Merge tag 'sound-5.18-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai...
[linux-block.git] / include / net / netfilter / nf_conntrack_timeout.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
dd705072
PNA
2#ifndef _NF_CONNTRACK_TIMEOUT_H
3#define _NF_CONNTRACK_TIMEOUT_H
4
5#include <net/net_namespace.h>
6#include <linux/netfilter/nf_conntrack_common.h>
7#include <linux/netfilter/nf_conntrack_tuple_common.h>
b54ab92b 8#include <linux/refcount.h>
dd705072
PNA
9#include <net/netfilter/nf_conntrack.h>
10#include <net/netfilter/nf_conntrack_extend.h>
11
12#define CTNL_TIMEOUT_NAME_MAX 32
13
6c1fd7dc
PNA
14struct nf_ct_timeout {
15 __u16 l3num;
16 const struct nf_conntrack_l4proto *l4proto;
6daf1414 17 char data[];
6c1fd7dc
PNA
18};
19
dd705072
PNA
20struct ctnl_timeout {
21 struct list_head head;
22 struct rcu_head rcu_head;
b54ab92b 23 refcount_t refcnt;
dd705072 24 char name[CTNL_TIMEOUT_NAME_MAX];
6c1fd7dc 25 struct nf_ct_timeout timeout;
dd705072
PNA
26};
27
28struct nf_conn_timeout {
6c1fd7dc 29 struct nf_ct_timeout __rcu *timeout;
dd705072
PNA
30};
31
ae2d708e 32static inline unsigned int *
0434ccdc 33nf_ct_timeout_data(const struct nf_conn_timeout *t)
ae2d708e 34{
22e81d74 35#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
6c1fd7dc 36 struct nf_ct_timeout *timeout;
ae2d708e
PNA
37
38 timeout = rcu_dereference(t->timeout);
39 if (timeout == NULL)
40 return NULL;
41
42 return (unsigned int *)timeout->data;
22e81d74
JS
43#else
44 return NULL;
45#endif
ae2d708e 46}
dd705072
PNA
47
48static inline
49struct nf_conn_timeout *nf_ct_timeout_find(const struct nf_conn *ct)
50{
51#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
52 return nf_ct_ext_find(ct, NF_CT_EXT_TIMEOUT);
53#else
54 return NULL;
55#endif
56}
57
58static inline
59struct nf_conn_timeout *nf_ct_timeout_ext_add(struct nf_conn *ct,
6c1fd7dc 60 struct nf_ct_timeout *timeout,
dd705072
PNA
61 gfp_t gfp)
62{
63#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
64 struct nf_conn_timeout *timeout_ext;
65
66 timeout_ext = nf_ct_ext_add(ct, NF_CT_EXT_TIMEOUT, gfp);
67 if (timeout_ext == NULL)
68 return NULL;
69
ae2d708e 70 rcu_assign_pointer(timeout_ext->timeout, timeout);
dd705072
PNA
71
72 return timeout_ext;
73#else
74 return NULL;
75#endif
76};
77
c779e849 78static inline unsigned int *nf_ct_timeout_lookup(const struct nf_conn *ct)
84b5ee93 79{
c779e849 80 unsigned int *timeouts = NULL;
84b5ee93
PNA
81#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
82 struct nf_conn_timeout *timeout_ext;
84b5ee93
PNA
83
84 timeout_ext = nf_ct_timeout_find(ct);
c779e849 85 if (timeout_ext)
ae2d708e 86 timeouts = nf_ct_timeout_data(timeout_ext);
84b5ee93 87#endif
c779e849 88 return timeouts;
84b5ee93
PNA
89}
90
dd705072 91#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
6c1fd7dc 92void nf_ct_untimeout(struct net *net, struct nf_ct_timeout *timeout);
717700d1
YHW
93int nf_ct_set_timeout(struct net *net, struct nf_conn *ct, u8 l3num, u8 l4num,
94 const char *timeout_name);
95void nf_ct_destroy_timeout(struct nf_conn *ct);
dd705072 96#else
717700d1
YHW
97static inline int nf_ct_set_timeout(struct net *net, struct nf_conn *ct,
98 u8 l3num, u8 l4num,
99 const char *timeout_name)
100{
101 return -EOPNOTSUPP;
102}
103
104static inline void nf_ct_destroy_timeout(struct nf_conn *ct)
105{
106 return;
107}
dd705072
PNA
108#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
109
110#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
7afa3883
FW
111struct nf_ct_timeout_hooks {
112 struct nf_ct_timeout *(*timeout_find_get)(struct net *net, const char *name);
113 void (*timeout_put)(struct nf_ct_timeout *timeout);
114};
115
116extern const struct nf_ct_timeout_hooks *nf_ct_timeout_hook;
dd705072
PNA
117#endif
118
119#endif /* _NF_CONNTRACK_TIMEOUT_H */