FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
gbp_endpoint.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 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 __GBP_ENDPOINT_H__
17 #define __GBP_ENDPOINT_H__
18 
19 #include <plugins/gbp/gbp_types.h>
20 #include <plugins/gbp/gbp_itf.h>
21 #include <vnet/ip/ip.h>
23 
24 #include <vppinfra/bihash_16_8.h>
26 #include <vppinfra/bihash_24_8.h>
28 
29 /**
30  * Flags for each endpoint
31  */
33 {
41 
43 {
50 
51 #define GBP_ENDPOINT_ATTR_NAMES { \
52  [GBP_ENDPOINT_ATTR_BOUNCE] = "bounce", \
53  [GBP_ENDPOINT_ATTR_REMOTE] = "remote", \
54  [GBP_ENDPOINT_ATTR_LEARNT] = "learnt", \
55  [GBP_ENDPOINT_ATTR_EXTERNAL] = "external", \
56 }
57 
58 extern u8 *format_gbp_endpoint_flags (u8 * s, va_list * args);
59 
60 /**
61  * Sources of Endpoints in priority order. The best (lowest value) source
62  * provides the forwarding information.
63  * Data-plane takes preference because the CP data is not always complete,
64  * it may not have the sclass.
65  */
66 #define foreach_gbp_endpoint_src \
67  _(DP, "data-plane") \
68  _(CP, "control-plane") \
69  _(RR, "recursive-resolution")
70 
71 typedef enum gbp_endpoint_src_t_
72 {
73 #define _(v,s) GBP_ENDPOINT_SRC_##v,
75 #undef _
77 
78 #define GBP_ENDPOINT_SRC_MAX (GBP_ENDPOINT_SRC_RR+1)
79 
80 extern u8 *format_gbp_endpoint_src (u8 * s, va_list * args);
81 
82 /**
83  * This is the identity of an endpoint, as such it is information
84  * about an endpoint that is idempotent.
85  * The ID is used to add the EP into the various data-bases for retrieval.
86  */
87 typedef struct gbp_endpoint_key_t_
88 {
89  /**
90  * A vector of ip addresses that belong to the endpoint.
91  * Together with the route EPG's RD this forms the EP's L3 key
92  */
94 
95  /**
96  * MAC address of the endpoint.
97  * Together with the route EPG's BD this forms the EP's L2 key
98  */
100 
101  /**
102  * Index of the Bridge-Domain
103  */
105 
106  /**
107  * Index of the Route-Domain
108  */
111 
112 /**
113  * Information about the location of the endpoint provided by a source
114  * of endpoints
115  */
116 typedef struct gbp_endpoint_loc_t_
117 {
118  /**
119  * The source providing this location information
120  */
122 
123  /**
124  * The interface on which the EP is connected
125  */
127 
128  /**
129  * Endpoint flags
130  */
132 
133  /**
134  * Endpoint Group.
135  */
137 
138  /**
139  * number of times this source has locked this
140  */
142 
143  /**
144  * Tunnel info for remote endpoints
145  */
146  struct
147  {
149  ip46_address_t gel_src;
150  ip46_address_t gel_dst;
151  } tun;
153 
154 /**
155  * And endpoints current forwarding state
156  */
157 typedef struct gbp_endpoint_fwd_t_
158 {
159  /**
160  * The interface on which the EP is connected
161  */
163 
164  /**
165  * The L3 adj, if created
166  */
168 
169  /**
170  * Endpoint Group's sclass. cached for fast DP access.
171  */
173 
174  /**
175  * FIB index the EP is in
176  */
178 
181 
182 /**
183  * A Group Based Policy Endpoint.
184  * This is typically a VM or container. If the endpoint is local (i.e. on
185  * the same compute node as VPP) then there is one interface per-endpoint.
186  * If the EP is remote,e.g. reachable over a [vxlan] tunnel, then there
187  * will be multiple EPs reachable over the tunnel and they can be distinguished
188  * via either their MAC or IP Address[es].
189  */
190 typedef struct gbp_endpoint_t_
191 {
192  /**
193  * A FIB node that allows the tracking of children.
194  */
196 
197  /**
198  * The key/ID of this EP
199  */
201 
202  /**
203  * Location information provided by the various sources.
204  * These are sorted based on source priority.
205  */
207 
209 
210  /**
211  * The last time a packet from seen from this end point
212  */
215 
216 extern u8 *format_gbp_endpoint (u8 * s, va_list * args);
217 
218 /**
219  * GBP Endpoint Databases
220  */
222 {
224  clib_bihash_24_8_t ged_by_ip_rd;
225  clib_bihash_16_8_t ged_by_mac_bd;
226 } gbp_ep_db_t;
227 
230  const ip46_address_t * ip,
231  const mac_address_t * mac,
232  index_t gbd, index_t grd,
235  const ip46_address_t * tun_src,
236  const ip46_address_t * tun_dst,
237  u32 * handle);
242 extern void gbp_endpoint_child_remove (index_t gei, u32 sibling);
243 
244 typedef walk_rc_t (*gbp_endpoint_cb_t) (index_t gbpei, void *ctx);
245 extern void gbp_endpoint_walk (gbp_endpoint_cb_t cb, void *ctx);
246 extern void gbp_endpoint_scan (vlib_main_t * vm);
247 extern int gbp_endpoint_is_remote (const gbp_endpoint_t * ge);
248 extern int gbp_endpoint_is_local (const gbp_endpoint_t * ge);
249 extern int gbp_endpoint_is_external (const gbp_endpoint_t * ge);
250 extern int gbp_endpoint_is_learnt (const gbp_endpoint_t * ge);
251 
252 
254 
255 /**
256  * DP functions and databases
257  */
258 extern gbp_ep_db_t gbp_ep_db;
260 
261 /**
262  * Get the endpoint from a port/interface
263  */
266 {
267  return (pool_elt_at_index (gbp_endpoint_pool, gbpei));
268 }
269 
272  u32 bd_index, clib_bihash_kv_16_8_t * key)
273 {
274  key->key[0] = ethernet_mac_address_u64 (mac);
275  key->key[1] = bd_index;
276 }
277 
279 gbp_endpoint_find_mac (const u8 * mac, u32 bd_index)
280 {
282  int rv;
283 
284  gbp_endpoint_mk_key_mac (mac, bd_index, &key);
285 
286  rv = clib_bihash_search_16_8 (&gbp_ep_db.ged_by_mac_bd, &key, &value);
287 
288  if (0 != rv)
289  return NULL;
290 
291  return (gbp_endpoint_get (value.value));
292 }
293 
295 gbp_endpoint_mk_key_ip (const ip46_address_t * ip,
296  u32 fib_index, clib_bihash_kv_24_8_t * key)
297 {
298  key->key[0] = ip->as_u64[0];
299  key->key[1] = ip->as_u64[1];
300  key->key[2] = fib_index;
301 }
302 
305  u32 fib_index, clib_bihash_kv_24_8_t * key)
306 {
307  const ip46_address_t a = {
308  .ip4 = *ip,
309  };
310  gbp_endpoint_mk_key_ip (&a, fib_index, key);
311 }
312 
315 {
317  int rv;
318 
319  gbp_endpoint_mk_key_ip4 (ip, fib_index, &key);
320 
321  rv = clib_bihash_search_24_8 (&gbp_ep_db.ged_by_ip_rd, &key, &value);
322 
323  if (0 != rv)
324  return NULL;
325 
326  return (gbp_endpoint_get (value.value));
327 }
328 
330 gbp_endpoint_mk_key_ip6 (const ip6_address_t * ip,
331  u32 fib_index, clib_bihash_kv_24_8_t * key)
332 {
333  key->key[0] = ip->as_u64[0];
334  key->key[1] = ip->as_u64[1];
335  key->key[2] = fib_index;
336 }
337 
339 gbp_endpoint_find_ip6 (const ip6_address_t * ip, u32 fib_index)
340 {
342  int rv;
343 
344  gbp_endpoint_mk_key_ip6 (ip, fib_index, &key);
345 
346  rv = clib_bihash_search_24_8 (&gbp_ep_db.ged_by_ip_rd, &key, &value);
347 
348  if (0 != rv)
349  return NULL;
350 
351  return (gbp_endpoint_get (value.value));
352 }
353 
356 {
357  index_t gei;
358 
360 
361  if (INDEX_INVALID != gei)
362  return (gbp_endpoint_get (gei));
363 
364  return (NULL);
365 }
366 
367 
368 #endif
369 
370 /*
371  * fd.io coding-style-patch-verification: ON
372  *
373  * Local Variables:
374  * eval: (c-set-style "gnu")
375  * End:
376  */
gbp_endpoint_loc_t_::gel_src
ip46_address_t gel_src
Definition: gbp_endpoint.h:149
foreach_gbp_endpoint_src
#define foreach_gbp_endpoint_src
Sources of Endpoints in priority order.
Definition: gbp_endpoint.h:66
bihash_24_8.h
gbp_endpoint_flags_t_
gbp_endpoint_flags_t_
Definition: gbp_endpoint.h:42
GBP_ENDPOINT_FLAG_LEARNT
@ GBP_ENDPOINT_FLAG_LEARNT
Definition: gbp_endpoint.h:47
mac
vl_api_mac_address_t mac
Definition: l2.api:559
gbp_endpoint_src_t
enum gbp_endpoint_src_t_ gbp_endpoint_src_t
gbp_endpoint_t_::ge_fwd
gbp_endpoint_fwd_t ge_fwd
Definition: gbp_endpoint.h:208
gbp_endpoint_is_remote
int gbp_endpoint_is_remote(const gbp_endpoint_t *ge)
Definition: gbp_endpoint.c:89
GBP_ENDPOINT_FLAG_REMOTE
@ GBP_ENDPOINT_FLAG_REMOTE
Definition: gbp_endpoint.h:46
gbp_endpoint_fwd_t_::gef_sclass
sclass_t gef_sclass
Endpoint Group's sclass.
Definition: gbp_endpoint.h:172
gbp_types.h
gbp_endpoint_fwd_t
struct gbp_endpoint_fwd_t_ gbp_endpoint_fwd_t
And endpoints current forwarding state.
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:553
gbp_ep_by_ip_itf_db_t_::ged_by_ip_rd
clib_bihash_24_8_t ged_by_ip_rd
Definition: gbp_endpoint.h:224
bihash_template.h
gbp_itf_hdl_t_
Definition: gbp_itf.h:45
gbp_endpoint_loc_t_::gel_itf
gbp_itf_hdl_t gel_itf
The interface on which the EP is connected.
Definition: gbp_endpoint.h:126
clib_bihash_kv_24_8_t
Definition: bihash_24_8.h:40
gbp_endpoint_t
struct gbp_endpoint_t_ gbp_endpoint_t
A Group Based Policy Endpoint.
gbp_ep_by_ip_itf_db_t_::ged_by_sw_if_index
index_t * ged_by_sw_if_index
Definition: gbp_endpoint.h:223
gbp_endpoint_get
static gbp_endpoint_t * gbp_endpoint_get(index_t gbpei)
Get the endpoint from a port/interface.
Definition: gbp_endpoint.h:265
gbp_endpoint_key_t
struct gbp_endpoint_key_t_ gbp_endpoint_key_t
This is the identity of an endpoint, as such it is information about an endpoint that is idempotent.
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
format_gbp_endpoint_flags
u8 * format_gbp_endpoint_flags(u8 *s, va_list *args)
Definition: gbp_endpoint.c:72
gbp_endpoint_fwd_t_::gef_flags
gbp_endpoint_flags_t gef_flags
Definition: gbp_endpoint.h:179
gbp_endpoint_fwd_t_
And endpoints current forwarding state.
Definition: gbp_endpoint.h:157
GBP_ENDPOINT_FLAG_NONE
@ GBP_ENDPOINT_FLAG_NONE
Definition: gbp_endpoint.h:44
fib_node_type_t
enum fib_node_type_t_ fib_node_type_t
The types of nodes in a FIB graph.
gbp_ep_by_ip_itf_db_t_::ged_by_mac_bd
clib_bihash_16_8_t ged_by_mac_bd
Definition: gbp_endpoint.h:225
gbp_ep_by_ip_itf_db_t_
GBP Endpoint Databases.
Definition: gbp_endpoint.h:221
gbp_endpoint_scan
void gbp_endpoint_scan(vlib_main_t *vm)
Definition: gbp_endpoint.c:1492
gbp_endpoint_loc_t_::gel_src
gbp_endpoint_src_t gel_src
The source providing this location information.
Definition: gbp_endpoint.h:121
GBP_ENDPOINT_ATTR_REMOTE
@ GBP_ENDPOINT_ATTR_REMOTE
Definition: gbp_endpoint.h:36
gbp_endpoint_attr_t
enum gbp_endpoint_attr_t_ gbp_endpoint_attr_t
Flags for each endpoint.
gbp_endpoint_t_::ge_locs
gbp_endpoint_loc_t * ge_locs
Location information provided by the various sources.
Definition: gbp_endpoint.h:206
gbp_endpoint_flags_t
enum gbp_endpoint_flags_t_ gbp_endpoint_flags_t
key
typedef key
Definition: ipsec_types.api:88
gbp_endpoint_find_ip4
static_always_inline gbp_endpoint_t * gbp_endpoint_find_ip4(const ip4_address_t *ip, u32 fib_index)
Definition: gbp_endpoint.h:314
GBP_ENDPOINT_ATTR_BOUNCE
@ GBP_ENDPOINT_ATTR_BOUNCE
Definition: gbp_endpoint.h:35
format_gbp_endpoint_src
u8 * format_gbp_endpoint_src(u8 *s, va_list *args)
Definition: gbp_endpoint.c:1162
ethernet_mac_address_u64
static u64 ethernet_mac_address_u64(const u8 *a)
Definition: mac_address.h:40
gbp_endpoint_attr_t_
gbp_endpoint_attr_t_
Flags for each endpoint.
Definition: gbp_endpoint.h:32
gbp_endpoint_key_t_::gek_ips
fib_prefix_t * gek_ips
A vector of ip addresses that belong to the endpoint.
Definition: gbp_endpoint.h:93
gbp_endpoint_find_mac
static_always_inline gbp_endpoint_t * gbp_endpoint_find_mac(const u8 *mac, u32 bd_index)
Definition: gbp_endpoint.h:279
gbp_endpoint_loc_t_::gel_flags
gbp_endpoint_flags_t gel_flags
Endpoint flags.
Definition: gbp_endpoint.h:131
gbp_endpoint_loc_t_::gel_dst
ip46_address_t gel_dst
Definition: gbp_endpoint.h:150
mac_address.h
gbp_endpoint_loc_t_
Information about the location of the endpoint provided by a source of endpoints.
Definition: gbp_endpoint.h:116
gbp_endpoint_unlock
void gbp_endpoint_unlock(gbp_endpoint_src_t src, index_t gbpei)
Definition: gbp_endpoint.c:916
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
gbp_endpoint_t_::ge_key
gbp_endpoint_key_t ge_key
The key/ID of this EP.
Definition: gbp_endpoint.h:200
fib_node_index_t
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:29
GBP_ENDPOINT_FLAG_BOUNCE
@ GBP_ENDPOINT_FLAG_BOUNCE
Definition: gbp_endpoint.h:45
gbp_endpoint_pool
gbp_endpoint_t * gbp_endpoint_pool
Pool of GBP endpoints.
Definition: gbp_endpoint.c:59
gbp_endpoint_is_learnt
int gbp_endpoint_is_learnt(const gbp_endpoint_t *ge)
Definition: gbp_endpoint.c:107
format_gbp_endpoint
u8 * format_gbp_endpoint(u8 *s, va_list *args)
Definition: gbp_endpoint.c:1237
gbp_endpoint_child_add
u32 gbp_endpoint_child_add(index_t gei, fib_node_type_t type, fib_node_index_t index)
Definition: gbp_endpoint.c:997
f64
double f64
Definition: types.h:142
gbp_itf.h
gbp_endpoint_mk_key_ip6
static_always_inline void gbp_endpoint_mk_key_ip6(const ip6_address_t *ip, u32 fib_index, clib_bihash_kv_24_8_t *key)
Definition: gbp_endpoint.h:330
GBP_ENDPOINT_FLAG_EXTERNAL
@ GBP_ENDPOINT_FLAG_EXTERNAL
Definition: gbp_endpoint.h:48
GBP_ENDPOINT_ATTR_EXTERNAL
@ GBP_ENDPOINT_ATTR_EXTERNAL
Definition: gbp_endpoint.h:38
gbp_endpoint_fwd_t_::gef_itf
gbp_itf_hdl_t gef_itf
The interface on which the EP is connected.
Definition: gbp_endpoint.h:162
src
vl_api_address_t src
Definition: gre.api:54
ge
u8 ge
Definition: ip_types.api:160
gbp_endpoint_loc_t_::gel_locks
u32 gel_locks
number of times this source has locked this
Definition: gbp_endpoint.h:141
sclass
u16 sclass
Definition: gbp.api:131
ip4_address_t
Definition: ip4_packet.h:50
gbp_endpoint_flush
void gbp_endpoint_flush(gbp_endpoint_src_t src, u32 sw_if_index)
remove all learnt endpoints using the interface
Definition: gbp_endpoint.c:1038
gbp_endpoint_loc_t_::gel_epg
index_t gel_epg
Endpoint Group.
Definition: gbp_endpoint.h:136
gbp_endpoint_loc_t
struct gbp_endpoint_loc_t_ gbp_endpoint_loc_t
Information about the location of the endpoint provided by a source of endpoints.
gbp_endpoint_key_t_
This is the identity of an endpoint, as such it is information about an endpoint that is idempotent.
Definition: gbp_endpoint.h:87
gbp_endpoint_src_t_
gbp_endpoint_src_t_
Definition: gbp_endpoint.h:71
gbp_endpoint_loc_t_::gel_parent_sw_if_index
u32 gel_parent_sw_if_index
Definition: gbp_endpoint.h:148
GBP_ENDPOINT_ATTR_LAST
@ GBP_ENDPOINT_ATTR_LAST
Definition: gbp_endpoint.h:39
index
u32 index
Definition: flow_types.api:221
always_inline
#define always_inline
Definition: rdma_mlx5dv.h:23
gbp_endpoint_key_t_::gek_mac
mac_address_t gek_mac
MAC address of the endpoint.
Definition: gbp_endpoint.h:99
sclass_t
u16 sclass_t
Definition: gbp_types.h:25
gbp_endpoint_key_t_::gek_gbd
index_t gek_gbd
Index of the Bridge-Domain.
Definition: gbp_endpoint.h:104
clib_bihash_kv_16_8_t
Definition: bihash_16_8.h:40
gbp_ep_db
gbp_ep_db_t gbp_ep_db
DP functions and databases.
Definition: gbp_endpoint.c:43
gbp_endpoint_t_::ge_last_time
f64 ge_last_time
The last time a packet from seen from this end point.
Definition: gbp_endpoint.h:213
gbp_endpoint_find_ip6
static_always_inline gbp_endpoint_t * gbp_endpoint_find_ip6(const ip6_address_t *ip, u32 fib_index)
Definition: gbp_endpoint.h:339
ip.h
u32
unsigned int u32
Definition: types.h:88
gbp_endpoint_mk_key_mac
static_always_inline void gbp_endpoint_mk_key_mac(const u8 *mac, u32 bd_index, clib_bihash_kv_16_8_t *key)
Definition: gbp_endpoint.h:271
ctx
long ctx[MAX_CONNS]
Definition: main.c:144
value
u8 value
Definition: qos.api:54
bihash_16_8.h
gbp_endpoint_loc_t_::tun
struct gbp_endpoint_loc_t_::@659 tun
Tunnel info for remote endpoints.
mac_address_t_
Definition: mac_address.h:21
fib_node_t_
An node in the FIB graph.
Definition: fib_node.h:301
gbp_endpoint_fwd_t_::gef_fib_index
u32 gef_fib_index
FIB index the EP is in.
Definition: gbp_endpoint.h:177
gbp_ep_db_t
struct gbp_ep_by_ip_itf_db_t_ gbp_ep_db_t
GBP Endpoint Databases.
vlib_main_t
Definition: main.h:102
gbp_endpoint_fwd_t_::gef_adjs
index_t * gef_adjs
The L3 adj, if created.
Definition: gbp_endpoint.h:167
u8
unsigned char u8
Definition: types.h:56
a
a
Definition: bitmap.h:544
ip
vl_api_address_t ip
Definition: l2.api:558
gbp_endpoint_t_::ge_node
fib_node_t ge_node
A FIB node that allows the tracking of children.
Definition: gbp_endpoint.h:195
gbp_endpoint_mk_key_ip
static_always_inline void gbp_endpoint_mk_key_ip(const ip46_address_t *ip, u32 fib_index, clib_bihash_kv_24_8_t *key)
Definition: gbp_endpoint.h:295
gbp_endpoint_cb_t
walk_rc_t(* gbp_endpoint_cb_t)(index_t gbpei, void *ctx)
Definition: gbp_endpoint.h:244
gbp_endpoint_is_external
int gbp_endpoint_is_external(const gbp_endpoint_t *ge)
Definition: gbp_endpoint.c:101
gbp_endpoint_is_local
int gbp_endpoint_is_local(const gbp_endpoint_t *ge)
Definition: gbp_endpoint.c:95
rv
int __clib_unused rv
Definition: application.c:491
GBP_ENDPOINT_ATTR_LEARNT
@ GBP_ENDPOINT_ATTR_LEARNT
Definition: gbp_endpoint.h:37
gbp_endpoint_t_
A Group Based Policy Endpoint.
Definition: gbp_endpoint.h:190
gbp_endpoint_mk_key_ip4
static_always_inline void gbp_endpoint_mk_key_ip4(const ip4_address_t *ip, u32 fib_index, clib_bihash_kv_24_8_t *key)
Definition: gbp_endpoint.h:304
INDEX_INVALID
#define INDEX_INVALID
Invalid index - used when no index is known blazoned capitals INVALID speak volumes where ~0 does not...
Definition: dpo.h:49
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
gbp_endpoint_find_itf
static_always_inline gbp_endpoint_t * gbp_endpoint_find_itf(u32 sw_if_index)
Definition: gbp_endpoint.h:355
walk_rc_t
enum walk_rc_t_ walk_rc_t
Walk return code.
fib_prefix_t_
Aggregate type for a prefix.
Definition: fib_types.h:202
gbp_endpoint_walk
void gbp_endpoint_walk(gbp_endpoint_cb_t cb, void *ctx)
Definition: gbp_endpoint.c:1061
type
vl_api_fib_path_type_t type
Definition: fib_types.api:123
gbp_endpoint_update_and_lock
int gbp_endpoint_update_and_lock(gbp_endpoint_src_t src, u32 sw_if_index, const ip46_address_t *ip, const mac_address_t *mac, index_t gbd, index_t grd, sclass_t sclass, gbp_endpoint_flags_t flags, const ip46_address_t *tun_src, const ip46_address_t *tun_dst, u32 *handle)
Definition: gbp_endpoint.c:820
gbp_endpoint_child_remove
void gbp_endpoint_child_remove(index_t gei, u32 sibling)
Definition: gbp_endpoint.c:1004
gbp_endpoint_key_t_::gek_grd
index_t gek_grd
Index of the Route-Domain.
Definition: gbp_endpoint.h:109
flags
vl_api_wireguard_peer_flags_t flags
Definition: wireguard.api:105
GBP_ENDPOINT_ATTR_FIRST
@ GBP_ENDPOINT_ATTR_FIRST
Definition: gbp_endpoint.h:34