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>
27 #include <vnet/fib/fib_path.h>
28 #include <vnet/fib/fib_node.h>
29 #include <vnet/fib/fib_table.h>
30 #include <vnet/fib/fib_entry.h>
31 #include <vnet/fib/fib_path_list.h>
32 #include <vnet/fib/fib_internal.h>
33 #include <vnet/fib/fib_urpf_list.h>
36 * Enurmeration of path types
38 typedef enum fib_path_type_t_ {
40 * Marker. Add new types after this one.
42 FIB_PATH_TYPE_FIRST = 0,
44 * Attached-nexthop. An interface and a nexthop are known.
46 FIB_PATH_TYPE_ATTACHED_NEXT_HOP = FIB_PATH_TYPE_FIRST,
48 * attached. Only the interface is known.
50 FIB_PATH_TYPE_ATTACHED,
52 * recursive. Only the next-hop is known.
54 FIB_PATH_TYPE_RECURSIVE,
56 * special. nothing is known. so we drop.
58 FIB_PATH_TYPE_SPECIAL,
60 * exclusive. user provided adj.
62 FIB_PATH_TYPE_EXCLUSIVE,
64 * deag. Link to a lookup adj in the next table
68 * receive. it's for-us.
70 FIB_PATH_TYPE_RECEIVE,
72 * Marker. Add new types before this one, then update it.
74 FIB_PATH_TYPE_LAST = FIB_PATH_TYPE_RECEIVE,
75 } __attribute__ ((packed)) fib_path_type_t;
78 * The maximum number of path_types
80 #define FIB_PATH_TYPE_MAX (FIB_PATH_TYPE_LAST + 1)
82 #define FIB_PATH_TYPES { \
83 [FIB_PATH_TYPE_ATTACHED_NEXT_HOP] = "attached-nexthop", \
84 [FIB_PATH_TYPE_ATTACHED] = "attached", \
85 [FIB_PATH_TYPE_RECURSIVE] = "recursive", \
86 [FIB_PATH_TYPE_SPECIAL] = "special", \
87 [FIB_PATH_TYPE_EXCLUSIVE] = "exclusive", \
88 [FIB_PATH_TYPE_DEAG] = "deag", \
89 [FIB_PATH_TYPE_RECEIVE] = "receive", \
92 #define FOR_EACH_FIB_PATH_TYPE(_item) \
93 for (_item = FIB_PATH_TYPE_FIRST; _item <= FIB_PATH_TYPE_LAST; _item++)
96 * Enurmeration of path operational (i.e. derived) attributes
98 typedef enum fib_path_oper_attribute_t_ {
100 * Marker. Add new types after this one.
102 FIB_PATH_OPER_ATTRIBUTE_FIRST = 0,
104 * The path forms part of a recursive loop.
106 FIB_PATH_OPER_ATTRIBUTE_RECURSIVE_LOOP = FIB_PATH_OPER_ATTRIBUTE_FIRST,
108 * The path is resolved
110 FIB_PATH_OPER_ATTRIBUTE_RESOLVED,
112 * The path has become a permanent drop.
114 FIB_PATH_OPER_ATTRIBUTE_DROP,
116 * Marker. Add new types before this one, then update it.
118 FIB_PATH_OPER_ATTRIBUTE_LAST = FIB_PATH_OPER_ATTRIBUTE_DROP,
119 } __attribute__ ((packed)) fib_path_oper_attribute_t;
122 * The maximum number of path operational attributes
124 #define FIB_PATH_OPER_ATTRIBUTE_MAX (FIB_PATH_OPER_ATTRIBUTE_LAST + 1)
126 #define FIB_PATH_OPER_ATTRIBUTES { \
127 [FIB_PATH_OPER_ATTRIBUTE_RECURSIVE_LOOP] = "recursive-loop", \
128 [FIB_PATH_OPER_ATTRIBUTE_RESOLVED] = "resolved", \
129 [FIB_PATH_OPER_ATTRIBUTE_DROP] = "drop", \
132 #define FOR_EACH_FIB_PATH_OPER_ATTRIBUTE(_item) \
133 for (_item = FIB_PATH_OPER_ATTRIBUTE_FIRST; \
134 _item <= FIB_PATH_OPER_ATTRIBUTE_LAST; \
138 * Path flags from the attributes
140 typedef enum fib_path_oper_flags_t_ {
141 FIB_PATH_OPER_FLAG_NONE = 0,
142 FIB_PATH_OPER_FLAG_RECURSIVE_LOOP = (1 << FIB_PATH_OPER_ATTRIBUTE_RECURSIVE_LOOP),
143 FIB_PATH_OPER_FLAG_DROP = (1 << FIB_PATH_OPER_ATTRIBUTE_DROP),
144 FIB_PATH_OPER_FLAG_RESOLVED = (1 << FIB_PATH_OPER_ATTRIBUTE_RESOLVED),
145 } __attribute__ ((packed)) fib_path_oper_flags_t;
150 typedef struct fib_path_t_ {
152 * A path is a node in the FIB graph.
157 * The index of the path-list to which this path belongs
162 * This marks the start of the memory area used to hash
165 STRUCT_MARK(path_hash_start);
168 * Configuration Flags
170 fib_path_cfg_flags_t fp_cfg_flags;
173 * The type of the path. This is the selector for the union
175 fib_path_type_t fp_type;
178 * The protocol of the next-hop, i.e. the address family of the
179 * next-hop's address. We can't derive this from the address itself
180 * since the address can be all zeros
182 fib_protocol_t fp_nh_proto;
185 * UCMP [unnormalised] weigt
190 * per-type union of the data required to resolve the path
197 ip46_address_t fp_nh;
215 ip46_address_t fp_ip;
217 * The local label to resolve through.
219 mpls_label_t fp_local_label;
222 * The FIB table index in which to find the next-hop.
223 * This needs to be fixed. We should lookup the adjacencies in
224 * a separate table of adjacencies, rather than from the FIB.
225 * Two reasons I can think of:
227 * int ip addr Gig0 10.0.0.1/24
228 * ip route 10.0.0.2/32 via Gig1 192.168.1.2
229 * ip route 1.1.1.1/32 via Gig0 10.0.0.2
230 * this is perfectly valid.
231 * Packets addressed to 10.0.0.2 should be sent via Gig1.
232 * Packets address to 1.1.1.1 should be sent via Gig0.
233 * when we perform the adj resolution from the FIB for the path
234 * "via Gig0 10.0.0.2" the lookup will result in the route via Gig1
235 * and so we will pick up the adj via Gig1 - which was not what the
237 * - we can only return link-type IPv4 and so not the link-type MPLS.
238 * more on this in a later commit.
240 * The table ID should only belong to a recursive path and indicate
241 * which FIB should be used to resolve the next-hop.
243 fib_node_index_t fp_tbl_id;
247 * The FIB index in which to perfom the next lookup
249 fib_node_index_t fp_tbl_id;
255 * The user provided 'exclusive' DPO
261 * The interface on which the local address is configured
267 ip46_address_t fp_addr;
270 STRUCT_MARK(path_hash_end);
273 * Memebers in this last section represent information that is
274 * dervied during resolution. It should not be copied to new paths
281 fib_path_oper_flags_t fp_oper_flags;
284 * the resolving via fib. not part of the union, since it it not part
285 * of the path's hash.
287 fib_node_index_t fp_via_fib;
290 * The Data-path objects through which this path resolves for IP.
295 * the index of this path in the parent's child list.
301 * Array of strings/names for the path types and attributes
303 static const char *fib_path_type_names[] = FIB_PATH_TYPES;
304 static const char *fib_path_oper_attribute_names[] = FIB_PATH_OPER_ATTRIBUTES;
305 static const char *fib_path_cfg_attribute_names[] = FIB_PATH_CFG_ATTRIBUTES;
308 * The memory pool from which we allocate all the paths
310 static fib_path_t *fib_path_pool;
316 #define FIB_PATH_DBG(_p, _fmt, _args...) \
319 _tmp = fib_path_format(fib_path_get_index(_p), _tmp); \
320 clib_warning("path:[%d:%s]:" _fmt, \
321 fib_path_get_index(_p), _tmp, \
326 #define FIB_PATH_DBG(_p, _fmt, _args...)
330 fib_path_get (fib_node_index_t index)
332 return (pool_elt_at_index(fib_path_pool, index));
335 static fib_node_index_t
336 fib_path_get_index (fib_path_t *path)
338 return (path - fib_path_pool);
342 fib_path_get_node (fib_node_index_t index)
344 return ((fib_node_t*)fib_path_get(index));
348 fib_path_from_fib_node (fib_node_t *node)
351 ASSERT(FIB_NODE_TYPE_PATH == node->fn_type);
353 return ((fib_path_t*)node);
357 format_fib_path (u8 * s, va_list * args)
359 fib_path_t *path = va_arg (*args, fib_path_t *);
360 vnet_main_t * vnm = vnet_get_main();
361 fib_path_oper_attribute_t oattr;
362 fib_path_cfg_attribute_t cattr;
364 s = format (s, " index:%d ", fib_path_get_index(path));
365 s = format (s, "pl-index:%d ", path->fp_pl_index);
366 s = format (s, "%U ", format_fib_protocol, path->fp_nh_proto);
367 s = format (s, "weight=%d ", path->fp_weight);
368 s = format (s, "%s: ", fib_path_type_names[path->fp_type]);
369 if (FIB_PATH_OPER_FLAG_NONE != path->fp_oper_flags) {
370 s = format(s, " oper-flags:");
371 FOR_EACH_FIB_PATH_OPER_ATTRIBUTE(oattr) {
372 if ((1<<oattr) & path->fp_oper_flags) {
373 s = format (s, "%s,", fib_path_oper_attribute_names[oattr]);
377 if (FIB_PATH_CFG_FLAG_NONE != path->fp_cfg_flags) {
378 s = format(s, " cfg-flags:");
379 FOR_EACH_FIB_PATH_CFG_ATTRIBUTE(cattr) {
380 if ((1<<cattr) & path->fp_cfg_flags) {
381 s = format (s, "%s,", fib_path_cfg_attribute_names[cattr]);
385 s = format(s, "\n ");
387 switch (path->fp_type)
389 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
390 s = format (s, "%U", format_ip46_address,
391 &path->attached_next_hop.fp_nh,
393 if (path->fp_oper_flags & FIB_PATH_OPER_FLAG_DROP)
395 s = format (s, " if_index:%d", path->attached_next_hop.fp_interface);
399 s = format (s, " %U",
400 format_vnet_sw_interface_name,
402 vnet_get_sw_interface(
404 path->attached_next_hop.fp_interface));
405 if (vnet_sw_interface_is_p2p(vnet_get_main(),
406 path->attached_next_hop.fp_interface))
408 s = format (s, " (p2p)");
411 if (!dpo_id_is_valid(&path->fp_dpo))
413 s = format(s, "\n unresolved");
417 s = format(s, "\n %U",
422 case FIB_PATH_TYPE_ATTACHED:
423 if (path->fp_oper_flags & FIB_PATH_OPER_FLAG_DROP)
425 s = format (s, " if_index:%d", path->attached_next_hop.fp_interface);
429 s = format (s, " %U",
430 format_vnet_sw_interface_name,
432 vnet_get_sw_interface(
434 path->attached.fp_interface));
437 case FIB_PATH_TYPE_RECURSIVE:
438 if (FIB_PROTOCOL_MPLS == path->fp_nh_proto)
440 s = format (s, "via %U",
441 format_mpls_unicast_label,
442 path->recursive.fp_nh.fp_local_label);
446 s = format (s, "via %U",
448 &path->recursive.fp_nh.fp_ip,
451 s = format (s, " in fib:%d",
452 path->recursive.fp_tbl_id,
454 s = format (s, " via-fib:%d", path->fp_via_fib);
455 s = format (s, " via-dpo:[%U:%d]",
456 format_dpo_type, path->fp_dpo.dpoi_type,
457 path->fp_dpo.dpoi_index);
460 case FIB_PATH_TYPE_RECEIVE:
461 case FIB_PATH_TYPE_SPECIAL:
462 case FIB_PATH_TYPE_DEAG:
463 case FIB_PATH_TYPE_EXCLUSIVE:
464 if (dpo_id_is_valid(&path->fp_dpo))
466 s = format(s, "%U", format_dpo_id,
475 fib_path_format (fib_node_index_t pi, u8 *s)
479 path = fib_path_get(pi);
480 ASSERT(NULL != path);
482 return (format (s, "%U", format_fib_path, path));
486 fib_path_adj_format (fib_node_index_t pi,
492 path = fib_path_get(pi);
493 ASSERT(NULL != path);
495 if (!dpo_id_is_valid(&path->fp_dpo))
497 s = format(s, " unresolved");
501 s = format(s, "%U", format_dpo_id,
509 * fib_path_last_lock_gone
511 * We don't share paths, we share path lists, so the [un]lock functions
515 fib_path_last_lock_gone (fib_node_t *node)
520 static const adj_index_t
521 fib_path_attached_next_hop_get_adj (fib_path_t *path,
524 if (vnet_sw_interface_is_p2p(vnet_get_main(),
525 path->attached_next_hop.fp_interface))
528 * if the interface is p2p then the adj for the specific
529 * neighbour on that link will never exist. on p2p links
530 * the subnet address (the attached route) links to the
531 * auto-adj (see below), we want that adj here too.
533 return (adj_nbr_add_or_lock(path->fp_nh_proto,
536 path->attached_next_hop.fp_interface));
540 return (adj_nbr_add_or_lock(path->fp_nh_proto,
542 &path->attached_next_hop.fp_nh,
543 path->attached_next_hop.fp_interface));
548 fib_path_attached_next_hop_set (fib_path_t *path)
551 * resolve directly via the adjacnecy discribed by the
552 * interface and next-hop
554 if (!vnet_sw_interface_is_admin_up(vnet_get_main(),
555 path->attached_next_hop.fp_interface))
557 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
560 dpo_set(&path->fp_dpo,
562 fib_proto_to_dpo(path->fp_nh_proto),
563 fib_path_attached_next_hop_get_adj(
565 fib_proto_to_link(path->fp_nh_proto)));
568 * become a child of the adjacency so we receive updates
569 * when its rewrite changes
571 path->fp_sibling = adj_child_add(path->fp_dpo.dpoi_index,
573 fib_path_get_index(path));
577 * create of update the paths recursive adj
580 fib_path_recursive_adj_update (fib_path_t *path,
581 fib_forward_chain_type_t fct,
584 dpo_id_t via_dpo = DPO_INVALID;
587 * get the DPO to resolve through from the via-entry
589 fib_entry_contribute_forwarding(path->fp_via_fib,
595 * hope for the best - clear if restrictions apply.
597 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RESOLVED;
600 * Validate any recursion constraints and over-ride the via
603 if (path->fp_oper_flags & FIB_PATH_OPER_FLAG_RECURSIVE_LOOP)
605 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
606 dpo_copy(&via_dpo, drop_dpo_get(fib_proto_to_dpo(path->fp_nh_proto)));
608 else if (path->fp_cfg_flags & FIB_PATH_CFG_FLAG_RESOLVE_HOST)
611 * the via FIB must be a host route.
612 * note the via FIB just added will always be a host route
613 * since it is an RR source added host route. So what we need to
614 * check is whether the route has other sources. If it does then
615 * some other source has added it as a host route. If it doesn't
616 * then it was added only here and inherits forwarding from a cover.
617 * the cover is not a host route.
618 * The RR source is the lowest priority source, so we check if it
619 * is the best. if it is there are no other sources.
621 if (fib_entry_get_best_source(path->fp_via_fib) >= FIB_SOURCE_RR)
623 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
624 dpo_copy(&via_dpo, drop_dpo_get(fib_proto_to_dpo(path->fp_nh_proto)));
627 * PIC edge trigger. let the load-balance maps know
629 load_balance_map_path_state_change(fib_path_get_index(path));
632 else if (path->fp_cfg_flags & FIB_PATH_CFG_FLAG_RESOLVE_ATTACHED)
635 * RR source entries inherit the flags from the cover, so
636 * we can check the via directly
638 if (!(FIB_ENTRY_FLAG_ATTACHED & fib_entry_get_flags(path->fp_via_fib)))
640 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
641 dpo_copy(&via_dpo, drop_dpo_get(fib_proto_to_dpo(path->fp_nh_proto)));
644 * PIC edge trigger. let the load-balance maps know
646 load_balance_map_path_state_change(fib_path_get_index(path));
651 * update the path's contributed DPO
653 dpo_copy(dpo, &via_dpo);
655 FIB_PATH_DBG(path, "recursive update: %U",
656 fib_get_lookup_main(path->fp_nh_proto),
663 * fib_path_is_permanent_drop
665 * Return !0 if the path is configured to permanently drop,
666 * despite other attributes.
669 fib_path_is_permanent_drop (fib_path_t *path)
671 return ((path->fp_cfg_flags & FIB_PATH_CFG_FLAG_DROP) ||
672 (path->fp_oper_flags & FIB_PATH_OPER_FLAG_DROP));
678 * Remove our dependency on the resolution target
681 fib_path_unresolve (fib_path_t *path)
684 * the forced drop path does not need unresolving
686 if (fib_path_is_permanent_drop(path))
691 switch (path->fp_type)
693 case FIB_PATH_TYPE_RECURSIVE:
694 if (FIB_NODE_INDEX_INVALID != path->fp_via_fib)
698 fib_entry_get_prefix(path->fp_via_fib, &pfx);
699 fib_entry_child_remove(path->fp_via_fib,
701 fib_table_entry_special_remove(path->recursive.fp_tbl_id,
704 path->fp_via_fib = FIB_NODE_INDEX_INVALID;
707 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
708 case FIB_PATH_TYPE_ATTACHED:
709 adj_child_remove(path->fp_dpo.dpoi_index,
711 adj_unlock(path->fp_dpo.dpoi_index);
713 case FIB_PATH_TYPE_EXCLUSIVE:
714 dpo_reset(&path->exclusive.fp_ex_dpo);
716 case FIB_PATH_TYPE_SPECIAL:
717 case FIB_PATH_TYPE_RECEIVE:
718 case FIB_PATH_TYPE_DEAG:
720 * these hold only the path's DPO, which is reset below.
726 * release the adj we were holding and pick up the
729 dpo_reset(&path->fp_dpo);
730 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
735 static fib_forward_chain_type_t
736 fib_path_proto_to_chain_type (fib_protocol_t proto)
740 case FIB_PROTOCOL_IP4:
741 return (FIB_FORW_CHAIN_TYPE_UNICAST_IP4);
742 case FIB_PROTOCOL_IP6:
743 return (FIB_FORW_CHAIN_TYPE_UNICAST_IP6);
744 case FIB_PROTOCOL_MPLS:
745 return (FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS);
747 return (FIB_FORW_CHAIN_TYPE_UNICAST_IP4);
751 * fib_path_back_walk_notify
753 * A back walk has reach this path.
755 static fib_node_back_walk_rc_t
756 fib_path_back_walk_notify (fib_node_t *node,
757 fib_node_back_walk_ctx_t *ctx)
761 path = fib_path_from_fib_node(node);
763 switch (path->fp_type)
765 case FIB_PATH_TYPE_RECURSIVE:
766 if (FIB_NODE_BW_REASON_FLAG_EVALUATE & ctx->fnbw_reason)
769 * modify the recursive adjacency to use the new forwarding
771 * this update is visible to packets in flight in the DP.
773 fib_path_recursive_adj_update(
775 fib_path_proto_to_chain_type(path->fp_nh_proto),
778 if ((FIB_NODE_BW_REASON_FLAG_ADJ_UPDATE & ctx->fnbw_reason) ||
779 (FIB_NODE_BW_REASON_FLAG_ADJ_DOWN & ctx->fnbw_reason))
782 * ADJ updates (complete<->incomplete) do not need to propagate to
784 * The only reason its needed as far back as here, is that the adj
785 * and the incomplete adj are a different DPO type, so the LBs need
787 * If this walk was quashed in the fib_entry, then any non-fib_path
788 * children (like tunnels that collapse out the LB when they stack)
789 * would not see the update.
791 return (FIB_NODE_BACK_WALK_CONTINUE);
794 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
797 * ADJ_UPDATE backwalk pass silently through here and up to
798 * the path-list when the multipath adj collapse occurs.
799 * The reason we do this is that the assumtption is that VPP
800 * runs in an environment where the Control-Plane is remote
801 * and hence reacts slowly to link up down. In order to remove
802 * this down link from the ECMP set quickly, we back-walk.
803 * VPP also has dedicated CPUs, so we are not stealing resources
804 * from the CP to do so.
806 if (FIB_NODE_BW_REASON_FLAG_INTERFACE_UP & ctx->fnbw_reason)
808 if (path->fp_oper_flags & FIB_PATH_OPER_FLAG_RESOLVED)
811 * alreday resolved. no need to walk back again
813 return (FIB_NODE_BACK_WALK_CONTINUE);
815 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RESOLVED;
817 if (FIB_NODE_BW_REASON_FLAG_INTERFACE_DOWN & ctx->fnbw_reason)
819 if (!(path->fp_oper_flags & FIB_PATH_OPER_FLAG_RESOLVED))
822 * alreday unresolved. no need to walk back again
824 return (FIB_NODE_BACK_WALK_CONTINUE);
826 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
828 if (FIB_NODE_BW_REASON_FLAG_INTERFACE_DELETE & ctx->fnbw_reason)
831 * The interface this path resolves through has been deleted.
832 * This will leave the path in a permanent drop state. The route
833 * needs to be removed and readded (and hence the path-list deleted)
834 * before it can forward again.
836 fib_path_unresolve(path);
837 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_DROP;
839 if (FIB_NODE_BW_REASON_FLAG_ADJ_UPDATE & ctx->fnbw_reason)
842 * restack the DPO to pick up the correct DPO sub-type
847 if_is_up = vnet_sw_interface_is_admin_up(
849 path->attached_next_hop.fp_interface);
853 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RESOLVED;
856 ai = fib_path_attached_next_hop_get_adj(
858 fib_proto_to_link(path->fp_nh_proto));
860 dpo_set(&path->fp_dpo, DPO_ADJACENCY,
861 fib_proto_to_dpo(path->fp_nh_proto),
868 * If the interface is not up there is no reason to walk
869 * back to children. if we did they would only evalute
870 * that this path is unresolved and hence it would
871 * not contribute the adjacency - so it would be wasted
874 return (FIB_NODE_BACK_WALK_CONTINUE);
877 if (FIB_NODE_BW_REASON_FLAG_ADJ_DOWN & ctx->fnbw_reason)
879 if (!(path->fp_oper_flags & FIB_PATH_OPER_FLAG_RESOLVED))
882 * alreday unresolved. no need to walk back again
884 return (FIB_NODE_BACK_WALK_CONTINUE);
887 * the adj has gone down. the path is no longer resolved.
889 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
892 case FIB_PATH_TYPE_ATTACHED:
894 * FIXME; this could schedule a lower priority walk, since attached
895 * routes are not usually in ECMP configurations so the backwalk to
896 * the FIB entry does not need to be high priority
898 if (FIB_NODE_BW_REASON_FLAG_INTERFACE_UP & ctx->fnbw_reason)
900 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RESOLVED;
902 if (FIB_NODE_BW_REASON_FLAG_INTERFACE_DOWN & ctx->fnbw_reason)
904 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
906 if (FIB_NODE_BW_REASON_FLAG_INTERFACE_DELETE & ctx->fnbw_reason)
908 fib_path_unresolve(path);
909 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_DROP;
912 case FIB_PATH_TYPE_DEAG:
914 * FIXME When VRF delete is allowed this will need a poke.
916 case FIB_PATH_TYPE_SPECIAL:
917 case FIB_PATH_TYPE_RECEIVE:
918 case FIB_PATH_TYPE_EXCLUSIVE:
920 * these path types have no parents. so to be
921 * walked from one is unexpected.
928 * propagate the backwalk further to the path-list
930 fib_path_list_back_walk(path->fp_pl_index, ctx);
932 return (FIB_NODE_BACK_WALK_CONTINUE);
936 fib_path_memory_show (void)
938 fib_show_memory_usage("Path",
939 pool_elts(fib_path_pool),
940 pool_len(fib_path_pool),
945 * The FIB path's graph node virtual function table
947 static const fib_node_vft_t fib_path_vft = {
948 .fnv_get = fib_path_get_node,
949 .fnv_last_lock = fib_path_last_lock_gone,
950 .fnv_back_walk = fib_path_back_walk_notify,
951 .fnv_mem_show = fib_path_memory_show,
954 static fib_path_cfg_flags_t
955 fib_path_route_flags_to_cfg_flags (const fib_route_path_t *rpath)
957 fib_path_cfg_flags_t cfg_flags = FIB_PATH_CFG_FLAG_NONE;
959 if (rpath->frp_flags & FIB_ROUTE_PATH_RESOLVE_VIA_HOST)
960 cfg_flags |= FIB_PATH_CFG_FLAG_RESOLVE_HOST;
961 if (rpath->frp_flags & FIB_ROUTE_PATH_RESOLVE_VIA_ATTACHED)
962 cfg_flags |= FIB_PATH_CFG_FLAG_RESOLVE_ATTACHED;
970 * Create and initialise a new path object.
971 * return the index of the path.
974 fib_path_create (fib_node_index_t pl_index,
975 fib_protocol_t nh_proto,
976 fib_path_cfg_flags_t flags,
977 const fib_route_path_t *rpath)
981 pool_get(fib_path_pool, path);
982 memset(path, 0, sizeof(*path));
984 fib_node_init(&path->fp_node,
987 dpo_reset(&path->fp_dpo);
988 path->fp_pl_index = pl_index;
989 path->fp_nh_proto = nh_proto;
990 path->fp_via_fib = FIB_NODE_INDEX_INVALID;
991 path->fp_weight = rpath->frp_weight;
992 if (0 == path->fp_weight)
995 * a weight of 0 is a meaningless value. We could either reject it, and thus force
996 * clients to always use 1, or we can accept it and fixup approrpiately.
1000 path->fp_cfg_flags = flags;
1001 path->fp_cfg_flags |= fib_path_route_flags_to_cfg_flags(rpath);
1004 * deduce the path's tpye from the parementers and save what is needed.
1006 if (~0 != rpath->frp_sw_if_index)
1008 if (flags & FIB_PATH_CFG_FLAG_LOCAL)
1010 path->fp_type = FIB_PATH_TYPE_RECEIVE;
1011 path->receive.fp_interface = rpath->frp_sw_if_index;
1012 path->receive.fp_addr = rpath->frp_addr;
1016 if (ip46_address_is_zero(&rpath->frp_addr))
1018 path->fp_type = FIB_PATH_TYPE_ATTACHED;
1019 path->attached.fp_interface = rpath->frp_sw_if_index;
1023 path->fp_type = FIB_PATH_TYPE_ATTACHED_NEXT_HOP;
1024 path->attached_next_hop.fp_interface = rpath->frp_sw_if_index;
1025 path->attached_next_hop.fp_nh = rpath->frp_addr;
1031 if (ip46_address_is_zero(&rpath->frp_addr))
1033 if (~0 == rpath->frp_fib_index)
1035 path->fp_type = FIB_PATH_TYPE_SPECIAL;
1039 path->fp_type = FIB_PATH_TYPE_DEAG;
1040 path->deag.fp_tbl_id = rpath->frp_fib_index;
1045 path->fp_type = FIB_PATH_TYPE_RECURSIVE;
1046 if (FIB_PROTOCOL_MPLS == path->fp_nh_proto)
1048 path->recursive.fp_nh.fp_local_label = rpath->frp_local_label;
1052 path->recursive.fp_nh.fp_ip = rpath->frp_addr;
1054 path->recursive.fp_tbl_id = rpath->frp_fib_index;
1058 FIB_PATH_DBG(path, "create");
1060 return (fib_path_get_index(path));
1064 * fib_path_create_special
1066 * Create and initialise a new path object.
1067 * return the index of the path.
1070 fib_path_create_special (fib_node_index_t pl_index,
1071 fib_protocol_t nh_proto,
1072 fib_path_cfg_flags_t flags,
1073 const dpo_id_t *dpo)
1077 pool_get(fib_path_pool, path);
1078 memset(path, 0, sizeof(*path));
1080 fib_node_init(&path->fp_node,
1081 FIB_NODE_TYPE_PATH);
1082 dpo_reset(&path->fp_dpo);
1084 path->fp_pl_index = pl_index;
1085 path->fp_weight = 1;
1086 path->fp_nh_proto = nh_proto;
1087 path->fp_via_fib = FIB_NODE_INDEX_INVALID;
1088 path->fp_cfg_flags = flags;
1090 if (FIB_PATH_CFG_FLAG_DROP & flags)
1092 path->fp_type = FIB_PATH_TYPE_SPECIAL;
1094 else if (FIB_PATH_CFG_FLAG_LOCAL & flags)
1096 path->fp_type = FIB_PATH_TYPE_RECEIVE;
1097 path->attached.fp_interface = FIB_NODE_INDEX_INVALID;
1101 path->fp_type = FIB_PATH_TYPE_EXCLUSIVE;
1102 ASSERT(NULL != dpo);
1103 dpo_copy(&path->exclusive.fp_ex_dpo, dpo);
1106 return (fib_path_get_index(path));
1112 * Copy a path. return index of new path.
1115 fib_path_copy (fib_node_index_t path_index,
1116 fib_node_index_t path_list_index)
1118 fib_path_t *path, *orig_path;
1120 pool_get(fib_path_pool, path);
1122 orig_path = fib_path_get(path_index);
1123 ASSERT(NULL != orig_path);
1125 memcpy(path, orig_path, sizeof(*path));
1127 FIB_PATH_DBG(path, "create-copy:%d", path_index);
1130 * reset the dynamic section
1132 fib_node_init(&path->fp_node, FIB_NODE_TYPE_PATH);
1133 path->fp_oper_flags = FIB_PATH_OPER_FLAG_NONE;
1134 path->fp_pl_index = path_list_index;
1135 path->fp_via_fib = FIB_NODE_INDEX_INVALID;
1136 memset(&path->fp_dpo, 0, sizeof(path->fp_dpo));
1137 dpo_reset(&path->fp_dpo);
1139 return (fib_path_get_index(path));
1145 * destroy a path that is no longer required
1148 fib_path_destroy (fib_node_index_t path_index)
1152 path = fib_path_get(path_index);
1154 ASSERT(NULL != path);
1155 FIB_PATH_DBG(path, "destroy");
1157 fib_path_unresolve(path);
1159 fib_node_deinit(&path->fp_node);
1160 pool_put(fib_path_pool, path);
1166 * destroy a path that is no longer required
1169 fib_path_hash (fib_node_index_t path_index)
1173 path = fib_path_get(path_index);
1175 return (hash_memory(STRUCT_MARK_PTR(path, path_hash_start),
1176 (STRUCT_OFFSET_OF(fib_path_t, path_hash_end) -
1177 STRUCT_OFFSET_OF(fib_path_t, path_hash_start)),
1184 * Compare two paths for equivalence.
1187 fib_path_cmp_i (const fib_path_t *path1,
1188 const fib_path_t *path2)
1195 * paths of different types and protocol are not equal.
1196 * different weights only are the same path.
1198 if (path1->fp_type != path2->fp_type)
1200 res = (path1->fp_type - path2->fp_type);
1202 if (path1->fp_nh_proto != path2->fp_nh_proto)
1204 res = (path1->fp_nh_proto - path2->fp_nh_proto);
1209 * both paths are of the same type.
1210 * consider each type and its attributes in turn.
1212 switch (path1->fp_type)
1214 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1215 res = ip46_address_cmp(&path1->attached_next_hop.fp_nh,
1216 &path2->attached_next_hop.fp_nh);
1218 res = vnet_sw_interface_compare(
1220 path1->attached_next_hop.fp_interface,
1221 path2->attached_next_hop.fp_interface);
1224 case FIB_PATH_TYPE_ATTACHED:
1225 res = vnet_sw_interface_compare(
1227 path1->attached.fp_interface,
1228 path2->attached.fp_interface);
1230 case FIB_PATH_TYPE_RECURSIVE:
1231 res = ip46_address_cmp(&path1->recursive.fp_nh,
1232 &path2->recursive.fp_nh);
1236 res = (path1->recursive.fp_tbl_id - path2->recursive.fp_tbl_id);
1239 case FIB_PATH_TYPE_DEAG:
1240 res = (path1->deag.fp_tbl_id - path2->deag.fp_tbl_id);
1242 case FIB_PATH_TYPE_SPECIAL:
1243 case FIB_PATH_TYPE_RECEIVE:
1244 case FIB_PATH_TYPE_EXCLUSIVE:
1253 * fib_path_cmp_for_sort
1255 * Compare two paths for equivalence. Used during path sorting.
1256 * As usual 0 means equal.
1259 fib_path_cmp_for_sort (void * v1,
1262 fib_node_index_t *pi1 = v1, *pi2 = v2;
1263 fib_path_t *path1, *path2;
1265 path1 = fib_path_get(*pi1);
1266 path2 = fib_path_get(*pi2);
1268 return (fib_path_cmp_i(path1, path2));
1274 * Compare two paths for equivalence.
1277 fib_path_cmp (fib_node_index_t pi1,
1278 fib_node_index_t pi2)
1280 fib_path_t *path1, *path2;
1282 path1 = fib_path_get(pi1);
1283 path2 = fib_path_get(pi2);
1285 return (fib_path_cmp_i(path1, path2));
1289 fib_path_cmp_w_route_path (fib_node_index_t path_index,
1290 const fib_route_path_t *rpath)
1295 path = fib_path_get(path_index);
1299 if (path->fp_weight != rpath->frp_weight)
1301 res = (path->fp_weight - rpath->frp_weight);
1306 * both paths are of the same type.
1307 * consider each type and its attributes in turn.
1309 switch (path->fp_type)
1311 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1312 res = ip46_address_cmp(&path->attached_next_hop.fp_nh,
1316 res = vnet_sw_interface_compare(
1318 path->attached_next_hop.fp_interface,
1319 rpath->frp_sw_if_index);
1322 case FIB_PATH_TYPE_ATTACHED:
1323 res = vnet_sw_interface_compare(
1325 path->attached.fp_interface,
1326 rpath->frp_sw_if_index);
1328 case FIB_PATH_TYPE_RECURSIVE:
1329 if (FIB_PROTOCOL_MPLS == path->fp_nh_proto)
1331 res = path->recursive.fp_nh.fp_local_label - rpath->frp_local_label;
1335 res = ip46_address_cmp(&path->recursive.fp_nh.fp_ip,
1341 res = (path->recursive.fp_tbl_id - rpath->frp_fib_index);
1344 case FIB_PATH_TYPE_DEAG:
1345 res = (path->deag.fp_tbl_id - rpath->frp_fib_index);
1347 case FIB_PATH_TYPE_SPECIAL:
1348 case FIB_PATH_TYPE_RECEIVE:
1349 case FIB_PATH_TYPE_EXCLUSIVE:
1358 * fib_path_recursive_loop_detect
1360 * A forward walk of the FIB object graph to detect for a cycle/loop. This
1361 * walk is initiated when an entry is linking to a new path list or from an old.
1362 * The entry vector passed contains all the FIB entrys that are children of this
1363 * path (it is all the entries encountered on the walk so far). If this vector
1364 * contains the entry this path resolve via, then a loop is about to form.
1365 * The loop must be allowed to form, since we need the dependencies in place
1366 * so that we can track when the loop breaks.
1367 * However, we MUST not produce a loop in the forwarding graph (else packets
1368 * would loop around the switch path until the loop breaks), so we mark recursive
1369 * paths as looped so that they do not contribute forwarding information.
1370 * By marking the path as looped, an etry such as;
1372 * via a.a.a.a (looped)
1373 * via b.b.b.b (not looped)
1374 * can still forward using the info provided by b.b.b.b only
1377 fib_path_recursive_loop_detect (fib_node_index_t path_index,
1378 fib_node_index_t **entry_indicies)
1382 path = fib_path_get(path_index);
1385 * the forced drop path is never looped, cos it is never resolved.
1387 if (fib_path_is_permanent_drop(path))
1392 switch (path->fp_type)
1394 case FIB_PATH_TYPE_RECURSIVE:
1396 fib_node_index_t *entry_index, *entries;
1398 entries = *entry_indicies;
1400 vec_foreach(entry_index, entries) {
1401 if (*entry_index == path->fp_via_fib)
1404 * the entry that is about to link to this path-list (or
1405 * one of this path-list's children) is the same entry that
1406 * this recursive path resolves through. this is a cycle.
1416 FIB_PATH_DBG(path, "recursive loop formed");
1417 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RECURSIVE_LOOP;
1419 dpo_copy(&path->fp_dpo,
1420 drop_dpo_get(fib_proto_to_dpo(path->fp_nh_proto)));
1425 * no loop here yet. keep forward walking the graph.
1427 if (fib_entry_recursive_loop_detect(path->fp_via_fib, entry_indicies))
1429 FIB_PATH_DBG(path, "recursive loop formed");
1430 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RECURSIVE_LOOP;
1434 FIB_PATH_DBG(path, "recursive loop cleared");
1435 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RECURSIVE_LOOP;
1440 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1441 case FIB_PATH_TYPE_ATTACHED:
1442 case FIB_PATH_TYPE_SPECIAL:
1443 case FIB_PATH_TYPE_DEAG:
1444 case FIB_PATH_TYPE_RECEIVE:
1445 case FIB_PATH_TYPE_EXCLUSIVE:
1447 * these path types cannot be part of a loop, since they are the leaves
1453 return (fib_path_is_looped(path_index));
1457 fib_path_resolve (fib_node_index_t path_index)
1461 path = fib_path_get(path_index);
1464 * hope for the best.
1466 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RESOLVED;
1469 * the forced drop path resolves via the drop adj
1471 if (fib_path_is_permanent_drop(path))
1473 dpo_copy(&path->fp_dpo,
1474 drop_dpo_get(fib_proto_to_dpo(path->fp_nh_proto)));
1475 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
1476 return (fib_path_is_resolved(path_index));
1479 switch (path->fp_type)
1481 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1482 fib_path_attached_next_hop_set(path);
1484 case FIB_PATH_TYPE_ATTACHED:
1486 * path->attached.fp_interface
1488 if (!vnet_sw_interface_is_admin_up(vnet_get_main(),
1489 path->attached.fp_interface))
1491 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
1493 if (vnet_sw_interface_is_p2p(vnet_get_main(),
1494 path->attached.fp_interface))
1497 * point-2-point interfaces do not require a glean, since
1498 * there is nothing to ARP. Install a rewrite/nbr adj instead
1500 dpo_set(&path->fp_dpo,
1502 fib_proto_to_dpo(path->fp_nh_proto),
1503 adj_nbr_add_or_lock(
1505 fib_proto_to_link(path->fp_nh_proto),
1507 path->attached.fp_interface));
1511 dpo_set(&path->fp_dpo,
1512 DPO_ADJACENCY_GLEAN,
1513 fib_proto_to_dpo(path->fp_nh_proto),
1514 adj_glean_add_or_lock(path->fp_nh_proto,
1515 path->attached.fp_interface,
1519 * become a child of the adjacency so we receive updates
1520 * when the interface state changes
1522 path->fp_sibling = adj_child_add(path->fp_dpo.dpoi_index,
1524 fib_path_get_index(path));
1527 case FIB_PATH_TYPE_RECURSIVE:
1530 * Create a RR source entry in the table for the address
1531 * that this path recurses through.
1532 * This resolve action is recursive, hence we may create
1533 * more paths in the process. more creates mean maybe realloc
1536 fib_node_index_t fei;
1539 ASSERT(FIB_NODE_INDEX_INVALID == path->fp_via_fib);
1541 if (FIB_PROTOCOL_MPLS == path->fp_nh_proto)
1543 fib_prefix_from_mpls_label(path->recursive.fp_nh.fp_local_label, &pfx);
1547 fib_prefix_from_ip46_addr(&path->recursive.fp_nh.fp_ip, &pfx);
1550 fei = fib_table_entry_special_add(path->recursive.fp_tbl_id,
1553 FIB_ENTRY_FLAG_NONE,
1556 path = fib_path_get(path_index);
1557 path->fp_via_fib = fei;
1560 * become a dependent child of the entry so the path is
1561 * informed when the forwarding for the entry changes.
1563 path->fp_sibling = fib_entry_child_add(path->fp_via_fib,
1565 fib_path_get_index(path));
1568 * create and configure the IP DPO
1570 fib_path_recursive_adj_update(
1572 fib_path_proto_to_chain_type(path->fp_nh_proto),
1577 case FIB_PATH_TYPE_SPECIAL:
1579 * Resolve via the drop
1581 dpo_copy(&path->fp_dpo,
1582 drop_dpo_get(fib_proto_to_dpo(path->fp_nh_proto)));
1584 case FIB_PATH_TYPE_DEAG:
1586 * Resolve via a lookup DPO.
1587 * FIXME. control plane should add routes with a table ID
1589 lookup_dpo_add_or_lock_w_fib_index(path->deag.fp_tbl_id,
1590 fib_proto_to_dpo(path->fp_nh_proto),
1591 LOOKUP_INPUT_DST_ADDR,
1592 LOOKUP_TABLE_FROM_CONFIG,
1595 case FIB_PATH_TYPE_RECEIVE:
1597 * Resolve via a receive DPO.
1599 receive_dpo_add_or_lock(fib_proto_to_dpo(path->fp_nh_proto),
1600 path->receive.fp_interface,
1601 &path->receive.fp_addr,
1604 case FIB_PATH_TYPE_EXCLUSIVE:
1606 * Resolve via the user provided DPO
1608 dpo_copy(&path->fp_dpo, &path->exclusive.fp_ex_dpo);
1612 return (fib_path_is_resolved(path_index));
1616 fib_path_get_resolving_interface (fib_node_index_t path_index)
1620 path = fib_path_get(path_index);
1622 switch (path->fp_type)
1624 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1625 return (path->attached_next_hop.fp_interface);
1626 case FIB_PATH_TYPE_ATTACHED:
1627 return (path->attached.fp_interface);
1628 case FIB_PATH_TYPE_RECEIVE:
1629 return (path->receive.fp_interface);
1630 case FIB_PATH_TYPE_RECURSIVE:
1631 return (fib_entry_get_resolving_interface(path->fp_via_fib));
1632 case FIB_PATH_TYPE_SPECIAL:
1633 case FIB_PATH_TYPE_DEAG:
1634 case FIB_PATH_TYPE_EXCLUSIVE:
1641 fib_path_get_adj (fib_node_index_t path_index)
1645 path = fib_path_get(path_index);
1647 ASSERT(dpo_is_adj(&path->fp_dpo));
1648 if (dpo_is_adj(&path->fp_dpo))
1650 return (path->fp_dpo.dpoi_index);
1652 return (ADJ_INDEX_INVALID);
1656 fib_path_get_weight (fib_node_index_t path_index)
1660 path = fib_path_get(path_index);
1664 return (path->fp_weight);
1668 * @brief Contribute the path's adjacency to the list passed.
1669 * By calling this function over all paths, recursively, a child
1670 * can construct its full set of forwarding adjacencies, and hence its
1674 fib_path_contribute_urpf (fib_node_index_t path_index,
1679 if (!fib_path_is_resolved(path_index))
1682 path = fib_path_get(path_index);
1684 switch (path->fp_type)
1686 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1687 fib_urpf_list_append(urpf, path->attached_next_hop.fp_interface);
1690 case FIB_PATH_TYPE_ATTACHED:
1691 fib_urpf_list_append(urpf, path->attached.fp_interface);
1694 case FIB_PATH_TYPE_RECURSIVE:
1695 fib_entry_contribute_urpf(path->fp_via_fib, urpf);
1698 case FIB_PATH_TYPE_EXCLUSIVE:
1699 case FIB_PATH_TYPE_SPECIAL:
1701 * these path types may link to an adj, if that's what
1704 if (dpo_is_adj(&path->fp_dpo))
1706 ip_adjacency_t *adj;
1708 adj = adj_get(path->fp_dpo.dpoi_index);
1710 fib_urpf_list_append(urpf, adj->rewrite_header.sw_if_index);
1714 case FIB_PATH_TYPE_DEAG:
1715 case FIB_PATH_TYPE_RECEIVE:
1717 * these path types don't link to an adj
1724 fib_path_contribute_forwarding (fib_node_index_t path_index,
1725 fib_forward_chain_type_t fct,
1730 path = fib_path_get(path_index);
1733 ASSERT(FIB_FORW_CHAIN_TYPE_MPLS_EOS != fct);
1735 FIB_PATH_DBG(path, "contribute");
1738 * The DPO stored in the path was created when the path was resolved.
1739 * This then represents the path's 'native' protocol; IP.
1740 * For all others will need to go find something else.
1742 if (fib_path_proto_to_chain_type(path->fp_nh_proto) == fct)
1744 dpo_copy(dpo, &path->fp_dpo);
1748 switch (path->fp_type)
1750 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1753 case FIB_FORW_CHAIN_TYPE_UNICAST_IP4:
1754 case FIB_FORW_CHAIN_TYPE_UNICAST_IP6:
1755 case FIB_FORW_CHAIN_TYPE_MPLS_EOS:
1756 case FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS:
1757 case FIB_FORW_CHAIN_TYPE_ETHERNET:
1762 * get a appropriate link type adj.
1764 ai = fib_path_attached_next_hop_get_adj(
1766 fib_forw_chain_type_to_link_type(fct));
1767 dpo_set(dpo, DPO_ADJACENCY,
1768 fib_forw_chain_type_to_dpo_proto(fct), ai);
1775 case FIB_PATH_TYPE_RECURSIVE:
1778 case FIB_FORW_CHAIN_TYPE_MPLS_EOS:
1779 case FIB_FORW_CHAIN_TYPE_UNICAST_IP4:
1780 case FIB_FORW_CHAIN_TYPE_UNICAST_IP6:
1781 case FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS:
1782 fib_path_recursive_adj_update(path, fct, dpo);
1784 case FIB_FORW_CHAIN_TYPE_ETHERNET:
1789 case FIB_PATH_TYPE_DEAG:
1792 case FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS:
1793 lookup_dpo_add_or_lock_w_table_id(MPLS_FIB_DEFAULT_TABLE_ID,
1795 LOOKUP_INPUT_DST_ADDR,
1796 LOOKUP_TABLE_FROM_CONFIG,
1799 case FIB_FORW_CHAIN_TYPE_UNICAST_IP4:
1800 case FIB_FORW_CHAIN_TYPE_UNICAST_IP6:
1801 case FIB_FORW_CHAIN_TYPE_MPLS_EOS:
1802 dpo_copy(dpo, &path->fp_dpo);
1804 case FIB_FORW_CHAIN_TYPE_ETHERNET:
1809 case FIB_PATH_TYPE_EXCLUSIVE:
1810 dpo_copy(dpo, &path->exclusive.fp_ex_dpo);
1812 case FIB_PATH_TYPE_ATTACHED:
1813 case FIB_PATH_TYPE_RECEIVE:
1814 case FIB_PATH_TYPE_SPECIAL:
1822 load_balance_path_t *
1823 fib_path_append_nh_for_multipath_hash (fib_node_index_t path_index,
1824 fib_forward_chain_type_t fct,
1825 load_balance_path_t *hash_key)
1827 load_balance_path_t *mnh;
1830 path = fib_path_get(path_index);
1834 if (fib_path_is_resolved(path_index))
1836 vec_add2(hash_key, mnh, 1);
1838 mnh->path_weight = path->fp_weight;
1839 mnh->path_index = path_index;
1840 fib_path_contribute_forwarding(path_index, fct, &mnh->path_dpo);
1847 fib_path_is_recursive (fib_node_index_t path_index)
1851 path = fib_path_get(path_index);
1853 return (FIB_PATH_TYPE_RECURSIVE == path->fp_type);
1857 fib_path_is_exclusive (fib_node_index_t path_index)
1861 path = fib_path_get(path_index);
1863 return (FIB_PATH_TYPE_EXCLUSIVE == path->fp_type);
1867 fib_path_is_deag (fib_node_index_t path_index)
1871 path = fib_path_get(path_index);
1873 return (FIB_PATH_TYPE_DEAG == path->fp_type);
1877 fib_path_is_resolved (fib_node_index_t path_index)
1881 path = fib_path_get(path_index);
1883 return (dpo_id_is_valid(&path->fp_dpo) &&
1884 (path->fp_oper_flags & FIB_PATH_OPER_FLAG_RESOLVED) &&
1885 !fib_path_is_looped(path_index) &&
1886 !fib_path_is_permanent_drop(path));
1890 fib_path_is_looped (fib_node_index_t path_index)
1894 path = fib_path_get(path_index);
1896 return (path->fp_oper_flags & FIB_PATH_OPER_FLAG_RECURSIVE_LOOP);
1900 fib_path_encode (fib_node_index_t path_list_index,
1901 fib_node_index_t path_index,
1904 fib_route_path_encode_t **api_rpaths = ctx;
1905 fib_route_path_encode_t *api_rpath;
1908 path = fib_path_get(path_index);
1911 vec_add2(*api_rpaths, api_rpath, 1);
1912 api_rpath->rpath.frp_weight = path->fp_weight;
1913 api_rpath->rpath.frp_proto = path->fp_nh_proto;
1914 api_rpath->rpath.frp_sw_if_index = ~0;
1915 api_rpath->dpo = path->exclusive.fp_ex_dpo;
1916 switch (path->fp_type)
1918 case FIB_PATH_TYPE_RECEIVE:
1919 api_rpath->rpath.frp_addr = path->receive.fp_addr;
1920 api_rpath->rpath.frp_sw_if_index = path->receive.fp_interface;
1922 case FIB_PATH_TYPE_ATTACHED:
1923 api_rpath->rpath.frp_sw_if_index = path->attached.fp_interface;
1925 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1926 api_rpath->rpath.frp_sw_if_index = path->attached_next_hop.fp_interface;
1927 api_rpath->rpath.frp_addr = path->attached_next_hop.fp_nh;
1929 case FIB_PATH_TYPE_SPECIAL:
1931 case FIB_PATH_TYPE_DEAG:
1933 case FIB_PATH_TYPE_RECURSIVE:
1934 api_rpath->rpath.frp_addr = path->recursive.fp_nh.fp_ip;
1943 fib_path_get_proto (fib_node_index_t path_index)
1947 path = fib_path_get(path_index);
1949 return (path->fp_nh_proto);
1953 fib_path_module_init (void)
1955 fib_node_register_type (FIB_NODE_TYPE_PATH, &fib_path_vft);
1958 static clib_error_t *
1959 show_fib_path_command (vlib_main_t * vm,
1960 unformat_input_t * input,
1961 vlib_cli_command_t * cmd)
1963 fib_node_index_t pi;
1966 if (unformat (input, "%d", &pi))
1969 * show one in detail
1971 if (!pool_is_free_index(fib_path_pool, pi))
1973 path = fib_path_get(pi);
1974 u8 *s = fib_path_format(pi, NULL);
1975 s = format(s, "children:");
1976 s = fib_node_children_format(path->fp_node.fn_children, s);
1977 vlib_cli_output (vm, "%s", s);
1982 vlib_cli_output (vm, "path %d invalid", pi);
1987 vlib_cli_output (vm, "FIB Paths");
1988 pool_foreach(path, fib_path_pool,
1990 vlib_cli_output (vm, "%U", format_fib_path, path);
1997 VLIB_CLI_COMMAND (show_fib_path, static) = {
1998 .path = "show fib paths",
1999 .function = show_fib_path_command,
2000 .short_help = "show fib paths",