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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include <vnet/adj/adj.h>
17 #include <vnet/dpo/load_balance.h>
18 #include <vnet/dpo/mpls_label_dpo.h>
19 #include <vnet/dpo/drop_dpo.h>
20 #include <vnet/dpo/replicate_dpo.h>
22 #include <vnet/fib/fib_entry_src.h>
23 #include <vnet/fib/fib_table.h>
24 #include <vnet/fib/fib_path_ext.h>
25 #include <vnet/fib/fib_urpf_list.h>
26 #include <vnet/fib/fib_entry_delegate.h>
31 static fib_entry_src_vft_t fib_entry_src_vft[FIB_SOURCE_MAX];
34 * Get the VFT for a given source. This is a combination of the source
35 * enum and the interposer flags
37 const fib_entry_src_vft_t*
38 fib_entry_src_get_vft (const fib_entry_src_t *esrc)
40 if (esrc->fes_entry_flags & FIB_ENTRY_FLAG_INTERPOSE)
42 return (&fib_entry_src_vft[FIB_SOURCE_INTERPOSE]);
45 return (&fib_entry_src_vft[esrc->fes_src]);
49 fib_entry_src_copy_default (const fib_entry_src_t *orig_src,
50 const fib_entry_t *fib_entry,
51 fib_entry_src_t *copy_src)
53 clib_memcpy(©_src->u, &orig_src->u, sizeof(copy_src->u));
57 fib_entry_src_register (fib_source_t source,
58 const fib_entry_src_vft_t *vft)
60 fib_entry_src_vft[source] = *vft;
62 if (NULL == fib_entry_src_vft[source].fesv_copy)
64 fib_entry_src_vft[source].fesv_copy = fib_entry_src_copy_default;
69 fib_entry_src_cmp_for_sort (void * v1,
72 fib_entry_src_t *esrc1 = v1, *esrc2 = v2;
74 return (esrc1->fes_src - esrc2->fes_src);
78 fib_entry_src_action_init (fib_entry_t *fib_entry,
80 fib_entry_flag_t flags)
82 fib_entry_src_t esrc = {
83 .fes_pl = FIB_NODE_INDEX_INVALID,
84 .fes_flags = FIB_ENTRY_SRC_FLAG_NONE,
86 .fes_entry_flags = flags,
89 FIB_ENTRY_SRC_VFT_INVOKE(&esrc, fesv_init, (&esrc));
91 vec_add1(fib_entry->fe_srcs, esrc);
92 vec_sort_with_function(fib_entry->fe_srcs,
93 fib_entry_src_cmp_for_sort);
96 static fib_entry_src_t *
97 fib_entry_src_find_i (const fib_entry_t *fib_entry,
102 fib_entry_src_t *esrc;
106 vec_foreach(esrc, fib_entry->fe_srcs)
108 if (esrc->fes_src == source)
125 static fib_entry_src_t *
126 fib_entry_src_find (const fib_entry_t *fib_entry,
130 return (fib_entry_src_find_i(fib_entry, source, NULL));
134 fib_entry_is_sourced (fib_node_index_t fib_entry_index,
137 fib_entry_t *fib_entry;
139 fib_entry = fib_entry_get(fib_entry_index);
141 return (NULL != fib_entry_src_find(fib_entry, source));
145 fib_entry_is_marked (fib_node_index_t fib_entry_index,
148 fib_entry_t *fib_entry;
149 fib_entry_src_t *esrc;
151 fib_entry = fib_entry_get(fib_entry_index);
153 esrc = fib_entry_src_find(fib_entry, source);
161 return (!!(esrc->fes_flags & FIB_ENTRY_SRC_FLAG_STALE));
166 fib_entry_mark (fib_node_index_t fib_entry_index,
169 fib_entry_t *fib_entry;
170 fib_entry_src_t *esrc;
172 fib_entry = fib_entry_get(fib_entry_index);
174 esrc = fib_entry_src_find(fib_entry, source);
178 esrc->fes_flags |= FIB_ENTRY_SRC_FLAG_STALE;
182 static fib_entry_src_t *
183 fib_entry_src_find_or_create (fib_entry_t *fib_entry,
185 fib_entry_flag_t flags)
187 fib_entry_src_t *esrc;
189 esrc = fib_entry_src_find(fib_entry, source);
193 fib_entry_src_action_init(fib_entry, source, flags);
196 return (fib_entry_src_find(fib_entry, source));
200 fib_entry_src_action_deinit (fib_entry_t *fib_entry,
204 fib_entry_src_t *esrc;
207 esrc = fib_entry_src_find_i(fib_entry, source, &index);
209 ASSERT(NULL != esrc);
211 FIB_ENTRY_SRC_VFT_INVOKE(esrc, fesv_deinit, (esrc));
213 fib_path_ext_list_flush(&esrc->fes_path_exts);
214 vec_del1(fib_entry->fe_srcs, index);
215 vec_sort_with_function(fib_entry->fe_srcs,
216 fib_entry_src_cmp_for_sort);
219 fib_entry_src_cover_res_t
220 fib_entry_src_action_cover_change (fib_entry_t *fib_entry,
221 fib_entry_src_t *esrc)
223 FIB_ENTRY_SRC_VFT_INVOKE_AND_RETURN(esrc, fesv_cover_change,
226 fib_entry_src_cover_res_t res = {
228 .bw_reason = FIB_NODE_BW_REASON_FLAG_NONE,
233 fib_entry_src_cover_res_t
234 fib_entry_src_action_cover_update (fib_entry_t *fib_entry,
235 fib_entry_src_t *esrc)
237 FIB_ENTRY_SRC_VFT_INVOKE_AND_RETURN(esrc, fesv_cover_update,
240 fib_entry_src_cover_res_t res = {
242 .bw_reason = FIB_NODE_BW_REASON_FLAG_NONE,
247 typedef struct fib_entry_src_collect_forwarding_ctx_t_
249 load_balance_path_t *next_hops;
250 const fib_entry_t *fib_entry;
251 const fib_entry_src_t *esrc;
252 fib_forward_chain_type_t fct;
253 int n_recursive_constrained;
255 } fib_entry_src_collect_forwarding_ctx_t;
258 * @brief Determine whether this FIB entry should use a load-balance MAP
259 * to support PIC edge fast convergence
262 fib_entry_calc_lb_flags (fib_entry_src_collect_forwarding_ctx_t *ctx)
265 * We'll use a LB map if the path-list has multiple recursive paths.
266 * recursive paths implies BGP, and hence scale.
268 if (ctx->n_recursive_constrained > 1 &&
269 fib_path_list_is_popular(ctx->esrc->fes_pl))
271 return (LOAD_BALANCE_FLAG_USES_MAP);
273 return (LOAD_BALANCE_FLAG_NONE);
277 fib_entry_src_valid_out_label (mpls_label_t label)
279 return ((MPLS_LABEL_IS_REAL(label) ||
280 MPLS_LABEL_POP == label ||
281 MPLS_IETF_IPV4_EXPLICIT_NULL_LABEL == label ||
282 MPLS_IETF_IPV6_EXPLICIT_NULL_LABEL == label ||
283 MPLS_IETF_IMPLICIT_NULL_LABEL == label));
287 * @brief Turn the chain type requested by the client into the one they
290 fib_forward_chain_type_t
291 fib_entry_chain_type_fixup (const fib_entry_t *entry,
292 fib_forward_chain_type_t fct)
295 * The EOS chain is a tricky since one cannot know the adjacency
296 * to link to without knowing what the packets payload protocol
297 * will be once the label is popped.
299 fib_forward_chain_type_t dfct;
301 if (FIB_FORW_CHAIN_TYPE_MPLS_EOS != fct)
306 dfct = fib_entry_get_default_chain_type(entry);
308 if (FIB_FORW_CHAIN_TYPE_MPLS_EOS == dfct)
311 * If the entry being asked is a eos-MPLS label entry,
312 * then use the payload-protocol field, that we stashed there
313 * for just this purpose
315 return (fib_forw_chain_type_from_dpo_proto(
316 entry->fe_prefix.fp_payload_proto));
319 * else give them what this entry would be by default. i.e. if it's a v6
320 * entry, then the label its local labelled should be carrying v6 traffic.
321 * If it's a non-EOS label entry, then there are more labels and we want
328 fib_prefix_get_payload_proto (const fib_prefix_t *pfx)
330 switch (pfx->fp_proto)
332 case FIB_PROTOCOL_IP4:
333 return (DPO_PROTO_IP4);
334 case FIB_PROTOCOL_IP6:
335 return (DPO_PROTO_IP6);
336 case FIB_PROTOCOL_MPLS:
337 return (pfx->fp_payload_proto);
341 return (DPO_PROTO_IP4);
345 fib_entry_src_get_path_forwarding (fib_node_index_t path_index,
346 fib_entry_src_collect_forwarding_ctx_t *ctx)
348 load_balance_path_t *nh;
351 * no extension => no out-going label for this path. that's OK
352 * in the case of an IP or EOS chain, but not for non-EOS
356 case FIB_FORW_CHAIN_TYPE_UNICAST_IP4:
357 case FIB_FORW_CHAIN_TYPE_UNICAST_IP6:
358 case FIB_FORW_CHAIN_TYPE_MCAST_IP4:
359 case FIB_FORW_CHAIN_TYPE_MCAST_IP6:
360 case FIB_FORW_CHAIN_TYPE_BIER:
362 * EOS traffic with no label to stack, we need the IP Adj
364 vec_add2(ctx->next_hops, nh, 1);
366 nh->path_index = path_index;
367 nh->path_weight = fib_path_get_weight(path_index);
368 fib_path_contribute_forwarding(path_index, ctx->fct, &nh->path_dpo);
371 case FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS:
372 if (fib_path_is_exclusive(path_index) ||
373 fib_path_is_deag(path_index))
375 vec_add2(ctx->next_hops, nh, 1);
377 nh->path_index = path_index;
378 nh->path_weight = fib_path_get_weight(path_index);
379 fib_path_contribute_forwarding(path_index,
380 FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS,
384 case FIB_FORW_CHAIN_TYPE_MPLS_EOS:
387 * no label. we need a chain based on the payload. fixup.
389 vec_add2(ctx->next_hops, nh, 1);
391 nh->path_index = path_index;
392 nh->path_weight = fib_path_get_weight(path_index);
393 fib_path_contribute_forwarding(path_index,
394 fib_entry_chain_type_fixup(ctx->fib_entry,
397 fib_path_stack_mpls_disp(path_index,
398 fib_prefix_get_payload_proto(&ctx->fib_entry->fe_prefix),
399 FIB_MPLS_LSP_MODE_PIPE,
404 case FIB_FORW_CHAIN_TYPE_ETHERNET:
405 case FIB_FORW_CHAIN_TYPE_NSH:
411 static fib_path_list_walk_rc_t
412 fib_entry_src_collect_forwarding (fib_node_index_t pl_index,
413 fib_node_index_t path_index,
416 fib_entry_src_collect_forwarding_ctx_t *ctx;
417 fib_path_ext_t *path_ext;
421 n_nhs = vec_len(ctx->next_hops);
424 * if the path is not resolved, don't include it.
426 if (!fib_path_is_resolved(path_index))
428 return (FIB_PATH_LIST_WALK_CONTINUE);
431 if (fib_path_is_recursive_constrained(path_index))
433 ctx->n_recursive_constrained += 1;
435 if (0xffff == ctx->preference)
438 * not set a preference yet, so the first path we encounter
439 * sets the preference we are collecting.
441 ctx->preference = fib_path_get_preference(path_index);
443 else if (ctx->preference != fib_path_get_preference(path_index))
446 * this path does not belong to the same preference as the
447 * previous paths encountered. we are done now.
449 return (FIB_PATH_LIST_WALK_STOP);
453 * get the matching path-extension for the path being visited.
455 path_ext = fib_path_ext_list_find_by_path_index(&ctx->esrc->fes_path_exts,
458 if (NULL != path_ext)
460 switch (path_ext->fpe_type)
462 case FIB_PATH_EXT_MPLS:
463 if (fib_entry_src_valid_out_label(path_ext->fpe_label_stack[0].fml_value))
466 * found a matching extension. stack it to obtain the forwarding
467 * info for this path.
470 fib_path_ext_stack(path_ext,
472 fib_entry_chain_type_fixup(ctx->fib_entry,
478 fib_entry_src_get_path_forwarding(path_index, ctx);
481 case FIB_PATH_EXT_ADJ:
482 if (FIB_PATH_EXT_ADJ_FLAG_REFINES_COVER & path_ext->fpe_adj_flags)
484 fib_entry_src_get_path_forwarding(path_index, ctx);
488 * the path does not refine the cover, meaning that
489 * the adjacency does/does not match the sub-net on the link.
490 * So this path does not contribute forwarding.
497 fib_entry_src_get_path_forwarding(path_index, ctx);
501 * a this point 'ctx' has the DPO the path contributed, plus
502 * any labels from path extensions.
503 * check if there are any interpose sources that want to contribute
505 if (n_nhs < vec_len(ctx->next_hops))
508 * the path contributed a new choice.
510 const fib_entry_src_vft_t *vft;
512 vft = fib_entry_src_get_vft(ctx->esrc);
514 if (NULL != vft->fesv_contribute_interpose)
516 const dpo_id_t *interposer;
518 interposer = vft->fesv_contribute_interpose(ctx->esrc,
521 if (NULL != interposer)
523 dpo_id_t clone = DPO_INVALID;
525 dpo_mk_interpose(interposer,
526 &ctx->next_hops[n_nhs].path_dpo,
529 dpo_copy(&ctx->next_hops[n_nhs].path_dpo, &clone);
535 return (FIB_PATH_LIST_WALK_CONTINUE);
539 fib_entry_src_mk_lb (fib_entry_t *fib_entry,
540 const fib_entry_src_t *esrc,
541 fib_forward_chain_type_t fct,
544 dpo_proto_t lb_proto;
547 * If the entry has path extensions then we construct a load-balance
548 * by stacking the extensions on the forwarding chains of the paths.
549 * Otherwise we use the load-balance of the path-list
551 fib_entry_src_collect_forwarding_ctx_t ctx = {
553 .fib_entry = fib_entry,
555 .n_recursive_constrained = 0,
557 .preference = 0xffff,
561 * As an optimisation we allocate the vector of next-hops to be sized
562 * equal to the maximum number of paths we will need, which is also the
563 * most likely number we will need, since in most cases the paths are 'up'.
565 vec_validate(ctx.next_hops, fib_path_list_get_n_paths(esrc->fes_pl));
566 vec_reset_length(ctx.next_hops);
568 lb_proto = fib_forw_chain_type_to_dpo_proto(fct);
570 fib_path_list_walk(esrc->fes_pl,
571 fib_entry_src_collect_forwarding,
574 if (esrc->fes_entry_flags & FIB_ENTRY_FLAG_EXCLUSIVE)
577 * the client provided the DPO that the entry should link to.
578 * all entries must link to a LB, so if it is an LB already
579 * then we can use it.
581 if ((1 == vec_len(ctx.next_hops)) &&
582 (DPO_LOAD_BALANCE == ctx.next_hops[0].path_dpo.dpoi_type))
584 dpo_copy(dpo_lb, &ctx.next_hops[0].path_dpo);
585 dpo_reset(&ctx.next_hops[0].path_dpo);
590 if (!dpo_id_is_valid(dpo_lb))
595 if (esrc->fes_entry_flags & FIB_ENTRY_FLAG_MULTICAST)
600 MPLS_IS_REPLICATE | replicate_create(0, lb_proto));
604 fib_protocol_t flow_hash_proto;
605 flow_hash_config_t fhc;
608 * if the protocol for the LB we are building does not match that
609 * of the fib_entry (i.e. we are build the [n]EOS LB for an IPv[46]
610 * then the fib_index is not an index that relates to the table
611 * type we need. So get the default flow-hash config instead.
613 flow_hash_proto = dpo_proto_to_fib(lb_proto);
614 if (fib_entry->fe_prefix.fp_proto != flow_hash_proto)
616 fhc = fib_table_get_default_flow_hash_config(flow_hash_proto);
620 fhc = fib_table_get_flow_hash_config(fib_entry->fe_fib_index,
627 load_balance_create(0, lb_proto, fhc));
631 if (esrc->fes_entry_flags & FIB_ENTRY_FLAG_MULTICAST)
636 replicate_multipath_update(dpo_lb, ctx.next_hops);
640 load_balance_multipath_update(dpo_lb,
642 fib_entry_calc_lb_flags(&ctx));
643 vec_free(ctx.next_hops);
646 * if this entry is sourced by the uRPF-exempt source then we
647 * append the always present local0 interface (index 0) to the
648 * uRPF list so it is not empty. that way packets pass the loose check.
650 index_t ui = fib_path_list_get_urpf(esrc->fes_pl);
652 if ((fib_entry_is_sourced(fib_entry_get_index(fib_entry),
653 FIB_SOURCE_URPF_EXEMPT) ||
654 (esrc->fes_entry_flags & FIB_ENTRY_FLAG_LOOSE_URPF_EXEMPT))&&
655 (0 == fib_urpf_check_size(ui)))
658 * The uRPF list we get from the path-list is shared by all
659 * other users of the list, but the uRPF exemption applies
660 * only to this prefix. So we need our own list.
662 ui = fib_urpf_list_alloc_and_lock();
663 fib_urpf_list_append(ui, 0);
664 fib_urpf_list_bake(ui);
665 load_balance_set_urpf(dpo_lb->dpoi_index, ui);
666 fib_urpf_list_unlock(ui);
670 load_balance_set_urpf(dpo_lb->dpoi_index, ui);
672 load_balance_set_fib_entry_flags(dpo_lb->dpoi_index,
673 fib_entry_get_flags_i(fib_entry));
678 fib_entry_src_action_install (fib_entry_t *fib_entry,
682 * Install the forwarding chain for the given source into the forwarding
685 fib_forward_chain_type_t fct;
686 fib_entry_src_t *esrc;
689 fct = fib_entry_get_default_chain_type(fib_entry);
690 esrc = fib_entry_src_find(fib_entry, source);
693 * Every entry has its own load-balance object. All changes to the entry's
694 * forwarding result in an inplace modify of the load-balance. This means
695 * the load-balance object only needs to be added to the forwarding
696 * DB once, when it is created.
698 insert = !dpo_id_is_valid(&fib_entry->fe_lb);
700 fib_entry_src_mk_lb(fib_entry, esrc, fct, &fib_entry->fe_lb);
702 ASSERT(dpo_id_is_valid(&fib_entry->fe_lb));
703 FIB_ENTRY_DBG(fib_entry, "install: %d", fib_entry->fe_lb);
706 * insert the adj into the data-plane forwarding trie
710 fib_table_fwding_dpo_update(fib_entry->fe_fib_index,
711 &fib_entry->fe_prefix,
716 * if any of the other chain types are already created they will need
719 fib_entry_delegate_type_t fdt;
720 fib_entry_delegate_t *fed;
722 FOR_EACH_DELEGATE_CHAIN(fib_entry, fdt, fed,
724 fib_entry_src_mk_lb(fib_entry, esrc,
725 fib_entry_delegate_type_to_chain_type(fdt),
731 fib_entry_src_action_uninstall (fib_entry_t *fib_entry)
734 * uninstall the forwarding chain from the forwarding tables
736 FIB_ENTRY_DBG(fib_entry, "uninstall");
738 if (dpo_id_is_valid(&fib_entry->fe_lb))
740 fib_table_fwding_dpo_remove(
741 fib_entry->fe_fib_index,
742 &fib_entry->fe_prefix,
745 dpo_reset(&fib_entry->fe_lb);
750 fib_entry_recursive_loop_detect_i (fib_node_index_t path_list_index)
752 fib_node_index_t *entries = NULL;
754 fib_path_list_recursive_loop_detect(path_list_index, &entries);
760 * fib_entry_src_action_copy
762 * copy a source data from another entry to this one
765 fib_entry_src_action_copy (fib_entry_t *fib_entry,
766 const fib_entry_src_t *orig_src)
768 fib_entry_src_t *esrc;
770 esrc = fib_entry_src_find_or_create(fib_entry,
772 orig_src->fes_entry_flags);
774 FIB_ENTRY_SRC_VFT_INVOKE(esrc, fesv_copy,
775 (orig_src, fib_entry, esrc));
777 fib_path_list_unlock(esrc->fes_pl);
780 * copy over all the data ...
782 esrc->fes_flags = orig_src->fes_flags;
783 esrc->fes_pl = orig_src->fes_pl;
788 esrc->fes_ref_count = 1;
789 esrc->fes_flags |= FIB_ENTRY_SRC_FLAG_INHERITED;
790 esrc->fes_flags &= ~(FIB_ENTRY_SRC_FLAG_ACTIVE |
791 FIB_ENTRY_SRC_FLAG_CONTRIBUTING);
792 esrc->fes_entry_flags &= ~FIB_ENTRY_FLAG_COVERED_INHERIT;
795 * the source owns a lock on the entry
797 fib_path_list_lock(esrc->fes_pl);
798 fib_entry_lock(fib_entry_get_index(fib_entry));
804 * fib_entry_src_action_update
806 * copy a source data from another entry to this one
808 static fib_entry_src_t *
809 fib_entry_src_action_update_from_cover (fib_entry_t *fib_entry,
810 const fib_entry_src_t *orig_src)
812 fib_entry_src_t *esrc;
814 esrc = fib_entry_src_find_or_create(fib_entry,
816 orig_src->fes_entry_flags);
819 * the source owns a lock on the entry
821 fib_path_list_unlock(esrc->fes_pl);
822 esrc->fes_pl = orig_src->fes_pl;
823 fib_path_list_lock(esrc->fes_pl);
828 static fib_table_walk_rc_t
829 fib_entry_src_covered_inherit_add_i (fib_entry_t *fib_entry,
830 const fib_entry_src_t *cover_src)
832 fib_entry_src_t *esrc;
834 esrc = fib_entry_src_find(fib_entry, cover_src->fes_src);
836 if (cover_src == esrc)
838 return (FIB_TABLE_WALK_CONTINUE);
844 * the covered entry already has this source.
846 if (esrc->fes_entry_flags & FIB_ENTRY_FLAG_COVERED_INHERIT)
849 * the covered source is itself a COVERED_INHERIT, i.e.
850 * it also pushes this source down the sub-tree.
851 * We consider this more specific covered to be the owner
852 * of the sub-tree from this point down.
854 return (FIB_TABLE_WALK_SUB_TREE_STOP);
856 if (esrc->fes_flags & FIB_ENTRY_SRC_FLAG_INHERITED)
859 * The covered's source data has been inherited, presumably
860 * from this cover, i.e. this is a modify.
862 esrc = fib_entry_src_action_update_from_cover(fib_entry, cover_src);
863 fib_entry_source_change(fib_entry, esrc->fes_src, esrc->fes_src);
868 * The covered's source was not inherited and it is also
869 * not inheriting. Nevertheless, it still owns the sub-tree from
872 return (FIB_TABLE_WALK_SUB_TREE_STOP);
878 * The covered does not have this source - add it.
880 fib_source_t best_source;
882 best_source = fib_entry_get_best_source(
883 fib_entry_get_index(fib_entry));
885 fib_entry_src_action_copy(fib_entry, cover_src);
886 fib_entry_source_change(fib_entry, best_source, cover_src->fes_src);
889 return (FIB_TABLE_WALK_CONTINUE);
892 static fib_table_walk_rc_t
893 fib_entry_src_covered_inherit_walk_add (fib_node_index_t fei,
896 return (fib_entry_src_covered_inherit_add_i(fib_entry_get(fei), ctx));
899 static fib_table_walk_rc_t
900 fib_entry_src_covered_inherit_walk_remove (fib_node_index_t fei,
903 fib_entry_src_t *cover_src, *esrc;
904 fib_entry_t *fib_entry;
906 fib_entry = fib_entry_get(fei);
909 esrc = fib_entry_src_find(fib_entry, cover_src->fes_src);
911 if (cover_src == esrc)
913 return (FIB_TABLE_WALK_CONTINUE);
919 * the covered entry already has this source.
921 if (esrc->fes_entry_flags & FIB_ENTRY_FLAG_COVERED_INHERIT)
924 * the covered source is itself a COVERED_INHERIT, i.e.
925 * it also pushes this source down the sub-tree.
926 * We consider this more specific covered to be the owner
927 * of the sub-tree from this point down.
929 return (FIB_TABLE_WALK_SUB_TREE_STOP);
931 if (esrc->fes_flags & FIB_ENTRY_SRC_FLAG_INHERITED)
934 * The covered's source data has been inherited, presumably
937 fib_entry_src_flag_t remaining;
939 remaining = fib_entry_special_remove(fei, cover_src->fes_src);
941 ASSERT(FIB_ENTRY_SRC_FLAG_ADDED == remaining);
946 * The covered's source was not inherited and it is also
947 * not inheriting. Nevertheless, it still owns the sub-tree from
950 return (FIB_TABLE_WALK_SUB_TREE_STOP);
956 * The covered does not have this source - that's an error,
957 * since it should have inherited, but there is nothing we can do
961 return (FIB_TABLE_WALK_CONTINUE);
965 fib_entry_src_inherit (const fib_entry_t *cover,
966 fib_entry_t *covered)
968 CLIB_UNUSED(fib_source_t source);
969 const fib_entry_src_t *src;
971 FOR_EACH_SRC_ADDED(cover, src, source,
973 if ((src->fes_entry_flags & FIB_ENTRY_FLAG_COVERED_INHERIT) ||
974 (src->fes_flags & FIB_ENTRY_SRC_FLAG_INHERITED))
976 fib_entry_src_covered_inherit_add_i(covered, src);
982 fib_entry_src_covered_inherit_add (fib_entry_t *fib_entry,
986 fib_entry_src_t *esrc;
988 esrc = fib_entry_src_find(fib_entry, source);
990 ASSERT(esrc->fes_flags & FIB_ENTRY_SRC_FLAG_ACTIVE);
992 if ((esrc->fes_entry_flags & FIB_ENTRY_FLAG_COVERED_INHERIT) ||
993 (esrc->fes_flags & FIB_ENTRY_SRC_FLAG_INHERITED))
995 fib_table_sub_tree_walk(fib_entry->fe_fib_index,
996 fib_entry->fe_prefix.fp_proto,
997 &fib_entry->fe_prefix,
998 fib_entry_src_covered_inherit_walk_add,
1004 fib_entry_src_covered_inherit_remove (fib_entry_t *fib_entry,
1005 fib_entry_src_t *esrc)
1008 ASSERT(!(esrc->fes_flags & FIB_ENTRY_SRC_FLAG_ACTIVE));
1010 if (esrc->fes_entry_flags & FIB_ENTRY_FLAG_COVERED_INHERIT)
1012 fib_table_sub_tree_walk(fib_entry->fe_fib_index,
1013 fib_entry->fe_prefix.fp_proto,
1014 &fib_entry->fe_prefix,
1015 fib_entry_src_covered_inherit_walk_remove,
1021 fib_entry_src_action_activate (fib_entry_t *fib_entry,
1022 fib_source_t source)
1025 int houston_we_are_go_for_install;
1026 const fib_entry_src_vft_t *vft;
1027 fib_entry_src_t *esrc;
1029 esrc = fib_entry_src_find(fib_entry, source);
1031 ASSERT(!(esrc->fes_flags & FIB_ENTRY_SRC_FLAG_ACTIVE));
1032 ASSERT(esrc->fes_flags & FIB_ENTRY_SRC_FLAG_ADDED);
1034 esrc->fes_flags |= (FIB_ENTRY_SRC_FLAG_ACTIVE |
1035 FIB_ENTRY_SRC_FLAG_CONTRIBUTING);
1036 vft = fib_entry_src_get_vft(esrc);
1038 if (NULL != vft->fesv_activate)
1040 houston_we_are_go_for_install = vft->fesv_activate(esrc, fib_entry);
1045 * the source is not providing an activate function, we'll assume
1046 * therefore it has no objection to installing the entry
1048 houston_we_are_go_for_install = !0;
1052 * link to the path-list provided by the source, and go check
1053 * if that forms any loops in the graph.
1055 fib_entry->fe_parent = esrc->fes_pl;
1056 fib_entry->fe_sibling =
1057 fib_path_list_child_add(fib_entry->fe_parent,
1058 FIB_NODE_TYPE_ENTRY,
1059 fib_entry_get_index(fib_entry));
1061 fib_entry_recursive_loop_detect_i(fib_entry->fe_parent);
1063 FIB_ENTRY_DBG(fib_entry, "activate: %d",
1064 fib_entry->fe_parent);
1067 * If this source should push its state to covered prefixs, do that now.
1069 fib_entry_src_covered_inherit_add(fib_entry, source);
1071 if (0 != houston_we_are_go_for_install)
1073 fib_entry_src_action_install(fib_entry, source);
1077 fib_entry_src_action_uninstall(fib_entry);
1082 fib_entry_src_action_deactivate (fib_entry_t *fib_entry,
1083 fib_source_t source)
1086 fib_node_index_t path_list_index;
1087 fib_entry_src_t *esrc;
1089 esrc = fib_entry_src_find(fib_entry, source);
1091 ASSERT(esrc->fes_flags & FIB_ENTRY_SRC_FLAG_ACTIVE);
1093 FIB_ENTRY_SRC_VFT_INVOKE(esrc, fesv_deactivate,
1096 esrc->fes_flags &= ~(FIB_ENTRY_SRC_FLAG_ACTIVE |
1097 FIB_ENTRY_SRC_FLAG_CONTRIBUTING);
1099 FIB_ENTRY_DBG(fib_entry, "deactivate: %d", fib_entry->fe_parent);
1102 * If this source should pull its state from covered prefixs, do that now.
1103 * If this source also has the INHERITED flag set then it has a cover
1104 * that wants to push down forwarding. We only want the covereds to see
1107 fib_entry_src_covered_inherit_remove(fib_entry, esrc);
1110 * un-link from an old path-list. Check for any loops this will clear
1112 path_list_index = fib_entry->fe_parent;
1113 fib_entry->fe_parent = FIB_NODE_INDEX_INVALID;
1115 fib_entry_recursive_loop_detect_i(path_list_index);
1118 * this will unlock the path-list, so it may be invalid thereafter.
1120 fib_path_list_child_remove(path_list_index, fib_entry->fe_sibling);
1121 fib_entry->fe_sibling = FIB_NODE_INDEX_INVALID;
1125 fib_entry_src_action_fwd_update (const fib_entry_t *fib_entry,
1126 fib_source_t source)
1128 fib_entry_src_t *esrc;
1130 vec_foreach(esrc, fib_entry->fe_srcs)
1132 FIB_ENTRY_SRC_VFT_INVOKE(esrc, fesv_fwd_update,
1133 (esrc, fib_entry, source));
1138 fib_entry_src_action_reactivate (fib_entry_t *fib_entry,
1139 fib_source_t source)
1141 fib_node_index_t path_list_index;
1142 const fib_entry_src_vft_t *vft;
1143 fib_entry_src_t *esrc;
1144 int remain_installed;
1146 esrc = fib_entry_src_find(fib_entry, source);
1148 ASSERT(esrc->fes_flags & FIB_ENTRY_SRC_FLAG_ACTIVE);
1150 FIB_ENTRY_DBG(fib_entry, "reactivate: %d to %d",
1151 fib_entry->fe_parent,
1155 * call the source to reactive and get the go/no-go to remain installed
1157 vft = fib_entry_src_get_vft(esrc);
1159 if (NULL != vft->fesv_reactivate)
1161 remain_installed = vft->fesv_reactivate(esrc, fib_entry);
1165 remain_installed = 1;
1168 if (fib_entry->fe_parent != esrc->fes_pl)
1171 * un-link from an old path-list. Check for any loops this will clear
1173 path_list_index = fib_entry->fe_parent;
1174 fib_entry->fe_parent = FIB_NODE_INDEX_INVALID;
1177 * temporary lock so it doesn't get deleted when this entry is no
1180 fib_path_list_lock(path_list_index);
1183 * this entry is no longer a child. after unlinking check if any loops
1186 fib_path_list_child_remove(path_list_index,
1187 fib_entry->fe_sibling);
1189 fib_entry_recursive_loop_detect_i(path_list_index);
1192 * link to the path-list provided by the source, and go check
1193 * if that forms any loops in the graph.
1195 fib_entry->fe_parent = esrc->fes_pl;
1196 fib_entry->fe_sibling =
1197 fib_path_list_child_add(fib_entry->fe_parent,
1198 FIB_NODE_TYPE_ENTRY,
1199 fib_entry_get_index(fib_entry));
1201 fib_entry_recursive_loop_detect_i(fib_entry->fe_parent);
1202 fib_path_list_unlock(path_list_index);
1205 * If this source should push its state to covered prefixs, do that now.
1207 fib_entry_src_covered_inherit_add(fib_entry, source);
1210 if (!remain_installed)
1212 fib_entry_src_action_uninstall(fib_entry);
1216 fib_entry_src_action_install(fib_entry, source);
1218 fib_entry_src_action_fwd_update(fib_entry, source);
1222 fib_entry_src_action_installed (const fib_entry_t *fib_entry,
1223 fib_source_t source)
1225 fib_entry_src_t *esrc;
1227 esrc = fib_entry_src_find(fib_entry, source);
1229 FIB_ENTRY_SRC_VFT_INVOKE(esrc, fesv_installed,
1232 fib_entry_src_action_fwd_update(fib_entry, source);
1236 * fib_entry_src_action_add
1238 * Adding a source can result in a new fib_entry being created, which
1239 * can inturn mean the pool is realloc'd and thus the entry passed as
1240 * an argument it also realloc'd
1241 * @return the original entry
1244 fib_entry_src_action_add (fib_entry_t *fib_entry,
1245 fib_source_t source,
1246 fib_entry_flag_t flags,
1247 const dpo_id_t *dpo)
1249 fib_node_index_t fib_entry_index;
1250 fib_entry_src_t *esrc;
1252 esrc = fib_entry_src_find_or_create(fib_entry, source, flags);
1254 ASSERT(esrc->fes_ref_count < 255);
1255 esrc->fes_ref_count++;
1257 if (flags != esrc->fes_entry_flags)
1259 FIB_ENTRY_SRC_VFT_INVOKE(esrc, fesv_flags_change,
1260 (esrc, fib_entry, flags));
1262 esrc->fes_entry_flags = flags;
1264 if (1 != esrc->fes_ref_count)
1267 * we only want to add the source on the 0->1 transition
1273 * save variable so we can recover from a fib_entry realloc.
1275 fib_entry_index = fib_entry_get_index(fib_entry);
1277 FIB_ENTRY_SRC_VFT_INVOKE(esrc, fesv_add,
1281 fib_entry_get_dpo_proto(fib_entry),
1284 fib_entry = fib_entry_get(fib_entry_index);
1286 esrc->fes_flags |= FIB_ENTRY_SRC_FLAG_ADDED;
1288 fib_path_list_lock(esrc->fes_pl);
1291 * the source owns a lock on the entry
1293 fib_entry_lock(fib_entry_get_index(fib_entry));
1299 * fib_entry_src_action_update
1301 * Adding a source can result in a new fib_entry being created, which
1302 * can inturn mean the pool is realloc'd and thus the entry passed as
1303 * an argument it also realloc'd
1304 * @return the original entry
1307 fib_entry_src_action_update (fib_entry_t *fib_entry,
1308 fib_source_t source,
1309 fib_entry_flag_t flags,
1310 const dpo_id_t *dpo)
1312 fib_node_index_t fib_entry_index, old_path_list_index;
1313 fib_entry_src_t *esrc;
1315 esrc = fib_entry_src_find_or_create(fib_entry, source, flags);
1319 return (fib_entry_src_action_add(fib_entry, source, flags, dpo));
1322 old_path_list_index = esrc->fes_pl;
1323 esrc->fes_entry_flags = flags;
1326 * save variable so we can recover from a fib_entry realloc.
1328 fib_entry_index = fib_entry_get_index(fib_entry);
1330 FIB_ENTRY_SRC_VFT_INVOKE(esrc, fesv_add,
1334 fib_entry_get_dpo_proto(fib_entry),
1337 fib_entry = fib_entry_get(fib_entry_index);
1339 esrc->fes_flags |= FIB_ENTRY_SRC_FLAG_ADDED;
1341 fib_path_list_lock(esrc->fes_pl);
1342 fib_path_list_unlock(old_path_list_index);
1347 fib_entry_src_flag_t
1348 fib_entry_src_action_remove_or_update_inherit (fib_entry_t *fib_entry,
1349 fib_source_t source)
1351 fib_entry_src_t *esrc;
1353 esrc = fib_entry_src_find(fib_entry, source);
1356 return (FIB_ENTRY_SRC_FLAG_ACTIVE);
1358 if ((esrc->fes_entry_flags & FIB_ENTRY_FLAG_COVERED_INHERIT) &&
1359 (esrc->fes_flags & FIB_ENTRY_SRC_FLAG_INHERITED))
1361 fib_entry_src_t *cover_src;
1362 fib_node_index_t coveri;
1366 * this source was pushing inherited state, but so is its
1367 * cover. Now that this source is going away, we need to
1368 * pull the covers forwarding and use it to update the covereds.
1369 * Go grab the path-list from the cover, rather than start a walk from
1370 * the cover, so we don't recursively update this entry.
1372 coveri = fib_table_get_less_specific(fib_entry->fe_fib_index,
1373 &fib_entry->fe_prefix);
1376 * only the default route has itself as its own cover, but the
1377 * default route cannot have inherited from something else.
1379 ASSERT(coveri != fib_entry_get_index(fib_entry));
1381 cover = fib_entry_get(coveri);
1382 cover_src = fib_entry_src_find(cover, source);
1384 ASSERT(NULL != cover_src);
1386 esrc = fib_entry_src_action_update_from_cover(fib_entry, cover_src);
1387 esrc->fes_entry_flags &= ~FIB_ENTRY_FLAG_COVERED_INHERIT;
1390 * Now push the new state from the cover down to the covereds
1392 fib_entry_src_covered_inherit_add(fib_entry, source);
1394 return (esrc->fes_flags);
1398 return (fib_entry_src_action_remove(fib_entry, source));
1402 fib_entry_src_flag_t
1403 fib_entry_src_action_remove (fib_entry_t *fib_entry,
1404 fib_source_t source)
1407 fib_node_index_t old_path_list;
1408 fib_entry_src_flag_t sflags;
1409 fib_entry_src_t *esrc;
1411 esrc = fib_entry_src_find(fib_entry, source);
1414 return (FIB_ENTRY_SRC_FLAG_ACTIVE);
1416 esrc->fes_ref_count--;
1417 sflags = esrc->fes_flags;
1419 if (0 != esrc->fes_ref_count)
1422 * only remove the source on the 1->0 transisition
1427 if (esrc->fes_flags & FIB_ENTRY_SRC_FLAG_ACTIVE)
1429 fib_entry_src_action_deactivate(fib_entry, source);
1431 else if (esrc->fes_flags & FIB_ENTRY_SRC_FLAG_CONTRIBUTING)
1433 FIB_ENTRY_SRC_VFT_INVOKE(esrc, fesv_deactivate,
1435 esrc->fes_flags &= ~FIB_ENTRY_SRC_FLAG_CONTRIBUTING;
1438 old_path_list = esrc->fes_pl;
1440 FIB_ENTRY_SRC_VFT_INVOKE(esrc, fesv_remove, (esrc));
1442 fib_path_list_unlock(old_path_list);
1443 fib_entry_unlock(fib_entry_get_index(fib_entry));
1445 sflags &= ~FIB_ENTRY_SRC_FLAG_ADDED;
1446 fib_entry_src_action_deinit(fib_entry, source);
1452 * fib_route_attached_cross_table
1454 * Return true the the route is attached via an interface that
1455 * is not in the same table as the route
1458 fib_route_attached_cross_table (const fib_entry_t *fib_entry,
1459 const fib_route_path_t *rpath)
1462 * - All zeros next-hop
1463 * - a valid interface
1464 * - entry's fib index not equeal to interface's index
1466 if (ip46_address_is_zero(&rpath->frp_addr) &&
1467 (~0 != rpath->frp_sw_if_index) &&
1468 !(rpath->frp_flags & FIB_ROUTE_PATH_DVR) &&
1469 (fib_entry->fe_fib_index !=
1470 fib_table_get_index_for_sw_if_index(fib_entry_get_proto(fib_entry),
1471 rpath->frp_sw_if_index)))
1479 * Return true if the path is attached
1482 fib_path_is_attached (const fib_route_path_t *rpath)
1485 * DVR paths are not attached, since we are not playing the
1486 * L3 game with these
1488 if (rpath->frp_flags & FIB_ROUTE_PATH_DVR)
1494 * - All zeros next-hop
1495 * - a valid interface
1497 if (ip46_address_is_zero(&rpath->frp_addr) &&
1498 (~0 != rpath->frp_sw_if_index))
1502 else if (rpath->frp_flags & FIB_ROUTE_PATH_ATTACHED)
1509 fib_path_list_flags_t
1510 fib_entry_src_flags_2_path_list_flags (fib_entry_flag_t eflags)
1512 fib_path_list_flags_t plf = FIB_PATH_LIST_FLAG_NONE;
1514 if (eflags & FIB_ENTRY_FLAG_DROP)
1516 plf |= FIB_PATH_LIST_FLAG_DROP;
1518 if (eflags & FIB_ENTRY_FLAG_EXCLUSIVE)
1520 plf |= FIB_PATH_LIST_FLAG_EXCLUSIVE;
1522 if (eflags & FIB_ENTRY_FLAG_LOCAL)
1524 plf |= FIB_PATH_LIST_FLAG_LOCAL;
1531 fib_entry_flags_update (const fib_entry_t *fib_entry,
1532 const fib_route_path_t *rpaths,
1533 fib_path_list_flags_t *pl_flags,
1534 fib_entry_src_t *esrc)
1536 const fib_route_path_t *rpath;
1538 vec_foreach(rpath, rpaths)
1540 if ((esrc->fes_src == FIB_SOURCE_API) ||
1541 (esrc->fes_src == FIB_SOURCE_CLI))
1543 if (fib_path_is_attached(rpath))
1545 esrc->fes_entry_flags |= FIB_ENTRY_FLAG_ATTACHED;
1549 esrc->fes_entry_flags &= ~FIB_ENTRY_FLAG_ATTACHED;
1551 if (rpath->frp_flags & FIB_ROUTE_PATH_DEAG)
1553 esrc->fes_entry_flags |= FIB_ENTRY_FLAG_LOOSE_URPF_EXEMPT;
1556 if (fib_route_attached_cross_table(fib_entry, rpath) &&
1557 !(esrc->fes_entry_flags & FIB_ENTRY_FLAG_NO_ATTACHED_EXPORT))
1559 esrc->fes_entry_flags |= FIB_ENTRY_FLAG_IMPORT;
1563 esrc->fes_entry_flags &= ~FIB_ENTRY_FLAG_IMPORT;
1569 * fib_entry_src_action_add
1571 * Adding a source can result in a new fib_entry being created, which
1572 * can inturn mean the pool is realloc'd and thus the entry passed as
1573 * an argument it also realloc'd
1577 fib_entry_src_action_path_add (fib_entry_t *fib_entry,
1578 fib_source_t source,
1579 fib_entry_flag_t flags,
1580 const fib_route_path_t *rpaths)
1582 fib_node_index_t old_path_list, fib_entry_index;
1583 fib_path_list_flags_t pl_flags;
1584 fib_entry_src_t *esrc;
1587 * save variable so we can recover from a fib_entry realloc.
1589 fib_entry_index = fib_entry_get_index(fib_entry);
1591 esrc = fib_entry_src_find(fib_entry, source);
1594 const dpo_id_t *dpo;
1596 if (flags == FIB_ENTRY_FLAG_EXCLUSIVE) {
1599 dpo = drop_dpo_get(fib_entry_get_dpo_proto(fib_entry));
1603 fib_entry_src_action_add(fib_entry,
1607 esrc = fib_entry_src_find(fib_entry, source);
1611 * we are no doubt modifying a path-list. If the path-list
1612 * is shared, and hence not modifiable, then the index returned
1613 * will be for a different path-list. This FIB entry to needs
1614 * to maintain its lock appropriately.
1616 old_path_list = esrc->fes_pl;
1618 ASSERT(FIB_ENTRY_SRC_VFT_EXISTS(esrc, fesv_path_add));
1620 pl_flags = fib_entry_src_flags_2_path_list_flags(fib_entry_get_flags_i(fib_entry));
1621 fib_entry_flags_update(fib_entry, rpaths, &pl_flags, esrc);
1623 FIB_ENTRY_SRC_VFT_INVOKE(esrc, fesv_path_add,
1624 (esrc, fib_entry, pl_flags, rpaths));
1625 fib_entry = fib_entry_get(fib_entry_index);
1627 fib_path_list_lock(esrc->fes_pl);
1628 fib_path_list_unlock(old_path_list);
1634 * fib_entry_src_action_swap
1636 * The source is providing new paths to replace the old ones.
1637 * Adding a source can result in a new fib_entry being created, which
1638 * can inturn mean the pool is realloc'd and thus the entry passed as
1639 * an argument it also realloc'd
1643 fib_entry_src_action_path_swap (fib_entry_t *fib_entry,
1644 fib_source_t source,
1645 fib_entry_flag_t flags,
1646 const fib_route_path_t *rpaths)
1648 fib_node_index_t old_path_list, fib_entry_index;
1649 fib_path_list_flags_t pl_flags;
1650 fib_entry_src_t *esrc;
1652 esrc = fib_entry_src_find(fib_entry, source);
1655 * save variable so we can recover from a fib_entry realloc.
1657 fib_entry_index = fib_entry_get_index(fib_entry);
1661 const dpo_id_t *dpo;
1663 if (flags == FIB_ENTRY_FLAG_EXCLUSIVE) {
1666 dpo = drop_dpo_get(fib_entry_get_dpo_proto(fib_entry));
1669 fib_entry = fib_entry_src_action_add(fib_entry,
1673 esrc = fib_entry_src_find(fib_entry, source);
1677 if (flags != esrc->fes_entry_flags)
1679 FIB_ENTRY_SRC_VFT_INVOKE(esrc, fesv_flags_change,
1680 (esrc, fib_entry, flags));
1682 esrc->fes_entry_flags = flags;
1686 * swapping paths may create a new path-list (or may use an existing shared)
1687 * but we are certainly getting a different one. This FIB entry to needs
1688 * to maintain its lock appropriately.
1690 old_path_list = esrc->fes_pl;
1692 ASSERT(FIB_ENTRY_SRC_VFT_EXISTS(esrc, fesv_path_swap));
1694 pl_flags = fib_entry_src_flags_2_path_list_flags(flags);
1696 fib_entry_flags_update(fib_entry, rpaths, &pl_flags, esrc);
1698 FIB_ENTRY_SRC_VFT_INVOKE(esrc, fesv_path_swap,
1702 fib_entry = fib_entry_get(fib_entry_index);
1704 fib_path_list_lock(esrc->fes_pl);
1705 fib_path_list_unlock(old_path_list);
1710 fib_entry_src_flag_t
1711 fib_entry_src_action_path_remove (fib_entry_t *fib_entry,
1712 fib_source_t source,
1713 const fib_route_path_t *rpaths)
1715 fib_path_list_flags_t pl_flags;
1716 fib_node_index_t old_path_list;
1717 fib_entry_src_t *esrc;
1719 esrc = fib_entry_src_find(fib_entry, source);
1721 ASSERT(NULL != esrc);
1722 ASSERT(esrc->fes_flags & FIB_ENTRY_SRC_FLAG_ADDED);
1725 * we no doubt modifying a path-list. If the path-list
1726 * is shared, and hence not modifiable, then the index returned
1727 * will be for a different path-list. This FIB entry to needs
1728 * to maintain its lock appropriately.
1730 old_path_list = esrc->fes_pl;
1732 ASSERT(FIB_ENTRY_SRC_VFT_EXISTS(esrc, fesv_path_remove));
1734 pl_flags = fib_entry_src_flags_2_path_list_flags(fib_entry_get_flags_i(fib_entry));
1735 fib_entry_flags_update(fib_entry, rpaths, &pl_flags, esrc);
1737 FIB_ENTRY_SRC_VFT_INVOKE(esrc, fesv_path_remove,
1738 (esrc, pl_flags, rpaths));
1741 * lock the new path-list, unlock the old if it had one
1743 fib_path_list_unlock(old_path_list);
1745 if (FIB_NODE_INDEX_INVALID != esrc->fes_pl) {
1746 fib_path_list_lock(esrc->fes_pl);
1747 return (FIB_ENTRY_SRC_FLAG_ADDED);
1752 * no more paths left from this source
1754 fib_entry_src_action_remove_or_update_inherit(fib_entry, source);
1755 return (FIB_ENTRY_SRC_FLAG_NONE);
1760 fib_entry_src_format (fib_entry_t *fib_entry,
1761 fib_source_t source,
1764 fib_entry_src_t *esrc;
1766 esrc = fib_entry_src_find(fib_entry, source);
1768 FIB_ENTRY_SRC_VFT_INVOKE_AND_RETURN(esrc, fesv_format, (esrc, s));
1774 fib_entry_get_adj_for_source (fib_node_index_t fib_entry_index,
1775 fib_source_t source)
1777 fib_entry_t *fib_entry;
1778 fib_entry_src_t *esrc;
1780 if (FIB_NODE_INDEX_INVALID == fib_entry_index)
1781 return (ADJ_INDEX_INVALID);
1783 fib_entry = fib_entry_get(fib_entry_index);
1784 esrc = fib_entry_src_find(fib_entry, source);
1788 if (FIB_NODE_INDEX_INVALID != esrc->fes_pl)
1790 return (fib_path_list_get_adj(
1792 fib_entry_get_default_chain_type(fib_entry)));
1795 return (ADJ_INDEX_INVALID);
1799 fib_entry_get_dpo_for_source (fib_node_index_t fib_entry_index,
1800 fib_source_t source,
1803 fib_entry_t *fib_entry;
1804 fib_entry_src_t *esrc;
1806 if (FIB_NODE_INDEX_INVALID == fib_entry_index)
1809 fib_entry = fib_entry_get(fib_entry_index);
1810 esrc = fib_entry_src_find(fib_entry, source);
1814 if (FIB_NODE_INDEX_INVALID != esrc->fes_pl)
1816 fib_path_list_contribute_forwarding(
1818 fib_entry_get_default_chain_type(fib_entry),
1819 FIB_PATH_LIST_FWD_FLAG_NONE,
1822 return (dpo_id_is_valid(dpo));
1829 fib_entry_get_resolving_interface_for_source (fib_node_index_t entry_index,
1830 fib_source_t source)
1832 fib_entry_t *fib_entry;
1833 fib_entry_src_t *esrc;
1835 fib_entry = fib_entry_get(entry_index);
1837 esrc = fib_entry_src_find(fib_entry, source);
1841 if (FIB_NODE_INDEX_INVALID != esrc->fes_pl)
1843 return (fib_path_list_get_resolving_interface(esrc->fes_pl));
1850 fib_entry_get_flags_for_source (fib_node_index_t entry_index,
1851 fib_source_t source)
1853 fib_entry_t *fib_entry;
1854 fib_entry_src_t *esrc;
1856 fib_entry = fib_entry_get(entry_index);
1858 esrc = fib_entry_src_find(fib_entry, source);
1862 return (esrc->fes_entry_flags);
1865 return (FIB_ENTRY_FLAG_NONE);
1869 fib_entry_get_source_i (const fib_entry_t *fib_entry)
1871 /* the vector of sources is deliberately arranged in priority order */
1872 if (0 == vec_len(fib_entry->fe_srcs))
1873 return (FIB_SOURCE_INVALID);
1874 return (vec_elt(fib_entry->fe_srcs, 0).fes_src);
1878 fib_entry_get_flags_i (const fib_entry_t *fib_entry)
1880 /* the vector of sources is deliberately arranged in priority order */
1881 if (0 == vec_len(fib_entry->fe_srcs))
1882 return (FIB_ENTRY_FLAG_NONE);
1883 return (vec_elt(fib_entry->fe_srcs, 0).fes_entry_flags);
1887 fib_entry_set_source_data (fib_node_index_t fib_entry_index,
1888 fib_source_t source,
1891 fib_entry_t *fib_entry;
1892 fib_entry_src_t *esrc;
1894 fib_entry = fib_entry_get(fib_entry_index);
1895 esrc = fib_entry_src_find(fib_entry, source);
1899 FIB_ENTRY_SRC_VFT_INVOKE(esrc, fesv_set_data,
1900 (esrc, fib_entry, data));
1905 fib_entry_get_source_data (fib_node_index_t fib_entry_index,
1906 fib_source_t source)
1908 fib_entry_t *fib_entry;
1909 fib_entry_src_t *esrc;
1911 fib_entry = fib_entry_get(fib_entry_index);
1912 esrc = fib_entry_src_find(fib_entry, source);
1916 FIB_ENTRY_SRC_VFT_INVOKE_AND_RETURN(esrc, fesv_get_data,
1923 fib_entry_src_module_init (void)
1925 fib_entry_src_rr_register();
1926 fib_entry_src_interface_register();
1927 fib_entry_src_interpose_register();
1928 fib_entry_src_default_route_register();
1929 fib_entry_src_special_register();
1930 fib_entry_src_api_register();
1931 fib_entry_src_adj_register();
1932 fib_entry_src_mpls_register();
1933 fib_entry_src_lisp_register();