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 <vnet/fib/fib_entry_src.h>
22 #include <vnet/fib/fib_table.h>
23 #include <vnet/fib/fib_path_ext.h>
24 #include <vnet/fib/fib_urpf_list.h>
29 static fib_entry_src_vft_t fib_entry_src_vft[FIB_SOURCE_MAX];
32 fib_entry_get_proto (const fib_entry_t * fib_entry)
34 return (fib_entry->fe_prefix.fp_proto);
38 fib_entry_src_register (fib_source_t source,
39 const fib_entry_src_vft_t *vft)
41 fib_entry_src_vft[source] = *vft;
45 fib_entry_src_cmp_for_sort (void * v1,
48 fib_entry_src_t *esrc1 = v1, *esrc2 = v2;
50 return (esrc1->fes_src - esrc2->fes_src);
54 fib_entry_src_action_init (fib_entry_t *fib_entry,
58 fib_entry_src_t esrc = {
59 .fes_pl = FIB_NODE_INDEX_INVALID,
60 .fes_flags = FIB_ENTRY_SRC_FLAG_NONE,
64 if (NULL != fib_entry_src_vft[source].fesv_init)
66 fib_entry_src_vft[source].fesv_init(&esrc);
69 vec_add1(fib_entry->fe_srcs, esrc);
70 vec_sort_with_function(fib_entry->fe_srcs,
71 fib_entry_src_cmp_for_sort);
74 static fib_entry_src_t *
75 fib_entry_src_find (const fib_entry_t *fib_entry,
80 fib_entry_src_t *esrc;
84 vec_foreach(esrc, fib_entry->fe_srcs)
86 if (esrc->fes_src == source)
104 fib_entry_is_sourced (fib_node_index_t fib_entry_index,
107 fib_entry_t *fib_entry;
109 fib_entry = fib_entry_get(fib_entry_index);
111 return (NULL != fib_entry_src_find(fib_entry, source, NULL));
114 static fib_entry_src_t *
115 fib_entry_src_find_or_create (fib_entry_t *fib_entry,
119 fib_entry_src_t *esrc;
121 esrc = fib_entry_src_find(fib_entry, source, NULL);
125 fib_entry_src_action_init(fib_entry, source);
128 return (fib_entry_src_find(fib_entry, source, NULL));
132 fib_entry_src_action_deinit (fib_entry_t *fib_entry,
136 fib_entry_src_t *esrc;
139 esrc = fib_entry_src_find(fib_entry, source, &index);
141 ASSERT(NULL != esrc);
143 if (NULL != fib_entry_src_vft[source].fesv_deinit)
145 fib_entry_src_vft[source].fesv_deinit(esrc);
148 vec_free(esrc->fes_path_exts);
149 vec_del1(fib_entry->fe_srcs, index);
152 fib_entry_src_cover_res_t
153 fib_entry_src_action_cover_change (fib_entry_t *fib_entry,
156 if (NULL != fib_entry_src_vft[source].fesv_cover_change)
158 return (fib_entry_src_vft[source].fesv_cover_change(
159 fib_entry_src_find(fib_entry, source, NULL),
163 fib_entry_src_cover_res_t res = {
165 .bw_reason = FIB_NODE_BW_REASON_FLAG_NONE,
170 fib_entry_src_cover_res_t
171 fib_entry_src_action_cover_update (fib_entry_t *fib_entry,
174 if (NULL != fib_entry_src_vft[source].fesv_cover_update)
176 return (fib_entry_src_vft[source].fesv_cover_update(
177 fib_entry_src_find(fib_entry, source, NULL),
181 fib_entry_src_cover_res_t res = {
183 .bw_reason = FIB_NODE_BW_REASON_FLAG_NONE,
188 typedef struct fib_entry_src_collect_forwarding_ctx_t_
190 load_balance_path_t * next_hops;
191 const fib_entry_t *fib_entry;
192 const fib_entry_src_t *esrc;
193 fib_forward_chain_type_t fct;
195 } fib_entry_src_collect_forwarding_ctx_t;
198 * @brief Determine whether this FIB entry should use a load-balance MAP
199 * to support PIC edge fast convergence
202 fib_entry_calc_lb_flags (fib_entry_src_collect_forwarding_ctx_t *ctx)
205 * We'll use a LB map is the path-list has recursive paths.
206 * recursive paths implies BGP, and hence scale.
208 if (ctx->is_recursive)
210 return (LOAD_BALANCE_FLAG_USES_MAP);
212 return (LOAD_BALANCE_FLAG_NONE);
216 fib_entry_src_valid_out_label (mpls_label_t label)
218 return ((MPLS_LABEL_IS_REAL(label) ||
219 MPLS_IETF_IPV4_EXPLICIT_NULL_LABEL == label ||
220 MPLS_IETF_IPV6_EXPLICIT_NULL_LABEL == label ||
221 MPLS_IETF_IMPLICIT_NULL_LABEL == label));
225 fib_entry_src_collect_forwarding (fib_node_index_t pl_index,
226 fib_node_index_t path_index,
229 fib_entry_src_collect_forwarding_ctx_t *ctx;
230 fib_path_ext_t *path_ext;
235 * if the path is not resolved, don't include it.
237 if (!fib_path_is_resolved(path_index))
242 if (fib_path_is_recursive(path_index))
244 ctx->is_recursive = 1;
248 * get the matching path-extension for the path being visited.
250 vec_foreach(path_ext, ctx->esrc->fes_path_exts)
252 if (path_ext->fpe_path_index == path_index)
256 if (NULL != path_ext &&
257 path_ext->fpe_path_index == path_index &&
258 fib_entry_src_valid_out_label(path_ext->fpe_label))
261 * found a matching extension. stack it to obtain the forwarding
262 * info for this path.
264 ctx->next_hops = fib_path_ext_stack(path_ext, ctx->fct, ctx->next_hops);
268 load_balance_path_t *nh;
271 * no extension => no out-going label for this path. that's OK
272 * in the case of an IP or EOS chain, but not for non-EOS
276 case FIB_FORW_CHAIN_TYPE_UNICAST_IP4:
277 case FIB_FORW_CHAIN_TYPE_UNICAST_IP6:
279 * EOS traffic with no label to stack, we need the IP Adj
281 vec_add2(ctx->next_hops, nh, 1);
283 nh->path_index = path_index;
284 nh->path_weight = fib_path_get_weight(path_index);
285 fib_path_contribute_forwarding(path_index, ctx->fct, &nh->path_dpo);
288 case FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS:
289 if (fib_path_is_exclusive(path_index) ||
290 fib_path_is_deag(path_index))
292 vec_add2(ctx->next_hops, nh, 1);
294 nh->path_index = path_index;
295 nh->path_weight = fib_path_get_weight(path_index);
296 fib_path_contribute_forwarding(path_index,
297 FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS,
301 case FIB_FORW_CHAIN_TYPE_MPLS_EOS:
302 case FIB_FORW_CHAIN_TYPE_ETHERNET:
312 fib_entry_src_mk_lb (fib_entry_t *fib_entry,
313 const fib_entry_src_t *esrc,
314 fib_forward_chain_type_t fct,
317 dpo_proto_t lb_proto;
320 * If the entry has path extensions then we construct a load-balance
321 * by stacking the extensions on the forwarding chains of the paths.
322 * Otherwise we use the load-balance of the path-list
324 fib_entry_src_collect_forwarding_ctx_t ctx = {
326 .fib_entry = fib_entry,
332 lb_proto = fib_proto_to_dpo(fib_entry->fe_prefix.fp_proto);
334 fib_path_list_walk(esrc->fes_pl,
335 fib_entry_src_collect_forwarding,
338 if (esrc->fes_entry_flags & FIB_ENTRY_FLAG_EXCLUSIVE)
341 * the client provided the DPO that the entry should link to.
342 * all entries must link to a LB, so if it is an LB already
343 * then we can use it.
345 if ((1 == vec_len(ctx.next_hops)) &&
346 (DPO_LOAD_BALANCE == ctx.next_hops[0].path_dpo.dpoi_type))
348 dpo_copy(dpo_lb, &ctx.next_hops[0].path_dpo);
349 dpo_reset(&ctx.next_hops[0].path_dpo);
354 if (!dpo_id_is_valid(dpo_lb))
359 flow_hash_config_t fhc;
361 fhc = fib_table_get_flow_hash_config(fib_entry->fe_fib_index,
362 dpo_proto_to_fib(lb_proto));
366 load_balance_create(0, lb_proto, fhc));
369 load_balance_multipath_update(dpo_lb,
371 fib_entry_calc_lb_flags(&ctx));
372 vec_free(ctx.next_hops);
375 * if this entry is sourced by the uRPF-exempt source then we
376 * append the always present local0 interface (index 0) to the
377 * uRPF list so it is not empty. that way packets pass the loose check.
379 index_t ui = fib_path_list_get_urpf(esrc->fes_pl);
381 if (fib_entry_is_sourced(fib_entry_get_index(fib_entry),
382 FIB_SOURCE_URPF_EXEMPT) &&
383 (0 == fib_urpf_check_size(ui)))
386 * The uRPF list we get from the path-list is shared by all
387 * other users of the list, but the uRPF exemption applies
388 * only to this prefix. So we need our own list.
390 ui = fib_urpf_list_alloc_and_lock();
391 fib_urpf_list_append(ui, 0);
392 fib_urpf_list_bake(ui);
393 load_balance_set_urpf(dpo_lb->dpoi_index, ui);
394 fib_urpf_list_unlock(ui);
398 load_balance_set_urpf(dpo_lb->dpoi_index, ui);
403 fib_entry_src_action_install (fib_entry_t *fib_entry,
407 * Install the forwarding chain for the given source into the forwarding
410 fib_forward_chain_type_t fct;
411 fib_entry_src_t *esrc;
414 fct = fib_entry_get_default_chain_type(fib_entry);
415 esrc = fib_entry_src_find(fib_entry, source, NULL);
418 * Every entry has its own load-balance object. All changes to the entry's
419 * forwarding result in an inplace modify of the load-balance. This means
420 * the load-balance object only needs to be added to the forwarding
421 * DB once, when it is created.
423 insert = !dpo_id_is_valid(&fib_entry->fe_lb[fct]);
425 fib_entry_src_mk_lb(fib_entry, esrc, fct, &fib_entry->fe_lb[fct]);
427 ASSERT(dpo_id_is_valid(&fib_entry->fe_lb[fct]));
428 FIB_ENTRY_DBG(fib_entry, "install: %d", fib_entry->fe_lb[fct]);
431 * insert the adj into the data-plane forwarding trie
435 fib_table_fwding_dpo_update(fib_entry->fe_fib_index,
436 &fib_entry->fe_prefix,
437 &fib_entry->fe_lb[fct]);
440 if (FIB_FORW_CHAIN_TYPE_UNICAST_IP4 == fct ||
441 FIB_FORW_CHAIN_TYPE_UNICAST_IP6 == fct)
443 for (fct = FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS;
444 fct <= FIB_FORW_CHAIN_TYPE_MPLS_EOS;
448 * if any of the other chain types are already created they will need
451 if (dpo_id_is_valid(&fib_entry->fe_lb[fct]))
453 fib_entry_src_mk_lb(fib_entry,
456 &fib_entry->fe_lb[fct]);
463 fib_entry_src_action_uninstall (fib_entry_t *fib_entry)
465 fib_forward_chain_type_t fct;
467 fct = fib_entry_get_default_chain_type(fib_entry);
469 * uninstall the forwarding chain from the forwarding tables
471 FIB_ENTRY_DBG(fib_entry, "uninstall: %d",
472 fib_entry->fe_adj_index);
474 if (dpo_id_is_valid(&fib_entry->fe_lb[fct]))
476 fib_table_fwding_dpo_remove(
477 fib_entry->fe_fib_index,
478 &fib_entry->fe_prefix,
479 &fib_entry->fe_lb[fct]);
481 dpo_reset(&fib_entry->fe_lb[fct]);
486 fib_entry_recursive_loop_detect_i (fib_node_index_t path_list_index)
488 fib_node_index_t *entries = NULL;
490 fib_path_list_recursive_loop_detect(path_list_index, &entries);
496 fib_entry_src_action_activate (fib_entry_t *fib_entry,
500 int houston_we_are_go_for_install;
501 fib_entry_src_t *esrc;
503 esrc = fib_entry_src_find(fib_entry, source, NULL);
505 ASSERT(!(esrc->fes_flags & FIB_ENTRY_SRC_FLAG_ACTIVE));
506 ASSERT(esrc->fes_flags & FIB_ENTRY_SRC_FLAG_ADDED);
508 esrc->fes_flags |= FIB_ENTRY_SRC_FLAG_ACTIVE;
510 if (NULL != fib_entry_src_vft[source].fesv_activate)
512 houston_we_are_go_for_install =
513 fib_entry_src_vft[source].fesv_activate(esrc, fib_entry);
518 * the source is not providing an activate function, we'll assume
519 * therefore it has no objection to installing the entry
521 houston_we_are_go_for_install = !0;
525 * link to the path-list provided by the source, and go check
526 * if that forms any loops in the graph.
528 fib_entry->fe_parent = esrc->fes_pl;
529 fib_entry->fe_sibling =
530 fib_path_list_child_add(fib_entry->fe_parent,
532 fib_entry_get_index(fib_entry));
534 fib_entry_recursive_loop_detect_i(fib_entry->fe_parent);
536 FIB_ENTRY_DBG(fib_entry, "activate: %d",
537 fib_entry->fe_parent);
539 if (0 != houston_we_are_go_for_install)
541 fib_entry_src_action_install(fib_entry, source);
545 fib_entry_src_action_uninstall(fib_entry);
550 fib_entry_src_action_deactivate (fib_entry_t *fib_entry,
554 fib_node_index_t path_list_index;
555 fib_entry_src_t *esrc;
557 esrc = fib_entry_src_find(fib_entry, source, NULL);
559 ASSERT(esrc->fes_flags & FIB_ENTRY_SRC_FLAG_ACTIVE);
561 if (NULL != fib_entry_src_vft[source].fesv_deactivate)
563 fib_entry_src_vft[source].fesv_deactivate(esrc, fib_entry);
566 esrc->fes_flags &= ~FIB_ENTRY_SRC_FLAG_ACTIVE;
568 FIB_ENTRY_DBG(fib_entry, "deactivate: %d", fib_entry->fe_parent);
571 * un-link from an old path-list. Check for any loops this will clear
573 path_list_index = fib_entry->fe_parent;
574 fib_entry->fe_parent = FIB_NODE_INDEX_INVALID;
576 fib_entry_recursive_loop_detect_i(path_list_index);
579 * this will unlock the path-list, so it may be invalid thereafter.
581 fib_path_list_child_remove(path_list_index, fib_entry->fe_sibling);
582 fib_entry->fe_sibling = FIB_NODE_INDEX_INVALID;
586 fib_entry_src_action_fwd_update (const fib_entry_t *fib_entry,
589 fib_entry_src_t *esrc;
591 vec_foreach(esrc, fib_entry->fe_srcs)
593 if (NULL != fib_entry_src_vft[esrc->fes_src].fesv_fwd_update)
595 fib_entry_src_vft[esrc->fes_src].fesv_fwd_update(esrc,
603 fib_entry_src_action_reactivate (fib_entry_t *fib_entry,
606 fib_node_index_t path_list_index;
607 fib_entry_src_t *esrc;
609 esrc = fib_entry_src_find(fib_entry, source, NULL);
611 ASSERT(esrc->fes_flags & FIB_ENTRY_SRC_FLAG_ACTIVE);
613 FIB_ENTRY_DBG(fib_entry, "reactivate: %d to %d",
614 fib_entry->fe_parent,
617 if (fib_entry->fe_parent != esrc->fes_pl)
620 * un-link from an old path-list. Check for any loops this will clear
622 path_list_index = fib_entry->fe_parent;
623 fib_entry->fe_parent = FIB_NODE_INDEX_INVALID;
626 * temporary lock so it doesn't get deleted when this entry is no
629 fib_path_list_lock(path_list_index);
632 * this entry is no longer a child. after unlinking check if any loops
635 fib_path_list_child_remove(path_list_index,
636 fib_entry->fe_sibling);
638 fib_entry_recursive_loop_detect_i(path_list_index);
641 * link to the path-list provided by the source, and go check
642 * if that forms any loops in the graph.
644 fib_entry->fe_parent = esrc->fes_pl;
645 fib_entry->fe_sibling =
646 fib_path_list_child_add(fib_entry->fe_parent,
648 fib_entry_get_index(fib_entry));
650 fib_entry_recursive_loop_detect_i(fib_entry->fe_parent);
651 fib_path_list_unlock(path_list_index);
653 fib_entry_src_action_install(fib_entry, source);
654 fib_entry_src_action_fwd_update(fib_entry, source);
658 fib_entry_src_action_installed (const fib_entry_t *fib_entry,
661 fib_entry_src_t *esrc;
663 esrc = fib_entry_src_find(fib_entry, source, NULL);
665 if (NULL != fib_entry_src_vft[source].fesv_installed)
667 fib_entry_src_vft[source].fesv_installed(esrc,
671 fib_entry_src_action_fwd_update(fib_entry, source);
675 * fib_entry_src_action_add
677 * Adding a source can result in a new fib_entry being created, which
678 * can inturn mean the pool is realloc'd and thus the entry passed as
679 * an argument it also realloc'd
680 * @return the original entry
683 fib_entry_src_action_add (fib_entry_t *fib_entry,
685 fib_entry_flag_t flags,
688 fib_node_index_t fib_entry_index;
689 fib_entry_src_t *esrc;
691 esrc = fib_entry_src_find_or_create(fib_entry, source, NULL);
693 esrc->fes_ref_count++;
695 if (1 != esrc->fes_ref_count)
698 * we only want to add the source on the 0->1 transition
703 esrc->fes_entry_flags = flags;
706 * save variable so we can recover from a fib_entry realloc.
708 fib_entry_index = fib_entry_get_index(fib_entry);
710 if (NULL != fib_entry_src_vft[source].fesv_add)
712 fib_entry_src_vft[source].fesv_add(esrc,
715 fib_entry_get_proto(fib_entry),
719 fib_entry = fib_entry_get(fib_entry_index);
721 esrc->fes_flags |= FIB_ENTRY_SRC_FLAG_ADDED;
723 fib_path_list_lock(esrc->fes_pl);
726 * the source owns a lock on the entry
728 fib_entry_lock(fib_entry_get_index(fib_entry));
734 * fib_entry_src_action_update
736 * Adding a source can result in a new fib_entry being created, which
737 * can inturn mean the pool is realloc'd and thus the entry passed as
738 * an argument it also realloc'd
739 * @return the original entry
742 fib_entry_src_action_update (fib_entry_t *fib_entry,
744 fib_entry_flag_t flags,
747 fib_node_index_t fib_entry_index, old_path_list_index;
748 fib_entry_src_t *esrc;
750 esrc = fib_entry_src_find_or_create(fib_entry, source, NULL);
753 return (fib_entry_src_action_add(fib_entry, source, flags, dpo));
755 old_path_list_index = esrc->fes_pl;
756 esrc->fes_entry_flags = flags;
759 * save variable so we can recover from a fib_entry realloc.
761 fib_entry_index = fib_entry_get_index(fib_entry);
763 if (NULL != fib_entry_src_vft[source].fesv_add)
765 fib_entry_src_vft[source].fesv_add(esrc,
768 fib_entry_get_proto(fib_entry),
772 fib_entry = fib_entry_get(fib_entry_index);
774 esrc->fes_flags |= FIB_ENTRY_SRC_FLAG_ADDED;
776 fib_path_list_lock(esrc->fes_pl);
777 fib_path_list_unlock(old_path_list_index);
784 fib_entry_src_action_remove (fib_entry_t *fib_entry,
788 fib_node_index_t old_path_list;
789 fib_entry_src_flag_t sflags;
790 fib_entry_src_t *esrc;
792 esrc = fib_entry_src_find(fib_entry, source, NULL);
795 return (FIB_ENTRY_SRC_FLAG_ACTIVE);
797 esrc->fes_ref_count--;
798 sflags = esrc->fes_flags;
800 if (0 != esrc->fes_ref_count)
803 * only remove the source on the 1->0 transisition
808 if (esrc->fes_flags & FIB_ENTRY_SRC_FLAG_ACTIVE)
810 fib_entry_src_action_deactivate(fib_entry, source);
813 old_path_list = esrc->fes_pl;
815 if (NULL != fib_entry_src_vft[source].fesv_remove)
817 fib_entry_src_vft[source].fesv_remove(esrc);
820 fib_path_list_unlock(old_path_list);
821 fib_entry_unlock(fib_entry_get_index(fib_entry));
823 sflags &= ~FIB_ENTRY_SRC_FLAG_ADDED;
824 fib_entry_src_action_deinit(fib_entry, source);
830 fib_route_recurses_via_self (const fib_prefix_t *prefix,
831 const fib_route_path_t *rpath)
834 * not all zeros next hop &&
835 * is recursive path &&
836 * nexthop is same as the route's address
838 return ((!ip46_address_is_zero(&rpath->frp_addr)) &&
839 (~0 == rpath->frp_sw_if_index) &&
840 (0 == ip46_address_cmp(&rpath->frp_addr, &prefix->fp_addr)));
845 * fib_route_attached_cross_table
847 * Return true the the route is attached via an interface that
848 * is not in the same table as the route
851 fib_route_attached_cross_table (const fib_entry_t *fib_entry,
852 const fib_route_path_t *rpath)
855 * - All zeros next-hop
856 * - a valid interface
857 * - entry's fib index not equeal to interface's index
859 if (ip46_address_is_zero(&rpath->frp_addr) &&
860 (~0 != rpath->frp_sw_if_index) &&
861 (fib_entry->fe_fib_index !=
862 fib_table_get_index_for_sw_if_index(fib_entry_get_proto(fib_entry),
863 rpath->frp_sw_if_index)))
871 * fib_route_attached_cross_table
873 * Return true the the route is attached via an interface that
874 * is not in the same table as the route
877 fib_path_is_attached (const fib_route_path_t *rpath)
880 * - All zeros next-hop
881 * - a valid interface
883 if (ip46_address_is_zero(&rpath->frp_addr) &&
884 (~0 != rpath->frp_sw_if_index))
891 fib_path_list_flags_t
892 fib_entry_src_flags_2_path_list_flags (fib_entry_flag_t eflags)
894 fib_path_list_flags_t plf = FIB_PATH_LIST_FLAG_NONE;
896 if (eflags & FIB_ENTRY_FLAG_DROP)
898 plf |= FIB_PATH_LIST_FLAG_DROP;
900 if (eflags & FIB_ENTRY_FLAG_LOCAL)
902 plf |= FIB_PATH_LIST_FLAG_LOCAL;
904 if (eflags & FIB_ENTRY_FLAG_EXCLUSIVE)
906 plf |= FIB_PATH_LIST_FLAG_EXCLUSIVE;
913 fib_entry_flags_update (const fib_entry_t *fib_entry,
914 const fib_route_path_t *rpath,
915 fib_path_list_flags_t *pl_flags,
916 fib_entry_src_t *esrc)
919 * don't allow the addition of a recursive looped path for prefix
922 if (fib_route_recurses_via_self(&fib_entry->fe_prefix, rpath))
925 * force the install of a drop path-list.
926 * we want the entry to have some path-list, mainly so
927 * the dodgy path can be rmeoved when the source stops playing
930 *pl_flags |= FIB_PATH_LIST_FLAG_DROP;
934 *pl_flags &= ~FIB_PATH_LIST_FLAG_DROP;
937 if ((esrc->fes_src == FIB_SOURCE_API) ||
938 (esrc->fes_src == FIB_SOURCE_CLI))
940 if (fib_path_is_attached(rpath))
942 esrc->fes_entry_flags |= FIB_ENTRY_FLAG_ATTACHED;
946 esrc->fes_entry_flags &= ~FIB_ENTRY_FLAG_ATTACHED;
949 if (fib_route_attached_cross_table(fib_entry, rpath))
951 esrc->fes_entry_flags |= FIB_ENTRY_FLAG_IMPORT;
955 esrc->fes_entry_flags &= ~FIB_ENTRY_FLAG_IMPORT;
960 * fib_entry_src_path_ext_add
962 * append a path extension to the entry's list
965 fib_entry_src_path_ext_append (fib_entry_src_t *esrc,
966 const fib_route_path_t *rpath)
968 if (MPLS_LABEL_INVALID != rpath->frp_label)
970 fib_path_ext_t *path_ext;
972 vec_add2(esrc->fes_path_exts, path_ext, 1);
974 fib_path_ext_init(path_ext, esrc->fes_pl, rpath);
979 * fib_entry_src_path_ext_insert
981 * insert, sorted, a path extension to the entry's list.
982 * It's not strictly necessary in sort the path extensions, since each
983 * extension has the path index to which it resolves. However, by being
984 * sorted the load-balance produced has a deterministic order, not an order
985 * based on the sequence of extension additions. this is a considerable benefit.
988 fib_entry_src_path_ext_insert (fib_entry_src_t *esrc,
989 const fib_route_path_t *rpath)
991 if (0 == vec_len(esrc->fes_path_exts))
992 return (fib_entry_src_path_ext_append(esrc, rpath));
994 if (MPLS_LABEL_INVALID != rpath->frp_label)
996 fib_path_ext_t path_ext;
999 fib_path_ext_init(&path_ext, esrc->fes_pl, rpath);
1001 while (i < vec_len(esrc->fes_path_exts) &&
1002 (fib_path_ext_cmp(&esrc->fes_path_exts[i], rpath) < 0))
1007 vec_insert_elts(esrc->fes_path_exts, &path_ext, 1, i);
1012 * fib_entry_src_action_add
1014 * Adding a source can result in a new fib_entry being created, which
1015 * can inturn mean the pool is realloc'd and thus the entry passed as
1016 * an argument it also realloc'd
1020 fib_entry_src_action_path_add (fib_entry_t *fib_entry,
1021 fib_source_t source,
1022 fib_entry_flag_t flags,
1023 const fib_route_path_t *rpath)
1025 fib_node_index_t old_path_list, fib_entry_index;
1026 fib_path_list_flags_t pl_flags;
1027 fib_path_ext_t *path_ext;
1028 fib_entry_src_t *esrc;
1031 * save variable so we can recover from a fib_entry realloc.
1033 fib_entry_index = fib_entry_get_index(fib_entry);
1035 esrc = fib_entry_src_find(fib_entry, source, NULL);
1039 fib_entry_src_action_add(fib_entry,
1044 fib_entry_get_proto(fib_entry))));
1045 esrc = fib_entry_src_find(fib_entry, source, NULL);
1049 * we are no doubt modifying a path-list. If the path-list
1050 * is shared, and hence not modifiable, then the index returned
1051 * will be for a different path-list. This FIB entry to needs
1052 * to maintain its lock appropriately.
1054 old_path_list = esrc->fes_pl;
1056 ASSERT(NULL != fib_entry_src_vft[source].fesv_path_add);
1058 pl_flags = fib_entry_src_flags_2_path_list_flags(fib_entry_get_flags_i(fib_entry));
1059 fib_entry_flags_update(fib_entry, rpath, &pl_flags, esrc);
1061 fib_entry_src_vft[source].fesv_path_add(esrc, fib_entry, pl_flags, rpath);
1062 fib_entry = fib_entry_get(fib_entry_index);
1065 * re-resolve all the path-extensions with the new path-list
1067 vec_foreach(path_ext, esrc->fes_path_exts)
1069 fib_path_ext_resolve(path_ext, esrc->fes_pl);
1072 * if the path has a label we need to add a path extension
1074 fib_entry_src_path_ext_insert(esrc, rpath);
1076 fib_path_list_lock(esrc->fes_pl);
1077 fib_path_list_unlock(old_path_list);
1083 * fib_entry_src_action_swap
1085 * The source is providing new paths to replace the old ones.
1086 * Adding a source can result in a new fib_entry being created, which
1087 * can inturn mean the pool is realloc'd and thus the entry passed as
1088 * an argument it also realloc'd
1092 fib_entry_src_action_path_swap (fib_entry_t *fib_entry,
1093 fib_source_t source,
1094 fib_entry_flag_t flags,
1095 const fib_route_path_t *rpaths)
1097 fib_node_index_t old_path_list, fib_entry_index;
1098 fib_path_list_flags_t pl_flags;
1099 const fib_route_path_t *rpath;
1100 fib_entry_src_t *esrc;
1102 esrc = fib_entry_src_find(fib_entry, source, NULL);
1105 * save variable so we can recover from a fib_entry realloc.
1107 fib_entry_index = fib_entry_get_index(fib_entry);
1111 fib_entry = fib_entry_src_action_add(fib_entry,
1116 fib_entry_get_proto(fib_entry))));
1117 esrc = fib_entry_src_find(fib_entry, source, NULL);
1121 * swapping paths may create a new path-list (or may use an existing shared)
1122 * but we are certainly getting a different one. This FIB entry to needs
1123 * to maintain its lock appropriately.
1125 old_path_list = esrc->fes_pl;
1127 ASSERT(NULL != fib_entry_src_vft[source].fesv_path_swap);
1129 pl_flags = fib_entry_src_flags_2_path_list_flags(flags);
1131 vec_foreach(rpath, rpaths)
1133 fib_entry_flags_update(fib_entry, rpath, &pl_flags, esrc);
1136 fib_entry_src_vft[source].fesv_path_swap(esrc,
1141 vec_free(esrc->fes_path_exts);
1142 vec_foreach(rpath, rpaths)
1144 fib_entry_src_path_ext_append(esrc, rpath);
1147 fib_entry = fib_entry_get(fib_entry_index);
1149 fib_path_list_lock(esrc->fes_pl);
1150 fib_path_list_unlock(old_path_list);
1155 fib_entry_src_flag_t
1156 fib_entry_src_action_path_remove (fib_entry_t *fib_entry,
1157 fib_source_t source,
1158 const fib_route_path_t *rpath)
1160 fib_path_list_flags_t pl_flags;
1161 fib_node_index_t old_path_list;
1162 fib_path_ext_t *path_ext;
1163 fib_entry_src_t *esrc;
1165 esrc = fib_entry_src_find(fib_entry, source, NULL);
1167 ASSERT(NULL != esrc);
1168 ASSERT(esrc->fes_flags & FIB_ENTRY_SRC_FLAG_ADDED);
1171 * we no doubt modifying a path-list. If the path-list
1172 * is shared, and hence not modifiable, then the index returned
1173 * will be for a different path-list. This FIB entry to needs
1174 * to maintain its lock appropriately.
1176 old_path_list = esrc->fes_pl;
1178 ASSERT(NULL != fib_entry_src_vft[source].fesv_path_remove);
1180 pl_flags = fib_entry_src_flags_2_path_list_flags(fib_entry_get_flags_i(fib_entry));
1181 fib_entry_flags_update(fib_entry, rpath, &pl_flags, esrc);
1183 fib_entry_src_vft[source].fesv_path_remove(esrc, pl_flags, rpath);
1185 * find the matching path extension and remove it
1187 vec_foreach(path_ext, esrc->fes_path_exts)
1189 if (!fib_path_ext_cmp(path_ext, rpath))
1192 * delete the element moving the remaining elements down 1 position.
1193 * this preserves the sorted order.
1195 vec_delete(esrc->fes_path_exts, 1, (path_ext - esrc->fes_path_exts));
1200 * re-resolve all the path-extensions with the new path-list
1202 vec_foreach(path_ext, esrc->fes_path_exts)
1204 fib_path_ext_resolve(path_ext, esrc->fes_pl);
1208 * lock the new path-list, unlock the old if it had one
1210 fib_path_list_unlock(old_path_list);
1212 if (FIB_NODE_INDEX_INVALID != esrc->fes_pl) {
1213 fib_path_list_lock(esrc->fes_pl);
1214 return (FIB_ENTRY_SRC_FLAG_ADDED);
1219 * no more paths left from this source
1221 fib_entry_src_action_remove(fib_entry, source);
1222 return (FIB_ENTRY_SRC_FLAG_NONE);
1227 fib_entry_src_format (fib_entry_t *fib_entry,
1228 fib_source_t source,
1231 fib_entry_src_t *esrc;
1233 esrc = fib_entry_src_find(fib_entry, source, NULL);
1235 if (NULL != fib_entry_src_vft[source].fesv_format)
1237 return (fib_entry_src_vft[source].fesv_format(esrc, s));
1243 fib_entry_get_adj_for_source (fib_node_index_t fib_entry_index,
1244 fib_source_t source)
1246 fib_entry_t *fib_entry;
1247 fib_entry_src_t *esrc;
1249 if (FIB_NODE_INDEX_INVALID == fib_entry_index)
1250 return (ADJ_INDEX_INVALID);
1252 fib_entry = fib_entry_get(fib_entry_index);
1253 esrc = fib_entry_src_find(fib_entry, source, NULL);
1257 if (FIB_NODE_INDEX_INVALID != esrc->fes_pl)
1259 return (fib_path_list_get_adj(
1261 fib_entry_get_default_chain_type(fib_entry)));
1264 return (ADJ_INDEX_INVALID);
1268 fib_entry_get_dpo_for_source (fib_node_index_t fib_entry_index,
1269 fib_source_t source,
1272 fib_entry_t *fib_entry;
1273 fib_entry_src_t *esrc;
1275 if (FIB_NODE_INDEX_INVALID == fib_entry_index)
1278 fib_entry = fib_entry_get(fib_entry_index);
1279 esrc = fib_entry_src_find(fib_entry, source, NULL);
1283 if (FIB_NODE_INDEX_INVALID != esrc->fes_pl)
1285 fib_path_list_contribute_forwarding(
1287 fib_entry_get_default_chain_type(fib_entry),
1290 return (dpo_id_is_valid(dpo));
1297 fib_entry_get_resolving_interface_for_source (fib_node_index_t entry_index,
1298 fib_source_t source)
1300 fib_entry_t *fib_entry;
1301 fib_entry_src_t *esrc;
1303 fib_entry = fib_entry_get(entry_index);
1305 esrc = fib_entry_src_find(fib_entry, source, NULL);
1309 if (FIB_NODE_INDEX_INVALID != esrc->fes_pl)
1311 return (fib_path_list_get_resolving_interface(esrc->fes_pl));
1318 fib_entry_get_flags_for_source (fib_node_index_t entry_index,
1319 fib_source_t source)
1321 fib_entry_t *fib_entry;
1322 fib_entry_src_t *esrc;
1324 fib_entry = fib_entry_get(entry_index);
1326 esrc = fib_entry_src_find(fib_entry, source, NULL);
1330 return (esrc->fes_entry_flags);
1333 return (FIB_ENTRY_FLAG_NONE);
1337 fib_entry_get_flags_i (const fib_entry_t *fib_entry)
1339 fib_entry_flag_t flags;
1342 * the vector of sources is deliberately arranged in priority order
1344 if (0 == vec_len(fib_entry->fe_srcs))
1346 flags = FIB_ENTRY_FLAG_NONE;
1350 fib_entry_src_t *esrc;
1352 esrc = vec_elt_at_index(fib_entry->fe_srcs, 0);
1353 flags = esrc->fes_entry_flags;
1360 fib_entry_set_source_data (fib_node_index_t fib_entry_index,
1361 fib_source_t source,
1364 fib_entry_t *fib_entry;
1365 fib_entry_src_t *esrc;
1367 fib_entry = fib_entry_get(fib_entry_index);
1368 esrc = fib_entry_src_find(fib_entry, source, NULL);
1371 NULL != fib_entry_src_vft[source].fesv_set_data)
1373 fib_entry_src_vft[source].fesv_set_data(esrc, fib_entry, data);
1378 fib_entry_get_source_data (fib_node_index_t fib_entry_index,
1379 fib_source_t source)
1381 fib_entry_t *fib_entry;
1382 fib_entry_src_t *esrc;
1384 fib_entry = fib_entry_get(fib_entry_index);
1385 esrc = fib_entry_src_find(fib_entry, source, NULL);
1388 NULL != fib_entry_src_vft[source].fesv_get_data)
1390 return (fib_entry_src_vft[source].fesv_get_data(esrc, fib_entry));
1396 fib_entry_src_module_init (void)
1398 fib_entry_src_rr_register();
1399 fib_entry_src_interface_register();
1400 fib_entry_src_default_route_register();
1401 fib_entry_src_special_register();
1402 fib_entry_src_api_register();
1403 fib_entry_src_adj_register();
1404 fib_entry_src_mpls_register();
1405 fib_entry_src_lisp_register();