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>
35 #include <vnet/fib/mpls_fib.h>
38 * Enurmeration of path types
40 typedef enum fib_path_type_t_ {
42 * Marker. Add new types after this one.
44 FIB_PATH_TYPE_FIRST = 0,
46 * Attached-nexthop. An interface and a nexthop are known.
48 FIB_PATH_TYPE_ATTACHED_NEXT_HOP = FIB_PATH_TYPE_FIRST,
50 * attached. Only the interface is known.
52 FIB_PATH_TYPE_ATTACHED,
54 * recursive. Only the next-hop is known.
56 FIB_PATH_TYPE_RECURSIVE,
58 * special. nothing is known. so we drop.
60 FIB_PATH_TYPE_SPECIAL,
62 * exclusive. user provided adj.
64 FIB_PATH_TYPE_EXCLUSIVE,
66 * deag. Link to a lookup adj in the next table
70 * receive. it's for-us.
72 FIB_PATH_TYPE_RECEIVE,
74 * Marker. Add new types before this one, then update it.
76 FIB_PATH_TYPE_LAST = FIB_PATH_TYPE_RECEIVE,
77 } __attribute__ ((packed)) fib_path_type_t;
80 * The maximum number of path_types
82 #define FIB_PATH_TYPE_MAX (FIB_PATH_TYPE_LAST + 1)
84 #define FIB_PATH_TYPES { \
85 [FIB_PATH_TYPE_ATTACHED_NEXT_HOP] = "attached-nexthop", \
86 [FIB_PATH_TYPE_ATTACHED] = "attached", \
87 [FIB_PATH_TYPE_RECURSIVE] = "recursive", \
88 [FIB_PATH_TYPE_SPECIAL] = "special", \
89 [FIB_PATH_TYPE_EXCLUSIVE] = "exclusive", \
90 [FIB_PATH_TYPE_DEAG] = "deag", \
91 [FIB_PATH_TYPE_RECEIVE] = "receive", \
94 #define FOR_EACH_FIB_PATH_TYPE(_item) \
95 for (_item = FIB_PATH_TYPE_FIRST; _item <= FIB_PATH_TYPE_LAST; _item++)
98 * Enurmeration of path operational (i.e. derived) attributes
100 typedef enum fib_path_oper_attribute_t_ {
102 * Marker. Add new types after this one.
104 FIB_PATH_OPER_ATTRIBUTE_FIRST = 0,
106 * The path forms part of a recursive loop.
108 FIB_PATH_OPER_ATTRIBUTE_RECURSIVE_LOOP = FIB_PATH_OPER_ATTRIBUTE_FIRST,
110 * The path is resolved
112 FIB_PATH_OPER_ATTRIBUTE_RESOLVED,
114 * The path is attached, despite what the next-hop may say.
116 FIB_PATH_OPER_ATTRIBUTE_ATTACHED,
118 * The path has become a permanent drop.
120 FIB_PATH_OPER_ATTRIBUTE_DROP,
122 * Marker. Add new types before this one, then update it.
124 FIB_PATH_OPER_ATTRIBUTE_LAST = FIB_PATH_OPER_ATTRIBUTE_DROP,
125 } __attribute__ ((packed)) fib_path_oper_attribute_t;
128 * The maximum number of path operational attributes
130 #define FIB_PATH_OPER_ATTRIBUTE_MAX (FIB_PATH_OPER_ATTRIBUTE_LAST + 1)
132 #define FIB_PATH_OPER_ATTRIBUTES { \
133 [FIB_PATH_OPER_ATTRIBUTE_RECURSIVE_LOOP] = "recursive-loop", \
134 [FIB_PATH_OPER_ATTRIBUTE_RESOLVED] = "resolved", \
135 [FIB_PATH_OPER_ATTRIBUTE_DROP] = "drop", \
138 #define FOR_EACH_FIB_PATH_OPER_ATTRIBUTE(_item) \
139 for (_item = FIB_PATH_OPER_ATTRIBUTE_FIRST; \
140 _item <= FIB_PATH_OPER_ATTRIBUTE_LAST; \
144 * Path flags from the attributes
146 typedef enum fib_path_oper_flags_t_ {
147 FIB_PATH_OPER_FLAG_NONE = 0,
148 FIB_PATH_OPER_FLAG_RECURSIVE_LOOP = (1 << FIB_PATH_OPER_ATTRIBUTE_RECURSIVE_LOOP),
149 FIB_PATH_OPER_FLAG_DROP = (1 << FIB_PATH_OPER_ATTRIBUTE_DROP),
150 FIB_PATH_OPER_FLAG_RESOLVED = (1 << FIB_PATH_OPER_ATTRIBUTE_RESOLVED),
151 FIB_PATH_OPER_FLAG_ATTACHED = (1 << FIB_PATH_OPER_ATTRIBUTE_ATTACHED),
152 } __attribute__ ((packed)) fib_path_oper_flags_t;
157 typedef struct fib_path_t_ {
159 * A path is a node in the FIB graph.
164 * The index of the path-list to which this path belongs
169 * This marks the start of the memory area used to hash
172 STRUCT_MARK(path_hash_start);
175 * Configuration Flags
177 fib_path_cfg_flags_t fp_cfg_flags;
180 * The type of the path. This is the selector for the union
182 fib_path_type_t fp_type;
185 * The protocol of the next-hop, i.e. the address family of the
186 * next-hop's address. We can't derive this from the address itself
187 * since the address can be all zeros
189 fib_protocol_t fp_nh_proto;
192 * UCMP [unnormalised] weigt
197 * per-type union of the data required to resolve the path
204 ip46_address_t fp_nh;
222 ip46_address_t fp_ip;
224 * The local label to resolve through.
226 mpls_label_t fp_local_label;
229 * The FIB table index in which to find the next-hop.
230 * This needs to be fixed. We should lookup the adjacencies in
231 * a separate table of adjacencies, rather than from the FIB.
232 * Two reasons I can think of:
234 * int ip addr Gig0 10.0.0.1/24
235 * ip route 10.0.0.2/32 via Gig1 192.168.1.2
236 * ip route 1.1.1.1/32 via Gig0 10.0.0.2
237 * this is perfectly valid.
238 * Packets addressed to 10.0.0.2 should be sent via Gig1.
239 * Packets address to 1.1.1.1 should be sent via Gig0.
240 * when we perform the adj resolution from the FIB for the path
241 * "via Gig0 10.0.0.2" the lookup will result in the route via Gig1
242 * and so we will pick up the adj via Gig1 - which was not what the
244 * - we can only return link-type IPv4 and so not the link-type MPLS.
245 * more on this in a later commit.
247 * The table ID should only belong to a recursive path and indicate
248 * which FIB should be used to resolve the next-hop.
250 fib_node_index_t fp_tbl_id;
254 * The FIB index in which to perfom the next lookup
256 fib_node_index_t fp_tbl_id;
262 * The user provided 'exclusive' DPO
268 * The interface on which the local address is configured
274 ip46_address_t fp_addr;
277 STRUCT_MARK(path_hash_end);
280 * Memebers in this last section represent information that is
281 * dervied during resolution. It should not be copied to new paths
288 fib_path_oper_flags_t fp_oper_flags;
291 * the resolving via fib. not part of the union, since it it not part
292 * of the path's hash.
294 fib_node_index_t fp_via_fib;
297 * The Data-path objects through which this path resolves for IP.
302 * the index of this path in the parent's child list.
308 * Array of strings/names for the path types and attributes
310 static const char *fib_path_type_names[] = FIB_PATH_TYPES;
311 static const char *fib_path_oper_attribute_names[] = FIB_PATH_OPER_ATTRIBUTES;
312 static const char *fib_path_cfg_attribute_names[] = FIB_PATH_CFG_ATTRIBUTES;
315 * The memory pool from which we allocate all the paths
317 static fib_path_t *fib_path_pool;
323 #define FIB_PATH_DBG(_p, _fmt, _args...) \
326 _tmp = fib_path_format(fib_path_get_index(_p), _tmp); \
327 clib_warning("path:[%d:%s]:" _fmt, \
328 fib_path_get_index(_p), _tmp, \
333 #define FIB_PATH_DBG(_p, _fmt, _args...)
337 fib_path_get (fib_node_index_t index)
339 return (pool_elt_at_index(fib_path_pool, index));
342 static fib_node_index_t
343 fib_path_get_index (fib_path_t *path)
345 return (path - fib_path_pool);
349 fib_path_get_node (fib_node_index_t index)
351 return ((fib_node_t*)fib_path_get(index));
355 fib_path_from_fib_node (fib_node_t *node)
358 ASSERT(FIB_NODE_TYPE_PATH == node->fn_type);
360 return ((fib_path_t*)node);
364 format_fib_path (u8 * s, va_list * args)
366 fib_path_t *path = va_arg (*args, fib_path_t *);
367 vnet_main_t * vnm = vnet_get_main();
368 fib_path_oper_attribute_t oattr;
369 fib_path_cfg_attribute_t cattr;
371 s = format (s, " index:%d ", fib_path_get_index(path));
372 s = format (s, "pl-index:%d ", path->fp_pl_index);
373 s = format (s, "%U ", format_fib_protocol, path->fp_nh_proto);
374 s = format (s, "weight=%d ", path->fp_weight);
375 s = format (s, "%s: ", fib_path_type_names[path->fp_type]);
376 if (FIB_PATH_OPER_FLAG_NONE != path->fp_oper_flags) {
377 s = format(s, " oper-flags:");
378 FOR_EACH_FIB_PATH_OPER_ATTRIBUTE(oattr) {
379 if ((1<<oattr) & path->fp_oper_flags) {
380 s = format (s, "%s,", fib_path_oper_attribute_names[oattr]);
384 if (FIB_PATH_CFG_FLAG_NONE != path->fp_cfg_flags) {
385 s = format(s, " cfg-flags:");
386 FOR_EACH_FIB_PATH_CFG_ATTRIBUTE(cattr) {
387 if ((1<<cattr) & path->fp_cfg_flags) {
388 s = format (s, "%s,", fib_path_cfg_attribute_names[cattr]);
392 s = format(s, "\n ");
394 switch (path->fp_type)
396 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
397 s = format (s, "%U", format_ip46_address,
398 &path->attached_next_hop.fp_nh,
400 if (path->fp_oper_flags & FIB_PATH_OPER_FLAG_DROP)
402 s = format (s, " if_index:%d", path->attached_next_hop.fp_interface);
406 s = format (s, " %U",
407 format_vnet_sw_interface_name,
409 vnet_get_sw_interface(
411 path->attached_next_hop.fp_interface));
412 if (vnet_sw_interface_is_p2p(vnet_get_main(),
413 path->attached_next_hop.fp_interface))
415 s = format (s, " (p2p)");
418 if (!dpo_id_is_valid(&path->fp_dpo))
420 s = format(s, "\n unresolved");
424 s = format(s, "\n %U",
429 case FIB_PATH_TYPE_ATTACHED:
430 if (path->fp_oper_flags & FIB_PATH_OPER_FLAG_DROP)
432 s = format (s, " if_index:%d", path->attached_next_hop.fp_interface);
436 s = format (s, " %U",
437 format_vnet_sw_interface_name,
439 vnet_get_sw_interface(
441 path->attached.fp_interface));
444 case FIB_PATH_TYPE_RECURSIVE:
445 if (FIB_PROTOCOL_MPLS == path->fp_nh_proto)
447 s = format (s, "via %U",
448 format_mpls_unicast_label,
449 path->recursive.fp_nh.fp_local_label);
453 s = format (s, "via %U",
455 &path->recursive.fp_nh.fp_ip,
458 s = format (s, " in fib:%d",
459 path->recursive.fp_tbl_id,
461 s = format (s, " via-fib:%d", path->fp_via_fib);
462 s = format (s, " via-dpo:[%U:%d]",
463 format_dpo_type, path->fp_dpo.dpoi_type,
464 path->fp_dpo.dpoi_index);
467 case FIB_PATH_TYPE_RECEIVE:
468 case FIB_PATH_TYPE_SPECIAL:
469 case FIB_PATH_TYPE_DEAG:
470 case FIB_PATH_TYPE_EXCLUSIVE:
471 if (dpo_id_is_valid(&path->fp_dpo))
473 s = format(s, "%U", format_dpo_id,
482 fib_path_format (fib_node_index_t pi, u8 *s)
486 path = fib_path_get(pi);
487 ASSERT(NULL != path);
489 return (format (s, "%U", format_fib_path, path));
493 fib_path_adj_format (fib_node_index_t pi,
499 path = fib_path_get(pi);
500 ASSERT(NULL != path);
502 if (!dpo_id_is_valid(&path->fp_dpo))
504 s = format(s, " unresolved");
508 s = format(s, "%U", format_dpo_id,
516 * fib_path_last_lock_gone
518 * We don't share paths, we share path lists, so the [un]lock functions
522 fib_path_last_lock_gone (fib_node_t *node)
527 static const adj_index_t
528 fib_path_attached_next_hop_get_adj (fib_path_t *path,
531 if (vnet_sw_interface_is_p2p(vnet_get_main(),
532 path->attached_next_hop.fp_interface))
535 * if the interface is p2p then the adj for the specific
536 * neighbour on that link will never exist. on p2p links
537 * the subnet address (the attached route) links to the
538 * auto-adj (see below), we want that adj here too.
540 return (adj_nbr_add_or_lock(path->fp_nh_proto,
543 path->attached_next_hop.fp_interface));
547 return (adj_nbr_add_or_lock(path->fp_nh_proto,
549 &path->attached_next_hop.fp_nh,
550 path->attached_next_hop.fp_interface));
555 fib_path_attached_next_hop_set (fib_path_t *path)
558 * resolve directly via the adjacnecy discribed by the
559 * interface and next-hop
561 if (!vnet_sw_interface_is_admin_up(vnet_get_main(),
562 path->attached_next_hop.fp_interface))
564 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
567 dpo_set(&path->fp_dpo,
569 fib_proto_to_dpo(path->fp_nh_proto),
570 fib_path_attached_next_hop_get_adj(
572 fib_proto_to_link(path->fp_nh_proto)));
575 * become a child of the adjacency so we receive updates
576 * when its rewrite changes
578 path->fp_sibling = adj_child_add(path->fp_dpo.dpoi_index,
580 fib_path_get_index(path));
584 * create of update the paths recursive adj
587 fib_path_recursive_adj_update (fib_path_t *path,
588 fib_forward_chain_type_t fct,
591 dpo_id_t via_dpo = DPO_INVALID;
594 * get the DPO to resolve through from the via-entry
596 fib_entry_contribute_forwarding(path->fp_via_fib,
602 * hope for the best - clear if restrictions apply.
604 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RESOLVED;
607 * Validate any recursion constraints and over-ride the via
610 if (path->fp_oper_flags & FIB_PATH_OPER_FLAG_RECURSIVE_LOOP)
612 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
613 dpo_copy(&via_dpo, drop_dpo_get(fib_proto_to_dpo(path->fp_nh_proto)));
615 else if (path->fp_cfg_flags & FIB_PATH_CFG_FLAG_RESOLVE_HOST)
618 * the via FIB must be a host route.
619 * note the via FIB just added will always be a host route
620 * since it is an RR source added host route. So what we need to
621 * check is whether the route has other sources. If it does then
622 * some other source has added it as a host route. If it doesn't
623 * then it was added only here and inherits forwarding from a cover.
624 * the cover is not a host route.
625 * The RR source is the lowest priority source, so we check if it
626 * is the best. if it is there are no other sources.
628 if (fib_entry_get_best_source(path->fp_via_fib) >= FIB_SOURCE_RR)
630 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
631 dpo_copy(&via_dpo, drop_dpo_get(fib_proto_to_dpo(path->fp_nh_proto)));
634 * PIC edge trigger. let the load-balance maps know
636 load_balance_map_path_state_change(fib_path_get_index(path));
639 else if (path->fp_cfg_flags & FIB_PATH_CFG_FLAG_RESOLVE_ATTACHED)
642 * RR source entries inherit the flags from the cover, so
643 * we can check the via directly
645 if (!(FIB_ENTRY_FLAG_ATTACHED & fib_entry_get_flags(path->fp_via_fib)))
647 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
648 dpo_copy(&via_dpo, drop_dpo_get(fib_proto_to_dpo(path->fp_nh_proto)));
651 * PIC edge trigger. let the load-balance maps know
653 load_balance_map_path_state_change(fib_path_get_index(path));
658 * update the path's contributed DPO
660 dpo_copy(dpo, &via_dpo);
662 FIB_PATH_DBG(path, "recursive update: %U",
663 fib_get_lookup_main(path->fp_nh_proto),
670 * fib_path_is_permanent_drop
672 * Return !0 if the path is configured to permanently drop,
673 * despite other attributes.
676 fib_path_is_permanent_drop (fib_path_t *path)
678 return ((path->fp_cfg_flags & FIB_PATH_CFG_FLAG_DROP) ||
679 (path->fp_oper_flags & FIB_PATH_OPER_FLAG_DROP));
685 * Remove our dependency on the resolution target
688 fib_path_unresolve (fib_path_t *path)
691 * the forced drop path does not need unresolving
693 if (fib_path_is_permanent_drop(path))
698 switch (path->fp_type)
700 case FIB_PATH_TYPE_RECURSIVE:
701 if (FIB_NODE_INDEX_INVALID != path->fp_via_fib)
705 fib_entry_get_prefix(path->fp_via_fib, &pfx);
706 fib_entry_child_remove(path->fp_via_fib,
708 fib_table_entry_special_remove(path->recursive.fp_tbl_id,
711 path->fp_via_fib = FIB_NODE_INDEX_INVALID;
714 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
715 case FIB_PATH_TYPE_ATTACHED:
716 adj_child_remove(path->fp_dpo.dpoi_index,
718 adj_unlock(path->fp_dpo.dpoi_index);
720 case FIB_PATH_TYPE_EXCLUSIVE:
721 dpo_reset(&path->exclusive.fp_ex_dpo);
723 case FIB_PATH_TYPE_SPECIAL:
724 case FIB_PATH_TYPE_RECEIVE:
725 case FIB_PATH_TYPE_DEAG:
727 * these hold only the path's DPO, which is reset below.
733 * release the adj we were holding and pick up the
736 dpo_reset(&path->fp_dpo);
737 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
742 static fib_forward_chain_type_t
743 fib_path_proto_to_chain_type (fib_protocol_t proto)
747 case FIB_PROTOCOL_IP4:
748 return (FIB_FORW_CHAIN_TYPE_UNICAST_IP4);
749 case FIB_PROTOCOL_IP6:
750 return (FIB_FORW_CHAIN_TYPE_UNICAST_IP6);
751 case FIB_PROTOCOL_MPLS:
752 return (FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS);
754 return (FIB_FORW_CHAIN_TYPE_UNICAST_IP4);
758 * fib_path_back_walk_notify
760 * A back walk has reach this path.
762 static fib_node_back_walk_rc_t
763 fib_path_back_walk_notify (fib_node_t *node,
764 fib_node_back_walk_ctx_t *ctx)
768 path = fib_path_from_fib_node(node);
770 switch (path->fp_type)
772 case FIB_PATH_TYPE_RECURSIVE:
773 if (FIB_NODE_BW_REASON_FLAG_EVALUATE & ctx->fnbw_reason)
776 * modify the recursive adjacency to use the new forwarding
778 * this update is visible to packets in flight in the DP.
780 fib_path_recursive_adj_update(
782 fib_path_proto_to_chain_type(path->fp_nh_proto),
785 if ((FIB_NODE_BW_REASON_FLAG_ADJ_UPDATE & ctx->fnbw_reason) ||
786 (FIB_NODE_BW_REASON_FLAG_ADJ_DOWN & ctx->fnbw_reason))
789 * ADJ updates (complete<->incomplete) do not need to propagate to
791 * The only reason its needed as far back as here, is that the adj
792 * and the incomplete adj are a different DPO type, so the LBs need
794 * If this walk was quashed in the fib_entry, then any non-fib_path
795 * children (like tunnels that collapse out the LB when they stack)
796 * would not see the update.
798 return (FIB_NODE_BACK_WALK_CONTINUE);
801 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
804 * ADJ_UPDATE backwalk pass silently through here and up to
805 * the path-list when the multipath adj collapse occurs.
806 * The reason we do this is that the assumtption is that VPP
807 * runs in an environment where the Control-Plane is remote
808 * and hence reacts slowly to link up down. In order to remove
809 * this down link from the ECMP set quickly, we back-walk.
810 * VPP also has dedicated CPUs, so we are not stealing resources
811 * from the CP to do so.
813 if (FIB_NODE_BW_REASON_FLAG_INTERFACE_UP & ctx->fnbw_reason)
815 if (path->fp_oper_flags & FIB_PATH_OPER_FLAG_RESOLVED)
818 * alreday resolved. no need to walk back again
820 return (FIB_NODE_BACK_WALK_CONTINUE);
822 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RESOLVED;
824 if (FIB_NODE_BW_REASON_FLAG_INTERFACE_DOWN & ctx->fnbw_reason)
826 if (!(path->fp_oper_flags & FIB_PATH_OPER_FLAG_RESOLVED))
829 * alreday unresolved. no need to walk back again
831 return (FIB_NODE_BACK_WALK_CONTINUE);
833 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
835 if (FIB_NODE_BW_REASON_FLAG_INTERFACE_DELETE & ctx->fnbw_reason)
838 * The interface this path resolves through has been deleted.
839 * This will leave the path in a permanent drop state. The route
840 * needs to be removed and readded (and hence the path-list deleted)
841 * before it can forward again.
843 fib_path_unresolve(path);
844 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_DROP;
846 if (FIB_NODE_BW_REASON_FLAG_ADJ_UPDATE & ctx->fnbw_reason)
849 * restack the DPO to pick up the correct DPO sub-type
854 if_is_up = vnet_sw_interface_is_admin_up(
856 path->attached_next_hop.fp_interface);
860 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RESOLVED;
863 ai = fib_path_attached_next_hop_get_adj(
865 fib_proto_to_link(path->fp_nh_proto));
867 dpo_set(&path->fp_dpo, DPO_ADJACENCY,
868 fib_proto_to_dpo(path->fp_nh_proto),
875 * If the interface is not up there is no reason to walk
876 * back to children. if we did they would only evalute
877 * that this path is unresolved and hence it would
878 * not contribute the adjacency - so it would be wasted
881 return (FIB_NODE_BACK_WALK_CONTINUE);
884 if (FIB_NODE_BW_REASON_FLAG_ADJ_DOWN & ctx->fnbw_reason)
886 if (!(path->fp_oper_flags & FIB_PATH_OPER_FLAG_RESOLVED))
889 * alreday unresolved. no need to walk back again
891 return (FIB_NODE_BACK_WALK_CONTINUE);
894 * the adj has gone down. the path is no longer resolved.
896 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
899 case FIB_PATH_TYPE_ATTACHED:
901 * FIXME; this could schedule a lower priority walk, since attached
902 * routes are not usually in ECMP configurations so the backwalk to
903 * the FIB entry does not need to be high priority
905 if (FIB_NODE_BW_REASON_FLAG_INTERFACE_UP & ctx->fnbw_reason)
907 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RESOLVED;
909 if (FIB_NODE_BW_REASON_FLAG_INTERFACE_DOWN & ctx->fnbw_reason)
911 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
913 if (FIB_NODE_BW_REASON_FLAG_INTERFACE_DELETE & ctx->fnbw_reason)
915 fib_path_unresolve(path);
916 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_DROP;
919 case FIB_PATH_TYPE_DEAG:
921 * FIXME When VRF delete is allowed this will need a poke.
923 case FIB_PATH_TYPE_SPECIAL:
924 case FIB_PATH_TYPE_RECEIVE:
925 case FIB_PATH_TYPE_EXCLUSIVE:
927 * these path types have no parents. so to be
928 * walked from one is unexpected.
935 * propagate the backwalk further to the path-list
937 fib_path_list_back_walk(path->fp_pl_index, ctx);
939 return (FIB_NODE_BACK_WALK_CONTINUE);
943 fib_path_memory_show (void)
945 fib_show_memory_usage("Path",
946 pool_elts(fib_path_pool),
947 pool_len(fib_path_pool),
952 * The FIB path's graph node virtual function table
954 static const fib_node_vft_t fib_path_vft = {
955 .fnv_get = fib_path_get_node,
956 .fnv_last_lock = fib_path_last_lock_gone,
957 .fnv_back_walk = fib_path_back_walk_notify,
958 .fnv_mem_show = fib_path_memory_show,
961 static fib_path_cfg_flags_t
962 fib_path_route_flags_to_cfg_flags (const fib_route_path_t *rpath)
964 fib_path_cfg_flags_t cfg_flags = FIB_PATH_CFG_FLAG_NONE;
966 if (rpath->frp_flags & FIB_ROUTE_PATH_RESOLVE_VIA_HOST)
967 cfg_flags |= FIB_PATH_CFG_FLAG_RESOLVE_HOST;
968 if (rpath->frp_flags & FIB_ROUTE_PATH_RESOLVE_VIA_ATTACHED)
969 cfg_flags |= FIB_PATH_CFG_FLAG_RESOLVE_ATTACHED;
970 if (rpath->frp_flags & FIB_ROUTE_PATH_LOCAL)
971 cfg_flags |= FIB_PATH_CFG_FLAG_LOCAL;
972 if (rpath->frp_flags & FIB_ROUTE_PATH_ATTACHED)
973 cfg_flags |= FIB_PATH_CFG_FLAG_ATTACHED;
981 * Create and initialise a new path object.
982 * return the index of the path.
985 fib_path_create (fib_node_index_t pl_index,
986 fib_protocol_t nh_proto,
987 fib_path_cfg_flags_t flags,
988 const fib_route_path_t *rpath)
992 pool_get(fib_path_pool, path);
993 memset(path, 0, sizeof(*path));
995 fib_node_init(&path->fp_node,
998 dpo_reset(&path->fp_dpo);
999 path->fp_pl_index = pl_index;
1000 path->fp_nh_proto = nh_proto;
1001 path->fp_via_fib = FIB_NODE_INDEX_INVALID;
1002 path->fp_weight = rpath->frp_weight;
1003 if (0 == path->fp_weight)
1006 * a weight of 0 is a meaningless value. We could either reject it, and thus force
1007 * clients to always use 1, or we can accept it and fixup approrpiately.
1009 path->fp_weight = 1;
1011 path->fp_cfg_flags = flags;
1012 path->fp_cfg_flags |= fib_path_route_flags_to_cfg_flags(rpath);
1015 * deduce the path's tpye from the parementers and save what is needed.
1017 if (path->fp_cfg_flags & FIB_PATH_CFG_FLAG_LOCAL)
1019 path->fp_type = FIB_PATH_TYPE_RECEIVE;
1020 path->receive.fp_interface = rpath->frp_sw_if_index;
1021 path->receive.fp_addr = rpath->frp_addr;
1023 else if (~0 != rpath->frp_sw_if_index)
1025 if (ip46_address_is_zero(&rpath->frp_addr))
1027 path->fp_type = FIB_PATH_TYPE_ATTACHED;
1028 path->attached.fp_interface = rpath->frp_sw_if_index;
1032 path->fp_type = FIB_PATH_TYPE_ATTACHED_NEXT_HOP;
1033 path->attached_next_hop.fp_interface = rpath->frp_sw_if_index;
1034 path->attached_next_hop.fp_nh = rpath->frp_addr;
1039 if (ip46_address_is_zero(&rpath->frp_addr))
1041 if (~0 == rpath->frp_fib_index)
1043 path->fp_type = FIB_PATH_TYPE_SPECIAL;
1047 path->fp_type = FIB_PATH_TYPE_DEAG;
1048 path->deag.fp_tbl_id = rpath->frp_fib_index;
1053 path->fp_type = FIB_PATH_TYPE_RECURSIVE;
1054 if (FIB_PROTOCOL_MPLS == path->fp_nh_proto)
1056 path->recursive.fp_nh.fp_local_label = rpath->frp_local_label;
1060 path->recursive.fp_nh.fp_ip = rpath->frp_addr;
1062 path->recursive.fp_tbl_id = rpath->frp_fib_index;
1066 FIB_PATH_DBG(path, "create");
1068 return (fib_path_get_index(path));
1072 * fib_path_create_special
1074 * Create and initialise a new path object.
1075 * return the index of the path.
1078 fib_path_create_special (fib_node_index_t pl_index,
1079 fib_protocol_t nh_proto,
1080 fib_path_cfg_flags_t flags,
1081 const dpo_id_t *dpo)
1085 pool_get(fib_path_pool, path);
1086 memset(path, 0, sizeof(*path));
1088 fib_node_init(&path->fp_node,
1089 FIB_NODE_TYPE_PATH);
1090 dpo_reset(&path->fp_dpo);
1092 path->fp_pl_index = pl_index;
1093 path->fp_weight = 1;
1094 path->fp_nh_proto = nh_proto;
1095 path->fp_via_fib = FIB_NODE_INDEX_INVALID;
1096 path->fp_cfg_flags = flags;
1098 if (FIB_PATH_CFG_FLAG_DROP & flags)
1100 path->fp_type = FIB_PATH_TYPE_SPECIAL;
1102 else if (FIB_PATH_CFG_FLAG_LOCAL & flags)
1104 path->fp_type = FIB_PATH_TYPE_RECEIVE;
1105 path->attached.fp_interface = FIB_NODE_INDEX_INVALID;
1109 path->fp_type = FIB_PATH_TYPE_EXCLUSIVE;
1110 ASSERT(NULL != dpo);
1111 dpo_copy(&path->exclusive.fp_ex_dpo, dpo);
1114 return (fib_path_get_index(path));
1120 * Copy a path. return index of new path.
1123 fib_path_copy (fib_node_index_t path_index,
1124 fib_node_index_t path_list_index)
1126 fib_path_t *path, *orig_path;
1128 pool_get(fib_path_pool, path);
1130 orig_path = fib_path_get(path_index);
1131 ASSERT(NULL != orig_path);
1133 memcpy(path, orig_path, sizeof(*path));
1135 FIB_PATH_DBG(path, "create-copy:%d", path_index);
1138 * reset the dynamic section
1140 fib_node_init(&path->fp_node, FIB_NODE_TYPE_PATH);
1141 path->fp_oper_flags = FIB_PATH_OPER_FLAG_NONE;
1142 path->fp_pl_index = path_list_index;
1143 path->fp_via_fib = FIB_NODE_INDEX_INVALID;
1144 memset(&path->fp_dpo, 0, sizeof(path->fp_dpo));
1145 dpo_reset(&path->fp_dpo);
1147 return (fib_path_get_index(path));
1153 * destroy a path that is no longer required
1156 fib_path_destroy (fib_node_index_t path_index)
1160 path = fib_path_get(path_index);
1162 ASSERT(NULL != path);
1163 FIB_PATH_DBG(path, "destroy");
1165 fib_path_unresolve(path);
1167 fib_node_deinit(&path->fp_node);
1168 pool_put(fib_path_pool, path);
1174 * destroy a path that is no longer required
1177 fib_path_hash (fib_node_index_t path_index)
1181 path = fib_path_get(path_index);
1183 return (hash_memory(STRUCT_MARK_PTR(path, path_hash_start),
1184 (STRUCT_OFFSET_OF(fib_path_t, path_hash_end) -
1185 STRUCT_OFFSET_OF(fib_path_t, path_hash_start)),
1192 * Compare two paths for equivalence.
1195 fib_path_cmp_i (const fib_path_t *path1,
1196 const fib_path_t *path2)
1203 * paths of different types and protocol are not equal.
1204 * different weights only are the same path.
1206 if (path1->fp_type != path2->fp_type)
1208 res = (path1->fp_type - path2->fp_type);
1210 else if (path1->fp_nh_proto != path2->fp_nh_proto)
1212 res = (path1->fp_nh_proto - path2->fp_nh_proto);
1217 * both paths are of the same type.
1218 * consider each type and its attributes in turn.
1220 switch (path1->fp_type)
1222 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1223 res = ip46_address_cmp(&path1->attached_next_hop.fp_nh,
1224 &path2->attached_next_hop.fp_nh);
1226 res = vnet_sw_interface_compare(
1228 path1->attached_next_hop.fp_interface,
1229 path2->attached_next_hop.fp_interface);
1232 case FIB_PATH_TYPE_ATTACHED:
1233 res = vnet_sw_interface_compare(
1235 path1->attached.fp_interface,
1236 path2->attached.fp_interface);
1238 case FIB_PATH_TYPE_RECURSIVE:
1239 res = ip46_address_cmp(&path1->recursive.fp_nh,
1240 &path2->recursive.fp_nh);
1244 res = (path1->recursive.fp_tbl_id - path2->recursive.fp_tbl_id);
1247 case FIB_PATH_TYPE_DEAG:
1248 res = (path1->deag.fp_tbl_id - path2->deag.fp_tbl_id);
1250 case FIB_PATH_TYPE_SPECIAL:
1251 case FIB_PATH_TYPE_RECEIVE:
1252 case FIB_PATH_TYPE_EXCLUSIVE:
1261 * fib_path_cmp_for_sort
1263 * Compare two paths for equivalence. Used during path sorting.
1264 * As usual 0 means equal.
1267 fib_path_cmp_for_sort (void * v1,
1270 fib_node_index_t *pi1 = v1, *pi2 = v2;
1271 fib_path_t *path1, *path2;
1273 path1 = fib_path_get(*pi1);
1274 path2 = fib_path_get(*pi2);
1276 return (fib_path_cmp_i(path1, path2));
1282 * Compare two paths for equivalence.
1285 fib_path_cmp (fib_node_index_t pi1,
1286 fib_node_index_t pi2)
1288 fib_path_t *path1, *path2;
1290 path1 = fib_path_get(pi1);
1291 path2 = fib_path_get(pi2);
1293 return (fib_path_cmp_i(path1, path2));
1297 fib_path_cmp_w_route_path (fib_node_index_t path_index,
1298 const fib_route_path_t *rpath)
1303 path = fib_path_get(path_index);
1307 if (path->fp_weight != rpath->frp_weight)
1309 res = (path->fp_weight - rpath->frp_weight);
1314 * both paths are of the same type.
1315 * consider each type and its attributes in turn.
1317 switch (path->fp_type)
1319 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1320 res = ip46_address_cmp(&path->attached_next_hop.fp_nh,
1324 res = vnet_sw_interface_compare(
1326 path->attached_next_hop.fp_interface,
1327 rpath->frp_sw_if_index);
1330 case FIB_PATH_TYPE_ATTACHED:
1331 res = vnet_sw_interface_compare(
1333 path->attached.fp_interface,
1334 rpath->frp_sw_if_index);
1336 case FIB_PATH_TYPE_RECURSIVE:
1337 if (FIB_PROTOCOL_MPLS == path->fp_nh_proto)
1339 res = path->recursive.fp_nh.fp_local_label - rpath->frp_local_label;
1343 res = ip46_address_cmp(&path->recursive.fp_nh.fp_ip,
1349 res = (path->recursive.fp_tbl_id - rpath->frp_fib_index);
1352 case FIB_PATH_TYPE_DEAG:
1353 res = (path->deag.fp_tbl_id - rpath->frp_fib_index);
1355 case FIB_PATH_TYPE_SPECIAL:
1356 case FIB_PATH_TYPE_RECEIVE:
1357 case FIB_PATH_TYPE_EXCLUSIVE:
1366 * fib_path_recursive_loop_detect
1368 * A forward walk of the FIB object graph to detect for a cycle/loop. This
1369 * walk is initiated when an entry is linking to a new path list or from an old.
1370 * The entry vector passed contains all the FIB entrys that are children of this
1371 * path (it is all the entries encountered on the walk so far). If this vector
1372 * contains the entry this path resolve via, then a loop is about to form.
1373 * The loop must be allowed to form, since we need the dependencies in place
1374 * so that we can track when the loop breaks.
1375 * However, we MUST not produce a loop in the forwarding graph (else packets
1376 * would loop around the switch path until the loop breaks), so we mark recursive
1377 * paths as looped so that they do not contribute forwarding information.
1378 * By marking the path as looped, an etry such as;
1380 * via a.a.a.a (looped)
1381 * via b.b.b.b (not looped)
1382 * can still forward using the info provided by b.b.b.b only
1385 fib_path_recursive_loop_detect (fib_node_index_t path_index,
1386 fib_node_index_t **entry_indicies)
1390 path = fib_path_get(path_index);
1393 * the forced drop path is never looped, cos it is never resolved.
1395 if (fib_path_is_permanent_drop(path))
1400 switch (path->fp_type)
1402 case FIB_PATH_TYPE_RECURSIVE:
1404 fib_node_index_t *entry_index, *entries;
1406 entries = *entry_indicies;
1408 vec_foreach(entry_index, entries) {
1409 if (*entry_index == path->fp_via_fib)
1412 * the entry that is about to link to this path-list (or
1413 * one of this path-list's children) is the same entry that
1414 * this recursive path resolves through. this is a cycle.
1424 FIB_PATH_DBG(path, "recursive loop formed");
1425 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RECURSIVE_LOOP;
1427 dpo_copy(&path->fp_dpo,
1428 drop_dpo_get(fib_proto_to_dpo(path->fp_nh_proto)));
1433 * no loop here yet. keep forward walking the graph.
1435 if (fib_entry_recursive_loop_detect(path->fp_via_fib, entry_indicies))
1437 FIB_PATH_DBG(path, "recursive loop formed");
1438 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RECURSIVE_LOOP;
1442 FIB_PATH_DBG(path, "recursive loop cleared");
1443 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RECURSIVE_LOOP;
1448 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1449 case FIB_PATH_TYPE_ATTACHED:
1450 case FIB_PATH_TYPE_SPECIAL:
1451 case FIB_PATH_TYPE_DEAG:
1452 case FIB_PATH_TYPE_RECEIVE:
1453 case FIB_PATH_TYPE_EXCLUSIVE:
1455 * these path types cannot be part of a loop, since they are the leaves
1461 return (fib_path_is_looped(path_index));
1465 fib_path_resolve (fib_node_index_t path_index)
1469 path = fib_path_get(path_index);
1472 * hope for the best.
1474 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RESOLVED;
1477 * the forced drop path resolves via the drop adj
1479 if (fib_path_is_permanent_drop(path))
1481 dpo_copy(&path->fp_dpo,
1482 drop_dpo_get(fib_proto_to_dpo(path->fp_nh_proto)));
1483 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
1484 return (fib_path_is_resolved(path_index));
1487 switch (path->fp_type)
1489 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1490 fib_path_attached_next_hop_set(path);
1492 case FIB_PATH_TYPE_ATTACHED:
1494 * path->attached.fp_interface
1496 if (!vnet_sw_interface_is_admin_up(vnet_get_main(),
1497 path->attached.fp_interface))
1499 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
1501 if (vnet_sw_interface_is_p2p(vnet_get_main(),
1502 path->attached.fp_interface))
1505 * point-2-point interfaces do not require a glean, since
1506 * there is nothing to ARP. Install a rewrite/nbr adj instead
1508 dpo_set(&path->fp_dpo,
1510 fib_proto_to_dpo(path->fp_nh_proto),
1511 adj_nbr_add_or_lock(
1513 fib_proto_to_link(path->fp_nh_proto),
1515 path->attached.fp_interface));
1519 dpo_set(&path->fp_dpo,
1520 DPO_ADJACENCY_GLEAN,
1521 fib_proto_to_dpo(path->fp_nh_proto),
1522 adj_glean_add_or_lock(path->fp_nh_proto,
1523 path->attached.fp_interface,
1527 * become a child of the adjacency so we receive updates
1528 * when the interface state changes
1530 path->fp_sibling = adj_child_add(path->fp_dpo.dpoi_index,
1532 fib_path_get_index(path));
1535 case FIB_PATH_TYPE_RECURSIVE:
1538 * Create a RR source entry in the table for the address
1539 * that this path recurses through.
1540 * This resolve action is recursive, hence we may create
1541 * more paths in the process. more creates mean maybe realloc
1544 fib_node_index_t fei;
1547 ASSERT(FIB_NODE_INDEX_INVALID == path->fp_via_fib);
1549 if (FIB_PROTOCOL_MPLS == path->fp_nh_proto)
1551 fib_prefix_from_mpls_label(path->recursive.fp_nh.fp_local_label, &pfx);
1555 fib_prefix_from_ip46_addr(&path->recursive.fp_nh.fp_ip, &pfx);
1558 fei = fib_table_entry_special_add(path->recursive.fp_tbl_id,
1561 FIB_ENTRY_FLAG_NONE,
1564 path = fib_path_get(path_index);
1565 path->fp_via_fib = fei;
1568 * become a dependent child of the entry so the path is
1569 * informed when the forwarding for the entry changes.
1571 path->fp_sibling = fib_entry_child_add(path->fp_via_fib,
1573 fib_path_get_index(path));
1576 * create and configure the IP DPO
1578 fib_path_recursive_adj_update(
1580 fib_path_proto_to_chain_type(path->fp_nh_proto),
1585 case FIB_PATH_TYPE_SPECIAL:
1587 * Resolve via the drop
1589 dpo_copy(&path->fp_dpo,
1590 drop_dpo_get(fib_proto_to_dpo(path->fp_nh_proto)));
1592 case FIB_PATH_TYPE_DEAG:
1594 * Resolve via a lookup DPO.
1595 * FIXME. control plane should add routes with a table ID
1597 lookup_dpo_add_or_lock_w_fib_index(path->deag.fp_tbl_id,
1598 fib_proto_to_dpo(path->fp_nh_proto),
1599 LOOKUP_INPUT_DST_ADDR,
1600 LOOKUP_TABLE_FROM_CONFIG,
1603 case FIB_PATH_TYPE_RECEIVE:
1605 * Resolve via a receive DPO.
1607 receive_dpo_add_or_lock(fib_proto_to_dpo(path->fp_nh_proto),
1608 path->receive.fp_interface,
1609 &path->receive.fp_addr,
1612 case FIB_PATH_TYPE_EXCLUSIVE:
1614 * Resolve via the user provided DPO
1616 dpo_copy(&path->fp_dpo, &path->exclusive.fp_ex_dpo);
1620 return (fib_path_is_resolved(path_index));
1624 fib_path_get_resolving_interface (fib_node_index_t path_index)
1628 path = fib_path_get(path_index);
1630 switch (path->fp_type)
1632 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1633 return (path->attached_next_hop.fp_interface);
1634 case FIB_PATH_TYPE_ATTACHED:
1635 return (path->attached.fp_interface);
1636 case FIB_PATH_TYPE_RECEIVE:
1637 return (path->receive.fp_interface);
1638 case FIB_PATH_TYPE_RECURSIVE:
1639 return (fib_entry_get_resolving_interface(path->fp_via_fib));
1640 case FIB_PATH_TYPE_SPECIAL:
1641 case FIB_PATH_TYPE_DEAG:
1642 case FIB_PATH_TYPE_EXCLUSIVE:
1649 fib_path_get_adj (fib_node_index_t path_index)
1653 path = fib_path_get(path_index);
1655 ASSERT(dpo_is_adj(&path->fp_dpo));
1656 if (dpo_is_adj(&path->fp_dpo))
1658 return (path->fp_dpo.dpoi_index);
1660 return (ADJ_INDEX_INVALID);
1664 fib_path_get_weight (fib_node_index_t path_index)
1668 path = fib_path_get(path_index);
1672 return (path->fp_weight);
1676 * @brief Contribute the path's adjacency to the list passed.
1677 * By calling this function over all paths, recursively, a child
1678 * can construct its full set of forwarding adjacencies, and hence its
1682 fib_path_contribute_urpf (fib_node_index_t path_index,
1687 if (!fib_path_is_resolved(path_index))
1690 path = fib_path_get(path_index);
1692 switch (path->fp_type)
1694 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1695 fib_urpf_list_append(urpf, path->attached_next_hop.fp_interface);
1698 case FIB_PATH_TYPE_ATTACHED:
1699 fib_urpf_list_append(urpf, path->attached.fp_interface);
1702 case FIB_PATH_TYPE_RECURSIVE:
1703 fib_entry_contribute_urpf(path->fp_via_fib, urpf);
1706 case FIB_PATH_TYPE_EXCLUSIVE:
1707 case FIB_PATH_TYPE_SPECIAL:
1709 * these path types may link to an adj, if that's what
1712 if (dpo_is_adj(&path->fp_dpo))
1714 ip_adjacency_t *adj;
1716 adj = adj_get(path->fp_dpo.dpoi_index);
1718 fib_urpf_list_append(urpf, adj->rewrite_header.sw_if_index);
1722 case FIB_PATH_TYPE_DEAG:
1723 case FIB_PATH_TYPE_RECEIVE:
1725 * these path types don't link to an adj
1732 fib_path_contribute_forwarding (fib_node_index_t path_index,
1733 fib_forward_chain_type_t fct,
1738 path = fib_path_get(path_index);
1741 ASSERT(FIB_FORW_CHAIN_TYPE_MPLS_EOS != fct);
1743 FIB_PATH_DBG(path, "contribute");
1746 * The DPO stored in the path was created when the path was resolved.
1747 * This then represents the path's 'native' protocol; IP.
1748 * For all others will need to go find something else.
1750 if (fib_path_proto_to_chain_type(path->fp_nh_proto) == fct)
1752 dpo_copy(dpo, &path->fp_dpo);
1756 switch (path->fp_type)
1758 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1761 case FIB_FORW_CHAIN_TYPE_UNICAST_IP4:
1762 case FIB_FORW_CHAIN_TYPE_UNICAST_IP6:
1763 case FIB_FORW_CHAIN_TYPE_MPLS_EOS:
1764 case FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS:
1765 case FIB_FORW_CHAIN_TYPE_ETHERNET:
1766 case FIB_FORW_CHAIN_TYPE_NSH:
1771 * get a appropriate link type adj.
1773 ai = fib_path_attached_next_hop_get_adj(
1775 fib_forw_chain_type_to_link_type(fct));
1776 dpo_set(dpo, DPO_ADJACENCY,
1777 fib_forw_chain_type_to_dpo_proto(fct), ai);
1782 case FIB_FORW_CHAIN_TYPE_MCAST_IP4:
1783 case FIB_FORW_CHAIN_TYPE_MCAST_IP6:
1787 case FIB_PATH_TYPE_RECURSIVE:
1790 case FIB_FORW_CHAIN_TYPE_MPLS_EOS:
1791 case FIB_FORW_CHAIN_TYPE_UNICAST_IP4:
1792 case FIB_FORW_CHAIN_TYPE_UNICAST_IP6:
1793 case FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS:
1794 fib_path_recursive_adj_update(path, fct, dpo);
1796 case FIB_FORW_CHAIN_TYPE_MCAST_IP4:
1797 case FIB_FORW_CHAIN_TYPE_MCAST_IP6:
1798 case FIB_FORW_CHAIN_TYPE_ETHERNET:
1799 case FIB_FORW_CHAIN_TYPE_NSH:
1804 case FIB_PATH_TYPE_DEAG:
1807 case FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS:
1808 lookup_dpo_add_or_lock_w_table_id(MPLS_FIB_DEFAULT_TABLE_ID,
1810 LOOKUP_INPUT_DST_ADDR,
1811 LOOKUP_TABLE_FROM_CONFIG,
1814 case FIB_FORW_CHAIN_TYPE_UNICAST_IP4:
1815 case FIB_FORW_CHAIN_TYPE_UNICAST_IP6:
1816 case FIB_FORW_CHAIN_TYPE_MPLS_EOS:
1817 dpo_copy(dpo, &path->fp_dpo);
1819 case FIB_FORW_CHAIN_TYPE_MCAST_IP4:
1820 case FIB_FORW_CHAIN_TYPE_MCAST_IP6:
1821 case FIB_FORW_CHAIN_TYPE_ETHERNET:
1822 case FIB_FORW_CHAIN_TYPE_NSH:
1827 case FIB_PATH_TYPE_EXCLUSIVE:
1828 dpo_copy(dpo, &path->exclusive.fp_ex_dpo);
1830 case FIB_PATH_TYPE_ATTACHED:
1833 case FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS:
1834 case FIB_FORW_CHAIN_TYPE_UNICAST_IP4:
1835 case FIB_FORW_CHAIN_TYPE_UNICAST_IP6:
1836 case FIB_FORW_CHAIN_TYPE_MPLS_EOS:
1837 case FIB_FORW_CHAIN_TYPE_ETHERNET:
1838 case FIB_FORW_CHAIN_TYPE_NSH:
1840 case FIB_FORW_CHAIN_TYPE_MCAST_IP4:
1841 case FIB_FORW_CHAIN_TYPE_MCAST_IP6:
1846 * Create the adj needed for sending IP multicast traffic
1848 ai = adj_mcast_add_or_lock(path->fp_nh_proto,
1849 fib_forw_chain_type_to_link_type(fct),
1850 path->attached.fp_interface);
1851 dpo_set(dpo, DPO_ADJACENCY_MCAST,
1852 fib_forw_chain_type_to_dpo_proto(fct),
1859 case FIB_PATH_TYPE_RECEIVE:
1860 case FIB_PATH_TYPE_SPECIAL:
1861 dpo_copy(dpo, &path->fp_dpo);
1867 load_balance_path_t *
1868 fib_path_append_nh_for_multipath_hash (fib_node_index_t path_index,
1869 fib_forward_chain_type_t fct,
1870 load_balance_path_t *hash_key)
1872 load_balance_path_t *mnh;
1875 path = fib_path_get(path_index);
1879 if (fib_path_is_resolved(path_index))
1881 vec_add2(hash_key, mnh, 1);
1883 mnh->path_weight = path->fp_weight;
1884 mnh->path_index = path_index;
1885 fib_path_contribute_forwarding(path_index, fct, &mnh->path_dpo);
1892 fib_path_is_recursive (fib_node_index_t path_index)
1896 path = fib_path_get(path_index);
1898 return (FIB_PATH_TYPE_RECURSIVE == path->fp_type);
1902 fib_path_is_exclusive (fib_node_index_t path_index)
1906 path = fib_path_get(path_index);
1908 return (FIB_PATH_TYPE_EXCLUSIVE == path->fp_type);
1912 fib_path_is_deag (fib_node_index_t path_index)
1916 path = fib_path_get(path_index);
1918 return (FIB_PATH_TYPE_DEAG == path->fp_type);
1922 fib_path_is_resolved (fib_node_index_t path_index)
1926 path = fib_path_get(path_index);
1928 return (dpo_id_is_valid(&path->fp_dpo) &&
1929 (path->fp_oper_flags & FIB_PATH_OPER_FLAG_RESOLVED) &&
1930 !fib_path_is_looped(path_index) &&
1931 !fib_path_is_permanent_drop(path));
1935 fib_path_is_looped (fib_node_index_t path_index)
1939 path = fib_path_get(path_index);
1941 return (path->fp_oper_flags & FIB_PATH_OPER_FLAG_RECURSIVE_LOOP);
1945 fib_path_encode (fib_node_index_t path_list_index,
1946 fib_node_index_t path_index,
1949 fib_route_path_encode_t **api_rpaths = ctx;
1950 fib_route_path_encode_t *api_rpath;
1953 path = fib_path_get(path_index);
1956 vec_add2(*api_rpaths, api_rpath, 1);
1957 api_rpath->rpath.frp_weight = path->fp_weight;
1958 api_rpath->rpath.frp_proto = path->fp_nh_proto;
1959 api_rpath->rpath.frp_sw_if_index = ~0;
1960 api_rpath->dpo = path->exclusive.fp_ex_dpo;
1961 switch (path->fp_type)
1963 case FIB_PATH_TYPE_RECEIVE:
1964 api_rpath->rpath.frp_addr = path->receive.fp_addr;
1965 api_rpath->rpath.frp_sw_if_index = path->receive.fp_interface;
1967 case FIB_PATH_TYPE_ATTACHED:
1968 api_rpath->rpath.frp_sw_if_index = path->attached.fp_interface;
1970 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1971 api_rpath->rpath.frp_sw_if_index = path->attached_next_hop.fp_interface;
1972 api_rpath->rpath.frp_addr = path->attached_next_hop.fp_nh;
1974 case FIB_PATH_TYPE_SPECIAL:
1976 case FIB_PATH_TYPE_DEAG:
1978 case FIB_PATH_TYPE_RECURSIVE:
1979 api_rpath->rpath.frp_addr = path->recursive.fp_nh.fp_ip;
1988 fib_path_get_proto (fib_node_index_t path_index)
1992 path = fib_path_get(path_index);
1994 return (path->fp_nh_proto);
1998 fib_path_module_init (void)
2000 fib_node_register_type (FIB_NODE_TYPE_PATH, &fib_path_vft);
2003 static clib_error_t *
2004 show_fib_path_command (vlib_main_t * vm,
2005 unformat_input_t * input,
2006 vlib_cli_command_t * cmd)
2008 fib_node_index_t pi;
2011 if (unformat (input, "%d", &pi))
2014 * show one in detail
2016 if (!pool_is_free_index(fib_path_pool, pi))
2018 path = fib_path_get(pi);
2019 u8 *s = fib_path_format(pi, NULL);
2020 s = format(s, "children:");
2021 s = fib_node_children_format(path->fp_node.fn_children, s);
2022 vlib_cli_output (vm, "%s", s);
2027 vlib_cli_output (vm, "path %d invalid", pi);
2032 vlib_cli_output (vm, "FIB Paths");
2033 pool_foreach(path, fib_path_pool,
2035 vlib_cli_output (vm, "%U", format_fib_path, path);
2042 VLIB_CLI_COMMAND (show_fib_path, static) = {
2043 .path = "show fib paths",
2044 .function = show_fib_path_command,
2045 .short_help = "show fib paths",