FD.io VPP  v17.10-9-gd594711
Vector Packet Processing
lisp_gpe_fwd_entry.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 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 
20 #include <vnet/fib/fib_table.h>
21 #include <vnet/fib/fib_entry.h>
22 #include <vnet/fib/fib_path_list.h>
23 #include <vnet/fib/ip6_fib.h>
24 #include <vnet/fib/ip4_fib.h>
25 #include <vnet/dpo/drop_dpo.h>
26 #include <vnet/dpo/lookup_dpo.h>
27 #include <vnet/dpo/load_balance.h>
28 #include <vnet/adj/adj_midchain.h>
29 
30 /**
31  * @brief Add route to IP4 or IP6 Destination FIB.
32  *
33  * Add a route to the destination FIB that results in the lookup
34  * in the SRC FIB. The SRC FIB is created is it does not yet exist.
35  *
36  * @param[in] dst_table_id Destination FIB Table-ID
37  * @param[in] dst_prefix Destination IP prefix.
38  *
39  * @return src_fib_index The index/ID of the SRC FIB created.
40  */
41 static u32
42 ip_dst_fib_add_route (u32 dst_fib_index, const ip_prefix_t * dst_prefix)
43 {
44  fib_node_index_t src_fib_index;
45  fib_prefix_t dst_fib_prefix;
46  fib_node_index_t dst_fei;
47 
48  ASSERT (NULL != dst_prefix);
49 
50  ip_prefix_to_fib_prefix (dst_prefix, &dst_fib_prefix);
51 
52  /*
53  * lookup the destination prefix in the VRF table and retrieve the
54  * LISP associated data
55  */
56  dst_fei = fib_table_lookup_exact_match (dst_fib_index, &dst_fib_prefix);
57 
58  /*
59  * If the FIB entry is not present, or not LISP sourced, add it
60  */
61  if (dst_fei == FIB_NODE_INDEX_INVALID ||
63  {
64  dpo_id_t src_lkup_dpo = DPO_INVALID;
65 
66  /* create a new src FIB. */
67  src_fib_index =
68  fib_table_create_and_lock (dst_fib_prefix.fp_proto,
70  "LISP-src for [%d,%U]",
71  dst_fib_index,
72  format_fib_prefix, &dst_fib_prefix);
73  /*
74  * add src fib default route
75  */
76  fib_prefix_t prefix = {
77  .fp_proto = dst_fib_prefix.fp_proto,
78  };
79  fib_table_entry_special_dpo_add (src_fib_index, &prefix,
83  (dst_fib_prefix.fp_proto)));
84  /*
85  * create a data-path object to perform the source address lookup
86  * in the SRC FIB
87  */
89  (ip_prefix_version (dst_prefix) ==
90  IP6 ? DPO_PROTO_IP6 :
95  &src_lkup_dpo);
96 
97  /*
98  * add the entry to the destination FIB that uses the lookup DPO
99  */
100  dst_fei = fib_table_entry_special_dpo_add (dst_fib_index,
101  &dst_fib_prefix,
104  &src_lkup_dpo);
105 
106  /*
107  * the DPO is locked by the FIB entry, and we have no further
108  * need for it.
109  */
110  dpo_unlock (&src_lkup_dpo);
111 
112  /*
113  * save the SRC FIB index on the entry so we can retrieve it for
114  * subsequent routes.
115  */
116  fib_entry_set_source_data (dst_fei, FIB_SOURCE_LISP, &src_fib_index);
117  }
118  else
119  {
120  /*
121  * destination FIB entry already present
122  */
123  src_fib_index = *(u32 *) fib_entry_get_source_data (dst_fei,
125  }
126 
127  return (src_fib_index);
128 }
129 
130 /**
131  * @brief Del route to IP4 or IP6 SD FIB.
132  *
133  * Remove routes from both destination and source FIBs.
134  *
135  * @param[in] src_fib_index The index/ID of the SRC FIB
136  * @param[in] src_prefix Source IP prefix.
137  * @param[in] dst_fib_index The index/ID of the DST FIB
138  * @param[in] dst_prefix Destination IP prefix.
139  */
140 static void
142  const ip_prefix_t * src_prefix,
143  u32 dst_fib_index, const ip_prefix_t * dst_prefix)
144 {
145  fib_prefix_t dst_fib_prefix, src_fib_prefix;
146  u8 have_default = 0;
147  u32 n_entries;
148 
149  ASSERT (NULL != dst_prefix);
150  ASSERT (NULL != src_prefix);
151 
152  ip_prefix_to_fib_prefix (dst_prefix, &dst_fib_prefix);
153  ip_prefix_to_fib_prefix (src_prefix, &src_fib_prefix);
154 
155  fib_table_entry_delete (src_fib_index, &src_fib_prefix, FIB_SOURCE_LISP);
156 
157  /* check if only default left or empty */
158  fib_prefix_t default_pref = {
159  .fp_proto = dst_fib_prefix.fp_proto
160  };
161 
162  if (fib_table_lookup_exact_match (src_fib_index,
163  &default_pref) != FIB_NODE_INDEX_INVALID)
164  have_default = 1;
165 
166  n_entries = fib_table_get_num_entries (src_fib_index,
167  src_fib_prefix.fp_proto,
169  if (n_entries == 0 || (have_default && n_entries == 1))
170  {
171  /*
172  * remove src FIB default route
173  */
174  if (have_default)
175  fib_table_entry_special_remove (src_fib_index, &default_pref,
177 
178  /*
179  * there's nothing left now, unlock the source FIB and the
180  * destination route
181  */
182  fib_table_entry_special_remove (dst_fib_index,
183  &dst_fib_prefix, FIB_SOURCE_LISP);
184  fib_table_unlock (src_fib_index, src_fib_prefix.fp_proto,
186  }
187 }
188 
189 /**
190  * @brief Add route to IP4 or IP6 SRC FIB.
191  *
192  * Adds a route to in the LISP SRC FIB with the result of the route
193  * being the DPO passed.
194  *
195  * @param[in] src_fib_index The index/ID of the SRC FIB
196  * @param[in] src_prefix Source IP prefix.
197  * @param[in] src_dpo The DPO the route will link to.
198  *
199  * @return fib index of the inserted prefix
200  */
201 static fib_node_index_t
203  const ip_prefix_t * src_prefix,
204  const dpo_id_t * src_dpo)
205 {
206  fib_node_index_t fei = ~0;
207  fib_prefix_t src_fib_prefix;
208 
209  ip_prefix_to_fib_prefix (src_prefix, &src_fib_prefix);
210 
211  /*
212  * add the entry into the source fib.
213  */
214  fib_node_index_t src_fei;
215 
216  src_fei = fib_table_lookup_exact_match (src_fib_index, &src_fib_prefix);
217 
218  if (FIB_NODE_INDEX_INVALID == src_fei ||
220  {
221  fei = fib_table_entry_special_dpo_add (src_fib_index,
222  &src_fib_prefix,
225  src_dpo);
226  }
227  return fei;
228 }
229 
230 static fib_route_path_t *
232 {
233  const lisp_gpe_adjacency_t *ladj;
234  fib_route_path_t *rpaths = NULL;
235  fib_protocol_t fp;
236  u8 best_priority;
237  u32 ii;
238 
239  vec_validate (rpaths, vec_len (paths) - 1);
240 
241  best_priority = paths[0].priority;
242 
243  vec_foreach_index (ii, paths)
244  {
245  if (paths[0].priority != best_priority)
246  break;
247 
248  ladj = lisp_gpe_adjacency_get (paths[ii].lisp_adj);
249 
250  ip_address_to_46 (&ladj->remote_rloc, &rpaths[ii].frp_addr, &fp);
251 
252  rpaths[ii].frp_proto = fib_proto_to_dpo (fp);
253  rpaths[ii].frp_sw_if_index = ladj->sw_if_index;
254  rpaths[ii].frp_weight = (paths[ii].weight ? paths[ii].weight : 1);
255  }
256 
257  ASSERT (0 != vec_len (rpaths));
258 
259  return (rpaths);
260 }
261 
262 /**
263  * @brief Add route to IP4 or IP6 SRC FIB.
264  *
265  * Adds a route to in the LISP SRC FIB for the tunnel.
266  *
267  * @param[in] src_fib_index The index/ID of the SRC FIB
268  * @param[in] src_prefix Source IP prefix.
269  * @param[in] paths The paths from which to construct the
270  * load balance
271  */
272 static fib_node_index_t
273 ip_src_fib_add_route (u32 src_fib_index,
274  const ip_prefix_t * src_prefix,
275  const lisp_fwd_path_t * paths)
276 {
277  fib_prefix_t src_fib_prefix;
278  fib_route_path_t *rpaths;
279 
280  ip_prefix_to_fib_prefix (src_prefix, &src_fib_prefix);
281 
282  rpaths = lisp_gpe_mk_fib_paths (paths);
283 
284  fib_node_index_t fib_entry_index =
285  fib_table_entry_update (src_fib_index, &src_fib_prefix, FIB_SOURCE_LISP,
286  FIB_ENTRY_FLAG_NONE, rpaths);
287  vec_free (rpaths);
288  return fib_entry_index;
289 }
290 
291 static void
293 {
295  u8 found = 0, ip_version;
296  u32 *lfei, new_lfei;
297  ip_version = ip_prefix_version (&lfe->key->rmt.ippref);
298 
299  new_lfei = lfe - lgm->lisp_fwd_entry_pool;
300  vec_foreach (lfei, lgm->native_fwd_lfes[ip_version])
301  {
302  lfe = pool_elt_at_index (lgm->lisp_fwd_entry_pool, lfei[0]);
303  if (lfei[0] == new_lfei)
304  {
305  found = 1;
306  break;
307  }
308  }
309 
310  if (is_add)
311  {
312  if (!found)
313  vec_add1 (lgm->native_fwd_lfes[ip_version], new_lfei);
314  }
315  else
316  {
317  if (found)
318  vec_del1 (lgm->native_fwd_lfes[ip_version], lfei[0]);
319  }
320 }
321 
322 static index_t
324 {
325  fib_node_index_t fi;
326  fib_entry_t *fe;
328  dpo_proto_t dproto;
329  ip_prefix_t ippref;
330  fib_prefix_t fib_prefix;
331  u8 ip_version = ip_prefix_version (&lfe->key->rmt.ippref);
332  dproto = (ip_version == IP4 ? DPO_PROTO_IP4 : DPO_PROTO_IP6);
333 
334  if (lfe->is_src_dst)
335  {
337  &lfe->key->rmt.ippref);
338  memcpy (&ippref, &lfe->key->lcl.ippref, sizeof (ippref));
339  }
340  else
341  {
342  lfe->src_fib_index = lfe->eid_fib_index;
343  memcpy (&ippref, &lfe->key->rmt.ippref, sizeof (ippref));
344  }
345 
347  {
348  dpo_id_t dpo = DPO_INVALID;
349 
350  switch (lfe->action)
351  {
352  case LISP_FORWARD_NATIVE:
353  /* TODO handle route overlaps with fib and default route */
354  if (vec_len (lgm->native_fwd_rpath[ip_version]))
355  {
356  ip_prefix_to_fib_prefix (&lfe->key->rmt.ippref, &fib_prefix);
357  fi = fib_table_entry_update (lfe->eid_fib_index, &fib_prefix,
360  lgm->native_fwd_rpath[ip_version]);
362  goto done;
363  }
364  case LISP_NO_ACTION:
365  /* TODO update timers? */
367  /* insert tunnel that always sends map-request */
368  dpo_copy (&dpo, lisp_cp_dpo_get (dproto));
369  break;
370  case LISP_DROP:
371  /* for drop fwd entries, just add route, no need to add encap tunnel */
372  dpo_copy (&dpo, drop_dpo_get (dproto));
373  break;
374  }
375  fi = ip_src_fib_add_route_w_dpo (lfe->src_fib_index, &ippref, &dpo);
376  dpo_reset (&dpo);
377  }
378  else
379  {
380  fi = ip_src_fib_add_route (lfe->src_fib_index, &ippref, lfe->paths);
381  }
382 done:
383  fe = fib_entry_get (fi);
384  return fe->fe_lb.dpoi_index;
385 }
386 
387 static void
389 {
390  fib_prefix_t dst_fib_prefix;
391 
392  if (lfe->is_src_dst)
394  &lfe->key->lcl.ippref,
395  lfe->eid_fib_index, &lfe->key->rmt.ippref);
396  else
397  {
398  ip_prefix_to_fib_prefix (&lfe->key->rmt.ippref, &dst_fib_prefix);
399  fib_table_entry_delete (lfe->src_fib_index, &dst_fib_prefix,
402  }
403 }
404 
405 static lisp_gpe_fwd_entry_t *
409 {
410  uword *p;
411 
412  memset (key, 0, sizeof (*key));
413 
415  {
416  /*
417  * the ip version of the source is not set to ip6 when the
418  * source is all zeros. force it.
419  */
422  }
423 
424  gid_to_dp_address (&a->rmt_eid, &key->rmt);
425  gid_to_dp_address (&a->lcl_eid, &key->lcl);
426  key->vni = a->vni;
427 
428  p = hash_get_mem (lgm->lisp_gpe_fwd_entries, key);
429 
430  if (NULL != p)
431  {
432  return (pool_elt_at_index (lgm->lisp_fwd_entry_pool, p[0]));
433  }
434  return (NULL);
435 }
436 
437 static int
438 lisp_gpe_fwd_entry_path_sort (void *a1, void *a2)
439 {
440  lisp_fwd_path_t *p1 = a1, *p2 = a2;
441 
442  return (p1->priority - p2->priority);
443 }
444 
445 static void
448 {
449  lisp_fwd_path_t *path;
450  u32 index;
451 
452  vec_validate (lfe->paths, vec_len (a->locator_pairs) - 1);
453 
454  vec_foreach_index (index, a->locator_pairs)
455  {
456  path = &lfe->paths[index];
457 
458  path->priority = a->locator_pairs[index].priority;
459  path->weight = a->locator_pairs[index].weight;
460 
461  path->lisp_adj =
463  [index],
464  a->dp_table, lfe->key->vni);
465  }
467 }
468 
469 void
471  u32 fwd_entry_index)
472 {
473  const lisp_gpe_adjacency_t *ladj;
474  lisp_fwd_path_t *path;
476  u8 *dummy_elt;
479  lisp_stats_key_t key;
480 
481  lfe = find_fwd_entry (lgm, a, &fe_key);
482 
483  if (!lfe)
484  return;
485 
487  return;
488 
489  memset (&key, 0, sizeof (key));
490  key.fwd_entry_index = fwd_entry_index;
491 
492  vec_foreach (path, lfe->paths)
493  {
494  ladj = lisp_gpe_adjacency_get (path->lisp_adj);
495  key.tunnel_index = ladj->tunnel_index;
496  lisp_stats_key_t *key_copy = clib_mem_alloc (sizeof (*key_copy));
497  memcpy (key_copy, &key, sizeof (*key_copy));
498  pool_get (lgm->dummy_stats_pool, dummy_elt);
499  hash_set_mem (lgm->lisp_stats_index_by_key, key_copy,
500  dummy_elt - lgm->dummy_stats_pool);
501 
503  dummy_elt - lgm->dummy_stats_pool);
505  dummy_elt - lgm->dummy_stats_pool);
506  }
507 }
508 
509 /**
510  * @brief Add/Delete LISP IP forwarding entry.
511  *
512  * creation of forwarding entries for IP LISP overlay:
513  *
514  * @param[in] lgm Reference to @ref lisp_gpe_main_t.
515  * @param[in] a Parameters for building the forwarding entry.
516  *
517  * @return 0 on success.
518  */
519 static int
522 {
525  fib_protocol_t fproto;
526 
527  lfe = find_fwd_entry (lgm, a, &key);
528 
529  if (NULL != lfe)
530  /* don't support updates */
531  return VNET_API_ERROR_INVALID_VALUE;
532 
533  pool_get (lgm->lisp_fwd_entry_pool, lfe);
534  memset (lfe, 0, sizeof (*lfe));
535  lfe->key = clib_mem_alloc (sizeof (key));
536  memcpy (lfe->key, &key, sizeof (key));
537 
539  lfe - lgm->lisp_fwd_entry_pool);
540  a->fwd_entry_index = lfe - lgm->lisp_fwd_entry_pool;
541 
542  fproto = (IP4 == ip_prefix_version (&fid_addr_ippref (&lfe->key->rmt)) ?
544 
545  lfe->type = (a->is_negative ?
549  lfe->eid_table_id = a->table_id;
551  lfe->eid_table_id,
553  lfe->is_src_dst = a->is_src_dst;
554 
556  {
558  }
559  else
560  {
561  lfe->action = a->action;
562  }
563 
564  lfe->dpoi_index = create_fib_entries (lfe);
565  return (0);
566 }
567 
568 static void
570 {
571  lisp_fwd_path_t *path;
572  fib_protocol_t fproto;
573 
575  {
576  vec_foreach (path, lfe->paths)
577  {
579  }
580  }
581 
582  delete_fib_entries (lfe);
583 
584  fproto = (IP4 == ip_prefix_version (&fid_addr_ippref (&lfe->key->rmt)) ?
587 
589  clib_mem_free (lfe->key);
590  pool_put (lgm->lisp_fwd_entry_pool, lfe);
591 }
592 
593 /**
594  * @brief Add/Delete LISP IP forwarding entry.
595  *
596  * removal of forwarding entries for IP LISP overlay:
597  *
598  * @param[in] lgm Reference to @ref lisp_gpe_main_t.
599  * @param[in] a Parameters for building the forwarding entry.
600  *
601  * @return 0 on success.
602  */
603 static int
606 {
609 
610  lfe = find_fwd_entry (lgm, a, &key);
611 
612  if (NULL == lfe)
613  /* no such entry */
614  return VNET_API_ERROR_INVALID_VALUE;
615 
616  del_ip_fwd_entry_i (lgm, lfe);
617 
618  return (0);
619 }
620 
621 static void
622 make_mac_fib_key (BVT (clib_bihash_kv) * kv, u16 bd_index, u8 src_mac[6],
623  u8 dst_mac[6])
624 {
625  kv->key[0] = (((u64) bd_index) << 48) | mac_to_u64 (dst_mac);
626  kv->key[1] = mac_to_u64 (src_mac);
627  kv->key[2] = 0;
628 }
629 
630 /**
631  * @brief Lookup L2 SD FIB entry
632  *
633  * Does a vni + dest + source lookup in the L2 LISP FIB. If the lookup fails
634  * it tries a second time with source set to 0 (i.e., a simple dest lookup).
635  *
636  * @param[in] lgm Reference to @ref lisp_gpe_main_t.
637  * @param[in] bd_index Bridge domain index.
638  * @param[in] src_mac Source mac address.
639  * @param[in] dst_mac Destination mac address.
640  *
641  * @return index of mapping matching the lookup key.
642  */
643 index_t
644 lisp_l2_fib_lookup (lisp_gpe_main_t * lgm, u16 bd_index, u8 src_mac[6],
645  u8 dst_mac[6])
646 {
647  int rv;
648  BVT (clib_bihash_kv) kv, value;
649 
650  make_mac_fib_key (&kv, bd_index, src_mac, dst_mac);
651  rv = BV (clib_bihash_search_inline_2) (&lgm->l2_fib, &kv, &value);
652 
653  /* no match, try with src 0, catch all for dst */
654  if (rv != 0)
655  {
656  kv.key[1] = 0;
657  rv = BV (clib_bihash_search_inline_2) (&lgm->l2_fib, &kv, &value);
658  if (rv == 0)
659  return value.value;
660  }
661  else
662  return value.value;
663 
665 }
666 
667 /**
668  * @brief Add/del L2 SD FIB entry
669  *
670  * Inserts value in L2 FIB keyed by vni + dest + source. If entry is
671  * overwritten the associated value is returned.
672  *
673  * @param[in] lgm Reference to @ref lisp_gpe_main_t.
674  * @param[in] bd_index Bridge domain index.
675  * @param[in] src_mac Source mac address.
676  * @param[in] dst_mac Destination mac address.
677  * @param[in] val Value to add.
678  * @param[in] is_add Add/del flag.
679  *
680  * @return ~0 or value of overwritten entry.
681  */
682 static u32
683 lisp_l2_fib_add_del_entry (u16 bd_index, u8 src_mac[6],
684  u8 dst_mac[6], const dpo_id_t * dpo, u8 is_add)
685 {
687  BVT (clib_bihash_kv) kv, value;
688  u32 old_val = ~0;
689 
690  make_mac_fib_key (&kv, bd_index, src_mac, dst_mac);
691 
692  if (BV (clib_bihash_search) (&lgm->l2_fib, &kv, &value) == 0)
693  old_val = value.value;
694 
695  if (!is_add)
696  BV (clib_bihash_add_del) (&lgm->l2_fib, &kv, 0 /* is_add */ );
697  else
698  {
699  kv.value = dpo->dpoi_index;
700  BV (clib_bihash_add_del) (&lgm->l2_fib, &kv, 1 /* is_add */ );
701  }
702  return old_val;
703 }
704 
705 #define L2_FIB_DEFAULT_HASH_NUM_BUCKETS (64 * 1024)
706 #define L2_FIB_DEFAULT_HASH_MEMORY_SIZE (32<<20)
707 
708 static void
710 {
711  index_t lbi;
712 
713  BV (clib_bihash_init) (&lgm->l2_fib, "l2 fib",
716 
717  /*
718  * the result from a 'miss' in a L2 Table
719  */
722 
724 }
725 
726 static void
728 {
729  lisp_fwd_path_t *path;
730 
732  {
733  vec_foreach (path, lfe->paths)
734  {
736  }
737  fib_path_list_child_remove (lfe->l2.path_list_index,
738  lfe->l2.child_index);
739  }
740 
741  lisp_l2_fib_add_del_entry (lfe->l2.eid_bd_index,
742  fid_addr_mac (&lfe->key->lcl),
743  fid_addr_mac (&lfe->key->rmt), NULL, 0);
744 
746  clib_mem_free (lfe->key);
747  pool_put (lgm->lisp_fwd_entry_pool, lfe);
748 }
749 
750 /**
751  * @brief Delete LISP L2 forwarding entry.
752  *
753  * Coordinates the removal of forwarding entries for L2 LISP overlay:
754  *
755  * @param[in] lgm Reference to @ref lisp_gpe_main_t.
756  * @param[in] a Parameters for building the forwarding entry.
757  *
758  * @return 0 on success.
759  */
760 static int
763 {
766 
767  lfe = find_fwd_entry (lgm, a, &key);
768 
769  if (NULL == lfe)
770  return VNET_API_ERROR_INVALID_VALUE;
771 
772  del_l2_fwd_entry_i (lgm, lfe);
773 
774  return (0);
775 }
776 
777 /**
778  * @brief Construct and insert the forwarding information used by an L2 entry
779  */
780 static void
782 {
784  dpo_id_t dpo = DPO_INVALID;
785 
787  {
788  fib_path_list_contribute_forwarding (lfe->l2.path_list_index,
790  &lfe->l2.dpo);
791  dpo_copy (&dpo, &lfe->l2.dpo);
792  }
793  else
794  {
795  switch (lfe->action)
796  {
797  case SEND_MAP_REQUEST:
798  dpo_copy (&dpo, &lgm->l2_lb_cp_lkup);
799  break;
800  case NO_ACTION:
801  case FORWARD_NATIVE:
802  case DROP:
804  }
805  }
806 
807  /* add entry to l2 lisp fib */
808  lisp_l2_fib_add_del_entry (lfe->l2.eid_bd_index,
809  fid_addr_mac (&lfe->key->lcl),
810  fid_addr_mac (&lfe->key->rmt), &dpo, 1);
811  lfe->dpoi_index = dpo.dpoi_index;
812 
813  dpo_reset (&dpo);
814 }
815 
816 /**
817  * @brief Add LISP L2 forwarding entry.
818  *
819  * Coordinates the creation of forwarding entries for L2 LISP overlay:
820  * creates lisp-gpe tunnel and injects new entry in Source/Dest L2 FIB.
821  *
822  * @param[in] lgm Reference to @ref lisp_gpe_main_t.
823  * @param[in] a Parameters for building the forwarding entry.
824  *
825  * @return 0 on success.
826  */
827 static int
830 {
832  bd_main_t *bdm = &bd_main;
834  uword *bd_indexp;
835 
836  bd_indexp = hash_get (bdm->bd_index_by_bd_id, a->bd_id);
837  if (!bd_indexp)
838  {
839  clib_warning ("bridge domain %d doesn't exist", a->bd_id);
840  return -1;
841  }
842 
843  lfe = find_fwd_entry (lgm, a, &key);
844 
845  if (NULL != lfe)
846  /* don't support updates */
847  return VNET_API_ERROR_INVALID_VALUE;
848 
849  pool_get (lgm->lisp_fwd_entry_pool, lfe);
850  memset (lfe, 0, sizeof (*lfe));
851  lfe->key = clib_mem_alloc (sizeof (key));
852  memcpy (lfe->key, &key, sizeof (key));
853 
855  lfe - lgm->lisp_fwd_entry_pool);
856  a->fwd_entry_index = lfe - lgm->lisp_fwd_entry_pool;
857 
858  lfe->type = (a->is_negative ?
861  lfe->l2.eid_bd_id = a->bd_id;
862  lfe->l2.eid_bd_index = bd_indexp[0];
864 
866  {
867  fib_route_path_t *rpaths;
868 
869  /*
870  * Make the sorted array of LISP paths with their resp. adjacency
871  */
873 
874  /*
875  * From the LISP paths, construct a FIB path list that will
876  * contribute a load-balance.
877  */
878  rpaths = lisp_gpe_mk_fib_paths (lfe->paths);
879 
880  lfe->l2.path_list_index =
882 
883  /*
884  * become a child of the path-list so we receive updates when
885  * its forwarding state changes. this includes an implicit lock.
886  */
887  lfe->l2.child_index =
888  fib_path_list_child_add (lfe->l2.path_list_index,
890  lfe - lgm->lisp_fwd_entry_pool);
891  }
892  else
893  {
894  lfe->action = a->action;
895  }
896 
898 
899  return 0;
900 }
901 
902 /**
903  * @brief Lookup NSH SD FIB entry
904  *
905  * Does an SPI+SI lookup in the NSH LISP FIB.
906  *
907  * @param[in] lgm Reference to @ref lisp_gpe_main_t.
908  * @param[in] spi_si SPI + SI.
909  *
910  * @return next node index.
911  */
912 const dpo_id_t *
913 lisp_nsh_fib_lookup (lisp_gpe_main_t * lgm, u32 spi_si_net_order)
914 {
915  int rv;
916  BVT (clib_bihash_kv) kv, value;
917 
918  memset (&kv, 0, sizeof (kv));
919  kv.key[0] = spi_si_net_order;
920  rv = BV (clib_bihash_search_inline_2) (&lgm->nsh_fib, &kv, &value);
921 
922  if (rv != 0)
923  {
924  return lgm->nsh_cp_lkup;
925  }
926  else
927  {
929  lfe = pool_elt_at_index (lgm->lisp_fwd_entry_pool, value.value);
930  return &lfe->nsh.choice;
931  }
932 }
933 
934 /**
935  * @brief Add/del NSH FIB entry
936  *
937  * Inserts value in NSH FIB keyed by SPI+SI. If entry is
938  * overwritten the associated value is returned.
939  *
940  * @param[in] lgm Reference to @ref lisp_gpe_main_t.
941  * @param[in] spi_si SPI + SI.
942  * @param[in] dpo Load balanced mapped to SPI + SI
943  *
944  * @return ~0 or value of overwritten entry.
945  */
946 static u32
947 lisp_nsh_fib_add_del_entry (u32 spi_si_host_order, u32 lfei, u8 is_add)
948 {
950  BVT (clib_bihash_kv) kv, value;
951  u32 old_val = ~0;
952 
953  memset (&kv, 0, sizeof (kv));
954  kv.key[0] = clib_host_to_net_u32 (spi_si_host_order);
955  kv.value = 0ULL;
956 
957  if (BV (clib_bihash_search) (&lgm->nsh_fib, &kv, &value) == 0)
958  old_val = value.value;
959 
960  if (!is_add)
961  BV (clib_bihash_add_del) (&lgm->nsh_fib, &kv, 0 /* is_add */ );
962  else
963  {
964  kv.value = lfei;
965  BV (clib_bihash_add_del) (&lgm->nsh_fib, &kv, 1 /* is_add */ );
966  }
967  return old_val;
968 }
969 
970 #define NSH_FIB_DEFAULT_HASH_NUM_BUCKETS (64 * 1024)
971 #define NSH_FIB_DEFAULT_HASH_MEMORY_SIZE (32<<20)
972 
973 static void
975 {
976  BV (clib_bihash_init) (&lgm->nsh_fib, "nsh fib",
979 
980  /*
981  * the result from a 'miss' in a NSH Table
982  */
984 }
985 
986 static void
988 {
989  lisp_fwd_path_t *path;
990 
992  {
993  vec_foreach (path, lfe->paths)
994  {
996  }
997  fib_path_list_child_remove (lfe->nsh.path_list_index,
998  lfe->nsh.child_index);
999  dpo_reset (&lfe->nsh.choice);
1000  }
1001 
1002  lisp_nsh_fib_add_del_entry (fid_addr_nsh (&lfe->key->rmt), (u32) ~ 0, 0);
1003 
1005  clib_mem_free (lfe->key);
1006  pool_put (lgm->lisp_fwd_entry_pool, lfe);
1007 }
1008 
1009 /**
1010  * @brief Delete LISP NSH forwarding entry.
1011  *
1012  * Coordinates the removal of forwarding entries for NSH LISP overlay:
1013  *
1014  * @param[in] lgm Reference to @ref lisp_gpe_main_t.
1015  * @param[in] a Parameters for building the forwarding entry.
1016  *
1017  * @return 0 on success.
1018  */
1019 static int
1022 {
1024  lisp_gpe_fwd_entry_t *lfe;
1025 
1026  lfe = find_fwd_entry (lgm, a, &key);
1027 
1028  if (NULL == lfe)
1029  return VNET_API_ERROR_INVALID_VALUE;
1030 
1031  del_nsh_fwd_entry_i (lgm, lfe);
1032 
1033  return (0);
1034 }
1035 
1036 /**
1037  * @brief Construct and insert the forwarding information used by an NSH entry
1038  */
1039 static void
1041 {
1043  dpo_id_t dpo = DPO_INVALID;
1045  uword *hip;
1046 
1048  {
1049  fib_path_list_contribute_forwarding (lfe->nsh.path_list_index,
1051  &lfe->nsh.dpo);
1052 
1053  /*
1054  * LISP encap is always the same for this SPI+SI so we do that hash now
1055  * and stack on the choice.
1056  */
1057  if (DPO_LOAD_BALANCE == lfe->nsh.dpo.dpoi_type)
1058  {
1059  const dpo_id_t *tmp;
1060  const load_balance_t *lb;
1061  int hash;
1062 
1063  lb = load_balance_get (lfe->nsh.dpo.dpoi_index);
1064  hash = fid_addr_nsh (&lfe->key->rmt) % lb->lb_n_buckets;
1065  tmp =
1067 
1068  dpo_copy (&dpo, tmp);
1069  }
1070  }
1071  else
1072  {
1073  switch (lfe->action)
1074  {
1075  case SEND_MAP_REQUEST:
1076  dpo_copy (&dpo, lgm->nsh_cp_lkup);
1077  break;
1078  case NO_ACTION:
1079  case FORWARD_NATIVE:
1080  case DROP:
1082  }
1083  }
1084 
1085  /* We have only one nsh-lisp interface (no NSH virtualization) */
1087  if (hip)
1088  {
1089  hi = vnet_get_hw_interface (lgm->vnet_main, hip[0]);
1090  dpo_stack_from_node (hi->tx_node_index, &lfe->nsh.choice, &dpo);
1091  }
1092  /* add entry to nsh lisp fib */
1094  lfe - lgm->lisp_fwd_entry_pool, 1);
1095  dpo_reset (&dpo);
1096 
1097 }
1098 
1099 /**
1100  * @brief Add LISP NSH forwarding entry.
1101  *
1102  * Coordinates the creation of forwarding entries for L2 LISP overlay:
1103  * creates lisp-gpe tunnel and injects new entry in Source/Dest L2 FIB.
1104  *
1105  * @param[in] lgm Reference to @ref lisp_gpe_main_t.
1106  * @param[in] a Parameters for building the forwarding entry.
1107  *
1108  * @return 0 on success.
1109  */
1110 static int
1113 {
1115  lisp_gpe_fwd_entry_t *lfe;
1116 
1117  lfe = find_fwd_entry (lgm, a, &key);
1118 
1119  if (NULL != lfe)
1120  /* don't support updates */
1121  return VNET_API_ERROR_INVALID_VALUE;
1122 
1123  pool_get (lgm->lisp_fwd_entry_pool, lfe);
1124  memset (lfe, 0, sizeof (*lfe));
1125  lfe->key = clib_mem_alloc (sizeof (key));
1126  memcpy (lfe->key, &key, sizeof (key));
1127 
1129  lfe - lgm->lisp_fwd_entry_pool);
1130  a->fwd_entry_index = lfe - lgm->lisp_fwd_entry_pool;
1131 
1132  lfe->type = (a->is_negative ?
1135  lfe->tenant = 0;
1136 
1138  {
1139  fib_route_path_t *rpaths;
1140 
1141  /*
1142  * Make the sorted array of LISP paths with their resp. adjacency
1143  */
1144  lisp_gpe_fwd_entry_mk_paths (lfe, a);
1145 
1146  /*
1147  * From the LISP paths, construct a FIB path list that will
1148  * contribute a load-balance.
1149  */
1150  rpaths = lisp_gpe_mk_fib_paths (lfe->paths);
1151 
1152  lfe->nsh.path_list_index =
1154 
1155  /*
1156  * become a child of the path-list so we receive updates when
1157  * its forwarding state changes. this includes an implicit lock.
1158  */
1159  lfe->nsh.child_index =
1160  fib_path_list_child_add (lfe->nsh.path_list_index,
1162  lfe - lgm->lisp_fwd_entry_pool);
1163  }
1164  else
1165  {
1166  lfe->action = a->action;
1167  }
1168 
1170 
1171  return 0;
1172 }
1173 
1174 /**
1175  * @brief conver from the embedded fib_node_t struct to the LSIP entry
1176  */
1177 static lisp_gpe_fwd_entry_t *
1179 {
1180  return ((lisp_gpe_fwd_entry_t *) (((char *) node) -
1182  node)));
1183 }
1184 
1185 /**
1186  * @brief Function invoked during a backwalk of the FIB graph
1187  */
1191 {
1193 
1194  if (fid_addr_type (&lfe->key->rmt) == FID_ADDR_MAC)
1196  else if (fid_addr_type (&lfe->key->rmt) == FID_ADDR_NSH)
1198 
1199  return (FIB_NODE_BACK_WALK_CONTINUE);
1200 }
1201 
1202 /**
1203  * @brief Get a fib_node_t struct from the index of a LISP fwd entry
1204  */
1205 static fib_node_t *
1207 {
1209  lisp_gpe_fwd_entry_t *lfe;
1210 
1211  lfe = pool_elt_at_index (lgm->lisp_fwd_entry_pool, index);
1212 
1213  return (&(lfe->node));
1214 }
1215 
1216 /**
1217  * @brief An indication from the graph that the last lock has gone
1218  */
1219 static void
1221 {
1222  /* We don't manage the locks of the LISP objects via the graph, since
1223  * this object has no children. so this is a no-op. */
1224 }
1225 
1226 /**
1227  * @brief Virtual function table to register with FIB for the LISP type
1228  */
1232  .fnv_back_walk = lisp_gpe_fib_node_back_walk,
1233 };
1234 
1235 /**
1236  * @brief Forwarding entry create/remove dispatcher.
1237  *
1238  * Calls l2 or l3 forwarding entry add/del function based on input data.
1239  *
1240  * @param[in] a Forwarding entry parameters.
1241  * @param[out] hw_if_indexp NOT USED
1242  *
1243  * @return 0 on success.
1244  */
1245 int
1247  u32 * hw_if_indexp)
1248 {
1250  u8 type;
1251 
1253  {
1254  clib_warning ("LISP is disabled!");
1255  return VNET_API_ERROR_LISP_DISABLED;
1256  }
1257 
1258  type = gid_address_type (&a->rmt_eid);
1259  switch (type)
1260  {
1261  case GID_ADDR_IP_PREFIX:
1262  if (a->is_add)
1263  return add_ip_fwd_entry (lgm, a);
1264  else
1265  return del_ip_fwd_entry (lgm, a);
1266  break;
1267  case GID_ADDR_MAC:
1268  if (a->is_add)
1269  return add_l2_fwd_entry (lgm, a);
1270  else
1271  return del_l2_fwd_entry (lgm, a);
1272  case GID_ADDR_NSH:
1273  if (a->is_add)
1274  return add_nsh_fwd_entry (lgm, a);
1275  else
1276  return del_nsh_fwd_entry (lgm, a);
1277  default:
1278  clib_warning ("Forwarding entries for type %d not supported!", type);
1279  return -1;
1280  }
1281 }
1282 
1283 int
1285 {
1288  u32 i;
1289 
1290  for (i = 0; i < vlib_combined_counter_n_counters (cm); i++)
1292 
1293  return 0;
1294 }
1295 
1296 static void
1297 lisp_del_adj_stats (lisp_gpe_main_t * lgm, u32 fwd_entry_index, u32 ti)
1298 {
1299  hash_pair_t *hp;
1300  lisp_stats_key_t key;
1301  void *key_copy;
1302  uword *p;
1303  u8 *s;
1304 
1305  memset (&key, 0, sizeof (key));
1306  key.fwd_entry_index = fwd_entry_index;
1307  key.tunnel_index = ti;
1308 
1309  p = hash_get_mem (lgm->lisp_stats_index_by_key, &key);
1310  if (p)
1311  {
1312  s = pool_elt_at_index (lgm->dummy_stats_pool, p[0]);
1313  hp = hash_get_pair (lgm->lisp_stats_index_by_key, &key);
1314  key_copy = (void *) (hp->key);
1316  clib_mem_free (key_copy);
1317  pool_put (lgm->dummy_stats_pool, s);
1318  }
1319 }
1320 
1321 void
1323  u32 fwd_entry_index)
1324 {
1326  lisp_gpe_fwd_entry_key_t fe_key;
1327  lisp_gpe_fwd_entry_t *lfe;
1328  lisp_fwd_path_t *path;
1329  const lisp_gpe_adjacency_t *ladj;
1330 
1331  lfe = find_fwd_entry (lgm, a, &fe_key);
1332  if (!lfe)
1333  return;
1334 
1336  return;
1337 
1338  vec_foreach (path, lfe->paths)
1339  {
1340  ladj = lisp_gpe_adjacency_get (path->lisp_adj);
1341  lisp_del_adj_stats (lgm, fwd_entry_index, ladj->tunnel_index);
1342  }
1343 }
1344 
1345 /**
1346  * @brief Flush all the forwrding entries
1347  */
1348 void
1350 {
1352  lisp_gpe_fwd_entry_t *lfe;
1353 
1354  /* *INDENT-OFF* */
1355  pool_foreach (lfe, lgm->lisp_fwd_entry_pool,
1356  ({
1357  switch (fid_addr_type(&lfe->key->rmt))
1358  {
1359  case FID_ADDR_MAC:
1360  del_l2_fwd_entry_i (lgm, lfe);
1361  break;
1362  case FID_ADDR_IP_PREF:
1363  del_ip_fwd_entry_i (lgm, lfe);
1364  break;
1365  case FID_ADDR_NSH:
1366  del_nsh_fwd_entry_i (lgm, lfe);
1367  break;
1368  }
1369  }));
1370  /* *INDENT-ON* */
1371 }
1372 
1373 static u8 *
1374 format_lisp_fwd_path (u8 * s, va_list ap)
1375 {
1376  lisp_fwd_path_t *lfp = va_arg (ap, lisp_fwd_path_t *);
1377 
1378  s = format (s, "weight:%d ", lfp->weight);
1379  s = format (s, "adj:[%U]\n",
1383 
1384  return (s);
1385 }
1386 
1388 {
1392 
1393 
1394 static u8 *
1396 {
1398  lisp_gpe_fwd_entry_t *lfe = va_arg (ap, lisp_gpe_fwd_entry_t *);
1400  va_arg (ap, lisp_gpe_fwd_entry_format_flag_t);
1401 
1402  s = format (s, "VNI:%d VRF:%d EID: %U -> %U [index:%d]",
1403  lfe->key->vni, lfe->eid_table_id,
1404  format_fid_address, &lfe->key->lcl,
1405  format_fid_address, &lfe->key->rmt,
1406  lfe - lgm->lisp_fwd_entry_pool);
1407 
1409  {
1410  s = format (s, "\n Negative - action:%U",
1412  }
1413  else
1414  {
1415  lisp_fwd_path_t *path;
1416 
1417  s = format (s, "\n via:");
1418  vec_foreach (path, lfe->paths)
1419  {
1420  s = format (s, "\n %U", format_lisp_fwd_path, path);
1421  }
1422  }
1423 
1425  {
1426  switch (fid_addr_type (&lfe->key->rmt))
1427  {
1428  case FID_ADDR_MAC:
1429  s = format (s, " fib-path-list:%d\n", lfe->l2.path_list_index);
1430  s = format (s, " dpo:%U\n", format_dpo_id, &lfe->l2.dpo, 0);
1431  break;
1432  case FID_ADDR_NSH:
1433  s = format (s, " fib-path-list:%d\n", lfe->nsh.path_list_index);
1434  s = format (s, " dpo:%U\n", format_dpo_id, &lfe->nsh.dpo, 0);
1435  break;
1436  case FID_ADDR_IP_PREF:
1437  break;
1438  }
1439  }
1440 
1441  return (s);
1442 }
1443 
1444 static clib_error_t *
1446  unformat_input_t * input, vlib_cli_command_t * cmd)
1447 {
1449  lisp_gpe_fwd_entry_t *lfe;
1450  index_t index;
1451  u32 vni = ~0;
1452 
1453  if (unformat (input, "vni %d", &vni))
1454  ;
1455  else if (unformat (input, "%d", &index))
1456  {
1457  if (!pool_is_free_index (lgm->lisp_fwd_entry_pool, index))
1458  {
1459  lfe = pool_elt_at_index (lgm->lisp_fwd_entry_pool, index);
1460 
1461  vlib_cli_output (vm, "[%d@] %U",
1462  index,
1465  }
1466  else
1467  {
1468  vlib_cli_output (vm, "entry %d invalid", index);
1469  }
1470 
1471  return (NULL);
1472  }
1473 
1474  /* *INDENT-OFF* */
1475  pool_foreach (lfe, lgm->lisp_fwd_entry_pool,
1476  ({
1477  if ((vni == ~0) ||
1478  (lfe->key->vni == vni))
1479  vlib_cli_output (vm, "%U", format_lisp_gpe_fwd_entry, lfe,
1480  LISP_GPE_FWD_ENTRY_FORMAT_NONE);
1481  }));
1482  /* *INDENT-ON* */
1483 
1484  return (NULL);
1485 }
1486 
1487 /* *INDENT-OFF* */
1489  .path = "show gpe entry",
1490  .short_help = "show gpe entry vni <vni> vrf <vrf> [leid <leid>] reid <reid>",
1491  .function = lisp_gpe_fwd_entry_show,
1492 };
1493 /* *INDENT-ON* */
1494 
1495 clib_error_t *
1497 {
1499  clib_error_t *error = NULL;
1500 
1502  return (error);
1503 
1504  l2_fib_init (lgm);
1505  nsh_fib_init (lgm);
1506 
1508 
1509  return (error);
1510 }
1511 
1512 u32 *
1514 {
1516  lisp_gpe_fwd_entry_t *lfe;
1517  u32 *vnis = 0;
1518 
1519  /* *INDENT-OFF* */
1520  pool_foreach (lfe, lgm->lisp_fwd_entry_pool,
1521  ({
1522  hash_set (vnis, lfe->key->vni, 0);
1523  }));
1524  /* *INDENT-ON* */
1525 
1526  return vnis;
1527 }
1528 
1531 {
1533  lisp_gpe_fwd_entry_t *lfe;
1534  lisp_api_gpe_fwd_entry_t *entries = 0, e;
1535 
1536  /* *INDENT-OFF* */
1537  pool_foreach (lfe, lgm->lisp_fwd_entry_pool,
1538  ({
1539  if (lfe->key->vni == vni)
1540  {
1541  memset (&e, 0, sizeof (e));
1542  e.dp_table = lfe->eid_table_id;
1543  e.vni = lfe->key->vni;
1544  if (lfe->type == LISP_GPE_FWD_ENTRY_TYPE_NEGATIVE)
1545  e.action = lfe->action;
1546  e.fwd_entry_index = lfe - lgm->lisp_fwd_entry_pool;
1547  memcpy (&e.reid, &lfe->key->rmt, sizeof (e.reid));
1548  memcpy (&e.leid, &lfe->key->lcl, sizeof (e.leid));
1549  vec_add1 (entries, e);
1550  }
1551  }));
1552  /* *INDENT-ON* */
1553 
1554  return entries;
1555 }
1556 
1557 int
1559  vlib_counter_t * c)
1560 {
1562  lisp_gpe_fwd_entry_t *lfe;
1563  lisp_gpe_fwd_entry_key_t unused;
1564 
1565  lfe = find_fwd_entry (lgm, a, &unused);
1566  if (NULL == lfe)
1567  return -1;
1568 
1570  return -1;
1571 
1572  if (~0 == lfe->dpoi_index)
1573  return -1;
1574 
1576  lfe->dpoi_index, c);
1577  return 0;
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  */
void dpo_unlock(dpo_id_t *dpo)
Release a reference counting lock on the DPO.
Definition: dpo.c:339
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:432
static void ip_src_dst_fib_del_route(u32 src_fib_index, const ip_prefix_t *src_prefix, u32 dst_fib_index, const ip_prefix_t *dst_prefix)
Del route to IP4 or IP6 SD FIB.
u16 lb_n_buckets
number of buckets in the load-balance.
Definition: load_balance.h:88
void dpo_stack_from_node(u32 child_node_index, dpo_id_t *dpo, const dpo_id_t *parent)
Stack one DPO object on another, and thus establish a child parent relationship.
Definition: dpo.c:471
fib_protocol_t fp_proto
protocol type
Definition: fib_types.h:169
vmrglw vmrglh hi
static void lisp_del_adj_stats(lisp_gpe_main_t *lgm, u32 fwd_entry_index, u32 ti)
#define vec_foreach_index(var, v)
Iterate over vector indices.
ip46_address_t frp_addr
The next-hop address.
Definition: fib_types.h:350
vlib_combined_counter_main_t lbm_to_counters
Definition: load_balance.h:46
static const fib_node_vft_t lisp_fwd_vft
Virtual function table to register with FIB for the LISP type.
sll srl srl sll sra u16x4 i
Definition: vector_sse2.h:337
static int add_l2_fwd_entry(lisp_gpe_main_t *lgm, vnet_lisp_gpe_add_del_fwd_entry_args_t *a)
Add LISP L2 forwarding entry.
An entry in a FIB table.
Definition: fib_entry.h:375
#define gid_address_type(_a)
Definition: lisp_types.h:261
static void l2_fib_init(lisp_gpe_main_t *lgm)
negative_fwd_actions_e action
When the type is negative.
void vlib_validate_combined_counter(vlib_combined_counter_main_t *cm, u32 index)
validate a combined counter
Definition: counter.c:89
void fib_path_list_child_remove(fib_node_index_t path_list_index, u32 si)
fib_node_index_t fib_table_lookup_exact_match(u32 fib_index, const fib_prefix_t *prefix)
Perfom an exact match in the non-forwarding table.
Definition: fib_table.c:95
a
Definition: bitmap.h:516
const dpo_id_t * lisp_cp_dpo_get(dpo_proto_t proto)
Definition: lisp_cp_dpo.c:26
u8 vnet_lisp_gpe_enable_disable_status(void)
Check if LISP-GPE is enabled.
Definition: lisp_gpe.c:184
A representation of a path as described by a route producer.
Definition: fib_types.h:336
u32 * vnet_lisp_gpe_get_fwd_entry_vnis(void)
u32 bd_id
bridge domain id
Definition: lisp_gpe.h:269
static fib_node_t * lisp_gpe_fwd_entry_get_fib_node(fib_node_index_t index)
Get a fib_node_t struct from the index of a LISP fwd entry.
dp_address_t lcl
void ip_prefix_to_fib_prefix(const ip_prefix_t *ip_prefix, fib_prefix_t *fib_prefix)
convert from a LISP to a FIB prefix
Definition: control.c:167
void vnet_lisp_gpe_fwd_entry_flush(void)
Flush all the forwrding entries.
fib_node_index_t fib_table_entry_update(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source, fib_entry_flag_t flags, fib_route_path_t *paths)
Update an entry to have a new set of paths.
Definition: fib_table.c:705
u8 priority
Priority.
#define NULL
Definition: clib.h:55
static u32 lisp_l2_fib_add_del_entry(u16 bd_index, u8 src_mac[6], u8 dst_mac[6], const dpo_id_t *dpo, u8 is_add)
Add/del L2 SD FIB entry.
enum fib_node_back_walk_rc_t_ fib_node_back_walk_rc_t
Return code from a back walk function.
LISP-GPE global state.
Definition: lisp_gpe.h:118
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
#define fid_addr_nsh(_a)
Definition: lisp_types.h:135
void dpo_copy(dpo_id_t *dst, const dpo_id_t *src)
atomic copy a data-plane object.
Definition: dpo.c:255
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:518
Combined counter to hold both packets and byte differences.
Definition: counter.h:139
u32 src_fib_index
The SRC-FIB index for created for anding source-route entries.
u32 eid_table_id
The VRF ID.
LISP-GPE definitions.
lisp_gpe_fwd_entry_key_t * key
The Entry&#39;s key: {lEID,rEID,vni}.
#define hash_set_mem(h, key, value)
Definition: hash.h:274
#define STRUCT_OFFSET_OF(t, f)
Definition: clib.h:62
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
void vnet_lisp_gpe_add_fwd_counters(vnet_lisp_gpe_add_del_fwd_entry_args_t *a, u32 fwd_entry_index)
dpo_proto_t frp_proto
The protocol of the address below.
Definition: fib_types.h:341
u32 lisp_gpe_tenant_find_or_create(u32 vni)
Find or create a tenant for the given VNI.
#define NSH_FIB_DEFAULT_HASH_MEMORY_SIZE
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:225
#define ip_prefix_version(_a)
Definition: lisp_types.h:72
u32 fib_path_list_child_add(fib_node_index_t path_list_index, fib_node_type_t child_type, fib_node_index_t child_index)
#define fid_addr_mac(_a)
Definition: lisp_types.h:134
enum fib_protocol_t_ fib_protocol_t
Protocol Type.
u32 tenant
The tenant the entry belongs to.
void fib_node_register_type(fib_node_type_t type, const fib_node_vft_t *vft)
fib_node_register_type
Definition: fib_node.c:58
static void delete_fib_entries(lisp_gpe_fwd_entry_t *lfe)
ip_prefix_t ippref
Definition: lisp_types.h:122
index_t load_balance_create(u32 n_buckets, dpo_proto_t lb_proto, flow_hash_config_t fhc)
Definition: load_balance.c:193
const dpo_id_t * drop_dpo_get(dpo_proto_t proto)
Definition: drop_dpo.c:25
static clib_error_t * lisp_gpe_fwd_entry_show(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static lisp_gpe_main_t * vnet_lisp_gpe_get_main()
Definition: lisp_gpe.h:183
const dpo_id_t * nsh_cp_lkup
Definition: lisp_gpe.h:158
static int add_ip_fwd_entry(lisp_gpe_main_t *lgm, vnet_lisp_gpe_add_del_fwd_entry_args_t *a)
Add/Delete LISP IP forwarding entry.
enum lisp_gpe_fwd_entry_format_flag_t_ lisp_gpe_fwd_entry_format_flag_t
static fib_node_index_t ip_src_fib_add_route(u32 src_fib_index, const ip_prefix_t *src_prefix, const lisp_fwd_path_t *paths)
Add route to IP4 or IP6 SRC FIB.
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:437
u32 frp_sw_if_index
The interface.
Definition: fib_types.h:369
int clib_bihash_add_del(clib_bihash *h, clib_bihash_kv *add_v, int is_add)
Add or delete a (key,value) pair from a bi-hash table.
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:111
u32 fwd_entry_index
Definition: lisp_gpe.h:95
clib_error_t * lisp_gpe_fwd_entry_init(vlib_main_t *vm)
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:390
u16 lb_n_buckets_minus_1
number of buckets in the load-balance - 1.
Definition: load_balance.h:93
static BVT(clib_bihash)
Definition: adj_nbr.c:26
static void make_mac_fib_key(BVT(clib_bihash_kv)*kv, u16 bd_index, u8 src_mac[6], u8 dst_mac[6])
vlib_combined_counter_main_t counters
Definition: lisp_gpe.h:164
LISP-GPE fwd entry key.
u8 is_add
Definition: lisp_gpe.h:233
void fib_path_list_contribute_forwarding(fib_node_index_t path_list_index, fib_forward_chain_type_t fct, dpo_id_t *dpo)
u8 * format_fib_prefix(u8 *s, va_list *args)
Definition: fib_types.c:151
static void lisp_gpe_fwd_entry_mk_paths(lisp_gpe_fwd_entry_t *lfe, vnet_lisp_gpe_add_del_fwd_entry_args_t *a)
void lisp_gpe_adjacency_unlock(index_t lai)
lisp_gpe_fwd_entry_type_t type
The forwarding entry type.
void vnet_lisp_gpe_del_fwd_counters(vnet_lisp_gpe_add_del_fwd_entry_args_t *a, u32 fwd_entry_index)
Aggregrate type for a prefix.
Definition: fib_types.h:160
uword * lisp_gpe_fwd_entries
DB of all forwarding entries.
Definition: lisp_gpe.h:124
unsigned long u64
Definition: types.h:89
#define hash_get_pair(h, key)
Definition: hash.h:251
Contribute an object that is to be used to forward Ethernet packets.
Definition: fib_types.h:109
enum dpo_proto_t_ dpo_proto_t
Data path protocol.
#define vlib_call_init_function(vm, x)
Definition: init.h:162
dp_address_t rmt
uword * bd_index_by_bd_id
Definition: l2_bd.h:27
Definition: lisp_gpe.h:226
Common utility functions for IPv4, IPv6 and L2 LISP-GPE adjacencys.
Definition: fib_entry.h:228
void gid_to_dp_address(gid_address_t *g, dp_address_t *d)
Definition: lisp_types.c:606
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
Definition: dpo.h:150
#define hash_get(h, key)
Definition: hash.h:248
Definition: fib_entry.h:232
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:458
static void vlib_zero_combined_counter(vlib_combined_counter_main_t *cm, u32 index)
Clear a combined counter Clears the set of per-thread counters.
Definition: counter.h:276
fib_node_index_t fib_path_list_create(fib_path_list_flags_t flags, const fib_route_path_t *rpaths)
#define hash_unset_mem(h, key)
Definition: hash.h:280
static int lisp_gpe_fwd_entry_path_sort(void *a1, void *a2)
u32 table_id
table (vrf) id
Definition: lisp_gpe.h:266
u8 * format_negative_mapping_action(u8 *s, va_list *args)
Definition: lisp_types.c:438
static u32 lisp_nsh_fib_add_del_entry(u32 spi_si_host_order, u32 lfei, u8 is_add)
Add/del NSH FIB entry.
index_t dpoi_index
used for getting load balance statistics
static int del_ip_fwd_entry(lisp_gpe_main_t *lgm, vnet_lisp_gpe_add_del_fwd_entry_args_t *a)
Add/Delete LISP IP forwarding entry.
static const dpo_id_t * load_balance_get_bucket_i(const load_balance_t *lb, u32 bucket)
Definition: load_balance.h:202
u32 vlib_combined_counter_n_counters(const vlib_combined_counter_main_t *cm)
The number of counters (not the number of per-thread counters)
Definition: counter.c:100
struct _unformat_input_t unformat_input_t
static void del_l2_fwd_entry_i(lisp_gpe_main_t *lgm, lisp_gpe_fwd_entry_t *lfe)
load-balancing over a choice of [un]equal cost paths
Definition: dpo.h:100
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:270
int vnet_lisp_flush_stats(void)
The FIB DPO provieds;.
Definition: load_balance.h:84
u32 fib_table_get_num_entries(u32 fib_index, fib_protocol_t proto, fib_source_t source)
Return the number of entries in the FIB added by a given source.
Definition: fib_table.c:1218
#define vec_del1(v, i)
Delete the element at index I.
Definition: vec.h:801
u32 sw_if_index
The SW IF index of the sub-interface this adjacency uses.
const lisp_gpe_adjacency_t * lisp_gpe_adjacency_get(index_t lai)
u8 * dummy_stats_pool
Definition: lisp_gpe.h:162
void lookup_dpo_add_or_lock_w_fib_index(fib_node_index_t fib_index, dpo_proto_t proto, lookup_cast_t cast, lookup_input_t input, lookup_table_t table_config, dpo_id_t *dpo)
Definition: lookup_dpo.c:127
load_balance_main_t load_balance_main
The one instance of load-balance main.
Definition: load_balance.c:55
static u32 ip_dst_fib_add_route(u32 dst_fib_index, const ip_prefix_t *dst_prefix)
Add route to IP4 or IP6 Destination FIB.
An node in the FIB graph.
Definition: fib_node.h:279
void clib_bihash_init(clib_bihash *h, char *name, u32 nbuckets, uword memory_size)
initialize a bounded index extensible hash table
void fib_table_unlock(u32 fib_index, fib_protocol_t proto, fib_source_t source)
Take a reference counting lock on the table.
Definition: fib_table.c:1177
struct lisp_gpe_fwd_entry_t_::@223::@230 nsh
Fields relevant to an NSH entry.
void ip_address_to_46(const ip_address_t *addr, ip46_address_t *a, fib_protocol_t *proto)
Definition: lisp_types.c:915
Definition: lisp_gpe.h:282
#define gid_address_ippref(_a)
Definition: lisp_types.h:262
#define L2_FIB_DEFAULT_HASH_MEMORY_SIZE
u8 is_negative
type of mapping
Definition: lisp_gpe.h:236
index_t lisp_gpe_adjacency_find_or_create_and_lock(const locator_pair_t *pair, u32 overlay_table_id, u32 vni)
u32 vni
VNI/tenant id in HOST byte order.
Definition: lisp_gpe.h:260
int fib_entry_is_sourced(fib_node_index_t fib_entry_index, fib_source_t source)
Definition: fib_entry_src.c:99
u32 fwd_entry_index
forwarding entry index of
Definition: lisp_gpe.h:229
svmdb_client_t * c
static void vlib_get_combined_counter(const vlib_combined_counter_main_t *cm, u32 index, vlib_counter_t *result)
Get the value of a combined counter, never called in the speed path Scrapes the entire set of per-thr...
Definition: counter.h:250
vlib_main_t * vm
Definition: buffer.c:283
Contribute an object that is to be used to forward NSH packets.
Definition: fib_types.h:115
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:336
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:835
vnet_main_t * vnet_main
Definition: lisp_gpe.h:172
static void lisp_gpe_fwd_entry_fib_node_last_lock_gone(fib_node_t *node)
An indication from the graph that the last lock has gone.
#define clib_warning(format, args...)
Definition: error.h:59
fib_node_get_t fnv_get
Definition: fib_node.h:267
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:28
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:267
void dpo_set(dpo_id_t *dpo, dpo_type_t type, dpo_proto_t proto, index_t index)
Set/create a DPO ID The DPO will be locked.
Definition: dpo.c:179
lisp_gpe_main_t lisp_gpe_main
LISP-GPE global state.
Definition: lisp_gpe.c:30
static int del_l2_fwd_entry(lisp_gpe_main_t *lgm, vnet_lisp_gpe_add_del_fwd_entry_args_t *a)
Delete LISP L2 forwarding entry.
fib_entry_t * fib_entry_get(fib_node_index_t index)
Definition: fib_entry.c:44
#define fid_addr_ippref(_a)
Definition: lisp_types.h:131
Context passed between object during a back walk.
Definition: fib_node.h:192
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:154
static int add_nsh_fwd_entry(lisp_gpe_main_t *lgm, vnet_lisp_gpe_add_del_fwd_entry_args_t *a)
Add LISP NSH forwarding entry.
static lisp_gpe_fwd_entry_t * lisp_gpe_fwd_entry_from_fib_node(fib_node_t *node)
conver from the embedded fib_node_t struct to the LSIP entry
int vnet_lisp_gpe_add_del_fwd_entry(vnet_lisp_gpe_add_del_fwd_entry_args_t *a, u32 *hw_if_indexp)
Forwarding entry create/remove dispatcher.
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:290
#define ASSERT(truth)
#define fid_addr_type(_a)
Definition: lisp_types.h:136
const void * fib_entry_get_source_data(fib_node_index_t fib_entry_index, fib_source_t source)
unsigned int u32
Definition: types.h:88
static void del_nsh_fwd_entry_i(lisp_gpe_main_t *lgm, lisp_gpe_fwd_entry_t *lfe)
int clib_bihash_search(clib_bihash *h, clib_bihash_kv *search_v, clib_bihash_kv *return_v)
Search a bi-hash table.
long ctx[MAX_CONNS]
Definition: main.c:95
static load_balance_t * load_balance_get(index_t lbi)
Definition: load_balance.h:193
DROP
Definition: error.def:41
A path on which to forward lisp traffic.
u8 weight
[UE]CMP weigt for the path
static void clib_mem_free(void *p)
Definition: mem.h:179
uword * hw_if_index_by_dp_table
Lookup lisp-gpe interfaces by dp table (eg.
Definition: lisp_gpe.h:84
u32 fib_table_find_or_create_and_lock(fib_protocol_t proto, u32 table_id, fib_source_t src)
Get the index of the FIB for a Table-ID.
Definition: fib_table.c:1084
static fib_node_index_t ip_src_fib_add_route_w_dpo(u32 src_fib_index, const ip_prefix_t *src_prefix, const dpo_id_t *src_dpo)
Add route to IP4 or IP6 SRC FIB.
static lisp_gpe_fwd_entry_t * find_fwd_entry(lisp_gpe_main_t *lgm, vnet_lisp_gpe_add_del_fwd_entry_args_t *a, lisp_gpe_fwd_entry_key_t *key)
u8 is_src_dst
Definition: lisp_gpe.h:231
static u64 mac_to_u64(u8 *m)
Definition: load_balance.c:901
dpo_proto_t fib_proto_to_dpo(fib_protocol_t fib_proto)
Definition: fib_types.c:211
static index_t create_fib_entries(lisp_gpe_fwd_entry_t *lfe)
gid_address_t rmt_eid
remote eid
Definition: lisp_gpe.h:245
void load_balance_set_bucket(index_t lbi, u32 bucket, const dpo_id_t *next)
Definition: load_balance.c:210
static void * clib_mem_alloc(uword size)
Definition: mem.h:112
u8 * format_dpo_id(u8 *s, va_list *args)
Format a DPO_id_t oject
Definition: dpo.c:143
dpo_id_t fe_lb
The load-balance used for forwarding.
Definition: fib_entry.h:401
u64 uword
Definition: types.h:112
static void gpe_native_fwd_add_del_lfe(lisp_gpe_fwd_entry_t *lfe, u8 is_add)
static void lisp_gpe_nsh_update_fwding(lisp_gpe_fwd_entry_t *lfe)
Construct and insert the forwarding information used by an NSH entry.
negative_fwd_actions_e action
action for negative mappings
Definition: lisp_gpe.h:239
A LISP GPE Adjacency.
unsigned short u16
Definition: types.h:57
static vlib_cli_command_t lisp_gpe_fwd_entry_show_command
(constructor) VLIB_CLI_COMMAND (lisp_gpe_fwd_entry_show_command)
u32 eid_fib_index
The FIB index for the overlay, i.e.
index_t dpoi_index
the index of objects of that type
Definition: dpo.h:166
#define FIB_NODE_INDEX_INVALID
Definition: fib_types.h:29
struct lisp_gpe_fwd_entry_t_ * lisp_fwd_entry_pool
A Pool of all LISP forwarding entries.
Definition: lisp_gpe.h:129
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
unsigned char u8
Definition: types.h:56
dpo_id_t l2_lb_cp_lkup
Load-balance for a miss in the table.
Definition: lisp_gpe.h:149
static u8 * format_lisp_gpe_fwd_entry(u8 *s, va_list ap)
u32 tunnel_index
The index of the LISP GPE tunnel that provides the transport in the underlay.
static uword max_log2(uword x)
Definition: clib.h:228
u32 dp_table
generic access
Definition: lisp_gpe.h:272
#define vec_sort_with_function(vec, f)
Sort a vector using the supplied element comparison function.
Definition: vec.h:956
static void del_ip_fwd_entry_i(lisp_gpe_main_t *lgm, lisp_gpe_fwd_entry_t *lfe)
static fib_route_path_t * lisp_gpe_mk_fib_paths(const lisp_fwd_path_t *paths)
locator_pair_t * locator_pairs
vector of locator pairs
Definition: lisp_gpe.h:248
#define DPO_INVALID
An initialiser for DPOs declared on the stack.
Definition: dpo.h:177
A collection of combined counters.
Definition: counter.h:180
Definition: lisp_types.h:37
lisp_fwd_path_t * paths
When the type is &#39;normal&#39; The RLOC pair that form the route&#39;s paths.
#define hash_get_mem(h, key)
Definition: hash.h:268
static void nsh_fib_init(lisp_gpe_main_t *lgm)
A FIB graph nodes virtual function table.
Definition: fib_node.h:266
u8 * format_lisp_gpe_adjacency(u8 *s, va_list *args)
static u8 * format_lisp_fwd_path(u8 *s, va_list ap)
index_t lisp_l2_fib_lookup(lisp_gpe_main_t *lgm, u16 bd_index, u8 src_mac[6], u8 dst_mac[6])
Lookup L2 SD FIB entry.
clib_error_t * lisp_cp_dpo_module_init(vlib_main_t *vm)
Definition: lisp_cp_dpo.c:96
fib_route_path_t * native_fwd_rpath[2]
Native fwd data structures.
Definition: lisp_gpe.h:167
int vnet_lisp_gpe_get_fwd_stats(vnet_lisp_gpe_add_del_fwd_entry_args_t *a, vlib_counter_t *c)
LISP.
Definition: fib_entry.h:70
static fib_node_back_walk_rc_t lisp_gpe_fib_node_back_walk(fib_node_t *node, fib_node_back_walk_ctx_t *ctx)
Function invoked during a backwalk of the FIB graph.
void dpo_reset(dpo_id_t *dpo)
reset a DPO ID The DPO will be unlocked.
Definition: dpo.c:225
#define vec_foreach(var, vec)
Vector iterator.
#define NSH_FIB_DEFAULT_HASH_NUM_BUCKETS
uword * lisp_stats_index_by_key
Definition: lisp_gpe.h:163
static void lisp_gpe_l2_update_fwding(lisp_gpe_fwd_entry_t *lfe)
Construct and insert the forwarding information used by an L2 entry.
static int del_nsh_fwd_entry(lisp_gpe_main_t *lgm, vnet_lisp_gpe_add_del_fwd_entry_args_t *a)
Delete LISP NSH forwarding entry.
u32 flags
Definition: vhost-user.h:77
Definition: lisp_types.h:38
bd_main_t bd_main
Definition: l2_bd.c:44
u32 vni
u8 frp_weight
[un]equal cost path weight
Definition: fib_types.h:383
fib_node_t node
This object joins the FIB control plane graph to receive updates to for changes to the graph...
u8 * format_fid_address(u8 *s, va_list *args)
Definition: lisp_types.c:244
gid_address_t lcl_eid
local eid
Definition: lisp_gpe.h:242
u32 fib_table_create_and_lock(fib_protocol_t proto, fib_source_t src, const char *const fmt,...)
Create a new table with no table ID.
Definition: fib_table.c:1103
tunnel_lookup_t nsh_ifaces
Definition: lisp_gpe.h:156
u32 * native_fwd_lfes[2]
Definition: lisp_gpe.h:168
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:680
#define L2_FIB_DEFAULT_HASH_NUM_BUCKETS
void fib_entry_set_source_data(fib_node_index_t fib_entry_index, fib_source_t source, const void *data)
const dpo_id_t * lisp_nsh_fib_lookup(lisp_gpe_main_t *lgm, u32 spi_si_net_order)
Lookup NSH SD FIB entry.
lisp_gpe_fwd_entry_format_flag_t_
ip_address_t remote_rloc
remote RLOC.
uword key
Definition: hash.h:161
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:972
lisp_api_gpe_fwd_entry_t * vnet_lisp_gpe_fwd_entries_get_by_vni(u32 vni)
u8 is_src_dst
Follows src/dst or dst only forwarding policy.
struct lisp_gpe_fwd_entry_t_::@223::@229 l2
Fields relevant to an L2 entry.
index_t lisp_adj
The adjacency constructed for the locator pair.
A LISP Forwarding Entry.