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>
25 #include <vnet/adj/adj.h>
26 #include <vnet/adj/adj_mcast.h>
28 #include <vnet/fib/fib_path.h>
29 #include <vnet/fib/fib_node.h>
30 #include <vnet/fib/fib_table.h>
31 #include <vnet/fib/fib_entry.h>
32 #include <vnet/fib/fib_path_list.h>
33 #include <vnet/fib/fib_internal.h>
34 #include <vnet/fib/fib_urpf_list.h>
37 * Enurmeration of path types
39 typedef enum fib_path_type_t_ {
41 * Marker. Add new types after this one.
43 FIB_PATH_TYPE_FIRST = 0,
45 * Attached-nexthop. An interface and a nexthop are known.
47 FIB_PATH_TYPE_ATTACHED_NEXT_HOP = FIB_PATH_TYPE_FIRST,
49 * attached. Only the interface is known.
51 FIB_PATH_TYPE_ATTACHED,
53 * recursive. Only the next-hop is known.
55 FIB_PATH_TYPE_RECURSIVE,
57 * special. nothing is known. so we drop.
59 FIB_PATH_TYPE_SPECIAL,
61 * exclusive. user provided adj.
63 FIB_PATH_TYPE_EXCLUSIVE,
65 * deag. Link to a lookup adj in the next table
69 * receive. it's for-us.
71 FIB_PATH_TYPE_RECEIVE,
73 * Marker. Add new types before this one, then update it.
75 FIB_PATH_TYPE_LAST = FIB_PATH_TYPE_RECEIVE,
76 } __attribute__ ((packed)) fib_path_type_t;
79 * The maximum number of path_types
81 #define FIB_PATH_TYPE_MAX (FIB_PATH_TYPE_LAST + 1)
83 #define FIB_PATH_TYPES { \
84 [FIB_PATH_TYPE_ATTACHED_NEXT_HOP] = "attached-nexthop", \
85 [FIB_PATH_TYPE_ATTACHED] = "attached", \
86 [FIB_PATH_TYPE_RECURSIVE] = "recursive", \
87 [FIB_PATH_TYPE_SPECIAL] = "special", \
88 [FIB_PATH_TYPE_EXCLUSIVE] = "exclusive", \
89 [FIB_PATH_TYPE_DEAG] = "deag", \
90 [FIB_PATH_TYPE_RECEIVE] = "receive", \
93 #define FOR_EACH_FIB_PATH_TYPE(_item) \
94 for (_item = FIB_PATH_TYPE_FIRST; _item <= FIB_PATH_TYPE_LAST; _item++)
97 * Enurmeration of path operational (i.e. derived) attributes
99 typedef enum fib_path_oper_attribute_t_ {
101 * Marker. Add new types after this one.
103 FIB_PATH_OPER_ATTRIBUTE_FIRST = 0,
105 * The path forms part of a recursive loop.
107 FIB_PATH_OPER_ATTRIBUTE_RECURSIVE_LOOP = FIB_PATH_OPER_ATTRIBUTE_FIRST,
109 * The path is resolved
111 FIB_PATH_OPER_ATTRIBUTE_RESOLVED,
113 * The path is attached, despite what the next-hop may say.
115 FIB_PATH_OPER_ATTRIBUTE_ATTACHED,
117 * The path has become a permanent drop.
119 FIB_PATH_OPER_ATTRIBUTE_DROP,
121 * Marker. Add new types before this one, then update it.
123 FIB_PATH_OPER_ATTRIBUTE_LAST = FIB_PATH_OPER_ATTRIBUTE_DROP,
124 } __attribute__ ((packed)) fib_path_oper_attribute_t;
127 * The maximum number of path operational attributes
129 #define FIB_PATH_OPER_ATTRIBUTE_MAX (FIB_PATH_OPER_ATTRIBUTE_LAST + 1)
131 #define FIB_PATH_OPER_ATTRIBUTES { \
132 [FIB_PATH_OPER_ATTRIBUTE_RECURSIVE_LOOP] = "recursive-loop", \
133 [FIB_PATH_OPER_ATTRIBUTE_RESOLVED] = "resolved", \
134 [FIB_PATH_OPER_ATTRIBUTE_DROP] = "drop", \
137 #define FOR_EACH_FIB_PATH_OPER_ATTRIBUTE(_item) \
138 for (_item = FIB_PATH_OPER_ATTRIBUTE_FIRST; \
139 _item <= FIB_PATH_OPER_ATTRIBUTE_LAST; \
143 * Path flags from the attributes
145 typedef enum fib_path_oper_flags_t_ {
146 FIB_PATH_OPER_FLAG_NONE = 0,
147 FIB_PATH_OPER_FLAG_RECURSIVE_LOOP = (1 << FIB_PATH_OPER_ATTRIBUTE_RECURSIVE_LOOP),
148 FIB_PATH_OPER_FLAG_DROP = (1 << FIB_PATH_OPER_ATTRIBUTE_DROP),
149 FIB_PATH_OPER_FLAG_RESOLVED = (1 << FIB_PATH_OPER_ATTRIBUTE_RESOLVED),
150 FIB_PATH_OPER_FLAG_ATTACHED = (1 << FIB_PATH_OPER_ATTRIBUTE_ATTACHED),
151 } __attribute__ ((packed)) fib_path_oper_flags_t;
156 typedef struct fib_path_t_ {
158 * A path is a node in the FIB graph.
163 * The index of the path-list to which this path belongs
168 * This marks the start of the memory area used to hash
171 STRUCT_MARK(path_hash_start);
174 * Configuration Flags
176 fib_path_cfg_flags_t fp_cfg_flags;
179 * The type of the path. This is the selector for the union
181 fib_path_type_t fp_type;
184 * The protocol of the next-hop, i.e. the address family of the
185 * next-hop's address. We can't derive this from the address itself
186 * since the address can be all zeros
188 fib_protocol_t fp_nh_proto;
191 * UCMP [unnormalised] weigt
196 * per-type union of the data required to resolve the path
203 ip46_address_t fp_nh;
221 ip46_address_t fp_ip;
223 * The local label to resolve through.
225 mpls_label_t fp_local_label;
228 * The FIB table index in which to find the next-hop.
229 * This needs to be fixed. We should lookup the adjacencies in
230 * a separate table of adjacencies, rather than from the FIB.
231 * Two reasons I can think of:
233 * int ip addr Gig0 10.0.0.1/24
234 * ip route 10.0.0.2/32 via Gig1 192.168.1.2
235 * ip route 1.1.1.1/32 via Gig0 10.0.0.2
236 * this is perfectly valid.
237 * Packets addressed to 10.0.0.2 should be sent via Gig1.
238 * Packets address to 1.1.1.1 should be sent via Gig0.
239 * when we perform the adj resolution from the FIB for the path
240 * "via Gig0 10.0.0.2" the lookup will result in the route via Gig1
241 * and so we will pick up the adj via Gig1 - which was not what the
243 * - we can only return link-type IPv4 and so not the link-type MPLS.
244 * more on this in a later commit.
246 * The table ID should only belong to a recursive path and indicate
247 * which FIB should be used to resolve the next-hop.
249 fib_node_index_t fp_tbl_id;
253 * The FIB index in which to perfom the next lookup
255 fib_node_index_t fp_tbl_id;
261 * The user provided 'exclusive' DPO
267 * The interface on which the local address is configured
273 ip46_address_t fp_addr;
276 STRUCT_MARK(path_hash_end);
279 * Memebers in this last section represent information that is
280 * dervied during resolution. It should not be copied to new paths
287 fib_path_oper_flags_t fp_oper_flags;
290 * the resolving via fib. not part of the union, since it it not part
291 * of the path's hash.
293 fib_node_index_t fp_via_fib;
296 * The Data-path objects through which this path resolves for IP.
301 * the index of this path in the parent's child list.
307 * Array of strings/names for the path types and attributes
309 static const char *fib_path_type_names[] = FIB_PATH_TYPES;
310 static const char *fib_path_oper_attribute_names[] = FIB_PATH_OPER_ATTRIBUTES;
311 static const char *fib_path_cfg_attribute_names[] = FIB_PATH_CFG_ATTRIBUTES;
314 * The memory pool from which we allocate all the paths
316 static fib_path_t *fib_path_pool;
322 #define FIB_PATH_DBG(_p, _fmt, _args...) \
325 _tmp = fib_path_format(fib_path_get_index(_p), _tmp); \
326 clib_warning("path:[%d:%s]:" _fmt, \
327 fib_path_get_index(_p), _tmp, \
332 #define FIB_PATH_DBG(_p, _fmt, _args...)
336 fib_path_get (fib_node_index_t index)
338 return (pool_elt_at_index(fib_path_pool, index));
341 static fib_node_index_t
342 fib_path_get_index (fib_path_t *path)
344 return (path - fib_path_pool);
348 fib_path_get_node (fib_node_index_t index)
350 return ((fib_node_t*)fib_path_get(index));
354 fib_path_from_fib_node (fib_node_t *node)
357 ASSERT(FIB_NODE_TYPE_PATH == node->fn_type);
359 return ((fib_path_t*)node);
363 format_fib_path (u8 * s, va_list * args)
365 fib_path_t *path = va_arg (*args, fib_path_t *);
366 vnet_main_t * vnm = vnet_get_main();
367 fib_path_oper_attribute_t oattr;
368 fib_path_cfg_attribute_t cattr;
370 s = format (s, " index:%d ", fib_path_get_index(path));
371 s = format (s, "pl-index:%d ", path->fp_pl_index);
372 s = format (s, "%U ", format_fib_protocol, path->fp_nh_proto);
373 s = format (s, "weight=%d ", path->fp_weight);
374 s = format (s, "%s: ", fib_path_type_names[path->fp_type]);
375 if (FIB_PATH_OPER_FLAG_NONE != path->fp_oper_flags) {
376 s = format(s, " oper-flags:");
377 FOR_EACH_FIB_PATH_OPER_ATTRIBUTE(oattr) {
378 if ((1<<oattr) & path->fp_oper_flags) {
379 s = format (s, "%s,", fib_path_oper_attribute_names[oattr]);
383 if (FIB_PATH_CFG_FLAG_NONE != path->fp_cfg_flags) {
384 s = format(s, " cfg-flags:");
385 FOR_EACH_FIB_PATH_CFG_ATTRIBUTE(cattr) {
386 if ((1<<cattr) & path->fp_cfg_flags) {
387 s = format (s, "%s,", fib_path_cfg_attribute_names[cattr]);
391 s = format(s, "\n ");
393 switch (path->fp_type)
395 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
396 s = format (s, "%U", format_ip46_address,
397 &path->attached_next_hop.fp_nh,
399 if (path->fp_oper_flags & FIB_PATH_OPER_FLAG_DROP)
401 s = format (s, " if_index:%d", path->attached_next_hop.fp_interface);
405 s = format (s, " %U",
406 format_vnet_sw_interface_name,
408 vnet_get_sw_interface(
410 path->attached_next_hop.fp_interface));
411 if (vnet_sw_interface_is_p2p(vnet_get_main(),
412 path->attached_next_hop.fp_interface))
414 s = format (s, " (p2p)");
417 if (!dpo_id_is_valid(&path->fp_dpo))
419 s = format(s, "\n unresolved");
423 s = format(s, "\n %U",
428 case FIB_PATH_TYPE_ATTACHED:
429 if (path->fp_oper_flags & FIB_PATH_OPER_FLAG_DROP)
431 s = format (s, " if_index:%d", path->attached_next_hop.fp_interface);
435 s = format (s, " %U",
436 format_vnet_sw_interface_name,
438 vnet_get_sw_interface(
440 path->attached.fp_interface));
443 case FIB_PATH_TYPE_RECURSIVE:
444 if (FIB_PROTOCOL_MPLS == path->fp_nh_proto)
446 s = format (s, "via %U",
447 format_mpls_unicast_label,
448 path->recursive.fp_nh.fp_local_label);
452 s = format (s, "via %U",
454 &path->recursive.fp_nh.fp_ip,
457 s = format (s, " in fib:%d",
458 path->recursive.fp_tbl_id,
460 s = format (s, " via-fib:%d", path->fp_via_fib);
461 s = format (s, " via-dpo:[%U:%d]",
462 format_dpo_type, path->fp_dpo.dpoi_type,
463 path->fp_dpo.dpoi_index);
466 case FIB_PATH_TYPE_RECEIVE:
467 case FIB_PATH_TYPE_SPECIAL:
468 case FIB_PATH_TYPE_DEAG:
469 case FIB_PATH_TYPE_EXCLUSIVE:
470 if (dpo_id_is_valid(&path->fp_dpo))
472 s = format(s, "%U", format_dpo_id,
481 fib_path_format (fib_node_index_t pi, u8 *s)
485 path = fib_path_get(pi);
486 ASSERT(NULL != path);
488 return (format (s, "%U", format_fib_path, path));
492 fib_path_adj_format (fib_node_index_t pi,
498 path = fib_path_get(pi);
499 ASSERT(NULL != path);
501 if (!dpo_id_is_valid(&path->fp_dpo))
503 s = format(s, " unresolved");
507 s = format(s, "%U", format_dpo_id,
515 * fib_path_last_lock_gone
517 * We don't share paths, we share path lists, so the [un]lock functions
521 fib_path_last_lock_gone (fib_node_t *node)
526 static const adj_index_t
527 fib_path_attached_next_hop_get_adj (fib_path_t *path,
530 if (vnet_sw_interface_is_p2p(vnet_get_main(),
531 path->attached_next_hop.fp_interface))
534 * if the interface is p2p then the adj for the specific
535 * neighbour on that link will never exist. on p2p links
536 * the subnet address (the attached route) links to the
537 * auto-adj (see below), we want that adj here too.
539 return (adj_nbr_add_or_lock(path->fp_nh_proto,
542 path->attached_next_hop.fp_interface));
546 return (adj_nbr_add_or_lock(path->fp_nh_proto,
548 &path->attached_next_hop.fp_nh,
549 path->attached_next_hop.fp_interface));
554 fib_path_attached_next_hop_set (fib_path_t *path)
557 * resolve directly via the adjacnecy discribed by the
558 * interface and next-hop
560 if (!vnet_sw_interface_is_admin_up(vnet_get_main(),
561 path->attached_next_hop.fp_interface))
563 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
566 dpo_set(&path->fp_dpo,
568 fib_proto_to_dpo(path->fp_nh_proto),
569 fib_path_attached_next_hop_get_adj(
571 fib_proto_to_link(path->fp_nh_proto)));
574 * become a child of the adjacency so we receive updates
575 * when its rewrite changes
577 path->fp_sibling = adj_child_add(path->fp_dpo.dpoi_index,
579 fib_path_get_index(path));
583 * create of update the paths recursive adj
586 fib_path_recursive_adj_update (fib_path_t *path,
587 fib_forward_chain_type_t fct,
590 dpo_id_t via_dpo = DPO_INVALID;
593 * get the DPO to resolve through from the via-entry
595 fib_entry_contribute_forwarding(path->fp_via_fib,
601 * hope for the best - clear if restrictions apply.
603 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RESOLVED;
606 * Validate any recursion constraints and over-ride the via
609 if (path->fp_oper_flags & FIB_PATH_OPER_FLAG_RECURSIVE_LOOP)
611 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
612 dpo_copy(&via_dpo, drop_dpo_get(fib_proto_to_dpo(path->fp_nh_proto)));
614 else if (path->fp_cfg_flags & FIB_PATH_CFG_FLAG_RESOLVE_HOST)
617 * the via FIB must be a host route.
618 * note the via FIB just added will always be a host route
619 * since it is an RR source added host route. So what we need to
620 * check is whether the route has other sources. If it does then
621 * some other source has added it as a host route. If it doesn't
622 * then it was added only here and inherits forwarding from a cover.
623 * the cover is not a host route.
624 * The RR source is the lowest priority source, so we check if it
625 * is the best. if it is there are no other sources.
627 if (fib_entry_get_best_source(path->fp_via_fib) >= FIB_SOURCE_RR)
629 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
630 dpo_copy(&via_dpo, drop_dpo_get(fib_proto_to_dpo(path->fp_nh_proto)));
633 * PIC edge trigger. let the load-balance maps know
635 load_balance_map_path_state_change(fib_path_get_index(path));
638 else if (path->fp_cfg_flags & FIB_PATH_CFG_FLAG_RESOLVE_ATTACHED)
641 * RR source entries inherit the flags from the cover, so
642 * we can check the via directly
644 if (!(FIB_ENTRY_FLAG_ATTACHED & fib_entry_get_flags(path->fp_via_fib)))
646 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
647 dpo_copy(&via_dpo, drop_dpo_get(fib_proto_to_dpo(path->fp_nh_proto)));
650 * PIC edge trigger. let the load-balance maps know
652 load_balance_map_path_state_change(fib_path_get_index(path));
657 * update the path's contributed DPO
659 dpo_copy(dpo, &via_dpo);
661 FIB_PATH_DBG(path, "recursive update: %U",
662 fib_get_lookup_main(path->fp_nh_proto),
669 * fib_path_is_permanent_drop
671 * Return !0 if the path is configured to permanently drop,
672 * despite other attributes.
675 fib_path_is_permanent_drop (fib_path_t *path)
677 return ((path->fp_cfg_flags & FIB_PATH_CFG_FLAG_DROP) ||
678 (path->fp_oper_flags & FIB_PATH_OPER_FLAG_DROP));
684 * Remove our dependency on the resolution target
687 fib_path_unresolve (fib_path_t *path)
690 * the forced drop path does not need unresolving
692 if (fib_path_is_permanent_drop(path))
697 switch (path->fp_type)
699 case FIB_PATH_TYPE_RECURSIVE:
700 if (FIB_NODE_INDEX_INVALID != path->fp_via_fib)
704 fib_entry_get_prefix(path->fp_via_fib, &pfx);
705 fib_entry_child_remove(path->fp_via_fib,
707 fib_table_entry_special_remove(path->recursive.fp_tbl_id,
710 path->fp_via_fib = FIB_NODE_INDEX_INVALID;
713 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
714 case FIB_PATH_TYPE_ATTACHED:
715 adj_child_remove(path->fp_dpo.dpoi_index,
717 adj_unlock(path->fp_dpo.dpoi_index);
719 case FIB_PATH_TYPE_EXCLUSIVE:
720 dpo_reset(&path->exclusive.fp_ex_dpo);
722 case FIB_PATH_TYPE_SPECIAL:
723 case FIB_PATH_TYPE_RECEIVE:
724 case FIB_PATH_TYPE_DEAG:
726 * these hold only the path's DPO, which is reset below.
732 * release the adj we were holding and pick up the
735 dpo_reset(&path->fp_dpo);
736 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
741 static fib_forward_chain_type_t
742 fib_path_proto_to_chain_type (fib_protocol_t proto)
746 case FIB_PROTOCOL_IP4:
747 return (FIB_FORW_CHAIN_TYPE_UNICAST_IP4);
748 case FIB_PROTOCOL_IP6:
749 return (FIB_FORW_CHAIN_TYPE_UNICAST_IP6);
750 case FIB_PROTOCOL_MPLS:
751 return (FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS);
753 return (FIB_FORW_CHAIN_TYPE_UNICAST_IP4);
757 * fib_path_back_walk_notify
759 * A back walk has reach this path.
761 static fib_node_back_walk_rc_t
762 fib_path_back_walk_notify (fib_node_t *node,
763 fib_node_back_walk_ctx_t *ctx)
767 path = fib_path_from_fib_node(node);
769 switch (path->fp_type)
771 case FIB_PATH_TYPE_RECURSIVE:
772 if (FIB_NODE_BW_REASON_FLAG_EVALUATE & ctx->fnbw_reason)
775 * modify the recursive adjacency to use the new forwarding
777 * this update is visible to packets in flight in the DP.
779 fib_path_recursive_adj_update(
781 fib_path_proto_to_chain_type(path->fp_nh_proto),
784 if ((FIB_NODE_BW_REASON_FLAG_ADJ_UPDATE & ctx->fnbw_reason) ||
785 (FIB_NODE_BW_REASON_FLAG_ADJ_DOWN & ctx->fnbw_reason))
788 * ADJ updates (complete<->incomplete) do not need to propagate to
790 * The only reason its needed as far back as here, is that the adj
791 * and the incomplete adj are a different DPO type, so the LBs need
793 * If this walk was quashed in the fib_entry, then any non-fib_path
794 * children (like tunnels that collapse out the LB when they stack)
795 * would not see the update.
797 return (FIB_NODE_BACK_WALK_CONTINUE);
800 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
803 * ADJ_UPDATE backwalk pass silently through here and up to
804 * the path-list when the multipath adj collapse occurs.
805 * The reason we do this is that the assumtption is that VPP
806 * runs in an environment where the Control-Plane is remote
807 * and hence reacts slowly to link up down. In order to remove
808 * this down link from the ECMP set quickly, we back-walk.
809 * VPP also has dedicated CPUs, so we are not stealing resources
810 * from the CP to do so.
812 if (FIB_NODE_BW_REASON_FLAG_INTERFACE_UP & ctx->fnbw_reason)
814 if (path->fp_oper_flags & FIB_PATH_OPER_FLAG_RESOLVED)
817 * alreday resolved. no need to walk back again
819 return (FIB_NODE_BACK_WALK_CONTINUE);
821 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RESOLVED;
823 if (FIB_NODE_BW_REASON_FLAG_INTERFACE_DOWN & ctx->fnbw_reason)
825 if (!(path->fp_oper_flags & FIB_PATH_OPER_FLAG_RESOLVED))
828 * alreday unresolved. no need to walk back again
830 return (FIB_NODE_BACK_WALK_CONTINUE);
832 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
834 if (FIB_NODE_BW_REASON_FLAG_INTERFACE_DELETE & ctx->fnbw_reason)
837 * The interface this path resolves through has been deleted.
838 * This will leave the path in a permanent drop state. The route
839 * needs to be removed and readded (and hence the path-list deleted)
840 * before it can forward again.
842 fib_path_unresolve(path);
843 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_DROP;
845 if (FIB_NODE_BW_REASON_FLAG_ADJ_UPDATE & ctx->fnbw_reason)
848 * restack the DPO to pick up the correct DPO sub-type
853 if_is_up = vnet_sw_interface_is_admin_up(
855 path->attached_next_hop.fp_interface);
859 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RESOLVED;
862 ai = fib_path_attached_next_hop_get_adj(
864 fib_proto_to_link(path->fp_nh_proto));
866 dpo_set(&path->fp_dpo, DPO_ADJACENCY,
867 fib_proto_to_dpo(path->fp_nh_proto),
874 * If the interface is not up there is no reason to walk
875 * back to children. if we did they would only evalute
876 * that this path is unresolved and hence it would
877 * not contribute the adjacency - so it would be wasted
880 return (FIB_NODE_BACK_WALK_CONTINUE);
883 if (FIB_NODE_BW_REASON_FLAG_ADJ_DOWN & ctx->fnbw_reason)
885 if (!(path->fp_oper_flags & FIB_PATH_OPER_FLAG_RESOLVED))
888 * alreday unresolved. no need to walk back again
890 return (FIB_NODE_BACK_WALK_CONTINUE);
893 * the adj has gone down. the path is no longer resolved.
895 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
898 case FIB_PATH_TYPE_ATTACHED:
900 * FIXME; this could schedule a lower priority walk, since attached
901 * routes are not usually in ECMP configurations so the backwalk to
902 * the FIB entry does not need to be high priority
904 if (FIB_NODE_BW_REASON_FLAG_INTERFACE_UP & ctx->fnbw_reason)
906 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RESOLVED;
908 if (FIB_NODE_BW_REASON_FLAG_INTERFACE_DOWN & ctx->fnbw_reason)
910 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
912 if (FIB_NODE_BW_REASON_FLAG_INTERFACE_DELETE & ctx->fnbw_reason)
914 fib_path_unresolve(path);
915 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_DROP;
918 case FIB_PATH_TYPE_DEAG:
920 * FIXME When VRF delete is allowed this will need a poke.
922 case FIB_PATH_TYPE_SPECIAL:
923 case FIB_PATH_TYPE_RECEIVE:
924 case FIB_PATH_TYPE_EXCLUSIVE:
926 * these path types have no parents. so to be
927 * walked from one is unexpected.
934 * propagate the backwalk further to the path-list
936 fib_path_list_back_walk(path->fp_pl_index, ctx);
938 return (FIB_NODE_BACK_WALK_CONTINUE);
942 fib_path_memory_show (void)
944 fib_show_memory_usage("Path",
945 pool_elts(fib_path_pool),
946 pool_len(fib_path_pool),
951 * The FIB path's graph node virtual function table
953 static const fib_node_vft_t fib_path_vft = {
954 .fnv_get = fib_path_get_node,
955 .fnv_last_lock = fib_path_last_lock_gone,
956 .fnv_back_walk = fib_path_back_walk_notify,
957 .fnv_mem_show = fib_path_memory_show,
960 static fib_path_cfg_flags_t
961 fib_path_route_flags_to_cfg_flags (const fib_route_path_t *rpath)
963 fib_path_cfg_flags_t cfg_flags = FIB_PATH_CFG_FLAG_NONE;
965 if (rpath->frp_flags & FIB_ROUTE_PATH_RESOLVE_VIA_HOST)
966 cfg_flags |= FIB_PATH_CFG_FLAG_RESOLVE_HOST;
967 if (rpath->frp_flags & FIB_ROUTE_PATH_RESOLVE_VIA_ATTACHED)
968 cfg_flags |= FIB_PATH_CFG_FLAG_RESOLVE_ATTACHED;
969 if (rpath->frp_flags & FIB_ROUTE_PATH_LOCAL)
970 cfg_flags |= FIB_PATH_CFG_FLAG_LOCAL;
971 if (rpath->frp_flags & FIB_ROUTE_PATH_ATTACHED)
972 cfg_flags |= FIB_PATH_CFG_FLAG_ATTACHED;
980 * Create and initialise a new path object.
981 * return the index of the path.
984 fib_path_create (fib_node_index_t pl_index,
985 fib_protocol_t nh_proto,
986 fib_path_cfg_flags_t flags,
987 const fib_route_path_t *rpath)
991 pool_get(fib_path_pool, path);
992 memset(path, 0, sizeof(*path));
994 fib_node_init(&path->fp_node,
997 dpo_reset(&path->fp_dpo);
998 path->fp_pl_index = pl_index;
999 path->fp_nh_proto = nh_proto;
1000 path->fp_via_fib = FIB_NODE_INDEX_INVALID;
1001 path->fp_weight = rpath->frp_weight;
1002 if (0 == path->fp_weight)
1005 * a weight of 0 is a meaningless value. We could either reject it, and thus force
1006 * clients to always use 1, or we can accept it and fixup approrpiately.
1008 path->fp_weight = 1;
1010 path->fp_cfg_flags = flags;
1011 path->fp_cfg_flags |= fib_path_route_flags_to_cfg_flags(rpath);
1014 * deduce the path's tpye from the parementers and save what is needed.
1016 if (path->fp_cfg_flags & FIB_PATH_CFG_FLAG_LOCAL)
1018 path->fp_type = FIB_PATH_TYPE_RECEIVE;
1019 path->receive.fp_interface = rpath->frp_sw_if_index;
1020 path->receive.fp_addr = rpath->frp_addr;
1022 else if (~0 != rpath->frp_sw_if_index)
1024 if (ip46_address_is_zero(&rpath->frp_addr))
1026 path->fp_type = FIB_PATH_TYPE_ATTACHED;
1027 path->attached.fp_interface = rpath->frp_sw_if_index;
1031 path->fp_type = FIB_PATH_TYPE_ATTACHED_NEXT_HOP;
1032 path->attached_next_hop.fp_interface = rpath->frp_sw_if_index;
1033 path->attached_next_hop.fp_nh = rpath->frp_addr;
1038 if (ip46_address_is_zero(&rpath->frp_addr))
1040 if (~0 == rpath->frp_fib_index)
1042 path->fp_type = FIB_PATH_TYPE_SPECIAL;
1046 path->fp_type = FIB_PATH_TYPE_DEAG;
1047 path->deag.fp_tbl_id = rpath->frp_fib_index;
1052 path->fp_type = FIB_PATH_TYPE_RECURSIVE;
1053 if (FIB_PROTOCOL_MPLS == path->fp_nh_proto)
1055 path->recursive.fp_nh.fp_local_label = rpath->frp_local_label;
1059 path->recursive.fp_nh.fp_ip = rpath->frp_addr;
1061 path->recursive.fp_tbl_id = rpath->frp_fib_index;
1065 FIB_PATH_DBG(path, "create");
1067 return (fib_path_get_index(path));
1071 * fib_path_create_special
1073 * Create and initialise a new path object.
1074 * return the index of the path.
1077 fib_path_create_special (fib_node_index_t pl_index,
1078 fib_protocol_t nh_proto,
1079 fib_path_cfg_flags_t flags,
1080 const dpo_id_t *dpo)
1084 pool_get(fib_path_pool, path);
1085 memset(path, 0, sizeof(*path));
1087 fib_node_init(&path->fp_node,
1088 FIB_NODE_TYPE_PATH);
1089 dpo_reset(&path->fp_dpo);
1091 path->fp_pl_index = pl_index;
1092 path->fp_weight = 1;
1093 path->fp_nh_proto = nh_proto;
1094 path->fp_via_fib = FIB_NODE_INDEX_INVALID;
1095 path->fp_cfg_flags = flags;
1097 if (FIB_PATH_CFG_FLAG_DROP & flags)
1099 path->fp_type = FIB_PATH_TYPE_SPECIAL;
1101 else if (FIB_PATH_CFG_FLAG_LOCAL & flags)
1103 path->fp_type = FIB_PATH_TYPE_RECEIVE;
1104 path->attached.fp_interface = FIB_NODE_INDEX_INVALID;
1108 path->fp_type = FIB_PATH_TYPE_EXCLUSIVE;
1109 ASSERT(NULL != dpo);
1110 dpo_copy(&path->exclusive.fp_ex_dpo, dpo);
1113 return (fib_path_get_index(path));
1119 * Copy a path. return index of new path.
1122 fib_path_copy (fib_node_index_t path_index,
1123 fib_node_index_t path_list_index)
1125 fib_path_t *path, *orig_path;
1127 pool_get(fib_path_pool, path);
1129 orig_path = fib_path_get(path_index);
1130 ASSERT(NULL != orig_path);
1132 memcpy(path, orig_path, sizeof(*path));
1134 FIB_PATH_DBG(path, "create-copy:%d", path_index);
1137 * reset the dynamic section
1139 fib_node_init(&path->fp_node, FIB_NODE_TYPE_PATH);
1140 path->fp_oper_flags = FIB_PATH_OPER_FLAG_NONE;
1141 path->fp_pl_index = path_list_index;
1142 path->fp_via_fib = FIB_NODE_INDEX_INVALID;
1143 memset(&path->fp_dpo, 0, sizeof(path->fp_dpo));
1144 dpo_reset(&path->fp_dpo);
1146 return (fib_path_get_index(path));
1152 * destroy a path that is no longer required
1155 fib_path_destroy (fib_node_index_t path_index)
1159 path = fib_path_get(path_index);
1161 ASSERT(NULL != path);
1162 FIB_PATH_DBG(path, "destroy");
1164 fib_path_unresolve(path);
1166 fib_node_deinit(&path->fp_node);
1167 pool_put(fib_path_pool, path);
1173 * destroy a path that is no longer required
1176 fib_path_hash (fib_node_index_t path_index)
1180 path = fib_path_get(path_index);
1182 return (hash_memory(STRUCT_MARK_PTR(path, path_hash_start),
1183 (STRUCT_OFFSET_OF(fib_path_t, path_hash_end) -
1184 STRUCT_OFFSET_OF(fib_path_t, path_hash_start)),
1191 * Compare two paths for equivalence.
1194 fib_path_cmp_i (const fib_path_t *path1,
1195 const fib_path_t *path2)
1202 * paths of different types and protocol are not equal.
1203 * different weights only are the same path.
1205 if (path1->fp_type != path2->fp_type)
1207 res = (path1->fp_type - path2->fp_type);
1209 else if (path1->fp_nh_proto != path2->fp_nh_proto)
1211 res = (path1->fp_nh_proto - path2->fp_nh_proto);
1216 * both paths are of the same type.
1217 * consider each type and its attributes in turn.
1219 switch (path1->fp_type)
1221 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1222 res = ip46_address_cmp(&path1->attached_next_hop.fp_nh,
1223 &path2->attached_next_hop.fp_nh);
1225 res = vnet_sw_interface_compare(
1227 path1->attached_next_hop.fp_interface,
1228 path2->attached_next_hop.fp_interface);
1231 case FIB_PATH_TYPE_ATTACHED:
1232 res = vnet_sw_interface_compare(
1234 path1->attached.fp_interface,
1235 path2->attached.fp_interface);
1237 case FIB_PATH_TYPE_RECURSIVE:
1238 res = ip46_address_cmp(&path1->recursive.fp_nh,
1239 &path2->recursive.fp_nh);
1243 res = (path1->recursive.fp_tbl_id - path2->recursive.fp_tbl_id);
1246 case FIB_PATH_TYPE_DEAG:
1247 res = (path1->deag.fp_tbl_id - path2->deag.fp_tbl_id);
1249 case FIB_PATH_TYPE_SPECIAL:
1250 case FIB_PATH_TYPE_RECEIVE:
1251 case FIB_PATH_TYPE_EXCLUSIVE:
1260 * fib_path_cmp_for_sort
1262 * Compare two paths for equivalence. Used during path sorting.
1263 * As usual 0 means equal.
1266 fib_path_cmp_for_sort (void * v1,
1269 fib_node_index_t *pi1 = v1, *pi2 = v2;
1270 fib_path_t *path1, *path2;
1272 path1 = fib_path_get(*pi1);
1273 path2 = fib_path_get(*pi2);
1275 return (fib_path_cmp_i(path1, path2));
1281 * Compare two paths for equivalence.
1284 fib_path_cmp (fib_node_index_t pi1,
1285 fib_node_index_t pi2)
1287 fib_path_t *path1, *path2;
1289 path1 = fib_path_get(pi1);
1290 path2 = fib_path_get(pi2);
1292 return (fib_path_cmp_i(path1, path2));
1296 fib_path_cmp_w_route_path (fib_node_index_t path_index,
1297 const fib_route_path_t *rpath)
1302 path = fib_path_get(path_index);
1306 if (path->fp_weight != rpath->frp_weight)
1308 res = (path->fp_weight - rpath->frp_weight);
1313 * both paths are of the same type.
1314 * consider each type and its attributes in turn.
1316 switch (path->fp_type)
1318 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1319 res = ip46_address_cmp(&path->attached_next_hop.fp_nh,
1323 res = vnet_sw_interface_compare(
1325 path->attached_next_hop.fp_interface,
1326 rpath->frp_sw_if_index);
1329 case FIB_PATH_TYPE_ATTACHED:
1330 res = vnet_sw_interface_compare(
1332 path->attached.fp_interface,
1333 rpath->frp_sw_if_index);
1335 case FIB_PATH_TYPE_RECURSIVE:
1336 if (FIB_PROTOCOL_MPLS == path->fp_nh_proto)
1338 res = path->recursive.fp_nh.fp_local_label - rpath->frp_local_label;
1342 res = ip46_address_cmp(&path->recursive.fp_nh.fp_ip,
1348 res = (path->recursive.fp_tbl_id - rpath->frp_fib_index);
1351 case FIB_PATH_TYPE_DEAG:
1352 res = (path->deag.fp_tbl_id - rpath->frp_fib_index);
1354 case FIB_PATH_TYPE_SPECIAL:
1355 case FIB_PATH_TYPE_RECEIVE:
1356 case FIB_PATH_TYPE_EXCLUSIVE:
1365 * fib_path_recursive_loop_detect
1367 * A forward walk of the FIB object graph to detect for a cycle/loop. This
1368 * walk is initiated when an entry is linking to a new path list or from an old.
1369 * The entry vector passed contains all the FIB entrys that are children of this
1370 * path (it is all the entries encountered on the walk so far). If this vector
1371 * contains the entry this path resolve via, then a loop is about to form.
1372 * The loop must be allowed to form, since we need the dependencies in place
1373 * so that we can track when the loop breaks.
1374 * However, we MUST not produce a loop in the forwarding graph (else packets
1375 * would loop around the switch path until the loop breaks), so we mark recursive
1376 * paths as looped so that they do not contribute forwarding information.
1377 * By marking the path as looped, an etry such as;
1379 * via a.a.a.a (looped)
1380 * via b.b.b.b (not looped)
1381 * can still forward using the info provided by b.b.b.b only
1384 fib_path_recursive_loop_detect (fib_node_index_t path_index,
1385 fib_node_index_t **entry_indicies)
1389 path = fib_path_get(path_index);
1392 * the forced drop path is never looped, cos it is never resolved.
1394 if (fib_path_is_permanent_drop(path))
1399 switch (path->fp_type)
1401 case FIB_PATH_TYPE_RECURSIVE:
1403 fib_node_index_t *entry_index, *entries;
1405 entries = *entry_indicies;
1407 vec_foreach(entry_index, entries) {
1408 if (*entry_index == path->fp_via_fib)
1411 * the entry that is about to link to this path-list (or
1412 * one of this path-list's children) is the same entry that
1413 * this recursive path resolves through. this is a cycle.
1423 FIB_PATH_DBG(path, "recursive loop formed");
1424 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RECURSIVE_LOOP;
1426 dpo_copy(&path->fp_dpo,
1427 drop_dpo_get(fib_proto_to_dpo(path->fp_nh_proto)));
1432 * no loop here yet. keep forward walking the graph.
1434 if (fib_entry_recursive_loop_detect(path->fp_via_fib, entry_indicies))
1436 FIB_PATH_DBG(path, "recursive loop formed");
1437 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RECURSIVE_LOOP;
1441 FIB_PATH_DBG(path, "recursive loop cleared");
1442 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RECURSIVE_LOOP;
1447 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1448 case FIB_PATH_TYPE_ATTACHED:
1449 case FIB_PATH_TYPE_SPECIAL:
1450 case FIB_PATH_TYPE_DEAG:
1451 case FIB_PATH_TYPE_RECEIVE:
1452 case FIB_PATH_TYPE_EXCLUSIVE:
1454 * these path types cannot be part of a loop, since they are the leaves
1460 return (fib_path_is_looped(path_index));
1464 fib_path_resolve (fib_node_index_t path_index)
1468 path = fib_path_get(path_index);
1471 * hope for the best.
1473 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RESOLVED;
1476 * the forced drop path resolves via the drop adj
1478 if (fib_path_is_permanent_drop(path))
1480 dpo_copy(&path->fp_dpo,
1481 drop_dpo_get(fib_proto_to_dpo(path->fp_nh_proto)));
1482 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
1483 return (fib_path_is_resolved(path_index));
1486 switch (path->fp_type)
1488 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1489 fib_path_attached_next_hop_set(path);
1491 case FIB_PATH_TYPE_ATTACHED:
1493 * path->attached.fp_interface
1495 if (!vnet_sw_interface_is_admin_up(vnet_get_main(),
1496 path->attached.fp_interface))
1498 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
1500 if (vnet_sw_interface_is_p2p(vnet_get_main(),
1501 path->attached.fp_interface))
1504 * point-2-point interfaces do not require a glean, since
1505 * there is nothing to ARP. Install a rewrite/nbr adj instead
1507 dpo_set(&path->fp_dpo,
1509 fib_proto_to_dpo(path->fp_nh_proto),
1510 adj_nbr_add_or_lock(
1512 fib_proto_to_link(path->fp_nh_proto),
1514 path->attached.fp_interface));
1518 dpo_set(&path->fp_dpo,
1519 DPO_ADJACENCY_GLEAN,
1520 fib_proto_to_dpo(path->fp_nh_proto),
1521 adj_glean_add_or_lock(path->fp_nh_proto,
1522 path->attached.fp_interface,
1526 * become a child of the adjacency so we receive updates
1527 * when the interface state changes
1529 path->fp_sibling = adj_child_add(path->fp_dpo.dpoi_index,
1531 fib_path_get_index(path));
1534 case FIB_PATH_TYPE_RECURSIVE:
1537 * Create a RR source entry in the table for the address
1538 * that this path recurses through.
1539 * This resolve action is recursive, hence we may create
1540 * more paths in the process. more creates mean maybe realloc
1543 fib_node_index_t fei;
1546 ASSERT(FIB_NODE_INDEX_INVALID == path->fp_via_fib);
1548 if (FIB_PROTOCOL_MPLS == path->fp_nh_proto)
1550 fib_prefix_from_mpls_label(path->recursive.fp_nh.fp_local_label, &pfx);
1554 fib_prefix_from_ip46_addr(&path->recursive.fp_nh.fp_ip, &pfx);
1557 fei = fib_table_entry_special_add(path->recursive.fp_tbl_id,
1560 FIB_ENTRY_FLAG_NONE,
1563 path = fib_path_get(path_index);
1564 path->fp_via_fib = fei;
1567 * become a dependent child of the entry so the path is
1568 * informed when the forwarding for the entry changes.
1570 path->fp_sibling = fib_entry_child_add(path->fp_via_fib,
1572 fib_path_get_index(path));
1575 * create and configure the IP DPO
1577 fib_path_recursive_adj_update(
1579 fib_path_proto_to_chain_type(path->fp_nh_proto),
1584 case FIB_PATH_TYPE_SPECIAL:
1586 * Resolve via the drop
1588 dpo_copy(&path->fp_dpo,
1589 drop_dpo_get(fib_proto_to_dpo(path->fp_nh_proto)));
1591 case FIB_PATH_TYPE_DEAG:
1593 * Resolve via a lookup DPO.
1594 * FIXME. control plane should add routes with a table ID
1596 lookup_dpo_add_or_lock_w_fib_index(path->deag.fp_tbl_id,
1597 fib_proto_to_dpo(path->fp_nh_proto),
1598 LOOKUP_INPUT_DST_ADDR,
1599 LOOKUP_TABLE_FROM_CONFIG,
1602 case FIB_PATH_TYPE_RECEIVE:
1604 * Resolve via a receive DPO.
1606 receive_dpo_add_or_lock(fib_proto_to_dpo(path->fp_nh_proto),
1607 path->receive.fp_interface,
1608 &path->receive.fp_addr,
1611 case FIB_PATH_TYPE_EXCLUSIVE:
1613 * Resolve via the user provided DPO
1615 dpo_copy(&path->fp_dpo, &path->exclusive.fp_ex_dpo);
1619 return (fib_path_is_resolved(path_index));
1623 fib_path_get_resolving_interface (fib_node_index_t path_index)
1627 path = fib_path_get(path_index);
1629 switch (path->fp_type)
1631 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1632 return (path->attached_next_hop.fp_interface);
1633 case FIB_PATH_TYPE_ATTACHED:
1634 return (path->attached.fp_interface);
1635 case FIB_PATH_TYPE_RECEIVE:
1636 return (path->receive.fp_interface);
1637 case FIB_PATH_TYPE_RECURSIVE:
1638 return (fib_entry_get_resolving_interface(path->fp_via_fib));
1639 case FIB_PATH_TYPE_SPECIAL:
1640 case FIB_PATH_TYPE_DEAG:
1641 case FIB_PATH_TYPE_EXCLUSIVE:
1648 fib_path_get_adj (fib_node_index_t path_index)
1652 path = fib_path_get(path_index);
1654 ASSERT(dpo_is_adj(&path->fp_dpo));
1655 if (dpo_is_adj(&path->fp_dpo))
1657 return (path->fp_dpo.dpoi_index);
1659 return (ADJ_INDEX_INVALID);
1663 fib_path_get_weight (fib_node_index_t path_index)
1667 path = fib_path_get(path_index);
1671 return (path->fp_weight);
1675 * @brief Contribute the path's adjacency to the list passed.
1676 * By calling this function over all paths, recursively, a child
1677 * can construct its full set of forwarding adjacencies, and hence its
1681 fib_path_contribute_urpf (fib_node_index_t path_index,
1686 if (!fib_path_is_resolved(path_index))
1689 path = fib_path_get(path_index);
1691 switch (path->fp_type)
1693 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1694 fib_urpf_list_append(urpf, path->attached_next_hop.fp_interface);
1697 case FIB_PATH_TYPE_ATTACHED:
1698 fib_urpf_list_append(urpf, path->attached.fp_interface);
1701 case FIB_PATH_TYPE_RECURSIVE:
1702 fib_entry_contribute_urpf(path->fp_via_fib, urpf);
1705 case FIB_PATH_TYPE_EXCLUSIVE:
1706 case FIB_PATH_TYPE_SPECIAL:
1708 * these path types may link to an adj, if that's what
1711 if (dpo_is_adj(&path->fp_dpo))
1713 ip_adjacency_t *adj;
1715 adj = adj_get(path->fp_dpo.dpoi_index);
1717 fib_urpf_list_append(urpf, adj->rewrite_header.sw_if_index);
1721 case FIB_PATH_TYPE_DEAG:
1722 case FIB_PATH_TYPE_RECEIVE:
1724 * these path types don't link to an adj
1731 fib_path_contribute_forwarding (fib_node_index_t path_index,
1732 fib_forward_chain_type_t fct,
1737 path = fib_path_get(path_index);
1740 ASSERT(FIB_FORW_CHAIN_TYPE_MPLS_EOS != fct);
1742 FIB_PATH_DBG(path, "contribute");
1745 * The DPO stored in the path was created when the path was resolved.
1746 * This then represents the path's 'native' protocol; IP.
1747 * For all others will need to go find something else.
1749 if (fib_path_proto_to_chain_type(path->fp_nh_proto) == fct)
1751 dpo_copy(dpo, &path->fp_dpo);
1755 switch (path->fp_type)
1757 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1760 case FIB_FORW_CHAIN_TYPE_UNICAST_IP4:
1761 case FIB_FORW_CHAIN_TYPE_UNICAST_IP6:
1762 case FIB_FORW_CHAIN_TYPE_MPLS_EOS:
1763 case FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS:
1764 case FIB_FORW_CHAIN_TYPE_ETHERNET:
1765 case FIB_FORW_CHAIN_TYPE_NSH:
1770 * get a appropriate link type adj.
1772 ai = fib_path_attached_next_hop_get_adj(
1774 fib_forw_chain_type_to_link_type(fct));
1775 dpo_set(dpo, DPO_ADJACENCY,
1776 fib_forw_chain_type_to_dpo_proto(fct), ai);
1781 case FIB_FORW_CHAIN_TYPE_MCAST_IP4:
1782 case FIB_FORW_CHAIN_TYPE_MCAST_IP6:
1786 case FIB_PATH_TYPE_RECURSIVE:
1789 case FIB_FORW_CHAIN_TYPE_MPLS_EOS:
1790 case FIB_FORW_CHAIN_TYPE_UNICAST_IP4:
1791 case FIB_FORW_CHAIN_TYPE_UNICAST_IP6:
1792 case FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS:
1793 fib_path_recursive_adj_update(path, fct, dpo);
1795 case FIB_FORW_CHAIN_TYPE_MCAST_IP4:
1796 case FIB_FORW_CHAIN_TYPE_MCAST_IP6:
1797 case FIB_FORW_CHAIN_TYPE_ETHERNET:
1798 case FIB_FORW_CHAIN_TYPE_NSH:
1803 case FIB_PATH_TYPE_DEAG:
1806 case FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS:
1807 lookup_dpo_add_or_lock_w_table_id(MPLS_FIB_DEFAULT_TABLE_ID,
1809 LOOKUP_INPUT_DST_ADDR,
1810 LOOKUP_TABLE_FROM_CONFIG,
1813 case FIB_FORW_CHAIN_TYPE_UNICAST_IP4:
1814 case FIB_FORW_CHAIN_TYPE_UNICAST_IP6:
1815 case FIB_FORW_CHAIN_TYPE_MPLS_EOS:
1816 dpo_copy(dpo, &path->fp_dpo);
1818 case FIB_FORW_CHAIN_TYPE_MCAST_IP4:
1819 case FIB_FORW_CHAIN_TYPE_MCAST_IP6:
1820 case FIB_FORW_CHAIN_TYPE_ETHERNET:
1821 case FIB_FORW_CHAIN_TYPE_NSH:
1826 case FIB_PATH_TYPE_EXCLUSIVE:
1827 dpo_copy(dpo, &path->exclusive.fp_ex_dpo);
1829 case FIB_PATH_TYPE_ATTACHED:
1832 case FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS:
1833 case FIB_FORW_CHAIN_TYPE_UNICAST_IP4:
1834 case FIB_FORW_CHAIN_TYPE_UNICAST_IP6:
1835 case FIB_FORW_CHAIN_TYPE_MPLS_EOS:
1836 case FIB_FORW_CHAIN_TYPE_ETHERNET:
1837 case FIB_FORW_CHAIN_TYPE_NSH:
1839 case FIB_FORW_CHAIN_TYPE_MCAST_IP4:
1840 case FIB_FORW_CHAIN_TYPE_MCAST_IP6:
1845 * Create the adj needed for sending IP multicast traffic
1847 ai = adj_mcast_add_or_lock(path->fp_nh_proto,
1848 fib_forw_chain_type_to_link_type(fct),
1849 path->attached.fp_interface);
1850 dpo_set(dpo, DPO_ADJACENCY_MCAST,
1851 fib_forw_chain_type_to_dpo_proto(fct),
1858 case FIB_PATH_TYPE_RECEIVE:
1859 case FIB_PATH_TYPE_SPECIAL:
1860 dpo_copy(dpo, &path->fp_dpo);
1866 load_balance_path_t *
1867 fib_path_append_nh_for_multipath_hash (fib_node_index_t path_index,
1868 fib_forward_chain_type_t fct,
1869 load_balance_path_t *hash_key)
1871 load_balance_path_t *mnh;
1874 path = fib_path_get(path_index);
1878 if (fib_path_is_resolved(path_index))
1880 vec_add2(hash_key, mnh, 1);
1882 mnh->path_weight = path->fp_weight;
1883 mnh->path_index = path_index;
1884 fib_path_contribute_forwarding(path_index, fct, &mnh->path_dpo);
1891 fib_path_is_recursive (fib_node_index_t path_index)
1895 path = fib_path_get(path_index);
1897 return (FIB_PATH_TYPE_RECURSIVE == path->fp_type);
1901 fib_path_is_exclusive (fib_node_index_t path_index)
1905 path = fib_path_get(path_index);
1907 return (FIB_PATH_TYPE_EXCLUSIVE == path->fp_type);
1911 fib_path_is_deag (fib_node_index_t path_index)
1915 path = fib_path_get(path_index);
1917 return (FIB_PATH_TYPE_DEAG == path->fp_type);
1921 fib_path_is_resolved (fib_node_index_t path_index)
1925 path = fib_path_get(path_index);
1927 return (dpo_id_is_valid(&path->fp_dpo) &&
1928 (path->fp_oper_flags & FIB_PATH_OPER_FLAG_RESOLVED) &&
1929 !fib_path_is_looped(path_index) &&
1930 !fib_path_is_permanent_drop(path));
1934 fib_path_is_looped (fib_node_index_t path_index)
1938 path = fib_path_get(path_index);
1940 return (path->fp_oper_flags & FIB_PATH_OPER_FLAG_RECURSIVE_LOOP);
1944 fib_path_encode (fib_node_index_t path_list_index,
1945 fib_node_index_t path_index,
1948 fib_route_path_encode_t **api_rpaths = ctx;
1949 fib_route_path_encode_t *api_rpath;
1952 path = fib_path_get(path_index);
1955 vec_add2(*api_rpaths, api_rpath, 1);
1956 api_rpath->rpath.frp_weight = path->fp_weight;
1957 api_rpath->rpath.frp_proto = path->fp_nh_proto;
1958 api_rpath->rpath.frp_sw_if_index = ~0;
1959 api_rpath->dpo = path->exclusive.fp_ex_dpo;
1960 switch (path->fp_type)
1962 case FIB_PATH_TYPE_RECEIVE:
1963 api_rpath->rpath.frp_addr = path->receive.fp_addr;
1964 api_rpath->rpath.frp_sw_if_index = path->receive.fp_interface;
1966 case FIB_PATH_TYPE_ATTACHED:
1967 api_rpath->rpath.frp_sw_if_index = path->attached.fp_interface;
1969 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1970 api_rpath->rpath.frp_sw_if_index = path->attached_next_hop.fp_interface;
1971 api_rpath->rpath.frp_addr = path->attached_next_hop.fp_nh;
1973 case FIB_PATH_TYPE_SPECIAL:
1975 case FIB_PATH_TYPE_DEAG:
1977 case FIB_PATH_TYPE_RECURSIVE:
1978 api_rpath->rpath.frp_addr = path->recursive.fp_nh.fp_ip;
1987 fib_path_get_proto (fib_node_index_t path_index)
1991 path = fib_path_get(path_index);
1993 return (path->fp_nh_proto);
1997 fib_path_module_init (void)
1999 fib_node_register_type (FIB_NODE_TYPE_PATH, &fib_path_vft);
2002 static clib_error_t *
2003 show_fib_path_command (vlib_main_t * vm,
2004 unformat_input_t * input,
2005 vlib_cli_command_t * cmd)
2007 fib_node_index_t pi;
2010 if (unformat (input, "%d", &pi))
2013 * show one in detail
2015 if (!pool_is_free_index(fib_path_pool, pi))
2017 path = fib_path_get(pi);
2018 u8 *s = fib_path_format(pi, NULL);
2019 s = format(s, "children:");
2020 s = fib_node_children_format(path->fp_node.fn_children, s);
2021 vlib_cli_output (vm, "%s", s);
2026 vlib_cli_output (vm, "path %d invalid", pi);
2031 vlib_cli_output (vm, "FIB Paths");
2032 pool_foreach(path, fib_path_pool,
2034 vlib_cli_output (vm, "%U", format_fib_path, path);
2041 VLIB_CLI_COMMAND (show_fib_path, static) = {
2042 .path = "show fib paths",
2043 .function = show_fib_path_command,
2044 .short_help = "show fib paths",