blob: f4063a7819ca4f336e08b2bae1d6a251b1b2e136 [file] [log] [blame]
Neale Ranns3bab8f92019-12-04 06:11:00 +00001/*
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:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
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.
14 */
15
16#ifndef __FIB_SOURCE_H__
17#define __FIB_SOURCE_H__
18
19#include <vnet/vnet.h>
20
21/**
22 * The different sources that can create a route.
Neale Rannsdfd39542020-11-09 10:09:42 +000023 *
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.
Neale Ranns3bab8f92019-12-04 06:11:00 +000028 */
29typedef enum fib_source_t_ {
30 /**
31 * An invalid source
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
34 */
35 FIB_SOURCE_INVALID = 0,
36 /**
37 * Marker. Add new values after this one.
38 */
39 FIB_SOURCE_FIRST,
40 /**
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)
44 */
45 FIB_SOURCE_SPECIAL = FIB_SOURCE_FIRST,
46 /**
47 * Classify. A route that links directly to a classify adj
48 */
49 FIB_SOURCE_CLASSIFY,
50 /**
51 * A route the is being 'proxied' on behalf of another device
52 */
53 FIB_SOURCE_PROXY,
54 /**
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
58 */
59 FIB_SOURCE_INTERFACE,
60 /**
61 * SRv6 and SR-MPLS
62 */
63 FIB_SOURCE_SR,
64 /**
65 * From the BIER subsystem
66 */
67 FIB_SOURCE_BIER,
68 /**
69 * From 6RD.
70 */
71 FIB_SOURCE_6RD,
72 /**
73 * From the control plane API
74 */
75 FIB_SOURCE_API,
76 /**
77 * From the CLI.
78 */
79 FIB_SOURCE_CLI,
80 /**
81 * LISP
82 */
83 FIB_SOURCE_LISP,
84 /**
85 * IPv[46] Mapping
86 */
87 FIB_SOURCE_MAP,
88 /**
89 * DHCP
90 */
91 FIB_SOURCE_DHCP,
92 /**
93 * IPv6 Proxy ND
94 */
95 FIB_SOURCE_IP6_ND_PROXY,
96 /**
97 * IPv6 ND (seen in the link-local tables)
98 */
99 FIB_SOURCE_IP6_ND,
100 /**
101 * Adjacency source.
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.
104 */
105 FIB_SOURCE_ADJ,
106 /**
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
110 */
111 FIB_SOURCE_MPLS,
112 /**
113 * Attached Export source.
114 * routes created as a result of attahced export. routes thus sourced
115 * will be present in the export tables
116 */
117 FIB_SOURCE_AE,
118 /**
119 * Recursive resolution source.
120 * Used to install an entry that is the resolution traget of another.
121 */
122 FIB_SOURCE_RR,
123 /**
124 * uRPF bypass/exemption.
125 * Used to install an entry that is exempt from the loose uRPF check
126 */
127 FIB_SOURCE_URPF_EXEMPT,
128 /**
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
133 */
134 FIB_SOURCE_DEFAULT_ROUTE,
135 /**
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.
140 */
141 FIB_SOURCE_INTERPOSE,
142 /**
143 * Marker. add new entries before this one.
144 */
145 FIB_SOURCE_LAST = FIB_SOURCE_INTERPOSE,
146} __attribute__ ((packed)) fib_source_t;
147
148STATIC_ASSERT (sizeof(fib_source_t) == 1,
149 "FIB too many sources");
150
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", \
174}
175
176/**
Neale Rannsdfd39542020-11-09 10:09:42 +0000177 * Each source is assigned a priority. lower priority is better.
Neale Ranns3bab8f92019-12-04 06:11:00 +0000178 * 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.
181 */
182typedef u8 fib_source_priority_t;
183
184/**
185 * source comparison
186 */
187typedef enum fib_source_priority_cmp_t_
188{
189 FIB_SOURCE_CMP_BETTER,
190 FIB_SOURCE_CMP_WORSE,
191 FIB_SOURCE_CMP_EQUAL,
192} fib_source_priority_cmp_t;
193
194/**
195 * Each source has a defined behaviour that controls how entries
Neale Rannsdfd39542020-11-09 10:09:42 +0000196 * 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.
Neale Ranns3bab8f92019-12-04 06:11:00 +0000199 */
200typedef enum fib_source_behaviour_t_
201{
202 /**
Neale Rannsdfd39542020-11-09 10:09:42 +0000203 * If you're adding a new source from a plugin pick one of these
Neale Ranns3bab8f92019-12-04 06:11:00 +0000204 */
205 /** Default behaviour - always install a drop */
206 FIB_SOURCE_BH_DROP,
207 /** add paths with [mpls] path extensions */
208 FIB_SOURCE_BH_API,
209 /** add paths without path extensions */
210 FIB_SOURCE_BH_SIMPLE,
211
212 /**
213 * If your adding a new source from a plugin
214 * these are probably not the behaviour you're lokking for.
215 */
216 /** recursive resolution w/ cover tracking*/
217 FIB_SOURCE_BH_RR,
218 /** associated label stored in private data */
219 FIB_SOURCE_BH_MPLS,
220 /** cover tracking w/ glean management */
221 FIB_SOURCE_BH_INTERFACE,
222 /** interpose */
223 FIB_SOURCE_BH_INTERPOSE,
Neale Rannsdfd39542020-11-09 10:09:42 +0000224 /**
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.
230 */
Neale Ranns3bab8f92019-12-04 06:11:00 +0000231 FIB_SOURCE_BH_LISP,
232 /** adj w/ cover tracking + refinement */
233 FIB_SOURCE_BH_ADJ,
234} fib_source_behaviour_t;
235
236#define FIB_SOURCE_BH_MAX (FIB_SOURCE_BH_ADJ+1)
237
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", \
248}
249
250/**
251 * The fixed source to priority mappings.
252 * Declared here so those adding new sources can better determine their respective
253 * priority values.
254 */
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)
279
280/**
281 * Some priority values that plugins might use when they are not to concerned
282 * where in the list they'll go.
283 */
284#define FIB_SOURCE_PRIORITY_HI 0x10
285#define FIB_SOURCE_PRIORITY_LOW 0xd0
286
287
288extern u16 fib_source_get_prio(fib_source_t src);
289extern fib_source_behaviour_t fib_source_get_behaviour(fib_source_t src);
290extern fib_source_priority_cmp_t fib_source_cmp(fib_source_t s1,
291 fib_source_t s2);
292
293extern u8 *format_fib_source(u8 *s, va_list *a);
294
295extern fib_source_t fib_source_allocate(const char *name,
296 fib_source_priority_t prio,
297 fib_source_behaviour_t bh);
298
299extern void fib_source_register(fib_source_t src,
300 fib_source_priority_t prio,
301 fib_source_behaviour_t bh);
302
303typedef walk_rc_t (*fib_source_walk_t)(fib_source_t id,
304 const char *name,
305 fib_source_priority_t prio,
306 fib_source_behaviour_t bh,
307 void *ctx);
308extern void fib_source_walk(fib_source_walk_t fn,
309 void *ctx);
310
311extern void fib_source_module_init(void);
312
313#endif