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 #ifndef __FIB_PATH_LIST_H__
17 #define __FIB_PATH_LIST_H__
19 #include <vlib/vlib.h>
20 #include <vnet/adj/adj.h>
26 * Enumeration of path-list flags.
28 typedef enum fib_path_list_attribute_t_ {
30 * Marker. Add new flags after this one.
32 FIB_PATH_LIST_ATTRIBUTE_FIRST = 0,
34 * This path list is shareable. Shareable path-lists
35 * are inserted into the path-list data-base.
36 * All path-list are inherently shareable, the reason we share some and
37 * not others is to limit the size of the path-list database. This DB must
38 * be searched for each route update.
40 FIB_PATH_LIST_ATTRIBUTE_SHARED = FIB_PATH_LIST_ATTRIBUTE_FIRST,
42 * Indexed means the path-list keeps a hash table of all paths for
43 * fast lookup. The lookup result is the fib_node_index of the path.
45 FIB_PATH_LIST_ATTRIBUTE_INDEXED,
47 * explicit drop path-list. Used when the entry source needs to
48 * force a drop, despite the fact the path info is present.
50 FIB_PATH_LIST_ATTRIBUTE_DROP,
52 * explicit local path-list.
54 FIB_PATH_LIST_ATTRIBUTE_LOCAL,
56 * exclusive path-list. Exclusive means the path will resolve via the
57 * exclusive (user provided) adj.
59 FIB_PATH_LIST_ATTRIBUTE_EXCLUSIVE,
63 FIB_PATH_LIST_ATTRIBUTE_RESOLVED,
65 * looped path-list. one path looped implies the whole list is
67 FIB_PATH_LIST_ATTRIBUTE_LOOPED,
69 * no uRPF - do not generate unicast RPF list for this path-list
71 FIB_PATH_LIST_ATTRIBUTE_NO_URPF,
73 * Marher. Add new flags before this one, and then update it.
75 FIB_PATH_LIST_ATTRIBUTE_LAST = FIB_PATH_LIST_ATTRIBUTE_LOOPED,
76 } fib_path_list_attribute_t;
78 typedef enum fib_path_list_flags_t_ {
79 FIB_PATH_LIST_FLAG_NONE = 0,
80 FIB_PATH_LIST_FLAG_SHARED = (1 << FIB_PATH_LIST_ATTRIBUTE_SHARED),
81 FIB_PATH_LIST_FLAG_INDEXED = (1 << FIB_PATH_LIST_ATTRIBUTE_INDEXED),
82 FIB_PATH_LIST_FLAG_DROP = (1 << FIB_PATH_LIST_ATTRIBUTE_DROP),
83 FIB_PATH_LIST_FLAG_LOCAL = (1 << FIB_PATH_LIST_ATTRIBUTE_LOCAL),
84 FIB_PATH_LIST_FLAG_EXCLUSIVE = (1 << FIB_PATH_LIST_ATTRIBUTE_EXCLUSIVE),
85 FIB_PATH_LIST_FLAG_RESOLVED = (1 << FIB_PATH_LIST_ATTRIBUTE_RESOLVED),
86 FIB_PATH_LIST_FLAG_LOOPED = (1 << FIB_PATH_LIST_ATTRIBUTE_LOOPED),
87 FIB_PATH_LIST_FLAG_NO_URPF = (1 << FIB_PATH_LIST_ATTRIBUTE_NO_URPF),
88 } fib_path_list_flags_t;
90 #define FIB_PATH_LIST_ATTRIBUTES { \
91 [FIB_PATH_LIST_ATTRIBUTE_SHARED] = "shared", \
92 [FIB_PATH_LIST_ATTRIBUTE_INDEXED] = "indexed", \
93 [FIB_PATH_LIST_ATTRIBUTE_RESOLVED] = "resolved", \
94 [FIB_PATH_LIST_ATTRIBUTE_DROP] = "drop", \
95 [FIB_PATH_LIST_ATTRIBUTE_EXCLUSIVE] = "exclusive", \
96 [FIB_PATH_LIST_ATTRIBUTE_LOCAL] = "local", \
97 [FIB_PATH_LIST_ATTRIBUTE_LOOPED] = "looped", \
98 [FIB_PATH_LIST_ATTRIBUTE_NO_URPF] = "no-uRPF", \
101 #define FOR_EACH_PATH_LIST_ATTRIBUTE(_item) \
102 for (_item = FIB_PATH_LIST_ATTRIBUTE_FIRST; \
103 _item <= FIB_PATH_LIST_ATTRIBUTE_LAST; \
106 extern fib_node_index_t fib_path_list_create(fib_path_list_flags_t flags,
107 const fib_route_path_t *paths);
108 extern fib_node_index_t fib_path_list_create_special(fib_protocol_t nh_proto,
109 fib_path_list_flags_t flags,
110 const dpo_id_t *dpo);
112 extern fib_node_index_t fib_path_list_copy_and_path_add(
113 fib_node_index_t pl_index,
114 fib_path_list_flags_t flags,
115 const fib_route_path_t *path);
116 extern fib_node_index_t fib_path_list_copy_and_path_remove(
117 fib_node_index_t pl_index,
118 fib_path_list_flags_t flags,
119 const fib_route_path_t *path);
120 extern fib_node_index_t fib_path_list_path_add (
121 fib_node_index_t path_list_index,
122 const fib_route_path_t *rpaths);
123 extern fib_node_index_t fib_path_list_path_remove (
124 fib_node_index_t path_list_index,
125 const fib_route_path_t *rpaths);
127 extern u32 fib_path_list_get_n_paths(fib_node_index_t pl_index);
129 extern void fib_path_list_contribute_forwarding(fib_node_index_t path_list_index,
130 fib_forward_chain_type_t type,
132 extern void fib_path_list_contribute_urpf(fib_node_index_t path_index,
134 extern index_t fib_path_list_get_urpf(fib_node_index_t path_list_index);
135 extern index_t fib_path_list_get_adj(fib_node_index_t path_list_index,
136 fib_forward_chain_type_t type);
138 extern u32 fib_path_list_child_add(fib_node_index_t pl_index,
139 fib_node_type_t type,
140 fib_node_index_t child_index);
141 extern void fib_path_list_child_remove(fib_node_index_t pl_index,
142 fib_node_index_t sibling_index);
143 extern void fib_path_list_back_walk(fib_node_index_t pl_index,
144 fib_node_back_walk_ctx_t *ctx);
145 extern void fib_path_list_lock(fib_node_index_t pl_index);
146 extern void fib_path_list_unlock(fib_node_index_t pl_index);
147 extern int fib_path_list_recursive_loop_detect(fib_node_index_t path_list_index,
148 fib_node_index_t **entry_indicies);
149 extern u32 fib_path_list_get_resolving_interface(fib_node_index_t path_list_index);
150 extern int fib_path_list_is_looped(fib_node_index_t path_list_index);
151 extern fib_protocol_t fib_path_list_get_proto(fib_node_index_t path_list_index);
152 extern u8 * fib_path_list_format(fib_node_index_t pl_index,
154 extern index_t fib_path_list_lb_map_add_or_lock(fib_node_index_t pl_index,
155 const fib_node_index_t *pis);
156 extern u32 fib_path_list_find_rpath (fib_node_index_t path_list_index,
157 const fib_route_path_t *rpath);
160 * A callback function type for walking a path-list's paths
162 typedef int (*fib_path_list_walk_fn_t)(fib_node_index_t pl_index,
163 fib_node_index_t path_index,
166 extern void fib_path_list_walk(fib_node_index_t pl_index,
167 fib_path_list_walk_fn_t func,
170 extern void fib_path_list_module_init(void);
172 extern void fib_path_list_module_init(void);
175 * functions for testing.
177 u32 fib_path_list_pool_size(void);
178 u32 fib_path_list_db_size(void);