blob: 198ef194e2b63293ae9f5ff1e732f17ac559af8a [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.
23 * The sources are defined here with their relative priority order.
24 * The lower the value the higher the priority
25 */
26typedef enum fib_source_t_ {
27 /**
28 * An invalid source
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
31 */
32 FIB_SOURCE_INVALID = 0,
33 /**
34 * Marker. Add new values after this one.
35 */
36 FIB_SOURCE_FIRST,
37 /**
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)
41 */
42 FIB_SOURCE_SPECIAL = FIB_SOURCE_FIRST,
43 /**
44 * Classify. A route that links directly to a classify adj
45 */
46 FIB_SOURCE_CLASSIFY,
47 /**
48 * A route the is being 'proxied' on behalf of another device
49 */
50 FIB_SOURCE_PROXY,
51 /**
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
55 */
56 FIB_SOURCE_INTERFACE,
57 /**
58 * SRv6 and SR-MPLS
59 */
60 FIB_SOURCE_SR,
61 /**
62 * From the BIER subsystem
63 */
64 FIB_SOURCE_BIER,
65 /**
66 * From 6RD.
67 */
68 FIB_SOURCE_6RD,
69 /**
70 * From the control plane API
71 */
72 FIB_SOURCE_API,
73 /**
74 * From the CLI.
75 */
76 FIB_SOURCE_CLI,
77 /**
78 * LISP
79 */
80 FIB_SOURCE_LISP,
81 /**
82 * IPv[46] Mapping
83 */
84 FIB_SOURCE_MAP,
85 /**
86 * DHCP
87 */
88 FIB_SOURCE_DHCP,
89 /**
90 * IPv6 Proxy ND
91 */
92 FIB_SOURCE_IP6_ND_PROXY,
93 /**
94 * IPv6 ND (seen in the link-local tables)
95 */
96 FIB_SOURCE_IP6_ND,
97 /**
98 * Adjacency source.
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.
101 */
102 FIB_SOURCE_ADJ,
103 /**
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
107 */
108 FIB_SOURCE_MPLS,
109 /**
110 * Attached Export source.
111 * routes created as a result of attahced export. routes thus sourced
112 * will be present in the export tables
113 */
114 FIB_SOURCE_AE,
115 /**
116 * Recursive resolution source.
117 * Used to install an entry that is the resolution traget of another.
118 */
119 FIB_SOURCE_RR,
120 /**
121 * uRPF bypass/exemption.
122 * Used to install an entry that is exempt from the loose uRPF check
123 */
124 FIB_SOURCE_URPF_EXEMPT,
125 /**
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
130 */
131 FIB_SOURCE_DEFAULT_ROUTE,
132 /**
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.
137 */
138 FIB_SOURCE_INTERPOSE,
139 /**
140 * Marker. add new entries before this one.
141 */
142 FIB_SOURCE_LAST = FIB_SOURCE_INTERPOSE,
143} __attribute__ ((packed)) fib_source_t;
144
145STATIC_ASSERT (sizeof(fib_source_t) == 1,
146 "FIB too many sources");
147
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", \
171}
172
173/**
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.
178 */
179typedef u8 fib_source_priority_t;
180
181/**
182 * source comparison
183 */
184typedef enum fib_source_priority_cmp_t_
185{
186 FIB_SOURCE_CMP_BETTER,
187 FIB_SOURCE_CMP_WORSE,
188 FIB_SOURCE_CMP_EQUAL,
189} fib_source_priority_cmp_t;
190
191/**
192 * Each source has a defined behaviour that controls how entries
193 * behave that have that source
194 */
195typedef enum fib_source_behaviour_t_
196{
197 /**
198 * If your adding a new source from a plugin pick one of these
199 */
200 /** Default behaviour - always install a drop */
201 FIB_SOURCE_BH_DROP,
202 /** add paths with [mpls] path extensions */
203 FIB_SOURCE_BH_API,
204 /** add paths without path extensions */
205 FIB_SOURCE_BH_SIMPLE,
206
207 /**
208 * If your adding a new source from a plugin
209 * these are probably not the behaviour you're lokking for.
210 */
211 /** recursive resolution w/ cover tracking*/
212 FIB_SOURCE_BH_RR,
213 /** associated label stored in private data */
214 FIB_SOURCE_BH_MPLS,
215 /** cover tracking w/ glean management */
216 FIB_SOURCE_BH_INTERFACE,
217 /** interpose */
218 FIB_SOURCE_BH_INTERPOSE,
219 /** simple + source fib tracking */
220 FIB_SOURCE_BH_LISP,
221 /** adj w/ cover tracking + refinement */
222 FIB_SOURCE_BH_ADJ,
223} fib_source_behaviour_t;
224
225#define FIB_SOURCE_BH_MAX (FIB_SOURCE_BH_ADJ+1)
226
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", \
237}
238
239/**
240 * The fixed source to priority mappings.
241 * Declared here so those adding new sources can better determine their respective
242 * priority values.
243 */
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)
268
269/**
270 * Some priority values that plugins might use when they are not to concerned
271 * where in the list they'll go.
272 */
273#define FIB_SOURCE_PRIORITY_HI 0x10
274#define FIB_SOURCE_PRIORITY_LOW 0xd0
275
276
277extern u16 fib_source_get_prio(fib_source_t src);
278extern fib_source_behaviour_t fib_source_get_behaviour(fib_source_t src);
279extern fib_source_priority_cmp_t fib_source_cmp(fib_source_t s1,
280 fib_source_t s2);
281
282extern u8 *format_fib_source(u8 *s, va_list *a);
283
284extern fib_source_t fib_source_allocate(const char *name,
285 fib_source_priority_t prio,
286 fib_source_behaviour_t bh);
287
288extern void fib_source_register(fib_source_t src,
289 fib_source_priority_t prio,
290 fib_source_behaviour_t bh);
291
292typedef walk_rc_t (*fib_source_walk_t)(fib_source_t id,
293 const char *name,
294 fib_source_priority_t prio,
295 fib_source_behaviour_t bh,
296 void *ctx);
297extern void fib_source_walk(fib_source_walk_t fn,
298 void *ctx);
299
300extern void fib_source_module_init(void);
301
302#endif