hc
2024-03-22 ac5f19e89dcbd5c7428fcc78a0d407c887564466
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _NF_CONNTRACK_TIMEOUT_H
#define _NF_CONNTRACK_TIMEOUT_H
 
#include <net/net_namespace.h>
#include <linux/netfilter/nf_conntrack_common.h>
#include <linux/netfilter/nf_conntrack_tuple_common.h>
#include <linux/refcount.h>
#include <net/netfilter/nf_conntrack.h>
#include <net/netfilter/nf_conntrack_extend.h>
 
#define CTNL_TIMEOUT_NAME_MAX    32
 
struct nf_ct_timeout {
   __u16            l3num;
   const struct nf_conntrack_l4proto *l4proto;
   char            data[];
};
 
struct ctnl_timeout {
   struct list_head    head;
   struct rcu_head        rcu_head;
   refcount_t        refcnt;
   char            name[CTNL_TIMEOUT_NAME_MAX];
   struct nf_ct_timeout    timeout;
};
 
struct nf_conn_timeout {
   struct nf_ct_timeout __rcu *timeout;
};
 
static inline unsigned int *
nf_ct_timeout_data(const struct nf_conn_timeout *t)
{
#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
   struct nf_ct_timeout *timeout;
 
   timeout = rcu_dereference(t->timeout);
   if (timeout == NULL)
       return NULL;
 
   return (unsigned int *)timeout->data;
#else
   return NULL;
#endif
}
 
static inline
struct nf_conn_timeout *nf_ct_timeout_find(const struct nf_conn *ct)
{
#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
   return nf_ct_ext_find(ct, NF_CT_EXT_TIMEOUT);
#else
   return NULL;
#endif
}
 
static inline
struct nf_conn_timeout *nf_ct_timeout_ext_add(struct nf_conn *ct,
                         struct nf_ct_timeout *timeout,
                         gfp_t gfp)
{
#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
   struct nf_conn_timeout *timeout_ext;
 
   timeout_ext = nf_ct_ext_add(ct, NF_CT_EXT_TIMEOUT, gfp);
   if (timeout_ext == NULL)
       return NULL;
 
   rcu_assign_pointer(timeout_ext->timeout, timeout);
 
   return timeout_ext;
#else
   return NULL;
#endif
};
 
static inline unsigned int *nf_ct_timeout_lookup(const struct nf_conn *ct)
{
   unsigned int *timeouts = NULL;
#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
   struct nf_conn_timeout *timeout_ext;
 
   timeout_ext = nf_ct_timeout_find(ct);
   if (timeout_ext)
       timeouts = nf_ct_timeout_data(timeout_ext);
#endif
   return timeouts;
}
 
#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
int nf_conntrack_timeout_init(void);
void nf_conntrack_timeout_fini(void);
void nf_ct_untimeout(struct net *net, struct nf_ct_timeout *timeout);
int nf_ct_set_timeout(struct net *net, struct nf_conn *ct, u8 l3num, u8 l4num,
             const char *timeout_name);
void nf_ct_destroy_timeout(struct nf_conn *ct);
#else
static inline int nf_conntrack_timeout_init(void)
{
        return 0;
}
 
static inline void nf_conntrack_timeout_fini(void)
{
        return;
}
 
static inline int nf_ct_set_timeout(struct net *net, struct nf_conn *ct,
                   u8 l3num, u8 l4num,
                   const char *timeout_name)
{
   return -EOPNOTSUPP;
}
 
static inline void nf_ct_destroy_timeout(struct nf_conn *ct)
{
   return;
}
#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
 
#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
extern struct nf_ct_timeout *(*nf_ct_timeout_find_get_hook)(struct net *net, const char *name);
extern void (*nf_ct_timeout_put_hook)(struct nf_ct_timeout *timeout);
#endif
 
#endif /* _NF_CONNTRACK_TIMEOUT_H */