FD.io VPP  v21.01.1
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  * Data used to track an EP in the FIB
30  */
31 typedef struct cnat_ep_trk_t_
32 {
33  /**
34  * The EP being tracked
35  */
37 
38  /**
39  * The FIB entry for the EP
40  */
42 
43  /**
44  * The sibling on the entry's child list
45  */
47 
48  /**
49  * The forwarding contributed by the entry
50  */
52 
53  /**
54  * Allows to disable if not resolved yet
55  */
58 
60 {
61  /* Do allocate a source port */
63  /* Has this translation been satcked ?
64  * this allow not being called twice when
65  * with more then FIB_PATH_LIST_POPULAR backends */
68 
69 typedef enum
70 {
77 
78 /**
79  * Entry used to account for a translation's backend
80  * waiting for address resolution
81  */
82 typedef struct addr_resolution_t_
83 {
84  /**
85  * The interface index to resolve
86  */
88  /**
89  * ip4 or ip6 resolution
90  */
92  /**
93  * The cnat_addr_resolution_t
94  */
95  cnat_addr_resol_type_t type;
96  /**
97  * Translation index
98  */
100  /**
101  * Callback data
102  */
105 
106 /**
107  * A Translation represents the translation of a VEP to one of a set
108  * of real server addresses
109  */
110 typedef struct cnat_translation_t_
111 {
112  /**
113  * Linkage into the FIB graph
114  */
116 
117  /**
118  * The LB used to forward to the backends
119  */
121 
122  /**
123  * The Virtual end point
124  */
126 
127  /**
128  * The vector of tracked back-ends
129  */
131 
132  /**
133  * The ip protocol for the translation
134  */
136 
137  /**
138  * The client object this translation belongs on
139  * INDEX_INVALID if vip is unresolved
140  */
142 
143  /**
144  * Own index (if copied for trace)
145  */
147 
148  /**
149  * Translation flags
150  */
153 
155 
156 extern u8 *format_cnat_translation (u8 * s, va_list * args);
157 
158 /**
159  * create or update a translation
160  *
161  * @param vip The Virtual Endpoint
162  * @param ip_proto The ip protocol to translate
163  * @param backends the backends to choose from
164  *
165  * @return the ID of the translation. used to delete and gather stats
166  */
170  backends, u8 flags);
171 
172 /**
173  * Delete a translation
174  *
175  * @param id the ID as returned from the create
176  */
177 extern int cnat_translation_delete (u32 id);
178 
179 /**
180  * Callback function invoked during a walk of all translations
181  */
183 
184 /**
185  * Walk/visit each of the translations
186  */
188 
189 /**
190  * Purge all the trahslations
191  */
192 extern int cnat_translation_purge (void);
193 
194 /**
195  * Add an address resolution request
196  */
197 extern void cnat_translation_watch_addr (index_t cti, u64 opaque,
198  cnat_endpoint_t * ep,
199  cnat_addr_resol_type_t type);
200 
201 /**
202  * Cleanup matching addr resolution requests
203  */
204 extern void cnat_translation_unwatch_addr (u32 cti,
205  cnat_addr_resol_type_t type);
206 
207 /*
208  * Data plane functions
209  */
210 extern clib_bihash_8_8_t cnat_translation_db;
211 
214 {
215  return (pool_elt_at_index (cnat_translation_pool, cti));
216 }
217 
220 {
221  clib_bihash_kv_8_8_t bkey, bvalue;
222  u64 key;
223  int rv;
224 
225  key = ((u64) proto << 24) | port;
226  key = key << 32 | (u32) cti;
227 
228  bkey.key = key;
229  rv = clib_bihash_search_inline_2_8_8 (&cnat_translation_db, &bkey, &bvalue);
230  if (!rv)
231  return (pool_elt_at_index (cnat_translation_pool, bvalue.value));
232 
233  return (NULL);
234 }
235 
236 /*
237  * fd.io coding-style-patch-verification: ON
238  *
239  * Local Variables:
240  * eval: (c-set-style "gnu")
241  * End:
242  */
243 
244 #endif
walk_rc_t(* cnat_translation_walk_cb_t)(index_t index, void *ctx)
Callback function invoked during a walk of all translations.
cnat_translation_flag_t_
vl_api_wireguard_peer_flags_t flags
Definition: wireguard.api:105
static_always_inline cnat_translation_t * cnat_translation_get(index_t cti)
cnat_translation_t * cnat_translation_pool
unsigned long u64
Definition: types.h:89
ip_proto
Definition: ip_types.api:75
ip_protocol_t ct_proto
The ip protocol for the translation.
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:41
int cnat_translation_purge(void)
Purge all the trahslations.
A Translation represents the translation of a VEP to one of a set of real server addresses.
vlib_combined_counter_main_t cnat_translation_counters
Counters for each translation.
int cnat_translation_delete(u32 id)
Delete a translation.
unsigned char u8
Definition: types.h:56
u32 sw_if_index
The interface index to resolve.
u64 opaque
Callback data.
enum walk_rc_t_ walk_rc_t
Walk return code.
u32 cnat_translation_update(cnat_endpoint_t *vip, ip_protocol_t ip_proto, cnat_endpoint_tuple_t *backends, u8 flags)
create or update a translation
#define static_always_inline
Definition: clib.h:109
cnat_endpoint_t ct_vip
The Virtual end point.
static_always_inline cnat_translation_t * cnat_find_translation(index_t cti, u16 port, ip_protocol_t proto)
enum cnat_translation_flag_t_ cnat_translation_flag_t
cnat_addr_resol_type_t
unsigned int u32
Definition: types.h:88
vl_api_fib_path_type_t type
Definition: fib_types.api:123
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
Definition: dpo.h:170
enum ip_protocol ip_protocol_t
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:546
index_t ct_cci
The client object this translation belongs on INDEX_INVALID if vip is unresolved. ...
vl_api_ip_proto_t proto
Definition: acl_types.api:51
u64 key
the key
Definition: bihash_8_8.h:43
long ctx[MAX_CONNS]
Definition: main.c:144
struct cnat_ep_trk_t_ cnat_ep_trk_t
Data used to track an EP in the FIB.
unsigned short u16
Definition: types.h:57
dpo_id_t ct_dpo
The forwarding contributed by the entry.
cnat_addr_resol_type_t type
The cnat_addr_resolution_t.
An node in the FIB graph.
Definition: fib_node.h:295
cnat_ep_trk_t * ct_paths
The vector of tracked back-ends.
fib_node_t ct_node
Linkage into the FIB graph.
u64 value
the value
Definition: bihash_8_8.h:44
Entry used to account for a translation&#39;s backend waiting for address resolution. ...
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:29
cnat_endpoint_t ct_ep[VLIB_N_DIR]
The EP being tracked.
8 octet key, 8 octet key value pair
Definition: bihash_8_8.h:41
ip_address_family_t af
ip4 or ip6 resolution
dpo_id_t ct_lb
The LB used to forward to the backends.
clib_bihash_8_8_t cnat_translation_db
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.
u8 is_active
Allows to disable if not resolved yet.
#define VLIB_N_DIR
Definition: defs.h:57
index_t cti
Translation index.
void cnat_translation_walk(cnat_translation_walk_cb_t cb, void *ctx)
Walk/visit each of the translations.
enum ip_address_family_t_ ip_address_family_t
typedef key
Definition: ipsec_types.api:86
void cnat_translation_unwatch_addr(u32 cti, cnat_addr_resol_type_t type)
Cleanup matching addr resolution requests.
struct addr_resolution_t_ addr_resolution_t
Entry used to account for a translation&#39;s backend waiting for address resolution. ...
u32 index
Definition: flow_types.api:221
fib_node_index_t ct_fei
The FIB entry for the EP.
A collection of combined counters.
Definition: counter.h:207
u16 port
Definition: lb_types.api:73
Data used to track an EP in the FIB.
u8 * format_cnat_translation(u8 *s, va_list *args)
struct cnat_translation_t_ cnat_translation_t
A Translation represents the translation of a VEP to one of a set of real server addresses.
index_t index
Own index (if copied for trace)
u8 flags
Translation flags.
u32 ct_sibling
The sibling on the entry&#39;s child list.