FD.io VPP  v19.04.2-12-g66b1689
Vector Packet Processing
gbp_endpoint.c
Go to the documentation of this file.
1 /*
2  * gbp.h : Group Based Policy
3  *
4  * Copyright (c) 2018 Cisco and/or its affiliates.
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
20 #include <plugins/gbp/gbp_itf.h>
25 #include <plugins/gbp/gbp_vxlan.h>
26 
27 #include <vnet/ethernet/arp.h>
28 #include <vnet/l2/l2_input.h>
29 #include <vnet/l2/l2_output.h>
30 #include <vnet/l2/feat_bitmap.h>
31 #include <vnet/l2/l2_fib.h>
32 #include <vnet/fib/fib_table.h>
33 #include <vnet/ip/ip_neighbor.h>
34 #include <vnet/fib/fib_walk.h>
36 
38 
39 /**
40  * EP DBs
41  */
43 
45 
47 
48 #define GBP_ENDPOINT_DBG(...) \
49  vlib_log_debug (gbp_ep_logger, __VA_ARGS__);
50 
51 #define GBP_ENDPOINT_INFO(...) \
52  vlib_log_notice (gbp_ep_logger, __VA_ARGS__);
53 
54 /**
55  * Pool of GBP endpoints
56  */
58 
59 /**
60  * A count of the number of dynamic entries
61  */
63 
64 #define FOR_EACH_GBP_ENDPOINT_ATTR(_item) \
65  for (_item = GBP_ENDPOINT_ATTR_FIRST; \
66  _item < GBP_ENDPOINT_ATTR_LAST; \
67  _item++)
68 
69 u8 *
70 format_gbp_endpoint_flags (u8 * s, va_list * args)
71 {
74 
76  {
77  if ((1 << attr) & flags)
78  {
79  s = format (s, "%s,", gbp_endpoint_attr_names[attr]);
80  }
81  }
82 
83  return (s);
84 }
85 
86 int
88 {
89  return (! !(ge->ge_fwd.gef_flags & GBP_ENDPOINT_FLAG_REMOTE));
90 }
91 
92 int
94 {
95  return (!(ge->ge_fwd.gef_flags & GBP_ENDPOINT_FLAG_REMOTE));
96 }
97 
98 int
100 {
101  return (! !(ge->ge_fwd.gef_flags & GBP_ENDPOINT_FLAG_EXTERNAL));
102 }
103 
104 static void
107 {
108  mac_address_from_u64 (mac, key->key[0]);
109  *sw_if_index = key->key[1];
110 }
111 
112 static void
114  ip46_address_t * ip, u32 * sw_if_index)
115 {
116  ip->as_u64[0] = key->key[0];
117  ip->as_u64[1] = key->key[1];
118  *sw_if_index = key->key[2];
119 }
120 
122 gbp_endpoint_find_ip (const ip46_address_t * ip, u32 fib_index)
123 {
124  clib_bihash_kv_24_8_t key, value;
125  int rv;
126 
127  gbp_endpoint_mk_key_ip (ip, fib_index, &key);
128 
129  rv = clib_bihash_search_24_8 (&gbp_ep_db.ged_by_ip_rd, &key, &value);
130 
131  if (0 != rv)
132  return NULL;
133 
134  return (gbp_endpoint_get (value.value));
135 }
136 
137 static void
139 {
140  vec_validate_init_empty (gbp_ep_db.ged_by_sw_if_index, sw_if_index, ~0);
141 
142  gbp_ep_db.ged_by_sw_if_index[sw_if_index] = gei;
143 }
144 
145 static bool
147 {
149  int rv;
150 
151  gbp_endpoint_mk_key_mac (mac->bytes, bd_index, &key);
152  key.value = gei;
153 
154  rv = clib_bihash_add_del_16_8 (&gbp_ep_db.ged_by_mac_bd, &key, 1);
155 
156 
157  return (0 == rv);
158 }
159 
160 static bool
161 gbp_endpoint_add_ip (const ip46_address_t * ip, u32 fib_index, index_t gei)
162 {
164  int rv;
165 
166  gbp_endpoint_mk_key_ip (ip, fib_index, &key);
167  key.value = gei;
168 
169  rv = clib_bihash_add_del_24_8 (&gbp_ep_db.ged_by_ip_rd, &key, 1);
170 
171  return (0 == rv);
172 }
173 
174 static void
176 {
178 
179  gbp_endpoint_mk_key_mac (mac->bytes, bd_index, &key);
180 
181  clib_bihash_add_del_16_8 (&gbp_ep_db.ged_by_mac_bd, &key, 0);
182 }
183 
184 static void
185 gbp_endpoint_del_ip (const ip46_address_t * ip, u32 fib_index)
186 {
188 
189  gbp_endpoint_mk_key_ip (ip, fib_index, &key);
190 
191  clib_bihash_add_del_24_8 (&gbp_ep_db.ged_by_ip_rd, &key, 0);
192 }
193 
194 static index_t
196 {
197  return (ge - gbp_endpoint_pool);
198 }
199 
200 static ip46_type_t
201 ip46_address_get_type (const ip46_address_t * a)
202 {
204 }
205 
206 static int
207 gbp_endpoint_ip_is_equal (const fib_prefix_t * fp, const ip46_address_t * ip)
208 {
209  return (ip46_address_is_equal (ip, &fp->fp_addr));
210 }
211 
212 static void
214  const ip46_address_t * ips,
215  const gbp_route_domain_t * grd)
216 {
217  const ip46_address_t *ip;
218  index_t gei, grdi;
219 
220  gei = gbp_endpoint_index (ge);
221  grdi = gbp_route_domain_index (grd);
222 
223  ASSERT ((ge->ge_key.gek_grd == INDEX_INVALID) ||
224  (ge->ge_key.gek_grd == grdi));
225 
226  vec_foreach (ip, ips)
227  {
228  if (~0 == vec_search_with_function (ge->ge_key.gek_ips, ip,
230  {
231  fib_prefix_t *pfx;
232 
233  vec_add2 (ge->ge_key.gek_ips, pfx, 1);
234  fib_prefix_from_ip46_addr (ip, pfx);
235 
237  grd->grd_fib_index[pfx->fp_proto], gei);
238  }
239  ge->ge_key.gek_grd = grdi;
240  }
241 }
242 
243 static gbp_endpoint_t *
244 gbp_endpoint_alloc (const ip46_address_t * ips,
245  const gbp_route_domain_t * grd,
246  const mac_address_t * mac,
247  const gbp_bridge_domain_t * gbd)
248 {
249  gbp_endpoint_t *ge;
250  index_t gei;
251 
252  pool_get_zero (gbp_endpoint_pool, ge);
253 
255  gei = gbp_endpoint_index (ge);
256  ge->ge_key.gek_gbd =
257  ge->ge_key.gek_grd =
261 
262  if (NULL != mac)
263  {
264  mac_address_copy (&ge->ge_key.gek_mac, mac);
265  gbp_endpoint_add_mac (mac, gbd->gb_bd_index, gei);
266  }
267  gbp_endpoint_ips_update (ge, ips, grd);
268 
269  return (ge);
270 }
271 
272 static int
274 {
275  return (a->gel_src == b->gel_src);
276 }
277 
278 static int
280 {
281  return (a->gel_src - b->gel_src);
282 }
283 
284 static gbp_endpoint_loc_t *
286 {
287  gbp_endpoint_loc_t gel = {
288  .gel_src = src,
289  };
290  u32 pos;
291 
292  pos = vec_search_with_function (ge->ge_locs, &gel,
294 
295  if (~0 != pos)
296  return (&ge->ge_locs[pos]);
297 
298  return NULL;
299 }
300 
301 static int
303 {
304  u32 pos;
305 
306  gel->gel_locks--;
307 
308  if (0 == gel->gel_locks)
309  {
310  pos = gel - ge->ge_locs;
311 
312  vec_del1 (ge->ge_locs, pos);
313  if (vec_len (ge->ge_locs) > 1)
315 
316  /* This could be the last lock, so don't access the EP from
317  * this point on */
318  fib_node_unlock (&ge->ge_node);
319 
320  return (1);
321  }
322  return (0);
323 }
324 
325 static void
327 {
329 
331  {
333  }
334 }
335 
336 static gbp_endpoint_loc_t *
338 {
339  gbp_endpoint_loc_t gel = {
340  .gel_src = src,
341  .gel_epg = INDEX_INVALID,
342  .gel_sw_if_index = INDEX_INVALID,
343  .gel_locks = 0,
344  };
345  u32 pos;
346 
347  pos = vec_search_with_function (ge->ge_locs, &gel,
349 
350  if (~0 == pos)
351  {
352  vec_add1 (ge->ge_locs, gel);
353 
354  if (vec_len (ge->ge_locs) > 1)
355  {
357 
358  pos = vec_search_with_function (ge->ge_locs, &gel,
360  }
361  else
362  pos = 0;
363 
364  /*
365  * it's the sources and children that lock the endpoints
366  */
367  fib_node_lock (&ge->ge_node);
368  }
369 
370  return (&ge->ge_locs[pos]);
371 }
372 
373 /**
374  * Find an EP inthe DBs and check that if we find it in the L2 DB
375  * it has the same IPs as this update
376  */
377 static int
378 gbp_endpoint_find_for_update (const ip46_address_t * ips,
379  const gbp_route_domain_t * grd,
380  const mac_address_t * mac,
381  const gbp_bridge_domain_t * gbd,
382  gbp_endpoint_t ** ge)
383 {
384  gbp_endpoint_t *l2_ge, *l3_ge, *tmp;
385 
386  l2_ge = l3_ge = NULL;
387 
388  if (NULL != mac && !mac_address_is_zero (mac))
389  {
390  ASSERT (gbd);
391  l2_ge = gbp_endpoint_find_mac (mac->bytes, gbd->gb_bd_index);
392  }
393  if (NULL != ips && !ip46_address_is_zero (ips))
394  {
395  const ip46_address_t *ip;
396  fib_protocol_t fproto;
397 
398  ASSERT (grd);
399  vec_foreach (ip, ips)
400  {
402 
403  tmp = gbp_endpoint_find_ip (ip, grd->grd_fib_index[fproto]);
404 
405  if (NULL == tmp)
406  /* not found */
407  continue;
408  else if (NULL == l3_ge)
409  /* first match against an IP address */
410  l3_ge = tmp;
411  else if (tmp == l3_ge)
412  /* another match against IP address that is the same endpoint */
413  continue;
414  else
415  {
416  /*
417  * a match agains a different endpoint.
418  * this means the KEY of the EP is changing which is not allowed
419  */
420  return (-1);
421  }
422  }
423  }
424 
425  if (NULL == l2_ge && NULL == l3_ge)
426  /* not found */
427  *ge = NULL;
428  else if (NULL == l2_ge)
429  /* found at L3 */
430  *ge = l3_ge;
431  else if (NULL == l3_ge)
432  /* found at L2 */
433  *ge = l2_ge;
434  else
435  {
436  /* found both L3 and L2 - they must be the same else the KEY
437  * is changing
438  */
439  if (l2_ge == l3_ge)
440  *ge = l2_ge;
441  else
442  return (-1);
443  }
444 
445  return (0);
446 }
447 
448 static gbp_endpoint_src_t
450 {
451  if (0 == vec_len (ge->ge_locs))
452  return (GBP_ENDPOINT_SRC_MAX);
453 
454  return (ge->ge_locs[0].gel_src);
455 }
456 
457 static void
459 {
461 
462  if (n > 0 && 1 == gbp_n_learnt_endpoints)
463  {
465  gbp_scanner_node.index,
467  }
468  if (n < 0 && 0 == gbp_n_learnt_endpoints)
469  {
471  gbp_scanner_node.index,
473  }
474 }
475 
476 static void
478  const gbp_bridge_domain_t * gb,
480  index_t ggi,
482  const ip46_address_t * tun_src,
483  const ip46_address_t * tun_dst)
484 {
485  int was_learnt, is_learnt;
486 
487  gel->gel_locks++;
488  was_learnt = ! !(gel->gel_flags & GBP_ENDPOINT_FLAG_REMOTE);
489  gel->gel_flags = flags;
490  is_learnt = ! !(gel->gel_flags & GBP_ENDPOINT_FLAG_REMOTE);
491 
492  gbp_endpoint_n_learned (is_learnt - was_learnt);
493 
494  if (INDEX_INVALID == gel->gel_epg)
495  {
496  gel->gel_epg = ggi;
497  if (INDEX_INVALID != gel->gel_epg)
498  {
500  }
501  }
502  else
503  {
504  ASSERT (gel->gel_epg == ggi);
505  }
506 
508  {
509  if (NULL != tun_src)
510  ip46_address_copy (&gel->tun.gel_src, tun_src);
511  if (NULL != tun_dst)
512  ip46_address_copy (&gel->tun.gel_dst, tun_dst);
513 
515  {
516  /*
517  * we learnt the EP from the multicast tunnel.
518  * Create a unicast TEP from the packet's source
519  * and the fixed address of the BD's parent tunnel
520  */
521  const gbp_vxlan_tunnel_t *gt;
522 
523  gt = gbp_vxlan_tunnel_get (gb->gb_vni);
524 
525  if (NULL != gt)
526  {
527  ip46_address_copy (&gel->tun.gel_src, &gt->gt_src);
528  sw_if_index = gt->gt_sw_if_index;
529  }
530  }
531 
532  /*
533  * the input interface may be the parent GBP-vxlan interface,
534  * create a child vlxan-gbp tunnel and use that as the endpoint's
535  * interface.
536  */
537  if (~0 != gel->gel_sw_if_index)
539 
540  switch (gbp_vxlan_tunnel_get_type (sw_if_index))
541  {
544  gel->gel_sw_if_index =
545  gbp_vxlan_tunnel_clone_and_lock (sw_if_index,
546  &gel->tun.gel_src,
547  &gel->tun.gel_dst);
548  break;
549  case VXLAN_GBP_TUNNEL:
551  vxlan_gbp_tunnel_get_parent (sw_if_index);
554  break;
555  }
556  }
557  else
558  {
560  }
561 }
562 
563 static void
565 {
566  const gbp_route_domain_t *grd;
567  const gbp_bridge_domain_t *gbd;
568  gbp_endpoint_fwd_t *gef;
569  const fib_prefix_t *pfx;
570  index_t *ai;
571  index_t gei;
572 
573  gei = gbp_endpoint_index (ge);
575  gef = &ge->ge_fwd;
576 
577  vec_foreach (pfx, ge->ge_key.gek_ips)
578  {
579  u32 fib_index;
580 
581  grd = gbp_route_domain_get (ge->ge_key.gek_grd);
582  fib_index = grd->grd_fib_index[pfx->fp_proto];
583 
585  &pfx->fp_addr, &ge->ge_key.gek_mac, 0);
586 
587  /*
588  * remove a host route
589  */
590  if (gbp_endpoint_is_remote (ge))
591  {
593  }
594 
596  }
597  vec_foreach (ai, gef->gef_adjs)
598  {
599  adj_unlock (*ai);
600  }
601 
602  if (INDEX_INVALID != gef->gef_itf)
603  {
605  gbd->gb_bd_index, gef->gef_itf);
608 
609  gbp_itf_unlock (gef->gef_itf);
610  gef->gef_itf = INDEX_INVALID;
611  }
612 
613  vec_free (gef->gef_adjs);
614 }
615 
616 static void
618 {
619  const gbp_route_domain_t *grd;
620  const gbp_bridge_domain_t *gbd;
621  const gbp_endpoint_group_t *gg;
622  gbp_endpoint_loc_t *gel;
623  gbp_endpoint_fwd_t *gef;
624  const fib_prefix_t *pfx;
625  index_t gei;
626 
627  /*
628  * locations are sort in source priority order
629  */
630  gei = gbp_endpoint_index (ge);
631  gel = &ge->ge_locs[0];
632  gef = &ge->ge_fwd;
634 
635  gef->gef_flags = gel->gel_flags;
636 
637  if (INDEX_INVALID != gel->gel_epg)
638  {
639  gg = gbp_endpoint_group_get (gel->gel_epg);
640  gef->gef_sclass = gg->gg_sclass;
641  }
642  else
643  {
644  gg = NULL;
645  }
646 
648  gbd->gb_bd_index);
649 
650  if (!mac_address_is_zero (&ge->ge_key.gek_mac))
651  {
652  gbp_itf_set_l2_input_feature (gef->gef_itf, gei, L2INPUT_FEAT_GBP_FWD);
653 
655  {
656  /*
657  * bridged packets to external endpoints should be classifed
658  * based on the EP's/BD's EPG
659  */
661  L2OUTPUT_FEAT_GBP_POLICY_MAC);
662  }
663  else
664  {
665  gbp_endpoint_add_itf (gef->gef_itf, gei);
667  L2OUTPUT_FEAT_GBP_POLICY_PORT);
668  }
670  gbd->gb_bd_index,
671  gef->gef_itf, L2FIB_ENTRY_RESULT_FLAG_STATIC);
672  }
673 
674  vec_foreach (pfx, ge->ge_key.gek_ips)
675  {
676  ethernet_header_t *eth;
677  u32 ip_sw_if_index;
678  u32 fib_index;
679  u8 *rewrite;
680  index_t ai;
681 
682  rewrite = NULL;
683  grd = gbp_route_domain_get (ge->ge_key.gek_grd);
684  fib_index = grd->grd_fib_index[pfx->fp_proto];
685  gef->gef_fib_index = fib_index;
686 
688  &pfx->fp_addr, &ge->ge_key.gek_mac, 1);
689 
690  /*
691  * add a host route via the EPG's BVI we need this because the
692  * adj fib does not install, due to cover refinement check, since
693  * the BVI's prefix is /32
694  */
695  vec_validate (rewrite, sizeof (*eth) - 1);
696  eth = (ethernet_header_t *) rewrite;
697 
698  eth->type = clib_host_to_net_u16 ((pfx->fp_proto == FIB_PROTOCOL_IP4 ?
699  ETHERNET_TYPE_IP4 :
700  ETHERNET_TYPE_IP6));
701 
702  if (gbp_endpoint_is_remote (ge))
703  {
704  /*
705  * for dynamic EPs we must add the IP adjacency via the learned
706  * tunnel since the BD will not contain the EP's MAC since it was
707  * L3 learned. The dst MAC address used is the 'BD's MAC'.
708  */
709  ip_sw_if_index = gef->gef_itf;
710 
712  eth->src_address);
714  eth->dst_address);
715  }
716  else
717  {
718  /*
719  * for the static EPs we add the IP adjacency via the BVI
720  * knowing that the BD has the MAC address to route to and
721  * that policy will be applied on egress to the EP's port
722  */
723  ip_sw_if_index = gbd->gb_bvi_sw_if_index;
724 
725  clib_memcpy (eth->src_address,
727  ip_sw_if_index),
728  sizeof (eth->src_address));
730  }
731 
732  fib_table_entry_path_add (fib_index, pfx,
735  fib_proto_to_dpo (pfx->fp_proto),
736  &pfx->fp_addr, ip_sw_if_index,
738 
741  &pfx->fp_addr,
742  ip_sw_if_index, rewrite);
743  vec_add1 (gef->gef_adjs, ai);
744 
745  /*
746  * if the endpoint is external then routed packet to it must be
747  * classifed to the BD's EPG. but this will happen anyway with
748  * the GBP_MAC classification.
749  */
750 
751  if (NULL != gg)
752  {
753  if (gbp_endpoint_is_remote (ge))
754  {
755  dpo_id_t policy_dpo = DPO_INVALID;
756 
757  /*
758  * interpose a policy DPO from the endpoint so that policy
759  * is applied
760  */
762  gg->gg_sclass, ~0, &policy_dpo);
763 
764  fib_table_entry_special_dpo_add (fib_index, pfx,
767  &policy_dpo);
768  dpo_reset (&policy_dpo);
769  }
770 
771  /*
772  * send a gratuitous ARP on the EPG's uplink. this is done so
773  * that if this EP has moved from some other place in the
774  * 'fabric', upstream devices are informed
775  */
776  if (gbp_endpoint_is_local (ge) && ~0 != gg->gg_uplink_sw_if_index)
777  {
778  gbp_endpoint_add_itf (gef->gef_itf, gei);
779  if (FIB_PROTOCOL_IP4 == pfx->fp_proto)
781  &pfx->fp_addr.ip4,
783  else
785  &pfx->fp_addr.ip6,
787  }
788  }
789  }
790 
791  if (gbp_endpoint_is_external (ge))
792  {
794  L2INPUT_FEAT_GBP_LPM_CLASSIFY);
795  }
796  else if (gbp_endpoint_is_local (ge))
797  {
798  /*
799  * non-remote endpoints (i.e. those not arriving on iVXLAN
800  * tunnels) need to be classifed based on the the input interface.
801  * We enable the GBP-FWD feature only if the group has an uplink
802  * interface (on which the GBP-FWD feature would send UU traffic).
803  * External endpoints get classified based on an LPM match
804  */
805  l2input_feat_masks_t feats = L2INPUT_FEAT_GBP_SRC_CLASSIFY;
806 
807  if (NULL != gg && ~0 != gg->gg_uplink_sw_if_index)
808  feats |= L2INPUT_FEAT_GBP_FWD;
809  gbp_itf_set_l2_input_feature (gef->gef_itf, gei, feats);
810  }
811 
812  /*
813  * update children with the new forwarding info
814  */
815  fib_node_back_walk_ctx_t bw_ctx = {
817  .fnbw_flags = FIB_NODE_BW_FLAG_FORCE_SYNC,
818  };
819 
820  fib_walk_sync (gbp_endpoint_fib_type, gei, &bw_ctx);
821 }
822 
823 int
826  const ip46_address_t * ips,
827  const mac_address_t * mac,
828  index_t gbdi, index_t grdi,
831  const ip46_address_t * tun_src,
832  const ip46_address_t * tun_dst, u32 * handle)
833 {
834  gbp_bridge_domain_t *gbd;
836  gbp_endpoint_src_t best;
837  gbp_route_domain_t *grd;
838  gbp_endpoint_loc_t *gel;
839  gbp_endpoint_t *ge;
840  index_t ggi, gei;
841  int rv;
842 
843  if (~0 == sw_if_index)
844  return (VNET_API_ERROR_INVALID_SW_IF_INDEX);
845 
846  ge = NULL;
847  gg = NULL;
848 
849  /*
850  * we need to determine the bridge-domain, either from the EPG or
851  * the BD passed
852  */
853  if (SCLASS_INVALID != sclass)
854  {
855  ggi = gbp_endpoint_group_find (sclass);
856 
857  if (INDEX_INVALID == ggi)
858  return (VNET_API_ERROR_NO_SUCH_ENTRY);
859 
860  gg = gbp_endpoint_group_get (ggi);
861  gbdi = gg->gg_gbd;
862  grdi = gg->gg_rd;
863  }
864  else
865  {
866  if (INDEX_INVALID == gbdi)
867  return (VNET_API_ERROR_NO_SUCH_ENTRY);
868  if (INDEX_INVALID == grdi)
869  return (VNET_API_ERROR_NO_SUCH_FIB);
870  ggi = INDEX_INVALID;
871  }
872 
873  gbd = gbp_bridge_domain_get (gbdi);
874  grd = gbp_route_domain_get (grdi);
875  rv = gbp_endpoint_find_for_update (ips, grd, mac, gbd, &ge);
876 
877  if (0 != rv)
878  return (rv);
879 
880  if (NULL == ge)
881  {
882  ge = gbp_endpoint_alloc (ips, grd, mac, gbd);
883  }
884  else
885  {
886  gbp_endpoint_ips_update (ge, ips, grd);
887  }
888 
889  best = gbp_endpoint_get_best_src (ge);
890  gei = gbp_endpoint_index (ge);
891  gel = gbp_endpoint_loc_find_or_add (ge, src);
892 
893  gbp_endpoint_loc_update (gel, gbd, sw_if_index, ggi, flags, tun_src,
894  tun_dst);
895 
896  if (src <= best)
897  {
898  /*
899  * either the best source has been updated or we have a new best source
900  */
903  }
904  else
905  {
906  /*
907  * an update to a lower priority source, so we need do nothing
908  */
909  }
910 
911  if (handle)
912  *handle = gei;
913 
914  GBP_ENDPOINT_INFO ("update: %U", format_gbp_endpoint, gei);
915 
916  return (0);
917 }
918 
919 void
921 {
922  gbp_endpoint_loc_t *gel, gel_copy;
923  gbp_endpoint_src_t best;
924  gbp_endpoint_t *ge;
925  int removed;
926 
927  if (pool_is_free_index (gbp_endpoint_pool, gei))
928  return;
929 
930  GBP_ENDPOINT_INFO ("delete: %U", format_gbp_endpoint, gei);
931 
932  ge = gbp_endpoint_get (gei);
933 
934  gel = gbp_endpoint_loc_find (ge, src);
935 
936  if (NULL == gel)
937  return;
938 
939  /*
940  * lock the EP so we can control when it is deleted
941  */
942  fib_node_lock (&ge->ge_node);
943  best = gbp_endpoint_get_best_src (ge);
944 
945  /*
946  * copy the location info since we'll lose it when it's removed from
947  * the vector
948  */
949  clib_memcpy (&gel_copy, gel, sizeof (gel_copy));
950 
951  /*
952  * remove the source we no longer need
953  */
954  removed = gbp_endpoint_loc_unlock (ge, gel);
955 
956  if (src == best)
957  {
958  /*
959  * we have removed the old best source => recalculate fwding
960  */
961  if (0 == vec_len (ge->ge_locs))
962  {
963  /*
964  * if there are no more sources left, then we need only release
965  * the fwding resources held and then this EP is gawn.
966  */
968  }
969  else
970  {
971  /*
972  * else there are more sources. release the old and get new
973  * fwding objects
974  */
977  }
978  }
979  /*
980  * else
981  * we removed a lower priority source so we need to do nothing
982  */
983 
984  /*
985  * clear up any resources held by the source
986  */
987  if (removed)
988  gbp_endpoint_loc_destroy (&gel_copy);
989 
990  /*
991  * remove the lock taken above
992  */
993  fib_node_unlock (&ge->ge_node);
994  /*
995  * We may have removed the last source and so this EP is now TOAST
996  * DO NOTHING BELOW HERE
997  */
998 }
999 
1000 u32
1002  fib_node_type_t type, fib_node_index_t index)
1003 {
1004  return (fib_node_child_add (gbp_endpoint_fib_type, gei, type, index));
1005 }
1006 
1007 void
1009 {
1010  return (fib_node_child_remove (gbp_endpoint_fib_type, gei, sibling));
1011 }
1012 
1014 {
1019 
1020 static walk_rc_t
1022 {
1023  gbp_endpoint_flush_ctx_t *ctx = args;
1024  gbp_endpoint_loc_t *gel;
1025  gbp_endpoint_t *ge;
1026 
1027  ge = gbp_endpoint_get (gei);
1028  gel = gbp_endpoint_loc_find (ge, ctx->src);
1029 
1030  if ((NULL != gel) && ctx->sw_if_index == gel->tun.gel_parent_sw_if_index)
1031  {
1032  vec_add1 (ctx->geis, gei);
1033  }
1034 
1035  return (WALK_CONTINUE);
1036 }
1037 
1038 /**
1039  * remove all learnt endpoints using the interface
1040  */
1041 void
1043 {
1045  .sw_if_index = sw_if_index,
1046  .src = src,
1047  };
1048  index_t *gei;
1049 
1050  GBP_ENDPOINT_INFO ("flush: %U %U",
1053  sw_if_index);
1055 
1056  vec_foreach (gei, ctx.geis)
1057  {
1058  gbp_endpoint_unlock (src, *gei);
1059  }
1060 
1061  vec_free (ctx.geis);
1062 }
1063 
1064 void
1066 {
1067  u32 index;
1068 
1069  /* *INDENT-OFF* */
1070  pool_foreach_index(index, gbp_endpoint_pool,
1071  {
1072  if (!cb(index, ctx))
1073  break;
1074  });
1075  /* *INDENT-ON* */
1076 }
1077 
1078 static clib_error_t *
1080  unformat_input_t * input, vlib_cli_command_t * cmd)
1081 {
1082  ip46_address_t ip = ip46_address_initializer, *ips = NULL;
1084  vnet_main_t *vnm = vnet_get_main ();
1086  u32 handle = INDEX_INVALID;
1087  u32 sw_if_index = ~0;
1088  u8 add = 1;
1089  int rv;
1090 
1091  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1092  {
1093  ip46_address_reset (&ip);
1094 
1095  if (unformat (input, "%U", unformat_vnet_sw_interface,
1096  vnm, &sw_if_index))
1097  ;
1098  else if (unformat (input, "add"))
1099  add = 1;
1100  else if (unformat (input, "del"))
1101  add = 0;
1102  else if (unformat (input, "sclass %d", &sclass))
1103  ;
1104  else if (unformat (input, "handle %d", &handle))
1105  ;
1106  else if (unformat (input, "ip %U", unformat_ip4_address, &ip.ip4))
1107  vec_add1 (ips, ip);
1108  else if (unformat (input, "ip %U", unformat_ip6_address, &ip.ip6))
1109  vec_add1 (ips, ip);
1110  else if (unformat (input, "mac %U", unformat_mac_address, &mac))
1111  ;
1112  else
1113  break;
1114  }
1115 
1116  if (add)
1117  {
1118  if (~0 == sw_if_index)
1119  return clib_error_return (0, "interface must be specified");
1120  if (SCLASS_INVALID == sclass)
1121  return clib_error_return (0, "SCLASS must be specified");
1122 
1123  rv =
1124  gbp_endpoint_update_and_lock (GBP_ENDPOINT_SRC_CP,
1125  sw_if_index, ips, &mac,
1127  sclass,
1129  NULL, NULL, &handle);
1130 
1131  if (rv)
1132  return clib_error_return (0, "GBP Endpoint update returned %d", rv);
1133  else
1134  vlib_cli_output (vm, "handle %d\n", handle);
1135  }
1136  else
1137  {
1138  if (INDEX_INVALID == handle)
1139  return clib_error_return (0, "handle must be specified");
1140 
1141  gbp_endpoint_unlock (GBP_ENDPOINT_SRC_CP, handle);
1142  }
1143 
1144  vec_free (ips);
1145 
1146  return (NULL);
1147 }
1148 
1149 /*?
1150  * Configure a GBP Endpoint
1151  *
1152  * @cliexpar
1153  * @cliexstart{set gbp endpoint [del] <interface> epg <ID> ip <IP>}
1154  * @cliexend
1155  ?*/
1156 /* *INDENT-OFF* */
1157 VLIB_CLI_COMMAND (gbp_endpoint_cli_node, static) = {
1158  .path = "gbp endpoint",
1159  .short_help = "gbp endpoint [del] <interface> epg <ID> ip <IP> mac <MAC>",
1160  .function = gbp_endpoint_cli,
1161 };
1162 /* *INDENT-ON* */
1163 
1164 u8 *
1165 format_gbp_endpoint_src (u8 * s, va_list * args)
1166 {
1167  gbp_endpoint_src_t action = va_arg (*args, gbp_endpoint_src_t);
1168 
1169  switch (action)
1170  {
1171 #define _(v,a) case GBP_ENDPOINT_SRC_##v: return (format (s, "%s", a));
1173 #undef _
1174  }
1175 
1176  return (format (s, "unknown"));
1177 }
1178 
1179 static u8 *
1180 format_gbp_endpoint_fwd (u8 * s, va_list * args)
1181 {
1182  gbp_endpoint_fwd_t *gef = va_arg (*args, gbp_endpoint_fwd_t *);
1183 
1184  s = format (s, "fwd:");
1185  s = format (s, "\n itf:[%U]", format_gbp_itf, gef->gef_itf);
1186  if (GBP_ENDPOINT_FLAG_NONE != gef->gef_flags)
1187  {
1188  s = format (s, " flags:%U", format_gbp_endpoint_flags, gef->gef_flags);
1189  }
1190 
1191  return (s);
1192 }
1193 
1194 static u8 *
1195 format_gbp_endpoint_key (u8 * s, va_list * args)
1196 {
1197  gbp_endpoint_key_t *gek = va_arg (*args, gbp_endpoint_key_t *);
1198  const fib_prefix_t *pfx;
1199 
1200  s = format (s, "ips:[");
1201 
1202  vec_foreach (pfx, gek->gek_ips)
1203  {
1204  s = format (s, "%U, ", format_fib_prefix, pfx);
1205  }
1206  s = format (s, "]");
1207 
1208  s = format (s, " mac:%U", format_mac_address_t, &gek->gek_mac);
1209 
1210  return (s);
1211 }
1212 
1213 static u8 *
1214 format_gbp_endpoint_loc (u8 * s, va_list * args)
1215 {
1216  gbp_endpoint_loc_t *gel = va_arg (*args, gbp_endpoint_loc_t *);
1217 
1218  s = format (s, "%U", format_gbp_endpoint_src, gel->gel_src);
1219  s =
1221  gel->gel_sw_if_index);
1222  s = format (s, " EPG:%d", gel->gel_epg);
1223 
1224  if (GBP_ENDPOINT_FLAG_NONE != gel->gel_flags)
1225  {
1226  s = format (s, " flags:%U", format_gbp_endpoint_flags, gel->gel_flags);
1227  }
1229  {
1230  s = format (s, " tun:[");
1231  s = format (s, "parent:%U", format_vnet_sw_if_index_name,
1233  s = format (s, " {%U,%U}]",
1236  }
1237 
1238  return (s);
1239 }
1240 
1241 u8 *
1242 format_gbp_endpoint (u8 * s, va_list * args)
1243 {
1244  index_t gei = va_arg (*args, index_t);
1245  gbp_endpoint_loc_t *gel;
1246  gbp_endpoint_t *ge;
1247 
1248  ge = gbp_endpoint_get (gei);
1249 
1250  s = format (s, "[@%d] %U", gei, format_gbp_endpoint_key, &ge->ge_key);
1251  s = format (s, " last-time:[%f]", ge->ge_last_time);
1252 
1253  vec_foreach (gel, ge->ge_locs)
1254  {
1255  s = format (s, "\n %U", format_gbp_endpoint_loc, gel);
1256  }
1257  s = format (s, "\n %U", format_gbp_endpoint_fwd, &ge->ge_fwd);
1258 
1259  return s;
1260 }
1261 
1262 static walk_rc_t
1264 {
1265  vlib_main_t *vm;
1266 
1267  vm = ctx;
1268  vlib_cli_output (vm, " %U", format_gbp_endpoint, gei);
1269 
1270  return (WALK_CONTINUE);
1271 }
1272 
1273 static void
1275 {
1276  ip46_address_t ip;
1277  vlib_main_t *vm;
1278  u32 sw_if_index;
1279 
1280  vm = arg;
1281 
1282  gbp_endpoint_extract_key_ip_itf (kvp, &ip, &sw_if_index);
1283 
1284  vlib_cli_output (vm, " {%U, %U} -> %d",
1287  sw_if_index, kvp->value);
1288 }
1289 
1290 static void
1292 {
1294  vlib_main_t *vm;
1295  u32 sw_if_index;
1296 
1297  vm = arg;
1298 
1299  gbp_endpoint_extract_key_mac_itf (kvp, &mac, &sw_if_index);
1300 
1301  vlib_cli_output (vm, " {%U, %U} -> %d",
1302  format_mac_address_t, &mac,
1304  sw_if_index, kvp->value);
1305 }
1306 
1307 static clib_error_t *
1309  unformat_input_t * input, vlib_cli_command_t * cmd)
1310 {
1311  u32 show_dbs, handle;
1312 
1313  handle = INDEX_INVALID;
1314  show_dbs = 0;
1315 
1316  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1317  {
1318  if (unformat (input, "%d", &handle))
1319  ;
1320  else if (unformat (input, "db"))
1321  show_dbs = 1;
1322  else
1323  break;
1324  }
1325 
1326  if (INDEX_INVALID != handle)
1327  {
1328  vlib_cli_output (vm, "%U", format_gbp_endpoint, handle);
1329  }
1330  else if (show_dbs)
1331  {
1332  vlib_cli_output (vm, "\nDatabases:");
1333  clib_bihash_foreach_key_value_pair_24_8 (&gbp_ep_db.ged_by_ip_rd,
1335  clib_bihash_foreach_key_value_pair_16_8
1336  (&gbp_ep_db.ged_by_mac_bd, gbp_endpoint_walk_mac_itf, vm);
1337  }
1338  else
1339  {
1340  vlib_cli_output (vm, "Endpoints:");
1342  }
1343 
1344  return (NULL);
1345 }
1346 
1347 /*?
1348  * Show Group Based Policy Endpoints and derived information
1349  *
1350  * @cliexpar
1351  * @cliexstart{show gbp endpoint}
1352  * @cliexend
1353  ?*/
1354 /* *INDENT-OFF* */
1355 VLIB_CLI_COMMAND (gbp_endpoint_show_node, static) = {
1356  .path = "show gbp endpoint",
1357  .short_help = "show gbp endpoint\n",
1358  .function = gbp_endpoint_show,
1359 };
1360 /* *INDENT-ON* */
1361 
1362 static void
1363 gbp_endpoint_check (index_t gei, f64 start_time)
1364 {
1366  gbp_endpoint_loc_t *gel;
1367  gbp_endpoint_t *ge;
1368 
1369  ge = gbp_endpoint_get (gei);
1370  gel = gbp_endpoint_loc_find (ge, GBP_ENDPOINT_SRC_DP);
1371 
1372  if (NULL != gel)
1373  {
1374  gg = gbp_endpoint_group_get (gel->gel_epg);
1375 
1376  if ((start_time - ge->ge_last_time) >
1378  {
1379  gbp_endpoint_unlock (GBP_ENDPOINT_SRC_DP, gei);
1380  }
1381  }
1382 }
1383 
1384 static void
1386 {
1387  clib_bihash_16_8_t *gte_table = &gbp_ep_db.ged_by_mac_bd;
1388  f64 last_start, start_time, delta_t;
1389  int i, j, k;
1390 
1391  delta_t = 0;
1392  last_start = start_time = vlib_time_now (vm);
1393 
1394  for (i = 0; i < gte_table->nbuckets; i++)
1395  {
1396  clib_bihash_bucket_16_8_t *b;
1397  clib_bihash_value_16_8_t *v;
1398 
1399  /* allow no more than 20us without a pause */
1400  delta_t = vlib_time_now (vm) - last_start;
1401  if (delta_t > 20e-6)
1402  {
1403  /* suspend for 100 us */
1404  vlib_process_suspend (vm, 100e-6);
1405  last_start = vlib_time_now (vm);
1406  }
1407 
1408  b = &gte_table->buckets[i];
1409  if (b->offset == 0)
1410  continue;
1411  v = clib_bihash_get_value_16_8 (gte_table, b->offset);
1412 
1413  for (j = 0; j < (1 << b->log2_pages); j++)
1414  {
1415  for (k = 0; k < BIHASH_KVP_PER_PAGE; k++)
1416  {
1417  if (clib_bihash_is_free_16_8 (&v->kvp[k]))
1418  continue;
1419 
1420  gbp_endpoint_check (v->kvp[k].value, start_time);
1421 
1422  /*
1423  * Note: we may have just freed the bucket's backing
1424  * storage, so check right here...
1425  */
1426  if (b->offset == 0)
1427  goto doublebreak;
1428  }
1429  v++;
1430  }
1431  doublebreak:
1432  ;
1433  }
1434 }
1435 
1436 static void
1438 {
1439  clib_bihash_24_8_t *gte_table = &gbp_ep_db.ged_by_ip_rd;
1440  f64 last_start, start_time, delta_t;
1441  int i, j, k;
1442 
1443  delta_t = 0;
1444  last_start = start_time = vlib_time_now (vm);
1445 
1446  for (i = 0; i < gte_table->nbuckets; i++)
1447  {
1448  clib_bihash_bucket_24_8_t *b;
1449  clib_bihash_value_24_8_t *v;
1450 
1451  /* allow no more than 20us without a pause */
1452  delta_t = vlib_time_now (vm) - last_start;
1453  if (delta_t > 20e-6)
1454  {
1455  /* suspend for 100 us */
1456  vlib_process_suspend (vm, 100e-6);
1457  last_start = vlib_time_now (vm);
1458  }
1459 
1460  b = &gte_table->buckets[i];
1461  if (b->offset == 0)
1462  continue;
1463  v = clib_bihash_get_value_24_8 (gte_table, b->offset);
1464 
1465  for (j = 0; j < (1 << b->log2_pages); j++)
1466  {
1467  for (k = 0; k < BIHASH_KVP_PER_PAGE; k++)
1468  {
1469  if (clib_bihash_is_free_24_8 (&v->kvp[k]))
1470  continue;
1471 
1472  gbp_endpoint_check (v->kvp[k].value, start_time);
1473 
1474  /*
1475  * Note: we may have just freed the bucket's backing
1476  * storage, so check right here...
1477  */
1478  if (b->offset == 0)
1479  goto doublebreak;
1480  }
1481  v++;
1482  }
1483  doublebreak:
1484  ;
1485  }
1486 }
1487 
1488 void
1490 {
1491  gbp_endpoint_scan_l2 (vm);
1492  gbp_endpoint_scan_l3 (vm);
1493 }
1494 
1495 static fib_node_t *
1497 {
1498  gbp_endpoint_t *ge;
1499 
1500  ge = gbp_endpoint_get (index);
1501 
1502  return (&ge->ge_node);
1503 }
1504 
1505 static gbp_endpoint_t *
1507 {
1509  return ((gbp_endpoint_t *) node);
1510 }
1511 
1512 static void
1514 {
1515  const gbp_bridge_domain_t *gbd;
1516  const gbp_route_domain_t *grd;
1517  const fib_prefix_t *pfx;
1518  gbp_endpoint_t *ge;
1519 
1520  ge = gbp_endpoint_from_fib_node (node);
1521 
1522  ASSERT (0 == vec_len (ge->ge_locs));
1523 
1524  gbd = gbp_bridge_domain_get (ge->ge_key.gek_gbd);
1525 
1526  /*
1527  * we have removed the last source. this EP is toast
1528  */
1529  if (INDEX_INVALID != ge->ge_key.gek_gbd)
1530  {
1532  }
1533  vec_foreach (pfx, ge->ge_key.gek_ips)
1534  {
1535  grd = gbp_route_domain_get (ge->ge_key.gek_grd);
1536  gbp_endpoint_del_ip (&pfx->fp_addr, grd->grd_fib_index[pfx->fp_proto]);
1537  }
1538  pool_put (gbp_endpoint_pool, ge);
1539 }
1540 
1544 {
1545  ASSERT (0);
1546 
1547  return (FIB_NODE_BACK_WALK_CONTINUE);
1548 }
1549 
1550 /*
1551  * The FIB path's graph node virtual function table
1552  */
1553 static const fib_node_vft_t gbp_endpoint_vft = {
1555  .fnv_last_lock = gbp_endpoint_last_lock_gone,
1556  .fnv_back_walk = gbp_endpoint_back_walk_notify,
1557  // .fnv_mem_show = fib_path_memory_show,
1558 };
1559 
1560 static clib_error_t *
1562 {
1563 #define GBP_EP_HASH_NUM_BUCKETS (2 * 1024)
1564 #define GBP_EP_HASH_MEMORY_SIZE (1 << 20)
1565 
1566  clib_bihash_init_24_8 (&gbp_ep_db.ged_by_ip_rd,
1567  "GBP Endpoints - IP/RD",
1569 
1570  clib_bihash_init_16_8 (&gbp_ep_db.ged_by_mac_bd,
1571  "GBP Endpoints - MAC/BD",
1573 
1574  gbp_ep_logger = vlib_log_register_class ("gbp", "ep");
1575  gbp_endpoint_fib_type = fib_node_register_new_type (&gbp_endpoint_vft);
1576 
1577  return (NULL);
1578 }
1579 
1581 
1582 /*
1583  * fd.io coding-style-patch-verification: ON
1584  *
1585  * Local Variables:
1586  * eval: (c-set-style "gnu")
1587  * End:
1588  */
vlib_log_class_t vlib_log_register_class(char *class, char *subclass)
Definition: log.c:227
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:439
A real VXLAN-GBP tunnel (from vnet/vxlan-gbp/...)
Definition: gbp_vxlan.h:107
u32 sw_if_index
Definition: ipsec_gre.api:37
static void gbp_endpoint_scan_l3(vlib_main_t *vm)
index_t gek_grd
Index of the Route-Domain.
Definition: gbp_endpoint.h:106
fib_protocol_t fp_proto
protocol type
Definition: fib_types.h:212
fib_node_index_t fib_table_entry_path_add(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source, fib_entry_flag_t flags, dpo_proto_t next_hop_proto, const ip46_address_t *next_hop, u32 next_hop_sw_if_index, u32 next_hop_fib_index, u32 next_hop_weight, fib_mpls_label_t *next_hop_labels, fib_route_path_flags_t path_flags)
Add one path to an entry (aka route) in the FIB.
Definition: fib_table.c:522
int gbp_endpoint_is_external(const gbp_endpoint_t *ge)
Definition: gbp_endpoint.c:99
void gbp_itf_set_l2_input_feature(index_t gii, index_t useri, l2input_feat_masks_t feats)
Definition: gbp_itf.c:102
u32 gbp_vxlan_tunnel_clone_and_lock(u32 sw_if_index, const ip46_address_t *src, const ip46_address_t *dst)
Definition: gbp_vxlan.c:239
static gbp_endpoint_loc_t * gbp_endpoint_loc_find_or_add(gbp_endpoint_t *ge, gbp_endpoint_src_t src)
Definition: gbp_endpoint.c:337
static gbp_endpoint_src_t gbp_endpoint_get_best_src(const gbp_endpoint_t *ge)
Definition: gbp_endpoint.c:449
u32 flags
Definition: vhost_user.h:115
u32 gef_fib_index
FIB index the EP is in.
Definition: gbp_endpoint.h:174
int gbp_endpoint_is_remote(const gbp_endpoint_t *ge)
Definition: gbp_endpoint.c:87
static gbp_endpoint_t * gbp_endpoint_get(index_t gbpei)
Get the endpoint from a port/interface.
Definition: gbp_endpoint.h:262
f64 ge_last_time
The last time a packet from seen from this end point.
Definition: gbp_endpoint.h:210
u16 sclass_t
Definition: gbp_types.h:24
index_t * ged_by_sw_if_index
Definition: gbp_endpoint.h:220
A Group Based Policy Endpoint.
Definition: gbp_endpoint.h:187
fib_prefix_t * gek_ips
A vector of ip addresses that belong to the endpoint.
Definition: gbp_endpoint.h:90
const mac_address_t * gbp_route_domain_get_local_mac(void)
#define BIHASH_KVP_PER_PAGE
Definition: bihash_16_8.h:19
a
Definition: bitmap.h:538
void gbp_endpoint_unlock(gbp_endpoint_src_t src, index_t gei)
Definition: gbp_endpoint.c:920
Information about the location of the endpoint provided by a source of endpoints. ...
Definition: gbp_endpoint.h:113
gbp_endpoint_fwd_t ge_fwd
Definition: gbp_endpoint.h:205
#define GBP_EP_HASH_NUM_BUCKETS
gbp_endpoint_key_t ge_key
The key/ID of this EP.
Definition: gbp_endpoint.h:197
u32 bd_add_del_ip_mac(u32 bd_index, ip46_type_t type, const ip46_address_t *ip, const mac_address_t *mac, u8 is_add)
Add/delete IP address to MAC address mapping.
Definition: l2_bd.c:742
vnet_main_t * vnet_get_main(void)
Definition: misc.c:47
static void gbp_endpoint_walk_mac_itf(const clib_bihash_kv_16_8_t *kvp, void *arg)
#define pool_get_zero(P, E)
Allocate an object E from a pool P and zero it.
Definition: pool.h:239
struct gbp_endpoint_loc_t_::@437 tun
Tunnel info for remote endpoints.
index_t * gef_adjs
The L3 adj, if created.
Definition: gbp_endpoint.h:164
void fib_node_init(fib_node_t *node, fib_node_type_t type)
Definition: fib_node.c:185
ip46_type_t fib_proto_to_ip46(fib_protocol_t fproto)
Convert from fib_protocol to ip46_type.
Definition: fib_types.c:287
u32 gb_vni
The index of the BD&#39;s VNI interface on which packets from unkown endpoints arrive.
static void gbp_endpoint_walk_ip_itf(const clib_bihash_kv_24_8_t *kvp, void *arg)
struct gbp_endpoint_flush_ctx_t_ gbp_endpoint_flush_ctx_t
Definition: fib_entry.h:286
static void gbp_endpoint_del_ip(const ip46_address_t *ip, u32 fib_index)
Definition: gbp_endpoint.c:185
#define NULL
Definition: clib.h:58
int gbp_endpoint_is_local(const gbp_endpoint_t *ge)
Definition: gbp_endpoint.c:93
static walk_rc_t gbp_endpoint_show_one(index_t gei, void *ctx)
gbp_endpoint_flags_t gef_flags
Definition: gbp_endpoint.h:176
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:255
index_t gef_itf
The interface on which the EP is connected.
Definition: gbp_endpoint.h:159
ip46_address_t gt_src
The source address to use for child tunnels.
Definition: gbp_vxlan.h:89
static gbp_endpoint_loc_t * gbp_endpoint_loc_find(gbp_endpoint_t *ge, gbp_endpoint_src_t src)
Definition: gbp_endpoint.c:285
enum fib_node_back_walk_rc_t_ fib_node_back_walk_rc_t
Return code from a back walk function.
u8 src_address[6]
Definition: packet.h:56
enum gbp_endpoint_src_t_ gbp_endpoint_src_t
A bridge Domain Representation.
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
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:522
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
Definition: vec.h:560
int i
static void gbp_endpoint_scan_l2(vlib_main_t *vm)
static_always_inline void mac_address_copy(mac_address_t *dst, const mac_address_t *src)
Definition: mac_address.h:128
format_function_t format_ip46_address
Definition: format.h:61
static_always_inline int mac_address_is_zero(const mac_address_t *mac)
Definition: mac_address.h:106
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
static u32 gbp_n_learnt_endpoints
A count of the number of dynamic entries.
Definition: gbp_endpoint.c:62
unformat_function_t unformat_vnet_sw_interface
index_t gg_rd
route-domain/IP-table ID the EPG is in
index_t gbp_route_domain_index(const gbp_route_domain_t *grd)
static gbp_bridge_domain_t * gbp_bridge_domain_get(index_t i)
gbp_endpoint_src_t gel_src
The source providing this location information.
Definition: gbp_endpoint.h:118
adj_index_t adj_nbr_add_or_lock_w_rewrite(fib_protocol_t nh_proto, vnet_link_t link_type, const ip46_address_t *nh_addr, u32 sw_if_index, u8 *rewrite)
Add (and lock) a new or lock an existing neighbour adjacency.
Definition: adj_nbr.c:263
static int clib_bihash_is_free_16_8(clib_bihash_kv_16_8_t *v)
Definition: bihash_16_8.h:37
static void gbb_endpoint_fwd_reset(gbp_endpoint_t *ge)
Definition: gbp_endpoint.c:564
format_function_t format_vnet_sw_if_index_name
#define GBP_ENDPOINT_SRC_MAX
Definition: gbp_endpoint.h:75
unsigned char u8
Definition: types.h:56
static gbp_endpoint_t * gbp_endpoint_from_fib_node(fib_node_t *node)
fib_node_type_t fib_node_register_new_type(const fib_node_vft_t *vft)
Create a new FIB node type and Register the function table for it.
Definition: fib_node.c:80
static int gbp_endpoint_ip_is_equal(const fib_prefix_t *fp, const ip46_address_t *ip)
Definition: gbp_endpoint.c:207
enum fib_protocol_t_ fib_protocol_t
Protocol Type.
void gbp_itf_unlock(index_t gii)
Definition: gbp_itf.c:81
u32 fib_node_child_add(fib_node_type_t parent_type, fib_node_index_t parent_index, fib_node_type_t type, fib_node_index_t index)
Definition: fib_node.c:98
static uword ip46_address_is_multicast(const ip46_address_t *a)
Definition: ip6_packet.h:178
double f64
Definition: types.h:142
static void gbp_endpoint_loc_destroy(gbp_endpoint_loc_t *gel)
Definition: gbp_endpoint.c:326
#define clib_memcpy(d, s, n)
Definition: string.h:180
index_t gbp_bridge_domain_index(const gbp_bridge_domain_t *gbd)
static uword vlib_process_suspend(vlib_main_t *vm, f64 dt)
Suspend a vlib cooperative multi-tasking thread for a period of time.
Definition: node_funcs.h:452
enum walk_rc_t_ walk_rc_t
Walk return code.
gbp_endpoint_t * gbp_endpoint_pool
Pool of GBP endpoints.
Definition: gbp_endpoint.c:57
u32 vlib_log_class_t
Definition: vlib.h:50
void vxlan_gbp_tunnel_unlock(u32 sw_if_index)
Definition: gbp_vxlan.c:297
unformat_function_t unformat_ip4_address
Definition: format.h:70
gbp_endpoint_flags_t gel_flags
Endpoint flags.
Definition: gbp_endpoint.h:128
static int gbp_endpoint_loc_unlock(gbp_endpoint_t *ge, gbp_endpoint_loc_t *gel)
Definition: gbp_endpoint.c:302
static_always_inline void mac_address_to_bytes(const mac_address_t *mac, u8 *bytes)
Definition: mac_address.h:99
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:163
void fib_table_entry_special_remove(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source)
Remove a &#39;special&#39; entry from the FIB.
Definition: fib_table.c:407
void fib_walk_sync(fib_node_type_t parent_type, fib_node_index_t parent_index, fib_node_back_walk_ctx_t *ctx)
Back walk all the children of a FIB node.
Definition: fib_walk.c:745
u8 dst_address[6]
Definition: packet.h:55
gbp_endpoint_group_t * gbp_endpoint_group_get(index_t i)
u8 * format_fib_prefix(u8 *s, va_list *args)
Definition: fib_types.c:177
A high priority source a plugin can use.
Definition: fib_entry.h:62
clib_bihash_24_8_t ged_by_ip_rd
Definition: gbp_endpoint.h:221
u32 gel_sw_if_index
The interface on which the EP is connected.
Definition: gbp_endpoint.h:123
static int clib_bihash_is_free_24_8(const clib_bihash_kv_24_8_t *v)
Definition: bihash_24_8.h:37
static_always_inline gbp_endpoint_t * gbp_endpoint_find_mac(const u8 *mac, u32 bd_index)
Definition: gbp_endpoint.h:276
Aggregrate type for a prefix.
Definition: fib_types.h:203
u8 * format_gbp_endpoint_flags(u8 *s, va_list *args)
Definition: gbp_endpoint.c:70
#define clib_error_return(e, args...)
Definition: error.h:99
void l2fib_add_entry(const u8 *mac, u32 bd_index, u32 sw_if_index, l2fib_entry_result_flags_t flags)
Add an entry to the l2fib.
Definition: l2_fib.c:401
u8 * format_gbp_itf(u8 *s, va_list *args)
Definition: gbp_itf.c:190
void adj_unlock(adj_index_t adj_index)
Release a reference counting lock on the adjacency.
Definition: adj.c:318
unsigned int u32
Definition: types.h:88
index_t gek_gbd
Index of the Bridge-Domain.
Definition: gbp_endpoint.h:101
static void gbp_endpoint_extract_key_ip_itf(const clib_bihash_kv_24_8_t *key, ip46_address_t *ip, u32 *sw_if_index)
Definition: gbp_endpoint.c:113
static fib_node_back_walk_rc_t gbp_endpoint_back_walk_notify(fib_node_t *node, fib_node_back_walk_ctx_t *ctx)
static void gbp_endpoint_check(index_t gei, f64 start_time)
static const u8 * vnet_sw_interface_get_hw_address(vnet_main_t *vnm, u32 sw_if_index)
Definition: fib_entry.h:275
fib_protocol_t fib_proto_from_ip46(ip46_type_t iproto)
Convert from ip46_type to fib_protocol.
Definition: fib_types.c:303
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
Definition: dpo.h:168
fib_node_bw_reason_flag_t fnbw_reason
The reason/trigger for the backwalk.
Definition: fib_node.h:208
#define GBP_ENDPOINT_ATTR_NAMES
Definition: gbp_endpoint.h:50
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
Definition: node_funcs.h:964
ip46_address_t fp_addr
The address type is not deriveable from the fp_addr member.
Definition: fib_types.h:226
GBP Endpoint Databases.
Definition: gbp_endpoint.h:218
void fib_node_lock(fib_node_t *node)
Definition: fib_node.c:203
long ctx[MAX_CONNS]
Definition: main.c:144
static u8 * format_gbp_endpoint_key(u8 *s, va_list *args)
struct _unformat_input_t unformat_input_t
void gbp_endpoint_scan(vlib_main_t *vm)
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:286
u16 sclass
Definition: gbp.api:118
This is the object type deifend above.
Definition: gbp_vxlan.h:102
static fib_node_t * gbp_endpoint_get_node(fib_node_index_t index)
clib_bihash_16_8_t ged_by_mac_bd
Definition: gbp_endpoint.h:222
#define vec_del1(v, i)
Delete the element at index I.
Definition: vec.h:804
u32 remote_ep_timeout
Aging timeout for remote endpoints.
static_always_inline void mac_address_from_u64(mac_address_t *mac, u64 u)
Definition: mac_address.h:122
vl_api_ip4_address_t src
Definition: ipsec_gre.api:38
#define SCLASS_INVALID
Definition: gbp_types.h:25
void gbp_itf_set_l2_output_feature(index_t gii, index_t useri, l2output_feat_masks_t feats)
Definition: gbp_itf.c:146
fib_node_type_t fn_type
The node&#39;s type.
Definition: fib_node.h:295
An node in the FIB graph.
Definition: fib_node.h:291
sclass_t gef_sclass
Endpoint Group&#39;s sclass.
Definition: gbp_endpoint.h:169
l2input_feat_masks_t
Definition: l2_input.h:138
void fib_node_unlock(fib_node_t *node)
Definition: fib_node.c:209
static void gbp_endpoint_loc_update(gbp_endpoint_loc_t *gel, const gbp_bridge_domain_t *gb, u32 sw_if_index, index_t ggi, gbp_endpoint_flags_t flags, const ip46_address_t *tun_src, const ip46_address_t *tun_dst)
Definition: gbp_endpoint.c:477
static ip46_type_t ip46_address_get_type(const ip46_address_t *a)
Definition: gbp_endpoint.c:201
mac_address_t gek_mac
MAC address of the endpoint.
Definition: gbp_endpoint.h:96
int gbp_endpoint_update_and_lock(gbp_endpoint_src_t src, u32 sw_if_index, const ip46_address_t *ips, const mac_address_t *mac, index_t gbdi, index_t grdi, 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:824
u32 gbp_endpoint_child_add(index_t gei, fib_node_type_t type, fib_node_index_t index)
An Endpoint Group representation.
#define ip46_address_initializer
Definition: ip6_packet.h:96
vlib_node_registration_t gbp_scanner_node
(constructor) VLIB_REGISTER_NODE (gbp_scanner_node)
Definition: gbp_scanner.c:89
static void gbp_endpoint_ips_update(gbp_endpoint_t *ge, const ip46_address_t *ips, const gbp_route_domain_t *grd)
Definition: gbp_endpoint.c:213
#define ip46_address_is_ip4(ip46)
Definition: ip6_packet.h:88
unformat_function_t unformat_ip6_address
Definition: format.h:91
static u8 * format_gbp_endpoint_loc(u8 *s, va_list *args)
#define UNFORMAT_END_OF_INPUT
Definition: format.h:144
u32 l2fib_del_entry(const u8 *mac, u32 bd_index, u32 sw_if_index)
Delete an entry from the l2fib.
Definition: l2_fib.c:685
static void gbp_endpoint_add_itf(u32 sw_if_index, index_t gei)
Definition: gbp_endpoint.c:138
enum gbp_endpoint_attr_t_ gbp_endpoint_attr_t
Flags for each endpoint.
vlib_main_t * vm
Definition: buffer.c:312
static bool gbp_endpoint_add_ip(const ip46_address_t *ip, u32 fib_index, index_t gei)
Definition: gbp_endpoint.c:161
void gbp_endpoint_walk(gbp_endpoint_cb_t cb, void *ctx)
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:341
void fib_table_entry_delete(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source)
Delete a FIB entry.
Definition: fib_table.c:853
Force the walk to be synchronous.
Definition: fib_node.h:170
#define FOR_EACH_GBP_ENDPOINT_ATTR(_item)
Definition: gbp_endpoint.c:64
u32 grd_fib_index[FIB_PROTOCOL_IP_MAX]
fib_node_get_t fnv_get
Definition: fib_node.h:279
void send_ip6_na_w_addr(vlib_main_t *vm, const ip6_address_t *addr, u32 sw_if_index)
#define vec_search_with_function(v, E, fn)
Search a vector for the index of the entry that matches.
Definition: vec.h:961
static_always_inline void ip46_address_copy(ip46_address_t *dst, const ip46_address_t *src)
Definition: ip6_packet.h:99
static void gbb_endpoint_fwd_recalc(gbp_endpoint_t *ge)
Definition: gbp_endpoint.c:617
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:30
void gbp_endpoint_group_lock(index_t i)
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:283
uword unformat_mac_address(unformat_input_t *input, va_list *args)
Definition: format.c:241
void fib_prefix_from_ip46_addr(const ip46_address_t *addr, fib_prefix_t *pfx)
Host prefix from ip.
Definition: fib_types.c:80
static clib_error_t * gbp_endpoint_init(vlib_main_t *vm)
gbp_endpoint_t * gbp_endpoint_find_ip(const ip46_address_t *ip, u32 fib_index)
Definition: gbp_endpoint.c:122
void send_ip4_garp_w_addr(vlib_main_t *vm, const ip4_address_t *ip4_addr, u32 sw_if_index)
Definition: arp.c:2566
void gbp_endpoint_flush(gbp_endpoint_src_t src, u32 sw_if_index)
remove all learnt endpoints using the interface
Context passed between object during a back walk.
Definition: fib_node.h:204
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:155
This is the identity of an endpoint, as such it is information about an endpoint that is idempotent...
Definition: gbp_endpoint.h:84
static walk_rc_t gbp_endpoint_flush_cb(index_t gei, void *args)
fib_node_index_t fib_table_entry_special_dpo_add(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source, fib_entry_flag_t flags, const dpo_id_t *dpo)
Add a &#39;special&#39; entry to the FIB that links to the DPO passed A special entry is an entry that the FI...
Definition: fib_table.c:307
gbp_endpoint_src_t src
enum gbp_endpoint_flags_t_ gbp_endpoint_flags_t
static bool gbp_endpoint_add_mac(const mac_address_t *mac, u32 bd_index, index_t gei)
Definition: gbp_endpoint.c:146
#define ASSERT(truth)
gbp_route_domain_t * gbp_route_domain_get(index_t i)
static u8 * format_gbp_endpoint_fwd(u8 *s, va_list *args)
u8 * format_gbp_endpoint(u8 *s, va_list *args)
const mac_address_t ZERO_MAC_ADDRESS
Definition: mac_address.c:19
u32 gb_bvi_sw_if_index
The BD&#39;s BVI interface (obligatory)
vlib_log_class_t gbp_ep_logger
Definition: gbp_endpoint.c:46
ip46_type_t
Definition: ip6_packet.h:70
void gbp_endpoint_group_unlock(index_t ggi)
const mac_address_t * gbp_route_domain_get_remote_mac(void)
#define GBP_ENDPOINT_INFO(...)
Definition: gbp_endpoint.c:51
static clib_error_t * gbp_endpoint_show(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
void fib_node_child_remove(fib_node_type_t parent_type, fib_node_index_t parent_index, fib_node_index_t sibling_index)
Definition: fib_node.c:123
gbp_endpoint_retention_t gg_retention
EP retention policy.
dpo_proto_t fib_proto_to_dpo(fib_protocol_t fib_proto)
Definition: fib_types.c:237
static gbp_endpoint_t * gbp_endpoint_alloc(const ip46_address_t *ips, const gbp_route_domain_t *grd, const mac_address_t *mac, const gbp_bridge_domain_t *gbd)
Definition: gbp_endpoint.c:244
static void gbp_endpoint_del_mac(const mac_address_t *mac, u32 bd_index)
Definition: gbp_endpoint.c:175
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:23
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:268
#define ip46_address_reset(ip46)
Definition: ip6_packet.h:91
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:292
static int gbp_endpoint_find_for_update(const ip46_address_t *ips, const gbp_route_domain_t *grd, const mac_address_t *mac, const gbp_bridge_domain_t *gbd, gbp_endpoint_t **ge)
Find an EP inthe DBs and check that if we find it in the L2 DB it has the same IPs as this update...
Definition: gbp_endpoint.c:378
static int gbp_endpoint_loc_cmp_for_sort(gbp_endpoint_loc_t *a, gbp_endpoint_loc_t *b)
Definition: gbp_endpoint.c:279
fib_node_t ge_node
A FIB node that allows the tracking of children.
Definition: gbp_endpoint.h:192
gbp_vxlan_tunnel_t * gbp_vxlan_tunnel_get(index_t gti)
Definition: gbp_vxlan.c:87
u32 gel_locks
number of times this source has locked this
Definition: gbp_endpoint.h:138
And endpoints current forwarding state.
Definition: gbp_endpoint.h:154
u32 vxlan_gbp_tunnel_get_parent(u32 sw_if_index)
Definition: gbp_vxlan.c:206
#define ip46_address_is_equal(a1, a2)
Definition: ip6_packet.h:94
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
A route Domain Representation.
u32 gg_uplink_sw_if_index
the uplink interface dedicated to the EPG
static void gbp_endpoint_n_learned(int n)
Definition: gbp_endpoint.c:458
#define INDEX_INVALID
Invalid index - used when no index is known blazoned capitals INVALID speak volumes where ~0 does not...
Definition: dpo.h:47
#define vec_sort_with_function(vec, f)
Sort a vector using the supplied element comparison function.
Definition: vec.h:980
static int gbp_endpoint_loc_is_equal(gbp_endpoint_loc_t *a, gbp_endpoint_loc_t *b)
Definition: gbp_endpoint.c:273
typedef key
Definition: ipsec.api:244
#define DPO_INVALID
An initialiser for DPOs declared on the stack.
Definition: dpo.h:195
static void gbp_endpoint_last_lock_gone(fib_node_t *node)
gbp_vxlan_tunnel_type_t gbp_vxlan_tunnel_get_type(u32 sw_if_index)
Definition: gbp_vxlan.c:221
gbp_ep_db_t gbp_ep_db
EP DBs.
Definition: gbp_endpoint.c:42
void gbp_policy_dpo_add_or_lock(dpo_proto_t dproto, sclass_t sclass, u32 sw_if_index, dpo_id_t *dpo)
A FIB graph nodes virtual function table.
Definition: fib_node.h:278
GBP VXLAN (template) tunnel.
Definition: gbp_vxlan.h:38
enum fib_node_type_t_ fib_node_type_t
The types of nodes in a FIB graph.
index_t gbp_endpoint_group_find(sclass_t sclass)
u8 * format_mac_address_t(u8 *s, va_list *args)
Definition: mac_address.c:27
vl_api_address_t ips[n_ips]
Definition: gbp.api:123
void dpo_reset(dpo_id_t *dpo)
reset a DPO ID The DPO will be unlocked.
Definition: dpo.c:231
#define vec_foreach(var, vec)
Vector iterator.
vnet_link_t fib_proto_to_link(fib_protocol_t proto)
Convert from a protocol to a link type.
Definition: fib_types.c:271
static void gbp_endpoint_extract_key_mac_itf(const clib_bihash_kv_16_8_t *key, mac_address_t *mac, u32 *sw_if_index)
Definition: gbp_endpoint.c:105
index_t gel_epg
Endpoint Group.
Definition: gbp_endpoint.h:133
#define pool_foreach_index(i, v, body)
Iterate pool by index.
Definition: pool.h:538
static const char * gbp_endpoint_attr_names[]
Definition: gbp_endpoint.c:37
#define vec_validate_init_empty(V, I, INIT)
Make sure vector is long enough for given index and initialize empty space (no header, unspecified alignment)
Definition: vec.h:486
fib_node_type_t gbp_endpoint_fib_type
Definition: gbp_endpoint.c:44
index_t gbp_itf_add_and_lock(u32 sw_if_index, u32 bd_index)
Definition: gbp_itf.c:57
gbp_endpoint_loc_t * ge_locs
Location information provided by the various sources.
Definition: gbp_endpoint.h:203
#define ip46_address_is_zero(ip46)
Definition: ip6_packet.h:93
ip46_address_t gel_dst
Definition: gbp_endpoint.h:147
vl_api_mac_address_t mac
Definition: gbp.api:120
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:762
A low (below routing) priority source a plugin can use.
Definition: fib_entry.h:82
#define GBP_EP_HASH_MEMORY_SIZE
void gbp_endpoint_child_remove(index_t gei, u32 sibling)
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:972
static index_t gbp_endpoint_index(const gbp_endpoint_t *ge)
Definition: gbp_endpoint.c:195
void vxlan_gbp_tunnel_lock(u32 sw_if_index)
Definition: gbp_vxlan.c:316
static clib_error_t * gbp_endpoint_cli(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:170
walk_rc_t(* gbp_endpoint_cb_t)(index_t gbpei, void *ctx)
Definition: gbp_endpoint.h:241
index_t gg_gbd
Bridge-domain ID the EPG is in.
u8 * format_gbp_endpoint_src(u8 *s, va_list *args)