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.
24 * A source is a combination of two concepts; priority and behaviour.
25 * Priority determines whether the source is contributing forwarding.
26 * Behaviour determines how FIB entries with this source interact with
27 * other elements of FIB.
29 typedef enum fib_source_t_ {
32 * This is not a real source, so don't use it to source a prefix.
33 * It exists here to provide a value for inexistant/uninitialized source
35 FIB_SOURCE_INVALID = 0,
37 * Marker. Add new values after this one.
41 * Special sources. These are for entries that are added to all
42 * FIBs by default, and should never be over-ridden (hence they
43 * are the highest priority)
45 FIB_SOURCE_SPECIAL = FIB_SOURCE_FIRST,
47 * Classify. A route that links directly to a classify adj
51 * A route the is being 'proxied' on behalf of another device
55 * Route added as a result of interface configuration.
56 * this will also come from the API/CLI, but the distinction is
57 * that is from confiiguration on an interface, not a 'ip route' command
65 * From the BIER subsystem
73 * From the control plane API
95 FIB_SOURCE_IP6_ND_PROXY,
97 * IPv6 ND (seen in the link-local tables)
102 * routes created as a result of ARP/ND entries. This is lower priority
103 * then the API/CLI. This is on purpose. trust me.
107 * MPLS label. The prefix has been assigned a local label. This source
108 * never provides forwarding information, instead it acts as a place-holder
109 * so the association of label to prefix can be maintained
113 * Attached Export source.
114 * routes created as a result of attahced export. routes thus sourced
115 * will be present in the export tables
119 * Recursive resolution source.
120 * Used to install an entry that is the resolution traget of another.
124 * uRPF bypass/exemption.
125 * Used to install an entry that is exempt from the loose uRPF check
127 FIB_SOURCE_URPF_EXEMPT,
129 * The default route source.
130 * The default route is always added to the FIB table (like the
131 * special sources) but we need to be able to over-ride it with
132 * 'ip route' sources when provided
134 FIB_SOURCE_DEFAULT_ROUTE,
136 * The interpose source.
137 * This is not a real source, so don't use it to source a prefix.
138 * It exists here to provide a value against which to register to the
139 * VFT for providing the interpose actions to a real source.
141 FIB_SOURCE_INTERPOSE,
143 * Marker. add new entries before this one.
145 FIB_SOURCE_LAST = FIB_SOURCE_INTERPOSE,
146 } __attribute__ ((packed)) fib_source_t;
148 STATIC_ASSERT (sizeof(fib_source_t) == 1,
149 "FIB too many sources");
151 #define FIB_SOURCES { \
152 [FIB_SOURCE_INVALID] = "invalid", \
153 [FIB_SOURCE_SPECIAL] = "special", \
154 [FIB_SOURCE_INTERFACE] = "interface", \
155 [FIB_SOURCE_PROXY] = "proxy", \
156 [FIB_SOURCE_BIER] = "BIER", \
157 [FIB_SOURCE_6RD] = "6RD", \
158 [FIB_SOURCE_API] = "API", \
159 [FIB_SOURCE_CLI] = "CLI", \
160 [FIB_SOURCE_ADJ] = "adjacency", \
161 [FIB_SOURCE_MAP] = "MAP", \
162 [FIB_SOURCE_SR] = "SR", \
163 [FIB_SOURCE_LISP] = "LISP", \
164 [FIB_SOURCE_CLASSIFY] = "classify", \
165 [FIB_SOURCE_DHCP] = "DHCP", \
166 [FIB_SOURCE_IP6_ND_PROXY] = "IPv6-proxy-nd", \
167 [FIB_SOURCE_IP6_ND] = "IPv6-nd", \
168 [FIB_SOURCE_RR] = "recursive-resolution", \
169 [FIB_SOURCE_AE] = "attached_export", \
170 [FIB_SOURCE_MPLS] = "mpls", \
171 [FIB_SOURCE_URPF_EXEMPT] = "urpf-exempt", \
172 [FIB_SOURCE_DEFAULT_ROUTE] = "default-route", \
173 [FIB_SOURCE_INTERPOSE] = "interpose", \
177 * Each source is assigned a priority. lower priority is better.
178 * the source with the best source with have its contribution added
179 * to forwarding. the lesser sources will be 'remembered' by FIB and
180 * added to forwarding should the best source be removed.
182 typedef u8 fib_source_priority_t;
187 typedef enum fib_source_priority_cmp_t_
189 FIB_SOURCE_CMP_BETTER,
190 FIB_SOURCE_CMP_WORSE,
191 FIB_SOURCE_CMP_EQUAL,
192 } fib_source_priority_cmp_t;
195 * Each source has a defined behaviour that controls how entries
196 * behave that have that source.
197 * Sources with non-default behaviour may have a private data area
198 * in the fib_entry_src_t union.
200 typedef enum fib_source_behaviour_t_
203 * If you're adding a new source from a plugin pick one of these
205 /** Default behaviour - always install a drop */
207 /** add paths with [mpls] path extensions */
209 /** add paths without path extensions */
210 FIB_SOURCE_BH_SIMPLE,
213 * If your adding a new source from a plugin
214 * these are probably not the behaviour you're lokking for.
216 /** recursive resolution w/ cover tracking*/
218 /** associated label stored in private data */
220 /** cover tracking w/ glean management */
221 FIB_SOURCE_BH_INTERFACE,
223 FIB_SOURCE_BH_INTERPOSE,
225 * simple behaviour, plus the source specific data stores the
226 * FIB index that is used for subsequent lookups using the
227 * packet's source address.
228 * This doesn't need to be a LISP specific source, it's just
229 * 'simple' behaviour with a u32 stored in the source specific data.
232 /** adj w/ cover tracking + refinement */
234 } fib_source_behaviour_t;
236 #define FIB_SOURCE_BH_MAX (FIB_SOURCE_BH_ADJ+1)
238 #define FIB_SOURCE_BEHAVIOURS { \
239 [FIB_SOURCE_BH_DROP] = "drop", \
240 [FIB_SOURCE_BH_RR] = "rr", \
241 [FIB_SOURCE_BH_MPLS] = "mpls", \
242 [FIB_SOURCE_BH_INTERFACE] = "interface", \
243 [FIB_SOURCE_BH_INTERPOSE] = "interpose", \
244 [FIB_SOURCE_BH_LISP] = "lisp", \
245 [FIB_SOURCE_BH_ADJ] = "adjacency", \
246 [FIB_SOURCE_BH_API] = "api", \
247 [FIB_SOURCE_BH_SIMPLE] = "simple", \
251 * The fixed source to priority mappings.
252 * Declared here so those adding new sources can better determine their respective
255 #define foreach_fib_source \
256 /** you can't do better then the special source */ \
257 _(FIB_SOURCE_SPECIAL, 0x00, FIB_SOURCE_BH_SIMPLE) \
258 _(FIB_SOURCE_CLASSIFY, 0x01, FIB_SOURCE_BH_SIMPLE) \
259 _(FIB_SOURCE_PROXY, 0x02, FIB_SOURCE_BH_SIMPLE) \
260 _(FIB_SOURCE_INTERFACE, 0x03, FIB_SOURCE_BH_INTERFACE) \
261 _(FIB_SOURCE_SR, 0x10, FIB_SOURCE_BH_API) \
262 _(FIB_SOURCE_BIER, 0x20, FIB_SOURCE_BH_SIMPLE) \
263 _(FIB_SOURCE_6RD, 0x30, FIB_SOURCE_BH_API) \
264 _(FIB_SOURCE_API, 0x80, FIB_SOURCE_BH_API) \
265 _(FIB_SOURCE_CLI, 0x81, FIB_SOURCE_BH_API) \
266 _(FIB_SOURCE_LISP, 0x90, FIB_SOURCE_BH_LISP) \
267 _(FIB_SOURCE_MAP, 0xa0, FIB_SOURCE_BH_SIMPLE) \
268 _(FIB_SOURCE_DHCP, 0xb0, FIB_SOURCE_BH_API) \
269 _(FIB_SOURCE_IP6_ND_PROXY, 0xc0, FIB_SOURCE_BH_API) \
270 _(FIB_SOURCE_IP6_ND, 0xc1, FIB_SOURCE_BH_API) \
271 _(FIB_SOURCE_ADJ, 0xd0, FIB_SOURCE_BH_ADJ) \
272 _(FIB_SOURCE_MPLS, 0xe0, FIB_SOURCE_BH_MPLS) \
273 _(FIB_SOURCE_AE, 0xf0, FIB_SOURCE_BH_SIMPLE) \
274 _(FIB_SOURCE_RR, 0xfb, FIB_SOURCE_BH_RR) \
275 _(FIB_SOURCE_URPF_EXEMPT, 0xfc, FIB_SOURCE_BH_RR) \
276 _(FIB_SOURCE_DEFAULT_ROUTE, 0xfd, FIB_SOURCE_BH_DROP) \
277 _(FIB_SOURCE_INTERPOSE, 0xfe, FIB_SOURCE_BH_INTERPOSE) \
278 _(FIB_SOURCE_INVALID, 0xff, FIB_SOURCE_BH_DROP)
281 * Some priority values that plugins might use when they are not to concerned
282 * where in the list they'll go.
284 #define FIB_SOURCE_PRIORITY_HI 0x10
285 #define FIB_SOURCE_PRIORITY_LOW 0xd0
288 extern u16 fib_source_get_prio(fib_source_t src);
289 extern fib_source_behaviour_t fib_source_get_behaviour(fib_source_t src);
290 extern fib_source_priority_cmp_t fib_source_cmp(fib_source_t s1,
293 extern u8 *format_fib_source(u8 *s, va_list *a);
295 extern fib_source_t fib_source_allocate(const char *name,
296 fib_source_priority_t prio,
297 fib_source_behaviour_t bh);
299 extern void fib_source_register(fib_source_t src,
300 fib_source_priority_t prio,
301 fib_source_behaviour_t bh);
303 typedef walk_rc_t (*fib_source_walk_t)(fib_source_t id,
305 fib_source_priority_t prio,
306 fib_source_behaviour_t bh,
308 extern void fib_source_walk(fib_source_walk_t fn,
311 extern void fib_source_module_init(void);