3 * ct6.h - skeleton vpp engine plug-in header file
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:
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #ifndef __included_ct6_h__
19 #define __included_ct6_h__
21 #include <vnet/vnet.h>
22 #include <vnet/ip/ip.h>
23 #include <vnet/ethernet/ethernet.h>
24 #include <vppinfra/bihash_48_8.h>
26 #include <vppinfra/hash.h>
27 #include <vppinfra/error.h>
30 typedef CLIB_PACKED (struct
41 u8 proto; /* byte 37 */
50 ct6_session_key_t key;
60 /* API message ID base */
63 /* session lookup table */
64 clib_bihash_48_8_t session_hash;
65 u8 feature_initialized;
67 /* per_thread session pools */
68 ct6_session_t **sessions;
72 /* Config parameters */
73 f64 session_timeout_interval;
74 uword session_hash_memory;
75 u32 session_hash_buckets;
76 u32 max_sessions_per_worker;
79 vlib_main_t *vlib_main;
80 vnet_main_t *vnet_main;
81 ethernet_main_t *ethernet_main;
84 extern ct6_main_t ct6_main;
86 extern vlib_node_registration_t ct6_out2in_node;
87 extern vlib_node_registration_t ct6_in2out_node;
89 format_function_t format_ct6_session;
91 ct6_session_t *ct6_create_or_recycle_session (ct6_main_t * cmp,
92 clib_bihash_kv_48_8_t * kvpp,
93 f64 now, u32 my_thread_index,
94 u32 * recyclep, u32 * createp);
97 ct6_lru_remove (ct6_main_t * cmp, ct6_session_t * s0)
99 ct6_session_t *next_sess, *prev_sess;
103 thread_index = s0->thread_index;
105 s0_index = s0 - cmp->sessions[thread_index];
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;
114 if (s0->next_index != ~0)
116 next_sess = pool_elt_at_index (cmp->sessions[thread_index],
118 next_sess->prev_index = s0->prev_index;
121 if (s0->prev_index != ~0)
123 prev_sess = pool_elt_at_index (cmp->sessions[thread_index],
125 prev_sess->next_index = s0->next_index;
130 ct6_lru_add (ct6_main_t * cmp, ct6_session_t * s0, f64 now)
132 ct6_session_t *next_sess;
137 s0->expires = now + cmp->session_timeout_interval;
138 thread_index = s0->thread_index;
140 s0_index = s0 - cmp->sessions[thread_index];
143 * Re-add at the head of the forward LRU list,
144 * tail of the reverse LRU list
146 if (cmp->first_index[thread_index] != ~0)
148 next_sess = pool_elt_at_index (cmp->sessions[thread_index],
149 cmp->first_index[thread_index]);
150 next_sess->prev_index = s0_index;
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;
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;
165 ct6_update_session_hit (ct6_main_t * cmp, ct6_session_t * s0, f64 now)
167 ct6_lru_remove (cmp, s0);
168 ct6_lru_add (cmp, s0, now);
171 #endif /* __included_ct6_h__ */
174 * fd.io coding-style-patch-verification: ON
177 * eval: (c-set-style "gnu")