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>
21 #include "fib_entry_src.h"
22 #include "fib_table.h"
23 #include "fib_path_ext.h"
28 static fib_entry_src_vft_t fib_entry_src_vft[FIB_SOURCE_MAX];
31 fib_entry_get_proto (const fib_entry_t * fib_entry)
33 return (fib_entry->fe_prefix.fp_proto);
37 fib_entry_src_register (fib_source_t source,
38 const fib_entry_src_vft_t *vft)
40 fib_entry_src_vft[source] = *vft;
44 fib_entry_src_cmp_for_sort (void * v1,
47 fib_entry_src_t *esrc1 = v1, *esrc2 = v2;
49 return (esrc1->fes_src - esrc2->fes_src);
53 fib_entry_src_action_init (fib_entry_t *fib_entry,
57 fib_entry_src_t esrc = {
58 .fes_pl = FIB_NODE_INDEX_INVALID,
59 .fes_flags = FIB_ENTRY_SRC_FLAG_NONE,
63 if (NULL != fib_entry_src_vft[source].fesv_init)
65 fib_entry_src_vft[source].fesv_init(&esrc);
68 vec_add1(fib_entry->fe_srcs, esrc);
69 vec_sort_with_function(fib_entry->fe_srcs,
70 fib_entry_src_cmp_for_sort);
73 static fib_entry_src_t *
74 fib_entry_src_find (const fib_entry_t *fib_entry,
79 fib_entry_src_t *esrc;
83 vec_foreach(esrc, fib_entry->fe_srcs)
85 if (esrc->fes_src == source)
103 fib_entry_is_sourced (fib_node_index_t fib_entry_index,
106 fib_entry_t *fib_entry;
108 fib_entry = fib_entry_get(fib_entry_index);
110 return (NULL != fib_entry_src_find(fib_entry, source, NULL));
113 static fib_entry_src_t *
114 fib_entry_src_find_or_create (fib_entry_t *fib_entry,
118 fib_entry_src_t *esrc;
120 esrc = fib_entry_src_find(fib_entry, source, NULL);
124 fib_entry_src_action_init(fib_entry, source);
127 return (fib_entry_src_find(fib_entry, source, NULL));
131 fib_entry_src_action_deinit (fib_entry_t *fib_entry,
135 fib_entry_src_t *esrc;
138 esrc = fib_entry_src_find(fib_entry, source, &index);
140 ASSERT(NULL != esrc);
142 if (NULL != fib_entry_src_vft[source].fesv_deinit)
144 fib_entry_src_vft[source].fesv_deinit(esrc);
147 vec_free(esrc->fes_path_exts);
148 vec_del1(fib_entry->fe_srcs, index);
151 fib_entry_src_cover_res_t
152 fib_entry_src_action_cover_change (fib_entry_t *fib_entry,
155 if (NULL != fib_entry_src_vft[source].fesv_cover_change)
157 return (fib_entry_src_vft[source].fesv_cover_change(
158 fib_entry_src_find(fib_entry, source, NULL),
162 fib_entry_src_cover_res_t res = {
164 .bw_reason = FIB_NODE_BW_REASON_FLAG_NONE,
169 fib_entry_src_cover_res_t
170 fib_entry_src_action_cover_update (fib_entry_t *fib_entry,
173 if (NULL != fib_entry_src_vft[source].fesv_cover_update)
175 return (fib_entry_src_vft[source].fesv_cover_update(
176 fib_entry_src_find(fib_entry, source, NULL),
180 fib_entry_src_cover_res_t res = {
182 .bw_reason = FIB_NODE_BW_REASON_FLAG_NONE,
187 typedef struct fib_entry_src_collect_forwarding_ctx_t_
189 load_balance_path_t * next_hops;
190 const fib_entry_t *fib_entry;
191 const fib_entry_src_t *esrc;
192 fib_forward_chain_type_t fct;
194 } fib_entry_src_collect_forwarding_ctx_t;
197 * @brief Determine whether this FIB entry should use a load-balance MAP
198 * to support PIC edge fast convergence
201 fib_entry_calc_lb_flags (fib_entry_src_collect_forwarding_ctx_t *ctx)
204 * We'll use a LB map is the path-list has recursive paths.
205 * recursive paths implies BGP, and hence scale.
207 if (ctx->is_recursive)
209 return (LOAD_BALANCE_FLAG_USES_MAP);
211 return (LOAD_BALANCE_FLAG_NONE);
215 fib_entry_src_valid_out_label (mpls_label_t label)
217 return ((MPLS_LABEL_IS_REAL(label) ||
218 MPLS_IETF_IPV4_EXPLICIT_NULL_LABEL == label ||
219 MPLS_IETF_IPV6_EXPLICIT_NULL_LABEL == label ||
220 MPLS_IETF_IMPLICIT_NULL_LABEL == label));
224 fib_entry_src_collect_forwarding (fib_node_index_t pl_index,
225 fib_node_index_t path_index,
228 fib_entry_src_collect_forwarding_ctx_t *ctx;
229 fib_path_ext_t *path_ext;
234 * if the path is not resolved, don't include it.
236 if (!fib_path_is_resolved(path_index))
241 if (fib_path_is_recursive(path_index))
243 ctx->is_recursive = 1;
247 * get the matching path-extension for the path being visited.
249 vec_foreach(path_ext, ctx->esrc->fes_path_exts)
251 if (path_ext->fpe_path_index == path_index)
255 if (NULL != path_ext &&
256 path_ext->fpe_path_index == path_index &&
257 fib_entry_src_valid_out_label(path_ext->fpe_label))
260 * found a matching extension. stack it to obtain the forwarding
261 * info for this path.
263 ctx->next_hops = fib_path_ext_stack(path_ext, ctx->fct, ctx->next_hops);
267 load_balance_path_t *nh;
270 * no extension => no out-going label for this path. that's OK
271 * in the case of an IP or EOS chain, but not for non-EOS
275 case FIB_FORW_CHAIN_TYPE_UNICAST_IP4:
276 case FIB_FORW_CHAIN_TYPE_UNICAST_IP6:
278 * EOS traffic with no label to stack, we need the IP Adj
280 vec_add2(ctx->next_hops, nh, 1);
282 nh->path_index = path_index;
283 nh->path_weight = fib_path_get_weight(path_index);
284 fib_path_contribute_forwarding(path_index, ctx->fct, &nh->path_dpo);
287 case FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS:
288 if (fib_path_is_exclusive(path_index) ||
289 fib_path_is_deag(path_index))
291 vec_add2(ctx->next_hops, nh, 1);
293 nh->path_index = path_index;
294 nh->path_weight = fib_path_get_weight(path_index);
295 fib_path_contribute_forwarding(path_index,
296 FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS,
300 case FIB_FORW_CHAIN_TYPE_MPLS_EOS:
310 fib_entry_src_mk_lb (fib_entry_t *fib_entry,
311 const fib_entry_src_t *esrc,
312 fib_forward_chain_type_t fct,
315 dpo_proto_t lb_proto;
318 * If the entry has path extensions then we construct a load-balance
319 * by stacking the extensions on the forwarding chains of the paths.
320 * Otherwise we use the load-balance of the path-list
322 fib_entry_src_collect_forwarding_ctx_t ctx = {
324 .fib_entry = fib_entry,
330 lb_proto = fib_proto_to_dpo(fib_entry_get_proto(fib_entry));
332 fib_path_list_walk(esrc->fes_pl,
333 fib_entry_src_collect_forwarding,
336 if (esrc->fes_entry_flags & FIB_ENTRY_FLAG_EXCLUSIVE)
339 * the client provided the DPO that the entry should link to.
340 * all entries must link to a LB, so if it is an LB already
341 * then we can use it.
343 if ((1 == vec_len(ctx.next_hops)) &&
344 (DPO_LOAD_BALANCE == ctx.next_hops[0].path_dpo.dpoi_type))
346 dpo_copy(dpo_lb, &ctx.next_hops[0].path_dpo);
347 dpo_reset(&ctx.next_hops[0].path_dpo);
352 if (!dpo_id_is_valid(dpo_lb))
357 flow_hash_config_t fhc;
359 fhc = fib_table_get_flow_hash_config(fib_entry->fe_fib_index,
360 dpo_proto_to_fib(lb_proto));
364 load_balance_create(0, lb_proto, fhc));
367 load_balance_multipath_update(dpo_lb,
369 fib_entry_calc_lb_flags(&ctx));
373 fib_entry_src_action_install (fib_entry_t *fib_entry,
377 * Install the forwarding chain for the given source into the forwarding
380 fib_forward_chain_type_t fct;
381 fib_entry_src_t *esrc;
383 fct = fib_entry_get_default_chain_type(fib_entry);
384 esrc = fib_entry_src_find(fib_entry, source, NULL);
386 fib_entry_src_mk_lb(fib_entry, esrc, fct, &fib_entry->fe_lb[fct]);
388 FIB_ENTRY_DBG(fib_entry, "install: %d",
389 fib_entry->fe_lb[fct]);
392 * insert the adj into the data-plane forwarding trie
394 fib_table_fwding_dpo_update(fib_entry->fe_fib_index,
395 &fib_entry->fe_prefix,
396 &fib_entry->fe_lb[fct]);
398 if (FIB_FORW_CHAIN_TYPE_UNICAST_IP4 == fct ||
399 FIB_FORW_CHAIN_TYPE_UNICAST_IP6 == fct)
401 for (fct = FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS;
402 fct <= FIB_FORW_CHAIN_TYPE_MPLS_EOS;
406 * if any of the other chain types are already created they will need
409 if (dpo_id_is_valid(&fib_entry->fe_lb[fct]))
411 fib_entry_src_mk_lb(fib_entry,
414 &fib_entry->fe_lb[fct]);
421 fib_entry_src_action_uninstall (fib_entry_t *fib_entry)
423 fib_forward_chain_type_t fct;
425 fct = fib_entry_get_default_chain_type(fib_entry);
427 * uninstall the forwarding chain for the given source from the
430 FIB_ENTRY_DBG(fib_entry, "uninstall: %d",
431 fib_entry->fe_adj_index);
433 if (dpo_id_is_valid(&fib_entry->fe_lb[fct]))
435 /* fib_forward_chain_type_t fct; */
436 /* fib_path_ext_t *path_ext; */
438 fib_table_fwding_dpo_remove(
439 fib_entry->fe_fib_index,
440 &fib_entry->fe_prefix,
441 &fib_entry->fe_lb[fct]);
443 dpo_reset(&fib_entry->fe_lb[fct]);
448 fib_entry_recursive_loop_detect_i (fib_node_index_t path_list_index)
450 fib_node_index_t *entries = NULL;
452 fib_path_list_recursive_loop_detect(path_list_index, &entries);
458 fib_entry_src_action_activate (fib_entry_t *fib_entry,
462 int houston_we_are_go_for_install;
463 fib_entry_src_t *esrc;
465 esrc = fib_entry_src_find(fib_entry, source, NULL);
467 ASSERT(!(esrc->fes_flags & FIB_ENTRY_SRC_FLAG_ACTIVE));
468 ASSERT(esrc->fes_flags & FIB_ENTRY_SRC_FLAG_ADDED);
470 esrc->fes_flags |= FIB_ENTRY_SRC_FLAG_ACTIVE;
472 if (NULL != fib_entry_src_vft[source].fesv_activate)
474 houston_we_are_go_for_install =
475 fib_entry_src_vft[source].fesv_activate(esrc, fib_entry);
480 * the source is not providing an activate function, we'll assume
481 * therefore it has no objection to installing the entry
483 houston_we_are_go_for_install = !0;
487 * link to the path-list provided by the source, and go check
488 * if that forms any loops in the graph.
490 fib_entry->fe_parent = esrc->fes_pl;
491 fib_entry->fe_sibling =
492 fib_path_list_child_add(fib_entry->fe_parent,
494 fib_entry_get_index(fib_entry));
496 fib_entry_recursive_loop_detect_i(fib_entry->fe_parent);
498 FIB_ENTRY_DBG(fib_entry, "activate: %d",
499 fib_entry->fe_parent);
501 if (0 != houston_we_are_go_for_install)
503 fib_entry_src_action_install(fib_entry, source);
507 fib_entry_src_action_uninstall(fib_entry);
512 fib_entry_src_action_deactivate (fib_entry_t *fib_entry,
516 fib_node_index_t path_list_index;
517 fib_entry_src_t *esrc;
519 esrc = fib_entry_src_find(fib_entry, source, NULL);
521 ASSERT(esrc->fes_flags & FIB_ENTRY_SRC_FLAG_ACTIVE);
523 if (NULL != fib_entry_src_vft[source].fesv_deactivate)
525 fib_entry_src_vft[source].fesv_deactivate(esrc, fib_entry);
528 esrc->fes_flags &= ~FIB_ENTRY_SRC_FLAG_ACTIVE;
530 FIB_ENTRY_DBG(fib_entry, "deactivate: %d", fib_entry->fe_parent);
533 * un-link from an old path-list. Check for any loops this will clear
535 path_list_index = fib_entry->fe_parent;
536 fib_entry->fe_parent = FIB_NODE_INDEX_INVALID;
538 fib_entry_recursive_loop_detect_i(path_list_index);
541 * this will unlock the path-list, so it may be invalid thereafter.
543 fib_path_list_child_remove(path_list_index, fib_entry->fe_sibling);
544 fib_entry->fe_sibling = FIB_NODE_INDEX_INVALID;
548 fib_entry_src_action_fwd_update (const fib_entry_t *fib_entry,
551 fib_entry_src_t *esrc;
553 vec_foreach(esrc, fib_entry->fe_srcs)
555 if (NULL != fib_entry_src_vft[esrc->fes_src].fesv_fwd_update)
557 fib_entry_src_vft[esrc->fes_src].fesv_fwd_update(esrc,
565 fib_entry_src_action_reactivate (fib_entry_t *fib_entry,
568 fib_node_index_t path_list_index;
569 fib_entry_src_t *esrc;
571 esrc = fib_entry_src_find(fib_entry, source, NULL);
573 ASSERT(esrc->fes_flags & FIB_ENTRY_SRC_FLAG_ACTIVE);
575 FIB_ENTRY_DBG(fib_entry, "reactivate: %d to %d",
576 fib_entry->fe_parent,
579 if (fib_entry->fe_parent != esrc->fes_pl)
582 * un-link from an old path-list. Check for any loops this will clear
584 path_list_index = fib_entry->fe_parent;
585 fib_entry->fe_parent = FIB_NODE_INDEX_INVALID;
588 * temporary lock so it doesn't get deleted when this entry is no
591 fib_path_list_lock(path_list_index);
594 * this entry is no longer a child. after unlinking check if any loops
597 fib_path_list_child_remove(path_list_index,
598 fib_entry->fe_sibling);
600 fib_entry_recursive_loop_detect_i(path_list_index);
603 * link to the path-list provided by the source, and go check
604 * if that forms any loops in the graph.
606 fib_entry->fe_parent = esrc->fes_pl;
607 fib_entry->fe_sibling =
608 fib_path_list_child_add(fib_entry->fe_parent,
610 fib_entry_get_index(fib_entry));
612 fib_entry_recursive_loop_detect_i(fib_entry->fe_parent);
613 fib_path_list_unlock(path_list_index);
615 fib_entry_src_action_install(fib_entry, source);
616 fib_entry_src_action_fwd_update(fib_entry, source);
620 fib_entry_src_action_installed (const fib_entry_t *fib_entry,
623 fib_entry_src_t *esrc;
625 esrc = fib_entry_src_find(fib_entry, source, NULL);
627 if (NULL != fib_entry_src_vft[source].fesv_installed)
629 fib_entry_src_vft[source].fesv_installed(esrc,
633 fib_entry_src_action_fwd_update(fib_entry, source);
637 * fib_entry_src_action_add
639 * Adding a source can result in a new fib_entry being created, which
640 * can inturn mean the pool is realloc'd and thus the entry passed as
641 * an argument it also realloc'd
642 * @return the original entry
645 fib_entry_src_action_add (fib_entry_t *fib_entry,
647 fib_entry_flag_t flags,
650 fib_node_index_t fib_entry_index;
651 fib_entry_src_t *esrc;
653 esrc = fib_entry_src_find_or_create(fib_entry, source, NULL);
655 esrc->fes_ref_count++;
657 if (1 != esrc->fes_ref_count)
660 * we only want to add the source on the 0->1 transition
665 esrc->fes_entry_flags = flags;
668 * save variable so we can recover from a fib_entry realloc.
670 fib_entry_index = fib_entry_get_index(fib_entry);
672 if (NULL != fib_entry_src_vft[source].fesv_add)
674 fib_entry_src_vft[source].fesv_add(esrc,
677 fib_entry_get_proto(fib_entry),
681 fib_entry = fib_entry_get(fib_entry_index);
683 esrc->fes_flags |= FIB_ENTRY_SRC_FLAG_ADDED;
685 fib_path_list_lock(esrc->fes_pl);
688 * the source owns a lock on the entry
690 fib_entry_lock(fib_entry_get_index(fib_entry));
696 fib_entry_src_action_remove (fib_entry_t *fib_entry,
700 fib_node_index_t old_path_list;
701 fib_entry_src_flag_t sflags;
702 fib_entry_src_t *esrc;
704 esrc = fib_entry_src_find(fib_entry, source, NULL);
707 return (FIB_ENTRY_SRC_FLAG_ACTIVE);
709 esrc->fes_ref_count--;
710 sflags = esrc->fes_flags;
712 if (0 != esrc->fes_ref_count)
715 * only remove the source on the 1->0 transisition
720 if (esrc->fes_flags & FIB_ENTRY_SRC_FLAG_ACTIVE)
722 fib_entry_src_action_deactivate(fib_entry, source);
725 old_path_list = esrc->fes_pl;
727 if (NULL != fib_entry_src_vft[source].fesv_remove)
729 fib_entry_src_vft[source].fesv_remove(esrc);
732 fib_path_list_unlock(old_path_list);
733 fib_entry_unlock(fib_entry_get_index(fib_entry));
735 sflags &= ~FIB_ENTRY_SRC_FLAG_ADDED;
736 fib_entry_src_action_deinit(fib_entry, source);
742 fib_route_recurses_via_self (const fib_prefix_t *prefix,
743 const fib_route_path_t *rpath)
746 * not all zeros next hop &&
747 * is recursive path &&
748 * nexthop is same as the route's address
750 return ((!ip46_address_is_zero(&rpath->frp_addr)) &&
751 (~0 == rpath->frp_sw_if_index) &&
752 (0 == ip46_address_cmp(&rpath->frp_addr, &prefix->fp_addr)));
757 * fib_route_attached_cross_table
759 * Return true the the route is attached via an interface that
760 * is not in the same table as the route
763 fib_route_attached_cross_table (const fib_entry_t *fib_entry,
764 const fib_route_path_t *rpath)
767 * - All zeros next-hop
768 * - a valid interface
769 * - entry's fib index not equeal to interface's index
771 if (ip46_address_is_zero(&rpath->frp_addr) &&
772 (~0 != rpath->frp_sw_if_index) &&
773 (fib_entry->fe_fib_index !=
774 fib_table_get_index_for_sw_if_index(fib_entry_get_proto(fib_entry),
775 rpath->frp_sw_if_index)))
783 * fib_route_attached_cross_table
785 * Return true the the route is attached via an interface that
786 * is not in the same table as the route
789 fib_path_is_attached (const fib_route_path_t *rpath)
792 * - All zeros next-hop
793 * - a valid interface
795 if (ip46_address_is_zero(&rpath->frp_addr) &&
796 (~0 != rpath->frp_sw_if_index))
803 fib_path_list_flags_t
804 fib_entry_src_flags_2_path_list_flags (fib_entry_flag_t eflags)
806 fib_path_list_flags_t plf = FIB_PATH_LIST_FLAG_NONE;
808 if (eflags & FIB_ENTRY_FLAG_DROP)
810 plf |= FIB_PATH_LIST_FLAG_DROP;
812 if (eflags & FIB_ENTRY_FLAG_LOCAL)
814 plf |= FIB_PATH_LIST_FLAG_LOCAL;
816 if (eflags & FIB_ENTRY_FLAG_EXCLUSIVE)
818 plf |= FIB_PATH_LIST_FLAG_EXCLUSIVE;
825 fib_entry_flags_update (const fib_entry_t *fib_entry,
826 const fib_route_path_t *rpath,
827 fib_path_list_flags_t *pl_flags,
828 fib_entry_src_t *esrc)
831 * don't allow the addition of a recursive looped path for prefix
834 if (fib_route_recurses_via_self(&fib_entry->fe_prefix, rpath))
837 * force the install of a drop path-list.
838 * we want the entry to have some path-list, mainly so
839 * the dodgy path can be rmeoved when the source stops playing
842 *pl_flags |= FIB_PATH_LIST_FLAG_DROP;
846 *pl_flags &= ~FIB_PATH_LIST_FLAG_DROP;
849 if ((esrc->fes_src == FIB_SOURCE_API) ||
850 (esrc->fes_src == FIB_SOURCE_CLI))
852 if (fib_path_is_attached(rpath))
854 esrc->fes_entry_flags |= FIB_ENTRY_FLAG_ATTACHED;
858 esrc->fes_entry_flags &= ~FIB_ENTRY_FLAG_ATTACHED;
861 if (fib_route_attached_cross_table(fib_entry, rpath))
863 esrc->fes_entry_flags |= FIB_ENTRY_FLAG_IMPORT;
867 esrc->fes_entry_flags &= ~FIB_ENTRY_FLAG_IMPORT;
872 * fib_entry_src_path_ext_add
874 * append a path extension to the entry's list
877 fib_entry_src_path_ext_append (fib_entry_src_t *esrc,
878 const fib_route_path_t *rpath)
880 if (MPLS_LABEL_INVALID != rpath->frp_label)
882 fib_path_ext_t *path_ext;
884 vec_add2(esrc->fes_path_exts, path_ext, 1);
886 fib_path_ext_init(path_ext, esrc->fes_pl, rpath);
891 * fib_entry_src_path_ext_insert
893 * insert, sorted, a path extension to the entry's list.
894 * It's not strictly necessary in sort the path extensions, since each
895 * extension has the path index to which it resolves. However, by being
896 * sorted the load-balance produced has a deterministic order, not an order
897 * based on the sequence of extension additions. this is a considerable benefit.
900 fib_entry_src_path_ext_insert (fib_entry_src_t *esrc,
901 const fib_route_path_t *rpath)
903 if (0 == vec_len(esrc->fes_path_exts))
904 return (fib_entry_src_path_ext_append(esrc, rpath));
906 if (MPLS_LABEL_INVALID != rpath->frp_label)
908 fib_path_ext_t path_ext;
911 fib_path_ext_init(&path_ext, esrc->fes_pl, rpath);
913 while (i < vec_len(esrc->fes_path_exts) &&
914 (fib_path_ext_cmp(&esrc->fes_path_exts[i], rpath) < 0))
919 vec_insert_elts(esrc->fes_path_exts, &path_ext, 1, i);
924 * fib_entry_src_action_add
926 * Adding a source can result in a new fib_entry being created, which
927 * can inturn mean the pool is realloc'd and thus the entry passed as
928 * an argument it also realloc'd
932 fib_entry_src_action_path_add (fib_entry_t *fib_entry,
934 fib_entry_flag_t flags,
935 const fib_route_path_t *rpath)
937 fib_node_index_t old_path_list, fib_entry_index;
938 fib_path_list_flags_t pl_flags;
939 fib_path_ext_t *path_ext;
940 fib_entry_src_t *esrc;
943 * save variable so we can recover from a fib_entry realloc.
945 fib_entry_index = fib_entry_get_index(fib_entry);
947 esrc = fib_entry_src_find(fib_entry, source, NULL);
951 fib_entry_src_action_add(fib_entry,
956 fib_entry_get_proto(fib_entry))));
957 esrc = fib_entry_src_find(fib_entry, source, NULL);
961 * we are no doubt modifying a path-list. If the path-list
962 * is shared, and hence not modifiable, then the index returned
963 * will be for a different path-list. This FIB entry to needs
964 * to maintain its lock appropriately.
966 old_path_list = esrc->fes_pl;
968 ASSERT(NULL != fib_entry_src_vft[source].fesv_path_add);
970 pl_flags = fib_entry_src_flags_2_path_list_flags(fib_entry_get_flags_i(fib_entry));
971 fib_entry_flags_update(fib_entry, rpath, &pl_flags, esrc);
973 fib_entry_src_vft[source].fesv_path_add(esrc, fib_entry, pl_flags, rpath);
974 fib_entry = fib_entry_get(fib_entry_index);
977 * re-resolve all the path-extensions with the new path-list
979 vec_foreach(path_ext, esrc->fes_path_exts)
981 fib_path_ext_resolve(path_ext, esrc->fes_pl);
984 * if the path has a label we need to add a path extension
986 fib_entry_src_path_ext_insert(esrc, rpath);
988 fib_path_list_lock(esrc->fes_pl);
989 fib_path_list_unlock(old_path_list);
995 * fib_entry_src_action_swap
997 * The source is providing new paths to replace the old ones.
998 * Adding a source can result in a new fib_entry being created, which
999 * can inturn mean the pool is realloc'd and thus the entry passed as
1000 * an argument it also realloc'd
1004 fib_entry_src_action_path_swap (fib_entry_t *fib_entry,
1005 fib_source_t source,
1006 fib_entry_flag_t flags,
1007 const fib_route_path_t *rpaths)
1009 fib_node_index_t old_path_list, fib_entry_index;
1010 fib_path_list_flags_t pl_flags;
1011 const fib_route_path_t *rpath;
1012 fib_entry_src_t *esrc;
1014 esrc = fib_entry_src_find(fib_entry, source, NULL);
1017 * save variable so we can recover from a fib_entry realloc.
1019 fib_entry_index = fib_entry_get_index(fib_entry);
1023 fib_entry = fib_entry_src_action_add(fib_entry,
1028 fib_entry_get_proto(fib_entry))));
1029 esrc = fib_entry_src_find(fib_entry, source, NULL);
1033 * swapping paths may create a new path-list (or may use an existing shared)
1034 * but we are certainly getting a different one. This FIB entry to needs
1035 * to maintain its lock appropriately.
1037 old_path_list = esrc->fes_pl;
1039 ASSERT(NULL != fib_entry_src_vft[source].fesv_path_swap);
1041 pl_flags = fib_entry_src_flags_2_path_list_flags(flags);
1043 vec_foreach(rpath, rpaths)
1045 fib_entry_flags_update(fib_entry, rpath, &pl_flags, esrc);
1048 fib_entry_src_vft[source].fesv_path_swap(esrc,
1053 vec_free(esrc->fes_path_exts);
1054 vec_foreach(rpath, rpaths)
1056 fib_entry_src_path_ext_append(esrc, rpath);
1059 fib_entry = fib_entry_get(fib_entry_index);
1061 fib_path_list_lock(esrc->fes_pl);
1062 fib_path_list_unlock(old_path_list);
1067 fib_entry_src_flag_t
1068 fib_entry_src_action_path_remove (fib_entry_t *fib_entry,
1069 fib_source_t source,
1070 const fib_route_path_t *rpath)
1072 fib_path_list_flags_t pl_flags;
1073 fib_node_index_t old_path_list;
1074 fib_path_ext_t *path_ext;
1075 fib_entry_src_t *esrc;
1077 esrc = fib_entry_src_find(fib_entry, source, NULL);
1079 ASSERT(NULL != esrc);
1080 ASSERT(esrc->fes_flags & FIB_ENTRY_SRC_FLAG_ADDED);
1083 * we no doubt modifying a path-list. If the path-list
1084 * is shared, and hence not modifiable, then the index returned
1085 * will be for a different path-list. This FIB entry to needs
1086 * to maintain its lock appropriately.
1088 old_path_list = esrc->fes_pl;
1090 ASSERT(NULL != fib_entry_src_vft[source].fesv_path_remove);
1092 pl_flags = fib_entry_src_flags_2_path_list_flags(fib_entry_get_flags_i(fib_entry));
1093 fib_entry_flags_update(fib_entry, rpath, &pl_flags, esrc);
1095 fib_entry_src_vft[source].fesv_path_remove(esrc, pl_flags, rpath);
1097 * find the matching path extension and remove it
1099 vec_foreach(path_ext, esrc->fes_path_exts)
1101 if (!fib_path_ext_cmp(path_ext, rpath))
1104 * delete the element moving the remaining elements down 1 position.
1105 * this preserves the sorted order.
1107 vec_delete(esrc->fes_path_exts, 1, (path_ext - esrc->fes_path_exts));
1112 * re-resolve all the path-extensions with the new path-list
1114 vec_foreach(path_ext, esrc->fes_path_exts)
1116 fib_path_ext_resolve(path_ext, esrc->fes_pl);
1120 * lock the new path-list, unlock the old if it had one
1122 fib_path_list_unlock(old_path_list);
1124 if (FIB_NODE_INDEX_INVALID != esrc->fes_pl) {
1125 fib_path_list_lock(esrc->fes_pl);
1126 return (FIB_ENTRY_SRC_FLAG_ADDED);
1131 * no more paths left from this source
1133 fib_entry_src_action_remove(fib_entry, source);
1134 return (FIB_ENTRY_SRC_FLAG_NONE);
1139 fib_entry_src_format (fib_entry_t *fib_entry,
1140 fib_source_t source,
1143 fib_entry_src_t *esrc;
1145 esrc = fib_entry_src_find(fib_entry, source, NULL);
1147 if (NULL != fib_entry_src_vft[source].fesv_format)
1149 return (fib_entry_src_vft[source].fesv_format(esrc, s));
1155 fib_entry_get_adj_for_source (fib_node_index_t fib_entry_index,
1156 fib_source_t source)
1158 fib_entry_t *fib_entry;
1159 fib_entry_src_t *esrc;
1161 if (FIB_NODE_INDEX_INVALID == fib_entry_index)
1162 return (ADJ_INDEX_INVALID);
1164 fib_entry = fib_entry_get(fib_entry_index);
1165 esrc = fib_entry_src_find(fib_entry, source, NULL);
1169 if (FIB_NODE_INDEX_INVALID != esrc->fes_pl)
1171 return (fib_path_list_get_adj(
1173 fib_entry_get_default_chain_type(fib_entry)));
1176 return (ADJ_INDEX_INVALID);
1180 fib_entry_get_dpo_for_source (fib_node_index_t fib_entry_index,
1181 fib_source_t source,
1184 fib_entry_t *fib_entry;
1185 fib_entry_src_t *esrc;
1187 if (FIB_NODE_INDEX_INVALID == fib_entry_index)
1190 fib_entry = fib_entry_get(fib_entry_index);
1191 esrc = fib_entry_src_find(fib_entry, source, NULL);
1195 if (FIB_NODE_INDEX_INVALID != esrc->fes_pl)
1197 fib_path_list_contribute_forwarding(
1199 fib_entry_get_default_chain_type(fib_entry),
1202 return (dpo_id_is_valid(dpo));
1209 fib_entry_get_resolving_interface_for_source (fib_node_index_t entry_index,
1210 fib_source_t source)
1212 fib_entry_t *fib_entry;
1213 fib_entry_src_t *esrc;
1215 fib_entry = fib_entry_get(entry_index);
1217 esrc = fib_entry_src_find(fib_entry, source, NULL);
1221 if (FIB_NODE_INDEX_INVALID != esrc->fes_pl)
1223 return (fib_path_list_get_resolving_interface(esrc->fes_pl));
1230 fib_entry_get_flags_for_source (fib_node_index_t entry_index,
1231 fib_source_t source)
1233 fib_entry_t *fib_entry;
1234 fib_entry_src_t *esrc;
1236 fib_entry = fib_entry_get(entry_index);
1238 esrc = fib_entry_src_find(fib_entry, source, NULL);
1242 return (esrc->fes_entry_flags);
1245 return (FIB_ENTRY_FLAG_NONE);
1249 fib_entry_get_flags_i (const fib_entry_t *fib_entry)
1251 fib_entry_flag_t flags;
1254 * the vector of sources is deliberately arranged in priority order
1256 if (0 == vec_len(fib_entry->fe_srcs))
1258 flags = FIB_ENTRY_FLAG_NONE;
1262 fib_entry_src_t *esrc;
1264 esrc = vec_elt_at_index(fib_entry->fe_srcs, 0);
1265 flags = esrc->fes_entry_flags;
1272 fib_entry_set_source_data (fib_node_index_t fib_entry_index,
1273 fib_source_t source,
1276 fib_entry_t *fib_entry;
1277 fib_entry_src_t *esrc;
1279 fib_entry = fib_entry_get(fib_entry_index);
1280 esrc = fib_entry_src_find(fib_entry, source, NULL);
1283 NULL != fib_entry_src_vft[source].fesv_set_data)
1285 fib_entry_src_vft[source].fesv_set_data(esrc, fib_entry, data);
1290 fib_entry_get_source_data (fib_node_index_t fib_entry_index,
1291 fib_source_t source)
1293 fib_entry_t *fib_entry;
1294 fib_entry_src_t *esrc;
1296 fib_entry = fib_entry_get(fib_entry_index);
1297 esrc = fib_entry_src_find(fib_entry, source, NULL);
1300 NULL != fib_entry_src_vft[source].fesv_get_data)
1302 return (fib_entry_src_vft[source].fesv_get_data(esrc, fib_entry));
1308 fib_entry_src_module_init (void)
1310 fib_entry_src_rr_register();
1311 fib_entry_src_interface_register();
1312 fib_entry_src_default_route_register();
1313 fib_entry_src_special_register();
1314 fib_entry_src_api_register();
1315 fib_entry_src_adj_register();
1316 fib_entry_src_mpls_register();
1317 fib_entry_src_lisp_register();