]>
Commit | Line | Data |
---|---|---|
718e3744 | 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 | * | |
896014f4 DL |
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 | |
718e3744 | 20 | */ |
21 | ||
22 | #ifndef _ZEBRA_RIB_H | |
23 | #define _ZEBRA_RIB_H | |
24 | ||
dc9ffce8 | 25 | #include "zebra.h" |
224ccf29 | 26 | #include "memory.h" |
4f8ea50c | 27 | #include "hook.h" |
aa57abfb | 28 | #include "typesafe.h" |
c6ffe645 | 29 | #include "linklist.h" |
ec1a4283 | 30 | #include "prefix.h" |
9fd92e3c | 31 | #include "table.h" |
5adc2528 | 32 | #include "queue.h" |
fb018d25 | 33 | #include "nexthop.h" |
7ee30f28 | 34 | #include "nexthop_group.h" |
244a59d2 | 35 | #include "vrf.h" |
fb148af4 | 36 | #include "if.h" |
40c7bdb0 | 37 | #include "mpls.h" |
05737783 | 38 | #include "srcdest_table.h" |
5463ce26 | 39 | #include "zebra/zebra_nhg.h" |
ec1a4283 | 40 | |
51e94aa7 EDP |
41 | #ifdef __cplusplus |
42 | extern "C" { | |
43 | #endif | |
44 | ||
224ccf29 DL |
45 | DECLARE_MGROUP(ZEBRA); |
46 | ||
47 | DECLARE_MTYPE(RE); | |
48 | ||
f9215571 | 49 | enum rnh_type { RNH_NEXTHOP_TYPE, RNH_IMPORT_CHECK_TYPE }; |
aa57abfb | 50 | |
960b9a53 | 51 | PREDECL_LIST(rnh_list); |
aa57abfb DS |
52 | |
53 | /* Nexthop structure. */ | |
54 | struct rnh { | |
55 | uint8_t flags; | |
56 | ||
57 | #define ZEBRA_NHT_CONNECTED 0x1 | |
58 | #define ZEBRA_NHT_DELETED 0x2 | |
59 | #define ZEBRA_NHT_EXACT_MATCH 0x4 | |
60 | ||
61 | /* VRF identifier. */ | |
62 | vrf_id_t vrf_id; | |
63 | ||
64 | afi_t afi; | |
65 | ||
f9215571 | 66 | enum rnh_type type; |
aa57abfb DS |
67 | |
68 | uint32_t seqno; | |
69 | ||
70 | struct route_entry *state; | |
71 | struct prefix resolved_route; | |
72 | struct list *client_list; | |
73 | ||
74 | /* pseudowires dependent on this nh */ | |
75 | struct list *zebra_pseudowire_list; | |
76 | ||
77 | struct route_node *node; | |
78 | ||
79 | /* | |
80 | * if this has been filtered for the client | |
81 | */ | |
82 | int filtered[ZEBRA_ROUTE_MAX]; | |
83 | ||
84 | struct rnh_list_item rnh_list_item; | |
85 | }; | |
86 | ||
718e3744 | 87 | #define DISTANCE_INFINITY 255 |
7a4bb9c5 | 88 | #define ZEBRA_KERNEL_TABLE_MAX 252 /* support for no more than this rt tables */ |
718e3744 | 89 | |
960b9a53 | 90 | PREDECL_LIST(re_list); |
045207e2 | 91 | |
a29a6001 DS |
92 | struct opaque { |
93 | uint16_t length; | |
94 | uint8_t data[]; | |
95 | }; | |
96 | ||
d62a17ae | 97 | struct route_entry { |
98 | /* Link list. */ | |
045207e2 | 99 | struct re_list_item next; |
d62a17ae | 100 | |
0eb97b86 MS |
101 | /* Nexthop group, shared/refcounted, based on the nexthop(s) |
102 | * provided by the owner of the route | |
103 | */ | |
104 | struct nhg_hash_entry *nhe; | |
d62a17ae | 105 | |
0eb97b86 | 106 | /* Nexthop group from FIB (optional), reflecting what is actually |
4db01e79 MS |
107 | * installed in the FIB if that differs. The 'backup' group is used |
108 | * when backup nexthops are present in the route's nhg. | |
0eb97b86 | 109 | */ |
ee5e8a48 | 110 | struct nexthop_group fib_ng; |
4db01e79 | 111 | struct nexthop_group fib_backup_ng; |
ee5e8a48 | 112 | |
8e766379 SW |
113 | /* Nexthop group hash entry ID */ |
114 | uint32_t nhe_id; | |
f0cb8e16 | 115 | |
d62a17ae | 116 | /* Tag */ |
117 | route_tag_t tag; | |
118 | ||
119 | /* Uptime. */ | |
120 | time_t uptime; | |
121 | ||
1d48702e | 122 | /* Type of this route. */ |
d62a17ae | 123 | int type; |
124 | ||
d62a17ae | 125 | /* VRF identifier. */ |
126 | vrf_id_t vrf_id; | |
127 | ||
128 | /* Which routing table */ | |
129 | uint32_t table; | |
130 | ||
131 | /* Metric */ | |
d7c0a89a | 132 | uint32_t metric; |
d62a17ae | 133 | |
134 | /* MTU */ | |
d7c0a89a QY |
135 | uint32_t mtu; |
136 | uint32_t nexthop_mtu; | |
d62a17ae | 137 | |
d62a17ae | 138 | /* Flags of this route. |
139 | * This flag's definition is in lib/zebra.h ZEBRA_FLAG_* and is exposed | |
140 | * to clients via Zserv | |
141 | */ | |
d7c0a89a | 142 | uint32_t flags; |
d62a17ae | 143 | |
144 | /* RIB internal status */ | |
88f7ea31 | 145 | uint32_t status; |
f0f77c9a | 146 | #define ROUTE_ENTRY_REMOVED 0x1 |
88f7ea31 | 147 | /* The Route Entry has changed */ |
42fc558e | 148 | #define ROUTE_ENTRY_CHANGED 0x2 |
88f7ea31 | 149 | /* The Label has changed on the Route entry */ |
42fc558e | 150 | #define ROUTE_ENTRY_LABELS_CHANGED 0x4 |
88f7ea31 | 151 | /* Route is queued for Installation into the Data Plane */ |
42fc558e | 152 | #define ROUTE_ENTRY_QUEUED 0x8 |
88f7ea31 | 153 | /* Route is installed into the Data Plane */ |
42fc558e | 154 | #define ROUTE_ENTRY_INSTALLED 0x10 |
88f7ea31 | 155 | /* Route has Failed installation into the Data Plane in some manner */ |
42fc558e | 156 | #define ROUTE_ENTRY_FAILED 0x20 |
7483dcbe MS |
157 | /* Route has a 'fib' set of nexthops, probably because the installed set |
158 | * differs from the rib/normal set of nexthops. | |
159 | */ | |
160 | #define ROUTE_ENTRY_USE_FIB_NHG 0x40 | |
6d691129 | 161 | |
7cdb1a84 MS |
162 | /* Sequence value incremented for each dataplane operation */ |
163 | uint32_t dplane_sequence; | |
7a741326 DS |
164 | |
165 | /* Source protocol instance */ | |
166 | uint16_t instance; | |
167 | ||
168 | /* Distance. */ | |
169 | uint8_t distance; | |
a29a6001 DS |
170 | |
171 | struct opaque *opaque; | |
718e3744 | 172 | }; |
173 | ||
66cb1845 | 174 | #define RIB_SYSTEM_ROUTE(R) RSYSTEM_ROUTE((R)->type) |
84340a15 | 175 | |
66cb1845 | 176 | #define RIB_KERNEL_ROUTE(R) RKERNEL_ROUTE((R)->type) |
84340a15 | 177 | |
e96f9203 | 178 | /* meta-queue structure: |
e22e8001 | 179 | * sub-queue 0: nexthop group objects |
c17b2d5b DS |
180 | * sub-queue 1: connected |
181 | * sub-queue 2: kernel | |
182 | * sub-queue 3: static | |
183 | * sub-queue 4: RIP, RIPng, OSPF, OSPF6, IS-IS, EIGRP, NHRP | |
184 | * sub-queue 5: iBGP, eBGP | |
185 | * sub-queue 6: any other origin (if any) typically those that | |
186 | * don't generate routes | |
e96f9203 | 187 | */ |
c17b2d5b | 188 | #define MQ_SIZE 7 |
d62a17ae | 189 | struct meta_queue { |
190 | struct list *subq[MQ_SIZE]; | |
d7c0a89a | 191 | uint32_t size; /* sum of lengths of all subqueues */ |
e96f9203 DO |
192 | }; |
193 | ||
9fd92e3c AS |
194 | /* |
195 | * Structure that represents a single destination (prefix). | |
196 | */ | |
d62a17ae | 197 | typedef struct rib_dest_t_ { |
9fd92e3c | 198 | |
d62a17ae | 199 | /* |
200 | * Back pointer to the route node for this destination. This helps | |
201 | * us get to the prefix that this structure is for. | |
202 | */ | |
203 | struct route_node *rnode; | |
9fd92e3c | 204 | |
d62a17ae | 205 | /* |
206 | * Doubly-linked list of routes for this prefix. | |
207 | */ | |
045207e2 | 208 | struct re_list_head routes; |
9fd92e3c | 209 | |
5f7a4718 DS |
210 | struct route_entry *selected_fib; |
211 | ||
d62a17ae | 212 | /* |
213 | * Flags, see below. | |
214 | */ | |
d7c0a89a | 215 | uint32_t flags; |
9fd92e3c | 216 | |
699dae23 DS |
217 | /* |
218 | * The list of nht prefixes that have ended up | |
219 | * depending on this route node. | |
220 | * After route processing is returned from | |
221 | * the data plane we will run evaluate_rnh | |
222 | * on these prefixes. | |
223 | */ | |
aa57abfb | 224 | struct rnh_list_head nht; |
699dae23 | 225 | |
d62a17ae | 226 | /* |
227 | * Linkage to put dest on the FPM processing queue. | |
228 | */ | |
229 | TAILQ_ENTRY(rib_dest_t_) fpm_q_entries; | |
5adc2528 | 230 | |
9fd92e3c AS |
231 | } rib_dest_t; |
232 | ||
aa57abfb | 233 | DECLARE_LIST(rnh_list, struct rnh, rnh_list_item); |
045207e2 | 234 | DECLARE_LIST(re_list, struct route_entry, next); |
aa57abfb | 235 | |
9fd92e3c | 236 | #define RIB_ROUTE_QUEUED(x) (1 << (x)) |
1ca60f2c | 237 | // If MQ_SIZE is modified this value needs to be updated. |
e22e8001 | 238 | #define RIB_ROUTE_ANY_QUEUED 0x3F |
9fd92e3c AS |
239 | |
240 | /* | |
241 | * The maximum qindex that can be used. | |
242 | */ | |
243 | #define ZEBRA_MAX_QINDEX (MQ_SIZE - 1) | |
244 | ||
5adc2528 AS |
245 | /* |
246 | * This flag indicates that a given prefix has been 'advertised' to | |
247 | * the FPM to be installed in the forwarding plane. | |
248 | */ | |
249 | #define RIB_DEST_SENT_TO_FPM (1 << (ZEBRA_MAX_QINDEX + 1)) | |
250 | ||
251 | /* | |
252 | * This flag is set when we need to send an update to the FPM about a | |
253 | * dest. | |
254 | */ | |
255 | #define RIB_DEST_UPDATE_FPM (1 << (ZEBRA_MAX_QINDEX + 2)) | |
256 | ||
a1494c25 DS |
257 | #define RIB_DEST_UPDATE_LSPS (1 << (ZEBRA_MAX_QINDEX + 3)) |
258 | ||
9fd92e3c AS |
259 | /* |
260 | * Macro to iterate over each route for a destination (prefix). | |
261 | */ | |
d62a17ae | 262 | #define RE_DEST_FOREACH_ROUTE(dest, re) \ |
045207e2 DS |
263 | for ((re) = (dest) ? re_list_first(&((dest)->routes)) : NULL; (re); \ |
264 | (re) = re_list_next(&((dest)->routes), (re))) | |
9fd92e3c AS |
265 | |
266 | /* | |
267 | * Same as above, but allows the current node to be unlinked. | |
268 | */ | |
d62a17ae | 269 | #define RE_DEST_FOREACH_ROUTE_SAFE(dest, re, next) \ |
045207e2 DS |
270 | for ((re) = (dest) ? re_list_first(&((dest)->routes)) : NULL; \ |
271 | (re) && ((next) = re_list_next(&((dest)->routes), (re)), 1); \ | |
272 | (re) = (next)) | |
9fd92e3c | 273 | |
db856683 CS |
274 | #define RE_DEST_FIRST_ROUTE(dest, re) \ |
275 | ((re) = (dest) ? re_list_first(&((dest)->routes)) : NULL) | |
276 | ||
277 | #define RE_DEST_NEXT_ROUTE(dest, re) \ | |
278 | ((re) = (dest) ? re_list_next(&((dest)->routes), (re)) : NULL) | |
279 | ||
d62a17ae | 280 | #define RNODE_FOREACH_RE(rn, re) \ |
996c9314 | 281 | RE_DEST_FOREACH_ROUTE (rib_dest_from_rnode(rn), re) |
9fd92e3c | 282 | |
d62a17ae | 283 | #define RNODE_FOREACH_RE_SAFE(rn, re, next) \ |
996c9314 | 284 | RE_DEST_FOREACH_ROUTE_SAFE (rib_dest_from_rnode(rn), re, next) |
9fd92e3c | 285 | |
db856683 CS |
286 | #define RNODE_FIRST_RE(rn, re) RE_DEST_FIRST_ROUTE(rib_dest_from_rnode(rn), re) |
287 | ||
288 | #define RNODE_NEXT_RE(rn, re) RE_DEST_NEXT_ROUTE(rib_dest_from_rnode(rn), re) | |
289 | ||
d62a17ae | 290 | #if defined(HAVE_RTADV) |
cd80d74f | 291 | /* Structure which hold status of router advertisement. */ |
d62a17ae | 292 | struct rtadv { |
293 | int sock; | |
cd80d74f | 294 | |
d62a17ae | 295 | int adv_if_count; |
296 | int adv_msec_if_count; | |
cd80d74f | 297 | |
d62a17ae | 298 | struct thread *ra_read; |
299 | struct thread *ra_timer; | |
cd80d74f | 300 | }; |
8da4e946 | 301 | #endif /* HAVE_RTADV */ |
cd80d74f | 302 | |
1b5ed1b0 AS |
303 | /* |
304 | * rib_table_info_t | |
305 | * | |
306 | * Structure that is hung off of a route_table that holds information about | |
307 | * the table. | |
308 | */ | |
630d5962 | 309 | struct rib_table_info { |
1b5ed1b0 | 310 | |
d62a17ae | 311 | /* |
312 | * Back pointer to zebra_vrf. | |
313 | */ | |
314 | struct zebra_vrf *zvrf; | |
315 | afi_t afi; | |
316 | safi_t safi; | |
b62983cf | 317 | uint32_t table_id; |
630d5962 | 318 | }; |
1b5ed1b0 | 319 | |
4d5647d0 | 320 | enum rib_tables_iter_state { |
d62a17ae | 321 | RIB_TABLES_ITER_S_INIT, |
322 | RIB_TABLES_ITER_S_ITERATING, | |
323 | RIB_TABLES_ITER_S_DONE | |
4d5647d0 | 324 | }; |
0915bb0c AS |
325 | |
326 | /* | |
327 | * Structure that holds state for iterating over all tables in the | |
328 | * Routing Information Base. | |
329 | */ | |
d62a17ae | 330 | typedef struct rib_tables_iter_t_ { |
331 | vrf_id_t vrf_id; | |
332 | int afi_safi_ix; | |
0915bb0c | 333 | |
4d5647d0 | 334 | enum rib_tables_iter_state state; |
0915bb0c AS |
335 | } rib_tables_iter_t; |
336 | ||
1c848137 | 337 | /* Events/reasons triggering a RIB update. */ |
91e6f25b | 338 | enum rib_update_event { |
2a99ab95 | 339 | RIB_UPDATE_KERNEL, |
d62a17ae | 340 | RIB_UPDATE_RMAP_CHANGE, |
2a99ab95 SW |
341 | RIB_UPDATE_OTHER, |
342 | RIB_UPDATE_MAX | |
91e6f25b | 343 | }; |
1c848137 | 344 | |
d62a17ae | 345 | extern void route_entry_copy_nexthops(struct route_entry *re, |
346 | struct nexthop *nh); | |
cd7108ba EDP |
347 | int route_entry_update_nhe(struct route_entry *re, |
348 | struct nhg_hash_entry *new_nhghe); | |
f0f77c9a | 349 | |
1f655680 | 350 | /* NHG replace has happend, we have to update route_entry pointers to new one */ |
2e8db20d EDP |
351 | void rib_handle_nhg_replace(struct nhg_hash_entry *old_entry, |
352 | struct nhg_hash_entry *new_entry); | |
1f655680 | 353 | |
f0f77c9a | 354 | #define route_entry_dump(prefix, src, re) _route_entry_dump(__func__, prefix, src, re) |
072834ca DS |
355 | extern void _route_entry_dump(const char *func, union prefixconstptr pp, |
356 | union prefixconstptr src_pp, | |
357 | const struct route_entry *re); | |
4623d897 | 358 | |
072834ca DS |
359 | extern void rib_lookup_and_dump(struct prefix_ipv4 *p, vrf_id_t vrf_id); |
360 | extern void rib_lookup_and_pushup(struct prefix_ipv4 *p, vrf_id_t vrf_id); | |
f0f77c9a | 361 | |
dc95824a DO |
362 | #define ZEBRA_RIB_LOOKUP_ERROR -1 |
363 | #define ZEBRA_RIB_FOUND_EXACT 0 | |
364 | #define ZEBRA_RIB_FOUND_NOGATE 1 | |
365 | #define ZEBRA_RIB_FOUND_CONNECTED 2 | |
366 | #define ZEBRA_RIB_NOTFOUND 3 | |
367 | ||
d7c0a89a QY |
368 | extern int is_zebra_valid_kernel_table(uint32_t table_id); |
369 | extern int is_zebra_main_routing_table(uint32_t table_id); | |
86391e56 | 370 | extern int zebra_check_addr(const struct prefix *p); |
718e3744 | 371 | |
d62a17ae | 372 | extern void rib_delnode(struct route_node *rn, struct route_entry *re); |
0c555cc6 DS |
373 | extern void rib_install_kernel(struct route_node *rn, struct route_entry *re, |
374 | struct route_entry *old); | |
375 | extern void rib_uninstall_kernel(struct route_node *rn, struct route_entry *re); | |
28f6dde8 | 376 | |
d24af186 | 377 | /* NOTE: |
b4c034b0 | 378 | * All rib_add function will not just add prefix into RIB, but |
d24af186 | 379 | * also implicitly withdraw equal prefix of same type. */ |
4a7371e9 | 380 | extern int rib_add(afi_t afi, safi_t safi, vrf_id_t vrf_id, int type, |
acde7f6b | 381 | unsigned short instance, uint32_t flags, struct prefix *p, |
fd36be7e | 382 | struct prefix_ipv6 *src_p, const struct nexthop *nh, |
8032b717 SW |
383 | uint32_t nhe_id, uint32_t table_id, uint32_t metric, |
384 | uint32_t mtu, uint8_t distance, route_tag_t tag); | |
1d48702e MS |
385 | /* |
386 | * Multipath route apis. | |
387 | */ | |
072834ca | 388 | extern int rib_add_multipath(afi_t afi, safi_t safi, struct prefix *p, |
0eb97b86 MS |
389 | struct prefix_ipv6 *src_p, struct route_entry *re, |
390 | struct nexthop_group *ng); | |
1d48702e MS |
391 | extern int rib_add_multipath_nhe(afi_t afi, safi_t safi, struct prefix *p, |
392 | struct prefix_ipv6 *src_p, | |
393 | struct route_entry *re, | |
394 | struct nhg_hash_entry *nhe); | |
d62a17ae | 395 | |
396 | extern void rib_delete(afi_t afi, safi_t safi, vrf_id_t vrf_id, int type, | |
acde7f6b DS |
397 | unsigned short instance, uint32_t flags, |
398 | struct prefix *p, struct prefix_ipv6 *src_p, | |
399 | const struct nexthop *nh, uint32_t nhe_id, | |
400 | uint32_t table_id, uint32_t metric, uint8_t distance, | |
3ceae22b | 401 | bool fromkernel); |
d62a17ae | 402 | |
072834ca DS |
403 | extern struct route_entry *rib_match(afi_t afi, safi_t safi, vrf_id_t vrf_id, |
404 | union g_addr *addr, | |
d62a17ae | 405 | struct route_node **rn_out); |
406 | extern struct route_entry *rib_match_ipv4_multicast(vrf_id_t vrf_id, | |
407 | struct in_addr addr, | |
408 | struct route_node **rn_out); | |
409 | ||
072834ca DS |
410 | extern struct route_entry *rib_lookup_ipv4(struct prefix_ipv4 *p, |
411 | vrf_id_t vrf_id); | |
d62a17ae | 412 | |
91e6f25b | 413 | extern void rib_update(enum rib_update_event event); |
d5b8c216 | 414 | extern void rib_update_table(struct route_table *table, |
54aeba35 | 415 | enum rib_update_event event, int rtype); |
d4644d41 | 416 | extern int rib_sweep_route(struct thread *t); |
072834ca DS |
417 | extern void rib_sweep_table(struct route_table *table); |
418 | extern void rib_close_table(struct route_table *table); | |
d62a17ae | 419 | extern void rib_init(void); |
d7c0a89a QY |
420 | extern unsigned long rib_score_proto(uint8_t proto, unsigned short instance); |
421 | extern unsigned long rib_score_proto_table(uint8_t proto, | |
422 | unsigned short instance, | |
47a08aa9 | 423 | struct route_table *table); |
e22e8001 SW |
424 | |
425 | extern int rib_queue_add(struct route_node *rn); | |
426 | ||
427 | struct nhg_ctx; /* Forward declaration */ | |
428 | ||
429 | extern int rib_queue_nhg_add(struct nhg_ctx *ctx); | |
430 | ||
d62a17ae | 431 | extern void meta_queue_free(struct meta_queue *mq); |
432 | extern int zebra_rib_labeled_unicast(struct route_entry *re); | |
718e3744 | 433 | extern struct route_table *rib_table_ipv6; |
434 | ||
072834ca | 435 | extern void rib_unlink(struct route_node *rn, struct route_entry *re); |
d62a17ae | 436 | extern int rib_gc_dest(struct route_node *rn); |
437 | extern struct route_table *rib_tables_iter_next(rib_tables_iter_t *iter); | |
9fd92e3c | 438 | |
fd289fc8 | 439 | extern uint8_t route_distance(int type); |
40c7bdb0 | 440 | |
699dae23 DS |
441 | extern void zebra_rib_evaluate_rn_nexthops(struct route_node *rn, uint32_t seq); |
442 | ||
9fd92e3c AS |
443 | /* |
444 | * Inline functions. | |
445 | */ | |
446 | ||
1b5ed1b0 AS |
447 | /* |
448 | * rib_table_info | |
449 | */ | |
630d5962 | 450 | static inline struct rib_table_info *rib_table_info(struct route_table *table) |
1b5ed1b0 | 451 | { |
630d5962 | 452 | return (struct rib_table_info *)route_table_get_info(table); |
1b5ed1b0 AS |
453 | } |
454 | ||
9fd92e3c AS |
455 | /* |
456 | * rib_dest_from_rnode | |
457 | */ | |
d62a17ae | 458 | static inline rib_dest_t *rib_dest_from_rnode(struct route_node *rn) |
9fd92e3c | 459 | { |
d62a17ae | 460 | return (rib_dest_t *)rn->info; |
9fd92e3c AS |
461 | } |
462 | ||
463 | /* | |
464 | * rnode_to_ribs | |
465 | * | |
466 | * Returns a pointer to the list of routes corresponding to the given | |
467 | * route_node. | |
468 | */ | |
d62a17ae | 469 | static inline struct route_entry *rnode_to_ribs(struct route_node *rn) |
9fd92e3c | 470 | { |
d62a17ae | 471 | rib_dest_t *dest; |
9fd92e3c | 472 | |
d62a17ae | 473 | dest = rib_dest_from_rnode(rn); |
474 | if (!dest) | |
475 | return NULL; | |
9fd92e3c | 476 | |
045207e2 | 477 | return re_list_first(&dest->routes); |
9fd92e3c AS |
478 | } |
479 | ||
480 | /* | |
481 | * rib_dest_prefix | |
482 | */ | |
d62a17ae | 483 | static inline struct prefix *rib_dest_prefix(rib_dest_t *dest) |
9fd92e3c | 484 | { |
d62a17ae | 485 | return &dest->rnode->p; |
9fd92e3c AS |
486 | } |
487 | ||
488 | /* | |
489 | * rib_dest_af | |
490 | * | |
491 | * Returns the address family that the destination is for. | |
492 | */ | |
d7c0a89a | 493 | static inline uint8_t rib_dest_af(rib_dest_t *dest) |
9fd92e3c | 494 | { |
d62a17ae | 495 | return dest->rnode->p.family; |
9fd92e3c AS |
496 | } |
497 | ||
498 | /* | |
499 | * rib_dest_table | |
500 | */ | |
d62a17ae | 501 | static inline struct route_table *rib_dest_table(rib_dest_t *dest) |
9fd92e3c | 502 | { |
d62a17ae | 503 | return srcdest_rnode_table(dest->rnode); |
9fd92e3c AS |
504 | } |
505 | ||
1b5ed1b0 AS |
506 | /* |
507 | * rib_dest_vrf | |
508 | */ | |
d62a17ae | 509 | static inline struct zebra_vrf *rib_dest_vrf(rib_dest_t *dest) |
1b5ed1b0 | 510 | { |
d62a17ae | 511 | return rib_table_info(rib_dest_table(dest))->zvrf; |
1b5ed1b0 AS |
512 | } |
513 | ||
434434f7 DS |
514 | /* |
515 | * Create the rib_dest_t and attach it to the specified node | |
516 | */ | |
517 | extern rib_dest_t *zebra_rib_create_dest(struct route_node *rn); | |
518 | ||
0915bb0c AS |
519 | /* |
520 | * rib_tables_iter_init | |
521 | */ | |
d62a17ae | 522 | static inline void rib_tables_iter_init(rib_tables_iter_t *iter) |
0915bb0c AS |
523 | |
524 | { | |
d62a17ae | 525 | memset(iter, 0, sizeof(*iter)); |
526 | iter->state = RIB_TABLES_ITER_S_INIT; | |
0915bb0c AS |
527 | } |
528 | ||
529 | /* | |
530 | * rib_tables_iter_started | |
531 | * | |
2951a7a4 | 532 | * Returns true if this iterator has started iterating over the set of |
0915bb0c AS |
533 | * tables. |
534 | */ | |
d62a17ae | 535 | static inline int rib_tables_iter_started(rib_tables_iter_t *iter) |
0915bb0c | 536 | { |
d62a17ae | 537 | return iter->state != RIB_TABLES_ITER_S_INIT; |
0915bb0c AS |
538 | } |
539 | ||
540 | /* | |
541 | * rib_tables_iter_cleanup | |
542 | */ | |
d62a17ae | 543 | static inline void rib_tables_iter_cleanup(rib_tables_iter_t *iter) |
0915bb0c | 544 | { |
d62a17ae | 545 | iter->state = RIB_TABLES_ITER_S_DONE; |
0915bb0c AS |
546 | } |
547 | ||
d62a17ae | 548 | DECLARE_HOOK(rib_update, (struct route_node * rn, const char *reason), |
8451921b | 549 | (rn, reason)); |
4f8ea50c | 550 | |
ee5e8a48 | 551 | /* |
7483dcbe MS |
552 | * Access installed/fib nexthops, which may be a subset of the |
553 | * rib nexthops. | |
ee5e8a48 | 554 | */ |
4db01e79 | 555 | static inline struct nexthop_group *rib_get_fib_nhg(struct route_entry *re) |
ee5e8a48 | 556 | { |
7483dcbe MS |
557 | /* If the fib set is a subset of the active rib set, |
558 | * use the dedicated fib list. | |
559 | */ | |
560 | if (CHECK_FLAG(re->status, ROUTE_ENTRY_USE_FIB_NHG)) | |
ee5e8a48 MS |
561 | return &(re->fib_ng); |
562 | else | |
c415d895 | 563 | return &(re->nhe->nhg); |
ee5e8a48 | 564 | } |
05f7f5db | 565 | |
4db01e79 | 566 | /* |
7483dcbe MS |
567 | * Access backup nexthop-group that represents the installed backup nexthops; |
568 | * any installed backup will be on the fib list. | |
4db01e79 MS |
569 | */ |
570 | static inline struct nexthop_group *rib_get_fib_backup_nhg( | |
571 | struct route_entry *re) | |
572 | { | |
7483dcbe | 573 | return &(re->fib_backup_ng); |
4db01e79 MS |
574 | } |
575 | ||
05f7f5db | 576 | extern void zebra_vty_init(void); |
4060008b | 577 | |
05f7f5db DS |
578 | extern pid_t pid; |
579 | ||
6b093863 | 580 | extern bool v6_rr_semantics; |
51e94aa7 EDP |
581 | |
582 | #ifdef __cplusplus | |
583 | } | |
584 | #endif | |
585 | ||
718e3744 | 586 | #endif /*_ZEBRA_RIB_H */ |