2 * Copyright (c) 2016 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 #include <vlib/vlib.h>
17 #include <vnet/vnet.h>
18 #include <vnet/ip/format.h>
19 #include <vnet/ip/ip.h>
20 #include <vnet/dpo/drop_dpo.h>
21 #include <vnet/dpo/receive_dpo.h>
22 #include <vnet/dpo/load_balance_map.h>
23 #include <vnet/dpo/lookup_dpo.h>
25 #include <vnet/adj/adj.h>
26 #include <vnet/adj/adj_mcast.h>
28 #include <vnet/fib/fib_path.h>
29 #include <vnet/fib/fib_node.h>
30 #include <vnet/fib/fib_table.h>
31 #include <vnet/fib/fib_entry.h>
32 #include <vnet/fib/fib_path_list.h>
33 #include <vnet/fib/fib_internal.h>
34 #include <vnet/fib/fib_urpf_list.h>
37 * Enurmeration of path types
39 typedef enum fib_path_type_t_ {
41 * Marker. Add new types after this one.
43 FIB_PATH_TYPE_FIRST = 0,
45 * Attached-nexthop. An interface and a nexthop are known.
47 FIB_PATH_TYPE_ATTACHED_NEXT_HOP = FIB_PATH_TYPE_FIRST,
49 * attached. Only the interface is known.
51 FIB_PATH_TYPE_ATTACHED,
53 * recursive. Only the next-hop is known.
55 FIB_PATH_TYPE_RECURSIVE,
57 * special. nothing is known. so we drop.
59 FIB_PATH_TYPE_SPECIAL,
61 * exclusive. user provided adj.
63 FIB_PATH_TYPE_EXCLUSIVE,
65 * deag. Link to a lookup adj in the next table
69 * receive. it's for-us.
71 FIB_PATH_TYPE_RECEIVE,
73 * Marker. Add new types before this one, then update it.
75 FIB_PATH_TYPE_LAST = FIB_PATH_TYPE_RECEIVE,
76 } __attribute__ ((packed)) fib_path_type_t;
79 * The maximum number of path_types
81 #define FIB_PATH_TYPE_MAX (FIB_PATH_TYPE_LAST + 1)
83 #define FIB_PATH_TYPES { \
84 [FIB_PATH_TYPE_ATTACHED_NEXT_HOP] = "attached-nexthop", \
85 [FIB_PATH_TYPE_ATTACHED] = "attached", \
86 [FIB_PATH_TYPE_RECURSIVE] = "recursive", \
87 [FIB_PATH_TYPE_SPECIAL] = "special", \
88 [FIB_PATH_TYPE_EXCLUSIVE] = "exclusive", \
89 [FIB_PATH_TYPE_DEAG] = "deag", \
90 [FIB_PATH_TYPE_RECEIVE] = "receive", \
93 #define FOR_EACH_FIB_PATH_TYPE(_item) \
94 for (_item = FIB_PATH_TYPE_FIRST; _item <= FIB_PATH_TYPE_LAST; _item++)
97 * Enurmeration of path operational (i.e. derived) attributes
99 typedef enum fib_path_oper_attribute_t_ {
101 * Marker. Add new types after this one.
103 FIB_PATH_OPER_ATTRIBUTE_FIRST = 0,
105 * The path forms part of a recursive loop.
107 FIB_PATH_OPER_ATTRIBUTE_RECURSIVE_LOOP = FIB_PATH_OPER_ATTRIBUTE_FIRST,
109 * The path is resolved
111 FIB_PATH_OPER_ATTRIBUTE_RESOLVED,
113 * The path has become a permanent drop.
115 FIB_PATH_OPER_ATTRIBUTE_DROP,
117 * Marker. Add new types before this one, then update it.
119 FIB_PATH_OPER_ATTRIBUTE_LAST = FIB_PATH_OPER_ATTRIBUTE_DROP,
120 } __attribute__ ((packed)) fib_path_oper_attribute_t;
123 * The maximum number of path operational attributes
125 #define FIB_PATH_OPER_ATTRIBUTE_MAX (FIB_PATH_OPER_ATTRIBUTE_LAST + 1)
127 #define FIB_PATH_OPER_ATTRIBUTES { \
128 [FIB_PATH_OPER_ATTRIBUTE_RECURSIVE_LOOP] = "recursive-loop", \
129 [FIB_PATH_OPER_ATTRIBUTE_RESOLVED] = "resolved", \
130 [FIB_PATH_OPER_ATTRIBUTE_DROP] = "drop", \
133 #define FOR_EACH_FIB_PATH_OPER_ATTRIBUTE(_item) \
134 for (_item = FIB_PATH_OPER_ATTRIBUTE_FIRST; \
135 _item <= FIB_PATH_OPER_ATTRIBUTE_LAST; \
139 * Path flags from the attributes
141 typedef enum fib_path_oper_flags_t_ {
142 FIB_PATH_OPER_FLAG_NONE = 0,
143 FIB_PATH_OPER_FLAG_RECURSIVE_LOOP = (1 << FIB_PATH_OPER_ATTRIBUTE_RECURSIVE_LOOP),
144 FIB_PATH_OPER_FLAG_DROP = (1 << FIB_PATH_OPER_ATTRIBUTE_DROP),
145 FIB_PATH_OPER_FLAG_RESOLVED = (1 << FIB_PATH_OPER_ATTRIBUTE_RESOLVED),
146 } __attribute__ ((packed)) fib_path_oper_flags_t;
151 typedef struct fib_path_t_ {
153 * A path is a node in the FIB graph.
158 * The index of the path-list to which this path belongs
163 * This marks the start of the memory area used to hash
166 STRUCT_MARK(path_hash_start);
169 * Configuration Flags
171 fib_path_cfg_flags_t fp_cfg_flags;
174 * The type of the path. This is the selector for the union
176 fib_path_type_t fp_type;
179 * The protocol of the next-hop, i.e. the address family of the
180 * next-hop's address. We can't derive this from the address itself
181 * since the address can be all zeros
183 fib_protocol_t fp_nh_proto;
186 * UCMP [unnormalised] weigt
191 * per-type union of the data required to resolve the path
198 ip46_address_t fp_nh;
216 ip46_address_t fp_ip;
218 * The local label to resolve through.
220 mpls_label_t fp_local_label;
223 * The FIB table index in which to find the next-hop.
224 * This needs to be fixed. We should lookup the adjacencies in
225 * a separate table of adjacencies, rather than from the FIB.
226 * Two reasons I can think of:
228 * int ip addr Gig0 10.0.0.1/24
229 * ip route 10.0.0.2/32 via Gig1 192.168.1.2
230 * ip route 1.1.1.1/32 via Gig0 10.0.0.2
231 * this is perfectly valid.
232 * Packets addressed to 10.0.0.2 should be sent via Gig1.
233 * Packets address to 1.1.1.1 should be sent via Gig0.
234 * when we perform the adj resolution from the FIB for the path
235 * "via Gig0 10.0.0.2" the lookup will result in the route via Gig1
236 * and so we will pick up the adj via Gig1 - which was not what the
238 * - we can only return link-type IPv4 and so not the link-type MPLS.
239 * more on this in a later commit.
241 * The table ID should only belong to a recursive path and indicate
242 * which FIB should be used to resolve the next-hop.
244 fib_node_index_t fp_tbl_id;
248 * The FIB index in which to perfom the next lookup
250 fib_node_index_t fp_tbl_id;
256 * The user provided 'exclusive' DPO
262 * The interface on which the local address is configured
268 ip46_address_t fp_addr;
271 STRUCT_MARK(path_hash_end);
274 * Memebers in this last section represent information that is
275 * dervied during resolution. It should not be copied to new paths
282 fib_path_oper_flags_t fp_oper_flags;
285 * the resolving via fib. not part of the union, since it it not part
286 * of the path's hash.
288 fib_node_index_t fp_via_fib;
291 * The Data-path objects through which this path resolves for IP.
296 * the index of this path in the parent's child list.
302 * Array of strings/names for the path types and attributes
304 static const char *fib_path_type_names[] = FIB_PATH_TYPES;
305 static const char *fib_path_oper_attribute_names[] = FIB_PATH_OPER_ATTRIBUTES;
306 static const char *fib_path_cfg_attribute_names[] = FIB_PATH_CFG_ATTRIBUTES;
309 * The memory pool from which we allocate all the paths
311 static fib_path_t *fib_path_pool;
317 #define FIB_PATH_DBG(_p, _fmt, _args...) \
320 _tmp = fib_path_format(fib_path_get_index(_p), _tmp); \
321 clib_warning("path:[%d:%s]:" _fmt, \
322 fib_path_get_index(_p), _tmp, \
327 #define FIB_PATH_DBG(_p, _fmt, _args...)
331 fib_path_get (fib_node_index_t index)
333 return (pool_elt_at_index(fib_path_pool, index));
336 static fib_node_index_t
337 fib_path_get_index (fib_path_t *path)
339 return (path - fib_path_pool);
343 fib_path_get_node (fib_node_index_t index)
345 return ((fib_node_t*)fib_path_get(index));
349 fib_path_from_fib_node (fib_node_t *node)
352 ASSERT(FIB_NODE_TYPE_PATH == node->fn_type);
354 return ((fib_path_t*)node);
358 format_fib_path (u8 * s, va_list * args)
360 fib_path_t *path = va_arg (*args, fib_path_t *);
361 vnet_main_t * vnm = vnet_get_main();
362 fib_path_oper_attribute_t oattr;
363 fib_path_cfg_attribute_t cattr;
365 s = format (s, " index:%d ", fib_path_get_index(path));
366 s = format (s, "pl-index:%d ", path->fp_pl_index);
367 s = format (s, "%U ", format_fib_protocol, path->fp_nh_proto);
368 s = format (s, "weight=%d ", path->fp_weight);
369 s = format (s, "%s: ", fib_path_type_names[path->fp_type]);
370 if (FIB_PATH_OPER_FLAG_NONE != path->fp_oper_flags) {
371 s = format(s, " oper-flags:");
372 FOR_EACH_FIB_PATH_OPER_ATTRIBUTE(oattr) {
373 if ((1<<oattr) & path->fp_oper_flags) {
374 s = format (s, "%s,", fib_path_oper_attribute_names[oattr]);
378 if (FIB_PATH_CFG_FLAG_NONE != path->fp_cfg_flags) {
379 s = format(s, " cfg-flags:");
380 FOR_EACH_FIB_PATH_CFG_ATTRIBUTE(cattr) {
381 if ((1<<cattr) & path->fp_cfg_flags) {
382 s = format (s, "%s,", fib_path_cfg_attribute_names[cattr]);
386 s = format(s, "\n ");
388 switch (path->fp_type)
390 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
391 s = format (s, "%U", format_ip46_address,
392 &path->attached_next_hop.fp_nh,
394 if (path->fp_oper_flags & FIB_PATH_OPER_FLAG_DROP)
396 s = format (s, " if_index:%d", path->attached_next_hop.fp_interface);
400 s = format (s, " %U",
401 format_vnet_sw_interface_name,
403 vnet_get_sw_interface(
405 path->attached_next_hop.fp_interface));
406 if (vnet_sw_interface_is_p2p(vnet_get_main(),
407 path->attached_next_hop.fp_interface))
409 s = format (s, " (p2p)");
412 if (!dpo_id_is_valid(&path->fp_dpo))
414 s = format(s, "\n unresolved");
418 s = format(s, "\n %U",
423 case FIB_PATH_TYPE_ATTACHED:
424 if (path->fp_oper_flags & FIB_PATH_OPER_FLAG_DROP)
426 s = format (s, " if_index:%d", path->attached_next_hop.fp_interface);
430 s = format (s, " %U",
431 format_vnet_sw_interface_name,
433 vnet_get_sw_interface(
435 path->attached.fp_interface));
438 case FIB_PATH_TYPE_RECURSIVE:
439 if (FIB_PROTOCOL_MPLS == path->fp_nh_proto)
441 s = format (s, "via %U",
442 format_mpls_unicast_label,
443 path->recursive.fp_nh.fp_local_label);
447 s = format (s, "via %U",
449 &path->recursive.fp_nh.fp_ip,
452 s = format (s, " in fib:%d",
453 path->recursive.fp_tbl_id,
455 s = format (s, " via-fib:%d", path->fp_via_fib);
456 s = format (s, " via-dpo:[%U:%d]",
457 format_dpo_type, path->fp_dpo.dpoi_type,
458 path->fp_dpo.dpoi_index);
461 case FIB_PATH_TYPE_RECEIVE:
462 case FIB_PATH_TYPE_SPECIAL:
463 case FIB_PATH_TYPE_DEAG:
464 case FIB_PATH_TYPE_EXCLUSIVE:
465 if (dpo_id_is_valid(&path->fp_dpo))
467 s = format(s, "%U", format_dpo_id,
476 fib_path_format (fib_node_index_t pi, u8 *s)
480 path = fib_path_get(pi);
481 ASSERT(NULL != path);
483 return (format (s, "%U", format_fib_path, path));
487 fib_path_adj_format (fib_node_index_t pi,
493 path = fib_path_get(pi);
494 ASSERT(NULL != path);
496 if (!dpo_id_is_valid(&path->fp_dpo))
498 s = format(s, " unresolved");
502 s = format(s, "%U", format_dpo_id,
510 * fib_path_last_lock_gone
512 * We don't share paths, we share path lists, so the [un]lock functions
516 fib_path_last_lock_gone (fib_node_t *node)
521 static const adj_index_t
522 fib_path_attached_next_hop_get_adj (fib_path_t *path,
525 if (vnet_sw_interface_is_p2p(vnet_get_main(),
526 path->attached_next_hop.fp_interface))
529 * if the interface is p2p then the adj for the specific
530 * neighbour on that link will never exist. on p2p links
531 * the subnet address (the attached route) links to the
532 * auto-adj (see below), we want that adj here too.
534 return (adj_nbr_add_or_lock(path->fp_nh_proto,
537 path->attached_next_hop.fp_interface));
541 return (adj_nbr_add_or_lock(path->fp_nh_proto,
543 &path->attached_next_hop.fp_nh,
544 path->attached_next_hop.fp_interface));
549 fib_path_attached_next_hop_set (fib_path_t *path)
552 * resolve directly via the adjacnecy discribed by the
553 * interface and next-hop
555 if (!vnet_sw_interface_is_admin_up(vnet_get_main(),
556 path->attached_next_hop.fp_interface))
558 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
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));
578 * create of update the paths recursive adj
581 fib_path_recursive_adj_update (fib_path_t *path,
582 fib_forward_chain_type_t fct,
585 dpo_id_t via_dpo = DPO_INVALID;
588 * get the DPO to resolve through from the via-entry
590 fib_entry_contribute_forwarding(path->fp_via_fib,
596 * hope for the best - clear if restrictions apply.
598 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RESOLVED;
601 * Validate any recursion constraints and over-ride the via
604 if (path->fp_oper_flags & FIB_PATH_OPER_FLAG_RECURSIVE_LOOP)
606 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
607 dpo_copy(&via_dpo, drop_dpo_get(fib_proto_to_dpo(path->fp_nh_proto)));
609 else if (path->fp_cfg_flags & FIB_PATH_CFG_FLAG_RESOLVE_HOST)
612 * the via FIB must be a host route.
613 * note the via FIB just added will always be a host route
614 * since it is an RR source added host route. So what we need to
615 * check is whether the route has other sources. If it does then
616 * some other source has added it as a host route. If it doesn't
617 * then it was added only here and inherits forwarding from a cover.
618 * the cover is not a host route.
619 * The RR source is the lowest priority source, so we check if it
620 * is the best. if it is there are no other sources.
622 if (fib_entry_get_best_source(path->fp_via_fib) >= FIB_SOURCE_RR)
624 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
625 dpo_copy(&via_dpo, drop_dpo_get(fib_proto_to_dpo(path->fp_nh_proto)));
628 * PIC edge trigger. let the load-balance maps know
630 load_balance_map_path_state_change(fib_path_get_index(path));
633 else if (path->fp_cfg_flags & FIB_PATH_CFG_FLAG_RESOLVE_ATTACHED)
636 * RR source entries inherit the flags from the cover, so
637 * we can check the via directly
639 if (!(FIB_ENTRY_FLAG_ATTACHED & fib_entry_get_flags(path->fp_via_fib)))
641 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
642 dpo_copy(&via_dpo, drop_dpo_get(fib_proto_to_dpo(path->fp_nh_proto)));
645 * PIC edge trigger. let the load-balance maps know
647 load_balance_map_path_state_change(fib_path_get_index(path));
652 * update the path's contributed DPO
654 dpo_copy(dpo, &via_dpo);
656 FIB_PATH_DBG(path, "recursive update: %U",
657 fib_get_lookup_main(path->fp_nh_proto),
664 * fib_path_is_permanent_drop
666 * Return !0 if the path is configured to permanently drop,
667 * despite other attributes.
670 fib_path_is_permanent_drop (fib_path_t *path)
672 return ((path->fp_cfg_flags & FIB_PATH_CFG_FLAG_DROP) ||
673 (path->fp_oper_flags & FIB_PATH_OPER_FLAG_DROP));
679 * Remove our dependency on the resolution target
682 fib_path_unresolve (fib_path_t *path)
685 * the forced drop path does not need unresolving
687 if (fib_path_is_permanent_drop(path))
692 switch (path->fp_type)
694 case FIB_PATH_TYPE_RECURSIVE:
695 if (FIB_NODE_INDEX_INVALID != path->fp_via_fib)
699 fib_entry_get_prefix(path->fp_via_fib, &pfx);
700 fib_entry_child_remove(path->fp_via_fib,
702 fib_table_entry_special_remove(path->recursive.fp_tbl_id,
705 path->fp_via_fib = FIB_NODE_INDEX_INVALID;
708 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
709 case FIB_PATH_TYPE_ATTACHED:
710 adj_child_remove(path->fp_dpo.dpoi_index,
712 adj_unlock(path->fp_dpo.dpoi_index);
714 case FIB_PATH_TYPE_EXCLUSIVE:
715 dpo_reset(&path->exclusive.fp_ex_dpo);
717 case FIB_PATH_TYPE_SPECIAL:
718 case FIB_PATH_TYPE_RECEIVE:
719 case FIB_PATH_TYPE_DEAG:
721 * these hold only the path's DPO, which is reset below.
727 * release the adj we were holding and pick up the
730 dpo_reset(&path->fp_dpo);
731 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
736 static fib_forward_chain_type_t
737 fib_path_proto_to_chain_type (fib_protocol_t proto)
741 case FIB_PROTOCOL_IP4:
742 return (FIB_FORW_CHAIN_TYPE_UNICAST_IP4);
743 case FIB_PROTOCOL_IP6:
744 return (FIB_FORW_CHAIN_TYPE_UNICAST_IP6);
745 case FIB_PROTOCOL_MPLS:
746 return (FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS);
748 return (FIB_FORW_CHAIN_TYPE_UNICAST_IP4);
752 * fib_path_back_walk_notify
754 * A back walk has reach this path.
756 static fib_node_back_walk_rc_t
757 fib_path_back_walk_notify (fib_node_t *node,
758 fib_node_back_walk_ctx_t *ctx)
762 path = fib_path_from_fib_node(node);
764 switch (path->fp_type)
766 case FIB_PATH_TYPE_RECURSIVE:
767 if (FIB_NODE_BW_REASON_FLAG_EVALUATE & ctx->fnbw_reason)
770 * modify the recursive adjacency to use the new forwarding
772 * this update is visible to packets in flight in the DP.
774 fib_path_recursive_adj_update(
776 fib_path_proto_to_chain_type(path->fp_nh_proto),
779 if ((FIB_NODE_BW_REASON_FLAG_ADJ_UPDATE & ctx->fnbw_reason) ||
780 (FIB_NODE_BW_REASON_FLAG_ADJ_DOWN & ctx->fnbw_reason))
783 * ADJ updates (complete<->incomplete) do not need to propagate to
785 * The only reason its needed as far back as here, is that the adj
786 * and the incomplete adj are a different DPO type, so the LBs need
788 * If this walk was quashed in the fib_entry, then any non-fib_path
789 * children (like tunnels that collapse out the LB when they stack)
790 * would not see the update.
792 return (FIB_NODE_BACK_WALK_CONTINUE);
795 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
798 * ADJ_UPDATE backwalk pass silently through here and up to
799 * the path-list when the multipath adj collapse occurs.
800 * The reason we do this is that the assumtption is that VPP
801 * runs in an environment where the Control-Plane is remote
802 * and hence reacts slowly to link up down. In order to remove
803 * this down link from the ECMP set quickly, we back-walk.
804 * VPP also has dedicated CPUs, so we are not stealing resources
805 * from the CP to do so.
807 if (FIB_NODE_BW_REASON_FLAG_INTERFACE_UP & ctx->fnbw_reason)
809 if (path->fp_oper_flags & FIB_PATH_OPER_FLAG_RESOLVED)
812 * alreday resolved. no need to walk back again
814 return (FIB_NODE_BACK_WALK_CONTINUE);
816 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RESOLVED;
818 if (FIB_NODE_BW_REASON_FLAG_INTERFACE_DOWN & ctx->fnbw_reason)
820 if (!(path->fp_oper_flags & FIB_PATH_OPER_FLAG_RESOLVED))
823 * alreday unresolved. no need to walk back again
825 return (FIB_NODE_BACK_WALK_CONTINUE);
827 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
829 if (FIB_NODE_BW_REASON_FLAG_INTERFACE_DELETE & ctx->fnbw_reason)
832 * The interface this path resolves through has been deleted.
833 * This will leave the path in a permanent drop state. The route
834 * needs to be removed and readded (and hence the path-list deleted)
835 * before it can forward again.
837 fib_path_unresolve(path);
838 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_DROP;
840 if (FIB_NODE_BW_REASON_FLAG_ADJ_UPDATE & ctx->fnbw_reason)
843 * restack the DPO to pick up the correct DPO sub-type
848 if_is_up = vnet_sw_interface_is_admin_up(
850 path->attached_next_hop.fp_interface);
854 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RESOLVED;
857 ai = fib_path_attached_next_hop_get_adj(
859 fib_proto_to_link(path->fp_nh_proto));
861 dpo_set(&path->fp_dpo, DPO_ADJACENCY,
862 fib_proto_to_dpo(path->fp_nh_proto),
869 * If the interface is not up there is no reason to walk
870 * back to children. if we did they would only evalute
871 * that this path is unresolved and hence it would
872 * not contribute the adjacency - so it would be wasted
875 return (FIB_NODE_BACK_WALK_CONTINUE);
878 if (FIB_NODE_BW_REASON_FLAG_ADJ_DOWN & ctx->fnbw_reason)
880 if (!(path->fp_oper_flags & FIB_PATH_OPER_FLAG_RESOLVED))
883 * alreday unresolved. no need to walk back again
885 return (FIB_NODE_BACK_WALK_CONTINUE);
888 * the adj has gone down. the path is no longer resolved.
890 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
893 case FIB_PATH_TYPE_ATTACHED:
895 * FIXME; this could schedule a lower priority walk, since attached
896 * routes are not usually in ECMP configurations so the backwalk to
897 * the FIB entry does not need to be high priority
899 if (FIB_NODE_BW_REASON_FLAG_INTERFACE_UP & ctx->fnbw_reason)
901 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RESOLVED;
903 if (FIB_NODE_BW_REASON_FLAG_INTERFACE_DOWN & ctx->fnbw_reason)
905 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
907 if (FIB_NODE_BW_REASON_FLAG_INTERFACE_DELETE & ctx->fnbw_reason)
909 fib_path_unresolve(path);
910 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_DROP;
913 case FIB_PATH_TYPE_DEAG:
915 * FIXME When VRF delete is allowed this will need a poke.
917 case FIB_PATH_TYPE_SPECIAL:
918 case FIB_PATH_TYPE_RECEIVE:
919 case FIB_PATH_TYPE_EXCLUSIVE:
921 * these path types have no parents. so to be
922 * walked from one is unexpected.
929 * propagate the backwalk further to the path-list
931 fib_path_list_back_walk(path->fp_pl_index, ctx);
933 return (FIB_NODE_BACK_WALK_CONTINUE);
937 fib_path_memory_show (void)
939 fib_show_memory_usage("Path",
940 pool_elts(fib_path_pool),
941 pool_len(fib_path_pool),
946 * The FIB path's graph node virtual function table
948 static const fib_node_vft_t fib_path_vft = {
949 .fnv_get = fib_path_get_node,
950 .fnv_last_lock = fib_path_last_lock_gone,
951 .fnv_back_walk = fib_path_back_walk_notify,
952 .fnv_mem_show = fib_path_memory_show,
955 static fib_path_cfg_flags_t
956 fib_path_route_flags_to_cfg_flags (const fib_route_path_t *rpath)
958 fib_path_cfg_flags_t cfg_flags = FIB_PATH_CFG_FLAG_NONE;
960 if (rpath->frp_flags & FIB_ROUTE_PATH_RESOLVE_VIA_HOST)
961 cfg_flags |= FIB_PATH_CFG_FLAG_RESOLVE_HOST;
962 if (rpath->frp_flags & FIB_ROUTE_PATH_RESOLVE_VIA_ATTACHED)
963 cfg_flags |= FIB_PATH_CFG_FLAG_RESOLVE_ATTACHED;
964 if (rpath->frp_flags & FIB_ROUTE_PATH_LOCAL)
965 cfg_flags |= FIB_PATH_CFG_FLAG_LOCAL;
973 * Create and initialise a new path object.
974 * return the index of the path.
977 fib_path_create (fib_node_index_t pl_index,
978 fib_protocol_t nh_proto,
979 fib_path_cfg_flags_t flags,
980 const fib_route_path_t *rpath)
984 pool_get(fib_path_pool, path);
985 memset(path, 0, sizeof(*path));
987 fib_node_init(&path->fp_node,
990 dpo_reset(&path->fp_dpo);
991 path->fp_pl_index = pl_index;
992 path->fp_nh_proto = nh_proto;
993 path->fp_via_fib = FIB_NODE_INDEX_INVALID;
994 path->fp_weight = rpath->frp_weight;
995 if (0 == path->fp_weight)
998 * a weight of 0 is a meaningless value. We could either reject it, and thus force
999 * clients to always use 1, or we can accept it and fixup approrpiately.
1001 path->fp_weight = 1;
1003 path->fp_cfg_flags = flags;
1004 path->fp_cfg_flags |= fib_path_route_flags_to_cfg_flags(rpath);
1007 * deduce the path's tpye from the parementers and save what is needed.
1009 if (path->fp_cfg_flags & FIB_PATH_CFG_FLAG_LOCAL)
1011 path->fp_type = FIB_PATH_TYPE_RECEIVE;
1012 path->receive.fp_interface = rpath->frp_sw_if_index;
1013 path->receive.fp_addr = rpath->frp_addr;
1015 else if (~0 != rpath->frp_sw_if_index)
1017 if (ip46_address_is_zero(&rpath->frp_addr))
1019 path->fp_type = FIB_PATH_TYPE_ATTACHED;
1020 path->attached.fp_interface = rpath->frp_sw_if_index;
1024 path->fp_type = FIB_PATH_TYPE_ATTACHED_NEXT_HOP;
1025 path->attached_next_hop.fp_interface = rpath->frp_sw_if_index;
1026 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 else 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:
1758 case FIB_FORW_CHAIN_TYPE_NSH:
1763 * get a appropriate link type adj.
1765 ai = fib_path_attached_next_hop_get_adj(
1767 fib_forw_chain_type_to_link_type(fct));
1768 dpo_set(dpo, DPO_ADJACENCY,
1769 fib_forw_chain_type_to_dpo_proto(fct), ai);
1774 case FIB_FORW_CHAIN_TYPE_MCAST_IP4:
1775 case FIB_FORW_CHAIN_TYPE_MCAST_IP6:
1779 case FIB_PATH_TYPE_RECURSIVE:
1782 case FIB_FORW_CHAIN_TYPE_MPLS_EOS:
1783 case FIB_FORW_CHAIN_TYPE_UNICAST_IP4:
1784 case FIB_FORW_CHAIN_TYPE_UNICAST_IP6:
1785 case FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS:
1786 fib_path_recursive_adj_update(path, fct, dpo);
1788 case FIB_FORW_CHAIN_TYPE_MCAST_IP4:
1789 case FIB_FORW_CHAIN_TYPE_MCAST_IP6:
1790 case FIB_FORW_CHAIN_TYPE_ETHERNET:
1791 case FIB_FORW_CHAIN_TYPE_NSH:
1796 case FIB_PATH_TYPE_DEAG:
1799 case FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS:
1800 lookup_dpo_add_or_lock_w_table_id(MPLS_FIB_DEFAULT_TABLE_ID,
1802 LOOKUP_INPUT_DST_ADDR,
1803 LOOKUP_TABLE_FROM_CONFIG,
1806 case FIB_FORW_CHAIN_TYPE_UNICAST_IP4:
1807 case FIB_FORW_CHAIN_TYPE_UNICAST_IP6:
1808 case FIB_FORW_CHAIN_TYPE_MPLS_EOS:
1809 dpo_copy(dpo, &path->fp_dpo);
1811 case FIB_FORW_CHAIN_TYPE_MCAST_IP4:
1812 case FIB_FORW_CHAIN_TYPE_MCAST_IP6:
1813 case FIB_FORW_CHAIN_TYPE_ETHERNET:
1814 case FIB_FORW_CHAIN_TYPE_NSH:
1819 case FIB_PATH_TYPE_EXCLUSIVE:
1820 dpo_copy(dpo, &path->exclusive.fp_ex_dpo);
1822 case FIB_PATH_TYPE_ATTACHED:
1825 case FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS:
1826 case FIB_FORW_CHAIN_TYPE_UNICAST_IP4:
1827 case FIB_FORW_CHAIN_TYPE_UNICAST_IP6:
1828 case FIB_FORW_CHAIN_TYPE_MPLS_EOS:
1829 case FIB_FORW_CHAIN_TYPE_ETHERNET:
1830 case FIB_FORW_CHAIN_TYPE_NSH:
1832 case FIB_FORW_CHAIN_TYPE_MCAST_IP4:
1833 case FIB_FORW_CHAIN_TYPE_MCAST_IP6:
1838 * Create the adj needed for sending IP multicast traffic
1840 ai = adj_mcast_add_or_lock(path->fp_nh_proto,
1841 fib_forw_chain_type_to_link_type(fct),
1842 path->attached.fp_interface);
1843 dpo_set(dpo, DPO_ADJACENCY_MCAST,
1844 fib_forw_chain_type_to_dpo_proto(fct),
1851 case FIB_PATH_TYPE_RECEIVE:
1852 case FIB_PATH_TYPE_SPECIAL:
1853 dpo_copy(dpo, &path->fp_dpo);
1859 load_balance_path_t *
1860 fib_path_append_nh_for_multipath_hash (fib_node_index_t path_index,
1861 fib_forward_chain_type_t fct,
1862 load_balance_path_t *hash_key)
1864 load_balance_path_t *mnh;
1867 path = fib_path_get(path_index);
1871 if (fib_path_is_resolved(path_index))
1873 vec_add2(hash_key, mnh, 1);
1875 mnh->path_weight = path->fp_weight;
1876 mnh->path_index = path_index;
1877 fib_path_contribute_forwarding(path_index, fct, &mnh->path_dpo);
1884 fib_path_is_recursive (fib_node_index_t path_index)
1888 path = fib_path_get(path_index);
1890 return (FIB_PATH_TYPE_RECURSIVE == path->fp_type);
1894 fib_path_is_exclusive (fib_node_index_t path_index)
1898 path = fib_path_get(path_index);
1900 return (FIB_PATH_TYPE_EXCLUSIVE == path->fp_type);
1904 fib_path_is_deag (fib_node_index_t path_index)
1908 path = fib_path_get(path_index);
1910 return (FIB_PATH_TYPE_DEAG == path->fp_type);
1914 fib_path_is_resolved (fib_node_index_t path_index)
1918 path = fib_path_get(path_index);
1920 return (dpo_id_is_valid(&path->fp_dpo) &&
1921 (path->fp_oper_flags & FIB_PATH_OPER_FLAG_RESOLVED) &&
1922 !fib_path_is_looped(path_index) &&
1923 !fib_path_is_permanent_drop(path));
1927 fib_path_is_looped (fib_node_index_t path_index)
1931 path = fib_path_get(path_index);
1933 return (path->fp_oper_flags & FIB_PATH_OPER_FLAG_RECURSIVE_LOOP);
1937 fib_path_encode (fib_node_index_t path_list_index,
1938 fib_node_index_t path_index,
1941 fib_route_path_encode_t **api_rpaths = ctx;
1942 fib_route_path_encode_t *api_rpath;
1945 path = fib_path_get(path_index);
1948 vec_add2(*api_rpaths, api_rpath, 1);
1949 api_rpath->rpath.frp_weight = path->fp_weight;
1950 api_rpath->rpath.frp_proto = path->fp_nh_proto;
1951 api_rpath->rpath.frp_sw_if_index = ~0;
1952 api_rpath->dpo = path->exclusive.fp_ex_dpo;
1953 switch (path->fp_type)
1955 case FIB_PATH_TYPE_RECEIVE:
1956 api_rpath->rpath.frp_addr = path->receive.fp_addr;
1957 api_rpath->rpath.frp_sw_if_index = path->receive.fp_interface;
1959 case FIB_PATH_TYPE_ATTACHED:
1960 api_rpath->rpath.frp_sw_if_index = path->attached.fp_interface;
1962 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1963 api_rpath->rpath.frp_sw_if_index = path->attached_next_hop.fp_interface;
1964 api_rpath->rpath.frp_addr = path->attached_next_hop.fp_nh;
1966 case FIB_PATH_TYPE_SPECIAL:
1968 case FIB_PATH_TYPE_DEAG:
1970 case FIB_PATH_TYPE_RECURSIVE:
1971 api_rpath->rpath.frp_addr = path->recursive.fp_nh.fp_ip;
1980 fib_path_get_proto (fib_node_index_t path_index)
1984 path = fib_path_get(path_index);
1986 return (path->fp_nh_proto);
1990 fib_path_module_init (void)
1992 fib_node_register_type (FIB_NODE_TYPE_PATH, &fib_path_vft);
1995 static clib_error_t *
1996 show_fib_path_command (vlib_main_t * vm,
1997 unformat_input_t * input,
1998 vlib_cli_command_t * cmd)
2000 fib_node_index_t pi;
2003 if (unformat (input, "%d", &pi))
2006 * show one in detail
2008 if (!pool_is_free_index(fib_path_pool, pi))
2010 path = fib_path_get(pi);
2011 u8 *s = fib_path_format(pi, NULL);
2012 s = format(s, "children:");
2013 s = fib_node_children_format(path->fp_node.fn_children, s);
2014 vlib_cli_output (vm, "%s", s);
2019 vlib_cli_output (vm, "path %d invalid", pi);
2024 vlib_cli_output (vm, "FIB Paths");
2025 pool_foreach(path, fib_path_pool,
2027 vlib_cli_output (vm, "%U", format_fib_path, path);
2034 VLIB_CLI_COMMAND (show_fib_path, static) = {
2035 .path = "show fib paths",
2036 .function = show_fib_path_command,
2037 .short_help = "show fib paths",