FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
cnat_translation.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef __CNAT_TRANSLATION_H__
17 #define __CNAT_TRANSLATION_H__
18 
19 #include <cnat/cnat_types.h>
20 #include <vnet/ip/ip_types.h>
21 #include <vppinfra/bihash_8_8.h>
22 
23 /**
24  * Counters for each translation
25  */
27 
28 
29 /**
30  * Data used to track an EP in the FIB
31  */
32 typedef struct cnat_ep_trk_t_
33 {
34  /**
35  * The EP being tracked
36  */
38 
39  /**
40  * The FIB entry for the EP
41  */
43 
44  /**
45  * The sibling on the entry's child list
46  */
48 
49  /**
50  * The forwarding contributed by the entry
51  */
53 
54  /**
55  * Allows to disable if not resolved yet
56  */
57  u8 ct_flags; /* cnat_trk_flag_t */
59 
61 {
62  /* Do allocate a source port */
64  /* Has this translation been satcked ?
65  * this allow not being called twice when
66  * with more then FIB_PATH_LIST_POPULAR backends */
69 
70 typedef enum
71 {
78 
79 typedef enum __attribute__ ((__packed__))
80 {
84 
85 /**
86  * Entry used to account for a translation's backend
87  * waiting for address resolution
88  */
89 typedef struct addr_resolution_t_
90 {
91  /**
92  * The interface index to resolve
93  */
95  /**
96  * ip4 or ip6 resolution
97  */
99  /**
100  * The cnat_addr_resolution_t
101  */
103  /**
104  * Translation index
105  */
107  /**
108  * Callback data
109  */
112 
113 /**
114  * A Translation represents the translation of a VEP to one of a set
115  * of real server addresses
116  */
117 typedef struct cnat_translation_t_
118 {
119  /**
120  * Linkage into the FIB graph
121  */
123 
124  /**
125  * The LB used to forward to the backends
126  */
128 
129  /**
130  * The Virtual end point
131  */
133 
134  /**
135  * The vector of tracked back-ends
136  */
138 
139  /**
140  * The vector of active tracked back-ends
141  */
143 
144  /**
145  * The ip protocol for the translation
146  */
148 
149  /**
150  * The client object this translation belongs on
151  * INDEX_INVALID if vip is unresolved
152  */
154 
155  /**
156  * Own index (if copied for trace)
157  */
159 
160  /**
161  * Translation flags
162  */
164 
165  /**
166  * Type of load balancing
167  */
169 
170  union
171  {
173  };
175 
177 
178 extern u8 *format_cnat_translation (u8 * s, va_list * args);
179 
180 /**
181  * create or update a translation
182  *
183  * @param vip The Virtual Endpoint
184  * @param ip_proto The ip protocol to translate
185  * @param backends the backends to choose from
186  *
187  * @return the ID of the translation. used to delete and gather stats
188  */
191  cnat_endpoint_tuple_t *backends, u8 flags,
193 
194 /**
195  * Delete a translation
196  *
197  * @param id the ID as returned from the create
198  */
199 extern int cnat_translation_delete (u32 id);
200 
201 /**
202  * Callback function invoked during a walk of all translations
203  */
205 
206 /**
207  * Walk/visit each of the translations
208  */
210 
211 /**
212  * Purge all the trahslations
213  */
214 extern int cnat_translation_purge (void);
215 
216 /**
217  * Add an address resolution request
218  */
219 extern void cnat_translation_watch_addr (index_t cti, u64 opaque,
220  cnat_endpoint_t * ep,
222 
223 /**
224  * Cleanup matching addr resolution requests
225  */
226 extern void cnat_translation_unwatch_addr (u32 cti,
228 
229 /**
230  * Register a call back for endpoint->address resolution
231  */
233  ip_address_t *address, u8 is_del);
234 
237 
238 /*
239  * Data plane functions
240  */
241 extern clib_bihash_8_8_t cnat_translation_db;
242 
245 {
247 }
248 
251 {
252  clib_bihash_kv_8_8_t bkey, bvalue;
253  u64 key;
254  int rv;
255 
256  key = ((u64) proto << 24) | port;
257  key = key << 32 | (u32) cti;
258 
259  bkey.key = key;
260  rv = clib_bihash_search_inline_2_8_8 (&cnat_translation_db, &bkey, &bvalue);
261  if (!rv)
262  return (pool_elt_at_index (cnat_translation_pool, bvalue.value));
263 
264  return (NULL);
265 }
266 
267 /*
268  * fd.io coding-style-patch-verification: ON
269  *
270  * Local Variables:
271  * eval: (c-set-style "gnu")
272  * End:
273  */
274 
275 #endif
ip_address
Definition: ip_types.h:79
CNAT_RESOLV_ADDR_BACKEND
@ CNAT_RESOLV_ADDR_BACKEND
Definition: cnat_translation.h:73
bihash_8_8.h
addr_resolution_t_::sw_if_index
u32 sw_if_index
The interface index to resolve.
Definition: cnat_translation.h:94
cnat_translation_t_::ct_proto
ip_protocol_t ct_proto
The ip protocol for the translation.
Definition: cnat_translation.h:147
cnat_ep_trk_t_::ct_ep
cnat_endpoint_t ct_ep[VLIB_N_DIR]
The EP being tracked.
Definition: cnat_translation.h:37
ip_proto
ip_proto
Definition: ip_types.api:75
CNAT_TRANSLATION_STACKED
@ CNAT_TRANSLATION_STACKED
Definition: cnat_translation.h:67
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:549
clib_bihash_kv_8_8_t::value
u64 value
the value
Definition: bihash_8_8.h:44
clib_bihash_kv_8_8_t::key
u64 key
the key
Definition: bihash_8_8.h:43
u16
unsigned short u16
Definition: types.h:57
cnat_translation_counters
vlib_combined_counter_main_t cnat_translation_counters
Counters for each translation.
Definition: cnat_translation.c:33
addr_resolution_t_::opaque
u64 opaque
Callback data.
Definition: cnat_translation.h:110
cnat_translation_flag_t
enum cnat_translation_flag_t_ cnat_translation_flag_t
port
u16 port
Definition: lb_types.api:73
cnat_endpoint_t_
Definition: cnat_types.h:73
cnat_ep_trk_t
struct cnat_ep_trk_t_ cnat_ep_trk_t
Data used to track an EP in the FIB.
key
typedef key
Definition: ipsec_types.api:91
cnat_ep_trk_t_::ct_fei
fib_node_index_t ct_fei
The FIB entry for the EP.
Definition: cnat_translation.h:42
cnat_types.h
cnat_endpoint_tuple_t_
Definition: cnat_types.h:81
CNAT_RESOLV_ADDR_SNAT
@ CNAT_RESOLV_ADDR_SNAT
Definition: cnat_translation.h:74
addr_resolution_t
struct addr_resolution_t_ addr_resolution_t
Entry used to account for a translation's backend waiting for address resolution.
cnat_translation_t_::ct_vip
cnat_endpoint_t ct_vip
The Virtual end point.
Definition: cnat_translation.h:132
cnat_translation_t_::ct_paths
cnat_ep_trk_t * ct_paths
The vector of tracked back-ends.
Definition: cnat_translation.h:137
cnat_translation_t_::lb_type
cnat_lb_type_t lb_type
Type of load balancing.
Definition: cnat_translation.h:168
cnat_ep_trk_t_::ct_flags
u8 ct_flags
Allows to disable if not resolved yet.
Definition: cnat_translation.h:57
lb_type
vl_api_cnat_lb_type_t lb_type
Definition: cnat.api:71
index_t
u32 index_t
A Data-Path Object is an object that represents actions that are applied to packets are they are swit...
Definition: dpo.h:43
static_always_inline
#define static_always_inline
Definition: clib.h:112
fib_node_index_t
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:29
cnat_ep_trk_t_::ct_sibling
u32 ct_sibling
The sibling on the entry's child list.
Definition: cnat_translation.h:47
cnat_translation_t_::ct_cci
index_t ct_cci
The client object this translation belongs on INDEX_INVALID if vip is unresolved.
Definition: cnat_translation.h:153
CNAT_LB_DEFAULT
@ CNAT_LB_DEFAULT
Definition: cnat_translation.h:81
address
manual_print typedef address
Definition: ip_types.api:96
ip_types.h
CNAT_TRANSLATION_FLAG_ALLOCATE_PORT
@ CNAT_TRANSLATION_FLAG_ALLOCATE_PORT
Definition: cnat_translation.h:63
cnat_translation_update
u32 cnat_translation_update(cnat_endpoint_t *vip, ip_protocol_t ip_proto, cnat_endpoint_tuple_t *backends, u8 flags, cnat_lb_type_t lb_type)
create or update a translation
Definition: cnat_translation.c:366
cnat_translation_t_::lb_maglev
u32 * lb_maglev
Definition: cnat_translation.h:172
CNAT_ADDR_N_RESOLUTIONS
@ CNAT_ADDR_N_RESOLUTIONS
Definition: cnat_translation.h:76
cnat_translation_register_addr_add_cb
void cnat_translation_register_addr_add_cb(cnat_addr_resol_type_t typ, cnat_if_addr_add_cb_t fn)
Definition: cnat_translation.c:814
cnat_translation_watch_addr
void cnat_translation_watch_addr(index_t cti, u64 opaque, cnat_endpoint_t *ep, cnat_addr_resol_type_t type)
Add an address resolution request.
Definition: cnat_translation.c:39
cnat_if_addr_add_cb_t
void(* cnat_if_addr_add_cb_t)(addr_resolution_t *ar, ip_address_t *address, u8 is_del)
Register a call back for endpoint->address resolution.
Definition: cnat_translation.h:232
cnat_translation_walk_cb_t
walk_rc_t(* cnat_translation_walk_cb_t)(index_t index, void *ctx)
Callback function invoked during a walk of all translations.
Definition: cnat_translation.h:204
cnat_translation_unwatch_addr
void cnat_translation_unwatch_addr(u32 cti, cnat_addr_resol_type_t type)
Cleanup matching addr resolution requests.
Definition: cnat_translation.c:63
format_cnat_translation
u8 * format_cnat_translation(u8 *s, va_list *args)
Definition: cnat_translation.c:478
addr_resolution_t_::type
cnat_addr_resol_type_t type
The cnat_addr_resolution_t.
Definition: cnat_translation.h:102
index
u32 index
Definition: flow_types.api:221
cnat_translation_t
struct cnat_translation_t_ cnat_translation_t
A Translation represents the translation of a VEP to one of a set of real server addresses.
u64
unsigned long u64
Definition: types.h:89
cnat_addr_resol_type_t
cnat_addr_resol_type_t
Definition: cnat_translation.h:70
vlib_combined_counter_main_t
A collection of combined counters.
Definition: counter.h:203
cnat_translation_t_::ct_node
fib_node_t ct_node
Linkage into the FIB graph.
Definition: cnat_translation.h:122
u32
unsigned int u32
Definition: types.h:88
cnat_lb_type_t
cnat_lb_type_t
Definition: cnat_translation.h:79
cnat_translation_pool
cnat_translation_t * cnat_translation_pool
Definition: cnat_translation.c:26
ctx
long ctx[MAX_CONNS]
Definition: main.c:144
cnat_translation_t_::ct_active_paths
cnat_ep_trk_t * ct_active_paths
The vector of active tracked back-ends.
Definition: cnat_translation.h:142
CNAT_LB_MAGLEV
@ CNAT_LB_MAGLEV
Definition: cnat_translation.h:82
clib_bihash_kv_8_8_t
8 octet key, 8 octet key value pair
Definition: bihash_8_8.h:41
cnat_translation_walk
void cnat_translation_walk(cnat_translation_walk_cb_t cb, void *ctx)
Walk/visit each of the translations.
Definition: cnat_translation.c:451
addr_resolution_t_::af
ip_address_family_t af
ip4 or ip6 resolution
Definition: cnat_translation.h:98
VLIB_N_DIR
#define VLIB_N_DIR
Definition: defs.h:57
fib_node_t_
An node in the FIB graph.
Definition: fib_node.h:301
ip_protocol_t
enum ip_protocol ip_protocol_t
cnat_translation_t_::index
index_t index
Own index (if copied for trace)
Definition: cnat_translation.h:158
u8
unsigned char u8
Definition: types.h:56
cnat_translation_delete
int cnat_translation_delete(u32 id)
Delete a translation.
Definition: cnat_translation.c:342
cnat_translation_db
clib_bihash_8_8_t cnat_translation_db
Definition: cnat_translation.c:27
CNAT_RESOLV_ADDR_TRANSLATION
@ CNAT_RESOLV_ADDR_TRANSLATION
Definition: cnat_translation.h:75
cnat_translation_t_::ct_lb
dpo_id_t ct_lb
The LB used to forward to the backends.
Definition: cnat_translation.h:127
dpo_id_t_
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
Definition: dpo.h:172
CNAT_RESOLV_ADDR_ANY
@ CNAT_RESOLV_ADDR_ANY
Definition: cnat_translation.h:72
rv
int __clib_unused rv
Definition: application.c:491
addr_resolution_t_::cti
index_t cti
Translation index.
Definition: cnat_translation.h:106
proto
vl_api_ip_proto_t proto
Definition: acl_types.api:51
cnat_translation_t_::flags
u8 flags
Translation flags.
Definition: cnat_translation.h:163
walk_rc_t
enum walk_rc_t_ walk_rc_t
Walk return code.
cnat_ep_trk_t_::ct_dpo
dpo_id_t ct_dpo
The forwarding contributed by the entry.
Definition: cnat_translation.h:52
cnat_translation_flag_t_
cnat_translation_flag_t_
Definition: cnat_translation.h:60
type
vl_api_fib_path_type_t type
Definition: fib_types.api:123
cnat_translation_get
static_always_inline cnat_translation_t * cnat_translation_get(index_t cti)
Definition: cnat_translation.h:244
addr_resolution_t_
Entry used to account for a translation's backend waiting for address resolution.
Definition: cnat_translation.h:89
cnat_translation_t_
A Translation represents the translation of a VEP to one of a set of real server addresses.
Definition: cnat_translation.h:117
cnat_ep_trk_t_
Data used to track an EP in the FIB.
Definition: cnat_translation.h:32
ip_address_family_t
enum ip_address_family_t_ ip_address_family_t
cnat_find_translation
static_always_inline cnat_translation_t * cnat_find_translation(index_t cti, u16 port, ip_protocol_t proto)
Definition: cnat_translation.h:250
cnat_translation_purge
int cnat_translation_purge(void)
Purge all the trahslations.
Definition: cnat_translation.c:557
flags
vl_api_wireguard_peer_flags_t flags
Definition: wireguard.api:105