1
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>
8#include <linux/refcount.h>
9#include <net/netfilter/nf_conntrack.h>
10#include <net/netfilter/nf_conntrack_extend.h>
11
12#define CTNL_TIMEOUT_NAME_MAX 32
13
14struct nf_ct_timeout {
15 __u16 l3num;
16 const struct nf_conntrack_l4proto *l4proto;
17 char data[0];
18};
19
20struct ctnl_timeout {
21 struct list_head head;
22 struct rcu_head rcu_head;
23 refcount_t refcnt;
24 char name[CTNL_TIMEOUT_NAME_MAX];
25 struct nf_ct_timeout timeout;
26};
27
28struct nf_conn_timeout {
29 struct nf_ct_timeout __rcu *timeout;
30};
31
32static inline unsigned int *
33nf_ct_timeout_data(const struct nf_conn_timeout *t)
34{
35#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
36 struct nf_ct_timeout *timeout;
37
38 timeout = rcu_dereference(t->timeout);
39 if (timeout == NULL)
40 return NULL;
41
42 return (unsigned int *)timeout->data;
43#else
44 return NULL;
45#endif
46}
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,
60 struct nf_ct_timeout *timeout,
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
70 rcu_assign_pointer(timeout_ext->timeout, timeout);
71
72 return timeout_ext;
73#else
74 return NULL;
75#endif
76};
77
78static inline unsigned int *nf_ct_timeout_lookup(const struct nf_conn *ct)
79{
80 unsigned int *timeouts = NULL;
81#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
82 struct nf_conn_timeout *timeout_ext;
83
84 timeout_ext = nf_ct_timeout_find(ct);
85 if (timeout_ext)
86 timeouts = nf_ct_timeout_data(timeout_ext);
87#endif
88 return timeouts;
89}
90
91#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
92int nf_conntrack_timeout_init(void);
93void nf_conntrack_timeout_fini(void);
94void nf_ct_untimeout(struct net *net, struct nf_ct_timeout *timeout);
95int nf_ct_set_timeout(struct net *net, struct nf_conn *ct, u8 l3num, u8 l4num,
96 const char *timeout_name);
97void nf_ct_destroy_timeout(struct nf_conn *ct);
98#else
99static inline int nf_conntrack_timeout_init(void)
100{
101 return 0;
102}
103
104static inline void nf_conntrack_timeout_fini(void)
105{
106 return;
107}
108
109static inline int nf_ct_set_timeout(struct net *net, struct nf_conn *ct,
110 u8 l3num, u8 l4num,
111 const char *timeout_name)
112{
113 return -EOPNOTSUPP;
114}
115
116static inline void nf_ct_destroy_timeout(struct nf_conn *ct)
117{
118 return;
119}
120#endif
121
122#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
123extern struct nf_ct_timeout *(*nf_ct_timeout_find_get_hook)(struct net *net, const char *name);
124extern void (*nf_ct_timeout_put_hook)(struct nf_ct_timeout *timeout);
125#endif
126
127#endif
128