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 <vlib/vlib.h>
17 #include <vnet/vnet.h>
18 #include <vnet/ip/format.h>
19 #include <vnet/ip/ip.h>
20 #include <vnet/dpo/drop_dpo.h>
21 #include <vnet/dpo/receive_dpo.h>
22 #include <vnet/dpo/load_balance_map.h>
23 #include <vnet/dpo/lookup_dpo.h>
24 #include <vnet/dpo/interface_rx_dpo.h>
25 #include <vnet/dpo/mpls_disposition.h>
26 #include <vnet/dpo/l2_bridge_dpo.h>
27 #include <vnet/dpo/drop_dpo.h>
29 #include <vnet/adj/adj.h>
30 #include <vnet/adj/adj_mcast.h>
32 #include <vnet/fib/fib_path.h>
33 #include <vnet/fib/fib_node.h>
34 #include <vnet/fib/fib_table.h>
35 #include <vnet/fib/fib_entry.h>
36 #include <vnet/fib/fib_path_list.h>
37 #include <vnet/fib/fib_internal.h>
38 #include <vnet/fib/fib_urpf_list.h>
39 #include <vnet/fib/mpls_fib.h>
40 #include <vnet/udp/udp_encap.h>
41 #include <vnet/bier/bier_fmask.h>
42 #include <vnet/bier/bier_table.h>
43 #include <vnet/bier/bier_imp.h>
46 * Enurmeration of path types
48 typedef enum fib_path_type_t_ {
50 * Marker. Add new types after this one.
52 FIB_PATH_TYPE_FIRST = 0,
54 * Attached-nexthop. An interface and a nexthop are known.
56 FIB_PATH_TYPE_ATTACHED_NEXT_HOP = FIB_PATH_TYPE_FIRST,
58 * attached. Only the interface is known.
60 FIB_PATH_TYPE_ATTACHED,
62 * recursive. Only the next-hop is known.
64 FIB_PATH_TYPE_RECURSIVE,
66 * special. nothing is known. so we drop.
68 FIB_PATH_TYPE_SPECIAL,
70 * exclusive. user provided adj.
72 FIB_PATH_TYPE_EXCLUSIVE,
74 * deag. Link to a lookup adj in the next table
80 FIB_PATH_TYPE_INTF_RX,
84 FIB_PATH_TYPE_UDP_ENCAP,
86 * receive. it's for-us.
88 FIB_PATH_TYPE_RECEIVE,
90 * bier-imp. it's via a BIER imposition.
92 FIB_PATH_TYPE_BIER_IMP,
94 * bier-fmask. it's via a BIER ECMP-table.
96 FIB_PATH_TYPE_BIER_TABLE,
98 * bier-fmask. it's via a BIER f-mask.
100 FIB_PATH_TYPE_BIER_FMASK,
102 * Marker. Add new types before this one, then update it.
104 FIB_PATH_TYPE_LAST = FIB_PATH_TYPE_BIER_FMASK,
105 } __attribute__ ((packed)) fib_path_type_t;
108 * The maximum number of path_types
110 #define FIB_PATH_TYPE_MAX (FIB_PATH_TYPE_LAST + 1)
112 #define FIB_PATH_TYPES { \
113 [FIB_PATH_TYPE_ATTACHED_NEXT_HOP] = "attached-nexthop", \
114 [FIB_PATH_TYPE_ATTACHED] = "attached", \
115 [FIB_PATH_TYPE_RECURSIVE] = "recursive", \
116 [FIB_PATH_TYPE_SPECIAL] = "special", \
117 [FIB_PATH_TYPE_EXCLUSIVE] = "exclusive", \
118 [FIB_PATH_TYPE_DEAG] = "deag", \
119 [FIB_PATH_TYPE_INTF_RX] = "intf-rx", \
120 [FIB_PATH_TYPE_UDP_ENCAP] = "udp-encap", \
121 [FIB_PATH_TYPE_RECEIVE] = "receive", \
122 [FIB_PATH_TYPE_BIER_IMP] = "bier-imp", \
123 [FIB_PATH_TYPE_BIER_TABLE] = "bier-table", \
124 [FIB_PATH_TYPE_BIER_FMASK] = "bier-fmask", \
127 #define FOR_EACH_FIB_PATH_TYPE(_item) \
128 for (_item = FIB_PATH_TYPE_FIRST; \
129 _item <= FIB_PATH_TYPE_LAST; \
133 * Enurmeration of path operational (i.e. derived) attributes
135 typedef enum fib_path_oper_attribute_t_ {
137 * Marker. Add new types after this one.
139 FIB_PATH_OPER_ATTRIBUTE_FIRST = 0,
141 * The path forms part of a recursive loop.
143 FIB_PATH_OPER_ATTRIBUTE_RECURSIVE_LOOP = FIB_PATH_OPER_ATTRIBUTE_FIRST,
145 * The path is resolved
147 FIB_PATH_OPER_ATTRIBUTE_RESOLVED,
149 * The path is attached, despite what the next-hop may say.
151 FIB_PATH_OPER_ATTRIBUTE_ATTACHED,
153 * The path has become a permanent drop.
155 FIB_PATH_OPER_ATTRIBUTE_DROP,
157 * Marker. Add new types before this one, then update it.
159 FIB_PATH_OPER_ATTRIBUTE_LAST = FIB_PATH_OPER_ATTRIBUTE_DROP,
160 } __attribute__ ((packed)) fib_path_oper_attribute_t;
163 * The maximum number of path operational attributes
165 #define FIB_PATH_OPER_ATTRIBUTE_MAX (FIB_PATH_OPER_ATTRIBUTE_LAST + 1)
167 #define FIB_PATH_OPER_ATTRIBUTES { \
168 [FIB_PATH_OPER_ATTRIBUTE_RECURSIVE_LOOP] = "recursive-loop", \
169 [FIB_PATH_OPER_ATTRIBUTE_RESOLVED] = "resolved", \
170 [FIB_PATH_OPER_ATTRIBUTE_DROP] = "drop", \
173 #define FOR_EACH_FIB_PATH_OPER_ATTRIBUTE(_item) \
174 for (_item = FIB_PATH_OPER_ATTRIBUTE_FIRST; \
175 _item <= FIB_PATH_OPER_ATTRIBUTE_LAST; \
179 * Path flags from the attributes
181 typedef enum fib_path_oper_flags_t_ {
182 FIB_PATH_OPER_FLAG_NONE = 0,
183 FIB_PATH_OPER_FLAG_RECURSIVE_LOOP = (1 << FIB_PATH_OPER_ATTRIBUTE_RECURSIVE_LOOP),
184 FIB_PATH_OPER_FLAG_DROP = (1 << FIB_PATH_OPER_ATTRIBUTE_DROP),
185 FIB_PATH_OPER_FLAG_RESOLVED = (1 << FIB_PATH_OPER_ATTRIBUTE_RESOLVED),
186 FIB_PATH_OPER_FLAG_ATTACHED = (1 << FIB_PATH_OPER_ATTRIBUTE_ATTACHED),
187 } __attribute__ ((packed)) fib_path_oper_flags_t;
192 typedef struct fib_path_t_ {
194 * A path is a node in the FIB graph.
199 * The index of the path-list to which this path belongs
204 * This marks the start of the memory area used to hash
207 STRUCT_MARK(path_hash_start);
210 * Configuration Flags
212 fib_path_cfg_flags_t fp_cfg_flags;
215 * The type of the path. This is the selector for the union
217 fib_path_type_t fp_type;
220 * The protocol of the next-hop, i.e. the address family of the
221 * next-hop's address. We can't derive this from the address itself
222 * since the address can be all zeros
224 dpo_proto_t fp_nh_proto;
227 * UCMP [unnormalised] weigth
232 * A path preference. 0 is the best.
233 * Only paths of the best preference, that are 'up', are considered
239 * per-type union of the data required to resolve the path
246 ip46_address_t fp_nh;
264 ip46_address_t fp_ip;
267 * The local label to resolve through.
269 mpls_label_t fp_local_label;
271 * The EOS bit of the resolving label
273 mpls_eos_bit_t fp_eos;
278 * The FIB table index in which to find the next-hop.
280 fib_node_index_t fp_tbl_id;
282 * The BIER FIB the fmask is in
291 ip46_address_t fp_nh;
293 * The BIER FIB the fmask is in
299 * The BIER table's ID
301 bier_table_id_t fp_bier_tbl;
305 * The BIER imposition object
306 * this is part of the path's key, since the index_t
307 * of an imposition object is the object's key.
313 * The FIB index in which to perfom the next lookup
315 fib_node_index_t fp_tbl_id;
317 * The RPF-ID to tag the packets with
319 fib_rpf_id_t fp_rpf_id;
325 * The user provided 'exclusive' DPO
331 * The interface on which the local address is configured
337 ip46_address_t fp_addr;
341 * The interface on which the packets will be input.
347 * The UDP Encap object this path resolves through
352 STRUCT_MARK(path_hash_end);
355 * Memebers in this last section represent information that is
356 * dervied during resolution. It should not be copied to new paths
363 fib_path_oper_flags_t fp_oper_flags;
367 * the resolving via fib. not part of the union, since it it not part
368 * of the path's hash.
370 fib_node_index_t fp_via_fib;
372 * the resolving bier-fmask
374 index_t fp_via_bier_fmask;
376 * the resolving bier-table
378 index_t fp_via_bier_tbl;
382 * The Data-path objects through which this path resolves for IP.
387 * the index of this path in the parent's child list.
393 * Array of strings/names for the path types and attributes
395 static const char *fib_path_type_names[] = FIB_PATH_TYPES;
396 static const char *fib_path_oper_attribute_names[] = FIB_PATH_OPER_ATTRIBUTES;
397 static const char *fib_path_cfg_attribute_names[] = FIB_PATH_CFG_ATTRIBUTES;
400 * The memory pool from which we allocate all the paths
402 static fib_path_t *fib_path_pool;
408 #define FIB_PATH_DBG(_p, _fmt, _args...) \
411 _tmp = fib_path_format(fib_path_get_index(_p), _tmp); \
412 clib_warning("path:[%d:%s]:" _fmt, \
413 fib_path_get_index(_p), _tmp, \
418 #define FIB_PATH_DBG(_p, _fmt, _args...)
422 fib_path_get (fib_node_index_t index)
424 return (pool_elt_at_index(fib_path_pool, index));
427 static fib_node_index_t
428 fib_path_get_index (fib_path_t *path)
430 return (path - fib_path_pool);
434 fib_path_get_node (fib_node_index_t index)
436 return ((fib_node_t*)fib_path_get(index));
440 fib_path_from_fib_node (fib_node_t *node)
443 ASSERT(FIB_NODE_TYPE_PATH == node->fn_type);
445 return ((fib_path_t*)node);
449 format_fib_path (u8 * s, va_list * args)
451 fib_path_t *path = va_arg (*args, fib_path_t *);
452 vnet_main_t * vnm = vnet_get_main();
453 fib_path_oper_attribute_t oattr;
454 fib_path_cfg_attribute_t cattr;
456 s = format (s, " index:%d ", fib_path_get_index(path));
457 s = format (s, "pl-index:%d ", path->fp_pl_index);
458 s = format (s, "%U ", format_dpo_proto, path->fp_nh_proto);
459 s = format (s, "weight=%d ", path->fp_weight);
460 s = format (s, "pref=%d ", path->fp_preference);
461 s = format (s, "%s: ", fib_path_type_names[path->fp_type]);
462 if (FIB_PATH_OPER_FLAG_NONE != path->fp_oper_flags) {
463 s = format(s, " oper-flags:");
464 FOR_EACH_FIB_PATH_OPER_ATTRIBUTE(oattr) {
465 if ((1<<oattr) & path->fp_oper_flags) {
466 s = format (s, "%s,", fib_path_oper_attribute_names[oattr]);
470 if (FIB_PATH_CFG_FLAG_NONE != path->fp_cfg_flags) {
471 s = format(s, " cfg-flags:");
472 FOR_EACH_FIB_PATH_CFG_ATTRIBUTE(cattr) {
473 if ((1<<cattr) & path->fp_cfg_flags) {
474 s = format (s, "%s,", fib_path_cfg_attribute_names[cattr]);
478 s = format(s, "\n ");
480 switch (path->fp_type)
482 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
483 s = format (s, "%U", format_ip46_address,
484 &path->attached_next_hop.fp_nh,
486 if (path->fp_oper_flags & FIB_PATH_OPER_FLAG_DROP)
488 s = format (s, " if_index:%d", path->attached_next_hop.fp_interface);
492 s = format (s, " %U",
493 format_vnet_sw_interface_name,
495 vnet_get_sw_interface(
497 path->attached_next_hop.fp_interface));
498 if (vnet_sw_interface_is_p2p(vnet_get_main(),
499 path->attached_next_hop.fp_interface))
501 s = format (s, " (p2p)");
504 if (!dpo_id_is_valid(&path->fp_dpo))
506 s = format(s, "\n unresolved");
510 s = format(s, "\n %U",
515 case FIB_PATH_TYPE_ATTACHED:
516 if (path->fp_oper_flags & FIB_PATH_OPER_FLAG_DROP)
518 s = format (s, " if_index:%d", path->attached_next_hop.fp_interface);
522 s = format (s, " %U",
523 format_vnet_sw_interface_name,
525 vnet_get_sw_interface(
527 path->attached.fp_interface));
530 case FIB_PATH_TYPE_RECURSIVE:
531 if (DPO_PROTO_MPLS == path->fp_nh_proto)
533 s = format (s, "via %U %U",
534 format_mpls_unicast_label,
535 path->recursive.fp_nh.fp_local_label,
537 path->recursive.fp_nh.fp_eos);
541 s = format (s, "via %U",
543 &path->recursive.fp_nh.fp_ip,
546 s = format (s, " in fib:%d",
547 path->recursive.fp_tbl_id,
549 s = format (s, " via-fib:%d", path->fp_via_fib);
550 s = format (s, " via-dpo:[%U:%d]",
551 format_dpo_type, path->fp_dpo.dpoi_type,
552 path->fp_dpo.dpoi_index);
555 case FIB_PATH_TYPE_UDP_ENCAP:
556 s = format (s, " UDP-encap ID:%d", path->udp_encap.fp_udp_encap_id);
558 case FIB_PATH_TYPE_BIER_TABLE:
559 s = format (s, "via bier-table:[%U}",
560 format_bier_table_id,
561 &path->bier_table.fp_bier_tbl);
562 s = format (s, " via-dpo:[%U:%d]",
563 format_dpo_type, path->fp_dpo.dpoi_type,
564 path->fp_dpo.dpoi_index);
566 case FIB_PATH_TYPE_BIER_FMASK:
567 s = format (s, "via %U",
569 &path->bier_fmask.fp_nh,
571 s = format (s, " in BIER-fib:%d",
572 path->bier_fmask.fp_bier_fib,
574 s = format (s, " via-fmask:%d", path->fp_via_bier_fmask);
575 s = format (s, " via-dpo:[%U:%d]",
576 format_dpo_type, path->fp_dpo.dpoi_type,
577 path->fp_dpo.dpoi_index);
579 case FIB_PATH_TYPE_BIER_IMP:
580 s = format (s, "via %U", format_bier_imp,
581 path->bier_imp.fp_bier_imp, 0, BIER_SHOW_BRIEF);
583 case FIB_PATH_TYPE_RECEIVE:
584 case FIB_PATH_TYPE_INTF_RX:
585 case FIB_PATH_TYPE_SPECIAL:
586 case FIB_PATH_TYPE_DEAG:
587 case FIB_PATH_TYPE_EXCLUSIVE:
588 if (dpo_id_is_valid(&path->fp_dpo))
590 s = format(s, "%U", format_dpo_id,
599 fib_path_format (fib_node_index_t pi, u8 *s)
603 path = fib_path_get(pi);
604 ASSERT(NULL != path);
606 return (format (s, "%U", format_fib_path, path));
610 fib_path_adj_format (fib_node_index_t pi,
616 path = fib_path_get(pi);
617 ASSERT(NULL != path);
619 if (!dpo_id_is_valid(&path->fp_dpo))
621 s = format(s, " unresolved");
625 s = format(s, "%U", format_dpo_id,
633 * fib_path_last_lock_gone
635 * We don't share paths, we share path lists, so the [un]lock functions
639 fib_path_last_lock_gone (fib_node_t *node)
644 static const adj_index_t
645 fib_path_attached_next_hop_get_adj (fib_path_t *path,
648 if (vnet_sw_interface_is_p2p(vnet_get_main(),
649 path->attached_next_hop.fp_interface))
652 * if the interface is p2p then the adj for the specific
653 * neighbour on that link will never exist. on p2p links
654 * the subnet address (the attached route) links to the
655 * auto-adj (see below), we want that adj here too.
657 return (adj_nbr_add_or_lock(dpo_proto_to_fib(path->fp_nh_proto),
660 path->attached_next_hop.fp_interface));
664 return (adj_nbr_add_or_lock(dpo_proto_to_fib(path->fp_nh_proto),
666 &path->attached_next_hop.fp_nh,
667 path->attached_next_hop.fp_interface));
672 fib_path_attached_next_hop_set (fib_path_t *path)
675 * resolve directly via the adjacnecy discribed by the
676 * interface and next-hop
678 dpo_set(&path->fp_dpo,
681 fib_path_attached_next_hop_get_adj(
683 dpo_proto_to_link(path->fp_nh_proto)));
686 * become a child of the adjacency so we receive updates
687 * when its rewrite changes
689 path->fp_sibling = adj_child_add(path->fp_dpo.dpoi_index,
691 fib_path_get_index(path));
693 if (!vnet_sw_interface_is_admin_up(vnet_get_main(),
694 path->attached_next_hop.fp_interface) ||
695 !adj_is_up(path->fp_dpo.dpoi_index))
697 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
701 static const adj_index_t
702 fib_path_attached_get_adj (fib_path_t *path,
705 if (vnet_sw_interface_is_p2p(vnet_get_main(),
706 path->attached.fp_interface))
709 * point-2-point interfaces do not require a glean, since
710 * there is nothing to ARP. Install a rewrite/nbr adj instead
712 return (adj_nbr_add_or_lock(dpo_proto_to_fib(path->fp_nh_proto),
715 path->attached.fp_interface));
719 return (adj_glean_add_or_lock(dpo_proto_to_fib(path->fp_nh_proto),
720 path->attached.fp_interface,
726 * create of update the paths recursive adj
729 fib_path_recursive_adj_update (fib_path_t *path,
730 fib_forward_chain_type_t fct,
733 dpo_id_t via_dpo = DPO_INVALID;
736 * get the DPO to resolve through from the via-entry
738 fib_entry_contribute_forwarding(path->fp_via_fib,
744 * hope for the best - clear if restrictions apply.
746 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RESOLVED;
749 * Validate any recursion constraints and over-ride the via
752 if (path->fp_oper_flags & FIB_PATH_OPER_FLAG_RECURSIVE_LOOP)
754 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
755 dpo_copy(&via_dpo, drop_dpo_get(path->fp_nh_proto));
757 else if (path->fp_cfg_flags & FIB_PATH_CFG_FLAG_RESOLVE_HOST)
760 * the via FIB must be a host route.
761 * note the via FIB just added will always be a host route
762 * since it is an RR source added host route. So what we need to
763 * check is whether the route has other sources. If it does then
764 * some other source has added it as a host route. If it doesn't
765 * then it was added only here and inherits forwarding from a cover.
766 * the cover is not a host route.
767 * The RR source is the lowest priority source, so we check if it
768 * is the best. if it is there are no other sources.
770 if (fib_entry_get_best_source(path->fp_via_fib) >= FIB_SOURCE_RR)
772 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
773 dpo_copy(&via_dpo, drop_dpo_get(path->fp_nh_proto));
776 * PIC edge trigger. let the load-balance maps know
778 load_balance_map_path_state_change(fib_path_get_index(path));
781 else if (path->fp_cfg_flags & FIB_PATH_CFG_FLAG_RESOLVE_ATTACHED)
784 * RR source entries inherit the flags from the cover, so
785 * we can check the via directly
787 if (!(FIB_ENTRY_FLAG_ATTACHED & fib_entry_get_flags(path->fp_via_fib)))
789 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
790 dpo_copy(&via_dpo, drop_dpo_get(path->fp_nh_proto));
793 * PIC edge trigger. let the load-balance maps know
795 load_balance_map_path_state_change(fib_path_get_index(path));
799 * check for over-riding factors on the FIB entry itself
801 if (!fib_entry_is_resolved(path->fp_via_fib))
803 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
804 dpo_copy(&via_dpo, drop_dpo_get(path->fp_nh_proto));
807 * PIC edge trigger. let the load-balance maps know
809 load_balance_map_path_state_change(fib_path_get_index(path));
813 * If this path is contributing a drop, then it's not resolved
815 if (dpo_is_drop(&via_dpo) || load_balance_is_drop(&via_dpo))
817 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
821 * update the path's contributed DPO
823 dpo_copy(dpo, &via_dpo);
825 FIB_PATH_DBG(path, "recursive update:");
831 * re-evaulate the forwarding state for a via fmask path
834 fib_path_bier_fmask_update (fib_path_t *path,
837 bier_fmask_contribute_forwarding(path->fp_via_bier_fmask, dpo);
840 * if we are stakcing on the drop, then the path is not resolved
842 if (dpo_is_drop(dpo))
844 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
848 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RESOLVED;
853 * fib_path_is_permanent_drop
855 * Return !0 if the path is configured to permanently drop,
856 * despite other attributes.
859 fib_path_is_permanent_drop (fib_path_t *path)
861 return ((path->fp_cfg_flags & FIB_PATH_CFG_FLAG_DROP) ||
862 (path->fp_oper_flags & FIB_PATH_OPER_FLAG_DROP));
868 * Remove our dependency on the resolution target
871 fib_path_unresolve (fib_path_t *path)
874 * the forced drop path does not need unresolving
876 if (fib_path_is_permanent_drop(path))
881 switch (path->fp_type)
883 case FIB_PATH_TYPE_RECURSIVE:
884 if (FIB_NODE_INDEX_INVALID != path->fp_via_fib)
888 fib_entry_get_prefix(path->fp_via_fib, &pfx);
889 fib_entry_child_remove(path->fp_via_fib,
891 fib_table_entry_special_remove(path->recursive.fp_tbl_id,
894 path->fp_via_fib = FIB_NODE_INDEX_INVALID;
897 case FIB_PATH_TYPE_BIER_FMASK:
898 if (FIB_NODE_INDEX_INVALID != path->fp_via_bier_fmask)
900 bier_fmask_child_remove(path->fp_via_bier_fmask,
902 path->fp_via_bier_fmask = FIB_NODE_INDEX_INVALID;
905 case FIB_PATH_TYPE_BIER_IMP:
906 bier_imp_unlock(path->fp_dpo.dpoi_index);
908 case FIB_PATH_TYPE_BIER_TABLE:
909 bier_table_ecmp_unlock(path->fp_via_bier_tbl);
911 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
912 adj_child_remove(path->fp_dpo.dpoi_index,
914 adj_unlock(path->fp_dpo.dpoi_index);
916 case FIB_PATH_TYPE_ATTACHED:
917 if (DPO_PROTO_ETHERNET != path->fp_nh_proto)
919 adj_child_remove(path->fp_dpo.dpoi_index,
921 adj_unlock(path->fp_dpo.dpoi_index);
924 case FIB_PATH_TYPE_UDP_ENCAP:
925 udp_encap_unlock_w_index(path->fp_dpo.dpoi_index);
927 case FIB_PATH_TYPE_EXCLUSIVE:
928 dpo_reset(&path->exclusive.fp_ex_dpo);
930 case FIB_PATH_TYPE_SPECIAL:
931 case FIB_PATH_TYPE_RECEIVE:
932 case FIB_PATH_TYPE_INTF_RX:
933 case FIB_PATH_TYPE_DEAG:
935 * these hold only the path's DPO, which is reset below.
941 * release the adj we were holding and pick up the
944 dpo_reset(&path->fp_dpo);
945 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
950 static fib_forward_chain_type_t
951 fib_path_to_chain_type (const fib_path_t *path)
953 if (DPO_PROTO_MPLS == path->fp_nh_proto)
955 if (FIB_PATH_TYPE_RECURSIVE == path->fp_type &&
956 MPLS_EOS == path->recursive.fp_nh.fp_eos)
958 return (FIB_FORW_CHAIN_TYPE_MPLS_EOS);
962 return (FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS);
967 return (fib_forw_chain_type_from_dpo_proto(path->fp_nh_proto));
972 * fib_path_back_walk_notify
974 * A back walk has reach this path.
976 static fib_node_back_walk_rc_t
977 fib_path_back_walk_notify (fib_node_t *node,
978 fib_node_back_walk_ctx_t *ctx)
982 path = fib_path_from_fib_node(node);
984 switch (path->fp_type)
986 case FIB_PATH_TYPE_RECURSIVE:
987 if (FIB_NODE_BW_REASON_FLAG_EVALUATE & ctx->fnbw_reason)
990 * modify the recursive adjacency to use the new forwarding
992 * this update is visible to packets in flight in the DP.
994 fib_path_recursive_adj_update(
996 fib_path_to_chain_type(path),
999 if ((FIB_NODE_BW_REASON_FLAG_ADJ_UPDATE & ctx->fnbw_reason) ||
1000 (FIB_NODE_BW_REASON_FLAG_ADJ_DOWN & ctx->fnbw_reason))
1003 * ADJ updates (complete<->incomplete) do not need to propagate to
1004 * recursive entries.
1005 * The only reason its needed as far back as here, is that the adj
1006 * and the incomplete adj are a different DPO type, so the LBs need
1008 * If this walk was quashed in the fib_entry, then any non-fib_path
1009 * children (like tunnels that collapse out the LB when they stack)
1010 * would not see the update.
1012 return (FIB_NODE_BACK_WALK_CONTINUE);
1015 case FIB_PATH_TYPE_BIER_FMASK:
1016 if (FIB_NODE_BW_REASON_FLAG_EVALUATE & ctx->fnbw_reason)
1019 * update to use the BIER fmask's new forwading
1021 fib_path_bier_fmask_update(path, &path->fp_dpo);
1023 if ((FIB_NODE_BW_REASON_FLAG_ADJ_UPDATE & ctx->fnbw_reason) ||
1024 (FIB_NODE_BW_REASON_FLAG_ADJ_DOWN & ctx->fnbw_reason))
1027 * ADJ updates (complete<->incomplete) do not need to propagate to
1028 * recursive entries.
1029 * The only reason its needed as far back as here, is that the adj
1030 * and the incomplete adj are a different DPO type, so the LBs need
1032 * If this walk was quashed in the fib_entry, then any non-fib_path
1033 * children (like tunnels that collapse out the LB when they stack)
1034 * would not see the update.
1036 return (FIB_NODE_BACK_WALK_CONTINUE);
1039 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1042 * ADJ_UPDATE backwalk pass silently through here and up to
1043 * the path-list when the multipath adj collapse occurs.
1044 * The reason we do this is that the assumtption is that VPP
1045 * runs in an environment where the Control-Plane is remote
1046 * and hence reacts slowly to link up down. In order to remove
1047 * this down link from the ECMP set quickly, we back-walk.
1048 * VPP also has dedicated CPUs, so we are not stealing resources
1049 * from the CP to do so.
1051 if (FIB_NODE_BW_REASON_FLAG_INTERFACE_UP & ctx->fnbw_reason)
1053 if (path->fp_oper_flags & FIB_PATH_OPER_FLAG_RESOLVED)
1056 * alreday resolved. no need to walk back again
1058 return (FIB_NODE_BACK_WALK_CONTINUE);
1060 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RESOLVED;
1062 if (FIB_NODE_BW_REASON_FLAG_INTERFACE_DOWN & ctx->fnbw_reason)
1064 if (!(path->fp_oper_flags & FIB_PATH_OPER_FLAG_RESOLVED))
1067 * alreday unresolved. no need to walk back again
1069 return (FIB_NODE_BACK_WALK_CONTINUE);
1071 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
1073 if (FIB_NODE_BW_REASON_FLAG_INTERFACE_DELETE & ctx->fnbw_reason)
1076 * The interface this path resolves through has been deleted.
1077 * This will leave the path in a permanent drop state. The route
1078 * needs to be removed and readded (and hence the path-list deleted)
1079 * before it can forward again.
1081 fib_path_unresolve(path);
1082 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_DROP;
1084 if (FIB_NODE_BW_REASON_FLAG_ADJ_UPDATE & ctx->fnbw_reason)
1087 * restack the DPO to pick up the correct DPO sub-type
1092 if_is_up = vnet_sw_interface_is_admin_up(
1094 path->attached_next_hop.fp_interface);
1096 ai = fib_path_attached_next_hop_get_adj(
1098 dpo_proto_to_link(path->fp_nh_proto));
1100 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
1101 if (if_is_up && adj_is_up(ai))
1103 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RESOLVED;
1106 dpo_set(&path->fp_dpo, DPO_ADJACENCY, path->fp_nh_proto, ai);
1112 * If the interface is not up there is no reason to walk
1113 * back to children. if we did they would only evalute
1114 * that this path is unresolved and hence it would
1115 * not contribute the adjacency - so it would be wasted
1118 return (FIB_NODE_BACK_WALK_CONTINUE);
1121 if (FIB_NODE_BW_REASON_FLAG_ADJ_DOWN & ctx->fnbw_reason)
1123 if (!(path->fp_oper_flags & FIB_PATH_OPER_FLAG_RESOLVED))
1126 * alreday unresolved. no need to walk back again
1128 return (FIB_NODE_BACK_WALK_CONTINUE);
1131 * the adj has gone down. the path is no longer resolved.
1133 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
1136 case FIB_PATH_TYPE_ATTACHED:
1138 * FIXME; this could schedule a lower priority walk, since attached
1139 * routes are not usually in ECMP configurations so the backwalk to
1140 * the FIB entry does not need to be high priority
1142 if (FIB_NODE_BW_REASON_FLAG_INTERFACE_UP & ctx->fnbw_reason)
1144 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RESOLVED;
1146 if (FIB_NODE_BW_REASON_FLAG_INTERFACE_DOWN & ctx->fnbw_reason)
1148 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
1150 if (FIB_NODE_BW_REASON_FLAG_INTERFACE_DELETE & ctx->fnbw_reason)
1152 fib_path_unresolve(path);
1153 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_DROP;
1156 case FIB_PATH_TYPE_UDP_ENCAP:
1158 dpo_id_t via_dpo = DPO_INVALID;
1161 * hope for the best - clear if restrictions apply.
1163 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RESOLVED;
1165 udp_encap_contribute_forwarding(path->udp_encap.fp_udp_encap_id,
1169 * If this path is contributing a drop, then it's not resolved
1171 if (dpo_is_drop(&via_dpo) || load_balance_is_drop(&via_dpo))
1173 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
1177 * update the path's contributed DPO
1179 dpo_copy(&path->fp_dpo, &via_dpo);
1180 dpo_reset(&via_dpo);
1183 case FIB_PATH_TYPE_INTF_RX:
1185 case FIB_PATH_TYPE_DEAG:
1187 * FIXME When VRF delete is allowed this will need a poke.
1189 case FIB_PATH_TYPE_SPECIAL:
1190 case FIB_PATH_TYPE_RECEIVE:
1191 case FIB_PATH_TYPE_EXCLUSIVE:
1192 case FIB_PATH_TYPE_BIER_TABLE:
1193 case FIB_PATH_TYPE_BIER_IMP:
1195 * these path types have no parents. so to be
1196 * walked from one is unexpected.
1203 * propagate the backwalk further to the path-list
1205 fib_path_list_back_walk(path->fp_pl_index, ctx);
1207 return (FIB_NODE_BACK_WALK_CONTINUE);
1211 fib_path_memory_show (void)
1213 fib_show_memory_usage("Path",
1214 pool_elts(fib_path_pool),
1215 pool_len(fib_path_pool),
1216 sizeof(fib_path_t));
1220 * The FIB path's graph node virtual function table
1222 static const fib_node_vft_t fib_path_vft = {
1223 .fnv_get = fib_path_get_node,
1224 .fnv_last_lock = fib_path_last_lock_gone,
1225 .fnv_back_walk = fib_path_back_walk_notify,
1226 .fnv_mem_show = fib_path_memory_show,
1229 static fib_path_cfg_flags_t
1230 fib_path_route_flags_to_cfg_flags (const fib_route_path_t *rpath)
1232 fib_path_cfg_flags_t cfg_flags = FIB_PATH_CFG_FLAG_NONE;
1234 if (rpath->frp_flags & FIB_ROUTE_PATH_RESOLVE_VIA_HOST)
1235 cfg_flags |= FIB_PATH_CFG_FLAG_RESOLVE_HOST;
1236 if (rpath->frp_flags & FIB_ROUTE_PATH_RESOLVE_VIA_ATTACHED)
1237 cfg_flags |= FIB_PATH_CFG_FLAG_RESOLVE_ATTACHED;
1238 if (rpath->frp_flags & FIB_ROUTE_PATH_LOCAL)
1239 cfg_flags |= FIB_PATH_CFG_FLAG_LOCAL;
1240 if (rpath->frp_flags & FIB_ROUTE_PATH_ATTACHED)
1241 cfg_flags |= FIB_PATH_CFG_FLAG_ATTACHED;
1242 if (rpath->frp_flags & FIB_ROUTE_PATH_INTF_RX)
1243 cfg_flags |= FIB_PATH_CFG_FLAG_INTF_RX;
1244 if (rpath->frp_flags & FIB_ROUTE_PATH_RPF_ID)
1245 cfg_flags |= FIB_PATH_CFG_FLAG_RPF_ID;
1246 if (rpath->frp_flags & FIB_ROUTE_PATH_EXCLUSIVE)
1247 cfg_flags |= FIB_PATH_CFG_FLAG_EXCLUSIVE;
1248 if (rpath->frp_flags & FIB_ROUTE_PATH_DROP)
1249 cfg_flags |= FIB_PATH_CFG_FLAG_DROP;
1250 if (rpath->frp_flags & FIB_ROUTE_PATH_SOURCE_LOOKUP)
1251 cfg_flags |= FIB_PATH_CFG_FLAG_DEAG_SRC;
1259 * Create and initialise a new path object.
1260 * return the index of the path.
1263 fib_path_create (fib_node_index_t pl_index,
1264 const fib_route_path_t *rpath)
1268 pool_get(fib_path_pool, path);
1269 memset(path, 0, sizeof(*path));
1271 fib_node_init(&path->fp_node,
1272 FIB_NODE_TYPE_PATH);
1274 dpo_reset(&path->fp_dpo);
1275 path->fp_pl_index = pl_index;
1276 path->fp_nh_proto = rpath->frp_proto;
1277 path->fp_via_fib = FIB_NODE_INDEX_INVALID;
1278 path->fp_weight = rpath->frp_weight;
1279 if (0 == path->fp_weight)
1282 * a weight of 0 is a meaningless value. We could either reject it, and thus force
1283 * clients to always use 1, or we can accept it and fixup approrpiately.
1285 path->fp_weight = 1;
1287 path->fp_preference = rpath->frp_preference;
1288 path->fp_cfg_flags = fib_path_route_flags_to_cfg_flags(rpath);
1291 * deduce the path's tpye from the parementers and save what is needed.
1293 if (path->fp_cfg_flags & FIB_PATH_CFG_FLAG_LOCAL)
1295 path->fp_type = FIB_PATH_TYPE_RECEIVE;
1296 path->receive.fp_interface = rpath->frp_sw_if_index;
1297 path->receive.fp_addr = rpath->frp_addr;
1299 else if (rpath->frp_flags & FIB_ROUTE_PATH_UDP_ENCAP)
1301 path->fp_type = FIB_PATH_TYPE_UDP_ENCAP;
1302 path->udp_encap.fp_udp_encap_id = rpath->frp_udp_encap_id;
1304 else if (path->fp_cfg_flags & FIB_PATH_CFG_FLAG_INTF_RX)
1306 path->fp_type = FIB_PATH_TYPE_INTF_RX;
1307 path->intf_rx.fp_interface = rpath->frp_sw_if_index;
1309 else if (path->fp_cfg_flags & FIB_PATH_CFG_FLAG_RPF_ID)
1311 path->fp_type = FIB_PATH_TYPE_DEAG;
1312 path->deag.fp_tbl_id = rpath->frp_fib_index;
1313 path->deag.fp_rpf_id = rpath->frp_rpf_id;
1315 else if (rpath->frp_flags & FIB_ROUTE_PATH_BIER_FMASK)
1317 path->fp_type = FIB_PATH_TYPE_BIER_FMASK;
1318 path->bier_fmask.fp_nh = rpath->frp_addr;
1319 path->bier_fmask.fp_bier_fib = rpath->frp_bier_fib_index;
1321 else if (rpath->frp_flags & FIB_ROUTE_PATH_BIER_IMP)
1323 path->fp_type = FIB_PATH_TYPE_BIER_IMP;
1324 path->bier_imp.fp_bier_imp = rpath->frp_bier_imp;
1326 else if (rpath->frp_flags & FIB_ROUTE_PATH_BIER_TABLE)
1328 path->fp_type = FIB_PATH_TYPE_BIER_TABLE;
1329 path->bier_table.fp_bier_tbl = rpath->frp_bier_tbl;
1331 else if (~0 != rpath->frp_sw_if_index)
1333 if (ip46_address_is_zero(&rpath->frp_addr))
1335 path->fp_type = FIB_PATH_TYPE_ATTACHED;
1336 path->attached.fp_interface = rpath->frp_sw_if_index;
1340 path->fp_type = FIB_PATH_TYPE_ATTACHED_NEXT_HOP;
1341 path->attached_next_hop.fp_interface = rpath->frp_sw_if_index;
1342 path->attached_next_hop.fp_nh = rpath->frp_addr;
1347 if (ip46_address_is_zero(&rpath->frp_addr))
1349 if (~0 == rpath->frp_fib_index)
1351 path->fp_type = FIB_PATH_TYPE_SPECIAL;
1355 path->fp_type = FIB_PATH_TYPE_DEAG;
1356 path->deag.fp_tbl_id = rpath->frp_fib_index;
1361 path->fp_type = FIB_PATH_TYPE_RECURSIVE;
1362 if (DPO_PROTO_MPLS == path->fp_nh_proto)
1364 path->recursive.fp_nh.fp_local_label = rpath->frp_local_label;
1365 path->recursive.fp_nh.fp_eos = rpath->frp_eos;
1369 path->recursive.fp_nh.fp_ip = rpath->frp_addr;
1371 path->recursive.fp_tbl_id = rpath->frp_fib_index;
1375 FIB_PATH_DBG(path, "create");
1377 return (fib_path_get_index(path));
1381 * fib_path_create_special
1383 * Create and initialise a new path object.
1384 * return the index of the path.
1387 fib_path_create_special (fib_node_index_t pl_index,
1388 dpo_proto_t nh_proto,
1389 fib_path_cfg_flags_t flags,
1390 const dpo_id_t *dpo)
1394 pool_get(fib_path_pool, path);
1395 memset(path, 0, sizeof(*path));
1397 fib_node_init(&path->fp_node,
1398 FIB_NODE_TYPE_PATH);
1399 dpo_reset(&path->fp_dpo);
1401 path->fp_pl_index = pl_index;
1402 path->fp_weight = 1;
1403 path->fp_preference = 0;
1404 path->fp_nh_proto = nh_proto;
1405 path->fp_via_fib = FIB_NODE_INDEX_INVALID;
1406 path->fp_cfg_flags = flags;
1408 if (FIB_PATH_CFG_FLAG_DROP & flags)
1410 path->fp_type = FIB_PATH_TYPE_SPECIAL;
1412 else if (FIB_PATH_CFG_FLAG_LOCAL & flags)
1414 path->fp_type = FIB_PATH_TYPE_RECEIVE;
1415 path->attached.fp_interface = FIB_NODE_INDEX_INVALID;
1419 path->fp_type = FIB_PATH_TYPE_EXCLUSIVE;
1420 ASSERT(NULL != dpo);
1421 dpo_copy(&path->exclusive.fp_ex_dpo, dpo);
1424 return (fib_path_get_index(path));
1430 * Copy a path. return index of new path.
1433 fib_path_copy (fib_node_index_t path_index,
1434 fib_node_index_t path_list_index)
1436 fib_path_t *path, *orig_path;
1438 pool_get(fib_path_pool, path);
1440 orig_path = fib_path_get(path_index);
1441 ASSERT(NULL != orig_path);
1443 memcpy(path, orig_path, sizeof(*path));
1445 FIB_PATH_DBG(path, "create-copy:%d", path_index);
1448 * reset the dynamic section
1450 fib_node_init(&path->fp_node, FIB_NODE_TYPE_PATH);
1451 path->fp_oper_flags = FIB_PATH_OPER_FLAG_NONE;
1452 path->fp_pl_index = path_list_index;
1453 path->fp_via_fib = FIB_NODE_INDEX_INVALID;
1454 memset(&path->fp_dpo, 0, sizeof(path->fp_dpo));
1455 dpo_reset(&path->fp_dpo);
1457 return (fib_path_get_index(path));
1463 * destroy a path that is no longer required
1466 fib_path_destroy (fib_node_index_t path_index)
1470 path = fib_path_get(path_index);
1472 ASSERT(NULL != path);
1473 FIB_PATH_DBG(path, "destroy");
1475 fib_path_unresolve(path);
1477 fib_node_deinit(&path->fp_node);
1478 pool_put(fib_path_pool, path);
1484 * destroy a path that is no longer required
1487 fib_path_hash (fib_node_index_t path_index)
1491 path = fib_path_get(path_index);
1493 return (hash_memory(STRUCT_MARK_PTR(path, path_hash_start),
1494 (STRUCT_OFFSET_OF(fib_path_t, path_hash_end) -
1495 STRUCT_OFFSET_OF(fib_path_t, path_hash_start)),
1502 * Compare two paths for equivalence.
1505 fib_path_cmp_i (const fib_path_t *path1,
1506 const fib_path_t *path2)
1513 * paths of different types and protocol are not equal.
1514 * different weights and/or preference only are the same path.
1516 if (path1->fp_type != path2->fp_type)
1518 res = (path1->fp_type - path2->fp_type);
1520 else if (path1->fp_nh_proto != path2->fp_nh_proto)
1522 res = (path1->fp_nh_proto - path2->fp_nh_proto);
1527 * both paths are of the same type.
1528 * consider each type and its attributes in turn.
1530 switch (path1->fp_type)
1532 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1533 res = ip46_address_cmp(&path1->attached_next_hop.fp_nh,
1534 &path2->attached_next_hop.fp_nh);
1536 res = (path1->attached_next_hop.fp_interface -
1537 path2->attached_next_hop.fp_interface);
1540 case FIB_PATH_TYPE_ATTACHED:
1541 res = (path1->attached.fp_interface -
1542 path2->attached.fp_interface);
1544 case FIB_PATH_TYPE_RECURSIVE:
1545 res = ip46_address_cmp(&path1->recursive.fp_nh,
1546 &path2->recursive.fp_nh);
1550 res = (path1->recursive.fp_tbl_id - path2->recursive.fp_tbl_id);
1553 case FIB_PATH_TYPE_BIER_FMASK:
1554 res = ip46_address_cmp(&path1->bier_fmask.fp_nh,
1555 &path2->bier_fmask.fp_nh);
1559 res = (path1->bier_fmask.fp_bier_fib -
1560 path2->bier_fmask.fp_bier_fib);
1563 case FIB_PATH_TYPE_BIER_IMP:
1564 res = (path1->bier_imp.fp_bier_imp -
1565 path2->bier_imp.fp_bier_imp);
1567 case FIB_PATH_TYPE_BIER_TABLE:
1568 res = bier_table_id_cmp(&path1->bier_table.fp_bier_tbl,
1569 &path2->bier_table.fp_bier_tbl);
1571 case FIB_PATH_TYPE_DEAG:
1572 res = (path1->deag.fp_tbl_id - path2->deag.fp_tbl_id);
1575 res = (path1->deag.fp_rpf_id - path2->deag.fp_rpf_id);
1578 case FIB_PATH_TYPE_INTF_RX:
1579 res = (path1->intf_rx.fp_interface - path2->intf_rx.fp_interface);
1581 case FIB_PATH_TYPE_UDP_ENCAP:
1582 res = (path1->udp_encap.fp_udp_encap_id - path2->udp_encap.fp_udp_encap_id);
1584 case FIB_PATH_TYPE_SPECIAL:
1585 case FIB_PATH_TYPE_RECEIVE:
1586 case FIB_PATH_TYPE_EXCLUSIVE:
1595 * fib_path_cmp_for_sort
1597 * Compare two paths for equivalence. Used during path sorting.
1598 * As usual 0 means equal.
1601 fib_path_cmp_for_sort (void * v1,
1604 fib_node_index_t *pi1 = v1, *pi2 = v2;
1605 fib_path_t *path1, *path2;
1607 path1 = fib_path_get(*pi1);
1608 path2 = fib_path_get(*pi2);
1611 * when sorting paths we want the highest preference paths
1612 * first, so that the choices set built is in prefernce order
1614 if (path1->fp_preference != path2->fp_preference)
1616 return (path1->fp_preference - path2->fp_preference);
1619 return (fib_path_cmp_i(path1, path2));
1625 * Compare two paths for equivalence.
1628 fib_path_cmp (fib_node_index_t pi1,
1629 fib_node_index_t pi2)
1631 fib_path_t *path1, *path2;
1633 path1 = fib_path_get(pi1);
1634 path2 = fib_path_get(pi2);
1636 return (fib_path_cmp_i(path1, path2));
1640 fib_path_cmp_w_route_path (fib_node_index_t path_index,
1641 const fib_route_path_t *rpath)
1646 path = fib_path_get(path_index);
1650 if (path->fp_weight != rpath->frp_weight)
1652 res = (path->fp_weight - rpath->frp_weight);
1657 * both paths are of the same type.
1658 * consider each type and its attributes in turn.
1660 switch (path->fp_type)
1662 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1663 res = ip46_address_cmp(&path->attached_next_hop.fp_nh,
1667 res = (path->attached_next_hop.fp_interface -
1668 rpath->frp_sw_if_index);
1671 case FIB_PATH_TYPE_ATTACHED:
1672 res = (path->attached.fp_interface - rpath->frp_sw_if_index);
1674 case FIB_PATH_TYPE_RECURSIVE:
1675 if (DPO_PROTO_MPLS == path->fp_nh_proto)
1677 res = path->recursive.fp_nh.fp_local_label - rpath->frp_local_label;
1681 res = path->recursive.fp_nh.fp_eos - rpath->frp_eos;
1686 res = ip46_address_cmp(&path->recursive.fp_nh.fp_ip,
1692 res = (path->recursive.fp_tbl_id - rpath->frp_fib_index);
1695 case FIB_PATH_TYPE_BIER_FMASK:
1696 res = ip46_address_cmp(&path->bier_fmask.fp_nh,
1701 res = (path->bier_fmask.fp_bier_fib - rpath->frp_bier_fib_index);
1704 case FIB_PATH_TYPE_BIER_IMP:
1705 res = (path->bier_imp.fp_bier_imp - rpath->frp_bier_imp);
1707 case FIB_PATH_TYPE_BIER_TABLE:
1708 res = bier_table_id_cmp(&path->bier_table.fp_bier_tbl,
1709 &rpath->frp_bier_tbl);
1711 case FIB_PATH_TYPE_INTF_RX:
1712 res = (path->intf_rx.fp_interface - rpath->frp_sw_if_index);
1714 case FIB_PATH_TYPE_UDP_ENCAP:
1715 res = (path->udp_encap.fp_udp_encap_id - rpath->frp_udp_encap_id);
1717 case FIB_PATH_TYPE_DEAG:
1718 res = (path->deag.fp_tbl_id - rpath->frp_fib_index);
1721 res = (path->deag.fp_rpf_id - rpath->frp_rpf_id);
1724 case FIB_PATH_TYPE_SPECIAL:
1725 case FIB_PATH_TYPE_RECEIVE:
1726 case FIB_PATH_TYPE_EXCLUSIVE:
1735 * fib_path_recursive_loop_detect
1737 * A forward walk of the FIB object graph to detect for a cycle/loop. This
1738 * walk is initiated when an entry is linking to a new path list or from an old.
1739 * The entry vector passed contains all the FIB entrys that are children of this
1740 * path (it is all the entries encountered on the walk so far). If this vector
1741 * contains the entry this path resolve via, then a loop is about to form.
1742 * The loop must be allowed to form, since we need the dependencies in place
1743 * so that we can track when the loop breaks.
1744 * However, we MUST not produce a loop in the forwarding graph (else packets
1745 * would loop around the switch path until the loop breaks), so we mark recursive
1746 * paths as looped so that they do not contribute forwarding information.
1747 * By marking the path as looped, an etry such as;
1749 * via a.a.a.a (looped)
1750 * via b.b.b.b (not looped)
1751 * can still forward using the info provided by b.b.b.b only
1754 fib_path_recursive_loop_detect (fib_node_index_t path_index,
1755 fib_node_index_t **entry_indicies)
1759 path = fib_path_get(path_index);
1762 * the forced drop path is never looped, cos it is never resolved.
1764 if (fib_path_is_permanent_drop(path))
1769 switch (path->fp_type)
1771 case FIB_PATH_TYPE_RECURSIVE:
1773 fib_node_index_t *entry_index, *entries;
1775 entries = *entry_indicies;
1777 vec_foreach(entry_index, entries) {
1778 if (*entry_index == path->fp_via_fib)
1781 * the entry that is about to link to this path-list (or
1782 * one of this path-list's children) is the same entry that
1783 * this recursive path resolves through. this is a cycle.
1793 FIB_PATH_DBG(path, "recursive loop formed");
1794 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RECURSIVE_LOOP;
1796 dpo_copy(&path->fp_dpo, drop_dpo_get(path->fp_nh_proto));
1801 * no loop here yet. keep forward walking the graph.
1803 if (fib_entry_recursive_loop_detect(path->fp_via_fib, entry_indicies))
1805 FIB_PATH_DBG(path, "recursive loop formed");
1806 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RECURSIVE_LOOP;
1810 FIB_PATH_DBG(path, "recursive loop cleared");
1811 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RECURSIVE_LOOP;
1816 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1817 case FIB_PATH_TYPE_ATTACHED:
1818 case FIB_PATH_TYPE_SPECIAL:
1819 case FIB_PATH_TYPE_DEAG:
1820 case FIB_PATH_TYPE_RECEIVE:
1821 case FIB_PATH_TYPE_INTF_RX:
1822 case FIB_PATH_TYPE_UDP_ENCAP:
1823 case FIB_PATH_TYPE_EXCLUSIVE:
1824 case FIB_PATH_TYPE_BIER_FMASK:
1825 case FIB_PATH_TYPE_BIER_TABLE:
1826 case FIB_PATH_TYPE_BIER_IMP:
1828 * these path types cannot be part of a loop, since they are the leaves
1834 return (fib_path_is_looped(path_index));
1838 fib_path_resolve (fib_node_index_t path_index)
1842 path = fib_path_get(path_index);
1845 * hope for the best.
1847 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RESOLVED;
1850 * the forced drop path resolves via the drop adj
1852 if (fib_path_is_permanent_drop(path))
1854 dpo_copy(&path->fp_dpo, drop_dpo_get(path->fp_nh_proto));
1855 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
1856 return (fib_path_is_resolved(path_index));
1859 switch (path->fp_type)
1861 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1862 fib_path_attached_next_hop_set(path);
1864 case FIB_PATH_TYPE_ATTACHED:
1865 if (DPO_PROTO_ETHERNET == path->fp_nh_proto)
1867 l2_bridge_dpo_add_or_lock(path->attached.fp_interface,
1873 * path->attached.fp_interface
1875 if (!vnet_sw_interface_is_admin_up(vnet_get_main(),
1876 path->attached.fp_interface))
1878 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
1880 dpo_set(&path->fp_dpo,
1883 fib_path_attached_get_adj(path,
1884 dpo_proto_to_link(path->fp_nh_proto)));
1887 * become a child of the adjacency so we receive updates
1888 * when the interface state changes
1890 path->fp_sibling = adj_child_add(path->fp_dpo.dpoi_index,
1892 fib_path_get_index(path));
1895 case FIB_PATH_TYPE_RECURSIVE:
1898 * Create a RR source entry in the table for the address
1899 * that this path recurses through.
1900 * This resolve action is recursive, hence we may create
1901 * more paths in the process. more creates mean maybe realloc
1904 fib_node_index_t fei;
1907 ASSERT(FIB_NODE_INDEX_INVALID == path->fp_via_fib);
1909 if (DPO_PROTO_MPLS == path->fp_nh_proto)
1911 fib_prefix_from_mpls_label(path->recursive.fp_nh.fp_local_label,
1912 path->recursive.fp_nh.fp_eos,
1917 fib_prefix_from_ip46_addr(&path->recursive.fp_nh.fp_ip, &pfx);
1920 fei = fib_table_entry_special_add(path->recursive.fp_tbl_id,
1923 FIB_ENTRY_FLAG_NONE);
1925 path = fib_path_get(path_index);
1926 path->fp_via_fib = fei;
1929 * become a dependent child of the entry so the path is
1930 * informed when the forwarding for the entry changes.
1932 path->fp_sibling = fib_entry_child_add(path->fp_via_fib,
1934 fib_path_get_index(path));
1937 * create and configure the IP DPO
1939 fib_path_recursive_adj_update(
1941 fib_path_to_chain_type(path),
1946 case FIB_PATH_TYPE_BIER_FMASK:
1949 * Find the BIER f-mask to link to
1951 bier_fmask_id_t fmid = {
1952 .bfmi_nh = path->bier_fmask.fp_nh,
1953 .bfmi_hdr_type = BIER_HDR_O_MPLS,
1956 ASSERT(FIB_NODE_INDEX_INVALID == path->fp_via_bier_fmask);
1958 path->fp_via_bier_fmask = bier_fmask_db_find(path->bier_fmask.fp_bier_fib,
1962 * become a dependent child of the entry so the path is
1963 * informed when the forwarding for the entry changes.
1965 path->fp_sibling = bier_fmask_child_add(path->fp_via_bier_fmask,
1967 fib_path_get_index(path));
1969 fib_path_bier_fmask_update(path, &path->fp_dpo);
1973 case FIB_PATH_TYPE_BIER_IMP:
1974 bier_imp_lock(path->bier_imp.fp_bier_imp);
1975 bier_imp_contribute_forwarding(path->bier_imp.fp_bier_imp,
1979 case FIB_PATH_TYPE_BIER_TABLE:
1982 * Find/create the BIER table to link to
1984 ASSERT(FIB_NODE_INDEX_INVALID == path->fp_via_bier_tbl);
1986 path->fp_via_bier_tbl =
1987 bier_table_ecmp_create_and_lock(&path->bier_table.fp_bier_tbl);
1989 bier_table_contribute_forwarding(path->fp_via_bier_tbl,
1993 case FIB_PATH_TYPE_SPECIAL:
1995 * Resolve via the drop
1997 dpo_copy(&path->fp_dpo, drop_dpo_get(path->fp_nh_proto));
1999 case FIB_PATH_TYPE_DEAG:
2002 * Resolve via a lookup DPO.
2003 * FIXME. control plane should add routes with a table ID
2005 lookup_input_t input;
2008 cast = (path->fp_cfg_flags & FIB_PATH_CFG_FLAG_RPF_ID ?
2011 input = (path->fp_cfg_flags & FIB_PATH_CFG_FLAG_DEAG_SRC ?
2012 LOOKUP_INPUT_SRC_ADDR :
2013 LOOKUP_INPUT_DST_ADDR);
2015 lookup_dpo_add_or_lock_w_fib_index(path->deag.fp_tbl_id,
2019 LOOKUP_TABLE_FROM_CONFIG,
2023 case FIB_PATH_TYPE_RECEIVE:
2025 * Resolve via a receive DPO.
2027 receive_dpo_add_or_lock(path->fp_nh_proto,
2028 path->receive.fp_interface,
2029 &path->receive.fp_addr,
2032 case FIB_PATH_TYPE_UDP_ENCAP:
2033 udp_encap_lock(path->udp_encap.fp_udp_encap_id);
2034 udp_encap_contribute_forwarding(path->udp_encap.fp_udp_encap_id,
2038 case FIB_PATH_TYPE_INTF_RX: {
2040 * Resolve via a receive DPO.
2042 interface_rx_dpo_add_or_lock(path->fp_nh_proto,
2043 path->intf_rx.fp_interface,
2047 case FIB_PATH_TYPE_EXCLUSIVE:
2049 * Resolve via the user provided DPO
2051 dpo_copy(&path->fp_dpo, &path->exclusive.fp_ex_dpo);
2055 return (fib_path_is_resolved(path_index));
2059 fib_path_get_resolving_interface (fib_node_index_t path_index)
2063 path = fib_path_get(path_index);
2065 switch (path->fp_type)
2067 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
2068 return (path->attached_next_hop.fp_interface);
2069 case FIB_PATH_TYPE_ATTACHED:
2070 return (path->attached.fp_interface);
2071 case FIB_PATH_TYPE_RECEIVE:
2072 return (path->receive.fp_interface);
2073 case FIB_PATH_TYPE_RECURSIVE:
2074 if (fib_path_is_resolved(path_index))
2076 return (fib_entry_get_resolving_interface(path->fp_via_fib));
2079 case FIB_PATH_TYPE_INTF_RX:
2080 case FIB_PATH_TYPE_UDP_ENCAP:
2081 case FIB_PATH_TYPE_SPECIAL:
2082 case FIB_PATH_TYPE_DEAG:
2083 case FIB_PATH_TYPE_EXCLUSIVE:
2084 case FIB_PATH_TYPE_BIER_FMASK:
2085 case FIB_PATH_TYPE_BIER_TABLE:
2086 case FIB_PATH_TYPE_BIER_IMP:
2093 fib_path_get_resolving_index (fib_node_index_t path_index)
2097 path = fib_path_get(path_index);
2099 switch (path->fp_type)
2101 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
2102 case FIB_PATH_TYPE_ATTACHED:
2103 case FIB_PATH_TYPE_RECEIVE:
2104 case FIB_PATH_TYPE_INTF_RX:
2105 case FIB_PATH_TYPE_SPECIAL:
2106 case FIB_PATH_TYPE_DEAG:
2107 case FIB_PATH_TYPE_EXCLUSIVE:
2109 case FIB_PATH_TYPE_UDP_ENCAP:
2110 return (path->udp_encap.fp_udp_encap_id);
2111 case FIB_PATH_TYPE_RECURSIVE:
2112 return (path->fp_via_fib);
2113 case FIB_PATH_TYPE_BIER_FMASK:
2114 return (path->fp_via_bier_fmask);
2115 case FIB_PATH_TYPE_BIER_TABLE:
2116 return (path->fp_via_bier_tbl);
2117 case FIB_PATH_TYPE_BIER_IMP:
2118 return (path->bier_imp.fp_bier_imp);
2124 fib_path_get_adj (fib_node_index_t path_index)
2128 path = fib_path_get(path_index);
2130 ASSERT(dpo_is_adj(&path->fp_dpo));
2131 if (dpo_is_adj(&path->fp_dpo))
2133 return (path->fp_dpo.dpoi_index);
2135 return (ADJ_INDEX_INVALID);
2139 fib_path_get_weight (fib_node_index_t path_index)
2143 path = fib_path_get(path_index);
2147 return (path->fp_weight);
2151 fib_path_get_preference (fib_node_index_t path_index)
2155 path = fib_path_get(path_index);
2159 return (path->fp_preference);
2163 fib_path_get_rpf_id (fib_node_index_t path_index)
2167 path = fib_path_get(path_index);
2171 if (FIB_PATH_CFG_FLAG_RPF_ID & path->fp_cfg_flags)
2173 return (path->deag.fp_rpf_id);
2180 * @brief Contribute the path's adjacency to the list passed.
2181 * By calling this function over all paths, recursively, a child
2182 * can construct its full set of forwarding adjacencies, and hence its
2186 fib_path_contribute_urpf (fib_node_index_t path_index,
2191 path = fib_path_get(path_index);
2194 * resolved and unresolved paths contribute to the RPF list.
2196 switch (path->fp_type)
2198 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
2199 fib_urpf_list_append(urpf, path->attached_next_hop.fp_interface);
2202 case FIB_PATH_TYPE_ATTACHED:
2203 fib_urpf_list_append(urpf, path->attached.fp_interface);
2206 case FIB_PATH_TYPE_RECURSIVE:
2207 if (FIB_NODE_INDEX_INVALID != path->fp_via_fib &&
2208 !fib_path_is_looped(path_index))
2211 * there's unresolved due to constraints, and there's unresolved
2212 * due to ain't got no via. can't do nowt w'out via.
2214 fib_entry_contribute_urpf(path->fp_via_fib, urpf);
2218 case FIB_PATH_TYPE_EXCLUSIVE:
2219 case FIB_PATH_TYPE_SPECIAL:
2222 * these path types may link to an adj, if that's what
2225 u32 rpf_sw_if_index;
2227 rpf_sw_if_index = dpo_get_urpf(&path->fp_dpo);
2229 if (~0 != rpf_sw_if_index)
2231 fib_urpf_list_append(urpf, rpf_sw_if_index);
2235 case FIB_PATH_TYPE_DEAG:
2236 case FIB_PATH_TYPE_RECEIVE:
2237 case FIB_PATH_TYPE_INTF_RX:
2238 case FIB_PATH_TYPE_UDP_ENCAP:
2239 case FIB_PATH_TYPE_BIER_FMASK:
2240 case FIB_PATH_TYPE_BIER_TABLE:
2241 case FIB_PATH_TYPE_BIER_IMP:
2243 * these path types don't link to an adj
2250 fib_path_stack_mpls_disp (fib_node_index_t path_index,
2251 dpo_proto_t payload_proto,
2256 path = fib_path_get(path_index);
2260 switch (path->fp_type)
2262 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
2264 dpo_id_t tmp = DPO_INVALID;
2266 dpo_copy(&tmp, dpo);
2268 DPO_MPLS_DISPOSITION,
2270 mpls_disp_dpo_create(payload_proto, ~0, &tmp));
2274 case FIB_PATH_TYPE_DEAG:
2276 dpo_id_t tmp = DPO_INVALID;
2278 dpo_copy(&tmp, dpo);
2280 DPO_MPLS_DISPOSITION,
2282 mpls_disp_dpo_create(payload_proto,
2283 path->deag.fp_rpf_id,
2288 case FIB_PATH_TYPE_RECEIVE:
2289 case FIB_PATH_TYPE_ATTACHED:
2290 case FIB_PATH_TYPE_RECURSIVE:
2291 case FIB_PATH_TYPE_INTF_RX:
2292 case FIB_PATH_TYPE_UDP_ENCAP:
2293 case FIB_PATH_TYPE_EXCLUSIVE:
2294 case FIB_PATH_TYPE_SPECIAL:
2295 case FIB_PATH_TYPE_BIER_FMASK:
2296 case FIB_PATH_TYPE_BIER_TABLE:
2297 case FIB_PATH_TYPE_BIER_IMP:
2303 fib_path_contribute_forwarding (fib_node_index_t path_index,
2304 fib_forward_chain_type_t fct,
2309 path = fib_path_get(path_index);
2312 ASSERT(FIB_FORW_CHAIN_TYPE_MPLS_EOS != fct);
2314 FIB_PATH_DBG(path, "contribute");
2317 * The DPO stored in the path was created when the path was resolved.
2318 * This then represents the path's 'native' protocol; IP.
2319 * For all others will need to go find something else.
2321 if (fib_path_to_chain_type(path) == fct)
2323 dpo_copy(dpo, &path->fp_dpo);
2327 switch (path->fp_type)
2329 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
2332 case FIB_FORW_CHAIN_TYPE_UNICAST_IP4:
2333 case FIB_FORW_CHAIN_TYPE_UNICAST_IP6:
2334 case FIB_FORW_CHAIN_TYPE_MPLS_EOS:
2335 case FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS:
2336 case FIB_FORW_CHAIN_TYPE_ETHERNET:
2337 case FIB_FORW_CHAIN_TYPE_NSH:
2342 * get a appropriate link type adj.
2344 ai = fib_path_attached_next_hop_get_adj(
2346 fib_forw_chain_type_to_link_type(fct));
2347 dpo_set(dpo, DPO_ADJACENCY,
2348 fib_forw_chain_type_to_dpo_proto(fct), ai);
2353 case FIB_FORW_CHAIN_TYPE_MCAST_IP4:
2354 case FIB_FORW_CHAIN_TYPE_MCAST_IP6:
2355 case FIB_FORW_CHAIN_TYPE_BIER:
2359 case FIB_PATH_TYPE_RECURSIVE:
2362 case FIB_FORW_CHAIN_TYPE_MPLS_EOS:
2363 case FIB_FORW_CHAIN_TYPE_UNICAST_IP4:
2364 case FIB_FORW_CHAIN_TYPE_UNICAST_IP6:
2365 case FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS:
2366 case FIB_FORW_CHAIN_TYPE_MCAST_IP4:
2367 case FIB_FORW_CHAIN_TYPE_MCAST_IP6:
2368 case FIB_FORW_CHAIN_TYPE_BIER:
2369 fib_path_recursive_adj_update(path, fct, dpo);
2371 case FIB_FORW_CHAIN_TYPE_ETHERNET:
2372 case FIB_FORW_CHAIN_TYPE_NSH:
2377 case FIB_PATH_TYPE_BIER_TABLE:
2380 case FIB_FORW_CHAIN_TYPE_BIER:
2381 bier_table_contribute_forwarding(path->fp_via_bier_tbl, dpo);
2383 case FIB_FORW_CHAIN_TYPE_MPLS_EOS:
2384 case FIB_FORW_CHAIN_TYPE_UNICAST_IP4:
2385 case FIB_FORW_CHAIN_TYPE_UNICAST_IP6:
2386 case FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS:
2387 case FIB_FORW_CHAIN_TYPE_MCAST_IP4:
2388 case FIB_FORW_CHAIN_TYPE_MCAST_IP6:
2389 case FIB_FORW_CHAIN_TYPE_ETHERNET:
2390 case FIB_FORW_CHAIN_TYPE_NSH:
2395 case FIB_PATH_TYPE_BIER_FMASK:
2398 case FIB_FORW_CHAIN_TYPE_BIER:
2399 fib_path_bier_fmask_update(path, dpo);
2401 case FIB_FORW_CHAIN_TYPE_MPLS_EOS:
2402 case FIB_FORW_CHAIN_TYPE_UNICAST_IP4:
2403 case FIB_FORW_CHAIN_TYPE_UNICAST_IP6:
2404 case FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS:
2405 case FIB_FORW_CHAIN_TYPE_MCAST_IP4:
2406 case FIB_FORW_CHAIN_TYPE_MCAST_IP6:
2407 case FIB_FORW_CHAIN_TYPE_ETHERNET:
2408 case FIB_FORW_CHAIN_TYPE_NSH:
2413 case FIB_PATH_TYPE_BIER_IMP:
2414 bier_imp_contribute_forwarding(path->bier_imp.fp_bier_imp,
2415 fib_forw_chain_type_to_dpo_proto(fct),
2418 case FIB_PATH_TYPE_DEAG:
2421 case FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS:
2422 lookup_dpo_add_or_lock_w_table_id(MPLS_FIB_DEFAULT_TABLE_ID,
2425 LOOKUP_INPUT_DST_ADDR,
2426 LOOKUP_TABLE_FROM_CONFIG,
2429 case FIB_FORW_CHAIN_TYPE_MPLS_EOS:
2430 case FIB_FORW_CHAIN_TYPE_UNICAST_IP4:
2431 case FIB_FORW_CHAIN_TYPE_UNICAST_IP6:
2432 dpo_copy(dpo, &path->fp_dpo);
2434 case FIB_FORW_CHAIN_TYPE_MCAST_IP4:
2435 case FIB_FORW_CHAIN_TYPE_MCAST_IP6:
2436 case FIB_FORW_CHAIN_TYPE_BIER:
2438 case FIB_FORW_CHAIN_TYPE_ETHERNET:
2439 case FIB_FORW_CHAIN_TYPE_NSH:
2444 case FIB_PATH_TYPE_EXCLUSIVE:
2445 dpo_copy(dpo, &path->exclusive.fp_ex_dpo);
2447 case FIB_PATH_TYPE_ATTACHED:
2448 if (DPO_PROTO_ETHERNET == path->fp_nh_proto)
2450 dpo_copy(dpo, &path->fp_dpo);
2455 case FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS:
2456 case FIB_FORW_CHAIN_TYPE_UNICAST_IP4:
2457 case FIB_FORW_CHAIN_TYPE_UNICAST_IP6:
2458 case FIB_FORW_CHAIN_TYPE_MPLS_EOS:
2459 case FIB_FORW_CHAIN_TYPE_ETHERNET:
2460 case FIB_FORW_CHAIN_TYPE_NSH:
2461 case FIB_FORW_CHAIN_TYPE_BIER:
2466 * get a appropriate link type adj.
2468 ai = fib_path_attached_get_adj(
2470 fib_forw_chain_type_to_link_type(fct));
2471 dpo_set(dpo, DPO_ADJACENCY,
2472 fib_forw_chain_type_to_dpo_proto(fct), ai);
2476 case FIB_FORW_CHAIN_TYPE_MCAST_IP4:
2477 case FIB_FORW_CHAIN_TYPE_MCAST_IP6:
2482 * Create the adj needed for sending IP multicast traffic
2484 ai = adj_mcast_add_or_lock(dpo_proto_to_fib(path->fp_nh_proto),
2485 fib_forw_chain_type_to_link_type(fct),
2486 path->attached.fp_interface);
2487 dpo_set(dpo, DPO_ADJACENCY,
2488 fib_forw_chain_type_to_dpo_proto(fct),
2495 case FIB_PATH_TYPE_INTF_RX:
2497 * Create the adj needed for sending IP multicast traffic
2499 interface_rx_dpo_add_or_lock(fib_forw_chain_type_to_dpo_proto(fct),
2500 path->attached.fp_interface,
2503 case FIB_PATH_TYPE_UDP_ENCAP:
2504 udp_encap_contribute_forwarding(path->udp_encap.fp_udp_encap_id,
2508 case FIB_PATH_TYPE_RECEIVE:
2509 case FIB_PATH_TYPE_SPECIAL:
2510 dpo_copy(dpo, &path->fp_dpo);
2516 load_balance_path_t *
2517 fib_path_append_nh_for_multipath_hash (fib_node_index_t path_index,
2518 fib_forward_chain_type_t fct,
2519 load_balance_path_t *hash_key)
2521 load_balance_path_t *mnh;
2524 path = fib_path_get(path_index);
2528 if (fib_path_is_resolved(path_index))
2530 vec_add2(hash_key, mnh, 1);
2532 mnh->path_weight = path->fp_weight;
2533 mnh->path_index = path_index;
2534 fib_path_contribute_forwarding(path_index, fct, &mnh->path_dpo);
2541 fib_path_is_recursive_constrained (fib_node_index_t path_index)
2545 path = fib_path_get(path_index);
2547 return ((FIB_PATH_TYPE_RECURSIVE == path->fp_type) &&
2548 ((path->fp_cfg_flags & FIB_PATH_CFG_FLAG_RESOLVE_ATTACHED) ||
2549 (path->fp_cfg_flags & FIB_PATH_CFG_FLAG_RESOLVE_HOST)));
2553 fib_path_is_exclusive (fib_node_index_t path_index)
2557 path = fib_path_get(path_index);
2559 return (FIB_PATH_TYPE_EXCLUSIVE == path->fp_type);
2563 fib_path_is_deag (fib_node_index_t path_index)
2567 path = fib_path_get(path_index);
2569 return (FIB_PATH_TYPE_DEAG == path->fp_type);
2573 fib_path_is_resolved (fib_node_index_t path_index)
2577 path = fib_path_get(path_index);
2579 return (dpo_id_is_valid(&path->fp_dpo) &&
2580 (path->fp_oper_flags & FIB_PATH_OPER_FLAG_RESOLVED) &&
2581 !fib_path_is_looped(path_index) &&
2582 !fib_path_is_permanent_drop(path));
2586 fib_path_is_looped (fib_node_index_t path_index)
2590 path = fib_path_get(path_index);
2592 return (path->fp_oper_flags & FIB_PATH_OPER_FLAG_RECURSIVE_LOOP);
2595 fib_path_list_walk_rc_t
2596 fib_path_encode (fib_node_index_t path_list_index,
2597 fib_node_index_t path_index,
2600 fib_route_path_encode_t **api_rpaths = ctx;
2601 fib_route_path_encode_t *api_rpath;
2604 path = fib_path_get(path_index);
2606 return (FIB_PATH_LIST_WALK_CONTINUE);
2607 vec_add2(*api_rpaths, api_rpath, 1);
2608 api_rpath->rpath.frp_weight = path->fp_weight;
2609 api_rpath->rpath.frp_preference = path->fp_preference;
2610 api_rpath->rpath.frp_proto = path->fp_nh_proto;
2611 api_rpath->rpath.frp_sw_if_index = ~0;
2612 api_rpath->dpo = path->exclusive.fp_ex_dpo;
2613 switch (path->fp_type)
2615 case FIB_PATH_TYPE_RECEIVE:
2616 api_rpath->rpath.frp_addr = path->receive.fp_addr;
2617 api_rpath->rpath.frp_sw_if_index = path->receive.fp_interface;
2618 api_rpath->dpo = path->fp_dpo;
2620 case FIB_PATH_TYPE_ATTACHED:
2621 api_rpath->rpath.frp_sw_if_index = path->attached.fp_interface;
2622 api_rpath->dpo = path->fp_dpo;
2624 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
2625 api_rpath->rpath.frp_sw_if_index = path->attached_next_hop.fp_interface;
2626 api_rpath->rpath.frp_addr = path->attached_next_hop.fp_nh;
2628 case FIB_PATH_TYPE_BIER_FMASK:
2629 api_rpath->rpath.frp_fib_index = path->bier_fmask.fp_bier_fib;
2630 api_rpath->rpath.frp_addr = path->bier_fmask.fp_nh;
2632 case FIB_PATH_TYPE_SPECIAL:
2634 case FIB_PATH_TYPE_DEAG:
2635 api_rpath->rpath.frp_fib_index = path->deag.fp_tbl_id;
2636 api_rpath->dpo = path->fp_dpo;
2638 case FIB_PATH_TYPE_RECURSIVE:
2639 api_rpath->rpath.frp_addr = path->recursive.fp_nh.fp_ip;
2644 return (FIB_PATH_LIST_WALK_CONTINUE);
2648 fib_path_get_proto (fib_node_index_t path_index)
2652 path = fib_path_get(path_index);
2654 return (path->fp_nh_proto);
2658 fib_path_module_init (void)
2660 fib_node_register_type (FIB_NODE_TYPE_PATH, &fib_path_vft);
2663 static clib_error_t *
2664 show_fib_path_command (vlib_main_t * vm,
2665 unformat_input_t * input,
2666 vlib_cli_command_t * cmd)
2668 fib_node_index_t pi;
2671 if (unformat (input, "%d", &pi))
2674 * show one in detail
2676 if (!pool_is_free_index(fib_path_pool, pi))
2678 path = fib_path_get(pi);
2679 u8 *s = fib_path_format(pi, NULL);
2680 s = format(s, "children:");
2681 s = fib_node_children_format(path->fp_node.fn_children, s);
2682 vlib_cli_output (vm, "%s", s);
2687 vlib_cli_output (vm, "path %d invalid", pi);
2692 vlib_cli_output (vm, "FIB Paths");
2693 pool_foreach(path, fib_path_pool,
2695 vlib_cli_output (vm, "%U", format_fib_path, path);
2702 VLIB_CLI_COMMAND (show_fib_path, static) = {
2703 .path = "show fib paths",
2704 .function = show_fib_path_command,
2705 .short_help = "show fib paths",