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:
301 case FIB_FORW_CHAIN_TYPE_ETHERNET:
311 fib_entry_src_mk_lb (fib_entry_t *fib_entry,
312 const fib_entry_src_t *esrc,
313 fib_forward_chain_type_t fct,
316 dpo_proto_t lb_proto;
319 * If the entry has path extensions then we construct a load-balance
320 * by stacking the extensions on the forwarding chains of the paths.
321 * Otherwise we use the load-balance of the path-list
323 fib_entry_src_collect_forwarding_ctx_t ctx = {
325 .fib_entry = fib_entry,
331 lb_proto = fib_proto_to_dpo(fib_entry_get_proto(fib_entry));
333 fib_path_list_walk(esrc->fes_pl,
334 fib_entry_src_collect_forwarding,
337 if (esrc->fes_entry_flags & FIB_ENTRY_FLAG_EXCLUSIVE)
340 * the client provided the DPO that the entry should link to.
341 * all entries must link to a LB, so if it is an LB already
342 * then we can use it.
344 if ((1 == vec_len(ctx.next_hops)) &&
345 (DPO_LOAD_BALANCE == ctx.next_hops[0].path_dpo.dpoi_type))
347 dpo_copy(dpo_lb, &ctx.next_hops[0].path_dpo);
348 dpo_reset(&ctx.next_hops[0].path_dpo);
353 if (!dpo_id_is_valid(dpo_lb))
358 flow_hash_config_t fhc;
360 fhc = fib_table_get_flow_hash_config(fib_entry->fe_fib_index,
361 dpo_proto_to_fib(lb_proto));
365 load_balance_create(0, lb_proto, fhc));
368 load_balance_multipath_update(dpo_lb,
370 fib_entry_calc_lb_flags(&ctx));
374 fib_entry_src_action_install (fib_entry_t *fib_entry,
378 * Install the forwarding chain for the given source into the forwarding
381 fib_forward_chain_type_t fct;
382 fib_entry_src_t *esrc;
384 fct = fib_entry_get_default_chain_type(fib_entry);
385 esrc = fib_entry_src_find(fib_entry, source, NULL);
387 fib_entry_src_mk_lb(fib_entry, esrc, fct, &fib_entry->fe_lb[fct]);
389 FIB_ENTRY_DBG(fib_entry, "install: %d",
390 fib_entry->fe_lb[fct]);
393 * insert the adj into the data-plane forwarding trie
395 fib_table_fwding_dpo_update(fib_entry->fe_fib_index,
396 &fib_entry->fe_prefix,
397 &fib_entry->fe_lb[fct]);
399 if (FIB_FORW_CHAIN_TYPE_UNICAST_IP4 == fct ||
400 FIB_FORW_CHAIN_TYPE_UNICAST_IP6 == fct)
402 for (fct = FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS;
403 fct <= FIB_FORW_CHAIN_TYPE_MPLS_EOS;
407 * if any of the other chain types are already created they will need
410 if (dpo_id_is_valid(&fib_entry->fe_lb[fct]))
412 fib_entry_src_mk_lb(fib_entry,
415 &fib_entry->fe_lb[fct]);
422 fib_entry_src_action_uninstall (fib_entry_t *fib_entry)
424 fib_forward_chain_type_t fct;
426 fct = fib_entry_get_default_chain_type(fib_entry);
428 * uninstall the forwarding chain for the given source from the
431 FIB_ENTRY_DBG(fib_entry, "uninstall: %d",
432 fib_entry->fe_adj_index);
434 if (dpo_id_is_valid(&fib_entry->fe_lb[fct]))
436 /* fib_forward_chain_type_t fct; */
437 /* fib_path_ext_t *path_ext; */
439 fib_table_fwding_dpo_remove(
440 fib_entry->fe_fib_index,
441 &fib_entry->fe_prefix,
442 &fib_entry->fe_lb[fct]);
444 dpo_reset(&fib_entry->fe_lb[fct]);
449 fib_entry_recursive_loop_detect_i (fib_node_index_t path_list_index)
451 fib_node_index_t *entries = NULL;
453 fib_path_list_recursive_loop_detect(path_list_index, &entries);
459 fib_entry_src_action_activate (fib_entry_t *fib_entry,
463 int houston_we_are_go_for_install;
464 fib_entry_src_t *esrc;
466 esrc = fib_entry_src_find(fib_entry, source, NULL);
468 ASSERT(!(esrc->fes_flags & FIB_ENTRY_SRC_FLAG_ACTIVE));
469 ASSERT(esrc->fes_flags & FIB_ENTRY_SRC_FLAG_ADDED);
471 esrc->fes_flags |= FIB_ENTRY_SRC_FLAG_ACTIVE;
473 if (NULL != fib_entry_src_vft[source].fesv_activate)
475 houston_we_are_go_for_install =
476 fib_entry_src_vft[source].fesv_activate(esrc, fib_entry);
481 * the source is not providing an activate function, we'll assume
482 * therefore it has no objection to installing the entry
484 houston_we_are_go_for_install = !0;
488 * link to the path-list provided by the source, and go check
489 * if that forms any loops in the graph.
491 fib_entry->fe_parent = esrc->fes_pl;
492 fib_entry->fe_sibling =
493 fib_path_list_child_add(fib_entry->fe_parent,
495 fib_entry_get_index(fib_entry));
497 fib_entry_recursive_loop_detect_i(fib_entry->fe_parent);
499 FIB_ENTRY_DBG(fib_entry, "activate: %d",
500 fib_entry->fe_parent);
502 if (0 != houston_we_are_go_for_install)
504 fib_entry_src_action_install(fib_entry, source);
508 fib_entry_src_action_uninstall(fib_entry);
513 fib_entry_src_action_deactivate (fib_entry_t *fib_entry,
517 fib_node_index_t path_list_index;
518 fib_entry_src_t *esrc;
520 esrc = fib_entry_src_find(fib_entry, source, NULL);
522 ASSERT(esrc->fes_flags & FIB_ENTRY_SRC_FLAG_ACTIVE);
524 if (NULL != fib_entry_src_vft[source].fesv_deactivate)
526 fib_entry_src_vft[source].fesv_deactivate(esrc, fib_entry);
529 esrc->fes_flags &= ~FIB_ENTRY_SRC_FLAG_ACTIVE;
531 FIB_ENTRY_DBG(fib_entry, "deactivate: %d", fib_entry->fe_parent);
534 * un-link from an old path-list. Check for any loops this will clear
536 path_list_index = fib_entry->fe_parent;
537 fib_entry->fe_parent = FIB_NODE_INDEX_INVALID;
539 fib_entry_recursive_loop_detect_i(path_list_index);
542 * this will unlock the path-list, so it may be invalid thereafter.
544 fib_path_list_child_remove(path_list_index, fib_entry->fe_sibling);
545 fib_entry->fe_sibling = FIB_NODE_INDEX_INVALID;
549 fib_entry_src_action_fwd_update (const fib_entry_t *fib_entry,
552 fib_entry_src_t *esrc;
554 vec_foreach(esrc, fib_entry->fe_srcs)
556 if (NULL != fib_entry_src_vft[esrc->fes_src].fesv_fwd_update)
558 fib_entry_src_vft[esrc->fes_src].fesv_fwd_update(esrc,
566 fib_entry_src_action_reactivate (fib_entry_t *fib_entry,
569 fib_node_index_t path_list_index;
570 fib_entry_src_t *esrc;
572 esrc = fib_entry_src_find(fib_entry, source, NULL);
574 ASSERT(esrc->fes_flags & FIB_ENTRY_SRC_FLAG_ACTIVE);
576 FIB_ENTRY_DBG(fib_entry, "reactivate: %d to %d",
577 fib_entry->fe_parent,
580 if (fib_entry->fe_parent != esrc->fes_pl)
583 * un-link from an old path-list. Check for any loops this will clear
585 path_list_index = fib_entry->fe_parent;
586 fib_entry->fe_parent = FIB_NODE_INDEX_INVALID;
589 * temporary lock so it doesn't get deleted when this entry is no
592 fib_path_list_lock(path_list_index);
595 * this entry is no longer a child. after unlinking check if any loops
598 fib_path_list_child_remove(path_list_index,
599 fib_entry->fe_sibling);
601 fib_entry_recursive_loop_detect_i(path_list_index);
604 * link to the path-list provided by the source, and go check
605 * if that forms any loops in the graph.
607 fib_entry->fe_parent = esrc->fes_pl;
608 fib_entry->fe_sibling =
609 fib_path_list_child_add(fib_entry->fe_parent,
611 fib_entry_get_index(fib_entry));
613 fib_entry_recursive_loop_detect_i(fib_entry->fe_parent);
614 fib_path_list_unlock(path_list_index);
616 fib_entry_src_action_install(fib_entry, source);
617 fib_entry_src_action_fwd_update(fib_entry, source);
621 fib_entry_src_action_installed (const fib_entry_t *fib_entry,
624 fib_entry_src_t *esrc;
626 esrc = fib_entry_src_find(fib_entry, source, NULL);
628 if (NULL != fib_entry_src_vft[source].fesv_installed)
630 fib_entry_src_vft[source].fesv_installed(esrc,
634 fib_entry_src_action_fwd_update(fib_entry, source);
638 * fib_entry_src_action_add
640 * Adding a source can result in a new fib_entry being created, which
641 * can inturn mean the pool is realloc'd and thus the entry passed as
642 * an argument it also realloc'd
643 * @return the original entry
646 fib_entry_src_action_add (fib_entry_t *fib_entry,
648 fib_entry_flag_t flags,
651 fib_node_index_t fib_entry_index;
652 fib_entry_src_t *esrc;
654 esrc = fib_entry_src_find_or_create(fib_entry, source, NULL);
656 esrc->fes_ref_count++;
658 if (1 != esrc->fes_ref_count)
661 * we only want to add the source on the 0->1 transition
666 esrc->fes_entry_flags = flags;
669 * save variable so we can recover from a fib_entry realloc.
671 fib_entry_index = fib_entry_get_index(fib_entry);
673 if (NULL != fib_entry_src_vft[source].fesv_add)
675 fib_entry_src_vft[source].fesv_add(esrc,
678 fib_entry_get_proto(fib_entry),
682 fib_entry = fib_entry_get(fib_entry_index);
684 esrc->fes_flags |= FIB_ENTRY_SRC_FLAG_ADDED;
686 fib_path_list_lock(esrc->fes_pl);
689 * the source owns a lock on the entry
691 fib_entry_lock(fib_entry_get_index(fib_entry));
697 fib_entry_src_action_remove (fib_entry_t *fib_entry,
701 fib_node_index_t old_path_list;
702 fib_entry_src_flag_t sflags;
703 fib_entry_src_t *esrc;
705 esrc = fib_entry_src_find(fib_entry, source, NULL);
708 return (FIB_ENTRY_SRC_FLAG_ACTIVE);
710 esrc->fes_ref_count--;
711 sflags = esrc->fes_flags;
713 if (0 != esrc->fes_ref_count)
716 * only remove the source on the 1->0 transisition
721 if (esrc->fes_flags & FIB_ENTRY_SRC_FLAG_ACTIVE)
723 fib_entry_src_action_deactivate(fib_entry, source);
726 old_path_list = esrc->fes_pl;
728 if (NULL != fib_entry_src_vft[source].fesv_remove)
730 fib_entry_src_vft[source].fesv_remove(esrc);
733 fib_path_list_unlock(old_path_list);
734 fib_entry_unlock(fib_entry_get_index(fib_entry));
736 sflags &= ~FIB_ENTRY_SRC_FLAG_ADDED;
737 fib_entry_src_action_deinit(fib_entry, source);
743 fib_route_recurses_via_self (const fib_prefix_t *prefix,
744 const fib_route_path_t *rpath)
747 * not all zeros next hop &&
748 * is recursive path &&
749 * nexthop is same as the route's address
751 return ((!ip46_address_is_zero(&rpath->frp_addr)) &&
752 (~0 == rpath->frp_sw_if_index) &&
753 (0 == ip46_address_cmp(&rpath->frp_addr, &prefix->fp_addr)));
758 * fib_route_attached_cross_table
760 * Return true the the route is attached via an interface that
761 * is not in the same table as the route
764 fib_route_attached_cross_table (const fib_entry_t *fib_entry,
765 const fib_route_path_t *rpath)
768 * - All zeros next-hop
769 * - a valid interface
770 * - entry's fib index not equeal to interface's index
772 if (ip46_address_is_zero(&rpath->frp_addr) &&
773 (~0 != rpath->frp_sw_if_index) &&
774 (fib_entry->fe_fib_index !=
775 fib_table_get_index_for_sw_if_index(fib_entry_get_proto(fib_entry),
776 rpath->frp_sw_if_index)))
784 * fib_route_attached_cross_table
786 * Return true the the route is attached via an interface that
787 * is not in the same table as the route
790 fib_path_is_attached (const fib_route_path_t *rpath)
793 * - All zeros next-hop
794 * - a valid interface
796 if (ip46_address_is_zero(&rpath->frp_addr) &&
797 (~0 != rpath->frp_sw_if_index))
804 fib_path_list_flags_t
805 fib_entry_src_flags_2_path_list_flags (fib_entry_flag_t eflags)
807 fib_path_list_flags_t plf = FIB_PATH_LIST_FLAG_NONE;
809 if (eflags & FIB_ENTRY_FLAG_DROP)
811 plf |= FIB_PATH_LIST_FLAG_DROP;
813 if (eflags & FIB_ENTRY_FLAG_LOCAL)
815 plf |= FIB_PATH_LIST_FLAG_LOCAL;
817 if (eflags & FIB_ENTRY_FLAG_EXCLUSIVE)
819 plf |= FIB_PATH_LIST_FLAG_EXCLUSIVE;
826 fib_entry_flags_update (const fib_entry_t *fib_entry,
827 const fib_route_path_t *rpath,
828 fib_path_list_flags_t *pl_flags,
829 fib_entry_src_t *esrc)
832 * don't allow the addition of a recursive looped path for prefix
835 if (fib_route_recurses_via_self(&fib_entry->fe_prefix, rpath))
838 * force the install of a drop path-list.
839 * we want the entry to have some path-list, mainly so
840 * the dodgy path can be rmeoved when the source stops playing
843 *pl_flags |= FIB_PATH_LIST_FLAG_DROP;
847 *pl_flags &= ~FIB_PATH_LIST_FLAG_DROP;
850 if ((esrc->fes_src == FIB_SOURCE_API) ||
851 (esrc->fes_src == FIB_SOURCE_CLI))
853 if (fib_path_is_attached(rpath))
855 esrc->fes_entry_flags |= FIB_ENTRY_FLAG_ATTACHED;
859 esrc->fes_entry_flags &= ~FIB_ENTRY_FLAG_ATTACHED;
862 if (fib_route_attached_cross_table(fib_entry, rpath))
864 esrc->fes_entry_flags |= FIB_ENTRY_FLAG_IMPORT;
868 esrc->fes_entry_flags &= ~FIB_ENTRY_FLAG_IMPORT;
873 * fib_entry_src_path_ext_add
875 * append a path extension to the entry's list
878 fib_entry_src_path_ext_append (fib_entry_src_t *esrc,
879 const fib_route_path_t *rpath)
881 if (MPLS_LABEL_INVALID != rpath->frp_label)
883 fib_path_ext_t *path_ext;
885 vec_add2(esrc->fes_path_exts, path_ext, 1);
887 fib_path_ext_init(path_ext, esrc->fes_pl, rpath);
892 * fib_entry_src_path_ext_insert
894 * insert, sorted, a path extension to the entry's list.
895 * It's not strictly necessary in sort the path extensions, since each
896 * extension has the path index to which it resolves. However, by being
897 * sorted the load-balance produced has a deterministic order, not an order
898 * based on the sequence of extension additions. this is a considerable benefit.
901 fib_entry_src_path_ext_insert (fib_entry_src_t *esrc,
902 const fib_route_path_t *rpath)
904 if (0 == vec_len(esrc->fes_path_exts))
905 return (fib_entry_src_path_ext_append(esrc, rpath));
907 if (MPLS_LABEL_INVALID != rpath->frp_label)
909 fib_path_ext_t path_ext;
912 fib_path_ext_init(&path_ext, esrc->fes_pl, rpath);
914 while (i < vec_len(esrc->fes_path_exts) &&
915 (fib_path_ext_cmp(&esrc->fes_path_exts[i], rpath) < 0))
920 vec_insert_elts(esrc->fes_path_exts, &path_ext, 1, i);
925 * fib_entry_src_action_add
927 * Adding a source can result in a new fib_entry being created, which
928 * can inturn mean the pool is realloc'd and thus the entry passed as
929 * an argument it also realloc'd
933 fib_entry_src_action_path_add (fib_entry_t *fib_entry,
935 fib_entry_flag_t flags,
936 const fib_route_path_t *rpath)
938 fib_node_index_t old_path_list, fib_entry_index;
939 fib_path_list_flags_t pl_flags;
940 fib_path_ext_t *path_ext;
941 fib_entry_src_t *esrc;
944 * save variable so we can recover from a fib_entry realloc.
946 fib_entry_index = fib_entry_get_index(fib_entry);
948 esrc = fib_entry_src_find(fib_entry, source, NULL);
952 fib_entry_src_action_add(fib_entry,
957 fib_entry_get_proto(fib_entry))));
958 esrc = fib_entry_src_find(fib_entry, source, NULL);
962 * we are no doubt modifying a path-list. If the path-list
963 * is shared, and hence not modifiable, then the index returned
964 * will be for a different path-list. This FIB entry to needs
965 * to maintain its lock appropriately.
967 old_path_list = esrc->fes_pl;
969 ASSERT(NULL != fib_entry_src_vft[source].fesv_path_add);
971 pl_flags = fib_entry_src_flags_2_path_list_flags(fib_entry_get_flags_i(fib_entry));
972 fib_entry_flags_update(fib_entry, rpath, &pl_flags, esrc);
974 fib_entry_src_vft[source].fesv_path_add(esrc, fib_entry, pl_flags, rpath);
975 fib_entry = fib_entry_get(fib_entry_index);
978 * re-resolve all the path-extensions with the new path-list
980 vec_foreach(path_ext, esrc->fes_path_exts)
982 fib_path_ext_resolve(path_ext, esrc->fes_pl);
985 * if the path has a label we need to add a path extension
987 fib_entry_src_path_ext_insert(esrc, rpath);
989 fib_path_list_lock(esrc->fes_pl);
990 fib_path_list_unlock(old_path_list);
996 * fib_entry_src_action_swap
998 * The source is providing new paths to replace the old ones.
999 * Adding a source can result in a new fib_entry being created, which
1000 * can inturn mean the pool is realloc'd and thus the entry passed as
1001 * an argument it also realloc'd
1005 fib_entry_src_action_path_swap (fib_entry_t *fib_entry,
1006 fib_source_t source,
1007 fib_entry_flag_t flags,
1008 const fib_route_path_t *rpaths)
1010 fib_node_index_t old_path_list, fib_entry_index;
1011 fib_path_list_flags_t pl_flags;
1012 const fib_route_path_t *rpath;
1013 fib_entry_src_t *esrc;
1015 esrc = fib_entry_src_find(fib_entry, source, NULL);
1018 * save variable so we can recover from a fib_entry realloc.
1020 fib_entry_index = fib_entry_get_index(fib_entry);
1024 fib_entry = fib_entry_src_action_add(fib_entry,
1029 fib_entry_get_proto(fib_entry))));
1030 esrc = fib_entry_src_find(fib_entry, source, NULL);
1034 * swapping paths may create a new path-list (or may use an existing shared)
1035 * but we are certainly getting a different one. This FIB entry to needs
1036 * to maintain its lock appropriately.
1038 old_path_list = esrc->fes_pl;
1040 ASSERT(NULL != fib_entry_src_vft[source].fesv_path_swap);
1042 pl_flags = fib_entry_src_flags_2_path_list_flags(flags);
1044 vec_foreach(rpath, rpaths)
1046 fib_entry_flags_update(fib_entry, rpath, &pl_flags, esrc);
1049 fib_entry_src_vft[source].fesv_path_swap(esrc,
1054 vec_free(esrc->fes_path_exts);
1055 vec_foreach(rpath, rpaths)
1057 fib_entry_src_path_ext_append(esrc, rpath);
1060 fib_entry = fib_entry_get(fib_entry_index);
1062 fib_path_list_lock(esrc->fes_pl);
1063 fib_path_list_unlock(old_path_list);
1068 fib_entry_src_flag_t
1069 fib_entry_src_action_path_remove (fib_entry_t *fib_entry,
1070 fib_source_t source,
1071 const fib_route_path_t *rpath)
1073 fib_path_list_flags_t pl_flags;
1074 fib_node_index_t old_path_list;
1075 fib_path_ext_t *path_ext;
1076 fib_entry_src_t *esrc;
1078 esrc = fib_entry_src_find(fib_entry, source, NULL);
1080 ASSERT(NULL != esrc);
1081 ASSERT(esrc->fes_flags & FIB_ENTRY_SRC_FLAG_ADDED);
1084 * we no doubt modifying a path-list. If the path-list
1085 * is shared, and hence not modifiable, then the index returned
1086 * will be for a different path-list. This FIB entry to needs
1087 * to maintain its lock appropriately.
1089 old_path_list = esrc->fes_pl;
1091 ASSERT(NULL != fib_entry_src_vft[source].fesv_path_remove);
1093 pl_flags = fib_entry_src_flags_2_path_list_flags(fib_entry_get_flags_i(fib_entry));
1094 fib_entry_flags_update(fib_entry, rpath, &pl_flags, esrc);
1096 fib_entry_src_vft[source].fesv_path_remove(esrc, pl_flags, rpath);
1098 * find the matching path extension and remove it
1100 vec_foreach(path_ext, esrc->fes_path_exts)
1102 if (!fib_path_ext_cmp(path_ext, rpath))
1105 * delete the element moving the remaining elements down 1 position.
1106 * this preserves the sorted order.
1108 vec_delete(esrc->fes_path_exts, 1, (path_ext - esrc->fes_path_exts));
1113 * re-resolve all the path-extensions with the new path-list
1115 vec_foreach(path_ext, esrc->fes_path_exts)
1117 fib_path_ext_resolve(path_ext, esrc->fes_pl);
1121 * lock the new path-list, unlock the old if it had one
1123 fib_path_list_unlock(old_path_list);
1125 if (FIB_NODE_INDEX_INVALID != esrc->fes_pl) {
1126 fib_path_list_lock(esrc->fes_pl);
1127 return (FIB_ENTRY_SRC_FLAG_ADDED);
1132 * no more paths left from this source
1134 fib_entry_src_action_remove(fib_entry, source);
1135 return (FIB_ENTRY_SRC_FLAG_NONE);
1140 fib_entry_src_format (fib_entry_t *fib_entry,
1141 fib_source_t source,
1144 fib_entry_src_t *esrc;
1146 esrc = fib_entry_src_find(fib_entry, source, NULL);
1148 if (NULL != fib_entry_src_vft[source].fesv_format)
1150 return (fib_entry_src_vft[source].fesv_format(esrc, s));
1156 fib_entry_get_adj_for_source (fib_node_index_t fib_entry_index,
1157 fib_source_t source)
1159 fib_entry_t *fib_entry;
1160 fib_entry_src_t *esrc;
1162 if (FIB_NODE_INDEX_INVALID == fib_entry_index)
1163 return (ADJ_INDEX_INVALID);
1165 fib_entry = fib_entry_get(fib_entry_index);
1166 esrc = fib_entry_src_find(fib_entry, source, NULL);
1170 if (FIB_NODE_INDEX_INVALID != esrc->fes_pl)
1172 return (fib_path_list_get_adj(
1174 fib_entry_get_default_chain_type(fib_entry)));
1177 return (ADJ_INDEX_INVALID);
1181 fib_entry_get_dpo_for_source (fib_node_index_t fib_entry_index,
1182 fib_source_t source,
1185 fib_entry_t *fib_entry;
1186 fib_entry_src_t *esrc;
1188 if (FIB_NODE_INDEX_INVALID == fib_entry_index)
1191 fib_entry = fib_entry_get(fib_entry_index);
1192 esrc = fib_entry_src_find(fib_entry, source, NULL);
1196 if (FIB_NODE_INDEX_INVALID != esrc->fes_pl)
1198 fib_path_list_contribute_forwarding(
1200 fib_entry_get_default_chain_type(fib_entry),
1203 return (dpo_id_is_valid(dpo));
1210 fib_entry_get_resolving_interface_for_source (fib_node_index_t entry_index,
1211 fib_source_t source)
1213 fib_entry_t *fib_entry;
1214 fib_entry_src_t *esrc;
1216 fib_entry = fib_entry_get(entry_index);
1218 esrc = fib_entry_src_find(fib_entry, source, NULL);
1222 if (FIB_NODE_INDEX_INVALID != esrc->fes_pl)
1224 return (fib_path_list_get_resolving_interface(esrc->fes_pl));
1231 fib_entry_get_flags_for_source (fib_node_index_t entry_index,
1232 fib_source_t source)
1234 fib_entry_t *fib_entry;
1235 fib_entry_src_t *esrc;
1237 fib_entry = fib_entry_get(entry_index);
1239 esrc = fib_entry_src_find(fib_entry, source, NULL);
1243 return (esrc->fes_entry_flags);
1246 return (FIB_ENTRY_FLAG_NONE);
1250 fib_entry_get_flags_i (const fib_entry_t *fib_entry)
1252 fib_entry_flag_t flags;
1255 * the vector of sources is deliberately arranged in priority order
1257 if (0 == vec_len(fib_entry->fe_srcs))
1259 flags = FIB_ENTRY_FLAG_NONE;
1263 fib_entry_src_t *esrc;
1265 esrc = vec_elt_at_index(fib_entry->fe_srcs, 0);
1266 flags = esrc->fes_entry_flags;
1273 fib_entry_set_source_data (fib_node_index_t fib_entry_index,
1274 fib_source_t source,
1277 fib_entry_t *fib_entry;
1278 fib_entry_src_t *esrc;
1280 fib_entry = fib_entry_get(fib_entry_index);
1281 esrc = fib_entry_src_find(fib_entry, source, NULL);
1284 NULL != fib_entry_src_vft[source].fesv_set_data)
1286 fib_entry_src_vft[source].fesv_set_data(esrc, fib_entry, data);
1291 fib_entry_get_source_data (fib_node_index_t fib_entry_index,
1292 fib_source_t source)
1294 fib_entry_t *fib_entry;
1295 fib_entry_src_t *esrc;
1297 fib_entry = fib_entry_get(fib_entry_index);
1298 esrc = fib_entry_src_find(fib_entry, source, NULL);
1301 NULL != fib_entry_src_vft[source].fesv_get_data)
1303 return (fib_entry_src_vft[source].fesv_get_data(esrc, fib_entry));
1309 fib_entry_src_module_init (void)
1311 fib_entry_src_rr_register();
1312 fib_entry_src_interface_register();
1313 fib_entry_src_default_route_register();
1314 fib_entry_src_special_register();
1315 fib_entry_src_api_register();
1316 fib_entry_src_adj_register();
1317 fib_entry_src_mpls_register();
1318 fib_entry_src_lisp_register();