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 dpo_set(&path->fp_dpo,
563 fib_proto_to_dpo(path->fp_nh_proto),
564 fib_path_attached_next_hop_get_adj(
566 fib_proto_to_link(path->fp_nh_proto)));
569 * become a child of the adjacency so we receive updates
570 * when its rewrite changes
572 path->fp_sibling = adj_child_add(path->fp_dpo.dpoi_index,
574 fib_path_get_index(path));
576 if (!vnet_sw_interface_is_admin_up(vnet_get_main(),
577 path->attached_next_hop.fp_interface) ||
578 !adj_is_up(path->fp_dpo.dpoi_index))
580 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
585 * create of update the paths recursive adj
588 fib_path_recursive_adj_update (fib_path_t *path,
589 fib_forward_chain_type_t fct,
592 dpo_id_t via_dpo = DPO_INVALID;
595 * get the DPO to resolve through from the via-entry
597 fib_entry_contribute_forwarding(path->fp_via_fib,
603 * hope for the best - clear if restrictions apply.
605 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RESOLVED;
608 * Validate any recursion constraints and over-ride the via
611 if (path->fp_oper_flags & FIB_PATH_OPER_FLAG_RECURSIVE_LOOP)
613 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
614 dpo_copy(&via_dpo, drop_dpo_get(fib_proto_to_dpo(path->fp_nh_proto)));
616 else if (path->fp_cfg_flags & FIB_PATH_CFG_FLAG_RESOLVE_HOST)
619 * the via FIB must be a host route.
620 * note the via FIB just added will always be a host route
621 * since it is an RR source added host route. So what we need to
622 * check is whether the route has other sources. If it does then
623 * some other source has added it as a host route. If it doesn't
624 * then it was added only here and inherits forwarding from a cover.
625 * the cover is not a host route.
626 * The RR source is the lowest priority source, so we check if it
627 * is the best. if it is there are no other sources.
629 if (fib_entry_get_best_source(path->fp_via_fib) >= FIB_SOURCE_RR)
631 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
632 dpo_copy(&via_dpo, drop_dpo_get(fib_proto_to_dpo(path->fp_nh_proto)));
635 * PIC edge trigger. let the load-balance maps know
637 load_balance_map_path_state_change(fib_path_get_index(path));
640 else if (path->fp_cfg_flags & FIB_PATH_CFG_FLAG_RESOLVE_ATTACHED)
643 * RR source entries inherit the flags from the cover, so
644 * we can check the via directly
646 if (!(FIB_ENTRY_FLAG_ATTACHED & fib_entry_get_flags(path->fp_via_fib)))
648 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
649 dpo_copy(&via_dpo, drop_dpo_get(fib_proto_to_dpo(path->fp_nh_proto)));
652 * PIC edge trigger. let the load-balance maps know
654 load_balance_map_path_state_change(fib_path_get_index(path));
658 * check for over-riding factors on the FIB entry itself
660 if (!fib_entry_is_resolved(path->fp_via_fib))
662 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
663 dpo_copy(&via_dpo, drop_dpo_get(fib_proto_to_dpo(path->fp_nh_proto)));
666 * PIC edge trigger. let the load-balance maps know
668 load_balance_map_path_state_change(fib_path_get_index(path));
672 * update the path's contributed DPO
674 dpo_copy(dpo, &via_dpo);
676 FIB_PATH_DBG(path, "recursive update: %U",
677 fib_get_lookup_main(path->fp_nh_proto),
684 * fib_path_is_permanent_drop
686 * Return !0 if the path is configured to permanently drop,
687 * despite other attributes.
690 fib_path_is_permanent_drop (fib_path_t *path)
692 return ((path->fp_cfg_flags & FIB_PATH_CFG_FLAG_DROP) ||
693 (path->fp_oper_flags & FIB_PATH_OPER_FLAG_DROP));
699 * Remove our dependency on the resolution target
702 fib_path_unresolve (fib_path_t *path)
705 * the forced drop path does not need unresolving
707 if (fib_path_is_permanent_drop(path))
712 switch (path->fp_type)
714 case FIB_PATH_TYPE_RECURSIVE:
715 if (FIB_NODE_INDEX_INVALID != path->fp_via_fib)
719 fib_entry_get_prefix(path->fp_via_fib, &pfx);
720 fib_entry_child_remove(path->fp_via_fib,
722 fib_table_entry_special_remove(path->recursive.fp_tbl_id,
725 path->fp_via_fib = FIB_NODE_INDEX_INVALID;
728 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
729 case FIB_PATH_TYPE_ATTACHED:
730 adj_child_remove(path->fp_dpo.dpoi_index,
732 adj_unlock(path->fp_dpo.dpoi_index);
734 case FIB_PATH_TYPE_EXCLUSIVE:
735 dpo_reset(&path->exclusive.fp_ex_dpo);
737 case FIB_PATH_TYPE_SPECIAL:
738 case FIB_PATH_TYPE_RECEIVE:
739 case FIB_PATH_TYPE_DEAG:
741 * these hold only the path's DPO, which is reset below.
747 * release the adj we were holding and pick up the
750 dpo_reset(&path->fp_dpo);
751 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
756 static fib_forward_chain_type_t
757 fib_path_proto_to_chain_type (fib_protocol_t proto)
761 case FIB_PROTOCOL_IP4:
762 return (FIB_FORW_CHAIN_TYPE_UNICAST_IP4);
763 case FIB_PROTOCOL_IP6:
764 return (FIB_FORW_CHAIN_TYPE_UNICAST_IP6);
765 case FIB_PROTOCOL_MPLS:
766 return (FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS);
768 return (FIB_FORW_CHAIN_TYPE_UNICAST_IP4);
772 * fib_path_back_walk_notify
774 * A back walk has reach this path.
776 static fib_node_back_walk_rc_t
777 fib_path_back_walk_notify (fib_node_t *node,
778 fib_node_back_walk_ctx_t *ctx)
782 path = fib_path_from_fib_node(node);
784 switch (path->fp_type)
786 case FIB_PATH_TYPE_RECURSIVE:
787 if (FIB_NODE_BW_REASON_FLAG_EVALUATE & ctx->fnbw_reason)
790 * modify the recursive adjacency to use the new forwarding
792 * this update is visible to packets in flight in the DP.
794 fib_path_recursive_adj_update(
796 fib_path_proto_to_chain_type(path->fp_nh_proto),
799 if ((FIB_NODE_BW_REASON_FLAG_ADJ_UPDATE & ctx->fnbw_reason) ||
800 (FIB_NODE_BW_REASON_FLAG_ADJ_DOWN & ctx->fnbw_reason))
803 * ADJ updates (complete<->incomplete) do not need to propagate to
805 * The only reason its needed as far back as here, is that the adj
806 * and the incomplete adj are a different DPO type, so the LBs need
808 * If this walk was quashed in the fib_entry, then any non-fib_path
809 * children (like tunnels that collapse out the LB when they stack)
810 * would not see the update.
812 return (FIB_NODE_BACK_WALK_CONTINUE);
815 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
818 * ADJ_UPDATE backwalk pass silently through here and up to
819 * the path-list when the multipath adj collapse occurs.
820 * The reason we do this is that the assumtption is that VPP
821 * runs in an environment where the Control-Plane is remote
822 * and hence reacts slowly to link up down. In order to remove
823 * this down link from the ECMP set quickly, we back-walk.
824 * VPP also has dedicated CPUs, so we are not stealing resources
825 * from the CP to do so.
827 if (FIB_NODE_BW_REASON_FLAG_INTERFACE_UP & ctx->fnbw_reason)
829 if (path->fp_oper_flags & FIB_PATH_OPER_FLAG_RESOLVED)
832 * alreday resolved. no need to walk back again
834 return (FIB_NODE_BACK_WALK_CONTINUE);
836 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RESOLVED;
838 if (FIB_NODE_BW_REASON_FLAG_INTERFACE_DOWN & ctx->fnbw_reason)
840 if (!(path->fp_oper_flags & FIB_PATH_OPER_FLAG_RESOLVED))
843 * alreday unresolved. no need to walk back again
845 return (FIB_NODE_BACK_WALK_CONTINUE);
847 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
849 if (FIB_NODE_BW_REASON_FLAG_INTERFACE_DELETE & ctx->fnbw_reason)
852 * The interface this path resolves through has been deleted.
853 * This will leave the path in a permanent drop state. The route
854 * needs to be removed and readded (and hence the path-list deleted)
855 * before it can forward again.
857 fib_path_unresolve(path);
858 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_DROP;
860 if (FIB_NODE_BW_REASON_FLAG_ADJ_UPDATE & ctx->fnbw_reason)
863 * restack the DPO to pick up the correct DPO sub-type
868 if_is_up = vnet_sw_interface_is_admin_up(
870 path->attached_next_hop.fp_interface);
872 ai = fib_path_attached_next_hop_get_adj(
874 fib_proto_to_link(path->fp_nh_proto));
876 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
877 if (if_is_up && adj_is_up(ai))
879 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RESOLVED;
882 dpo_set(&path->fp_dpo, DPO_ADJACENCY,
883 fib_proto_to_dpo(path->fp_nh_proto),
890 * If the interface is not up there is no reason to walk
891 * back to children. if we did they would only evalute
892 * that this path is unresolved and hence it would
893 * not contribute the adjacency - so it would be wasted
896 return (FIB_NODE_BACK_WALK_CONTINUE);
899 if (FIB_NODE_BW_REASON_FLAG_ADJ_DOWN & ctx->fnbw_reason)
901 if (!(path->fp_oper_flags & FIB_PATH_OPER_FLAG_RESOLVED))
904 * alreday unresolved. no need to walk back again
906 return (FIB_NODE_BACK_WALK_CONTINUE);
909 * the adj has gone down. the path is no longer resolved.
911 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
914 case FIB_PATH_TYPE_ATTACHED:
916 * FIXME; this could schedule a lower priority walk, since attached
917 * routes are not usually in ECMP configurations so the backwalk to
918 * the FIB entry does not need to be high priority
920 if (FIB_NODE_BW_REASON_FLAG_INTERFACE_UP & ctx->fnbw_reason)
922 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RESOLVED;
924 if (FIB_NODE_BW_REASON_FLAG_INTERFACE_DOWN & ctx->fnbw_reason)
926 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
928 if (FIB_NODE_BW_REASON_FLAG_INTERFACE_DELETE & ctx->fnbw_reason)
930 fib_path_unresolve(path);
931 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_DROP;
934 case FIB_PATH_TYPE_DEAG:
936 * FIXME When VRF delete is allowed this will need a poke.
938 case FIB_PATH_TYPE_SPECIAL:
939 case FIB_PATH_TYPE_RECEIVE:
940 case FIB_PATH_TYPE_EXCLUSIVE:
942 * these path types have no parents. so to be
943 * walked from one is unexpected.
950 * propagate the backwalk further to the path-list
952 fib_path_list_back_walk(path->fp_pl_index, ctx);
954 return (FIB_NODE_BACK_WALK_CONTINUE);
958 fib_path_memory_show (void)
960 fib_show_memory_usage("Path",
961 pool_elts(fib_path_pool),
962 pool_len(fib_path_pool),
967 * The FIB path's graph node virtual function table
969 static const fib_node_vft_t fib_path_vft = {
970 .fnv_get = fib_path_get_node,
971 .fnv_last_lock = fib_path_last_lock_gone,
972 .fnv_back_walk = fib_path_back_walk_notify,
973 .fnv_mem_show = fib_path_memory_show,
976 static fib_path_cfg_flags_t
977 fib_path_route_flags_to_cfg_flags (const fib_route_path_t *rpath)
979 fib_path_cfg_flags_t cfg_flags = FIB_PATH_CFG_FLAG_NONE;
981 if (rpath->frp_flags & FIB_ROUTE_PATH_RESOLVE_VIA_HOST)
982 cfg_flags |= FIB_PATH_CFG_FLAG_RESOLVE_HOST;
983 if (rpath->frp_flags & FIB_ROUTE_PATH_RESOLVE_VIA_ATTACHED)
984 cfg_flags |= FIB_PATH_CFG_FLAG_RESOLVE_ATTACHED;
985 if (rpath->frp_flags & FIB_ROUTE_PATH_LOCAL)
986 cfg_flags |= FIB_PATH_CFG_FLAG_LOCAL;
987 if (rpath->frp_flags & FIB_ROUTE_PATH_ATTACHED)
988 cfg_flags |= FIB_PATH_CFG_FLAG_ATTACHED;
996 * Create and initialise a new path object.
997 * return the index of the path.
1000 fib_path_create (fib_node_index_t pl_index,
1001 fib_protocol_t nh_proto,
1002 fib_path_cfg_flags_t flags,
1003 const fib_route_path_t *rpath)
1007 pool_get(fib_path_pool, path);
1008 memset(path, 0, sizeof(*path));
1010 fib_node_init(&path->fp_node,
1011 FIB_NODE_TYPE_PATH);
1013 dpo_reset(&path->fp_dpo);
1014 path->fp_pl_index = pl_index;
1015 path->fp_nh_proto = nh_proto;
1016 path->fp_via_fib = FIB_NODE_INDEX_INVALID;
1017 path->fp_weight = rpath->frp_weight;
1018 if (0 == path->fp_weight)
1021 * a weight of 0 is a meaningless value. We could either reject it, and thus force
1022 * clients to always use 1, or we can accept it and fixup approrpiately.
1024 path->fp_weight = 1;
1026 path->fp_cfg_flags = flags;
1027 path->fp_cfg_flags |= fib_path_route_flags_to_cfg_flags(rpath);
1030 * deduce the path's tpye from the parementers and save what is needed.
1032 if (path->fp_cfg_flags & FIB_PATH_CFG_FLAG_LOCAL)
1034 path->fp_type = FIB_PATH_TYPE_RECEIVE;
1035 path->receive.fp_interface = rpath->frp_sw_if_index;
1036 path->receive.fp_addr = rpath->frp_addr;
1038 else if (~0 != rpath->frp_sw_if_index)
1040 if (ip46_address_is_zero(&rpath->frp_addr))
1042 path->fp_type = FIB_PATH_TYPE_ATTACHED;
1043 path->attached.fp_interface = rpath->frp_sw_if_index;
1047 path->fp_type = FIB_PATH_TYPE_ATTACHED_NEXT_HOP;
1048 path->attached_next_hop.fp_interface = rpath->frp_sw_if_index;
1049 path->attached_next_hop.fp_nh = rpath->frp_addr;
1054 if (ip46_address_is_zero(&rpath->frp_addr))
1056 if (~0 == rpath->frp_fib_index)
1058 path->fp_type = FIB_PATH_TYPE_SPECIAL;
1062 path->fp_type = FIB_PATH_TYPE_DEAG;
1063 path->deag.fp_tbl_id = rpath->frp_fib_index;
1068 path->fp_type = FIB_PATH_TYPE_RECURSIVE;
1069 if (FIB_PROTOCOL_MPLS == path->fp_nh_proto)
1071 path->recursive.fp_nh.fp_local_label = rpath->frp_local_label;
1075 path->recursive.fp_nh.fp_ip = rpath->frp_addr;
1077 path->recursive.fp_tbl_id = rpath->frp_fib_index;
1081 FIB_PATH_DBG(path, "create");
1083 return (fib_path_get_index(path));
1087 * fib_path_create_special
1089 * Create and initialise a new path object.
1090 * return the index of the path.
1093 fib_path_create_special (fib_node_index_t pl_index,
1094 fib_protocol_t nh_proto,
1095 fib_path_cfg_flags_t flags,
1096 const dpo_id_t *dpo)
1100 pool_get(fib_path_pool, path);
1101 memset(path, 0, sizeof(*path));
1103 fib_node_init(&path->fp_node,
1104 FIB_NODE_TYPE_PATH);
1105 dpo_reset(&path->fp_dpo);
1107 path->fp_pl_index = pl_index;
1108 path->fp_weight = 1;
1109 path->fp_nh_proto = nh_proto;
1110 path->fp_via_fib = FIB_NODE_INDEX_INVALID;
1111 path->fp_cfg_flags = flags;
1113 if (FIB_PATH_CFG_FLAG_DROP & flags)
1115 path->fp_type = FIB_PATH_TYPE_SPECIAL;
1117 else if (FIB_PATH_CFG_FLAG_LOCAL & flags)
1119 path->fp_type = FIB_PATH_TYPE_RECEIVE;
1120 path->attached.fp_interface = FIB_NODE_INDEX_INVALID;
1124 path->fp_type = FIB_PATH_TYPE_EXCLUSIVE;
1125 ASSERT(NULL != dpo);
1126 dpo_copy(&path->exclusive.fp_ex_dpo, dpo);
1129 return (fib_path_get_index(path));
1135 * Copy a path. return index of new path.
1138 fib_path_copy (fib_node_index_t path_index,
1139 fib_node_index_t path_list_index)
1141 fib_path_t *path, *orig_path;
1143 pool_get(fib_path_pool, path);
1145 orig_path = fib_path_get(path_index);
1146 ASSERT(NULL != orig_path);
1148 memcpy(path, orig_path, sizeof(*path));
1150 FIB_PATH_DBG(path, "create-copy:%d", path_index);
1153 * reset the dynamic section
1155 fib_node_init(&path->fp_node, FIB_NODE_TYPE_PATH);
1156 path->fp_oper_flags = FIB_PATH_OPER_FLAG_NONE;
1157 path->fp_pl_index = path_list_index;
1158 path->fp_via_fib = FIB_NODE_INDEX_INVALID;
1159 memset(&path->fp_dpo, 0, sizeof(path->fp_dpo));
1160 dpo_reset(&path->fp_dpo);
1162 return (fib_path_get_index(path));
1168 * destroy a path that is no longer required
1171 fib_path_destroy (fib_node_index_t path_index)
1175 path = fib_path_get(path_index);
1177 ASSERT(NULL != path);
1178 FIB_PATH_DBG(path, "destroy");
1180 fib_path_unresolve(path);
1182 fib_node_deinit(&path->fp_node);
1183 pool_put(fib_path_pool, path);
1189 * destroy a path that is no longer required
1192 fib_path_hash (fib_node_index_t path_index)
1196 path = fib_path_get(path_index);
1198 return (hash_memory(STRUCT_MARK_PTR(path, path_hash_start),
1199 (STRUCT_OFFSET_OF(fib_path_t, path_hash_end) -
1200 STRUCT_OFFSET_OF(fib_path_t, path_hash_start)),
1207 * Compare two paths for equivalence.
1210 fib_path_cmp_i (const fib_path_t *path1,
1211 const fib_path_t *path2)
1218 * paths of different types and protocol are not equal.
1219 * different weights only are the same path.
1221 if (path1->fp_type != path2->fp_type)
1223 res = (path1->fp_type - path2->fp_type);
1225 else if (path1->fp_nh_proto != path2->fp_nh_proto)
1227 res = (path1->fp_nh_proto - path2->fp_nh_proto);
1232 * both paths are of the same type.
1233 * consider each type and its attributes in turn.
1235 switch (path1->fp_type)
1237 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1238 res = ip46_address_cmp(&path1->attached_next_hop.fp_nh,
1239 &path2->attached_next_hop.fp_nh);
1241 res = vnet_sw_interface_compare(
1243 path1->attached_next_hop.fp_interface,
1244 path2->attached_next_hop.fp_interface);
1247 case FIB_PATH_TYPE_ATTACHED:
1248 res = vnet_sw_interface_compare(
1250 path1->attached.fp_interface,
1251 path2->attached.fp_interface);
1253 case FIB_PATH_TYPE_RECURSIVE:
1254 res = ip46_address_cmp(&path1->recursive.fp_nh,
1255 &path2->recursive.fp_nh);
1259 res = (path1->recursive.fp_tbl_id - path2->recursive.fp_tbl_id);
1262 case FIB_PATH_TYPE_DEAG:
1263 res = (path1->deag.fp_tbl_id - path2->deag.fp_tbl_id);
1265 case FIB_PATH_TYPE_SPECIAL:
1266 case FIB_PATH_TYPE_RECEIVE:
1267 case FIB_PATH_TYPE_EXCLUSIVE:
1276 * fib_path_cmp_for_sort
1278 * Compare two paths for equivalence. Used during path sorting.
1279 * As usual 0 means equal.
1282 fib_path_cmp_for_sort (void * v1,
1285 fib_node_index_t *pi1 = v1, *pi2 = v2;
1286 fib_path_t *path1, *path2;
1288 path1 = fib_path_get(*pi1);
1289 path2 = fib_path_get(*pi2);
1291 return (fib_path_cmp_i(path1, path2));
1297 * Compare two paths for equivalence.
1300 fib_path_cmp (fib_node_index_t pi1,
1301 fib_node_index_t pi2)
1303 fib_path_t *path1, *path2;
1305 path1 = fib_path_get(pi1);
1306 path2 = fib_path_get(pi2);
1308 return (fib_path_cmp_i(path1, path2));
1312 fib_path_cmp_w_route_path (fib_node_index_t path_index,
1313 const fib_route_path_t *rpath)
1318 path = fib_path_get(path_index);
1322 if (path->fp_weight != rpath->frp_weight)
1324 res = (path->fp_weight - rpath->frp_weight);
1329 * both paths are of the same type.
1330 * consider each type and its attributes in turn.
1332 switch (path->fp_type)
1334 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1335 res = ip46_address_cmp(&path->attached_next_hop.fp_nh,
1339 res = vnet_sw_interface_compare(
1341 path->attached_next_hop.fp_interface,
1342 rpath->frp_sw_if_index);
1345 case FIB_PATH_TYPE_ATTACHED:
1346 res = vnet_sw_interface_compare(
1348 path->attached.fp_interface,
1349 rpath->frp_sw_if_index);
1351 case FIB_PATH_TYPE_RECURSIVE:
1352 if (FIB_PROTOCOL_MPLS == path->fp_nh_proto)
1354 res = path->recursive.fp_nh.fp_local_label - rpath->frp_local_label;
1358 res = ip46_address_cmp(&path->recursive.fp_nh.fp_ip,
1364 res = (path->recursive.fp_tbl_id - rpath->frp_fib_index);
1367 case FIB_PATH_TYPE_DEAG:
1368 res = (path->deag.fp_tbl_id - rpath->frp_fib_index);
1370 case FIB_PATH_TYPE_SPECIAL:
1371 case FIB_PATH_TYPE_RECEIVE:
1372 case FIB_PATH_TYPE_EXCLUSIVE:
1381 * fib_path_recursive_loop_detect
1383 * A forward walk of the FIB object graph to detect for a cycle/loop. This
1384 * walk is initiated when an entry is linking to a new path list or from an old.
1385 * The entry vector passed contains all the FIB entrys that are children of this
1386 * path (it is all the entries encountered on the walk so far). If this vector
1387 * contains the entry this path resolve via, then a loop is about to form.
1388 * The loop must be allowed to form, since we need the dependencies in place
1389 * so that we can track when the loop breaks.
1390 * However, we MUST not produce a loop in the forwarding graph (else packets
1391 * would loop around the switch path until the loop breaks), so we mark recursive
1392 * paths as looped so that they do not contribute forwarding information.
1393 * By marking the path as looped, an etry such as;
1395 * via a.a.a.a (looped)
1396 * via b.b.b.b (not looped)
1397 * can still forward using the info provided by b.b.b.b only
1400 fib_path_recursive_loop_detect (fib_node_index_t path_index,
1401 fib_node_index_t **entry_indicies)
1405 path = fib_path_get(path_index);
1408 * the forced drop path is never looped, cos it is never resolved.
1410 if (fib_path_is_permanent_drop(path))
1415 switch (path->fp_type)
1417 case FIB_PATH_TYPE_RECURSIVE:
1419 fib_node_index_t *entry_index, *entries;
1421 entries = *entry_indicies;
1423 vec_foreach(entry_index, entries) {
1424 if (*entry_index == path->fp_via_fib)
1427 * the entry that is about to link to this path-list (or
1428 * one of this path-list's children) is the same entry that
1429 * this recursive path resolves through. this is a cycle.
1439 FIB_PATH_DBG(path, "recursive loop formed");
1440 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RECURSIVE_LOOP;
1442 dpo_copy(&path->fp_dpo,
1443 drop_dpo_get(fib_proto_to_dpo(path->fp_nh_proto)));
1448 * no loop here yet. keep forward walking the graph.
1450 if (fib_entry_recursive_loop_detect(path->fp_via_fib, entry_indicies))
1452 FIB_PATH_DBG(path, "recursive loop formed");
1453 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RECURSIVE_LOOP;
1457 FIB_PATH_DBG(path, "recursive loop cleared");
1458 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RECURSIVE_LOOP;
1463 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1464 case FIB_PATH_TYPE_ATTACHED:
1465 case FIB_PATH_TYPE_SPECIAL:
1466 case FIB_PATH_TYPE_DEAG:
1467 case FIB_PATH_TYPE_RECEIVE:
1468 case FIB_PATH_TYPE_EXCLUSIVE:
1470 * these path types cannot be part of a loop, since they are the leaves
1476 return (fib_path_is_looped(path_index));
1480 fib_path_resolve (fib_node_index_t path_index)
1484 path = fib_path_get(path_index);
1487 * hope for the best.
1489 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RESOLVED;
1492 * the forced drop path resolves via the drop adj
1494 if (fib_path_is_permanent_drop(path))
1496 dpo_copy(&path->fp_dpo,
1497 drop_dpo_get(fib_proto_to_dpo(path->fp_nh_proto)));
1498 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
1499 return (fib_path_is_resolved(path_index));
1502 switch (path->fp_type)
1504 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1505 fib_path_attached_next_hop_set(path);
1507 case FIB_PATH_TYPE_ATTACHED:
1509 * path->attached.fp_interface
1511 if (!vnet_sw_interface_is_admin_up(vnet_get_main(),
1512 path->attached.fp_interface))
1514 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
1516 if (vnet_sw_interface_is_p2p(vnet_get_main(),
1517 path->attached.fp_interface))
1520 * point-2-point interfaces do not require a glean, since
1521 * there is nothing to ARP. Install a rewrite/nbr adj instead
1523 dpo_set(&path->fp_dpo,
1525 fib_proto_to_dpo(path->fp_nh_proto),
1526 adj_nbr_add_or_lock(
1528 fib_proto_to_link(path->fp_nh_proto),
1530 path->attached.fp_interface));
1534 dpo_set(&path->fp_dpo,
1535 DPO_ADJACENCY_GLEAN,
1536 fib_proto_to_dpo(path->fp_nh_proto),
1537 adj_glean_add_or_lock(path->fp_nh_proto,
1538 path->attached.fp_interface,
1542 * become a child of the adjacency so we receive updates
1543 * when the interface state changes
1545 path->fp_sibling = adj_child_add(path->fp_dpo.dpoi_index,
1547 fib_path_get_index(path));
1550 case FIB_PATH_TYPE_RECURSIVE:
1553 * Create a RR source entry in the table for the address
1554 * that this path recurses through.
1555 * This resolve action is recursive, hence we may create
1556 * more paths in the process. more creates mean maybe realloc
1559 fib_node_index_t fei;
1562 ASSERT(FIB_NODE_INDEX_INVALID == path->fp_via_fib);
1564 if (FIB_PROTOCOL_MPLS == path->fp_nh_proto)
1566 fib_prefix_from_mpls_label(path->recursive.fp_nh.fp_local_label, &pfx);
1570 fib_prefix_from_ip46_addr(&path->recursive.fp_nh.fp_ip, &pfx);
1573 fei = fib_table_entry_special_add(path->recursive.fp_tbl_id,
1576 FIB_ENTRY_FLAG_NONE,
1579 path = fib_path_get(path_index);
1580 path->fp_via_fib = fei;
1583 * become a dependent child of the entry so the path is
1584 * informed when the forwarding for the entry changes.
1586 path->fp_sibling = fib_entry_child_add(path->fp_via_fib,
1588 fib_path_get_index(path));
1591 * create and configure the IP DPO
1593 fib_path_recursive_adj_update(
1595 fib_path_proto_to_chain_type(path->fp_nh_proto),
1600 case FIB_PATH_TYPE_SPECIAL:
1602 * Resolve via the drop
1604 dpo_copy(&path->fp_dpo,
1605 drop_dpo_get(fib_proto_to_dpo(path->fp_nh_proto)));
1607 case FIB_PATH_TYPE_DEAG:
1609 * Resolve via a lookup DPO.
1610 * FIXME. control plane should add routes with a table ID
1612 lookup_dpo_add_or_lock_w_fib_index(path->deag.fp_tbl_id,
1613 fib_proto_to_dpo(path->fp_nh_proto),
1614 LOOKUP_INPUT_DST_ADDR,
1615 LOOKUP_TABLE_FROM_CONFIG,
1618 case FIB_PATH_TYPE_RECEIVE:
1620 * Resolve via a receive DPO.
1622 receive_dpo_add_or_lock(fib_proto_to_dpo(path->fp_nh_proto),
1623 path->receive.fp_interface,
1624 &path->receive.fp_addr,
1627 case FIB_PATH_TYPE_EXCLUSIVE:
1629 * Resolve via the user provided DPO
1631 dpo_copy(&path->fp_dpo, &path->exclusive.fp_ex_dpo);
1635 return (fib_path_is_resolved(path_index));
1639 fib_path_get_resolving_interface (fib_node_index_t path_index)
1643 path = fib_path_get(path_index);
1645 switch (path->fp_type)
1647 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1648 return (path->attached_next_hop.fp_interface);
1649 case FIB_PATH_TYPE_ATTACHED:
1650 return (path->attached.fp_interface);
1651 case FIB_PATH_TYPE_RECEIVE:
1652 return (path->receive.fp_interface);
1653 case FIB_PATH_TYPE_RECURSIVE:
1654 return (fib_entry_get_resolving_interface(path->fp_via_fib));
1655 case FIB_PATH_TYPE_SPECIAL:
1656 case FIB_PATH_TYPE_DEAG:
1657 case FIB_PATH_TYPE_EXCLUSIVE:
1664 fib_path_get_adj (fib_node_index_t path_index)
1668 path = fib_path_get(path_index);
1670 ASSERT(dpo_is_adj(&path->fp_dpo));
1671 if (dpo_is_adj(&path->fp_dpo))
1673 return (path->fp_dpo.dpoi_index);
1675 return (ADJ_INDEX_INVALID);
1679 fib_path_get_weight (fib_node_index_t path_index)
1683 path = fib_path_get(path_index);
1687 return (path->fp_weight);
1691 * @brief Contribute the path's adjacency to the list passed.
1692 * By calling this function over all paths, recursively, a child
1693 * can construct its full set of forwarding adjacencies, and hence its
1697 fib_path_contribute_urpf (fib_node_index_t path_index,
1702 path = fib_path_get(path_index);
1705 * resolved and unresolved paths contribute to the RPF list.
1707 switch (path->fp_type)
1709 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1710 fib_urpf_list_append(urpf, path->attached_next_hop.fp_interface);
1713 case FIB_PATH_TYPE_ATTACHED:
1714 fib_urpf_list_append(urpf, path->attached.fp_interface);
1717 case FIB_PATH_TYPE_RECURSIVE:
1718 if (FIB_NODE_INDEX_INVALID != path->fp_via_fib)
1721 * there's unresolved due to constraints, and there's unresolved
1722 * due to ain't go no via. can't do nowt w'out via.
1724 fib_entry_contribute_urpf(path->fp_via_fib, urpf);
1728 case FIB_PATH_TYPE_EXCLUSIVE:
1729 case FIB_PATH_TYPE_SPECIAL:
1731 * these path types may link to an adj, if that's what
1734 if (dpo_is_adj(&path->fp_dpo))
1736 ip_adjacency_t *adj;
1738 adj = adj_get(path->fp_dpo.dpoi_index);
1740 fib_urpf_list_append(urpf, adj->rewrite_header.sw_if_index);
1744 case FIB_PATH_TYPE_DEAG:
1745 case FIB_PATH_TYPE_RECEIVE:
1747 * these path types don't link to an adj
1754 fib_path_contribute_forwarding (fib_node_index_t path_index,
1755 fib_forward_chain_type_t fct,
1760 path = fib_path_get(path_index);
1763 ASSERT(FIB_FORW_CHAIN_TYPE_MPLS_EOS != fct);
1765 FIB_PATH_DBG(path, "contribute");
1768 * The DPO stored in the path was created when the path was resolved.
1769 * This then represents the path's 'native' protocol; IP.
1770 * For all others will need to go find something else.
1772 if (fib_path_proto_to_chain_type(path->fp_nh_proto) == fct)
1774 dpo_copy(dpo, &path->fp_dpo);
1778 switch (path->fp_type)
1780 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1783 case FIB_FORW_CHAIN_TYPE_UNICAST_IP4:
1784 case FIB_FORW_CHAIN_TYPE_UNICAST_IP6:
1785 case FIB_FORW_CHAIN_TYPE_MPLS_EOS:
1786 case FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS:
1787 case FIB_FORW_CHAIN_TYPE_ETHERNET:
1788 case FIB_FORW_CHAIN_TYPE_NSH:
1793 * get a appropriate link type adj.
1795 ai = fib_path_attached_next_hop_get_adj(
1797 fib_forw_chain_type_to_link_type(fct));
1798 dpo_set(dpo, DPO_ADJACENCY,
1799 fib_forw_chain_type_to_dpo_proto(fct), ai);
1804 case FIB_FORW_CHAIN_TYPE_MCAST_IP4:
1805 case FIB_FORW_CHAIN_TYPE_MCAST_IP6:
1809 case FIB_PATH_TYPE_RECURSIVE:
1812 case FIB_FORW_CHAIN_TYPE_MPLS_EOS:
1813 case FIB_FORW_CHAIN_TYPE_UNICAST_IP4:
1814 case FIB_FORW_CHAIN_TYPE_UNICAST_IP6:
1815 case FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS:
1816 fib_path_recursive_adj_update(path, fct, 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_DEAG:
1829 case FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS:
1830 lookup_dpo_add_or_lock_w_table_id(MPLS_FIB_DEFAULT_TABLE_ID,
1832 LOOKUP_INPUT_DST_ADDR,
1833 LOOKUP_TABLE_FROM_CONFIG,
1836 case FIB_FORW_CHAIN_TYPE_UNICAST_IP4:
1837 case FIB_FORW_CHAIN_TYPE_UNICAST_IP6:
1838 case FIB_FORW_CHAIN_TYPE_MPLS_EOS:
1839 dpo_copy(dpo, &path->fp_dpo);
1841 case FIB_FORW_CHAIN_TYPE_MCAST_IP4:
1842 case FIB_FORW_CHAIN_TYPE_MCAST_IP6:
1843 case FIB_FORW_CHAIN_TYPE_ETHERNET:
1844 case FIB_FORW_CHAIN_TYPE_NSH:
1849 case FIB_PATH_TYPE_EXCLUSIVE:
1850 dpo_copy(dpo, &path->exclusive.fp_ex_dpo);
1852 case FIB_PATH_TYPE_ATTACHED:
1855 case FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS:
1856 case FIB_FORW_CHAIN_TYPE_UNICAST_IP4:
1857 case FIB_FORW_CHAIN_TYPE_UNICAST_IP6:
1858 case FIB_FORW_CHAIN_TYPE_MPLS_EOS:
1859 case FIB_FORW_CHAIN_TYPE_ETHERNET:
1860 case FIB_FORW_CHAIN_TYPE_NSH:
1862 case FIB_FORW_CHAIN_TYPE_MCAST_IP4:
1863 case FIB_FORW_CHAIN_TYPE_MCAST_IP6:
1868 * Create the adj needed for sending IP multicast traffic
1870 ai = adj_mcast_add_or_lock(path->fp_nh_proto,
1871 fib_forw_chain_type_to_link_type(fct),
1872 path->attached.fp_interface);
1873 dpo_set(dpo, DPO_ADJACENCY_MCAST,
1874 fib_forw_chain_type_to_dpo_proto(fct),
1881 case FIB_PATH_TYPE_RECEIVE:
1882 case FIB_PATH_TYPE_SPECIAL:
1883 dpo_copy(dpo, &path->fp_dpo);
1889 load_balance_path_t *
1890 fib_path_append_nh_for_multipath_hash (fib_node_index_t path_index,
1891 fib_forward_chain_type_t fct,
1892 load_balance_path_t *hash_key)
1894 load_balance_path_t *mnh;
1897 path = fib_path_get(path_index);
1901 if (fib_path_is_resolved(path_index))
1903 vec_add2(hash_key, mnh, 1);
1905 mnh->path_weight = path->fp_weight;
1906 mnh->path_index = path_index;
1907 fib_path_contribute_forwarding(path_index, fct, &mnh->path_dpo);
1914 fib_path_is_recursive (fib_node_index_t path_index)
1918 path = fib_path_get(path_index);
1920 return (FIB_PATH_TYPE_RECURSIVE == path->fp_type);
1924 fib_path_is_exclusive (fib_node_index_t path_index)
1928 path = fib_path_get(path_index);
1930 return (FIB_PATH_TYPE_EXCLUSIVE == path->fp_type);
1934 fib_path_is_deag (fib_node_index_t path_index)
1938 path = fib_path_get(path_index);
1940 return (FIB_PATH_TYPE_DEAG == path->fp_type);
1944 fib_path_is_resolved (fib_node_index_t path_index)
1948 path = fib_path_get(path_index);
1950 return (dpo_id_is_valid(&path->fp_dpo) &&
1951 (path->fp_oper_flags & FIB_PATH_OPER_FLAG_RESOLVED) &&
1952 !fib_path_is_looped(path_index) &&
1953 !fib_path_is_permanent_drop(path));
1957 fib_path_is_looped (fib_node_index_t path_index)
1961 path = fib_path_get(path_index);
1963 return (path->fp_oper_flags & FIB_PATH_OPER_FLAG_RECURSIVE_LOOP);
1967 fib_path_encode (fib_node_index_t path_list_index,
1968 fib_node_index_t path_index,
1971 fib_route_path_encode_t **api_rpaths = ctx;
1972 fib_route_path_encode_t *api_rpath;
1975 path = fib_path_get(path_index);
1978 vec_add2(*api_rpaths, api_rpath, 1);
1979 api_rpath->rpath.frp_weight = path->fp_weight;
1980 api_rpath->rpath.frp_proto = path->fp_nh_proto;
1981 api_rpath->rpath.frp_sw_if_index = ~0;
1982 api_rpath->dpo = path->exclusive.fp_ex_dpo;
1983 switch (path->fp_type)
1985 case FIB_PATH_TYPE_RECEIVE:
1986 api_rpath->rpath.frp_addr = path->receive.fp_addr;
1987 api_rpath->rpath.frp_sw_if_index = path->receive.fp_interface;
1989 case FIB_PATH_TYPE_ATTACHED:
1990 api_rpath->rpath.frp_sw_if_index = path->attached.fp_interface;
1992 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1993 api_rpath->rpath.frp_sw_if_index = path->attached_next_hop.fp_interface;
1994 api_rpath->rpath.frp_addr = path->attached_next_hop.fp_nh;
1996 case FIB_PATH_TYPE_SPECIAL:
1998 case FIB_PATH_TYPE_DEAG:
2000 case FIB_PATH_TYPE_RECURSIVE:
2001 api_rpath->rpath.frp_addr = path->recursive.fp_nh.fp_ip;
2010 fib_path_get_proto (fib_node_index_t path_index)
2014 path = fib_path_get(path_index);
2016 return (path->fp_nh_proto);
2020 fib_path_module_init (void)
2022 fib_node_register_type (FIB_NODE_TYPE_PATH, &fib_path_vft);
2025 static clib_error_t *
2026 show_fib_path_command (vlib_main_t * vm,
2027 unformat_input_t * input,
2028 vlib_cli_command_t * cmd)
2030 fib_node_index_t pi;
2033 if (unformat (input, "%d", &pi))
2036 * show one in detail
2038 if (!pool_is_free_index(fib_path_pool, pi))
2040 path = fib_path_get(pi);
2041 u8 *s = fib_path_format(pi, NULL);
2042 s = format(s, "children:");
2043 s = fib_node_children_format(path->fp_node.fn_children, s);
2044 vlib_cli_output (vm, "%s", s);
2049 vlib_cli_output (vm, "path %d invalid", pi);
2054 vlib_cli_output (vm, "FIB Paths");
2055 pool_foreach(path, fib_path_pool,
2057 vlib_cli_output (vm, "%U", format_fib_path, path);
2064 VLIB_CLI_COMMAND (show_fib_path, static) = {
2065 .path = "show fib paths",
2066 .function = show_fib_path_command,
2067 .short_help = "show fib paths",