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_bh_vft[FIB_SOURCE_BH_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 fib_source_behaviour_t bh;
42 bh = fib_source_get_behaviour(esrc->fes_src);
44 if (esrc->fes_entry_flags & FIB_ENTRY_FLAG_INTERPOSE)
46 return (&fib_entry_src_bh_vft[FIB_SOURCE_BH_INTERPOSE]);
49 return (&fib_entry_src_bh_vft[bh]);
53 fib_entry_src_copy_default (const fib_entry_src_t *orig_src,
54 const fib_entry_t *fib_entry,
55 fib_entry_src_t *copy_src)
57 clib_memcpy(©_src->u, &orig_src->u, sizeof(copy_src->u));
61 fib_entry_src_behaviour_register (fib_source_behaviour_t bh,
62 const fib_entry_src_vft_t *vft)
64 fib_entry_src_bh_vft[bh] = *vft;
66 if (NULL == fib_entry_src_bh_vft[bh].fesv_copy)
68 fib_entry_src_bh_vft[bh].fesv_copy = fib_entry_src_copy_default;
73 fib_entry_src_cmp_for_sort (void * v1,
76 fib_entry_src_t *esrc1 = v1, *esrc2 = v2;
78 return (fib_source_get_prio(esrc1->fes_src) -
79 fib_source_get_prio(esrc2->fes_src));
83 fib_entry_src_action_init (fib_entry_t *fib_entry,
85 fib_entry_flag_t flags)
87 fib_entry_src_t esrc = {
88 .fes_pl = FIB_NODE_INDEX_INVALID,
89 .fes_flags = FIB_ENTRY_SRC_FLAG_NONE,
91 .fes_entry_flags = flags,
94 FIB_ENTRY_SRC_VFT_INVOKE(fib_entry, &esrc, fesv_init, (&esrc));
96 vec_add1(fib_entry->fe_srcs, esrc);
97 vec_sort_with_function(fib_entry->fe_srcs,
98 fib_entry_src_cmp_for_sort);
101 static fib_entry_src_t *
102 fib_entry_src_find_i (const fib_entry_t *fib_entry,
107 fib_entry_src_t *esrc;
111 vec_foreach(esrc, fib_entry->fe_srcs)
113 if (esrc->fes_src == source)
131 fib_entry_src_find (const fib_entry_t *fib_entry,
135 return (fib_entry_src_find_i(fib_entry, source, NULL));
139 fib_entry_is_sourced (fib_node_index_t fib_entry_index,
142 fib_entry_t *fib_entry;
144 fib_entry = fib_entry_get(fib_entry_index);
146 return (NULL != fib_entry_src_find(fib_entry, source));
150 fib_entry_is_marked (fib_node_index_t fib_entry_index,
153 fib_entry_t *fib_entry;
154 fib_entry_src_t *esrc;
156 fib_entry = fib_entry_get(fib_entry_index);
158 esrc = fib_entry_src_find(fib_entry, source);
166 return (!!(esrc->fes_flags & FIB_ENTRY_SRC_FLAG_STALE));
171 fib_entry_mark (fib_node_index_t fib_entry_index,
174 fib_entry_t *fib_entry;
175 fib_entry_src_t *esrc;
177 fib_entry = fib_entry_get(fib_entry_index);
179 esrc = fib_entry_src_find(fib_entry, source);
183 esrc->fes_flags |= FIB_ENTRY_SRC_FLAG_STALE;
187 static fib_entry_src_t *
188 fib_entry_src_find_or_create (fib_entry_t *fib_entry,
190 fib_entry_flag_t flags)
192 fib_entry_src_t *esrc;
194 esrc = fib_entry_src_find(fib_entry, source);
198 fib_entry_src_action_init(fib_entry, source, flags);
201 return (fib_entry_src_find(fib_entry, source));
205 fib_entry_src_action_deinit (fib_entry_t *fib_entry,
209 fib_entry_src_t *esrc;
212 esrc = fib_entry_src_find_i(fib_entry, source, &index);
214 ASSERT(NULL != esrc);
216 FIB_ENTRY_SRC_VFT_INVOKE(fib_entry, esrc, fesv_deinit, (esrc));
218 fib_path_ext_list_flush(&esrc->fes_path_exts);
219 vec_del1(fib_entry->fe_srcs, index);
220 vec_sort_with_function(fib_entry->fe_srcs,
221 fib_entry_src_cmp_for_sort);
224 fib_entry_src_cover_res_t
225 fib_entry_src_action_cover_change (fib_entry_t *fib_entry,
226 fib_entry_src_t *esrc)
228 FIB_ENTRY_SRC_VFT_INVOKE_AND_RETURN(esrc, fesv_cover_change,
231 fib_entry_src_cover_res_t res = {
233 .bw_reason = FIB_NODE_BW_REASON_FLAG_NONE,
238 fib_entry_src_cover_res_t
239 fib_entry_src_action_cover_update (fib_entry_t *fib_entry,
240 fib_entry_src_t *esrc)
242 FIB_ENTRY_SRC_VFT_INVOKE_AND_RETURN(esrc, fesv_cover_update,
245 fib_entry_src_cover_res_t res = {
247 .bw_reason = FIB_NODE_BW_REASON_FLAG_NONE,
252 typedef struct fib_entry_src_collect_forwarding_ctx_t_
254 load_balance_path_t *next_hops;
255 const fib_entry_t *fib_entry;
256 i32 start_source_index, end_source_index;
257 fib_forward_chain_type_t fct;
258 int n_recursive_constrained;
260 dpo_proto_t payload_proto;
261 } fib_entry_src_collect_forwarding_ctx_t;
264 * @brief Determine whether this FIB entry should use a load-balance MAP
265 * to support PIC edge fast convergence
267 static load_balance_flags_t
268 fib_entry_calc_lb_flags (fib_entry_src_collect_forwarding_ctx_t *ctx,
269 const fib_entry_src_t *esrc)
272 * We'll use a LB map if the path-list has multiple recursive paths.
273 * recursive paths implies BGP, and hence scale.
275 if (ctx->n_recursive_constrained > 1 &&
276 fib_path_list_is_popular(esrc->fes_pl))
278 return (LOAD_BALANCE_FLAG_USES_MAP);
280 return (LOAD_BALANCE_FLAG_NONE);
284 fib_entry_src_valid_out_label (mpls_label_t label)
286 return ((MPLS_LABEL_IS_REAL(label) ||
287 MPLS_LABEL_POP == label ||
288 MPLS_IETF_IPV4_EXPLICIT_NULL_LABEL == label ||
289 MPLS_IETF_IPV6_EXPLICIT_NULL_LABEL == label ||
290 MPLS_IETF_IMPLICIT_NULL_LABEL == label));
294 fib_prefix_get_payload_proto (const fib_prefix_t *pfx)
296 switch (pfx->fp_proto)
298 case FIB_PROTOCOL_IP4:
299 return (DPO_PROTO_IP4);
300 case FIB_PROTOCOL_IP6:
301 return (DPO_PROTO_IP6);
302 case FIB_PROTOCOL_MPLS:
303 return (pfx->fp_payload_proto);
307 return (DPO_PROTO_IP4);
311 fib_entry_src_get_path_forwarding (fib_node_index_t path_index,
312 fib_entry_src_collect_forwarding_ctx_t *ctx)
314 load_balance_path_t *nh;
317 * no extension => no out-going label for this path. that's OK
318 * in the case of an IP or EOS chain, but not for non-EOS
322 case FIB_FORW_CHAIN_TYPE_UNICAST_IP4:
323 case FIB_FORW_CHAIN_TYPE_UNICAST_IP6:
324 case FIB_FORW_CHAIN_TYPE_MCAST_IP4:
325 case FIB_FORW_CHAIN_TYPE_MCAST_IP6:
326 case FIB_FORW_CHAIN_TYPE_BIER:
328 * EOS traffic with no label to stack, we need the IP Adj
330 vec_add2(ctx->next_hops, nh, 1);
332 nh->path_index = path_index;
333 nh->path_weight = fib_path_get_weight(path_index);
334 fib_path_contribute_forwarding(path_index, ctx->fct,
335 ctx->payload_proto, &nh->path_dpo);
338 case FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS:
339 if (fib_path_is_exclusive(path_index) ||
340 fib_path_is_deag(path_index))
342 vec_add2(ctx->next_hops, nh, 1);
344 nh->path_index = path_index;
345 nh->path_weight = fib_path_get_weight(path_index);
346 fib_path_contribute_forwarding(path_index,
347 FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS,
352 case FIB_FORW_CHAIN_TYPE_MPLS_EOS:
355 * no label. we need a chain based on the payload. fixup.
357 vec_add2(ctx->next_hops, nh, 1);
359 nh->path_index = path_index;
360 nh->path_weight = fib_path_get_weight(path_index);
361 fib_path_contribute_forwarding(path_index,
365 fib_path_stack_mpls_disp(path_index,
367 FIB_MPLS_LSP_MODE_PIPE,
372 case FIB_FORW_CHAIN_TYPE_ETHERNET:
373 case FIB_FORW_CHAIN_TYPE_NSH:
379 static fib_path_list_walk_rc_t
380 fib_entry_src_collect_forwarding (fib_node_index_t pl_index,
381 fib_node_index_t path_index,
384 fib_entry_src_collect_forwarding_ctx_t *ctx;
385 const fib_entry_src_t *esrc;
386 fib_path_ext_t *path_ext;
390 n_nhs = vec_len(ctx->next_hops);
393 * walk the paths and extension of the best non-interpose source
395 esrc = &ctx->fib_entry->fe_srcs[ctx->end_source_index];
398 * if the path is not resolved, don't include it.
400 if (!fib_path_is_resolved(path_index))
402 return (FIB_PATH_LIST_WALK_CONTINUE);
405 if (fib_path_is_recursive_constrained(path_index))
407 ctx->n_recursive_constrained += 1;
409 if (0xffff == ctx->preference)
412 * not set a preference yet, so the first path we encounter
413 * sets the preference we are collecting.
415 ctx->preference = fib_path_get_preference(path_index);
417 else if (ctx->preference != fib_path_get_preference(path_index))
420 * this path does not belong to the same preference as the
421 * previous paths encountered. we are done now.
423 return (FIB_PATH_LIST_WALK_STOP);
427 * get the matching path-extension for the path being visited.
429 path_ext = fib_path_ext_list_find_by_path_index(&esrc->fes_path_exts,
432 if (NULL != path_ext)
434 switch (path_ext->fpe_type)
436 case FIB_PATH_EXT_MPLS:
437 if (fib_entry_src_valid_out_label(path_ext->fpe_label_stack[0].fml_value))
440 * found a matching extension. stack it to obtain the forwarding
441 * info for this path.
444 fib_path_ext_stack(path_ext,
451 fib_entry_src_get_path_forwarding(path_index, ctx);
454 case FIB_PATH_EXT_ADJ:
455 if (FIB_PATH_EXT_ADJ_FLAG_REFINES_COVER & path_ext->fpe_adj_flags)
457 fib_entry_src_get_path_forwarding(path_index, ctx);
461 * the path does not refine the cover, meaning that
462 * the adjacency does/does not match the sub-net on the link.
463 * So this path does not contribute forwarding.
470 fib_entry_src_get_path_forwarding(path_index, ctx);
474 * a this point 'ctx' has the DPO the path contributed, plus
475 * any labels from path extensions.
476 * check if there are any interpose sources that want to contribute
478 if (n_nhs < vec_len(ctx->next_hops))
481 * the path contributed a new choice.
483 const fib_entry_src_vft_t *vft;
486 * roll up the sources that are interposes
490 for (index = ctx->end_source_index;
491 index >= ctx->start_source_index;
494 const dpo_id_t *interposer;
496 esrc = &ctx->fib_entry->fe_srcs[index];
497 vft = fib_entry_src_get_vft(esrc);
499 if (!(esrc->fes_flags & FIB_ENTRY_SRC_FLAG_CONTRIBUTING) ||
500 !(esrc->fes_entry_flags & FIB_ENTRY_FLAG_INTERPOSE))
503 ASSERT(vft->fesv_contribute_interpose);
504 interposer = vft->fesv_contribute_interpose(esrc, ctx->fib_entry);
506 if (NULL != interposer)
508 dpo_id_t clone = DPO_INVALID;
510 dpo_mk_interpose(interposer,
511 &ctx->next_hops[n_nhs].path_dpo,
514 dpo_copy(&ctx->next_hops[n_nhs].path_dpo, &clone);
520 return (FIB_PATH_LIST_WALK_CONTINUE);
524 fib_entry_src_mk_lb (fib_entry_t *fib_entry,
526 fib_forward_chain_type_t fct,
529 const fib_entry_src_t *esrc;
530 dpo_proto_t lb_proto;
534 * The source passed here is the 'best', i.e. the one the client
535 * wants. however, if it's an interpose then it does not contribute
536 * the forwarding, the next best source that is not an interpose does.
537 * So roll down the sources, to find the best non-interpose
539 vec_foreach_index (start, fib_entry->fe_srcs)
541 if (source == fib_entry->fe_srcs[start].fes_src)
544 for (end = start; end < vec_len (fib_entry->fe_srcs); end++)
546 if (!(fib_entry->fe_srcs[end].fes_entry_flags &
547 FIB_ENTRY_FLAG_INTERPOSE) &&
548 (fib_entry->fe_srcs[end].fes_flags &
549 FIB_ENTRY_SRC_FLAG_CONTRIBUTING))
552 if (end == vec_len(fib_entry->fe_srcs))
554 /* didn't find any contributing non-interpose sources */
558 esrc = &fib_entry->fe_srcs[end];
561 * If the entry has path extensions then we construct a load-balance
562 * by stacking the extensions on the forwarding chains of the paths.
563 * Otherwise we use the load-balance of the path-list
565 fib_entry_src_collect_forwarding_ctx_t ctx = {
566 .fib_entry = fib_entry,
568 .n_recursive_constrained = 0,
570 .preference = 0xffff,
571 .start_source_index = start,
572 .end_source_index = end,
573 .payload_proto = fib_prefix_get_payload_proto(&fib_entry->fe_prefix),
577 * As an optimisation we allocate the vector of next-hops to be sized
578 * equal to the maximum number of paths we will need, which is also the
579 * most likely number we will need, since in most cases the paths are 'up'.
581 vec_validate(ctx.next_hops, fib_path_list_get_n_paths(esrc->fes_pl));
582 vec_reset_length(ctx.next_hops);
584 lb_proto = fib_forw_chain_type_to_dpo_proto(fct);
586 fib_path_list_walk(esrc->fes_pl,
587 fib_entry_src_collect_forwarding,
590 if (esrc->fes_entry_flags & FIB_ENTRY_FLAG_EXCLUSIVE)
593 * the client provided the DPO that the entry should link to.
594 * all entries must link to a LB, so if it is an LB already
595 * then we can use it.
597 if ((1 == vec_len(ctx.next_hops)) &&
598 (DPO_LOAD_BALANCE == ctx.next_hops[0].path_dpo.dpoi_type))
600 dpo_copy(dpo_lb, &ctx.next_hops[0].path_dpo);
601 dpo_reset(&ctx.next_hops[0].path_dpo);
606 if (!dpo_id_is_valid(dpo_lb))
611 if (esrc->fes_entry_flags & FIB_ENTRY_FLAG_MULTICAST)
616 MPLS_IS_REPLICATE | replicate_create(0, lb_proto));
620 fib_protocol_t flow_hash_proto;
621 flow_hash_config_t fhc;
624 * if the protocol for the LB we are building does not match that
625 * of the fib_entry (i.e. we are build the [n]EOS LB for an IPv[46]
626 * then the fib_index is not an index that relates to the table
627 * type we need. So get the default flow-hash config instead.
629 flow_hash_proto = dpo_proto_to_fib(lb_proto);
630 if (fib_entry->fe_prefix.fp_proto != flow_hash_proto)
632 fhc = fib_table_get_default_flow_hash_config(flow_hash_proto);
636 fhc = fib_table_get_flow_hash_config(fib_entry->fe_fib_index,
643 load_balance_create(0, lb_proto, fhc));
647 if (esrc->fes_entry_flags & FIB_ENTRY_FLAG_MULTICAST)
652 replicate_multipath_update(dpo_lb, ctx.next_hops);
656 load_balance_multipath_update(dpo_lb,
658 fib_entry_calc_lb_flags(&ctx, esrc));
659 vec_free(ctx.next_hops);
662 * if this entry is sourced by the uRPF-exempt source then we
663 * append the always present local0 interface (index 0) to the
664 * uRPF list so it is not empty. that way packets pass the loose check.
666 index_t ui = fib_path_list_get_urpf(esrc->fes_pl);
668 if ((fib_entry_is_sourced(fib_entry_get_index(fib_entry),
669 FIB_SOURCE_URPF_EXEMPT) ||
670 (esrc->fes_entry_flags & FIB_ENTRY_FLAG_LOOSE_URPF_EXEMPT))&&
671 (0 == fib_urpf_check_size(ui)))
674 * The uRPF list we get from the path-list is shared by all
675 * other users of the list, but the uRPF exemption applies
676 * only to this prefix. So we need our own list.
678 ui = fib_urpf_list_alloc_and_lock();
679 fib_urpf_list_append(ui, 0);
680 fib_urpf_list_bake(ui);
681 load_balance_set_urpf(dpo_lb->dpoi_index, ui);
682 fib_urpf_list_unlock(ui);
686 load_balance_set_urpf(dpo_lb->dpoi_index, ui);
688 load_balance_set_fib_entry_flags(dpo_lb->dpoi_index,
689 fib_entry_get_flags_i(fib_entry));
694 fib_entry_src_action_install (fib_entry_t *fib_entry,
698 * Install the forwarding chain for the given source into the forwarding
701 fib_forward_chain_type_t fct;
704 fct = fib_entry_get_default_chain_type(fib_entry);
707 * Every entry has its own load-balance object. All changes to the entry's
708 * forwarding result in an inplace modify of the load-balance. This means
709 * the load-balance object only needs to be added to the forwarding
710 * DB once, when it is created.
712 insert = !dpo_id_is_valid(&fib_entry->fe_lb);
714 fib_entry_src_mk_lb(fib_entry, source, fct, &fib_entry->fe_lb);
716 ASSERT(dpo_id_is_valid(&fib_entry->fe_lb));
717 FIB_ENTRY_DBG(fib_entry, "install: %d", fib_entry->fe_lb);
720 * insert the adj into the data-plane forwarding trie
724 fib_table_fwding_dpo_update(fib_entry->fe_fib_index,
725 &fib_entry->fe_prefix,
730 * if any of the other chain types are already created they will need
733 fib_entry_delegate_type_t fdt;
734 fib_entry_delegate_t *fed;
736 FOR_EACH_DELEGATE_CHAIN(fib_entry, fdt, fed,
738 fib_entry_src_mk_lb(fib_entry, source,
739 fib_entry_delegate_type_to_chain_type(fdt),
745 fib_entry_src_action_uninstall (fib_entry_t *fib_entry)
748 * uninstall the forwarding chain from the forwarding tables
750 FIB_ENTRY_DBG(fib_entry, "uninstall");
752 if (dpo_id_is_valid(&fib_entry->fe_lb))
754 fib_table_fwding_dpo_remove(
755 fib_entry->fe_fib_index,
756 &fib_entry->fe_prefix,
759 dpo_reset(&fib_entry->fe_lb);
764 fib_entry_recursive_loop_detect_i (fib_node_index_t path_list_index)
766 fib_node_index_t *entries = NULL;
768 fib_path_list_recursive_loop_detect(path_list_index, &entries);
774 * fib_entry_src_action_copy
776 * copy a source data from another entry to this one
779 fib_entry_src_action_copy (fib_entry_t *fib_entry,
780 const fib_entry_src_t *orig_src)
782 fib_entry_src_t *esrc;
784 esrc = fib_entry_src_find_or_create(fib_entry,
786 orig_src->fes_entry_flags);
788 FIB_ENTRY_SRC_VFT_INVOKE(fib_entry, esrc, fesv_copy,
789 (orig_src, fib_entry, esrc));
791 fib_path_list_unlock(esrc->fes_pl);
794 * copy over all the data ...
796 esrc->fes_flags = orig_src->fes_flags;
797 esrc->fes_pl = orig_src->fes_pl;
802 esrc->fes_ref_count = 1;
803 esrc->fes_flags |= FIB_ENTRY_SRC_FLAG_INHERITED;
804 esrc->fes_flags &= ~(FIB_ENTRY_SRC_FLAG_ACTIVE |
805 FIB_ENTRY_SRC_FLAG_CONTRIBUTING);
806 esrc->fes_entry_flags &= ~FIB_ENTRY_FLAG_COVERED_INHERIT;
809 * the source owns a lock on the entry
811 fib_path_list_lock(esrc->fes_pl);
812 fib_entry_lock(fib_entry_get_index(fib_entry));
818 * fib_entry_src_action_update
820 * copy a source data from another entry to this one
822 static fib_entry_src_t *
823 fib_entry_src_action_update_from_cover (fib_entry_t *fib_entry,
824 const fib_entry_src_t *orig_src)
826 fib_entry_src_t *esrc;
828 esrc = fib_entry_src_find_or_create(fib_entry,
830 orig_src->fes_entry_flags);
833 * the source owns a lock on the entry
835 fib_path_list_unlock(esrc->fes_pl);
836 esrc->fes_pl = orig_src->fes_pl;
837 fib_path_list_lock(esrc->fes_pl);
842 static fib_table_walk_rc_t
843 fib_entry_src_covered_inherit_add_i (fib_entry_t *fib_entry,
844 const fib_entry_src_t *cover_src)
846 fib_entry_src_t *esrc;
848 esrc = fib_entry_src_find(fib_entry, cover_src->fes_src);
850 if (cover_src == esrc)
852 return (FIB_TABLE_WALK_CONTINUE);
858 * the covered entry already has this source.
860 if (esrc->fes_entry_flags & FIB_ENTRY_FLAG_COVERED_INHERIT)
863 * the covered source is itself a COVERED_INHERIT, i.e.
864 * it also pushes this source down the sub-tree.
865 * We consider this more specific covered to be the owner
866 * of the sub-tree from this point down.
868 return (FIB_TABLE_WALK_SUB_TREE_STOP);
870 if (esrc->fes_flags & FIB_ENTRY_SRC_FLAG_INHERITED)
873 * The covered's source data has been inherited, presumably
874 * from this cover, i.e. this is a modify.
876 esrc = fib_entry_src_action_update_from_cover(fib_entry, cover_src);
877 fib_entry_source_change(fib_entry, esrc->fes_src, esrc->fes_src);
882 * The covered's source was not inherited and it is also
883 * not inheriting. Nevertheless, it still owns the sub-tree from
886 return (FIB_TABLE_WALK_SUB_TREE_STOP);
892 * The covered does not have this source - add it.
894 fib_source_t best_source;
896 best_source = fib_entry_get_best_source(
897 fib_entry_get_index(fib_entry));
899 fib_entry_src_action_copy(fib_entry, cover_src);
900 fib_entry_source_change(fib_entry, best_source, cover_src->fes_src);
903 return (FIB_TABLE_WALK_CONTINUE);
906 static fib_table_walk_rc_t
907 fib_entry_src_covered_inherit_walk_add (fib_node_index_t fei,
910 return (fib_entry_src_covered_inherit_add_i(fib_entry_get(fei), ctx));
913 static fib_table_walk_rc_t
914 fib_entry_src_covered_inherit_walk_remove (fib_node_index_t fei,
917 fib_entry_src_t *cover_src, *esrc;
918 fib_entry_t *fib_entry;
920 fib_entry = fib_entry_get(fei);
923 esrc = fib_entry_src_find(fib_entry, cover_src->fes_src);
925 if (cover_src == esrc)
927 return (FIB_TABLE_WALK_CONTINUE);
933 * the covered entry already has this source.
935 if (esrc->fes_entry_flags & FIB_ENTRY_FLAG_COVERED_INHERIT)
938 * the covered source is itself a COVERED_INHERIT, i.e.
939 * it also pushes this source down the sub-tree.
940 * We consider this more specific covered to be the owner
941 * of the sub-tree from this point down.
943 return (FIB_TABLE_WALK_SUB_TREE_STOP);
945 if (esrc->fes_flags & FIB_ENTRY_SRC_FLAG_INHERITED)
948 * The covered's source data has been inherited, presumably
951 fib_entry_src_flag_t remaining;
953 remaining = fib_entry_special_remove(fei, cover_src->fes_src);
955 ASSERT(FIB_ENTRY_SRC_FLAG_ADDED == remaining);
960 * The covered's source was not inherited and it is also
961 * not inheriting. Nevertheless, it still owns the sub-tree from
964 return (FIB_TABLE_WALK_SUB_TREE_STOP);
970 * The covered does not have this source - that's an error,
971 * since it should have inherited, but there is nothing we can do
975 return (FIB_TABLE_WALK_CONTINUE);
979 fib_entry_src_inherit (const fib_entry_t *cover,
980 fib_entry_t *covered)
982 CLIB_UNUSED(fib_source_t source);
983 const fib_entry_src_t *src;
985 FOR_EACH_SRC_ADDED(cover, src, source,
987 if ((src->fes_entry_flags & FIB_ENTRY_FLAG_COVERED_INHERIT) ||
988 (src->fes_flags & FIB_ENTRY_SRC_FLAG_INHERITED))
990 fib_entry_src_covered_inherit_add_i(covered, src);
996 fib_entry_src_covered_inherit_add (fib_entry_t *fib_entry,
1000 fib_entry_src_t *esrc;
1002 esrc = fib_entry_src_find(fib_entry, source);
1004 ASSERT(esrc->fes_flags & FIB_ENTRY_SRC_FLAG_ACTIVE);
1006 if ((esrc->fes_entry_flags & FIB_ENTRY_FLAG_COVERED_INHERIT) ||
1007 (esrc->fes_flags & FIB_ENTRY_SRC_FLAG_INHERITED))
1009 fib_table_sub_tree_walk(fib_entry->fe_fib_index,
1010 fib_entry->fe_prefix.fp_proto,
1011 &fib_entry->fe_prefix,
1012 fib_entry_src_covered_inherit_walk_add,
1018 fib_entry_src_covered_inherit_remove (fib_entry_t *fib_entry,
1019 fib_entry_src_t *esrc)
1022 ASSERT(!(esrc->fes_flags & FIB_ENTRY_SRC_FLAG_ACTIVE));
1024 if (esrc->fes_entry_flags & FIB_ENTRY_FLAG_COVERED_INHERIT)
1026 fib_table_sub_tree_walk(fib_entry->fe_fib_index,
1027 fib_entry->fe_prefix.fp_proto,
1028 &fib_entry->fe_prefix,
1029 fib_entry_src_covered_inherit_walk_remove,
1035 fib_entry_src_action_activate (fib_entry_t *fib_entry,
1036 fib_source_t source)
1039 int houston_we_are_go_for_install;
1040 const fib_entry_src_vft_t *vft;
1041 fib_entry_src_t *esrc;
1043 esrc = fib_entry_src_find(fib_entry, source);
1045 ASSERT(!(esrc->fes_flags & FIB_ENTRY_SRC_FLAG_ACTIVE));
1046 ASSERT(esrc->fes_flags & FIB_ENTRY_SRC_FLAG_ADDED);
1048 esrc->fes_flags |= (FIB_ENTRY_SRC_FLAG_ACTIVE |
1049 FIB_ENTRY_SRC_FLAG_CONTRIBUTING);
1050 vft = fib_entry_src_get_vft(esrc);
1052 if (NULL != vft->fesv_activate)
1054 houston_we_are_go_for_install = vft->fesv_activate(esrc, fib_entry);
1059 * the source is not providing an activate function, we'll assume
1060 * therefore it has no objection to installing the entry
1062 houston_we_are_go_for_install = !0;
1066 * link to the path-list provided by the source, and go check
1067 * if that forms any loops in the graph.
1069 fib_entry->fe_parent = esrc->fes_pl;
1070 fib_entry->fe_sibling =
1071 fib_path_list_child_add(fib_entry->fe_parent,
1072 FIB_NODE_TYPE_ENTRY,
1073 fib_entry_get_index(fib_entry));
1075 fib_entry_recursive_loop_detect_i(fib_entry->fe_parent);
1077 FIB_ENTRY_DBG(fib_entry, "activate: %d",
1078 fib_entry->fe_parent);
1081 * If this source should push its state to covered prefixs, do that now.
1083 fib_entry_src_covered_inherit_add(fib_entry, source);
1085 if (0 != houston_we_are_go_for_install)
1087 fib_entry_src_action_install(fib_entry, source);
1091 fib_entry_src_action_uninstall(fib_entry);
1096 fib_entry_src_action_deactivate (fib_entry_t *fib_entry,
1097 fib_source_t source)
1100 fib_node_index_t path_list_index;
1101 fib_entry_src_t *esrc;
1103 esrc = fib_entry_src_find(fib_entry, source);
1105 ASSERT(esrc->fes_flags & FIB_ENTRY_SRC_FLAG_ACTIVE);
1107 FIB_ENTRY_SRC_VFT_INVOKE(fib_entry, esrc, fesv_deactivate,
1110 esrc->fes_flags &= ~(FIB_ENTRY_SRC_FLAG_ACTIVE |
1111 FIB_ENTRY_SRC_FLAG_CONTRIBUTING);
1113 FIB_ENTRY_DBG(fib_entry, "deactivate: %d", fib_entry->fe_parent);
1116 * If this source should pull its state from covered prefixs, do that now.
1117 * If this source also has the INHERITED flag set then it has a cover
1118 * that wants to push down forwarding. We only want the covereds to see
1121 fib_entry_src_covered_inherit_remove(fib_entry, esrc);
1124 * un-link from an old path-list. Check for any loops this will clear
1126 path_list_index = fib_entry->fe_parent;
1127 fib_entry->fe_parent = FIB_NODE_INDEX_INVALID;
1129 fib_entry_recursive_loop_detect_i(path_list_index);
1132 * this will unlock the path-list, so it may be invalid thereafter.
1134 fib_path_list_child_remove(path_list_index, fib_entry->fe_sibling);
1135 fib_entry->fe_sibling = FIB_NODE_INDEX_INVALID;
1139 fib_entry_src_action_fwd_update (const fib_entry_t *fib_entry,
1140 fib_source_t source)
1142 fib_entry_src_t *esrc;
1144 vec_foreach(esrc, fib_entry->fe_srcs)
1146 FIB_ENTRY_SRC_VFT_INVOKE(fib_entry, esrc, fesv_fwd_update,
1147 (esrc, fib_entry, source));
1152 fib_entry_src_action_reactivate (fib_entry_t *fib_entry,
1153 fib_source_t source)
1155 fib_node_index_t path_list_index;
1156 const fib_entry_src_vft_t *vft;
1157 fib_entry_src_t *esrc;
1158 int remain_installed;
1160 esrc = fib_entry_src_find(fib_entry, source);
1162 ASSERT(esrc->fes_flags & FIB_ENTRY_SRC_FLAG_ACTIVE);
1164 FIB_ENTRY_DBG(fib_entry, "reactivate: %d to %d",
1165 fib_entry->fe_parent,
1169 * call the source to reactive and get the go/no-go to remain installed
1171 vft = fib_entry_src_get_vft(esrc);
1173 if (NULL != vft->fesv_reactivate)
1175 remain_installed = vft->fesv_reactivate(esrc, fib_entry);
1179 remain_installed = 1;
1182 if (fib_entry->fe_parent != esrc->fes_pl)
1185 * un-link from an old path-list. Check for any loops this will clear
1187 path_list_index = fib_entry->fe_parent;
1188 fib_entry->fe_parent = FIB_NODE_INDEX_INVALID;
1191 * temporary lock so it doesn't get deleted when this entry is no
1194 fib_path_list_lock(path_list_index);
1197 * this entry is no longer a child. after unlinking check if any loops
1200 fib_path_list_child_remove(path_list_index,
1201 fib_entry->fe_sibling);
1203 fib_entry_recursive_loop_detect_i(path_list_index);
1206 * link to the path-list provided by the source, and go check
1207 * if that forms any loops in the graph.
1209 fib_entry->fe_parent = esrc->fes_pl;
1210 fib_entry->fe_sibling =
1211 fib_path_list_child_add(fib_entry->fe_parent,
1212 FIB_NODE_TYPE_ENTRY,
1213 fib_entry_get_index(fib_entry));
1215 fib_entry_recursive_loop_detect_i(fib_entry->fe_parent);
1216 fib_path_list_unlock(path_list_index);
1219 * If this source should push its state to covered prefixs, do that now.
1221 fib_entry_src_covered_inherit_add(fib_entry, source);
1224 if (!remain_installed)
1226 fib_entry_src_action_uninstall(fib_entry);
1230 fib_entry_src_action_install(fib_entry, source);
1232 fib_entry_src_action_fwd_update(fib_entry, source);
1236 fib_entry_src_action_installed (fib_entry_t *fib_entry,
1237 fib_source_t source)
1239 fib_entry_src_t *esrc;
1241 esrc = fib_entry_src_find(fib_entry, source);
1243 FIB_ENTRY_SRC_VFT_INVOKE(fib_entry, esrc, fesv_installed,
1246 fib_entry_src_action_fwd_update(fib_entry, source);
1252 * fib_entry_src_action_add
1254 * Adding a source can result in a new fib_entry being created, which
1255 * can inturn mean the pool is realloc'd and thus the entry passed as
1256 * an argument it also realloc'd
1257 * @return the original entry
1260 fib_entry_src_action_add (fib_entry_t *fib_entry,
1261 fib_source_t source,
1262 fib_entry_flag_t flags,
1263 const dpo_id_t *dpo)
1265 fib_entry_src_t *esrc;
1267 esrc = fib_entry_src_find_or_create(fib_entry, source, flags);
1269 ASSERT(esrc->fes_ref_count < 255);
1270 esrc->fes_ref_count++;
1272 if (flags != esrc->fes_entry_flags)
1274 FIB_ENTRY_SRC_VFT_INVOKE(fib_entry, esrc, fesv_flags_change,
1275 (esrc, fib_entry, flags));
1277 esrc->fes_entry_flags = flags;
1279 if (1 != esrc->fes_ref_count)
1282 * we only want to add the source on the 0->1 transition
1287 FIB_ENTRY_SRC_VFT_INVOKE(fib_entry, esrc, fesv_add,
1291 fib_entry_get_dpo_proto(fib_entry),
1294 esrc->fes_flags |= FIB_ENTRY_SRC_FLAG_ADDED;
1296 fib_path_list_lock(esrc->fes_pl);
1299 * the source owns a lock on the entry
1301 fib_entry_lock(fib_entry_get_index(fib_entry));
1307 * fib_entry_src_action_update
1309 * Adding a source can result in a new fib_entry being created, which
1310 * can inturn mean the pool is realloc'd and thus the entry passed as
1311 * an argument it also realloc'd
1312 * @return the original entry
1315 fib_entry_src_action_update (fib_entry_t *fib_entry,
1316 fib_source_t source,
1317 fib_entry_flag_t flags,
1318 const dpo_id_t *dpo)
1320 fib_node_index_t old_path_list_index;
1321 fib_entry_src_t *esrc;
1323 esrc = fib_entry_src_find_or_create(fib_entry, source, flags);
1327 return (fib_entry_src_action_add(fib_entry, source, flags, dpo));
1330 old_path_list_index = esrc->fes_pl;
1331 esrc->fes_entry_flags = flags;
1333 FIB_ENTRY_SRC_VFT_INVOKE(fib_entry, esrc, fesv_add,
1337 fib_entry_get_dpo_proto(fib_entry),
1340 esrc->fes_flags |= FIB_ENTRY_SRC_FLAG_ADDED;
1342 fib_path_list_lock(esrc->fes_pl);
1343 fib_path_list_unlock(old_path_list_index);
1348 fib_entry_src_flag_t
1349 fib_entry_src_action_remove_or_update_inherit (fib_entry_t *fib_entry,
1350 fib_source_t source)
1352 fib_entry_src_t *esrc;
1354 esrc = fib_entry_src_find(fib_entry, source);
1357 return (FIB_ENTRY_SRC_FLAG_ACTIVE);
1359 if ((esrc->fes_entry_flags & FIB_ENTRY_FLAG_COVERED_INHERIT) &&
1360 (esrc->fes_flags & FIB_ENTRY_SRC_FLAG_INHERITED))
1362 fib_entry_src_t *cover_src;
1363 fib_node_index_t coveri;
1367 * this source was pushing inherited state, but so is its
1368 * cover. Now that this source is going away, we need to
1369 * pull the covers forwarding and use it to update the covereds.
1370 * Go grab the path-list from the cover, rather than start a walk from
1371 * the cover, so we don't recursively update this entry.
1373 coveri = fib_table_get_less_specific(fib_entry->fe_fib_index,
1374 &fib_entry->fe_prefix);
1377 * only the default route has itself as its own cover, but the
1378 * default route cannot have inherited from something else.
1380 ASSERT(coveri != fib_entry_get_index(fib_entry));
1382 cover = fib_entry_get(coveri);
1383 cover_src = fib_entry_src_find(cover, source);
1385 ASSERT(NULL != cover_src);
1387 esrc = fib_entry_src_action_update_from_cover(fib_entry, cover_src);
1388 esrc->fes_entry_flags &= ~FIB_ENTRY_FLAG_COVERED_INHERIT;
1391 * Now push the new state from the cover down to the covereds
1393 fib_entry_src_covered_inherit_add(fib_entry, source);
1395 return (esrc->fes_flags);
1399 return (fib_entry_src_action_remove(fib_entry, source));
1403 fib_entry_src_flag_t
1404 fib_entry_src_action_remove (fib_entry_t *fib_entry,
1405 fib_source_t source)
1408 fib_node_index_t old_path_list;
1409 fib_entry_src_flag_t sflags;
1410 fib_entry_src_t *esrc;
1412 esrc = fib_entry_src_find(fib_entry, source);
1415 return (FIB_ENTRY_SRC_FLAG_ACTIVE);
1417 esrc->fes_ref_count--;
1418 sflags = esrc->fes_flags;
1420 if (0 != esrc->fes_ref_count)
1423 * only remove the source on the 1->0 transisition
1428 if (esrc->fes_flags & FIB_ENTRY_SRC_FLAG_ACTIVE)
1430 fib_entry_src_action_deactivate(fib_entry, source);
1432 else if (esrc->fes_flags & FIB_ENTRY_SRC_FLAG_CONTRIBUTING)
1434 FIB_ENTRY_SRC_VFT_INVOKE(fib_entry, esrc, fesv_deactivate,
1436 esrc->fes_flags &= ~FIB_ENTRY_SRC_FLAG_CONTRIBUTING;
1439 old_path_list = esrc->fes_pl;
1441 FIB_ENTRY_SRC_VFT_INVOKE(fib_entry, esrc, fesv_remove, (esrc));
1443 fib_path_list_unlock(old_path_list);
1444 fib_entry_unlock(fib_entry_get_index(fib_entry));
1446 sflags &= ~FIB_ENTRY_SRC_FLAG_ADDED;
1447 fib_entry_src_action_deinit(fib_entry, source);
1453 * fib_route_attached_cross_table
1455 * Return true the the route is attached via an interface that
1456 * is not in the same table as the route
1459 fib_route_attached_cross_table (const fib_entry_t *fib_entry,
1460 const fib_route_path_t *rpath)
1462 const fib_prefix_t *pfx = &fib_entry->fe_prefix;
1464 switch (pfx->fp_proto)
1466 case FIB_PROTOCOL_MPLS:
1467 /* MPLS routes are never imported/exported */
1469 case FIB_PROTOCOL_IP6:
1470 /* Ignore link local addresses these also can't be imported/exported */
1471 if (ip6_address_is_link_local_unicast (&pfx->fp_addr.ip6))
1476 case FIB_PROTOCOL_IP4:
1481 * an attached path and entry's fib index not equal to interface's index
1483 if (fib_route_path_is_attached(rpath) &&
1484 fib_entry->fe_fib_index !=
1485 fib_table_get_index_for_sw_if_index(fib_entry_get_proto(fib_entry),
1486 rpath->frp_sw_if_index))
1493 fib_path_list_flags_t
1494 fib_entry_src_flags_2_path_list_flags (fib_entry_flag_t eflags)
1496 fib_path_list_flags_t plf = FIB_PATH_LIST_FLAG_NONE;
1498 if (eflags & FIB_ENTRY_FLAG_DROP)
1500 plf |= FIB_PATH_LIST_FLAG_DROP;
1502 if (eflags & FIB_ENTRY_FLAG_EXCLUSIVE)
1504 plf |= FIB_PATH_LIST_FLAG_EXCLUSIVE;
1506 if (eflags & FIB_ENTRY_FLAG_LOCAL)
1508 plf |= FIB_PATH_LIST_FLAG_LOCAL;
1515 fib_entry_flags_update (const fib_entry_t *fib_entry,
1516 const fib_route_path_t *rpaths,
1517 fib_path_list_flags_t *pl_flags,
1518 fib_entry_src_t *esrc)
1520 const fib_route_path_t *rpath;
1522 vec_foreach(rpath, rpaths)
1524 if ((esrc->fes_src == FIB_SOURCE_API) ||
1525 (esrc->fes_src == FIB_SOURCE_CLI))
1527 if (fib_route_path_is_attached(rpath))
1529 esrc->fes_entry_flags |= FIB_ENTRY_FLAG_ATTACHED;
1533 esrc->fes_entry_flags &= ~FIB_ENTRY_FLAG_ATTACHED;
1535 if (rpath->frp_flags & FIB_ROUTE_PATH_DEAG)
1537 esrc->fes_entry_flags |= FIB_ENTRY_FLAG_LOOSE_URPF_EXEMPT;
1540 if (fib_route_attached_cross_table(fib_entry, rpath) &&
1541 !(esrc->fes_entry_flags & FIB_ENTRY_FLAG_NO_ATTACHED_EXPORT))
1543 esrc->fes_entry_flags |= FIB_ENTRY_FLAG_IMPORT;
1547 esrc->fes_entry_flags &= ~FIB_ENTRY_FLAG_IMPORT;
1553 * fib_entry_src_action_add
1555 * Adding a source can result in a new fib_entry being created, which
1556 * can inturn mean the pool is realloc'd and thus the entry passed as
1557 * an argument it also realloc'd
1561 fib_entry_src_action_path_add (fib_entry_t *fib_entry,
1562 fib_source_t source,
1563 fib_entry_flag_t flags,
1564 const fib_route_path_t *rpaths)
1566 fib_node_index_t old_path_list;
1567 fib_path_list_flags_t pl_flags;
1568 fib_entry_src_t *esrc;
1570 esrc = fib_entry_src_find(fib_entry, source);
1573 const dpo_id_t *dpo;
1575 if (flags == FIB_ENTRY_FLAG_EXCLUSIVE) {
1578 dpo = drop_dpo_get(fib_entry_get_dpo_proto(fib_entry));
1582 fib_entry_src_action_add(fib_entry,
1586 esrc = fib_entry_src_find(fib_entry, source);
1590 * we are no doubt modifying a path-list. If the path-list
1591 * is shared, and hence not modifiable, then the index returned
1592 * will be for a different path-list. This FIB entry to needs
1593 * to maintain its lock appropriately.
1595 old_path_list = esrc->fes_pl;
1597 ASSERT(FIB_ENTRY_SRC_VFT_EXISTS(esrc, fesv_path_add));
1599 pl_flags = fib_entry_src_flags_2_path_list_flags(fib_entry_get_flags_i(fib_entry));
1600 fib_entry_flags_update(fib_entry, rpaths, &pl_flags, esrc);
1602 FIB_ENTRY_SRC_VFT_INVOKE(fib_entry, esrc, fesv_path_add,
1603 (esrc, fib_entry, pl_flags, rpaths));
1605 fib_path_list_lock(esrc->fes_pl);
1606 fib_path_list_unlock(old_path_list);
1612 * fib_entry_src_action_swap
1614 * The source is providing new paths to replace the old ones.
1615 * Adding a source can result in a new fib_entry being created, which
1616 * can inturn mean the pool is realloc'd and thus the entry passed as
1617 * an argument it also realloc'd
1621 fib_entry_src_action_path_swap (fib_entry_t *fib_entry,
1622 fib_source_t source,
1623 fib_entry_flag_t flags,
1624 const fib_route_path_t *rpaths)
1626 fib_node_index_t old_path_list;
1627 fib_path_list_flags_t pl_flags;
1628 fib_entry_src_t *esrc;
1630 esrc = fib_entry_src_find(fib_entry, source);
1634 const dpo_id_t *dpo;
1636 if (flags == FIB_ENTRY_FLAG_EXCLUSIVE) {
1639 dpo = drop_dpo_get(fib_entry_get_dpo_proto(fib_entry));
1642 fib_entry = fib_entry_src_action_add(fib_entry,
1646 esrc = fib_entry_src_find(fib_entry, source);
1650 if (flags != esrc->fes_entry_flags)
1652 FIB_ENTRY_SRC_VFT_INVOKE(fib_entry, esrc, fesv_flags_change,
1653 (esrc, fib_entry, flags));
1655 esrc->fes_entry_flags = flags;
1659 * swapping paths may create a new path-list (or may use an existing shared)
1660 * but we are certainly getting a different one. This FIB entry to needs
1661 * to maintain its lock appropriately.
1663 old_path_list = esrc->fes_pl;
1665 ASSERT(FIB_ENTRY_SRC_VFT_EXISTS(esrc, fesv_path_swap));
1667 pl_flags = fib_entry_src_flags_2_path_list_flags(flags);
1669 fib_entry_flags_update(fib_entry, rpaths, &pl_flags, esrc);
1671 FIB_ENTRY_SRC_VFT_INVOKE(fib_entry, esrc, fesv_path_swap,
1675 fib_path_list_lock(esrc->fes_pl);
1676 fib_path_list_unlock(old_path_list);
1681 fib_entry_src_flag_t
1682 fib_entry_src_action_path_remove (fib_entry_t *fib_entry,
1683 fib_source_t source,
1684 const fib_route_path_t *rpaths)
1686 fib_path_list_flags_t pl_flags;
1687 fib_node_index_t old_path_list;
1688 fib_entry_src_t *esrc;
1690 esrc = fib_entry_src_find(fib_entry, source);
1692 ASSERT(NULL != esrc);
1693 ASSERT(esrc->fes_flags & FIB_ENTRY_SRC_FLAG_ADDED);
1696 * we no doubt modifying a path-list. If the path-list
1697 * is shared, and hence not modifiable, then the index returned
1698 * will be for a different path-list. This FIB entry to needs
1699 * to maintain its lock appropriately.
1701 old_path_list = esrc->fes_pl;
1703 ASSERT(FIB_ENTRY_SRC_VFT_EXISTS(esrc, fesv_path_remove));
1705 pl_flags = fib_entry_src_flags_2_path_list_flags(fib_entry_get_flags_i(fib_entry));
1706 fib_entry_flags_update(fib_entry, rpaths, &pl_flags, esrc);
1708 FIB_ENTRY_SRC_VFT_INVOKE(fib_entry, esrc, fesv_path_remove,
1709 (esrc, pl_flags, rpaths));
1712 * lock the new path-list, unlock the old if it had one
1714 fib_path_list_unlock(old_path_list);
1716 if (FIB_NODE_INDEX_INVALID != esrc->fes_pl) {
1717 fib_path_list_lock(esrc->fes_pl);
1718 return (FIB_ENTRY_SRC_FLAG_ADDED);
1723 * no more paths left from this source
1725 fib_entry_src_action_remove_or_update_inherit(fib_entry, source);
1726 return (FIB_ENTRY_SRC_FLAG_NONE);
1731 fib_entry_src_format (fib_entry_t *fib_entry,
1732 fib_source_t source,
1735 fib_entry_src_t *esrc;
1737 esrc = fib_entry_src_find(fib_entry, source);
1739 FIB_ENTRY_SRC_VFT_INVOKE_AND_RETURN(esrc, fesv_format, (esrc, s));
1745 fib_entry_get_adj_for_source (fib_node_index_t fib_entry_index,
1746 fib_source_t source)
1748 fib_entry_t *fib_entry;
1749 fib_entry_src_t *esrc;
1751 if (FIB_NODE_INDEX_INVALID == fib_entry_index)
1752 return (ADJ_INDEX_INVALID);
1754 fib_entry = fib_entry_get(fib_entry_index);
1755 esrc = fib_entry_src_find(fib_entry, source);
1759 if (FIB_NODE_INDEX_INVALID != esrc->fes_pl)
1761 return (fib_path_list_get_adj(
1763 fib_entry_get_default_chain_type(fib_entry)));
1766 return (ADJ_INDEX_INVALID);
1770 fib_entry_get_dpo_for_source (fib_node_index_t fib_entry_index,
1771 fib_source_t source,
1774 fib_entry_t *fib_entry;
1775 fib_entry_src_t *esrc;
1777 if (FIB_NODE_INDEX_INVALID == fib_entry_index)
1780 fib_entry = fib_entry_get(fib_entry_index);
1781 esrc = fib_entry_src_find(fib_entry, source);
1785 if (FIB_NODE_INDEX_INVALID != esrc->fes_pl)
1787 fib_path_list_contribute_forwarding(
1789 fib_entry_get_default_chain_type(fib_entry),
1790 FIB_PATH_LIST_FWD_FLAG_NONE,
1793 return (dpo_id_is_valid(dpo));
1800 fib_entry_get_resolving_interface_for_source (fib_node_index_t entry_index,
1801 fib_source_t source)
1803 fib_entry_t *fib_entry;
1804 fib_entry_src_t *esrc;
1806 fib_entry = fib_entry_get(entry_index);
1808 esrc = fib_entry_src_find(fib_entry, source);
1812 if (FIB_NODE_INDEX_INVALID != esrc->fes_pl)
1814 return (fib_path_list_get_resolving_interface(esrc->fes_pl));
1821 fib_entry_get_flags_for_source (fib_node_index_t entry_index,
1822 fib_source_t source)
1824 fib_entry_t *fib_entry;
1825 fib_entry_src_t *esrc;
1827 fib_entry = fib_entry_get(entry_index);
1829 esrc = fib_entry_src_find(fib_entry, source);
1833 return (esrc->fes_entry_flags);
1836 return (FIB_ENTRY_FLAG_NONE);
1840 fib_entry_get_source_i (const fib_entry_t *fib_entry)
1842 /* the vector of sources is deliberately arranged in priority order */
1843 if (0 == vec_len(fib_entry->fe_srcs))
1844 return (FIB_SOURCE_INVALID);
1845 return (vec_elt(fib_entry->fe_srcs, 0).fes_src);
1849 fib_entry_get_flags_i (const fib_entry_t *fib_entry)
1851 /* the vector of sources is deliberately arranged in priority order */
1852 if (0 == vec_len(fib_entry->fe_srcs))
1853 return (FIB_ENTRY_FLAG_NONE);
1854 return (vec_elt(fib_entry->fe_srcs, 0).fes_entry_flags);
1858 fib_entry_set_source_data (fib_node_index_t fib_entry_index,
1859 fib_source_t source,
1862 fib_entry_t *fib_entry;
1863 fib_entry_src_t *esrc;
1865 fib_entry = fib_entry_get(fib_entry_index);
1866 esrc = fib_entry_src_find(fib_entry, source);
1870 FIB_ENTRY_SRC_VFT_INVOKE(fib_entry, esrc, fesv_set_data,
1871 (esrc, fib_entry, data));
1876 fib_entry_get_source_data (fib_node_index_t fib_entry_index,
1877 fib_source_t source)
1879 fib_entry_t *fib_entry;
1880 fib_entry_src_t *esrc;
1882 fib_entry = fib_entry_get(fib_entry_index);
1883 esrc = fib_entry_src_find(fib_entry, source);
1887 FIB_ENTRY_SRC_VFT_INVOKE_AND_RETURN(esrc, fesv_get_data,
1894 fib_entry_src_module_init (void)
1896 fib_entry_src_rr_register();
1897 fib_entry_src_interface_register();
1898 fib_entry_src_interpose_register();
1899 fib_entry_src_drop_register();
1900 fib_entry_src_simple_register();
1901 fib_entry_src_api_register();
1902 fib_entry_src_adj_register();
1903 fib_entry_src_mpls_register();
1904 fib_entry_src_lisp_register();