]> git.proxmox.com Git - mirror_frr.git/blob - zebra/rib.h
isisd: implement the 'lsp-too-large' notification
[mirror_frr.git] / zebra / rib.h
1 /*
2 * Routing Information Base header
3 * Copyright (C) 1997 Kunihiro Ishiguro
4 *
5 * This file is part of GNU Zebra.
6 *
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
10 * later version.
11 *
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #ifndef _ZEBRA_RIB_H
23 #define _ZEBRA_RIB_H
24
25 #include "zebra.h"
26 #include "hook.h"
27 #include "linklist.h"
28 #include "prefix.h"
29 #include "table.h"
30 #include "queue.h"
31 #include "nexthop.h"
32 #include "nexthop_group.h"
33 #include "vrf.h"
34 #include "if.h"
35 #include "mpls.h"
36 #include "srcdest_table.h"
37
38 #define DISTANCE_INFINITY 255
39 #define ZEBRA_KERNEL_TABLE_MAX 252 /* support for no more than this rt tables */
40
41 struct route_entry {
42 /* Link list. */
43 struct route_entry *next;
44 struct route_entry *prev;
45
46 /* Nexthop structure */
47 struct nexthop_group ng;
48
49 /* Tag */
50 route_tag_t tag;
51
52 /* Uptime. */
53 time_t uptime;
54
55 /* Type fo this route. */
56 int type;
57
58 /* Source protocol instance */
59 unsigned short instance;
60
61 /* VRF identifier. */
62 vrf_id_t vrf_id;
63
64 /* Which routing table */
65 uint32_t table;
66
67 /* Metric */
68 uint32_t metric;
69
70 /* MTU */
71 uint32_t mtu;
72 uint32_t nexthop_mtu;
73
74 /* Distance. */
75 uint8_t distance;
76
77 /* Flags of this route.
78 * This flag's definition is in lib/zebra.h ZEBRA_FLAG_* and is exposed
79 * to clients via Zserv
80 */
81 uint32_t flags;
82
83 /* RIB internal status */
84 uint8_t status;
85 #define ROUTE_ENTRY_REMOVED 0x1
86 /* to simplify NHT logic when NHs change, instead of doing a NH by NH cmp */
87 #define ROUTE_ENTRY_NEXTHOPS_CHANGED 0x2
88 #define ROUTE_ENTRY_CHANGED 0x4
89 #define ROUTE_ENTRY_LABELS_CHANGED 0x8
90
91 /* Nexthop information. */
92 uint8_t nexthop_num;
93 uint8_t nexthop_active_num;
94
95 /* Sequence value incremented for each dataplane operation */
96 uint32_t dplane_sequence;
97 };
98
99 /* meta-queue structure:
100 * sub-queue 0: connected, kernel
101 * sub-queue 1: static
102 * sub-queue 2: RIP, RIPng, OSPF, OSPF6, IS-IS, EIGRP, NHRP
103 * sub-queue 3: iBGP, eBGP
104 * sub-queue 4: any other origin (if any)
105 */
106 #define MQ_SIZE 5
107 struct meta_queue {
108 struct list *subq[MQ_SIZE];
109 uint32_t size; /* sum of lengths of all subqueues */
110 };
111
112 /*
113 * Structure that represents a single destination (prefix).
114 */
115 typedef struct rib_dest_t_ {
116
117 /*
118 * Back pointer to the route node for this destination. This helps
119 * us get to the prefix that this structure is for.
120 */
121 struct route_node *rnode;
122
123 /*
124 * Doubly-linked list of routes for this prefix.
125 */
126 struct route_entry *routes;
127
128 struct route_entry *selected_fib;
129
130 /*
131 * Flags, see below.
132 */
133 uint32_t flags;
134
135 /*
136 * Linkage to put dest on the FPM processing queue.
137 */
138 TAILQ_ENTRY(rib_dest_t_) fpm_q_entries;
139
140 } rib_dest_t;
141
142 #define RIB_ROUTE_QUEUED(x) (1 << (x))
143 // If MQ_SIZE is modified this value needs to be updated.
144 #define RIB_ROUTE_ANY_QUEUED 0x1F
145
146 /*
147 * The maximum qindex that can be used.
148 */
149 #define ZEBRA_MAX_QINDEX (MQ_SIZE - 1)
150
151 /*
152 * This flag indicates that a given prefix has been 'advertised' to
153 * the FPM to be installed in the forwarding plane.
154 */
155 #define RIB_DEST_SENT_TO_FPM (1 << (ZEBRA_MAX_QINDEX + 1))
156
157 /*
158 * This flag is set when we need to send an update to the FPM about a
159 * dest.
160 */
161 #define RIB_DEST_UPDATE_FPM (1 << (ZEBRA_MAX_QINDEX + 2))
162
163 /*
164 * Macro to iterate over each route for a destination (prefix).
165 */
166 #define RE_DEST_FOREACH_ROUTE(dest, re) \
167 for ((re) = (dest) ? (dest)->routes : NULL; (re); (re) = (re)->next)
168
169 /*
170 * Same as above, but allows the current node to be unlinked.
171 */
172 #define RE_DEST_FOREACH_ROUTE_SAFE(dest, re, next) \
173 for ((re) = (dest) ? (dest)->routes : NULL; \
174 (re) && ((next) = (re)->next, 1); (re) = (next))
175
176 #define RNODE_FOREACH_RE(rn, re) \
177 RE_DEST_FOREACH_ROUTE (rib_dest_from_rnode(rn), re)
178
179 #define RNODE_FOREACH_RE_SAFE(rn, re, next) \
180 RE_DEST_FOREACH_ROUTE_SAFE (rib_dest_from_rnode(rn), re, next)
181
182 #if defined(HAVE_RTADV)
183 /* Structure which hold status of router advertisement. */
184 struct rtadv {
185 int sock;
186
187 int adv_if_count;
188 int adv_msec_if_count;
189
190 struct thread *ra_read;
191 struct thread *ra_timer;
192 };
193 #endif /* HAVE_RTADV */
194
195 /*
196 * rib_table_info_t
197 *
198 * Structure that is hung off of a route_table that holds information about
199 * the table.
200 */
201 typedef struct rib_table_info_t_ {
202
203 /*
204 * Back pointer to zebra_vrf.
205 */
206 struct zebra_vrf *zvrf;
207 afi_t afi;
208 safi_t safi;
209
210 } rib_table_info_t;
211
212 typedef enum {
213 RIB_TABLES_ITER_S_INIT,
214 RIB_TABLES_ITER_S_ITERATING,
215 RIB_TABLES_ITER_S_DONE
216 } rib_tables_iter_state_t;
217
218 /*
219 * Structure that holds state for iterating over all tables in the
220 * Routing Information Base.
221 */
222 typedef struct rib_tables_iter_t_ {
223 vrf_id_t vrf_id;
224 int afi_safi_ix;
225
226 rib_tables_iter_state_t state;
227 } rib_tables_iter_t;
228
229 /* Events/reasons triggering a RIB update. */
230 typedef enum {
231 RIB_UPDATE_IF_CHANGE,
232 RIB_UPDATE_RMAP_CHANGE,
233 RIB_UPDATE_OTHER
234 } rib_update_event_t;
235
236 extern struct nexthop *route_entry_nexthop_ifindex_add(struct route_entry *re,
237 ifindex_t ifindex,
238 vrf_id_t nh_vrf_id);
239 extern struct nexthop *
240 route_entry_nexthop_blackhole_add(struct route_entry *re,
241 enum blackhole_type bh_type);
242 extern struct nexthop *route_entry_nexthop_ipv4_add(struct route_entry *re,
243 struct in_addr *ipv4,
244 struct in_addr *src,
245 vrf_id_t nh_vrf_id);
246 extern struct nexthop *
247 route_entry_nexthop_ipv4_ifindex_add(struct route_entry *re,
248 struct in_addr *ipv4, struct in_addr *src,
249 ifindex_t ifindex, vrf_id_t nh_vrf_id);
250 extern void route_entry_nexthop_delete(struct route_entry *re,
251 struct nexthop *nexthop);
252 extern struct nexthop *route_entry_nexthop_ipv6_add(struct route_entry *re,
253 struct in6_addr *ipv6,
254 vrf_id_t nh_vrf_id);
255 extern struct nexthop *
256 route_entry_nexthop_ipv6_ifindex_add(struct route_entry *re,
257 struct in6_addr *ipv6, ifindex_t ifindex,
258 vrf_id_t nh_vrf_id);
259 extern void route_entry_nexthop_add(struct route_entry *re,
260 struct nexthop *nexthop);
261 extern void route_entry_copy_nexthops(struct route_entry *re,
262 struct nexthop *nh);
263
264 #define route_entry_dump(prefix, src, re) _route_entry_dump(__func__, prefix, src, re)
265 extern void _route_entry_dump(const char *func, union prefixconstptr pp,
266 union prefixconstptr src_pp,
267 const struct route_entry *re);
268 /* RPF lookup behaviour */
269 enum multicast_mode {
270 MCAST_NO_CONFIG = 0, /* MIX_MRIB_FIRST, but no show in config write */
271 MCAST_MRIB_ONLY, /* MRIB only */
272 MCAST_URIB_ONLY, /* URIB only */
273 MCAST_MIX_MRIB_FIRST, /* MRIB, if nothing at all then URIB */
274 MCAST_MIX_DISTANCE, /* MRIB & URIB, lower distance wins */
275 MCAST_MIX_PFXLEN, /* MRIB & URIB, longer prefix wins */
276 /* on equal value, MRIB wins for last 2 */
277 };
278
279 extern void multicast_mode_ipv4_set(enum multicast_mode mode);
280 extern enum multicast_mode multicast_mode_ipv4_get(void);
281
282 extern void rib_lookup_and_dump(struct prefix_ipv4 *p, vrf_id_t vrf_id);
283 extern void rib_lookup_and_pushup(struct prefix_ipv4 *p, vrf_id_t vrf_id);
284
285 #define ZEBRA_RIB_LOOKUP_ERROR -1
286 #define ZEBRA_RIB_FOUND_EXACT 0
287 #define ZEBRA_RIB_FOUND_NOGATE 1
288 #define ZEBRA_RIB_FOUND_CONNECTED 2
289 #define ZEBRA_RIB_NOTFOUND 3
290
291 extern int is_zebra_valid_kernel_table(uint32_t table_id);
292 extern int is_zebra_main_routing_table(uint32_t table_id);
293 extern int zebra_check_addr(const struct prefix *p);
294
295 extern void rib_delnode(struct route_node *rn, struct route_entry *re);
296 extern void rib_install_kernel(struct route_node *rn, struct route_entry *re,
297 struct route_entry *old);
298 extern void rib_uninstall_kernel(struct route_node *rn, struct route_entry *re);
299
300 /* NOTE:
301 * All rib_add function will not just add prefix into RIB, but
302 * also implicitly withdraw equal prefix of same type. */
303 extern int rib_add(afi_t afi, safi_t safi, vrf_id_t vrf_id, int type,
304 unsigned short instance, int flags, struct prefix *p,
305 struct prefix_ipv6 *src_p, const struct nexthop *nh,
306 uint32_t table_id, uint32_t metric, uint32_t mtu,
307 uint8_t distance, route_tag_t tag);
308
309 extern int rib_add_multipath(afi_t afi, safi_t safi, struct prefix *p,
310 struct prefix_ipv6 *src_p, struct route_entry *re);
311
312 extern void rib_delete(afi_t afi, safi_t safi, vrf_id_t vrf_id, int type,
313 unsigned short instance, int flags, struct prefix *p,
314 struct prefix_ipv6 *src_p, const struct nexthop *nh,
315 uint32_t table_id, uint32_t metric, uint8_t distance,
316 bool fromkernel);
317
318 extern struct route_entry *rib_match(afi_t afi, safi_t safi, vrf_id_t vrf_id,
319 union g_addr *addr,
320 struct route_node **rn_out);
321 extern struct route_entry *rib_match_ipv4_multicast(vrf_id_t vrf_id,
322 struct in_addr addr,
323 struct route_node **rn_out);
324
325 extern struct route_entry *rib_lookup_ipv4(struct prefix_ipv4 *p,
326 vrf_id_t vrf_id);
327
328 extern void rib_update(vrf_id_t vrf_id, rib_update_event_t event);
329 extern void rib_update_table(struct route_table *table,
330 rib_update_event_t event);
331 extern void rib_sweep_route(void);
332 extern void rib_sweep_table(struct route_table *table);
333 extern void rib_close_table(struct route_table *table);
334 extern void rib_init(void);
335 extern unsigned long rib_score_proto(uint8_t proto, unsigned short instance);
336 extern unsigned long rib_score_proto_table(uint8_t proto,
337 unsigned short instance,
338 struct route_table *table);
339 extern void rib_queue_add(struct route_node *rn);
340 extern void meta_queue_free(struct meta_queue *mq);
341 extern int zebra_rib_labeled_unicast(struct route_entry *re);
342 extern struct route_table *rib_table_ipv6;
343
344 extern void rib_unlink(struct route_node *rn, struct route_entry *re);
345 extern int rib_gc_dest(struct route_node *rn);
346 extern struct route_table *rib_tables_iter_next(rib_tables_iter_t *iter);
347
348 extern uint8_t route_distance(int type);
349
350 /*
351 * Inline functions.
352 */
353
354 /*
355 * rib_table_info
356 */
357 static inline rib_table_info_t *rib_table_info(struct route_table *table)
358 {
359 return (rib_table_info_t *)route_table_get_info(table);
360 }
361
362 /*
363 * rib_dest_from_rnode
364 */
365 static inline rib_dest_t *rib_dest_from_rnode(struct route_node *rn)
366 {
367 return (rib_dest_t *)rn->info;
368 }
369
370 /*
371 * rnode_to_ribs
372 *
373 * Returns a pointer to the list of routes corresponding to the given
374 * route_node.
375 */
376 static inline struct route_entry *rnode_to_ribs(struct route_node *rn)
377 {
378 rib_dest_t *dest;
379
380 dest = rib_dest_from_rnode(rn);
381 if (!dest)
382 return NULL;
383
384 return dest->routes;
385 }
386
387 /*
388 * rib_dest_prefix
389 */
390 static inline struct prefix *rib_dest_prefix(rib_dest_t *dest)
391 {
392 return &dest->rnode->p;
393 }
394
395 /*
396 * rib_dest_af
397 *
398 * Returns the address family that the destination is for.
399 */
400 static inline uint8_t rib_dest_af(rib_dest_t *dest)
401 {
402 return dest->rnode->p.family;
403 }
404
405 /*
406 * rib_dest_table
407 */
408 static inline struct route_table *rib_dest_table(rib_dest_t *dest)
409 {
410 return srcdest_rnode_table(dest->rnode);
411 }
412
413 /*
414 * rib_dest_vrf
415 */
416 static inline struct zebra_vrf *rib_dest_vrf(rib_dest_t *dest)
417 {
418 return rib_table_info(rib_dest_table(dest))->zvrf;
419 }
420
421 /*
422 * rib_tables_iter_init
423 */
424 static inline void rib_tables_iter_init(rib_tables_iter_t *iter)
425
426 {
427 memset(iter, 0, sizeof(*iter));
428 iter->state = RIB_TABLES_ITER_S_INIT;
429 }
430
431 /*
432 * rib_tables_iter_started
433 *
434 * Returns TRUE if this iterator has started iterating over the set of
435 * tables.
436 */
437 static inline int rib_tables_iter_started(rib_tables_iter_t *iter)
438 {
439 return iter->state != RIB_TABLES_ITER_S_INIT;
440 }
441
442 /*
443 * rib_tables_iter_cleanup
444 */
445 static inline void rib_tables_iter_cleanup(rib_tables_iter_t *iter)
446 {
447 iter->state = RIB_TABLES_ITER_S_DONE;
448 }
449
450 DECLARE_HOOK(rib_update, (struct route_node * rn, const char *reason),
451 (rn, reason))
452
453
454 extern void zebra_vty_init(void);
455
456 extern pid_t pid;
457
458 extern bool v6_rr_semantics;
459 #endif /*_ZEBRA_RIB_H */