FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
ct6.h
Go to the documentation of this file.
1 
2 /*
3  * ct6.h - skeleton vpp engine plug-in header file
4  *
5  * Copyright (c) <current-year> <your-organization>
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at:
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 #ifndef __included_ct6_h__
19 #define __included_ct6_h__
20 
21 #include <vnet/vnet.h>
22 #include <vnet/ip/ip.h>
23 #include <vnet/ethernet/ethernet.h>
24 #include <vppinfra/bihash_48_8.h>
25 
26 #include <vppinfra/hash.h>
27 #include <vppinfra/error.h>
28 
29 /* *INDENT-OFF* */
30 typedef CLIB_PACKED (struct
31 {
32  union
33  {
34  struct
35  {
36  /* out2in */
37  ip6_address_t src;
38  ip6_address_t dst;
39  u16 sport;
40  u16 dport;
41  u8 proto; /* byte 37 */
42  };
43  u64 as_u64[6];
44  };
45 }) ct6_session_key_t;
46 /* *INDENT-ON* */
47 
48 typedef struct
49 {
50  ct6_session_key_t key;
57 
58 typedef struct
59 {
60  /* API message ID base */
62 
63  /* session lookup table */
64  clib_bihash_48_8_t session_hash;
66 
67  /* per_thread session pools */
71 
72  /* Config parameters */
77 
78  /* convenience */
82 } ct6_main_t;
83 
84 extern ct6_main_t ct6_main;
85 
88 
90 
92  clib_bihash_kv_48_8_t * kvpp,
93  f64 now, u32 my_thread_index,
94  u32 * recyclep, u32 * createp);
95 
96 static inline void
98 {
99  ct6_session_t *next_sess, *prev_sess;
101  u32 s0_index;
102 
104 
105  s0_index = s0 - cmp->sessions[thread_index];
106 
107  /* Deal with list heads */
108  if (s0_index == cmp->first_index[thread_index])
109  cmp->first_index[thread_index] = s0->next_index;
110  if (s0_index == cmp->last_index[thread_index])
111  cmp->last_index[thread_index] = s0->prev_index;
112 
113  /* Fix next->prev */
114  if (s0->next_index != ~0)
115  {
116  next_sess = pool_elt_at_index (cmp->sessions[thread_index],
117  s0->next_index);
118  next_sess->prev_index = s0->prev_index;
119  }
120  /* Fix prev->next */
121  if (s0->prev_index != ~0)
122  {
123  prev_sess = pool_elt_at_index (cmp->sessions[thread_index],
124  s0->prev_index);
125  prev_sess->next_index = s0->next_index;
126  }
127 }
128 
129 static inline void
131 {
132  ct6_session_t *next_sess;
134  u32 s0_index;
135 
136  s0->hits++;
137  s0->expires = now + cmp->session_timeout_interval;
139 
140  s0_index = s0 - cmp->sessions[thread_index];
141 
142  /*
143  * Re-add at the head of the forward LRU list,
144  * tail of the reverse LRU list
145  */
146  if (cmp->first_index[thread_index] != ~0)
147  {
148  next_sess = pool_elt_at_index (cmp->sessions[thread_index],
149  cmp->first_index[thread_index]);
150  next_sess->prev_index = s0_index;
151  }
152 
153  s0->prev_index = ~0;
154 
155  /* s0 now the new head of the LRU forward list */
156  s0->next_index = cmp->first_index[thread_index];
157  cmp->first_index[thread_index] = s0_index;
158 
159  /* single session case: also the tail of the reverse LRU list */
160  if (cmp->last_index[thread_index] == ~0)
161  cmp->last_index[thread_index] = s0_index;
162 }
163 
164 static inline void
166 {
167  ct6_lru_remove (cmp, s0);
168  ct6_lru_add (cmp, s0, now);
169 }
170 
171 #endif /* __included_ct6_h__ */
172 
173 /*
174  * fd.io coding-style-patch-verification: ON
175  *
176  * Local Variables:
177  * eval: (c-set-style "gnu")
178  * End:
179  */
thread_index
u32 thread_index
Definition: nat44_ei_hairpinning.c:495
ct6_main_t::first_index
u32 * first_index
Definition: ct6.h:69
ct6_session_t::thread_index
u32 thread_index
Definition: ct6.h:51
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:549
ct6_out2in_node
vlib_node_registration_t ct6_out2in_node
(constructor) VLIB_REGISTER_NODE (ct6_out2in_node)
Definition: ct6_out2in.c:251
ct6_session_t::key
ct6_session_key_t key
Definition: ct6.h:50
ct6_update_session_hit
static void ct6_update_session_hit(ct6_main_t *cmp, ct6_session_t *s0, f64 now)
Definition: ct6.h:165
u16
unsigned short u16
Definition: types.h:57
ct6_in2out_node
vlib_node_registration_t ct6_in2out_node
(constructor) VLIB_REGISTER_NODE (ct6_in2out_node)
Definition: ct6_in2out.c:349
ethernet.h
ct6_session_t::hits
u32 hits
Definition: ct6.h:54
ct6_main_t
Definition: ct6.h:58
sport
u16 sport
Definition: pnat.api:43
ct6_main_t::session_hash
clib_bihash_48_8_t session_hash
Definition: ct6.h:64
hash.h
ct6_session_t::prev_index
u32 prev_index
Definition: ct6.h:53
error.h
ct6_main_t::vnet_main
vnet_main_t * vnet_main
Definition: ct6.h:80
ethernet_main_t_
Definition: ethernet.h:288
ct6_main_t::sessions
ct6_session_t ** sessions
Definition: ct6.h:68
ct6_lru_add
static void ct6_lru_add(ct6_main_t *cmp, ct6_session_t *s0, f64 now)
Definition: ct6.h:130
uword
u64 uword
Definition: types.h:112
ct6_session_t::expires
f64 expires
Definition: ct6.h:55
ct6_lru_remove
static void ct6_lru_remove(ct6_main_t *cmp, ct6_session_t *s0)
Definition: ct6.h:97
f64
double f64
Definition: types.h:142
ct6_main_t::feature_initialized
u8 feature_initialized
Definition: ct6.h:65
src
vl_api_address_t src
Definition: gre.api:54
ct6_main_t::msg_id_base
u16 msg_id_base
Definition: ct6.h:61
vlib_node_registration_t
struct _vlib_node_registration vlib_node_registration_t
ct6_main_t::session_hash_memory
uword session_hash_memory
Definition: ct6.h:74
ct6_main_t::session_hash_buckets
u32 session_hash_buckets
Definition: ct6.h:75
ct6_main_t::vlib_main
vlib_main_t * vlib_main
Definition: ct6.h:79
ct6_create_or_recycle_session
ct6_session_t * ct6_create_or_recycle_session(ct6_main_t *cmp, clib_bihash_kv_48_8_t *kvpp, f64 now, u32 my_thread_index, u32 *recyclep, u32 *createp)
Definition: ct6_in2out.c:77
format_function_t
u8 *() format_function_t(u8 *s, va_list *args)
Definition: format.h:48
vnet_main_t
Definition: vnet.h:76
u64
unsigned long u64
Definition: types.h:89
dport
u16 dport
Definition: pnat.api:44
ip.h
u32
unsigned int u32
Definition: types.h:88
dst
vl_api_ip4_address_t dst
Definition: pnat.api:41
ct6_session_t
Definition: ct6.h:48
as_u64
u64 as_u64
Definition: bihash_doc.h:63
now
f64 now
Definition: nat44_ei_out2in.c:710
vlib_main_t
Definition: main.h:102
u8
unsigned char u8
Definition: types.h:56
CLIB_PACKED
typedef CLIB_PACKED(struct { union { struct { ip6_address_t src;ip6_address_t dst;u16 sport;u16 dport;u8 proto;};u64 as_u64[6];};}) ct6_session_key_t
ct6_main_t::max_sessions_per_worker
u32 max_sessions_per_worker
Definition: ct6.h:76
ct6_session_t::next_index
u32 next_index
Definition: ct6.h:52
ct6_main_t::session_timeout_interval
f64 session_timeout_interval
Definition: ct6.h:73
vnet.h
proto
vl_api_ip_proto_t proto
Definition: acl_types.api:51
ct6_main_t::last_index
u32 * last_index
Definition: ct6.h:70
ct6_main_t::ethernet_main
ethernet_main_t * ethernet_main
Definition: ct6.h:81
clib_bihash_kv_48_8_t
Definition: bihash_48_8.h:39
format_ct6_session
format_function_t format_ct6_session
Definition: ct6.h:89
bihash_48_8.h
ct6_main
ct6_main_t ct6_main
Definition: ct6.c:33