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_SOURCE_H__
17 #define __FIB_SOURCE_H__
19 #include <vnet/vnet.h>
22 * The different sources that can create a route.
23 * The sources are defined here with their relative priority order.
24 * The lower the value the higher the priority
26 typedef enum fib_source_t_ {
29 * This is not a real source, so don't use it to source a prefix.
30 * It exists here to provide a value for inexistant/uninitialized source
32 FIB_SOURCE_INVALID = 0,
34 * Marker. Add new values after this one.
38 * Special sources. These are for entries that are added to all
39 * FIBs by default, and should never be over-ridden (hence they
40 * are the highest priority)
42 FIB_SOURCE_SPECIAL = FIB_SOURCE_FIRST,
44 * Classify. A route that links directly to a classify adj
48 * A route the is being 'proxied' on behalf of another device
52 * Route added as a result of interface configuration.
53 * this will also come from the API/CLI, but the distinction is
54 * that is from confiiguration on an interface, not a 'ip route' command
62 * From the BIER subsystem
70 * From the control plane API
92 FIB_SOURCE_IP6_ND_PROXY,
94 * IPv6 ND (seen in the link-local tables)
99 * routes created as a result of ARP/ND entries. This is lower priority
100 * then the API/CLI. This is on purpose. trust me.
104 * MPLS label. The prefix has been assigned a local label. This source
105 * never provides forwarding information, instead it acts as a place-holder
106 * so the association of label to prefix can be maintained
110 * Attached Export source.
111 * routes created as a result of attahced export. routes thus sourced
112 * will be present in the export tables
116 * Recursive resolution source.
117 * Used to install an entry that is the resolution traget of another.
121 * uRPF bypass/exemption.
122 * Used to install an entry that is exempt from the loose uRPF check
124 FIB_SOURCE_URPF_EXEMPT,
126 * The default route source.
127 * The default route is always added to the FIB table (like the
128 * special sources) but we need to be able to over-ride it with
129 * 'ip route' sources when provided
131 FIB_SOURCE_DEFAULT_ROUTE,
133 * The interpose source.
134 * This is not a real source, so don't use it to source a prefix.
135 * It exists here to provide a value against which to register to the
136 * VFT for providing the interpose actions to a real source.
138 FIB_SOURCE_INTERPOSE,
140 * Marker. add new entries before this one.
142 FIB_SOURCE_LAST = FIB_SOURCE_INTERPOSE,
143 } __attribute__ ((packed)) fib_source_t;
145 STATIC_ASSERT (sizeof(fib_source_t) == 1,
146 "FIB too many sources");
148 #define FIB_SOURCES { \
149 [FIB_SOURCE_INVALID] = "invalid", \
150 [FIB_SOURCE_SPECIAL] = "special", \
151 [FIB_SOURCE_INTERFACE] = "interface", \
152 [FIB_SOURCE_PROXY] = "proxy", \
153 [FIB_SOURCE_BIER] = "BIER", \
154 [FIB_SOURCE_6RD] = "6RD", \
155 [FIB_SOURCE_API] = "API", \
156 [FIB_SOURCE_CLI] = "CLI", \
157 [FIB_SOURCE_ADJ] = "adjacency", \
158 [FIB_SOURCE_MAP] = "MAP", \
159 [FIB_SOURCE_SR] = "SR", \
160 [FIB_SOURCE_LISP] = "LISP", \
161 [FIB_SOURCE_CLASSIFY] = "classify", \
162 [FIB_SOURCE_DHCP] = "DHCP", \
163 [FIB_SOURCE_IP6_ND_PROXY] = "IPv6-proxy-nd", \
164 [FIB_SOURCE_IP6_ND] = "IPv6-nd", \
165 [FIB_SOURCE_RR] = "recursive-resolution", \
166 [FIB_SOURCE_AE] = "attached_export", \
167 [FIB_SOURCE_MPLS] = "mpls", \
168 [FIB_SOURCE_URPF_EXEMPT] = "urpf-exempt", \
169 [FIB_SOURCE_DEFAULT_ROUTE] = "default-route", \
170 [FIB_SOURCE_INTERPOSE] = "interpose", \
174 * Each source is assigned a priority. lower priority is beeter.
175 * the source with the best source with have its contribution added
176 * to forwarding. the lesser sources will be 'remembered' by FIB and
177 * added to forwarding should the best source be removed.
179 typedef u8 fib_source_priority_t;
184 typedef enum fib_source_priority_cmp_t_
186 FIB_SOURCE_CMP_BETTER,
187 FIB_SOURCE_CMP_WORSE,
188 FIB_SOURCE_CMP_EQUAL,
189 } fib_source_priority_cmp_t;
192 * Each source has a defined behaviour that controls how entries
193 * behave that have that source
195 typedef enum fib_source_behaviour_t_
198 * If your adding a new source from a plugin pick one of these
200 /** Default behaviour - always install a drop */
202 /** add paths with [mpls] path extensions */
204 /** add paths without path extensions */
205 FIB_SOURCE_BH_SIMPLE,
208 * If your adding a new source from a plugin
209 * these are probably not the behaviour you're lokking for.
211 /** recursive resolution w/ cover tracking*/
213 /** associated label stored in private data */
215 /** cover tracking w/ glean management */
216 FIB_SOURCE_BH_INTERFACE,
218 FIB_SOURCE_BH_INTERPOSE,
219 /** simple + source fib tracking */
221 /** adj w/ cover tracking + refinement */
223 } fib_source_behaviour_t;
225 #define FIB_SOURCE_BH_MAX (FIB_SOURCE_BH_ADJ+1)
227 #define FIB_SOURCE_BEHAVIOURS { \
228 [FIB_SOURCE_BH_DROP] = "drop", \
229 [FIB_SOURCE_BH_RR] = "rr", \
230 [FIB_SOURCE_BH_MPLS] = "mpls", \
231 [FIB_SOURCE_BH_INTERFACE] = "interface", \
232 [FIB_SOURCE_BH_INTERPOSE] = "interpose", \
233 [FIB_SOURCE_BH_LISP] = "lisp", \
234 [FIB_SOURCE_BH_ADJ] = "adjacency", \
235 [FIB_SOURCE_BH_API] = "api", \
236 [FIB_SOURCE_BH_SIMPLE] = "simple", \
240 * The fixed source to priority mappings.
241 * Declared here so those adding new sources can better determine their respective
244 #define foreach_fib_source \
245 /** you can't do better then the special source */ \
246 _(FIB_SOURCE_SPECIAL, 0x00, FIB_SOURCE_BH_SIMPLE) \
247 _(FIB_SOURCE_CLASSIFY, 0x01, FIB_SOURCE_BH_SIMPLE) \
248 _(FIB_SOURCE_PROXY, 0x02, FIB_SOURCE_BH_SIMPLE) \
249 _(FIB_SOURCE_INTERFACE, 0x03, FIB_SOURCE_BH_INTERFACE) \
250 _(FIB_SOURCE_SR, 0x10, FIB_SOURCE_BH_API) \
251 _(FIB_SOURCE_BIER, 0x20, FIB_SOURCE_BH_SIMPLE) \
252 _(FIB_SOURCE_6RD, 0x30, FIB_SOURCE_BH_API) \
253 _(FIB_SOURCE_API, 0x80, FIB_SOURCE_BH_API) \
254 _(FIB_SOURCE_CLI, 0x81, FIB_SOURCE_BH_API) \
255 _(FIB_SOURCE_LISP, 0x90, FIB_SOURCE_BH_LISP) \
256 _(FIB_SOURCE_MAP, 0xa0, FIB_SOURCE_BH_SIMPLE) \
257 _(FIB_SOURCE_DHCP, 0xb0, FIB_SOURCE_BH_API) \
258 _(FIB_SOURCE_IP6_ND_PROXY, 0xc0, FIB_SOURCE_BH_API) \
259 _(FIB_SOURCE_IP6_ND, 0xc1, FIB_SOURCE_BH_API) \
260 _(FIB_SOURCE_ADJ, 0xd0, FIB_SOURCE_BH_ADJ) \
261 _(FIB_SOURCE_MPLS, 0xe0, FIB_SOURCE_BH_MPLS) \
262 _(FIB_SOURCE_AE, 0xf0, FIB_SOURCE_BH_SIMPLE) \
263 _(FIB_SOURCE_RR, 0xfb, FIB_SOURCE_BH_RR) \
264 _(FIB_SOURCE_URPF_EXEMPT, 0xfc, FIB_SOURCE_BH_RR) \
265 _(FIB_SOURCE_DEFAULT_ROUTE, 0xfd, FIB_SOURCE_BH_DROP) \
266 _(FIB_SOURCE_INTERPOSE, 0xfe, FIB_SOURCE_BH_INTERPOSE) \
267 _(FIB_SOURCE_INVALID, 0xff, FIB_SOURCE_BH_DROP)
270 * Some priority values that plugins might use when they are not to concerned
271 * where in the list they'll go.
273 #define FIB_SOURCE_PRIORITY_HI 0x10
274 #define FIB_SOURCE_PRIORITY_LOW 0xd0
277 extern u16 fib_source_get_prio(fib_source_t src);
278 extern fib_source_behaviour_t fib_source_get_behaviour(fib_source_t src);
279 extern fib_source_priority_cmp_t fib_source_cmp(fib_source_t s1,
282 extern u8 *format_fib_source(u8 *s, va_list *a);
284 extern fib_source_t fib_source_allocate(const char *name,
285 fib_source_priority_t prio,
286 fib_source_behaviour_t bh);
288 extern void fib_source_register(fib_source_t src,
289 fib_source_priority_t prio,
290 fib_source_behaviour_t bh);
292 typedef walk_rc_t (*fib_source_walk_t)(fib_source_t id,
294 fib_source_priority_t prio,
295 fib_source_behaviour_t bh,
297 extern void fib_source_walk(fib_source_walk_t fn,
300 extern void fib_source_module_init(void);