A Protocol Independent Hierarchical FIB (VPP-352)
[vpp.git] / vnet / vnet / fib / fib_entry.c
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
16 #include <vlib/vlib.h>
17 #include <vnet/ip/format.h>
18 #include <vnet/ip/lookup.h>
19 #include <vnet/adj/adj.h>
20 #include <vnet/dpo/load_balance.h>
21 #include <vnet/dpo/drop_dpo.h>
22
23 #include <vnet/fib/fib_entry.h>
24 #include <vnet/fib/fib_walk.h>
25 #include <vnet/fib/fib_entry_src.h>
26 #include <vnet/fib/fib_entry_cover.h>
27 #include <vnet/fib/fib_table.h>
28 #include <vnet/fib/fib_internal.h>
29 #include <vnet/fib/fib_attached_export.h>
30 #include <vnet/fib/fib_path_ext.h>
31
32 /*
33  * Array of strings/names for the FIB sources
34  */
35 static const char *fib_source_names[] = FIB_SOURCES;
36 static const char *fib_attribute_names[] = FIB_ENTRY_ATTRIBUTES;
37
38 /*
39  * Pool for all fib_entries
40  */
41 static fib_entry_t *fib_entry_pool;
42
43 fib_entry_t *
44 fib_entry_get (fib_node_index_t index)
45 {
46     return (pool_elt_at_index(fib_entry_pool, index));
47 }
48
49 static fib_node_t *
50 fib_entry_get_node (fib_node_index_t index)
51 {
52     return ((fib_node_t*)fib_entry_get(index));
53 }
54
55 fib_node_index_t
56 fib_entry_get_index (const fib_entry_t * fib_entry)
57 {
58     return (fib_entry - fib_entry_pool);
59 }
60
61 static fib_protocol_t
62 fib_entry_get_proto (const fib_entry_t * fib_entry)
63 {
64     return (fib_entry->fe_prefix.fp_proto);
65 }
66
67 /**
68  * @brief Turn the chain type requested by the client into the one they
69  * really wanted
70  */
71 static fib_forward_chain_type_t
72 fib_entry_chain_type_fixup (const fib_entry_t *entry,
73                             fib_forward_chain_type_t fct)
74 {
75     if (FIB_FORW_CHAIN_TYPE_MPLS_EOS == fct)
76     {
77         /*
78          * The EOS chain is a tricky since one cannot know the adjacency
79          * to link to without knowing what the packets payload protocol
80          * will be once the label is popped.
81          */
82         fib_forward_chain_type_t dfct;
83
84         dfct = fib_entry_get_default_chain_type(entry);
85
86         if (FIB_FORW_CHAIN_TYPE_MPLS_EOS == dfct)
87         {
88             /*
89              * If the entry being asked is a eos-MPLS label entry,
90              * then use the payload-protocol field, that we stashed there
91              * for just this purpose
92              */
93             return (fib_proto_to_forw_chain_type(entry->fe_prefix.fp_payload_proto));
94         }
95         /*
96          * else give them what this entry would be by default. i.e. if it's a v6
97          * entry, then the label its local labelled should be carrying v6 traffic.
98          * If it's a non-EOS label entry, then there are more labels and we want
99          * a non-eos chain.
100          */
101         return (dfct);
102     }
103
104     return (fct);
105 }
106
107 fib_forward_chain_type_t
108 fib_entry_get_default_chain_type (const fib_entry_t *fib_entry)
109 {
110     switch (fib_entry->fe_prefix.fp_proto)
111     {
112     case FIB_PROTOCOL_IP4:
113         return (FIB_FORW_CHAIN_TYPE_UNICAST_IP4);
114     case FIB_PROTOCOL_IP6:
115         return (FIB_FORW_CHAIN_TYPE_UNICAST_IP6);
116     case FIB_PROTOCOL_MPLS:
117         if (MPLS_EOS == fib_entry->fe_prefix.fp_eos)
118             /*
119              * If the entry being asked is a eos-MPLS label entry,
120              * then use the payload-protocol field, that we stashed there
121              * for just this purpose
122              */
123             return (fib_proto_to_forw_chain_type(fib_entry->fe_prefix.fp_payload_proto));
124         else
125             return (FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS);
126     }
127
128     return (FIB_FORW_CHAIN_TYPE_UNICAST_IP4);
129 }
130
131 u8 *
132 format_fib_entry (u8 * s, va_list * args)
133 {
134     fib_forward_chain_type_t fct;
135     fib_entry_attribute_t attr;
136     fib_path_ext_t *path_ext;
137     fib_entry_t *fib_entry;
138     fib_entry_src_t *src;
139     fib_node_index_t fei;
140     fib_source_t source;
141     u32 n_covered;
142     int level;
143
144     fei = va_arg (*args, fib_node_index_t);
145     level = va_arg (*args, int);
146     fib_entry = fib_entry_get(fei);
147
148     s = format (s, "%U", format_fib_prefix, &fib_entry->fe_prefix);
149
150     if (level >= FIB_ENTRY_FORMAT_DETAIL)
151     {
152         s = format (s, " fib:%d", fib_entry->fe_fib_index);
153         s = format (s, " index:%d", fib_entry_get_index(fib_entry));
154         s = format (s, " locks:%d", fib_entry->fe_node.fn_locks);
155
156         FOR_EACH_SRC_ADDED(fib_entry, src, source,
157         ({
158             s = format (s, "\n  src:%s ",
159                         fib_source_names[source]);
160             s = fib_entry_src_format(fib_entry, source, s);
161             s = format (s, " refs:%d ", src->fes_ref_count);
162             if (FIB_ENTRY_FLAG_NONE != src->fes_entry_flags) {
163                 s = format(s, "flags:");
164                 FOR_EACH_FIB_ATTRIBUTE(attr) {
165                     if ((1<<attr) & src->fes_entry_flags) {
166                         s = format (s, "%s,", fib_attribute_names[attr]);
167                     }
168                 }
169             }
170             s = format (s, "\n");
171             if (FIB_NODE_INDEX_INVALID != src->fes_pl)
172             {
173                 s = fib_path_list_format(src->fes_pl, s);
174             }
175             if (NULL != src->fes_path_exts)
176             {
177                 s = format(s, "    Extensions:");
178                 vec_foreach(path_ext, src->fes_path_exts)
179                 {
180                     s = format(s, "\n     %U", format_fib_path_ext, path_ext);
181                 }
182             }
183         }));
184     
185         n_covered = fib_entry_cover_get_size(fib_entry);
186         if (n_covered > 0) {
187             s = format(s, "\n tracking %d covered: ", n_covered);
188             s = fib_entry_cover_list_format(fib_entry, s);
189         }
190         s = fib_ae_import_format(fib_entry->fe_import, s);
191         s = fib_ae_export_format(fib_entry->fe_export, s);
192
193         s = format (s, "\n forwarding: ");
194     }
195     else
196     {
197         s = format (s, "\n");
198     }
199
200     fct = fib_entry_get_default_chain_type(fib_entry);
201
202     if (!dpo_id_is_valid(&fib_entry->fe_lb[fct]))
203     {
204         s = format (s, "  UNRESOLVED\n");
205         return (s);
206     }
207     else
208     {
209         if (level >= FIB_ENTRY_FORMAT_DETAIL2)
210         {
211
212             FOR_EACH_FIB_FORW_CHAIN(fct)
213             {
214                 s = format(s, "  %U-chain\n  %U",
215                            format_fib_forw_chain_type, fct,
216                            format_dpo_id,
217                            &fib_entry->fe_lb[fct],
218                            2);
219                 s = format(s, "\n");
220             }
221         }
222         else
223         {
224             s = format(s, "  %U-chain\n  %U",
225                        format_fib_forw_chain_type, fct,
226                        format_dpo_id,
227                        &fib_entry->fe_lb[fct],
228                        2);
229             s = format(s, "\n");
230         }
231     }
232
233     if (level >= FIB_ENTRY_FORMAT_DETAIL2)
234     {
235         s = format(s, "\nchildren:");
236         s = fib_node_children_format(fib_entry->fe_node.fn_children, s);
237     }
238
239     /* adj = adj_get(fib_entry->fe_prefix.fp_proto, fib_entry->fe_adj_index); */
240
241     /* ip_multipath_next_hop_t * nhs, tmp_nhs[1]; */
242     /* u32 i, j, n_left, n_nhs; */
243     /* vlib_counter_t c, sum; */
244     /* ip_lookup_main_t *lm = fib_get_lookup_main(fib_entry->fe_prefix.fp_proto); */
245
246     /* if (adj->n_adj == 1) */
247     /* { */
248     /*  nhs = &tmp_nhs[0]; */
249     /*  nhs[0].next_hop_adj_index = ~0; /\* not used *\/ */
250     /*  nhs[0].weight = 1; */
251     /*  n_nhs = 1; */
252     /* } */
253     /* else */
254     /* { */
255     /*  ip_multipath_adjacency_t * madj; */
256     /*  madj = vec_elt_at_index (lm->multipath_adjacencies, adj->heap_handle); */
257     /*  nhs = heap_elt_at_index (lm->next_hop_heap, madj->normalized_next_hops.heap_offset); */
258     /*  n_nhs = madj->normalized_next_hops.count; */
259     /* } */
260
261     /* n_left = nhs[0].weight; */
262     /* vlib_counter_zero (&sum); */
263     /* for (i = j = 0; i < adj->n_adj; i++) */
264     /* { */
265     /*  n_left -= 1; */
266     /*  vlib_get_combined_counter(&lm->adjacency_counters,  */
267     /*                            fib_entry->fe_adj_index + i, */
268     /*                            &c); */
269     /*  /\* if (clear) *\/ */
270     /*  /\*     vlib_zero_combined_counter (&lm->adjacency_counters,  *\/ */
271     /*  /\*                             fib_entry->fe_adj_index + i); *\/ */
272
273     /*  vlib_counter_add (&sum, &c); */
274     /*  if (n_left == 0) */
275     /*  { */
276     /*      s = format (s, "%16Ld%16Ld ", sum.packets, sum.bytes); */
277     /*      s = format (s, "weight %d, index %d", */
278     /*                    nhs[j].weight, fib_entry->fe_adj_index + i); */
279
280     /*      if (adj->n_adj > 1) */
281     /*          s = format (s, ", multipath"); */
282
283     /*      s = format (s, "\n%U", */
284     /*                  format_ip_adjacency, */
285     /*                  vnet_get_main(), lm, fib_entry->fe_adj_index + i); */
286
287     /*      //   vlib_cli_output (vm, "%v", msg); */
288     /*      //vec_free (msg); */
289     /*  } */
290     /*  else */
291     /*  { */
292     /*      j++; */
293     /*      if (j < n_nhs) */
294     /*      { */
295     /*          n_left = nhs[j].weight; */
296     /*          vlib_counter_zero (&sum); */
297     /*      } */
298     /*  } */
299     /* } */
300
301     return (s);
302 }
303
304 static fib_entry_t*
305 fib_entry_from_fib_node (fib_node_t *node)
306 {
307 #if CLIB_DEBUG > 0
308     ASSERT(FIB_NODE_TYPE_ENTRY == node->fn_type);
309 #endif
310     return ((fib_entry_t*)node);
311 }
312
313 static void
314 fib_entry_last_lock_gone (fib_node_t *node)
315 {
316     fib_forward_chain_type_t fct;
317     fib_entry_t *fib_entry;
318
319     fib_entry = fib_entry_from_fib_node(node);
320
321     FOR_EACH_FIB_FORW_CHAIN(fct)
322     {
323         dpo_reset(&fib_entry->fe_lb[fct]);
324     }
325
326     FIB_ENTRY_DBG(fib_entry, "last-lock");
327
328     fib_node_deinit(&fib_entry->fe_node);
329     // FIXME -RR Backwalk
330     pool_put(fib_entry_pool, fib_entry);
331 }
332
333 static fib_entry_src_t*
334 fib_entry_get_best_src_i (const fib_entry_t *fib_entry)
335 {
336     fib_entry_src_t *bsrc;
337
338     /*
339      * the enum of sources is deliberately arranged in priority order
340      */
341     if (0 == vec_len(fib_entry->fe_srcs))
342     {
343         bsrc = NULL;
344     }
345     else
346     {
347         bsrc = vec_elt_at_index(fib_entry->fe_srcs, 0);
348     }
349
350     return (bsrc);
351 }
352
353 static fib_source_t
354 fib_entry_src_get_source (const fib_entry_src_t *esrc)
355 {
356     if (NULL != esrc)
357     {
358         return (esrc->fes_src);
359     }
360     return (FIB_SOURCE_MAX);
361 }
362
363 static fib_entry_flag_t
364 fib_entry_src_get_flags (const fib_entry_src_t *esrc)
365 {
366     if (NULL != esrc)
367     {
368         return (esrc->fes_entry_flags);
369     }
370     return (FIB_ENTRY_FLAG_NONE);
371 }
372
373 fib_entry_flag_t
374 fib_entry_get_flags (fib_node_index_t fib_entry_index)
375 {
376     return (fib_entry_get_flags_i(fib_entry_get(fib_entry_index)));
377 }
378
379 /*
380  * fib_entry_back_walk_notify
381  *
382  * A back walk has reach this entry.
383  */
384 static fib_node_back_walk_rc_t
385 fib_entry_back_walk_notify (fib_node_t *node,
386                             fib_node_back_walk_ctx_t *ctx)
387 {
388     fib_entry_t *fib_entry;
389
390     fib_entry = fib_entry_from_fib_node(node);
391
392     if (FIB_NODE_BW_REASON_FLAG_EVALUATE & ctx->fnbw_reason        ||
393         FIB_NODE_BW_REASON_FLAG_ADJ_UPDATE & ctx->fnbw_reason      ||
394         FIB_NODE_BW_REASON_FLAG_INTERFACE_UP & ctx->fnbw_reason    ||
395         FIB_NODE_BW_REASON_FLAG_INTERFACE_DOWN & ctx->fnbw_reason  ||
396         FIB_NODE_BW_REASON_FLAG_INTERFACE_DELETE & ctx->fnbw_reason)
397     {
398         fib_entry_src_action_reactivate(fib_entry,
399                                         fib_entry_get_best_source(
400                                             fib_entry_get_index(fib_entry)));
401     }
402
403     if (FIB_NODE_BW_REASON_FLAG_ADJ_UPDATE & ctx->fnbw_reason)
404     {
405         /*
406          * ADJ updates (complete<->incomplete) do not need to propagate to
407          * recursive entries.
408          * The only reason its needed as far back as here, is that the adj
409          * and the incomplete adj are a different DPO type, so the LBs need
410          * to re-stack.
411          */
412         return (FIB_NODE_BACK_WALK_CONTINUE);
413     }
414     else
415     {
416         /*
417          * all other walk types can be reclassifed to a re-evaluate to
418          * all recursive dependents.
419          * By reclassifying we ensure that should any of these walk types meet
420          * they can be merged.
421          */
422         ctx->fnbw_reason = FIB_NODE_BW_REASON_FLAG_EVALUATE;
423
424         /*
425          * propagate the backwalk further if we haven't already reached the
426          * maximum depth.
427          */
428         fib_walk_sync(FIB_NODE_TYPE_ENTRY,
429                       fib_entry_get_index(fib_entry),
430                       ctx);
431     }
432
433     return (FIB_NODE_BACK_WALK_CONTINUE);
434 }
435
436 /*
437  * The FIB path-list's graph node virtual function table
438  */
439 static const fib_node_vft_t fib_entry_vft = {
440     .fnv_get = fib_entry_get_node,
441     .fnv_last_lock = fib_entry_last_lock_gone,
442     .fnv_back_walk = fib_entry_back_walk_notify,
443 };
444
445 /*
446  * fib_entry_contribute_forwarding
447  *
448  * Get an lock the forwarding information (DPO) contributed by the FIB entry.
449  */
450 void
451 fib_entry_contribute_forwarding (fib_node_index_t fib_entry_index,
452                                  fib_forward_chain_type_t type,
453                                  dpo_id_t *dpo)
454 {
455     fib_entry_t *fib_entry;
456
457     fib_entry = fib_entry_get(fib_entry_index);
458
459     /*
460      * these are not the droids you are looking for...
461      */
462     type = fib_entry_chain_type_fixup(fib_entry, type);
463
464     if (!dpo_id_is_valid(&fib_entry->fe_lb[type]))
465     {
466         /*
467          * on-demand create eos/non-eos.
468          * There is no on-demand delete because:
469          *   - memory versus complexity & reliability:
470          *      leaving unrequired [n]eos LB arounds wastes memory, cleaning
471          *      then up on the right trigger is more code. i favour the latter.
472          */
473         fib_entry_src_mk_lb(fib_entry,
474                             fib_entry_get_best_src_i(fib_entry),
475                             type,
476                             &fib_entry->fe_lb[type]);
477     }
478
479     dpo_copy(dpo, &fib_entry->fe_lb[type]);
480 }
481
482 const dpo_id_t *
483 fib_entry_contribute_ip_forwarding (fib_node_index_t fib_entry_index)
484 {
485     fib_entry_t *fib_entry;
486
487     fib_entry = fib_entry_get(fib_entry_index);
488
489     return (&fib_entry->fe_lb[fib_entry_get_default_chain_type(fib_entry)]);
490 }
491
492 adj_index_t
493 fib_entry_get_adj (fib_node_index_t fib_entry_index)
494 {
495     const dpo_id_t *dpo;
496
497     dpo = fib_entry_contribute_ip_forwarding(fib_entry_index);
498     dpo = load_balance_get_bucket(dpo->dpoi_index, 0);
499
500     if (dpo_is_adj(dpo))
501     {
502         return (dpo->dpoi_index);
503     }
504     return (ADJ_INDEX_INVALID);
505 }
506
507 fib_node_index_t
508 fib_entry_get_path_list (fib_node_index_t fib_entry_index)
509 {
510     fib_entry_t *fib_entry;
511
512     fib_entry = fib_entry_get(fib_entry_index);
513
514     return (fib_entry->fe_parent);
515 }
516
517 u32
518 fib_entry_get_fib_table_id(fib_node_index_t fib_entry_index)
519 {
520     
521
522     return (0);
523 }
524
525 u32
526 fib_entry_child_add (fib_node_index_t fib_entry_index,
527                      fib_node_type_t child_type,
528                      fib_node_index_t child_index)
529 {
530     return (fib_node_child_add(FIB_NODE_TYPE_ENTRY,
531                                fib_entry_index,
532                                child_type,
533                                child_index));
534 };
535
536 void
537 fib_entry_child_remove (fib_node_index_t fib_entry_index,
538                         u32 sibling_index)
539 {
540     fib_node_child_remove(FIB_NODE_TYPE_ENTRY,
541                           fib_entry_index,
542                           sibling_index);
543 }
544
545 static fib_entry_t *
546 fib_entry_alloc (u32 fib_index,
547                  const fib_prefix_t *prefix,
548                  fib_node_index_t *fib_entry_index)
549 {
550     fib_forward_chain_type_t fct;
551     fib_entry_t *fib_entry;
552
553     pool_get(fib_entry_pool, fib_entry);
554     memset(fib_entry, 0, sizeof(*fib_entry));
555
556     fib_node_init(&fib_entry->fe_node,
557                   FIB_NODE_TYPE_ENTRY);
558
559     fib_entry->fe_fib_index = fib_index;
560     fib_entry->fe_prefix = *prefix;
561     if (FIB_PROTOCOL_MPLS == fib_entry->fe_prefix.fp_proto)
562     {
563         fib_entry->fe_prefix.fp_len = 21;
564         ASSERT(DPO_PROTO_NONE != fib_entry->fe_prefix.fp_payload_proto);
565     }
566
567     fib_entry->fe_export = FIB_NODE_INDEX_INVALID;
568     fib_entry->fe_import = FIB_NODE_INDEX_INVALID;
569     fib_entry->fe_covered = FIB_NODE_INDEX_INVALID;
570     FOR_EACH_FIB_FORW_CHAIN(fct)
571     {
572         dpo_reset(&fib_entry->fe_lb[fct]);
573     }
574
575     *fib_entry_index = fib_entry_get_index(fib_entry);
576
577     FIB_ENTRY_DBG(fib_entry, "alloc");
578
579     return (fib_entry);
580 }
581
582 static void
583 fib_entry_post_flag_update_actions (fib_entry_t *fib_entry,
584                                     fib_source_t source,
585                                     fib_entry_flag_t old_flags)
586 {
587     /*
588      * handle changes to attached export for import entries
589      */
590     int is_import  = (FIB_ENTRY_FLAG_IMPORT & fib_entry_get_flags_i(fib_entry));
591     int was_import = (FIB_ENTRY_FLAG_IMPORT & old_flags);
592
593     if (!was_import && is_import)
594     {
595         /*
596          * transition from not exported to exported
597          */
598
599         /*
600          * there is an assumption here that the entry resolves via only
601          * one interface and that it is the cross VRF interface.
602          */
603         u32 sw_if_index = fib_path_list_get_resolving_interface(fib_entry->fe_parent);
604
605         fib_attached_export_import(fib_entry,
606                                    fib_table_get_index_for_sw_if_index(
607                                        fib_entry_get_proto(fib_entry),
608                                        sw_if_index));
609     }
610     else if (was_import && !is_import)
611     {
612         /*
613          * transition from exported to not exported
614          */
615         fib_attached_export_purge(fib_entry);
616     }
617     /*
618      * else
619      *   no change. nothing to do.
620      */
621
622     /*
623      * handle changes to attached export for export entries
624      */
625     int is_attached  = (FIB_ENTRY_FLAG_ATTACHED & fib_entry_get_flags_i(fib_entry));
626     int was_attached = (FIB_ENTRY_FLAG_ATTACHED & old_flags);
627
628     if (!was_attached && is_attached)
629     {
630         /*
631          * transition to attached. time to export
632          */
633         // FIXME
634     }
635     // else FIXME
636 }
637
638 static void
639 fib_entry_post_install_actions (fib_entry_t *fib_entry,
640                                 fib_source_t source,
641                                 fib_entry_flag_t old_flags)
642 {
643     fib_entry_post_flag_update_actions(fib_entry, source, old_flags);
644     fib_entry_src_action_installed(fib_entry, source);
645 }
646
647 fib_node_index_t
648 fib_entry_create (u32 fib_index,
649                   const fib_prefix_t *prefix,
650                   fib_source_t source,
651                   fib_entry_flag_t flags,
652                   const fib_route_path_t *paths)
653 {
654     fib_node_index_t fib_entry_index;
655     fib_entry_t *fib_entry;
656
657     ASSERT(0 < vec_len(paths));
658
659     fib_entry = fib_entry_alloc(fib_index, prefix, &fib_entry_index);
660
661     /*
662      * since this is a new entry create, we don't need to check for winning
663      * sources - there is only one.
664      */
665     fib_entry = fib_entry_src_action_add(fib_entry, source, flags,
666                                          drop_dpo_get(
667                                              fib_proto_to_dpo(
668                                                  fib_entry_get_proto(fib_entry))));
669     fib_entry_src_action_path_swap(fib_entry,
670                                    source,
671                                    flags,
672                                    paths);
673     /*
674      * handle possible realloc's by refetching the pointer
675      */
676     fib_entry = fib_entry_get(fib_entry_index);
677     fib_entry_src_action_activate(fib_entry, source);
678
679     fib_entry_post_install_actions(fib_entry, source, FIB_ENTRY_FLAG_NONE);
680
681     return (fib_entry_index);
682 }
683
684 fib_node_index_t
685 fib_entry_create_special (u32 fib_index,
686                           const fib_prefix_t *prefix,
687                           fib_source_t source,
688                           fib_entry_flag_t flags,
689                           const dpo_id_t *dpo)
690 {
691     fib_node_index_t fib_entry_index;
692     fib_entry_t *fib_entry;
693
694     /*
695      * create and initiliase the new enty
696      */
697     fib_entry = fib_entry_alloc(fib_index, prefix, &fib_entry_index);
698
699     /*
700      * create the path-list
701      */
702     fib_entry = fib_entry_src_action_add(fib_entry, source, flags, dpo);
703     fib_entry_src_action_activate(fib_entry, source);
704
705     fib_entry_post_install_actions(fib_entry, source, FIB_ENTRY_FLAG_NONE);
706
707     return (fib_entry_index);
708 }
709
710 static void
711 fib_entry_post_update_actions (fib_entry_t *fib_entry,
712                                fib_source_t source,
713                                fib_entry_flag_t old_flags)
714 {
715     /*
716      * backwalk to children to inform then of the change to forwarding.
717      */
718     fib_node_back_walk_ctx_t bw_ctx = {
719         .fnbw_reason = FIB_NODE_BW_REASON_FLAG_EVALUATE,
720     };
721
722     fib_walk_sync(FIB_NODE_TYPE_ENTRY, fib_entry_get_index(fib_entry), &bw_ctx);
723
724     /*
725      * then inform any covered prefixes
726      */
727     fib_entry_cover_update_notify(fib_entry);
728
729     fib_entry_post_install_actions(fib_entry, source, old_flags);
730 }
731
732 void
733 fib_entry_special_add (fib_node_index_t fib_entry_index,
734                        fib_source_t source,
735                        fib_entry_flag_t flags,
736                        const dpo_id_t *dpo)
737 {
738     fib_source_t best_source;
739     fib_entry_flag_t bflags;
740     fib_entry_t *fib_entry;
741     fib_entry_src_t *bsrc;
742
743     fib_entry = fib_entry_get(fib_entry_index);
744
745     bsrc = fib_entry_get_best_src_i(fib_entry);
746     best_source = fib_entry_src_get_source(bsrc);
747     bflags = fib_entry_src_get_flags(bsrc);
748
749     fib_entry = fib_entry_src_action_add(fib_entry, source, flags, dpo);
750
751     /*
752      * if the path list for the source passed is invalid,
753      * then we need to create a new one. else we are updating
754      * an existing.
755      */
756     if (source < best_source)
757     {
758         /*
759          * we have a new winning source.
760          */
761         fib_entry_src_action_deactivate(fib_entry, best_source);
762         fib_entry_src_action_activate(fib_entry, source);
763     }
764     else if (source > best_source)
765     {
766         /*
767          * the new source loses. nothing to do here.
768          * the data from the source is saved in the path-list created
769          */
770         return;
771     }
772     else
773     {
774         /*
775          * the new source is one this entry already has.
776          * But the path-list was updated, which will contribute new forwarding,
777          * so install it.
778          */
779         fib_entry_src_action_deactivate(fib_entry, source);
780         fib_entry_src_action_activate(fib_entry, source);
781     }
782
783     fib_entry_post_update_actions(fib_entry, source, bflags);
784 }
785
786 void
787 fib_entry_path_add (fib_node_index_t fib_entry_index,
788                     fib_source_t source,
789                     fib_entry_flag_t flags,
790                     const fib_route_path_t *rpath)
791 {
792     fib_source_t best_source;
793     fib_entry_flag_t bflags;
794     fib_entry_t *fib_entry;
795     fib_entry_src_t *bsrc;
796
797     ASSERT(1 == vec_len(rpath));
798
799     fib_entry = fib_entry_get(fib_entry_index);
800     ASSERT(NULL != fib_entry);
801
802     bsrc = fib_entry_get_best_src_i(fib_entry);
803     best_source = fib_entry_src_get_source(bsrc);
804     bflags = fib_entry_src_get_flags(bsrc);
805     
806     fib_entry = fib_entry_src_action_path_add(fib_entry, source, flags, rpath);
807
808     /*
809      * if the path list for the source passed is invalid,
810      * then we need to create a new one. else we are updating
811      * an existing.
812      */
813     if (source < best_source)
814     {
815         /*
816          * we have a new winning source.
817          */
818         fib_entry_src_action_deactivate(fib_entry, best_source);
819         fib_entry_src_action_activate(fib_entry, source);
820     }
821     else if (source > best_source)
822     {
823         /*
824          * the new source loses. nothing to do here.
825          * the data from the source is saved in the path-list created
826          */
827         return;
828     }
829     else
830     {
831         /*
832          * the new source is one this entry already has.
833          * But the path-list was updated, which will contribute new forwarding,
834          * so install it.
835          */
836         fib_entry_src_action_deactivate(fib_entry, source);
837         fib_entry_src_action_activate(fib_entry, source);
838     }
839
840     fib_entry_post_update_actions(fib_entry, source, bflags);
841 }
842
843 /*
844  * fib_entry_path_remove
845  *
846  * remove a path from the entry.
847  * return the fib_entry's index if it is still present, INVALID otherwise.
848  */
849 fib_entry_src_flag_t
850 fib_entry_path_remove (fib_node_index_t fib_entry_index,
851                        fib_source_t source,
852                        const fib_route_path_t *rpath)
853 {
854     fib_entry_src_flag_t sflag;
855     fib_source_t best_source;
856     fib_entry_flag_t bflags;
857     fib_entry_t *fib_entry;
858     fib_entry_src_t *bsrc;
859
860     ASSERT(1 == vec_len(rpath));
861
862     fib_entry = fib_entry_get(fib_entry_index);
863     ASSERT(NULL != fib_entry);
864
865     bsrc = fib_entry_get_best_src_i(fib_entry);
866     best_source = fib_entry_src_get_source(bsrc);
867     bflags = fib_entry_src_get_flags(bsrc);
868
869     sflag = fib_entry_src_action_path_remove(fib_entry, source, rpath);
870
871     /*
872      * if the path list for the source passed is invalid,
873      * then we need to create a new one. else we are updating
874      * an existing.
875      */
876     if (source < best_source )
877     {
878         /*
879          * Que! removing a path from a source that is better than the
880          * one this entry is using.
881          */
882         ASSERT(0);
883     }
884     else if (source > best_source )
885     {
886         /*
887          * the source is not the best. nothing to do.
888          */
889         return (FIB_ENTRY_SRC_FLAG_ADDED);
890     }
891     else
892     {
893         /*
894          * removing a path from the path-list we were using.
895          */
896         if (!(FIB_ENTRY_SRC_FLAG_ADDED & sflag))
897         {
898             /*
899              * the last path from the source was removed.
900              * fallback to lower source
901              */
902             bsrc = fib_entry_get_best_src_i(fib_entry);
903             best_source = fib_entry_src_get_source(bsrc);
904
905             if (FIB_SOURCE_MAX == best_source) {
906                 /*
907                  * no more sources left. this entry is toast.
908                  */
909                 fib_entry_src_action_uninstall(fib_entry);
910                 fib_entry_post_flag_update_actions(fib_entry, source, bflags);
911
912                 return (FIB_ENTRY_SRC_FLAG_NONE);
913             }
914             else
915             {
916                 fib_entry_src_action_activate(fib_entry, best_source);
917                 source = best_source;
918             }
919         }
920         else
921         {
922             /*
923              * re-install the new forwarding information
924              */
925             fib_entry_src_action_deactivate(fib_entry, source);
926             fib_entry_src_action_activate(fib_entry, source);
927         }
928     }
929
930     fib_entry_post_update_actions(fib_entry, source, bflags);
931
932     /*
933      * still have sources
934      */
935     return (FIB_ENTRY_SRC_FLAG_ADDED);
936 }
937
938 /*
939  * fib_entry_special_remove
940  *
941  * remove a special source from the entry.
942  * return the fib_entry's index if it is still present, INVALID otherwise.
943  */
944 fib_entry_src_flag_t
945 fib_entry_special_remove (fib_node_index_t fib_entry_index,
946                           fib_source_t source)
947 {
948     fib_entry_src_flag_t sflag;
949     fib_source_t best_source;
950     fib_entry_flag_t bflags;
951     fib_entry_t *fib_entry;
952     fib_entry_src_t *bsrc;
953
954     fib_entry = fib_entry_get(fib_entry_index);
955     ASSERT(NULL != fib_entry);
956
957     bsrc = fib_entry_get_best_src_i(fib_entry);
958     best_source = fib_entry_src_get_source(bsrc);
959     bflags = fib_entry_src_get_flags(bsrc);
960
961     sflag = fib_entry_src_action_remove(fib_entry, source);
962
963     /*
964      * if the path list for the source passed is invalid,
965      * then we need to create a new one. else we are updating
966      * an existing.
967      */
968     if (source < best_source )
969     {
970         /*
971          * Que! removing a path from a source that is better than the
972          * one this entry is using. This can only mean it is a source
973          * this prefix does not have.
974          */
975         return (FIB_ENTRY_SRC_FLAG_ADDED);
976     }
977     else if (source > best_source ) {
978         /*
979          * the source is not the best. nothing to do.
980          */
981         return (FIB_ENTRY_SRC_FLAG_ADDED);
982     }
983     else
984     {
985         if (!(FIB_ENTRY_SRC_FLAG_ADDED & sflag))
986         {
987             /*
988              * the source was removed. use the next best.
989              */
990             bsrc = fib_entry_get_best_src_i(fib_entry);
991             best_source = fib_entry_src_get_source(bsrc);
992
993             if (FIB_SOURCE_MAX == best_source) {
994                 /*
995                  * no more sources left. this entry is toast.
996                  */
997                 fib_entry_src_action_uninstall(fib_entry);
998                 fib_entry_post_flag_update_actions(fib_entry, source, bflags);
999
1000                 return (FIB_ENTRY_SRC_FLAG_NONE);
1001             }
1002             else
1003             {
1004                 fib_entry_src_action_activate(fib_entry, best_source);
1005                 source = best_source;
1006             }
1007         }
1008         else
1009         {
1010             /*
1011              * re-install the new forwarding information
1012              */
1013             fib_entry_src_action_reactivate(fib_entry, source);
1014         }
1015     }
1016
1017     fib_entry_post_update_actions(fib_entry, source, bflags);
1018
1019     /*
1020      * still have sources
1021      */
1022     return (FIB_ENTRY_SRC_FLAG_ADDED);
1023 }
1024
1025 /**
1026  * fib_entry_delete
1027  *
1028  * The source is withdrawing all the paths it provided
1029  */
1030 fib_entry_src_flag_t
1031 fib_entry_delete (fib_node_index_t fib_entry_index,
1032                   fib_source_t source)
1033 {
1034     return (fib_entry_special_remove(fib_entry_index, source));
1035 }
1036
1037 /**
1038  * fib_entry_update
1039  *
1040  * The source has provided a new set of paths that will replace the old.
1041  */
1042 void
1043 fib_entry_update (fib_node_index_t fib_entry_index,
1044                   fib_source_t source,
1045                   fib_entry_flag_t flags,
1046                   const fib_route_path_t *paths)
1047 {
1048     fib_source_t best_source;
1049     fib_entry_flag_t bflags;
1050     fib_entry_t *fib_entry;
1051     fib_entry_src_t *bsrc;
1052
1053     fib_entry = fib_entry_get(fib_entry_index);
1054     ASSERT(NULL != fib_entry);
1055
1056     bsrc = fib_entry_get_best_src_i(fib_entry);
1057     best_source = fib_entry_src_get_source(bsrc);
1058     bflags = fib_entry_src_get_flags(bsrc);
1059
1060     fib_entry_src_action_path_swap(fib_entry,
1061                                    source,
1062                                    flags,
1063                                    paths);
1064     /*
1065      * handle possible realloc's by refetching the pointer
1066      */
1067     fib_entry = fib_entry_get(fib_entry_index);
1068
1069     /*
1070      * if the path list for the source passed is invalid,
1071      * then we need to create a new one. else we are updating
1072      * an existing.
1073      */
1074     if (source < best_source)
1075     {
1076         /*
1077          * we have a new winning source.
1078          */
1079         fib_entry_src_action_deactivate(fib_entry, best_source);
1080         fib_entry_src_action_activate(fib_entry, source);
1081     }
1082     else if (source > best_source) {
1083         /*
1084          * the new source loses. nothing to do here.
1085          * the data from the source is saved in the path-list created
1086          */
1087         return;
1088     }
1089     else
1090     {
1091         /*
1092          * the new source is one this entry already has.
1093          * But the path-list was updated, which will contribute new forwarding,
1094          * so install it.
1095          */
1096         fib_entry_src_action_deactivate(fib_entry, source);
1097         fib_entry_src_action_activate(fib_entry, source);
1098     }
1099
1100     fib_entry_post_update_actions(fib_entry, source, bflags);
1101 }
1102
1103
1104 /*
1105  * fib_entry_cover_changed
1106  *
1107  * this entry is tracking its cover and that cover has changed.
1108  */
1109 void
1110 fib_entry_cover_changed (fib_node_index_t fib_entry_index)
1111 {
1112     fib_entry_src_cover_res_t res = {
1113         .install = !0,
1114         .bw_reason = FIB_NODE_BW_REASON_FLAG_NONE,
1115     };
1116     fib_source_t source, best_source;
1117     fib_entry_flag_t bflags;
1118     fib_entry_t *fib_entry;
1119     fib_entry_src_t *esrc;
1120     u32 index;
1121
1122     bflags = FIB_ENTRY_FLAG_NONE;
1123     best_source = FIB_SOURCE_FIRST;
1124     fib_entry = fib_entry_get(fib_entry_index);
1125
1126     fib_attached_export_cover_change(fib_entry);
1127
1128     /*
1129      * propagate the notificuation to each of the added sources
1130      */
1131     index = 0;
1132     FOR_EACH_SRC_ADDED(fib_entry, esrc, source,
1133     ({
1134         if (0 == index)
1135         {
1136             /*
1137              * only the best source gets to set the back walk flags
1138              */
1139             res = fib_entry_src_action_cover_change(fib_entry, source);
1140             bflags = fib_entry_src_get_flags(esrc);
1141             best_source = fib_entry_src_get_source(esrc);
1142         }
1143         else
1144         {
1145             fib_entry_src_action_cover_change(fib_entry, source);
1146         }
1147         index++;
1148     }));
1149
1150     if (res.install)
1151     {
1152         fib_entry_src_action_reactivate(fib_entry,
1153                                         fib_entry_src_get_source(
1154                                             fib_entry_get_best_src_i(fib_entry)));
1155         fib_entry_post_install_actions(fib_entry, best_source, bflags);
1156     }
1157     else
1158     {
1159         fib_entry_src_action_uninstall(fib_entry);
1160     }
1161
1162     if (FIB_NODE_BW_REASON_FLAG_NONE != res.bw_reason)
1163     {
1164         /*
1165          * time for walkies fido.
1166          */
1167         fib_node_back_walk_ctx_t bw_ctx = {
1168             .fnbw_reason = res.bw_reason,
1169         };
1170
1171         fib_walk_sync(FIB_NODE_TYPE_ENTRY, fib_entry_index, &bw_ctx);
1172     }
1173 }
1174
1175 /*
1176  * fib_entry_cover_updated
1177  *
1178  * this entry is tracking its cover and that cover has been updated
1179  * (i.e. its forwarding information has changed).
1180  */
1181 void
1182 fib_entry_cover_updated (fib_node_index_t fib_entry_index)
1183 {
1184     fib_entry_src_cover_res_t res = {
1185         .install = !0,
1186         .bw_reason = FIB_NODE_BW_REASON_FLAG_NONE,
1187     };
1188     fib_source_t source, best_source;
1189     fib_entry_flag_t bflags;
1190     fib_entry_t *fib_entry;
1191     fib_entry_src_t *esrc;
1192     u32 index;
1193
1194     bflags = FIB_ENTRY_FLAG_NONE;
1195     best_source = FIB_SOURCE_FIRST;
1196     fib_entry = fib_entry_get(fib_entry_index);
1197
1198     fib_attached_export_cover_update(fib_entry);
1199
1200     /*
1201      * propagate the notificuation to each of the added sources
1202      */
1203     index = 0;
1204     FOR_EACH_SRC_ADDED(fib_entry, esrc, source,
1205     ({
1206         if (0 == index)
1207         {
1208             /*
1209              * only the best source gets to set the back walk flags
1210              */
1211             res = fib_entry_src_action_cover_update(fib_entry, source);
1212             bflags = fib_entry_src_get_flags(esrc);
1213             best_source = fib_entry_src_get_source(esrc);
1214         }
1215         else
1216         {
1217             fib_entry_src_action_cover_update(fib_entry, source);
1218         }
1219         index++;
1220     }));
1221
1222     if (res.install)
1223     {
1224         fib_entry_src_action_reactivate(fib_entry,
1225                                         fib_entry_src_get_source(
1226                                             fib_entry_get_best_src_i(fib_entry)));
1227         fib_entry_post_install_actions(fib_entry, best_source, bflags);
1228     }
1229     else
1230     {
1231         fib_entry_src_action_uninstall(fib_entry);
1232     }
1233
1234     if (FIB_NODE_BW_REASON_FLAG_NONE != res.bw_reason)
1235     {
1236         /*
1237          * time for walkies fido.
1238          */
1239         fib_node_back_walk_ctx_t bw_ctx = {
1240             .fnbw_reason = res.bw_reason,
1241         };
1242
1243         fib_walk_sync(FIB_NODE_TYPE_ENTRY, fib_entry_index, &bw_ctx);
1244     }
1245 }
1246
1247 int
1248 fib_entry_recursive_loop_detect (fib_node_index_t entry_index,
1249                                  fib_node_index_t **entry_indicies)
1250 {
1251     fib_entry_t *fib_entry;
1252     int was_looped, is_looped;
1253
1254     fib_entry = fib_entry_get(entry_index);
1255
1256     if (FIB_NODE_INDEX_INVALID != fib_entry->fe_parent)
1257     {
1258         fib_node_index_t *entries = *entry_indicies;
1259         fib_forward_chain_type_t fct;
1260
1261         vec_add1(entries, entry_index);
1262         was_looped = fib_path_list_is_looped(fib_entry->fe_parent);
1263         is_looped = fib_path_list_recursive_loop_detect(fib_entry->fe_parent,
1264                                                         &entries);
1265
1266         *entry_indicies = entries;
1267
1268         if (!!was_looped != !!is_looped)
1269         {
1270             /*
1271              * re-evaluate all the entry's forwarding
1272              * NOTE: this is an inplace modify
1273              */
1274             FOR_EACH_FIB_FORW_CHAIN(fct)
1275             {
1276                 if (dpo_id_is_valid(&fib_entry->fe_lb[fct]))
1277                 {
1278                     fib_entry_src_mk_lb(fib_entry,
1279                                         fib_entry_get_best_src_i(fib_entry),
1280                                         fct,
1281                                         &fib_entry->fe_lb[fct]);
1282                 }
1283             }
1284         }
1285     }
1286     else
1287     {
1288         /*
1289          * the entry is currently not linked to a path-list. this happens
1290          * when it is this entry that is re-linking path-lists and has thus
1291          * broken the loop
1292          */
1293         is_looped = 0;
1294     }
1295
1296     return (is_looped);
1297 }
1298
1299 u32
1300 fib_entry_get_resolving_interface (fib_node_index_t entry_index)
1301 {
1302    fib_entry_t *fib_entry;
1303
1304     fib_entry = fib_entry_get(entry_index);
1305
1306     return (fib_path_list_get_resolving_interface(fib_entry->fe_parent));
1307 }
1308
1309 fib_source_t
1310 fib_entry_get_best_source (fib_node_index_t entry_index)
1311 {
1312     fib_entry_t *fib_entry;
1313     fib_entry_src_t *bsrc;
1314
1315     fib_entry = fib_entry_get(entry_index);
1316
1317     bsrc = fib_entry_get_best_src_i(fib_entry);
1318     return (fib_entry_src_get_source(bsrc));
1319 }
1320
1321 static int
1322 fib_ip4_address_compare (ip4_address_t * a1,
1323                          ip4_address_t * a2)
1324 {
1325     /*
1326      * IP addresses are unsiged ints. the return value here needs to be signed
1327      * a simple subtraction won't cut it.
1328      * If the addresses are the same, the sort order is undefiend, so phoey.
1329      */
1330     return ((clib_net_to_host_u32(a1->data_u32) >
1331              clib_net_to_host_u32(a2->data_u32) ) ?
1332             1 : -1);
1333 }
1334
1335 static int
1336 fib_ip6_address_compare (ip6_address_t * a1,
1337                          ip6_address_t * a2)
1338 {
1339   int i;
1340   for (i = 0; i < ARRAY_LEN (a1->as_u16); i++)
1341   {
1342       int cmp = (clib_net_to_host_u16 (a1->as_u16[i]) -
1343                  clib_net_to_host_u16 (a2->as_u16[i]));
1344       if (cmp != 0)
1345           return cmp;
1346   }
1347   return 0;
1348 }
1349
1350 static int
1351 fib_entry_cmp (fib_node_index_t fib_entry_index1,
1352                fib_node_index_t fib_entry_index2)
1353 {
1354     fib_entry_t *fib_entry1, *fib_entry2;
1355     int cmp = 0;
1356
1357     fib_entry1 = fib_entry_get(fib_entry_index1);
1358     fib_entry2 = fib_entry_get(fib_entry_index2);
1359
1360     switch (fib_entry1->fe_prefix.fp_proto)
1361     {
1362     case FIB_PROTOCOL_IP4:
1363         cmp = fib_ip4_address_compare(&fib_entry1->fe_prefix.fp_addr.ip4,
1364                                       &fib_entry2->fe_prefix.fp_addr.ip4);
1365         break;
1366     case FIB_PROTOCOL_IP6:
1367         cmp = fib_ip6_address_compare(&fib_entry1->fe_prefix.fp_addr.ip6,
1368                                       &fib_entry2->fe_prefix.fp_addr.ip6);
1369         break;
1370     case FIB_PROTOCOL_MPLS:
1371         cmp = (fib_entry1->fe_prefix.fp_label - fib_entry2->fe_prefix.fp_label);
1372
1373         if (0 == cmp)
1374         {
1375             cmp = (fib_entry1->fe_prefix.fp_eos - fib_entry2->fe_prefix.fp_eos);
1376         }
1377         break;
1378     }
1379
1380     if (0 == cmp) {
1381         cmp = (fib_entry1->fe_prefix.fp_len - fib_entry2->fe_prefix.fp_len);
1382     }
1383     return (cmp);   
1384 }
1385
1386 int
1387 fib_entry_cmp_for_sort (void *i1, void *i2)
1388 {
1389     fib_node_index_t *fib_entry_index1 = i1, *fib_entry_index2 = i2;
1390
1391     return (fib_entry_cmp(*fib_entry_index1,
1392                           *fib_entry_index2));
1393 }
1394
1395 void
1396 fib_entry_lock (fib_node_index_t fib_entry_index)
1397 {
1398     fib_entry_t *fib_entry;
1399
1400     fib_entry = fib_entry_get(fib_entry_index);
1401
1402     fib_node_lock(&fib_entry->fe_node);
1403 }
1404
1405 void
1406 fib_entry_unlock (fib_node_index_t fib_entry_index)
1407 {
1408     fib_entry_t *fib_entry;
1409
1410     fib_entry = fib_entry_get(fib_entry_index);
1411
1412     fib_node_unlock(&fib_entry->fe_node);
1413 }
1414
1415 void
1416 fib_entry_module_init (void)
1417 {
1418     fib_node_register_type (FIB_NODE_TYPE_ENTRY, &fib_entry_vft);
1419 }
1420
1421 void
1422 fib_entry_get_prefix (fib_node_index_t fib_entry_index,
1423                       fib_prefix_t *pfx)
1424 {
1425     fib_entry_t *fib_entry;
1426
1427     fib_entry = fib_entry_get(fib_entry_index);
1428     *pfx = fib_entry->fe_prefix;
1429 }
1430
1431 u32
1432 fib_entry_get_fib_index (fib_node_index_t fib_entry_index)
1433 {
1434     fib_entry_t *fib_entry;
1435
1436     fib_entry = fib_entry_get(fib_entry_index);
1437
1438     return (fib_entry->fe_fib_index);
1439 }
1440
1441 u32
1442 fib_entry_pool_size (void)
1443 {
1444     return (pool_elts(fib_entry_pool));
1445 }
1446
1447 static clib_error_t *
1448 show_fib_entry_command (vlib_main_t * vm,
1449                         unformat_input_t * input,
1450                         vlib_cli_command_t * cmd)
1451 {
1452     fib_node_index_t fei;
1453
1454     if (unformat (input, "%d", &fei))
1455     {
1456         /*
1457          * show one in detail
1458          */
1459         if (!pool_is_free_index(fib_entry_pool, fei))
1460         {
1461             vlib_cli_output (vm, "%d@%U",
1462                              fei,
1463                              format_fib_entry, fei,
1464                              FIB_ENTRY_FORMAT_DETAIL2);
1465         }
1466         else
1467         {
1468             vlib_cli_output (vm, "entry %d invalid", fei);
1469         }
1470     }
1471     else
1472     {
1473         /*
1474          * show all
1475          */
1476         vlib_cli_output (vm, "FIB Entries:");
1477         pool_foreach_index(fei, fib_entry_pool,
1478         ({
1479             vlib_cli_output (vm, "%d@%U",
1480                              fei,
1481                              format_fib_entry, fei,
1482                              FIB_ENTRY_FORMAT_BRIEF);
1483         }));
1484     }
1485
1486     return (NULL);
1487 }
1488
1489 VLIB_CLI_COMMAND (show_fib_entry, static) = {
1490   .path = "show fib entry",
1491   .function = show_fib_entry_command,
1492   .short_help = "show fib entry",
1493 };