FD.io VPP  v20.09-64-g4f7b92f0a
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  */
53 
55 {
58 
59 /**
60  * A Translation represents the translation of a VEP to one of a set
61  * of real server addresses
62  */
63 typedef struct cnat_translation_t_
64 {
65  /**
66  * Linkage into the FIB graph
67  */
69 
70  /**
71  * The LB used to forward to the backends
72  */
74 
75  /**
76  * The Virtual end point
77  */
79 
80  /**
81  * The vector of tracked back-ends
82  */
84 
85  /**
86  * The ip protocol for the translation
87  */
89 
90  /**
91  * The client object this translation belongs on
92  */
94 
95  /**
96  * Own index (if copied for trace)
97  */
99 
100  /**
101  * Translation flags
102  */
105 
107 
108 extern u8 *format_cnat_translation (u8 * s, va_list * args);
109 
110 /**
111  * create or update a translation
112  *
113  * @param vip The Virtual Endpoint
114  * @param ip_proto The ip protocol to translate
115  * @param backends the backends to choose from
116  *
117  * @return the ID of the translation. used to delete and gather stats
118  */
119 extern u32 cnat_translation_update (const cnat_endpoint_t * vip,
121  const cnat_endpoint_tuple_t *
122  backends, u8 flags);
123 
124 /**
125  * Add a translation to the bihash
126  *
127  * @param cci the ID of the parent client
128  * @param port the translation port
129  * @param proto the translation proto
130  * @param cti the translation index to be used as value
131  */
132 extern void cnat_add_translation_to_db (index_t cci, u16 port,
134 
135 /**
136  * Remove a translation from the bihash
137  *
138  * @param cci the ID of the parent client
139  * @param port the translation port
140  * @param proto the translation proto
141  */
144 
145 /**
146  * Delete a translation
147  *
148  * @param id the ID as returned from the create
149  */
150 extern int cnat_translation_delete (u32 id);
151 
152 /**
153  * Callback function invoked during a walk of all translations
154  */
156 
157 /**
158  * Walk/visit each of the translations
159  */
161 
162 /**
163  * Purge all the trahslations
164  */
165 extern int cnat_translation_purge (void);
166 
167 /*
168  * Data plane functions
169  */
170 extern clib_bihash_8_8_t cnat_translation_db;
171 
174 {
175  return (pool_elt_at_index (cnat_translation_pool, cti));
176 }
177 
180 {
181  clib_bihash_kv_8_8_t bkey, bvalue;
182  u64 key;
183  int rv;
184 
185  key = (proto << 16) | port;
186  key = key << 32 | (u32) cti;
187 
188  bkey.key = key;
189  rv = clib_bihash_search_inline_2_8_8 (&cnat_translation_db, &bkey, &bvalue);
190  if (!rv)
191  return (pool_elt_at_index (cnat_translation_pool, bvalue.value));
192 
193  return (NULL);
194 }
195 
196 /*
197  * fd.io coding-style-patch-verification: ON
198  *
199  * Local Variables:
200  * eval: (c-set-style "gnu")
201  * End:
202  */
203 
204 #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:103
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:64
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
enum walk_rc_t_ walk_rc_t
Walk return code.
#define static_always_inline
Definition: clib.h:108
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
unsigned int u32
Definition: types.h:88
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:534
index_t ct_cci
The client object this translation belongs on.
vl_api_ip_proto_t proto
Definition: acl_types.api:50
u64 key
the key
Definition: bihash_8_8.h:41
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.
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:42
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:30
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:39
dpo_id_t ct_lb
The LB used to forward to the backends.
clib_bihash_8_8_t cnat_translation_db
#define VLIB_N_DIR
Definition: defs.h:57
u32 cnat_translation_update(const cnat_endpoint_t *vip, ip_protocol_t ip_proto, const cnat_endpoint_tuple_t *backends, u8 flags)
create or update a translation
void cnat_translation_walk(cnat_translation_walk_cb_t cb, void *ctx)
Walk/visit each of the translations.
typedef key
Definition: ipsec_types.api:85
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:188
u16 port
Definition: lb_types.api:72
void cnat_remove_translation_from_db(index_t cci, u16 port, ip_protocol_t proto)
Remove a translation from the bihash.
Data used to track an EP in the FIB.
void cnat_add_translation_to_db(index_t cci, u16 port, ip_protocol_t proto, index_t cti)
Add a translation to the bihash.
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.