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>
24 #include <vnet/dpo/interface_rx_dpo.h>
25 #include <vnet/dpo/mpls_disposition.h>
26 #include <vnet/dpo/l2_bridge_dpo.h>
28 #include <vnet/adj/adj.h>
29 #include <vnet/adj/adj_mcast.h>
31 #include <vnet/fib/fib_path.h>
32 #include <vnet/fib/fib_node.h>
33 #include <vnet/fib/fib_table.h>
34 #include <vnet/fib/fib_entry.h>
35 #include <vnet/fib/fib_path_list.h>
36 #include <vnet/fib/fib_internal.h>
37 #include <vnet/fib/fib_urpf_list.h>
38 #include <vnet/fib/mpls_fib.h>
41 * Enurmeration of path types
43 typedef enum fib_path_type_t_ {
45 * Marker. Add new types after this one.
47 FIB_PATH_TYPE_FIRST = 0,
49 * Attached-nexthop. An interface and a nexthop are known.
51 FIB_PATH_TYPE_ATTACHED_NEXT_HOP = FIB_PATH_TYPE_FIRST,
53 * attached. Only the interface is known.
55 FIB_PATH_TYPE_ATTACHED,
57 * recursive. Only the next-hop is known.
59 FIB_PATH_TYPE_RECURSIVE,
61 * special. nothing is known. so we drop.
63 FIB_PATH_TYPE_SPECIAL,
65 * exclusive. user provided adj.
67 FIB_PATH_TYPE_EXCLUSIVE,
69 * deag. Link to a lookup adj in the next table
75 FIB_PATH_TYPE_INTF_RX,
77 * receive. it's for-us.
79 FIB_PATH_TYPE_RECEIVE,
81 * Marker. Add new types before this one, then update it.
83 FIB_PATH_TYPE_LAST = FIB_PATH_TYPE_RECEIVE,
84 } __attribute__ ((packed)) fib_path_type_t;
87 * The maximum number of path_types
89 #define FIB_PATH_TYPE_MAX (FIB_PATH_TYPE_LAST + 1)
91 #define FIB_PATH_TYPES { \
92 [FIB_PATH_TYPE_ATTACHED_NEXT_HOP] = "attached-nexthop", \
93 [FIB_PATH_TYPE_ATTACHED] = "attached", \
94 [FIB_PATH_TYPE_RECURSIVE] = "recursive", \
95 [FIB_PATH_TYPE_SPECIAL] = "special", \
96 [FIB_PATH_TYPE_EXCLUSIVE] = "exclusive", \
97 [FIB_PATH_TYPE_DEAG] = "deag", \
98 [FIB_PATH_TYPE_INTF_RX] = "intf-rx", \
99 [FIB_PATH_TYPE_RECEIVE] = "receive", \
102 #define FOR_EACH_FIB_PATH_TYPE(_item) \
103 for (_item = FIB_PATH_TYPE_FIRST; _item <= FIB_PATH_TYPE_LAST; _item++)
106 * Enurmeration of path operational (i.e. derived) attributes
108 typedef enum fib_path_oper_attribute_t_ {
110 * Marker. Add new types after this one.
112 FIB_PATH_OPER_ATTRIBUTE_FIRST = 0,
114 * The path forms part of a recursive loop.
116 FIB_PATH_OPER_ATTRIBUTE_RECURSIVE_LOOP = FIB_PATH_OPER_ATTRIBUTE_FIRST,
118 * The path is resolved
120 FIB_PATH_OPER_ATTRIBUTE_RESOLVED,
122 * The path is attached, despite what the next-hop may say.
124 FIB_PATH_OPER_ATTRIBUTE_ATTACHED,
126 * The path has become a permanent drop.
128 FIB_PATH_OPER_ATTRIBUTE_DROP,
130 * Marker. Add new types before this one, then update it.
132 FIB_PATH_OPER_ATTRIBUTE_LAST = FIB_PATH_OPER_ATTRIBUTE_DROP,
133 } __attribute__ ((packed)) fib_path_oper_attribute_t;
136 * The maximum number of path operational attributes
138 #define FIB_PATH_OPER_ATTRIBUTE_MAX (FIB_PATH_OPER_ATTRIBUTE_LAST + 1)
140 #define FIB_PATH_OPER_ATTRIBUTES { \
141 [FIB_PATH_OPER_ATTRIBUTE_RECURSIVE_LOOP] = "recursive-loop", \
142 [FIB_PATH_OPER_ATTRIBUTE_RESOLVED] = "resolved", \
143 [FIB_PATH_OPER_ATTRIBUTE_DROP] = "drop", \
146 #define FOR_EACH_FIB_PATH_OPER_ATTRIBUTE(_item) \
147 for (_item = FIB_PATH_OPER_ATTRIBUTE_FIRST; \
148 _item <= FIB_PATH_OPER_ATTRIBUTE_LAST; \
152 * Path flags from the attributes
154 typedef enum fib_path_oper_flags_t_ {
155 FIB_PATH_OPER_FLAG_NONE = 0,
156 FIB_PATH_OPER_FLAG_RECURSIVE_LOOP = (1 << FIB_PATH_OPER_ATTRIBUTE_RECURSIVE_LOOP),
157 FIB_PATH_OPER_FLAG_DROP = (1 << FIB_PATH_OPER_ATTRIBUTE_DROP),
158 FIB_PATH_OPER_FLAG_RESOLVED = (1 << FIB_PATH_OPER_ATTRIBUTE_RESOLVED),
159 FIB_PATH_OPER_FLAG_ATTACHED = (1 << FIB_PATH_OPER_ATTRIBUTE_ATTACHED),
160 } __attribute__ ((packed)) fib_path_oper_flags_t;
165 typedef struct fib_path_t_ {
167 * A path is a node in the FIB graph.
172 * The index of the path-list to which this path belongs
177 * This marks the start of the memory area used to hash
180 STRUCT_MARK(path_hash_start);
183 * Configuration Flags
185 fib_path_cfg_flags_t fp_cfg_flags;
188 * The type of the path. This is the selector for the union
190 fib_path_type_t fp_type;
193 * The protocol of the next-hop, i.e. the address family of the
194 * next-hop's address. We can't derive this from the address itself
195 * since the address can be all zeros
197 dpo_proto_t fp_nh_proto;
200 * UCMP [unnormalised] weigth
205 * A path preference. 0 is the best.
206 * Only paths of the best preference, that are 'up', are considered
212 * per-type union of the data required to resolve the path
219 ip46_address_t fp_nh;
237 ip46_address_t fp_ip;
240 * The local label to resolve through.
242 mpls_label_t fp_local_label;
244 * The EOS bit of the resolving label
246 mpls_eos_bit_t fp_eos;
250 * The FIB table index in which to find the next-hop.
252 fib_node_index_t fp_tbl_id;
256 * The FIB index in which to perfom the next lookup
258 fib_node_index_t fp_tbl_id;
260 * The RPF-ID to tag the packets with
262 fib_rpf_id_t fp_rpf_id;
268 * The user provided 'exclusive' DPO
274 * The interface on which the local address is configured
280 ip46_address_t fp_addr;
284 * The interface on which the packets will be input.
289 STRUCT_MARK(path_hash_end);
292 * Memebers in this last section represent information that is
293 * dervied during resolution. It should not be copied to new paths
300 fib_path_oper_flags_t fp_oper_flags;
303 * the resolving via fib. not part of the union, since it it not part
304 * of the path's hash.
306 fib_node_index_t fp_via_fib;
309 * The Data-path objects through which this path resolves for IP.
314 * the index of this path in the parent's child list.
320 * Array of strings/names for the path types and attributes
322 static const char *fib_path_type_names[] = FIB_PATH_TYPES;
323 static const char *fib_path_oper_attribute_names[] = FIB_PATH_OPER_ATTRIBUTES;
324 static const char *fib_path_cfg_attribute_names[] = FIB_PATH_CFG_ATTRIBUTES;
327 * The memory pool from which we allocate all the paths
329 static fib_path_t *fib_path_pool;
335 #define FIB_PATH_DBG(_p, _fmt, _args...) \
338 _tmp = fib_path_format(fib_path_get_index(_p), _tmp); \
339 clib_warning("path:[%d:%s]:" _fmt, \
340 fib_path_get_index(_p), _tmp, \
345 #define FIB_PATH_DBG(_p, _fmt, _args...)
349 fib_path_get (fib_node_index_t index)
351 return (pool_elt_at_index(fib_path_pool, index));
354 static fib_node_index_t
355 fib_path_get_index (fib_path_t *path)
357 return (path - fib_path_pool);
361 fib_path_get_node (fib_node_index_t index)
363 return ((fib_node_t*)fib_path_get(index));
367 fib_path_from_fib_node (fib_node_t *node)
370 ASSERT(FIB_NODE_TYPE_PATH == node->fn_type);
372 return ((fib_path_t*)node);
376 format_fib_path (u8 * s, va_list * args)
378 fib_path_t *path = va_arg (*args, fib_path_t *);
379 vnet_main_t * vnm = vnet_get_main();
380 fib_path_oper_attribute_t oattr;
381 fib_path_cfg_attribute_t cattr;
383 s = format (s, " index:%d ", fib_path_get_index(path));
384 s = format (s, "pl-index:%d ", path->fp_pl_index);
385 s = format (s, "%U ", format_dpo_proto, path->fp_nh_proto);
386 s = format (s, "weight=%d ", path->fp_weight);
387 s = format (s, "pref=%d ", path->fp_preference);
388 s = format (s, "%s: ", fib_path_type_names[path->fp_type]);
389 if (FIB_PATH_OPER_FLAG_NONE != path->fp_oper_flags) {
390 s = format(s, " oper-flags:");
391 FOR_EACH_FIB_PATH_OPER_ATTRIBUTE(oattr) {
392 if ((1<<oattr) & path->fp_oper_flags) {
393 s = format (s, "%s,", fib_path_oper_attribute_names[oattr]);
397 if (FIB_PATH_CFG_FLAG_NONE != path->fp_cfg_flags) {
398 s = format(s, " cfg-flags:");
399 FOR_EACH_FIB_PATH_CFG_ATTRIBUTE(cattr) {
400 if ((1<<cattr) & path->fp_cfg_flags) {
401 s = format (s, "%s,", fib_path_cfg_attribute_names[cattr]);
405 s = format(s, "\n ");
407 switch (path->fp_type)
409 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
410 s = format (s, "%U", format_ip46_address,
411 &path->attached_next_hop.fp_nh,
413 if (path->fp_oper_flags & FIB_PATH_OPER_FLAG_DROP)
415 s = format (s, " if_index:%d", path->attached_next_hop.fp_interface);
419 s = format (s, " %U",
420 format_vnet_sw_interface_name,
422 vnet_get_sw_interface(
424 path->attached_next_hop.fp_interface));
425 if (vnet_sw_interface_is_p2p(vnet_get_main(),
426 path->attached_next_hop.fp_interface))
428 s = format (s, " (p2p)");
431 if (!dpo_id_is_valid(&path->fp_dpo))
433 s = format(s, "\n unresolved");
437 s = format(s, "\n %U",
442 case FIB_PATH_TYPE_ATTACHED:
443 if (path->fp_oper_flags & FIB_PATH_OPER_FLAG_DROP)
445 s = format (s, " if_index:%d", path->attached_next_hop.fp_interface);
449 s = format (s, " %U",
450 format_vnet_sw_interface_name,
452 vnet_get_sw_interface(
454 path->attached.fp_interface));
457 case FIB_PATH_TYPE_RECURSIVE:
458 if (DPO_PROTO_MPLS == path->fp_nh_proto)
460 s = format (s, "via %U %U",
461 format_mpls_unicast_label,
462 path->recursive.fp_nh.fp_local_label,
464 path->recursive.fp_nh.fp_eos);
468 s = format (s, "via %U",
470 &path->recursive.fp_nh.fp_ip,
473 s = format (s, " in fib:%d",
474 path->recursive.fp_tbl_id,
476 s = format (s, " via-fib:%d", path->fp_via_fib);
477 s = format (s, " via-dpo:[%U:%d]",
478 format_dpo_type, path->fp_dpo.dpoi_type,
479 path->fp_dpo.dpoi_index);
482 case FIB_PATH_TYPE_RECEIVE:
483 case FIB_PATH_TYPE_INTF_RX:
484 case FIB_PATH_TYPE_SPECIAL:
485 case FIB_PATH_TYPE_DEAG:
486 case FIB_PATH_TYPE_EXCLUSIVE:
487 if (dpo_id_is_valid(&path->fp_dpo))
489 s = format(s, "%U", format_dpo_id,
498 fib_path_format (fib_node_index_t pi, u8 *s)
502 path = fib_path_get(pi);
503 ASSERT(NULL != path);
505 return (format (s, "%U", format_fib_path, path));
509 fib_path_adj_format (fib_node_index_t pi,
515 path = fib_path_get(pi);
516 ASSERT(NULL != path);
518 if (!dpo_id_is_valid(&path->fp_dpo))
520 s = format(s, " unresolved");
524 s = format(s, "%U", format_dpo_id,
532 * fib_path_last_lock_gone
534 * We don't share paths, we share path lists, so the [un]lock functions
538 fib_path_last_lock_gone (fib_node_t *node)
543 static const adj_index_t
544 fib_path_attached_next_hop_get_adj (fib_path_t *path,
547 if (vnet_sw_interface_is_p2p(vnet_get_main(),
548 path->attached_next_hop.fp_interface))
551 * if the interface is p2p then the adj for the specific
552 * neighbour on that link will never exist. on p2p links
553 * the subnet address (the attached route) links to the
554 * auto-adj (see below), we want that adj here too.
556 return (adj_nbr_add_or_lock(dpo_proto_to_fib(path->fp_nh_proto),
559 path->attached_next_hop.fp_interface));
563 return (adj_nbr_add_or_lock(dpo_proto_to_fib(path->fp_nh_proto),
565 &path->attached_next_hop.fp_nh,
566 path->attached_next_hop.fp_interface));
571 fib_path_attached_next_hop_set (fib_path_t *path)
574 * resolve directly via the adjacnecy discribed by the
575 * interface and next-hop
577 dpo_set(&path->fp_dpo,
580 fib_path_attached_next_hop_get_adj(
582 dpo_proto_to_link(path->fp_nh_proto)));
585 * become a child of the adjacency so we receive updates
586 * when its rewrite changes
588 path->fp_sibling = adj_child_add(path->fp_dpo.dpoi_index,
590 fib_path_get_index(path));
592 if (!vnet_sw_interface_is_admin_up(vnet_get_main(),
593 path->attached_next_hop.fp_interface) ||
594 !adj_is_up(path->fp_dpo.dpoi_index))
596 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
600 static const adj_index_t
601 fib_path_attached_get_adj (fib_path_t *path,
604 if (vnet_sw_interface_is_p2p(vnet_get_main(),
605 path->attached.fp_interface))
608 * point-2-point interfaces do not require a glean, since
609 * there is nothing to ARP. Install a rewrite/nbr adj instead
611 return (adj_nbr_add_or_lock(dpo_proto_to_fib(path->fp_nh_proto),
614 path->attached.fp_interface));
618 return (adj_glean_add_or_lock(dpo_proto_to_fib(path->fp_nh_proto),
619 path->attached.fp_interface,
625 * create of update the paths recursive adj
628 fib_path_recursive_adj_update (fib_path_t *path,
629 fib_forward_chain_type_t fct,
632 dpo_id_t via_dpo = DPO_INVALID;
635 * get the DPO to resolve through from the via-entry
637 fib_entry_contribute_forwarding(path->fp_via_fib,
643 * hope for the best - clear if restrictions apply.
645 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RESOLVED;
648 * Validate any recursion constraints and over-ride the via
651 if (path->fp_oper_flags & FIB_PATH_OPER_FLAG_RECURSIVE_LOOP)
653 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
654 dpo_copy(&via_dpo, drop_dpo_get(path->fp_nh_proto));
656 else if (path->fp_cfg_flags & FIB_PATH_CFG_FLAG_RESOLVE_HOST)
659 * the via FIB must be a host route.
660 * note the via FIB just added will always be a host route
661 * since it is an RR source added host route. So what we need to
662 * check is whether the route has other sources. If it does then
663 * some other source has added it as a host route. If it doesn't
664 * then it was added only here and inherits forwarding from a cover.
665 * the cover is not a host route.
666 * The RR source is the lowest priority source, so we check if it
667 * is the best. if it is there are no other sources.
669 if (fib_entry_get_best_source(path->fp_via_fib) >= FIB_SOURCE_RR)
671 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
672 dpo_copy(&via_dpo, drop_dpo_get(path->fp_nh_proto));
675 * PIC edge trigger. let the load-balance maps know
677 load_balance_map_path_state_change(fib_path_get_index(path));
680 else if (path->fp_cfg_flags & FIB_PATH_CFG_FLAG_RESOLVE_ATTACHED)
683 * RR source entries inherit the flags from the cover, so
684 * we can check the via directly
686 if (!(FIB_ENTRY_FLAG_ATTACHED & fib_entry_get_flags(path->fp_via_fib)))
688 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
689 dpo_copy(&via_dpo, drop_dpo_get(path->fp_nh_proto));
692 * PIC edge trigger. let the load-balance maps know
694 load_balance_map_path_state_change(fib_path_get_index(path));
698 * check for over-riding factors on the FIB entry itself
700 if (!fib_entry_is_resolved(path->fp_via_fib))
702 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
703 dpo_copy(&via_dpo, drop_dpo_get(path->fp_nh_proto));
706 * PIC edge trigger. let the load-balance maps know
708 load_balance_map_path_state_change(fib_path_get_index(path));
712 * If this path is contributing a drop, then it's not resolved
714 if (dpo_is_drop(&via_dpo) || load_balance_is_drop(&via_dpo))
716 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
720 * update the path's contributed DPO
722 dpo_copy(dpo, &via_dpo);
724 FIB_PATH_DBG(path, "recursive update:");
730 * fib_path_is_permanent_drop
732 * Return !0 if the path is configured to permanently drop,
733 * despite other attributes.
736 fib_path_is_permanent_drop (fib_path_t *path)
738 return ((path->fp_cfg_flags & FIB_PATH_CFG_FLAG_DROP) ||
739 (path->fp_oper_flags & FIB_PATH_OPER_FLAG_DROP));
745 * Remove our dependency on the resolution target
748 fib_path_unresolve (fib_path_t *path)
751 * the forced drop path does not need unresolving
753 if (fib_path_is_permanent_drop(path))
758 switch (path->fp_type)
760 case FIB_PATH_TYPE_RECURSIVE:
761 if (FIB_NODE_INDEX_INVALID != path->fp_via_fib)
765 fib_entry_get_prefix(path->fp_via_fib, &pfx);
766 fib_entry_child_remove(path->fp_via_fib,
768 fib_table_entry_special_remove(path->recursive.fp_tbl_id,
771 path->fp_via_fib = FIB_NODE_INDEX_INVALID;
774 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
775 adj_child_remove(path->fp_dpo.dpoi_index,
777 adj_unlock(path->fp_dpo.dpoi_index);
779 case FIB_PATH_TYPE_ATTACHED:
780 if (DPO_PROTO_ETHERNET != path->fp_nh_proto)
782 adj_child_remove(path->fp_dpo.dpoi_index,
784 adj_unlock(path->fp_dpo.dpoi_index);
787 case FIB_PATH_TYPE_EXCLUSIVE:
788 dpo_reset(&path->exclusive.fp_ex_dpo);
790 case FIB_PATH_TYPE_SPECIAL:
791 case FIB_PATH_TYPE_RECEIVE:
792 case FIB_PATH_TYPE_INTF_RX:
793 case FIB_PATH_TYPE_DEAG:
795 * these hold only the path's DPO, which is reset below.
801 * release the adj we were holding and pick up the
804 dpo_reset(&path->fp_dpo);
805 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
810 static fib_forward_chain_type_t
811 fib_path_to_chain_type (const fib_path_t *path)
813 if (DPO_PROTO_MPLS == path->fp_nh_proto)
815 if (FIB_PATH_TYPE_RECURSIVE == path->fp_type &&
816 MPLS_EOS == path->recursive.fp_nh.fp_eos)
818 return (FIB_FORW_CHAIN_TYPE_MPLS_EOS);
822 return (FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS);
827 return (fib_forw_chain_type_from_dpo_proto(path->fp_nh_proto));
832 * fib_path_back_walk_notify
834 * A back walk has reach this path.
836 static fib_node_back_walk_rc_t
837 fib_path_back_walk_notify (fib_node_t *node,
838 fib_node_back_walk_ctx_t *ctx)
842 path = fib_path_from_fib_node(node);
844 switch (path->fp_type)
846 case FIB_PATH_TYPE_RECURSIVE:
847 if (FIB_NODE_BW_REASON_FLAG_EVALUATE & ctx->fnbw_reason)
850 * modify the recursive adjacency to use the new forwarding
852 * this update is visible to packets in flight in the DP.
854 fib_path_recursive_adj_update(
856 fib_path_to_chain_type(path),
859 if ((FIB_NODE_BW_REASON_FLAG_ADJ_UPDATE & ctx->fnbw_reason) ||
860 (FIB_NODE_BW_REASON_FLAG_ADJ_DOWN & ctx->fnbw_reason))
863 * ADJ updates (complete<->incomplete) do not need to propagate to
865 * The only reason its needed as far back as here, is that the adj
866 * and the incomplete adj are a different DPO type, so the LBs need
868 * If this walk was quashed in the fib_entry, then any non-fib_path
869 * children (like tunnels that collapse out the LB when they stack)
870 * would not see the update.
872 return (FIB_NODE_BACK_WALK_CONTINUE);
875 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
878 * ADJ_UPDATE backwalk pass silently through here and up to
879 * the path-list when the multipath adj collapse occurs.
880 * The reason we do this is that the assumtption is that VPP
881 * runs in an environment where the Control-Plane is remote
882 * and hence reacts slowly to link up down. In order to remove
883 * this down link from the ECMP set quickly, we back-walk.
884 * VPP also has dedicated CPUs, so we are not stealing resources
885 * from the CP to do so.
887 if (FIB_NODE_BW_REASON_FLAG_INTERFACE_UP & ctx->fnbw_reason)
889 if (path->fp_oper_flags & FIB_PATH_OPER_FLAG_RESOLVED)
892 * alreday resolved. no need to walk back again
894 return (FIB_NODE_BACK_WALK_CONTINUE);
896 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RESOLVED;
898 if (FIB_NODE_BW_REASON_FLAG_INTERFACE_DOWN & ctx->fnbw_reason)
900 if (!(path->fp_oper_flags & FIB_PATH_OPER_FLAG_RESOLVED))
903 * alreday unresolved. no need to walk back again
905 return (FIB_NODE_BACK_WALK_CONTINUE);
907 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
909 if (FIB_NODE_BW_REASON_FLAG_INTERFACE_DELETE & ctx->fnbw_reason)
912 * The interface this path resolves through has been deleted.
913 * This will leave the path in a permanent drop state. The route
914 * needs to be removed and readded (and hence the path-list deleted)
915 * before it can forward again.
917 fib_path_unresolve(path);
918 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_DROP;
920 if (FIB_NODE_BW_REASON_FLAG_ADJ_UPDATE & ctx->fnbw_reason)
923 * restack the DPO to pick up the correct DPO sub-type
928 if_is_up = vnet_sw_interface_is_admin_up(
930 path->attached_next_hop.fp_interface);
932 ai = fib_path_attached_next_hop_get_adj(
934 dpo_proto_to_link(path->fp_nh_proto));
936 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
937 if (if_is_up && adj_is_up(ai))
939 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RESOLVED;
942 dpo_set(&path->fp_dpo, DPO_ADJACENCY, path->fp_nh_proto, ai);
948 * If the interface is not up there is no reason to walk
949 * back to children. if we did they would only evalute
950 * that this path is unresolved and hence it would
951 * not contribute the adjacency - so it would be wasted
954 return (FIB_NODE_BACK_WALK_CONTINUE);
957 if (FIB_NODE_BW_REASON_FLAG_ADJ_DOWN & ctx->fnbw_reason)
959 if (!(path->fp_oper_flags & FIB_PATH_OPER_FLAG_RESOLVED))
962 * alreday unresolved. no need to walk back again
964 return (FIB_NODE_BACK_WALK_CONTINUE);
967 * the adj has gone down. the path is no longer resolved.
969 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
972 case FIB_PATH_TYPE_ATTACHED:
974 * FIXME; this could schedule a lower priority walk, since attached
975 * routes are not usually in ECMP configurations so the backwalk to
976 * the FIB entry does not need to be high priority
978 if (FIB_NODE_BW_REASON_FLAG_INTERFACE_UP & ctx->fnbw_reason)
980 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RESOLVED;
982 if (FIB_NODE_BW_REASON_FLAG_INTERFACE_DOWN & ctx->fnbw_reason)
984 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
986 if (FIB_NODE_BW_REASON_FLAG_INTERFACE_DELETE & ctx->fnbw_reason)
988 fib_path_unresolve(path);
989 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_DROP;
992 case FIB_PATH_TYPE_INTF_RX:
994 case FIB_PATH_TYPE_DEAG:
996 * FIXME When VRF delete is allowed this will need a poke.
998 case FIB_PATH_TYPE_SPECIAL:
999 case FIB_PATH_TYPE_RECEIVE:
1000 case FIB_PATH_TYPE_EXCLUSIVE:
1002 * these path types have no parents. so to be
1003 * walked from one is unexpected.
1010 * propagate the backwalk further to the path-list
1012 fib_path_list_back_walk(path->fp_pl_index, ctx);
1014 return (FIB_NODE_BACK_WALK_CONTINUE);
1018 fib_path_memory_show (void)
1020 fib_show_memory_usage("Path",
1021 pool_elts(fib_path_pool),
1022 pool_len(fib_path_pool),
1023 sizeof(fib_path_t));
1027 * The FIB path's graph node virtual function table
1029 static const fib_node_vft_t fib_path_vft = {
1030 .fnv_get = fib_path_get_node,
1031 .fnv_last_lock = fib_path_last_lock_gone,
1032 .fnv_back_walk = fib_path_back_walk_notify,
1033 .fnv_mem_show = fib_path_memory_show,
1036 static fib_path_cfg_flags_t
1037 fib_path_route_flags_to_cfg_flags (const fib_route_path_t *rpath)
1039 fib_path_cfg_flags_t cfg_flags = FIB_PATH_CFG_FLAG_NONE;
1041 if (rpath->frp_flags & FIB_ROUTE_PATH_RESOLVE_VIA_HOST)
1042 cfg_flags |= FIB_PATH_CFG_FLAG_RESOLVE_HOST;
1043 if (rpath->frp_flags & FIB_ROUTE_PATH_RESOLVE_VIA_ATTACHED)
1044 cfg_flags |= FIB_PATH_CFG_FLAG_RESOLVE_ATTACHED;
1045 if (rpath->frp_flags & FIB_ROUTE_PATH_LOCAL)
1046 cfg_flags |= FIB_PATH_CFG_FLAG_LOCAL;
1047 if (rpath->frp_flags & FIB_ROUTE_PATH_ATTACHED)
1048 cfg_flags |= FIB_PATH_CFG_FLAG_ATTACHED;
1049 if (rpath->frp_flags & FIB_ROUTE_PATH_INTF_RX)
1050 cfg_flags |= FIB_PATH_CFG_FLAG_INTF_RX;
1051 if (rpath->frp_flags & FIB_ROUTE_PATH_RPF_ID)
1052 cfg_flags |= FIB_PATH_CFG_FLAG_RPF_ID;
1053 if (rpath->frp_flags & FIB_ROUTE_PATH_EXCLUSIVE)
1054 cfg_flags |= FIB_PATH_CFG_FLAG_EXCLUSIVE;
1055 if (rpath->frp_flags & FIB_ROUTE_PATH_DROP)
1056 cfg_flags |= FIB_PATH_CFG_FLAG_DROP;
1057 if (rpath->frp_flags & FIB_ROUTE_PATH_SOURCE_LOOKUP)
1058 cfg_flags |= FIB_PATH_CFG_FLAG_DEAG_SRC;
1066 * Create and initialise a new path object.
1067 * return the index of the path.
1070 fib_path_create (fib_node_index_t pl_index,
1071 const fib_route_path_t *rpath)
1075 pool_get(fib_path_pool, path);
1076 memset(path, 0, sizeof(*path));
1078 fib_node_init(&path->fp_node,
1079 FIB_NODE_TYPE_PATH);
1081 dpo_reset(&path->fp_dpo);
1082 path->fp_pl_index = pl_index;
1083 path->fp_nh_proto = rpath->frp_proto;
1084 path->fp_via_fib = FIB_NODE_INDEX_INVALID;
1085 path->fp_weight = rpath->frp_weight;
1086 if (0 == path->fp_weight)
1089 * a weight of 0 is a meaningless value. We could either reject it, and thus force
1090 * clients to always use 1, or we can accept it and fixup approrpiately.
1092 path->fp_weight = 1;
1094 path->fp_preference = rpath->frp_preference;
1095 path->fp_cfg_flags = fib_path_route_flags_to_cfg_flags(rpath);
1098 * deduce the path's tpye from the parementers and save what is needed.
1100 if (path->fp_cfg_flags & FIB_PATH_CFG_FLAG_LOCAL)
1102 path->fp_type = FIB_PATH_TYPE_RECEIVE;
1103 path->receive.fp_interface = rpath->frp_sw_if_index;
1104 path->receive.fp_addr = rpath->frp_addr;
1106 else if (path->fp_cfg_flags & FIB_PATH_CFG_FLAG_INTF_RX)
1108 path->fp_type = FIB_PATH_TYPE_INTF_RX;
1109 path->intf_rx.fp_interface = rpath->frp_sw_if_index;
1111 else if (path->fp_cfg_flags & FIB_PATH_CFG_FLAG_RPF_ID)
1113 path->fp_type = FIB_PATH_TYPE_DEAG;
1114 path->deag.fp_tbl_id = rpath->frp_fib_index;
1115 path->deag.fp_rpf_id = rpath->frp_rpf_id;
1117 else if (~0 != rpath->frp_sw_if_index)
1119 if (ip46_address_is_zero(&rpath->frp_addr))
1121 path->fp_type = FIB_PATH_TYPE_ATTACHED;
1122 path->attached.fp_interface = rpath->frp_sw_if_index;
1126 path->fp_type = FIB_PATH_TYPE_ATTACHED_NEXT_HOP;
1127 path->attached_next_hop.fp_interface = rpath->frp_sw_if_index;
1128 path->attached_next_hop.fp_nh = rpath->frp_addr;
1133 if (ip46_address_is_zero(&rpath->frp_addr))
1135 if (~0 == rpath->frp_fib_index)
1137 path->fp_type = FIB_PATH_TYPE_SPECIAL;
1141 path->fp_type = FIB_PATH_TYPE_DEAG;
1142 path->deag.fp_tbl_id = rpath->frp_fib_index;
1147 path->fp_type = FIB_PATH_TYPE_RECURSIVE;
1148 if (DPO_PROTO_MPLS == path->fp_nh_proto)
1150 path->recursive.fp_nh.fp_local_label = rpath->frp_local_label;
1151 path->recursive.fp_nh.fp_eos = rpath->frp_eos;
1155 path->recursive.fp_nh.fp_ip = rpath->frp_addr;
1157 path->recursive.fp_tbl_id = rpath->frp_fib_index;
1161 FIB_PATH_DBG(path, "create");
1163 return (fib_path_get_index(path));
1167 * fib_path_create_special
1169 * Create and initialise a new path object.
1170 * return the index of the path.
1173 fib_path_create_special (fib_node_index_t pl_index,
1174 dpo_proto_t nh_proto,
1175 fib_path_cfg_flags_t flags,
1176 const dpo_id_t *dpo)
1180 pool_get(fib_path_pool, path);
1181 memset(path, 0, sizeof(*path));
1183 fib_node_init(&path->fp_node,
1184 FIB_NODE_TYPE_PATH);
1185 dpo_reset(&path->fp_dpo);
1187 path->fp_pl_index = pl_index;
1188 path->fp_weight = 1;
1189 path->fp_preference = 0;
1190 path->fp_nh_proto = nh_proto;
1191 path->fp_via_fib = FIB_NODE_INDEX_INVALID;
1192 path->fp_cfg_flags = flags;
1194 if (FIB_PATH_CFG_FLAG_DROP & flags)
1196 path->fp_type = FIB_PATH_TYPE_SPECIAL;
1198 else if (FIB_PATH_CFG_FLAG_LOCAL & flags)
1200 path->fp_type = FIB_PATH_TYPE_RECEIVE;
1201 path->attached.fp_interface = FIB_NODE_INDEX_INVALID;
1205 path->fp_type = FIB_PATH_TYPE_EXCLUSIVE;
1206 ASSERT(NULL != dpo);
1207 dpo_copy(&path->exclusive.fp_ex_dpo, dpo);
1210 return (fib_path_get_index(path));
1216 * Copy a path. return index of new path.
1219 fib_path_copy (fib_node_index_t path_index,
1220 fib_node_index_t path_list_index)
1222 fib_path_t *path, *orig_path;
1224 pool_get(fib_path_pool, path);
1226 orig_path = fib_path_get(path_index);
1227 ASSERT(NULL != orig_path);
1229 memcpy(path, orig_path, sizeof(*path));
1231 FIB_PATH_DBG(path, "create-copy:%d", path_index);
1234 * reset the dynamic section
1236 fib_node_init(&path->fp_node, FIB_NODE_TYPE_PATH);
1237 path->fp_oper_flags = FIB_PATH_OPER_FLAG_NONE;
1238 path->fp_pl_index = path_list_index;
1239 path->fp_via_fib = FIB_NODE_INDEX_INVALID;
1240 memset(&path->fp_dpo, 0, sizeof(path->fp_dpo));
1241 dpo_reset(&path->fp_dpo);
1243 return (fib_path_get_index(path));
1249 * destroy a path that is no longer required
1252 fib_path_destroy (fib_node_index_t path_index)
1256 path = fib_path_get(path_index);
1258 ASSERT(NULL != path);
1259 FIB_PATH_DBG(path, "destroy");
1261 fib_path_unresolve(path);
1263 fib_node_deinit(&path->fp_node);
1264 pool_put(fib_path_pool, path);
1270 * destroy a path that is no longer required
1273 fib_path_hash (fib_node_index_t path_index)
1277 path = fib_path_get(path_index);
1279 return (hash_memory(STRUCT_MARK_PTR(path, path_hash_start),
1280 (STRUCT_OFFSET_OF(fib_path_t, path_hash_end) -
1281 STRUCT_OFFSET_OF(fib_path_t, path_hash_start)),
1288 * Compare two paths for equivalence.
1291 fib_path_cmp_i (const fib_path_t *path1,
1292 const fib_path_t *path2)
1299 * paths of different types and protocol are not equal.
1300 * different weights and/or preference only are the same path.
1302 if (path1->fp_type != path2->fp_type)
1304 res = (path1->fp_type - path2->fp_type);
1306 else if (path1->fp_nh_proto != path2->fp_nh_proto)
1308 res = (path1->fp_nh_proto - path2->fp_nh_proto);
1313 * both paths are of the same type.
1314 * consider each type and its attributes in turn.
1316 switch (path1->fp_type)
1318 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1319 res = ip46_address_cmp(&path1->attached_next_hop.fp_nh,
1320 &path2->attached_next_hop.fp_nh);
1322 res = (path1->attached_next_hop.fp_interface -
1323 path2->attached_next_hop.fp_interface);
1326 case FIB_PATH_TYPE_ATTACHED:
1327 res = (path1->attached.fp_interface -
1328 path2->attached.fp_interface);
1330 case FIB_PATH_TYPE_RECURSIVE:
1331 res = ip46_address_cmp(&path1->recursive.fp_nh,
1332 &path2->recursive.fp_nh);
1336 res = (path1->recursive.fp_tbl_id - path2->recursive.fp_tbl_id);
1339 case FIB_PATH_TYPE_DEAG:
1340 res = (path1->deag.fp_tbl_id - path2->deag.fp_tbl_id);
1343 res = (path1->deag.fp_rpf_id - path2->deag.fp_rpf_id);
1346 case FIB_PATH_TYPE_INTF_RX:
1347 res = (path1->intf_rx.fp_interface - path2->intf_rx.fp_interface);
1349 case FIB_PATH_TYPE_SPECIAL:
1350 case FIB_PATH_TYPE_RECEIVE:
1351 case FIB_PATH_TYPE_EXCLUSIVE:
1360 * fib_path_cmp_for_sort
1362 * Compare two paths for equivalence. Used during path sorting.
1363 * As usual 0 means equal.
1366 fib_path_cmp_for_sort (void * v1,
1369 fib_node_index_t *pi1 = v1, *pi2 = v2;
1370 fib_path_t *path1, *path2;
1372 path1 = fib_path_get(*pi1);
1373 path2 = fib_path_get(*pi2);
1376 * when sorting paths we want the highest preference paths
1377 * first, so that the choices set built is in prefernce order
1379 if (path1->fp_preference != path2->fp_preference)
1381 return (path1->fp_preference - path2->fp_preference);
1384 return (fib_path_cmp_i(path1, path2));
1390 * Compare two paths for equivalence.
1393 fib_path_cmp (fib_node_index_t pi1,
1394 fib_node_index_t pi2)
1396 fib_path_t *path1, *path2;
1398 path1 = fib_path_get(pi1);
1399 path2 = fib_path_get(pi2);
1401 return (fib_path_cmp_i(path1, path2));
1405 fib_path_cmp_w_route_path (fib_node_index_t path_index,
1406 const fib_route_path_t *rpath)
1411 path = fib_path_get(path_index);
1415 if (path->fp_weight != rpath->frp_weight)
1417 res = (path->fp_weight - rpath->frp_weight);
1422 * both paths are of the same type.
1423 * consider each type and its attributes in turn.
1425 switch (path->fp_type)
1427 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1428 res = ip46_address_cmp(&path->attached_next_hop.fp_nh,
1432 res = (path->attached_next_hop.fp_interface -
1433 rpath->frp_sw_if_index);
1436 case FIB_PATH_TYPE_ATTACHED:
1437 res = (path->attached.fp_interface - rpath->frp_sw_if_index);
1439 case FIB_PATH_TYPE_RECURSIVE:
1440 if (DPO_PROTO_MPLS == path->fp_nh_proto)
1442 res = path->recursive.fp_nh.fp_local_label - rpath->frp_local_label;
1446 res = path->recursive.fp_nh.fp_eos - rpath->frp_eos;
1451 res = ip46_address_cmp(&path->recursive.fp_nh.fp_ip,
1457 res = (path->recursive.fp_tbl_id - rpath->frp_fib_index);
1460 case FIB_PATH_TYPE_INTF_RX:
1461 res = (path->intf_rx.fp_interface - rpath->frp_sw_if_index);
1463 case FIB_PATH_TYPE_DEAG:
1464 res = (path->deag.fp_tbl_id - rpath->frp_fib_index);
1467 res = (path->deag.fp_rpf_id - rpath->frp_rpf_id);
1470 case FIB_PATH_TYPE_SPECIAL:
1471 case FIB_PATH_TYPE_RECEIVE:
1472 case FIB_PATH_TYPE_EXCLUSIVE:
1481 * fib_path_recursive_loop_detect
1483 * A forward walk of the FIB object graph to detect for a cycle/loop. This
1484 * walk is initiated when an entry is linking to a new path list or from an old.
1485 * The entry vector passed contains all the FIB entrys that are children of this
1486 * path (it is all the entries encountered on the walk so far). If this vector
1487 * contains the entry this path resolve via, then a loop is about to form.
1488 * The loop must be allowed to form, since we need the dependencies in place
1489 * so that we can track when the loop breaks.
1490 * However, we MUST not produce a loop in the forwarding graph (else packets
1491 * would loop around the switch path until the loop breaks), so we mark recursive
1492 * paths as looped so that they do not contribute forwarding information.
1493 * By marking the path as looped, an etry such as;
1495 * via a.a.a.a (looped)
1496 * via b.b.b.b (not looped)
1497 * can still forward using the info provided by b.b.b.b only
1500 fib_path_recursive_loop_detect (fib_node_index_t path_index,
1501 fib_node_index_t **entry_indicies)
1505 path = fib_path_get(path_index);
1508 * the forced drop path is never looped, cos it is never resolved.
1510 if (fib_path_is_permanent_drop(path))
1515 switch (path->fp_type)
1517 case FIB_PATH_TYPE_RECURSIVE:
1519 fib_node_index_t *entry_index, *entries;
1521 entries = *entry_indicies;
1523 vec_foreach(entry_index, entries) {
1524 if (*entry_index == path->fp_via_fib)
1527 * the entry that is about to link to this path-list (or
1528 * one of this path-list's children) is the same entry that
1529 * this recursive path resolves through. this is a cycle.
1539 FIB_PATH_DBG(path, "recursive loop formed");
1540 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RECURSIVE_LOOP;
1542 dpo_copy(&path->fp_dpo, drop_dpo_get(path->fp_nh_proto));
1547 * no loop here yet. keep forward walking the graph.
1549 if (fib_entry_recursive_loop_detect(path->fp_via_fib, entry_indicies))
1551 FIB_PATH_DBG(path, "recursive loop formed");
1552 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RECURSIVE_LOOP;
1556 FIB_PATH_DBG(path, "recursive loop cleared");
1557 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RECURSIVE_LOOP;
1562 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1563 case FIB_PATH_TYPE_ATTACHED:
1564 case FIB_PATH_TYPE_SPECIAL:
1565 case FIB_PATH_TYPE_DEAG:
1566 case FIB_PATH_TYPE_RECEIVE:
1567 case FIB_PATH_TYPE_INTF_RX:
1568 case FIB_PATH_TYPE_EXCLUSIVE:
1570 * these path types cannot be part of a loop, since they are the leaves
1576 return (fib_path_is_looped(path_index));
1580 fib_path_resolve (fib_node_index_t path_index)
1584 path = fib_path_get(path_index);
1587 * hope for the best.
1589 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RESOLVED;
1592 * the forced drop path resolves via the drop adj
1594 if (fib_path_is_permanent_drop(path))
1596 dpo_copy(&path->fp_dpo, drop_dpo_get(path->fp_nh_proto));
1597 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
1598 return (fib_path_is_resolved(path_index));
1601 switch (path->fp_type)
1603 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1604 fib_path_attached_next_hop_set(path);
1606 case FIB_PATH_TYPE_ATTACHED:
1607 if (DPO_PROTO_ETHERNET == path->fp_nh_proto)
1609 l2_bridge_dpo_add_or_lock(path->attached.fp_interface,
1615 * path->attached.fp_interface
1617 if (!vnet_sw_interface_is_admin_up(vnet_get_main(),
1618 path->attached.fp_interface))
1620 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
1622 dpo_set(&path->fp_dpo,
1625 fib_path_attached_get_adj(path,
1626 dpo_proto_to_link(path->fp_nh_proto)));
1629 * become a child of the adjacency so we receive updates
1630 * when the interface state changes
1632 path->fp_sibling = adj_child_add(path->fp_dpo.dpoi_index,
1634 fib_path_get_index(path));
1637 case FIB_PATH_TYPE_RECURSIVE:
1640 * Create a RR source entry in the table for the address
1641 * that this path recurses through.
1642 * This resolve action is recursive, hence we may create
1643 * more paths in the process. more creates mean maybe realloc
1646 fib_node_index_t fei;
1649 ASSERT(FIB_NODE_INDEX_INVALID == path->fp_via_fib);
1651 if (DPO_PROTO_MPLS == path->fp_nh_proto)
1653 fib_prefix_from_mpls_label(path->recursive.fp_nh.fp_local_label,
1654 path->recursive.fp_nh.fp_eos,
1659 fib_prefix_from_ip46_addr(&path->recursive.fp_nh.fp_ip, &pfx);
1662 fei = fib_table_entry_special_add(path->recursive.fp_tbl_id,
1665 FIB_ENTRY_FLAG_NONE);
1667 path = fib_path_get(path_index);
1668 path->fp_via_fib = fei;
1671 * become a dependent child of the entry so the path is
1672 * informed when the forwarding for the entry changes.
1674 path->fp_sibling = fib_entry_child_add(path->fp_via_fib,
1676 fib_path_get_index(path));
1679 * create and configure the IP DPO
1681 fib_path_recursive_adj_update(
1683 fib_path_to_chain_type(path),
1688 case FIB_PATH_TYPE_SPECIAL:
1690 * Resolve via the drop
1692 dpo_copy(&path->fp_dpo, drop_dpo_get(path->fp_nh_proto));
1694 case FIB_PATH_TYPE_DEAG:
1697 * Resolve via a lookup DPO.
1698 * FIXME. control plane should add routes with a table ID
1700 lookup_input_t input;
1703 cast = (path->fp_cfg_flags & FIB_PATH_CFG_FLAG_RPF_ID ?
1706 input = (path->fp_cfg_flags & FIB_PATH_CFG_FLAG_DEAG_SRC ?
1707 LOOKUP_INPUT_SRC_ADDR :
1708 LOOKUP_INPUT_DST_ADDR);
1710 lookup_dpo_add_or_lock_w_fib_index(path->deag.fp_tbl_id,
1714 LOOKUP_TABLE_FROM_CONFIG,
1718 case FIB_PATH_TYPE_RECEIVE:
1720 * Resolve via a receive DPO.
1722 receive_dpo_add_or_lock(path->fp_nh_proto,
1723 path->receive.fp_interface,
1724 &path->receive.fp_addr,
1727 case FIB_PATH_TYPE_INTF_RX: {
1729 * Resolve via a receive DPO.
1731 interface_rx_dpo_add_or_lock(path->fp_nh_proto,
1732 path->intf_rx.fp_interface,
1736 case FIB_PATH_TYPE_EXCLUSIVE:
1738 * Resolve via the user provided DPO
1740 dpo_copy(&path->fp_dpo, &path->exclusive.fp_ex_dpo);
1744 return (fib_path_is_resolved(path_index));
1748 fib_path_get_resolving_interface (fib_node_index_t path_index)
1752 path = fib_path_get(path_index);
1754 switch (path->fp_type)
1756 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1757 return (path->attached_next_hop.fp_interface);
1758 case FIB_PATH_TYPE_ATTACHED:
1759 return (path->attached.fp_interface);
1760 case FIB_PATH_TYPE_RECEIVE:
1761 return (path->receive.fp_interface);
1762 case FIB_PATH_TYPE_RECURSIVE:
1763 if (fib_path_is_resolved(path_index))
1765 return (fib_entry_get_resolving_interface(path->fp_via_fib));
1768 case FIB_PATH_TYPE_INTF_RX:
1769 case FIB_PATH_TYPE_SPECIAL:
1770 case FIB_PATH_TYPE_DEAG:
1771 case FIB_PATH_TYPE_EXCLUSIVE:
1778 fib_path_get_adj (fib_node_index_t path_index)
1782 path = fib_path_get(path_index);
1784 ASSERT(dpo_is_adj(&path->fp_dpo));
1785 if (dpo_is_adj(&path->fp_dpo))
1787 return (path->fp_dpo.dpoi_index);
1789 return (ADJ_INDEX_INVALID);
1793 fib_path_get_weight (fib_node_index_t path_index)
1797 path = fib_path_get(path_index);
1801 return (path->fp_weight);
1805 fib_path_get_preference (fib_node_index_t path_index)
1809 path = fib_path_get(path_index);
1813 return (path->fp_preference);
1817 * @brief Contribute the path's adjacency to the list passed.
1818 * By calling this function over all paths, recursively, a child
1819 * can construct its full set of forwarding adjacencies, and hence its
1823 fib_path_contribute_urpf (fib_node_index_t path_index,
1828 path = fib_path_get(path_index);
1831 * resolved and unresolved paths contribute to the RPF list.
1833 switch (path->fp_type)
1835 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1836 fib_urpf_list_append(urpf, path->attached_next_hop.fp_interface);
1839 case FIB_PATH_TYPE_ATTACHED:
1840 fib_urpf_list_append(urpf, path->attached.fp_interface);
1843 case FIB_PATH_TYPE_RECURSIVE:
1844 if (FIB_NODE_INDEX_INVALID != path->fp_via_fib &&
1845 !fib_path_is_looped(path_index))
1848 * there's unresolved due to constraints, and there's unresolved
1849 * due to ain't got no via. can't do nowt w'out via.
1851 fib_entry_contribute_urpf(path->fp_via_fib, urpf);
1855 case FIB_PATH_TYPE_EXCLUSIVE:
1856 case FIB_PATH_TYPE_SPECIAL:
1859 * these path types may link to an adj, if that's what
1862 u32 rpf_sw_if_index;
1864 rpf_sw_if_index = dpo_get_urpf(&path->fp_dpo);
1866 if (~0 != rpf_sw_if_index)
1868 fib_urpf_list_append(urpf, rpf_sw_if_index);
1872 case FIB_PATH_TYPE_DEAG:
1873 case FIB_PATH_TYPE_RECEIVE:
1874 case FIB_PATH_TYPE_INTF_RX:
1876 * these path types don't link to an adj
1883 fib_path_stack_mpls_disp (fib_node_index_t path_index,
1884 dpo_proto_t payload_proto,
1889 path = fib_path_get(path_index);
1893 switch (path->fp_type)
1895 case FIB_PATH_TYPE_DEAG:
1897 dpo_id_t tmp = DPO_INVALID;
1899 dpo_copy(&tmp, dpo);
1901 DPO_MPLS_DISPOSITION,
1903 mpls_disp_dpo_create(payload_proto,
1904 path->deag.fp_rpf_id,
1909 case FIB_PATH_TYPE_RECEIVE:
1910 case FIB_PATH_TYPE_ATTACHED:
1911 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1912 case FIB_PATH_TYPE_RECURSIVE:
1913 case FIB_PATH_TYPE_INTF_RX:
1914 case FIB_PATH_TYPE_EXCLUSIVE:
1915 case FIB_PATH_TYPE_SPECIAL:
1921 fib_path_contribute_forwarding (fib_node_index_t path_index,
1922 fib_forward_chain_type_t fct,
1927 path = fib_path_get(path_index);
1930 ASSERT(FIB_FORW_CHAIN_TYPE_MPLS_EOS != fct);
1932 FIB_PATH_DBG(path, "contribute");
1935 * The DPO stored in the path was created when the path was resolved.
1936 * This then represents the path's 'native' protocol; IP.
1937 * For all others will need to go find something else.
1939 if (fib_path_to_chain_type(path) == fct)
1941 dpo_copy(dpo, &path->fp_dpo);
1945 switch (path->fp_type)
1947 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1950 case FIB_FORW_CHAIN_TYPE_UNICAST_IP4:
1951 case FIB_FORW_CHAIN_TYPE_UNICAST_IP6:
1952 case FIB_FORW_CHAIN_TYPE_MPLS_EOS:
1953 case FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS:
1954 case FIB_FORW_CHAIN_TYPE_ETHERNET:
1955 case FIB_FORW_CHAIN_TYPE_NSH:
1960 * get a appropriate link type adj.
1962 ai = fib_path_attached_next_hop_get_adj(
1964 fib_forw_chain_type_to_link_type(fct));
1965 dpo_set(dpo, DPO_ADJACENCY,
1966 fib_forw_chain_type_to_dpo_proto(fct), ai);
1971 case FIB_FORW_CHAIN_TYPE_MCAST_IP4:
1972 case FIB_FORW_CHAIN_TYPE_MCAST_IP6:
1976 case FIB_PATH_TYPE_RECURSIVE:
1979 case FIB_FORW_CHAIN_TYPE_MPLS_EOS:
1980 case FIB_FORW_CHAIN_TYPE_UNICAST_IP4:
1981 case FIB_FORW_CHAIN_TYPE_UNICAST_IP6:
1982 case FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS:
1983 case FIB_FORW_CHAIN_TYPE_MCAST_IP4:
1984 case FIB_FORW_CHAIN_TYPE_MCAST_IP6:
1985 fib_path_recursive_adj_update(path, fct, dpo);
1987 case FIB_FORW_CHAIN_TYPE_ETHERNET:
1988 case FIB_FORW_CHAIN_TYPE_NSH:
1993 case FIB_PATH_TYPE_DEAG:
1996 case FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS:
1997 lookup_dpo_add_or_lock_w_table_id(MPLS_FIB_DEFAULT_TABLE_ID,
2000 LOOKUP_INPUT_DST_ADDR,
2001 LOOKUP_TABLE_FROM_CONFIG,
2004 case FIB_FORW_CHAIN_TYPE_MPLS_EOS:
2005 case FIB_FORW_CHAIN_TYPE_UNICAST_IP4:
2006 case FIB_FORW_CHAIN_TYPE_UNICAST_IP6:
2007 dpo_copy(dpo, &path->fp_dpo);
2009 case FIB_FORW_CHAIN_TYPE_MCAST_IP4:
2010 case FIB_FORW_CHAIN_TYPE_MCAST_IP6:
2011 case FIB_FORW_CHAIN_TYPE_ETHERNET:
2012 case FIB_FORW_CHAIN_TYPE_NSH:
2017 case FIB_PATH_TYPE_EXCLUSIVE:
2018 dpo_copy(dpo, &path->exclusive.fp_ex_dpo);
2020 case FIB_PATH_TYPE_ATTACHED:
2021 if (DPO_PROTO_ETHERNET == path->fp_nh_proto)
2023 dpo_copy(dpo, &path->fp_dpo);
2028 case FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS:
2029 case FIB_FORW_CHAIN_TYPE_UNICAST_IP4:
2030 case FIB_FORW_CHAIN_TYPE_UNICAST_IP6:
2031 case FIB_FORW_CHAIN_TYPE_MPLS_EOS:
2032 case FIB_FORW_CHAIN_TYPE_ETHERNET:
2033 case FIB_FORW_CHAIN_TYPE_NSH:
2038 * get a appropriate link type adj.
2040 ai = fib_path_attached_get_adj(
2042 fib_forw_chain_type_to_link_type(fct));
2043 dpo_set(dpo, DPO_ADJACENCY,
2044 fib_forw_chain_type_to_dpo_proto(fct), ai);
2048 case FIB_FORW_CHAIN_TYPE_MCAST_IP4:
2049 case FIB_FORW_CHAIN_TYPE_MCAST_IP6:
2054 * Create the adj needed for sending IP multicast traffic
2056 ai = adj_mcast_add_or_lock(dpo_proto_to_fib(path->fp_nh_proto),
2057 fib_forw_chain_type_to_link_type(fct),
2058 path->attached.fp_interface);
2059 dpo_set(dpo, DPO_ADJACENCY,
2060 fib_forw_chain_type_to_dpo_proto(fct),
2067 case FIB_PATH_TYPE_INTF_RX:
2069 * Create the adj needed for sending IP multicast traffic
2071 interface_rx_dpo_add_or_lock(fib_forw_chain_type_to_dpo_proto(fct),
2072 path->attached.fp_interface,
2075 case FIB_PATH_TYPE_RECEIVE:
2076 case FIB_PATH_TYPE_SPECIAL:
2077 dpo_copy(dpo, &path->fp_dpo);
2083 load_balance_path_t *
2084 fib_path_append_nh_for_multipath_hash (fib_node_index_t path_index,
2085 fib_forward_chain_type_t fct,
2086 load_balance_path_t *hash_key)
2088 load_balance_path_t *mnh;
2091 path = fib_path_get(path_index);
2095 if (fib_path_is_resolved(path_index))
2097 vec_add2(hash_key, mnh, 1);
2099 mnh->path_weight = path->fp_weight;
2100 mnh->path_index = path_index;
2101 fib_path_contribute_forwarding(path_index, fct, &mnh->path_dpo);
2108 fib_path_is_recursive_constrained (fib_node_index_t path_index)
2112 path = fib_path_get(path_index);
2114 return ((FIB_PATH_TYPE_RECURSIVE == path->fp_type) &&
2115 ((path->fp_cfg_flags & FIB_PATH_CFG_FLAG_RESOLVE_ATTACHED) ||
2116 (path->fp_cfg_flags & FIB_PATH_CFG_FLAG_RESOLVE_HOST)));
2120 fib_path_is_exclusive (fib_node_index_t path_index)
2124 path = fib_path_get(path_index);
2126 return (FIB_PATH_TYPE_EXCLUSIVE == path->fp_type);
2130 fib_path_is_deag (fib_node_index_t path_index)
2134 path = fib_path_get(path_index);
2136 return (FIB_PATH_TYPE_DEAG == path->fp_type);
2140 fib_path_is_resolved (fib_node_index_t path_index)
2144 path = fib_path_get(path_index);
2146 return (dpo_id_is_valid(&path->fp_dpo) &&
2147 (path->fp_oper_flags & FIB_PATH_OPER_FLAG_RESOLVED) &&
2148 !fib_path_is_looped(path_index) &&
2149 !fib_path_is_permanent_drop(path));
2153 fib_path_is_looped (fib_node_index_t path_index)
2157 path = fib_path_get(path_index);
2159 return (path->fp_oper_flags & FIB_PATH_OPER_FLAG_RECURSIVE_LOOP);
2162 fib_path_list_walk_rc_t
2163 fib_path_encode (fib_node_index_t path_list_index,
2164 fib_node_index_t path_index,
2167 fib_route_path_encode_t **api_rpaths = ctx;
2168 fib_route_path_encode_t *api_rpath;
2171 path = fib_path_get(path_index);
2173 return (FIB_PATH_LIST_WALK_CONTINUE);
2174 vec_add2(*api_rpaths, api_rpath, 1);
2175 api_rpath->rpath.frp_weight = path->fp_weight;
2176 api_rpath->rpath.frp_preference = path->fp_preference;
2177 api_rpath->rpath.frp_proto = path->fp_nh_proto;
2178 api_rpath->rpath.frp_sw_if_index = ~0;
2179 api_rpath->dpo = path->exclusive.fp_ex_dpo;
2180 switch (path->fp_type)
2182 case FIB_PATH_TYPE_RECEIVE:
2183 api_rpath->rpath.frp_addr = path->receive.fp_addr;
2184 api_rpath->rpath.frp_sw_if_index = path->receive.fp_interface;
2185 api_rpath->dpo = path->fp_dpo;
2187 case FIB_PATH_TYPE_ATTACHED:
2188 api_rpath->rpath.frp_sw_if_index = path->attached.fp_interface;
2189 api_rpath->dpo = path->fp_dpo;
2191 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
2192 api_rpath->rpath.frp_sw_if_index = path->attached_next_hop.fp_interface;
2193 api_rpath->rpath.frp_addr = path->attached_next_hop.fp_nh;
2195 case FIB_PATH_TYPE_SPECIAL:
2197 case FIB_PATH_TYPE_DEAG:
2198 api_rpath->rpath.frp_fib_index = path->deag.fp_tbl_id;
2199 api_rpath->dpo = path->fp_dpo;
2201 case FIB_PATH_TYPE_RECURSIVE:
2202 api_rpath->rpath.frp_addr = path->recursive.fp_nh.fp_ip;
2207 return (FIB_PATH_LIST_WALK_CONTINUE);
2211 fib_path_get_proto (fib_node_index_t path_index)
2215 path = fib_path_get(path_index);
2217 return (path->fp_nh_proto);
2221 fib_path_module_init (void)
2223 fib_node_register_type (FIB_NODE_TYPE_PATH, &fib_path_vft);
2226 static clib_error_t *
2227 show_fib_path_command (vlib_main_t * vm,
2228 unformat_input_t * input,
2229 vlib_cli_command_t * cmd)
2231 fib_node_index_t pi;
2234 if (unformat (input, "%d", &pi))
2237 * show one in detail
2239 if (!pool_is_free_index(fib_path_pool, pi))
2241 path = fib_path_get(pi);
2242 u8 *s = fib_path_format(pi, NULL);
2243 s = format(s, "children:");
2244 s = fib_node_children_format(path->fp_node.fn_children, s);
2245 vlib_cli_output (vm, "%s", s);
2250 vlib_cli_output (vm, "path %d invalid", pi);
2255 vlib_cli_output (vm, "FIB Paths");
2256 pool_foreach(path, fib_path_pool,
2258 vlib_cli_output (vm, "%U", format_fib_path, path);
2265 VLIB_CLI_COMMAND (show_fib_path, static) = {
2266 .path = "show fib paths",
2267 .function = show_fib_path_command,
2268 .short_help = "show fib paths",