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_dpo.h>
25 #include <vnet/dpo/mpls_disposition.h>
27 #include <vnet/adj/adj.h>
28 #include <vnet/adj/adj_mcast.h>
30 #include <vnet/fib/fib_path.h>
31 #include <vnet/fib/fib_node.h>
32 #include <vnet/fib/fib_table.h>
33 #include <vnet/fib/fib_entry.h>
34 #include <vnet/fib/fib_path_list.h>
35 #include <vnet/fib/fib_internal.h>
36 #include <vnet/fib/fib_urpf_list.h>
37 #include <vnet/fib/mpls_fib.h>
40 * Enurmeration of path types
42 typedef enum fib_path_type_t_ {
44 * Marker. Add new types after this one.
46 FIB_PATH_TYPE_FIRST = 0,
48 * Attached-nexthop. An interface and a nexthop are known.
50 FIB_PATH_TYPE_ATTACHED_NEXT_HOP = FIB_PATH_TYPE_FIRST,
52 * attached. Only the interface is known.
54 FIB_PATH_TYPE_ATTACHED,
56 * recursive. Only the next-hop is known.
58 FIB_PATH_TYPE_RECURSIVE,
60 * special. nothing is known. so we drop.
62 FIB_PATH_TYPE_SPECIAL,
64 * exclusive. user provided adj.
66 FIB_PATH_TYPE_EXCLUSIVE,
68 * deag. Link to a lookup adj in the next table
74 FIB_PATH_TYPE_INTF_RX,
76 * receive. it's for-us.
78 FIB_PATH_TYPE_RECEIVE,
80 * Marker. Add new types before this one, then update it.
82 FIB_PATH_TYPE_LAST = FIB_PATH_TYPE_RECEIVE,
83 } __attribute__ ((packed)) fib_path_type_t;
86 * The maximum number of path_types
88 #define FIB_PATH_TYPE_MAX (FIB_PATH_TYPE_LAST + 1)
90 #define FIB_PATH_TYPES { \
91 [FIB_PATH_TYPE_ATTACHED_NEXT_HOP] = "attached-nexthop", \
92 [FIB_PATH_TYPE_ATTACHED] = "attached", \
93 [FIB_PATH_TYPE_RECURSIVE] = "recursive", \
94 [FIB_PATH_TYPE_SPECIAL] = "special", \
95 [FIB_PATH_TYPE_EXCLUSIVE] = "exclusive", \
96 [FIB_PATH_TYPE_DEAG] = "deag", \
97 [FIB_PATH_TYPE_INTF_RX] = "intf-rx", \
98 [FIB_PATH_TYPE_RECEIVE] = "receive", \
101 #define FOR_EACH_FIB_PATH_TYPE(_item) \
102 for (_item = FIB_PATH_TYPE_FIRST; _item <= FIB_PATH_TYPE_LAST; _item++)
105 * Enurmeration of path operational (i.e. derived) attributes
107 typedef enum fib_path_oper_attribute_t_ {
109 * Marker. Add new types after this one.
111 FIB_PATH_OPER_ATTRIBUTE_FIRST = 0,
113 * The path forms part of a recursive loop.
115 FIB_PATH_OPER_ATTRIBUTE_RECURSIVE_LOOP = FIB_PATH_OPER_ATTRIBUTE_FIRST,
117 * The path is resolved
119 FIB_PATH_OPER_ATTRIBUTE_RESOLVED,
121 * The path is attached, despite what the next-hop may say.
123 FIB_PATH_OPER_ATTRIBUTE_ATTACHED,
125 * The path has become a permanent drop.
127 FIB_PATH_OPER_ATTRIBUTE_DROP,
129 * Marker. Add new types before this one, then update it.
131 FIB_PATH_OPER_ATTRIBUTE_LAST = FIB_PATH_OPER_ATTRIBUTE_DROP,
132 } __attribute__ ((packed)) fib_path_oper_attribute_t;
135 * The maximum number of path operational attributes
137 #define FIB_PATH_OPER_ATTRIBUTE_MAX (FIB_PATH_OPER_ATTRIBUTE_LAST + 1)
139 #define FIB_PATH_OPER_ATTRIBUTES { \
140 [FIB_PATH_OPER_ATTRIBUTE_RECURSIVE_LOOP] = "recursive-loop", \
141 [FIB_PATH_OPER_ATTRIBUTE_RESOLVED] = "resolved", \
142 [FIB_PATH_OPER_ATTRIBUTE_DROP] = "drop", \
145 #define FOR_EACH_FIB_PATH_OPER_ATTRIBUTE(_item) \
146 for (_item = FIB_PATH_OPER_ATTRIBUTE_FIRST; \
147 _item <= FIB_PATH_OPER_ATTRIBUTE_LAST; \
151 * Path flags from the attributes
153 typedef enum fib_path_oper_flags_t_ {
154 FIB_PATH_OPER_FLAG_NONE = 0,
155 FIB_PATH_OPER_FLAG_RECURSIVE_LOOP = (1 << FIB_PATH_OPER_ATTRIBUTE_RECURSIVE_LOOP),
156 FIB_PATH_OPER_FLAG_DROP = (1 << FIB_PATH_OPER_ATTRIBUTE_DROP),
157 FIB_PATH_OPER_FLAG_RESOLVED = (1 << FIB_PATH_OPER_ATTRIBUTE_RESOLVED),
158 FIB_PATH_OPER_FLAG_ATTACHED = (1 << FIB_PATH_OPER_ATTRIBUTE_ATTACHED),
159 } __attribute__ ((packed)) fib_path_oper_flags_t;
164 typedef struct fib_path_t_ {
166 * A path is a node in the FIB graph.
171 * The index of the path-list to which this path belongs
176 * This marks the start of the memory area used to hash
179 STRUCT_MARK(path_hash_start);
182 * Configuration Flags
184 fib_path_cfg_flags_t fp_cfg_flags;
187 * The type of the path. This is the selector for the union
189 fib_path_type_t fp_type;
192 * The protocol of the next-hop, i.e. the address family of the
193 * next-hop's address. We can't derive this from the address itself
194 * since the address can be all zeros
196 fib_protocol_t fp_nh_proto;
199 * UCMP [unnormalised] weigt
204 * per-type union of the data required to resolve the path
211 ip46_address_t fp_nh;
229 ip46_address_t fp_ip;
232 * The local label to resolve through.
234 mpls_label_t fp_local_label;
236 * The EOS bit of the resolving label
238 mpls_eos_bit_t fp_eos;
242 * The FIB table index in which to find the next-hop.
243 * This needs to be fixed. We should lookup the adjacencies in
244 * a separate table of adjacencies, rather than from the FIB.
245 * Two reasons I can think of:
247 * int ip addr Gig0 10.0.0.1/24
248 * ip route 10.0.0.2/32 via Gig1 192.168.1.2
249 * ip route 1.1.1.1/32 via Gig0 10.0.0.2
250 * this is perfectly valid.
251 * Packets addressed to 10.0.0.2 should be sent via Gig1.
252 * Packets address to 1.1.1.1 should be sent via Gig0.
253 * when we perform the adj resolution from the FIB for the path
254 * "via Gig0 10.0.0.2" the lookup will result in the route via Gig1
255 * and so we will pick up the adj via Gig1 - which was not what the
257 * - we can only return link-type IPv4 and so not the link-type MPLS.
258 * more on this in a later commit.
260 * The table ID should only belong to a recursive path and indicate
261 * which FIB should be used to resolve the next-hop.
263 fib_node_index_t fp_tbl_id;
267 * The FIB index in which to perfom the next lookup
269 fib_node_index_t fp_tbl_id;
271 * The RPF-ID to tag the packets with
273 fib_rpf_id_t fp_rpf_id;
279 * The user provided 'exclusive' DPO
285 * The interface on which the local address is configured
291 ip46_address_t fp_addr;
295 * The interface on which the packets will be input.
300 STRUCT_MARK(path_hash_end);
303 * Memebers in this last section represent information that is
304 * dervied during resolution. It should not be copied to new paths
311 fib_path_oper_flags_t fp_oper_flags;
314 * the resolving via fib. not part of the union, since it it not part
315 * of the path's hash.
317 fib_node_index_t fp_via_fib;
320 * The Data-path objects through which this path resolves for IP.
325 * the index of this path in the parent's child list.
331 * Array of strings/names for the path types and attributes
333 static const char *fib_path_type_names[] = FIB_PATH_TYPES;
334 static const char *fib_path_oper_attribute_names[] = FIB_PATH_OPER_ATTRIBUTES;
335 static const char *fib_path_cfg_attribute_names[] = FIB_PATH_CFG_ATTRIBUTES;
338 * The memory pool from which we allocate all the paths
340 static fib_path_t *fib_path_pool;
346 #define FIB_PATH_DBG(_p, _fmt, _args...) \
349 _tmp = fib_path_format(fib_path_get_index(_p), _tmp); \
350 clib_warning("path:[%d:%s]:" _fmt, \
351 fib_path_get_index(_p), _tmp, \
356 #define FIB_PATH_DBG(_p, _fmt, _args...)
360 fib_path_get (fib_node_index_t index)
362 return (pool_elt_at_index(fib_path_pool, index));
365 static fib_node_index_t
366 fib_path_get_index (fib_path_t *path)
368 return (path - fib_path_pool);
372 fib_path_get_node (fib_node_index_t index)
374 return ((fib_node_t*)fib_path_get(index));
378 fib_path_from_fib_node (fib_node_t *node)
381 ASSERT(FIB_NODE_TYPE_PATH == node->fn_type);
383 return ((fib_path_t*)node);
387 format_fib_path (u8 * s, va_list * args)
389 fib_path_t *path = va_arg (*args, fib_path_t *);
390 vnet_main_t * vnm = vnet_get_main();
391 fib_path_oper_attribute_t oattr;
392 fib_path_cfg_attribute_t cattr;
394 s = format (s, " index:%d ", fib_path_get_index(path));
395 s = format (s, "pl-index:%d ", path->fp_pl_index);
396 s = format (s, "%U ", format_fib_protocol, path->fp_nh_proto);
397 s = format (s, "weight=%d ", path->fp_weight);
398 s = format (s, "%s: ", fib_path_type_names[path->fp_type]);
399 if (FIB_PATH_OPER_FLAG_NONE != path->fp_oper_flags) {
400 s = format(s, " oper-flags:");
401 FOR_EACH_FIB_PATH_OPER_ATTRIBUTE(oattr) {
402 if ((1<<oattr) & path->fp_oper_flags) {
403 s = format (s, "%s,", fib_path_oper_attribute_names[oattr]);
407 if (FIB_PATH_CFG_FLAG_NONE != path->fp_cfg_flags) {
408 s = format(s, " cfg-flags:");
409 FOR_EACH_FIB_PATH_CFG_ATTRIBUTE(cattr) {
410 if ((1<<cattr) & path->fp_cfg_flags) {
411 s = format (s, "%s,", fib_path_cfg_attribute_names[cattr]);
415 s = format(s, "\n ");
417 switch (path->fp_type)
419 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
420 s = format (s, "%U", format_ip46_address,
421 &path->attached_next_hop.fp_nh,
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_next_hop.fp_interface));
435 if (vnet_sw_interface_is_p2p(vnet_get_main(),
436 path->attached_next_hop.fp_interface))
438 s = format (s, " (p2p)");
441 if (!dpo_id_is_valid(&path->fp_dpo))
443 s = format(s, "\n unresolved");
447 s = format(s, "\n %U",
452 case FIB_PATH_TYPE_ATTACHED:
453 if (path->fp_oper_flags & FIB_PATH_OPER_FLAG_DROP)
455 s = format (s, " if_index:%d", path->attached_next_hop.fp_interface);
459 s = format (s, " %U",
460 format_vnet_sw_interface_name,
462 vnet_get_sw_interface(
464 path->attached.fp_interface));
467 case FIB_PATH_TYPE_RECURSIVE:
468 if (FIB_PROTOCOL_MPLS == path->fp_nh_proto)
470 s = format (s, "via %U %U",
471 format_mpls_unicast_label,
472 path->recursive.fp_nh.fp_local_label,
474 path->recursive.fp_nh.fp_eos);
478 s = format (s, "via %U",
480 &path->recursive.fp_nh.fp_ip,
483 s = format (s, " in fib:%d",
484 path->recursive.fp_tbl_id,
486 s = format (s, " via-fib:%d", path->fp_via_fib);
487 s = format (s, " via-dpo:[%U:%d]",
488 format_dpo_type, path->fp_dpo.dpoi_type,
489 path->fp_dpo.dpoi_index);
492 case FIB_PATH_TYPE_RECEIVE:
493 case FIB_PATH_TYPE_INTF_RX:
494 case FIB_PATH_TYPE_SPECIAL:
495 case FIB_PATH_TYPE_DEAG:
496 case FIB_PATH_TYPE_EXCLUSIVE:
497 if (dpo_id_is_valid(&path->fp_dpo))
499 s = format(s, "%U", format_dpo_id,
508 fib_path_format (fib_node_index_t pi, u8 *s)
512 path = fib_path_get(pi);
513 ASSERT(NULL != path);
515 return (format (s, "%U", format_fib_path, path));
519 fib_path_adj_format (fib_node_index_t pi,
525 path = fib_path_get(pi);
526 ASSERT(NULL != path);
528 if (!dpo_id_is_valid(&path->fp_dpo))
530 s = format(s, " unresolved");
534 s = format(s, "%U", format_dpo_id,
542 * fib_path_last_lock_gone
544 * We don't share paths, we share path lists, so the [un]lock functions
548 fib_path_last_lock_gone (fib_node_t *node)
553 static const adj_index_t
554 fib_path_attached_next_hop_get_adj (fib_path_t *path,
557 if (vnet_sw_interface_is_p2p(vnet_get_main(),
558 path->attached_next_hop.fp_interface))
561 * if the interface is p2p then the adj for the specific
562 * neighbour on that link will never exist. on p2p links
563 * the subnet address (the attached route) links to the
564 * auto-adj (see below), we want that adj here too.
566 return (adj_nbr_add_or_lock(path->fp_nh_proto,
569 path->attached_next_hop.fp_interface));
573 return (adj_nbr_add_or_lock(path->fp_nh_proto,
575 &path->attached_next_hop.fp_nh,
576 path->attached_next_hop.fp_interface));
581 fib_path_attached_next_hop_set (fib_path_t *path)
584 * resolve directly via the adjacnecy discribed by the
585 * interface and next-hop
587 dpo_set(&path->fp_dpo,
589 fib_proto_to_dpo(path->fp_nh_proto),
590 fib_path_attached_next_hop_get_adj(
592 fib_proto_to_link(path->fp_nh_proto)));
595 * become a child of the adjacency so we receive updates
596 * when its rewrite changes
598 path->fp_sibling = adj_child_add(path->fp_dpo.dpoi_index,
600 fib_path_get_index(path));
602 if (!vnet_sw_interface_is_admin_up(vnet_get_main(),
603 path->attached_next_hop.fp_interface) ||
604 !adj_is_up(path->fp_dpo.dpoi_index))
606 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
611 * create of update the paths recursive adj
614 fib_path_recursive_adj_update (fib_path_t *path,
615 fib_forward_chain_type_t fct,
618 dpo_id_t via_dpo = DPO_INVALID;
621 * get the DPO to resolve through from the via-entry
623 fib_entry_contribute_forwarding(path->fp_via_fib,
629 * hope for the best - clear if restrictions apply.
631 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RESOLVED;
634 * Validate any recursion constraints and over-ride the via
637 if (path->fp_oper_flags & FIB_PATH_OPER_FLAG_RECURSIVE_LOOP)
639 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
640 dpo_copy(&via_dpo, drop_dpo_get(fib_proto_to_dpo(path->fp_nh_proto)));
642 else if (path->fp_cfg_flags & FIB_PATH_CFG_FLAG_RESOLVE_HOST)
645 * the via FIB must be a host route.
646 * note the via FIB just added will always be a host route
647 * since it is an RR source added host route. So what we need to
648 * check is whether the route has other sources. If it does then
649 * some other source has added it as a host route. If it doesn't
650 * then it was added only here and inherits forwarding from a cover.
651 * the cover is not a host route.
652 * The RR source is the lowest priority source, so we check if it
653 * is the best. if it is there are no other sources.
655 if (fib_entry_get_best_source(path->fp_via_fib) >= FIB_SOURCE_RR)
657 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
658 dpo_copy(&via_dpo, drop_dpo_get(fib_proto_to_dpo(path->fp_nh_proto)));
661 * PIC edge trigger. let the load-balance maps know
663 load_balance_map_path_state_change(fib_path_get_index(path));
666 else if (path->fp_cfg_flags & FIB_PATH_CFG_FLAG_RESOLVE_ATTACHED)
669 * RR source entries inherit the flags from the cover, so
670 * we can check the via directly
672 if (!(FIB_ENTRY_FLAG_ATTACHED & fib_entry_get_flags(path->fp_via_fib)))
674 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
675 dpo_copy(&via_dpo, drop_dpo_get(fib_proto_to_dpo(path->fp_nh_proto)));
678 * PIC edge trigger. let the load-balance maps know
680 load_balance_map_path_state_change(fib_path_get_index(path));
684 * check for over-riding factors on the FIB entry itself
686 if (!fib_entry_is_resolved(path->fp_via_fib))
688 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
689 dpo_copy(&via_dpo, drop_dpo_get(fib_proto_to_dpo(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 * update the path's contributed DPO
700 dpo_copy(dpo, &via_dpo);
702 FIB_PATH_DBG(path, "recursive update: %U",
703 fib_get_lookup_main(path->fp_nh_proto),
710 * fib_path_is_permanent_drop
712 * Return !0 if the path is configured to permanently drop,
713 * despite other attributes.
716 fib_path_is_permanent_drop (fib_path_t *path)
718 return ((path->fp_cfg_flags & FIB_PATH_CFG_FLAG_DROP) ||
719 (path->fp_oper_flags & FIB_PATH_OPER_FLAG_DROP));
725 * Remove our dependency on the resolution target
728 fib_path_unresolve (fib_path_t *path)
731 * the forced drop path does not need unresolving
733 if (fib_path_is_permanent_drop(path))
738 switch (path->fp_type)
740 case FIB_PATH_TYPE_RECURSIVE:
741 if (FIB_NODE_INDEX_INVALID != path->fp_via_fib)
745 fib_entry_get_prefix(path->fp_via_fib, &pfx);
746 fib_entry_child_remove(path->fp_via_fib,
748 fib_table_entry_special_remove(path->recursive.fp_tbl_id,
751 path->fp_via_fib = FIB_NODE_INDEX_INVALID;
754 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
755 case FIB_PATH_TYPE_ATTACHED:
756 adj_child_remove(path->fp_dpo.dpoi_index,
758 adj_unlock(path->fp_dpo.dpoi_index);
760 case FIB_PATH_TYPE_EXCLUSIVE:
761 dpo_reset(&path->exclusive.fp_ex_dpo);
763 case FIB_PATH_TYPE_SPECIAL:
764 case FIB_PATH_TYPE_RECEIVE:
765 case FIB_PATH_TYPE_INTF_RX:
766 case FIB_PATH_TYPE_DEAG:
768 * these hold only the path's DPO, which is reset below.
774 * release the adj we were holding and pick up the
777 dpo_reset(&path->fp_dpo);
778 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
783 static fib_forward_chain_type_t
784 fib_path_to_chain_type (const fib_path_t *path)
786 switch (path->fp_nh_proto)
788 case FIB_PROTOCOL_IP4:
789 return (FIB_FORW_CHAIN_TYPE_UNICAST_IP4);
790 case FIB_PROTOCOL_IP6:
791 return (FIB_FORW_CHAIN_TYPE_UNICAST_IP6);
792 case FIB_PROTOCOL_MPLS:
793 if (FIB_PATH_TYPE_RECURSIVE == path->fp_type &&
794 MPLS_EOS == path->recursive.fp_nh.fp_eos)
796 return (FIB_FORW_CHAIN_TYPE_MPLS_EOS);
800 return (FIB_FORW_CHAIN_TYPE_MPLS_EOS);
803 return (FIB_FORW_CHAIN_TYPE_UNICAST_IP4);
807 * fib_path_back_walk_notify
809 * A back walk has reach this path.
811 static fib_node_back_walk_rc_t
812 fib_path_back_walk_notify (fib_node_t *node,
813 fib_node_back_walk_ctx_t *ctx)
817 path = fib_path_from_fib_node(node);
819 switch (path->fp_type)
821 case FIB_PATH_TYPE_RECURSIVE:
822 if (FIB_NODE_BW_REASON_FLAG_EVALUATE & ctx->fnbw_reason)
825 * modify the recursive adjacency to use the new forwarding
827 * this update is visible to packets in flight in the DP.
829 fib_path_recursive_adj_update(
831 fib_path_to_chain_type(path),
834 if ((FIB_NODE_BW_REASON_FLAG_ADJ_UPDATE & ctx->fnbw_reason) ||
835 (FIB_NODE_BW_REASON_FLAG_ADJ_DOWN & ctx->fnbw_reason))
838 * ADJ updates (complete<->incomplete) do not need to propagate to
840 * The only reason its needed as far back as here, is that the adj
841 * and the incomplete adj are a different DPO type, so the LBs need
843 * If this walk was quashed in the fib_entry, then any non-fib_path
844 * children (like tunnels that collapse out the LB when they stack)
845 * would not see the update.
847 return (FIB_NODE_BACK_WALK_CONTINUE);
850 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
853 * ADJ_UPDATE backwalk pass silently through here and up to
854 * the path-list when the multipath adj collapse occurs.
855 * The reason we do this is that the assumtption is that VPP
856 * runs in an environment where the Control-Plane is remote
857 * and hence reacts slowly to link up down. In order to remove
858 * this down link from the ECMP set quickly, we back-walk.
859 * VPP also has dedicated CPUs, so we are not stealing resources
860 * from the CP to do so.
862 if (FIB_NODE_BW_REASON_FLAG_INTERFACE_UP & ctx->fnbw_reason)
864 if (path->fp_oper_flags & FIB_PATH_OPER_FLAG_RESOLVED)
867 * alreday resolved. no need to walk back again
869 return (FIB_NODE_BACK_WALK_CONTINUE);
871 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RESOLVED;
873 if (FIB_NODE_BW_REASON_FLAG_INTERFACE_DOWN & ctx->fnbw_reason)
875 if (!(path->fp_oper_flags & FIB_PATH_OPER_FLAG_RESOLVED))
878 * alreday unresolved. no need to walk back again
880 return (FIB_NODE_BACK_WALK_CONTINUE);
882 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
884 if (FIB_NODE_BW_REASON_FLAG_INTERFACE_DELETE & ctx->fnbw_reason)
887 * The interface this path resolves through has been deleted.
888 * This will leave the path in a permanent drop state. The route
889 * needs to be removed and readded (and hence the path-list deleted)
890 * before it can forward again.
892 fib_path_unresolve(path);
893 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_DROP;
895 if (FIB_NODE_BW_REASON_FLAG_ADJ_UPDATE & ctx->fnbw_reason)
898 * restack the DPO to pick up the correct DPO sub-type
903 if_is_up = vnet_sw_interface_is_admin_up(
905 path->attached_next_hop.fp_interface);
907 ai = fib_path_attached_next_hop_get_adj(
909 fib_proto_to_link(path->fp_nh_proto));
911 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
912 if (if_is_up && adj_is_up(ai))
914 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RESOLVED;
917 dpo_set(&path->fp_dpo, DPO_ADJACENCY,
918 fib_proto_to_dpo(path->fp_nh_proto),
925 * If the interface is not up there is no reason to walk
926 * back to children. if we did they would only evalute
927 * that this path is unresolved and hence it would
928 * not contribute the adjacency - so it would be wasted
931 return (FIB_NODE_BACK_WALK_CONTINUE);
934 if (FIB_NODE_BW_REASON_FLAG_ADJ_DOWN & ctx->fnbw_reason)
936 if (!(path->fp_oper_flags & FIB_PATH_OPER_FLAG_RESOLVED))
939 * alreday unresolved. no need to walk back again
941 return (FIB_NODE_BACK_WALK_CONTINUE);
944 * the adj has gone down. the path is no longer resolved.
946 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
949 case FIB_PATH_TYPE_ATTACHED:
951 * FIXME; this could schedule a lower priority walk, since attached
952 * routes are not usually in ECMP configurations so the backwalk to
953 * the FIB entry does not need to be high priority
955 if (FIB_NODE_BW_REASON_FLAG_INTERFACE_UP & ctx->fnbw_reason)
957 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RESOLVED;
959 if (FIB_NODE_BW_REASON_FLAG_INTERFACE_DOWN & ctx->fnbw_reason)
961 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
963 if (FIB_NODE_BW_REASON_FLAG_INTERFACE_DELETE & ctx->fnbw_reason)
965 fib_path_unresolve(path);
966 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_DROP;
969 case FIB_PATH_TYPE_INTF_RX:
971 case FIB_PATH_TYPE_DEAG:
973 * FIXME When VRF delete is allowed this will need a poke.
975 case FIB_PATH_TYPE_SPECIAL:
976 case FIB_PATH_TYPE_RECEIVE:
977 case FIB_PATH_TYPE_EXCLUSIVE:
979 * these path types have no parents. so to be
980 * walked from one is unexpected.
987 * propagate the backwalk further to the path-list
989 fib_path_list_back_walk(path->fp_pl_index, ctx);
991 return (FIB_NODE_BACK_WALK_CONTINUE);
995 fib_path_memory_show (void)
997 fib_show_memory_usage("Path",
998 pool_elts(fib_path_pool),
999 pool_len(fib_path_pool),
1000 sizeof(fib_path_t));
1004 * The FIB path's graph node virtual function table
1006 static const fib_node_vft_t fib_path_vft = {
1007 .fnv_get = fib_path_get_node,
1008 .fnv_last_lock = fib_path_last_lock_gone,
1009 .fnv_back_walk = fib_path_back_walk_notify,
1010 .fnv_mem_show = fib_path_memory_show,
1013 static fib_path_cfg_flags_t
1014 fib_path_route_flags_to_cfg_flags (const fib_route_path_t *rpath)
1016 fib_path_cfg_flags_t cfg_flags = FIB_PATH_CFG_FLAG_NONE;
1018 if (rpath->frp_flags & FIB_ROUTE_PATH_RESOLVE_VIA_HOST)
1019 cfg_flags |= FIB_PATH_CFG_FLAG_RESOLVE_HOST;
1020 if (rpath->frp_flags & FIB_ROUTE_PATH_RESOLVE_VIA_ATTACHED)
1021 cfg_flags |= FIB_PATH_CFG_FLAG_RESOLVE_ATTACHED;
1022 if (rpath->frp_flags & FIB_ROUTE_PATH_LOCAL)
1023 cfg_flags |= FIB_PATH_CFG_FLAG_LOCAL;
1024 if (rpath->frp_flags & FIB_ROUTE_PATH_ATTACHED)
1025 cfg_flags |= FIB_PATH_CFG_FLAG_ATTACHED;
1026 if (rpath->frp_flags & FIB_ROUTE_PATH_INTF_RX)
1027 cfg_flags |= FIB_PATH_CFG_FLAG_INTF_RX;
1028 if (rpath->frp_flags & FIB_ROUTE_PATH_RPF_ID)
1029 cfg_flags |= FIB_PATH_CFG_FLAG_RPF_ID;
1030 if (rpath->frp_flags & FIB_ROUTE_PATH_EXCLUSIVE)
1031 cfg_flags |= FIB_PATH_CFG_FLAG_EXCLUSIVE;
1032 if (rpath->frp_flags & FIB_ROUTE_PATH_DROP)
1033 cfg_flags |= FIB_PATH_CFG_FLAG_DROP;
1041 * Create and initialise a new path object.
1042 * return the index of the path.
1045 fib_path_create (fib_node_index_t pl_index,
1046 const fib_route_path_t *rpath)
1050 pool_get(fib_path_pool, path);
1051 memset(path, 0, sizeof(*path));
1053 fib_node_init(&path->fp_node,
1054 FIB_NODE_TYPE_PATH);
1056 dpo_reset(&path->fp_dpo);
1057 path->fp_pl_index = pl_index;
1058 path->fp_nh_proto = rpath->frp_proto;
1059 path->fp_via_fib = FIB_NODE_INDEX_INVALID;
1060 path->fp_weight = rpath->frp_weight;
1061 if (0 == path->fp_weight)
1064 * a weight of 0 is a meaningless value. We could either reject it, and thus force
1065 * clients to always use 1, or we can accept it and fixup approrpiately.
1067 path->fp_weight = 1;
1069 path->fp_cfg_flags = fib_path_route_flags_to_cfg_flags(rpath);
1072 * deduce the path's tpye from the parementers and save what is needed.
1074 if (path->fp_cfg_flags & FIB_PATH_CFG_FLAG_LOCAL)
1076 path->fp_type = FIB_PATH_TYPE_RECEIVE;
1077 path->receive.fp_interface = rpath->frp_sw_if_index;
1078 path->receive.fp_addr = rpath->frp_addr;
1080 else if (path->fp_cfg_flags & FIB_PATH_CFG_FLAG_INTF_RX)
1082 path->fp_type = FIB_PATH_TYPE_INTF_RX;
1083 path->intf_rx.fp_interface = rpath->frp_sw_if_index;
1085 else if (path->fp_cfg_flags & FIB_PATH_CFG_FLAG_RPF_ID)
1087 path->fp_type = FIB_PATH_TYPE_DEAG;
1088 path->deag.fp_tbl_id = rpath->frp_fib_index;
1089 path->deag.fp_rpf_id = rpath->frp_rpf_id;
1091 else if (~0 != rpath->frp_sw_if_index)
1093 if (ip46_address_is_zero(&rpath->frp_addr))
1095 path->fp_type = FIB_PATH_TYPE_ATTACHED;
1096 path->attached.fp_interface = rpath->frp_sw_if_index;
1100 path->fp_type = FIB_PATH_TYPE_ATTACHED_NEXT_HOP;
1101 path->attached_next_hop.fp_interface = rpath->frp_sw_if_index;
1102 path->attached_next_hop.fp_nh = rpath->frp_addr;
1107 if (ip46_address_is_zero(&rpath->frp_addr))
1109 if (~0 == rpath->frp_fib_index)
1111 path->fp_type = FIB_PATH_TYPE_SPECIAL;
1115 path->fp_type = FIB_PATH_TYPE_DEAG;
1116 path->deag.fp_tbl_id = rpath->frp_fib_index;
1121 path->fp_type = FIB_PATH_TYPE_RECURSIVE;
1122 if (FIB_PROTOCOL_MPLS == path->fp_nh_proto)
1124 path->recursive.fp_nh.fp_local_label = rpath->frp_local_label;
1125 path->recursive.fp_nh.fp_eos = rpath->frp_eos;
1129 path->recursive.fp_nh.fp_ip = rpath->frp_addr;
1131 path->recursive.fp_tbl_id = rpath->frp_fib_index;
1135 FIB_PATH_DBG(path, "create");
1137 return (fib_path_get_index(path));
1141 * fib_path_create_special
1143 * Create and initialise a new path object.
1144 * return the index of the path.
1147 fib_path_create_special (fib_node_index_t pl_index,
1148 fib_protocol_t nh_proto,
1149 fib_path_cfg_flags_t flags,
1150 const dpo_id_t *dpo)
1154 pool_get(fib_path_pool, path);
1155 memset(path, 0, sizeof(*path));
1157 fib_node_init(&path->fp_node,
1158 FIB_NODE_TYPE_PATH);
1159 dpo_reset(&path->fp_dpo);
1161 path->fp_pl_index = pl_index;
1162 path->fp_weight = 1;
1163 path->fp_nh_proto = nh_proto;
1164 path->fp_via_fib = FIB_NODE_INDEX_INVALID;
1165 path->fp_cfg_flags = flags;
1167 if (FIB_PATH_CFG_FLAG_DROP & flags)
1169 path->fp_type = FIB_PATH_TYPE_SPECIAL;
1171 else if (FIB_PATH_CFG_FLAG_LOCAL & flags)
1173 path->fp_type = FIB_PATH_TYPE_RECEIVE;
1174 path->attached.fp_interface = FIB_NODE_INDEX_INVALID;
1178 path->fp_type = FIB_PATH_TYPE_EXCLUSIVE;
1179 ASSERT(NULL != dpo);
1180 dpo_copy(&path->exclusive.fp_ex_dpo, dpo);
1183 return (fib_path_get_index(path));
1189 * Copy a path. return index of new path.
1192 fib_path_copy (fib_node_index_t path_index,
1193 fib_node_index_t path_list_index)
1195 fib_path_t *path, *orig_path;
1197 pool_get(fib_path_pool, path);
1199 orig_path = fib_path_get(path_index);
1200 ASSERT(NULL != orig_path);
1202 memcpy(path, orig_path, sizeof(*path));
1204 FIB_PATH_DBG(path, "create-copy:%d", path_index);
1207 * reset the dynamic section
1209 fib_node_init(&path->fp_node, FIB_NODE_TYPE_PATH);
1210 path->fp_oper_flags = FIB_PATH_OPER_FLAG_NONE;
1211 path->fp_pl_index = path_list_index;
1212 path->fp_via_fib = FIB_NODE_INDEX_INVALID;
1213 memset(&path->fp_dpo, 0, sizeof(path->fp_dpo));
1214 dpo_reset(&path->fp_dpo);
1216 return (fib_path_get_index(path));
1222 * destroy a path that is no longer required
1225 fib_path_destroy (fib_node_index_t path_index)
1229 path = fib_path_get(path_index);
1231 ASSERT(NULL != path);
1232 FIB_PATH_DBG(path, "destroy");
1234 fib_path_unresolve(path);
1236 fib_node_deinit(&path->fp_node);
1237 pool_put(fib_path_pool, path);
1243 * destroy a path that is no longer required
1246 fib_path_hash (fib_node_index_t path_index)
1250 path = fib_path_get(path_index);
1252 return (hash_memory(STRUCT_MARK_PTR(path, path_hash_start),
1253 (STRUCT_OFFSET_OF(fib_path_t, path_hash_end) -
1254 STRUCT_OFFSET_OF(fib_path_t, path_hash_start)),
1261 * Compare two paths for equivalence.
1264 fib_path_cmp_i (const fib_path_t *path1,
1265 const fib_path_t *path2)
1272 * paths of different types and protocol are not equal.
1273 * different weights only are the same path.
1275 if (path1->fp_type != path2->fp_type)
1277 res = (path1->fp_type - path2->fp_type);
1279 else if (path1->fp_nh_proto != path2->fp_nh_proto)
1281 res = (path1->fp_nh_proto - path2->fp_nh_proto);
1286 * both paths are of the same type.
1287 * consider each type and its attributes in turn.
1289 switch (path1->fp_type)
1291 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1292 res = ip46_address_cmp(&path1->attached_next_hop.fp_nh,
1293 &path2->attached_next_hop.fp_nh);
1295 res = (path1->attached_next_hop.fp_interface -
1296 path2->attached_next_hop.fp_interface);
1299 case FIB_PATH_TYPE_ATTACHED:
1300 res = (path1->attached.fp_interface -
1301 path2->attached.fp_interface);
1303 case FIB_PATH_TYPE_RECURSIVE:
1304 res = ip46_address_cmp(&path1->recursive.fp_nh,
1305 &path2->recursive.fp_nh);
1309 res = (path1->recursive.fp_tbl_id - path2->recursive.fp_tbl_id);
1312 case FIB_PATH_TYPE_DEAG:
1313 res = (path1->deag.fp_tbl_id - path2->deag.fp_tbl_id);
1316 res = (path1->deag.fp_rpf_id - path2->deag.fp_rpf_id);
1319 case FIB_PATH_TYPE_INTF_RX:
1320 res = (path1->intf_rx.fp_interface - path2->intf_rx.fp_interface);
1322 case FIB_PATH_TYPE_SPECIAL:
1323 case FIB_PATH_TYPE_RECEIVE:
1324 case FIB_PATH_TYPE_EXCLUSIVE:
1333 * fib_path_cmp_for_sort
1335 * Compare two paths for equivalence. Used during path sorting.
1336 * As usual 0 means equal.
1339 fib_path_cmp_for_sort (void * v1,
1342 fib_node_index_t *pi1 = v1, *pi2 = v2;
1343 fib_path_t *path1, *path2;
1345 path1 = fib_path_get(*pi1);
1346 path2 = fib_path_get(*pi2);
1348 return (fib_path_cmp_i(path1, path2));
1354 * Compare two paths for equivalence.
1357 fib_path_cmp (fib_node_index_t pi1,
1358 fib_node_index_t pi2)
1360 fib_path_t *path1, *path2;
1362 path1 = fib_path_get(pi1);
1363 path2 = fib_path_get(pi2);
1365 return (fib_path_cmp_i(path1, path2));
1369 fib_path_cmp_w_route_path (fib_node_index_t path_index,
1370 const fib_route_path_t *rpath)
1375 path = fib_path_get(path_index);
1379 if (path->fp_weight != rpath->frp_weight)
1381 res = (path->fp_weight - rpath->frp_weight);
1386 * both paths are of the same type.
1387 * consider each type and its attributes in turn.
1389 switch (path->fp_type)
1391 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1392 res = ip46_address_cmp(&path->attached_next_hop.fp_nh,
1396 res = (path->attached_next_hop.fp_interface -
1397 rpath->frp_sw_if_index);
1400 case FIB_PATH_TYPE_ATTACHED:
1401 res = (path->attached.fp_interface - rpath->frp_sw_if_index);
1403 case FIB_PATH_TYPE_RECURSIVE:
1404 if (FIB_PROTOCOL_MPLS == path->fp_nh_proto)
1406 res = path->recursive.fp_nh.fp_local_label - rpath->frp_local_label;
1410 res = path->recursive.fp_nh.fp_eos - rpath->frp_eos;
1415 res = ip46_address_cmp(&path->recursive.fp_nh.fp_ip,
1421 res = (path->recursive.fp_tbl_id - rpath->frp_fib_index);
1424 case FIB_PATH_TYPE_INTF_RX:
1425 res = (path->intf_rx.fp_interface - rpath->frp_sw_if_index);
1427 case FIB_PATH_TYPE_DEAG:
1428 res = (path->deag.fp_tbl_id - rpath->frp_fib_index);
1431 res = (path->deag.fp_rpf_id - rpath->frp_rpf_id);
1434 case FIB_PATH_TYPE_SPECIAL:
1435 case FIB_PATH_TYPE_RECEIVE:
1436 case FIB_PATH_TYPE_EXCLUSIVE:
1445 * fib_path_recursive_loop_detect
1447 * A forward walk of the FIB object graph to detect for a cycle/loop. This
1448 * walk is initiated when an entry is linking to a new path list or from an old.
1449 * The entry vector passed contains all the FIB entrys that are children of this
1450 * path (it is all the entries encountered on the walk so far). If this vector
1451 * contains the entry this path resolve via, then a loop is about to form.
1452 * The loop must be allowed to form, since we need the dependencies in place
1453 * so that we can track when the loop breaks.
1454 * However, we MUST not produce a loop in the forwarding graph (else packets
1455 * would loop around the switch path until the loop breaks), so we mark recursive
1456 * paths as looped so that they do not contribute forwarding information.
1457 * By marking the path as looped, an etry such as;
1459 * via a.a.a.a (looped)
1460 * via b.b.b.b (not looped)
1461 * can still forward using the info provided by b.b.b.b only
1464 fib_path_recursive_loop_detect (fib_node_index_t path_index,
1465 fib_node_index_t **entry_indicies)
1469 path = fib_path_get(path_index);
1472 * the forced drop path is never looped, cos it is never resolved.
1474 if (fib_path_is_permanent_drop(path))
1479 switch (path->fp_type)
1481 case FIB_PATH_TYPE_RECURSIVE:
1483 fib_node_index_t *entry_index, *entries;
1485 entries = *entry_indicies;
1487 vec_foreach(entry_index, entries) {
1488 if (*entry_index == path->fp_via_fib)
1491 * the entry that is about to link to this path-list (or
1492 * one of this path-list's children) is the same entry that
1493 * this recursive path resolves through. this is a cycle.
1503 FIB_PATH_DBG(path, "recursive loop formed");
1504 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RECURSIVE_LOOP;
1506 dpo_copy(&path->fp_dpo,
1507 drop_dpo_get(fib_proto_to_dpo(path->fp_nh_proto)));
1512 * no loop here yet. keep forward walking the graph.
1514 if (fib_entry_recursive_loop_detect(path->fp_via_fib, entry_indicies))
1516 FIB_PATH_DBG(path, "recursive loop formed");
1517 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RECURSIVE_LOOP;
1521 FIB_PATH_DBG(path, "recursive loop cleared");
1522 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RECURSIVE_LOOP;
1527 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1528 case FIB_PATH_TYPE_ATTACHED:
1529 case FIB_PATH_TYPE_SPECIAL:
1530 case FIB_PATH_TYPE_DEAG:
1531 case FIB_PATH_TYPE_RECEIVE:
1532 case FIB_PATH_TYPE_INTF_RX:
1533 case FIB_PATH_TYPE_EXCLUSIVE:
1535 * these path types cannot be part of a loop, since they are the leaves
1541 return (fib_path_is_looped(path_index));
1545 fib_path_resolve (fib_node_index_t path_index)
1549 path = fib_path_get(path_index);
1552 * hope for the best.
1554 path->fp_oper_flags |= FIB_PATH_OPER_FLAG_RESOLVED;
1557 * the forced drop path resolves via the drop adj
1559 if (fib_path_is_permanent_drop(path))
1561 dpo_copy(&path->fp_dpo,
1562 drop_dpo_get(fib_proto_to_dpo(path->fp_nh_proto)));
1563 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
1564 return (fib_path_is_resolved(path_index));
1567 switch (path->fp_type)
1569 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1570 fib_path_attached_next_hop_set(path);
1572 case FIB_PATH_TYPE_ATTACHED:
1574 * path->attached.fp_interface
1576 if (!vnet_sw_interface_is_admin_up(vnet_get_main(),
1577 path->attached.fp_interface))
1579 path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
1581 if (vnet_sw_interface_is_p2p(vnet_get_main(),
1582 path->attached.fp_interface))
1585 * point-2-point interfaces do not require a glean, since
1586 * there is nothing to ARP. Install a rewrite/nbr adj instead
1588 dpo_set(&path->fp_dpo,
1590 fib_proto_to_dpo(path->fp_nh_proto),
1591 adj_nbr_add_or_lock(
1593 fib_proto_to_link(path->fp_nh_proto),
1595 path->attached.fp_interface));
1599 dpo_set(&path->fp_dpo,
1600 DPO_ADJACENCY_GLEAN,
1601 fib_proto_to_dpo(path->fp_nh_proto),
1602 adj_glean_add_or_lock(path->fp_nh_proto,
1603 path->attached.fp_interface,
1607 * become a child of the adjacency so we receive updates
1608 * when the interface state changes
1610 path->fp_sibling = adj_child_add(path->fp_dpo.dpoi_index,
1612 fib_path_get_index(path));
1615 case FIB_PATH_TYPE_RECURSIVE:
1618 * Create a RR source entry in the table for the address
1619 * that this path recurses through.
1620 * This resolve action is recursive, hence we may create
1621 * more paths in the process. more creates mean maybe realloc
1624 fib_node_index_t fei;
1627 ASSERT(FIB_NODE_INDEX_INVALID == path->fp_via_fib);
1629 if (FIB_PROTOCOL_MPLS == path->fp_nh_proto)
1631 fib_prefix_from_mpls_label(path->recursive.fp_nh.fp_local_label,
1632 path->recursive.fp_nh.fp_eos,
1637 fib_prefix_from_ip46_addr(&path->recursive.fp_nh.fp_ip, &pfx);
1640 fei = fib_table_entry_special_add(path->recursive.fp_tbl_id,
1643 FIB_ENTRY_FLAG_NONE,
1646 path = fib_path_get(path_index);
1647 path->fp_via_fib = fei;
1650 * become a dependent child of the entry so the path is
1651 * informed when the forwarding for the entry changes.
1653 path->fp_sibling = fib_entry_child_add(path->fp_via_fib,
1655 fib_path_get_index(path));
1658 * create and configure the IP DPO
1660 fib_path_recursive_adj_update(
1662 fib_path_to_chain_type(path),
1667 case FIB_PATH_TYPE_SPECIAL:
1669 * Resolve via the drop
1671 dpo_copy(&path->fp_dpo,
1672 drop_dpo_get(fib_proto_to_dpo(path->fp_nh_proto)));
1674 case FIB_PATH_TYPE_DEAG:
1677 * Resolve via a lookup DPO.
1678 * FIXME. control plane should add routes with a table ID
1682 cast = (path->fp_cfg_flags & FIB_PATH_CFG_FLAG_RPF_ID ?
1686 lookup_dpo_add_or_lock_w_fib_index(path->deag.fp_tbl_id,
1687 fib_proto_to_dpo(path->fp_nh_proto),
1689 LOOKUP_INPUT_DST_ADDR,
1690 LOOKUP_TABLE_FROM_CONFIG,
1694 case FIB_PATH_TYPE_RECEIVE:
1696 * Resolve via a receive DPO.
1698 receive_dpo_add_or_lock(fib_proto_to_dpo(path->fp_nh_proto),
1699 path->receive.fp_interface,
1700 &path->receive.fp_addr,
1703 case FIB_PATH_TYPE_INTF_RX: {
1705 * Resolve via a receive DPO.
1707 interface_dpo_add_or_lock(fib_proto_to_dpo(path->fp_nh_proto),
1708 path->intf_rx.fp_interface,
1712 case FIB_PATH_TYPE_EXCLUSIVE:
1714 * Resolve via the user provided DPO
1716 dpo_copy(&path->fp_dpo, &path->exclusive.fp_ex_dpo);
1720 return (fib_path_is_resolved(path_index));
1724 fib_path_get_resolving_interface (fib_node_index_t path_index)
1728 path = fib_path_get(path_index);
1730 switch (path->fp_type)
1732 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1733 return (path->attached_next_hop.fp_interface);
1734 case FIB_PATH_TYPE_ATTACHED:
1735 return (path->attached.fp_interface);
1736 case FIB_PATH_TYPE_RECEIVE:
1737 return (path->receive.fp_interface);
1738 case FIB_PATH_TYPE_RECURSIVE:
1739 return (fib_entry_get_resolving_interface(path->fp_via_fib));
1740 case FIB_PATH_TYPE_INTF_RX:
1741 case FIB_PATH_TYPE_SPECIAL:
1742 case FIB_PATH_TYPE_DEAG:
1743 case FIB_PATH_TYPE_EXCLUSIVE:
1750 fib_path_get_adj (fib_node_index_t path_index)
1754 path = fib_path_get(path_index);
1756 ASSERT(dpo_is_adj(&path->fp_dpo));
1757 if (dpo_is_adj(&path->fp_dpo))
1759 return (path->fp_dpo.dpoi_index);
1761 return (ADJ_INDEX_INVALID);
1765 fib_path_get_weight (fib_node_index_t path_index)
1769 path = fib_path_get(path_index);
1773 return (path->fp_weight);
1777 * @brief Contribute the path's adjacency to the list passed.
1778 * By calling this function over all paths, recursively, a child
1779 * can construct its full set of forwarding adjacencies, and hence its
1783 fib_path_contribute_urpf (fib_node_index_t path_index,
1788 path = fib_path_get(path_index);
1791 * resolved and unresolved paths contribute to the RPF list.
1793 switch (path->fp_type)
1795 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1796 fib_urpf_list_append(urpf, path->attached_next_hop.fp_interface);
1799 case FIB_PATH_TYPE_ATTACHED:
1800 fib_urpf_list_append(urpf, path->attached.fp_interface);
1803 case FIB_PATH_TYPE_RECURSIVE:
1804 if (FIB_NODE_INDEX_INVALID != path->fp_via_fib)
1807 * there's unresolved due to constraints, and there's unresolved
1808 * due to ain't go no via. can't do nowt w'out via.
1810 fib_entry_contribute_urpf(path->fp_via_fib, urpf);
1814 case FIB_PATH_TYPE_EXCLUSIVE:
1815 case FIB_PATH_TYPE_SPECIAL:
1817 * these path types may link to an adj, if that's what
1820 if (dpo_is_adj(&path->fp_dpo))
1822 ip_adjacency_t *adj;
1824 adj = adj_get(path->fp_dpo.dpoi_index);
1826 fib_urpf_list_append(urpf, adj->rewrite_header.sw_if_index);
1830 case FIB_PATH_TYPE_DEAG:
1831 case FIB_PATH_TYPE_RECEIVE:
1832 case FIB_PATH_TYPE_INTF_RX:
1834 * these path types don't link to an adj
1841 fib_path_stack_mpls_disp (fib_node_index_t path_index,
1842 dpo_proto_t payload_proto,
1847 path = fib_path_get(path_index);
1851 switch (path->fp_type)
1853 case FIB_PATH_TYPE_DEAG:
1855 dpo_id_t tmp = DPO_INVALID;
1857 dpo_copy(&tmp, dpo);
1859 DPO_MPLS_DISPOSITION,
1861 mpls_disp_dpo_create(payload_proto,
1862 path->deag.fp_rpf_id,
1867 case FIB_PATH_TYPE_RECEIVE:
1868 case FIB_PATH_TYPE_ATTACHED:
1869 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1870 case FIB_PATH_TYPE_RECURSIVE:
1871 case FIB_PATH_TYPE_INTF_RX:
1872 case FIB_PATH_TYPE_EXCLUSIVE:
1873 case FIB_PATH_TYPE_SPECIAL:
1879 fib_path_contribute_forwarding (fib_node_index_t path_index,
1880 fib_forward_chain_type_t fct,
1885 path = fib_path_get(path_index);
1888 ASSERT(FIB_FORW_CHAIN_TYPE_MPLS_EOS != fct);
1890 FIB_PATH_DBG(path, "contribute");
1893 * The DPO stored in the path was created when the path was resolved.
1894 * This then represents the path's 'native' protocol; IP.
1895 * For all others will need to go find something else.
1897 if (fib_path_to_chain_type(path) == fct)
1899 dpo_copy(dpo, &path->fp_dpo);
1903 switch (path->fp_type)
1905 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
1908 case FIB_FORW_CHAIN_TYPE_UNICAST_IP4:
1909 case FIB_FORW_CHAIN_TYPE_UNICAST_IP6:
1910 case FIB_FORW_CHAIN_TYPE_MPLS_EOS:
1911 case FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS:
1912 case FIB_FORW_CHAIN_TYPE_ETHERNET:
1913 case FIB_FORW_CHAIN_TYPE_NSH:
1918 * get a appropriate link type adj.
1920 ai = fib_path_attached_next_hop_get_adj(
1922 fib_forw_chain_type_to_link_type(fct));
1923 dpo_set(dpo, DPO_ADJACENCY,
1924 fib_forw_chain_type_to_dpo_proto(fct), ai);
1929 case FIB_FORW_CHAIN_TYPE_MCAST_IP4:
1930 case FIB_FORW_CHAIN_TYPE_MCAST_IP6:
1934 case FIB_PATH_TYPE_RECURSIVE:
1937 case FIB_FORW_CHAIN_TYPE_MPLS_EOS:
1938 case FIB_FORW_CHAIN_TYPE_UNICAST_IP4:
1939 case FIB_FORW_CHAIN_TYPE_UNICAST_IP6:
1940 case FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS:
1941 case FIB_FORW_CHAIN_TYPE_MCAST_IP4:
1942 case FIB_FORW_CHAIN_TYPE_MCAST_IP6:
1943 fib_path_recursive_adj_update(path, fct, dpo);
1945 case FIB_FORW_CHAIN_TYPE_ETHERNET:
1946 case FIB_FORW_CHAIN_TYPE_NSH:
1951 case FIB_PATH_TYPE_DEAG:
1954 case FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS:
1955 lookup_dpo_add_or_lock_w_table_id(MPLS_FIB_DEFAULT_TABLE_ID,
1958 LOOKUP_INPUT_DST_ADDR,
1959 LOOKUP_TABLE_FROM_CONFIG,
1962 case FIB_FORW_CHAIN_TYPE_MPLS_EOS:
1963 case FIB_FORW_CHAIN_TYPE_UNICAST_IP4:
1964 case FIB_FORW_CHAIN_TYPE_UNICAST_IP6:
1965 dpo_copy(dpo, &path->fp_dpo);
1967 case FIB_FORW_CHAIN_TYPE_MCAST_IP4:
1968 case FIB_FORW_CHAIN_TYPE_MCAST_IP6:
1969 case FIB_FORW_CHAIN_TYPE_ETHERNET:
1970 case FIB_FORW_CHAIN_TYPE_NSH:
1975 case FIB_PATH_TYPE_EXCLUSIVE:
1976 dpo_copy(dpo, &path->exclusive.fp_ex_dpo);
1978 case FIB_PATH_TYPE_ATTACHED:
1981 case FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS:
1982 case FIB_FORW_CHAIN_TYPE_UNICAST_IP4:
1983 case FIB_FORW_CHAIN_TYPE_UNICAST_IP6:
1984 case FIB_FORW_CHAIN_TYPE_MPLS_EOS:
1985 case FIB_FORW_CHAIN_TYPE_ETHERNET:
1986 case FIB_FORW_CHAIN_TYPE_NSH:
1988 case FIB_FORW_CHAIN_TYPE_MCAST_IP4:
1989 case FIB_FORW_CHAIN_TYPE_MCAST_IP6:
1994 * Create the adj needed for sending IP multicast traffic
1996 ai = adj_mcast_add_or_lock(path->fp_nh_proto,
1997 fib_forw_chain_type_to_link_type(fct),
1998 path->attached.fp_interface);
1999 dpo_set(dpo, DPO_ADJACENCY,
2000 fib_forw_chain_type_to_dpo_proto(fct),
2007 case FIB_PATH_TYPE_INTF_RX:
2009 * Create the adj needed for sending IP multicast traffic
2011 interface_dpo_add_or_lock(fib_forw_chain_type_to_dpo_proto(fct),
2012 path->attached.fp_interface,
2015 case FIB_PATH_TYPE_RECEIVE:
2016 case FIB_PATH_TYPE_SPECIAL:
2017 dpo_copy(dpo, &path->fp_dpo);
2023 load_balance_path_t *
2024 fib_path_append_nh_for_multipath_hash (fib_node_index_t path_index,
2025 fib_forward_chain_type_t fct,
2026 load_balance_path_t *hash_key)
2028 load_balance_path_t *mnh;
2031 path = fib_path_get(path_index);
2035 if (fib_path_is_resolved(path_index))
2037 vec_add2(hash_key, mnh, 1);
2039 mnh->path_weight = path->fp_weight;
2040 mnh->path_index = path_index;
2041 fib_path_contribute_forwarding(path_index, fct, &mnh->path_dpo);
2048 fib_path_is_recursive (fib_node_index_t path_index)
2052 path = fib_path_get(path_index);
2054 return (FIB_PATH_TYPE_RECURSIVE == path->fp_type);
2058 fib_path_is_exclusive (fib_node_index_t path_index)
2062 path = fib_path_get(path_index);
2064 return (FIB_PATH_TYPE_EXCLUSIVE == path->fp_type);
2068 fib_path_is_deag (fib_node_index_t path_index)
2072 path = fib_path_get(path_index);
2074 return (FIB_PATH_TYPE_DEAG == path->fp_type);
2078 fib_path_is_resolved (fib_node_index_t path_index)
2082 path = fib_path_get(path_index);
2084 return (dpo_id_is_valid(&path->fp_dpo) &&
2085 (path->fp_oper_flags & FIB_PATH_OPER_FLAG_RESOLVED) &&
2086 !fib_path_is_looped(path_index) &&
2087 !fib_path_is_permanent_drop(path));
2091 fib_path_is_looped (fib_node_index_t path_index)
2095 path = fib_path_get(path_index);
2097 return (path->fp_oper_flags & FIB_PATH_OPER_FLAG_RECURSIVE_LOOP);
2101 fib_path_encode (fib_node_index_t path_list_index,
2102 fib_node_index_t path_index,
2105 fib_route_path_encode_t **api_rpaths = ctx;
2106 fib_route_path_encode_t *api_rpath;
2109 path = fib_path_get(path_index);
2112 vec_add2(*api_rpaths, api_rpath, 1);
2113 api_rpath->rpath.frp_weight = path->fp_weight;
2114 api_rpath->rpath.frp_proto = path->fp_nh_proto;
2115 api_rpath->rpath.frp_sw_if_index = ~0;
2116 api_rpath->dpo = path->exclusive.fp_ex_dpo;
2117 switch (path->fp_type)
2119 case FIB_PATH_TYPE_RECEIVE:
2120 api_rpath->rpath.frp_addr = path->receive.fp_addr;
2121 api_rpath->rpath.frp_sw_if_index = path->receive.fp_interface;
2123 case FIB_PATH_TYPE_ATTACHED:
2124 api_rpath->rpath.frp_sw_if_index = path->attached.fp_interface;
2126 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
2127 api_rpath->rpath.frp_sw_if_index = path->attached_next_hop.fp_interface;
2128 api_rpath->rpath.frp_addr = path->attached_next_hop.fp_nh;
2130 case FIB_PATH_TYPE_SPECIAL:
2132 case FIB_PATH_TYPE_DEAG:
2134 case FIB_PATH_TYPE_RECURSIVE:
2135 api_rpath->rpath.frp_addr = path->recursive.fp_nh.fp_ip;
2144 fib_path_get_proto (fib_node_index_t path_index)
2148 path = fib_path_get(path_index);
2150 return (path->fp_nh_proto);
2154 fib_path_module_init (void)
2156 fib_node_register_type (FIB_NODE_TYPE_PATH, &fib_path_vft);
2159 static clib_error_t *
2160 show_fib_path_command (vlib_main_t * vm,
2161 unformat_input_t * input,
2162 vlib_cli_command_t * cmd)
2164 fib_node_index_t pi;
2167 if (unformat (input, "%d", &pi))
2170 * show one in detail
2172 if (!pool_is_free_index(fib_path_pool, pi))
2174 path = fib_path_get(pi);
2175 u8 *s = fib_path_format(pi, NULL);
2176 s = format(s, "children:");
2177 s = fib_node_children_format(path->fp_node.fn_children, s);
2178 vlib_cli_output (vm, "%s", s);
2183 vlib_cli_output (vm, "path %d invalid", pi);
2188 vlib_cli_output (vm, "FIB Paths");
2189 pool_foreach(path, fib_path_pool,
2191 vlib_cli_output (vm, "%U", format_fib_path, path);
2198 VLIB_CLI_COMMAND (show_fib_path, static) = {
2199 .path = "show fib paths",
2200 .function = show_fib_path_command,
2201 .short_help = "show fib paths",