]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_table.h
bgpd: Replace bgp_flag_* to [UN]SET/CHECK_FLAG macros
[mirror_frr.git] / bgpd / bgp_table.h
1 /* BGP routing table
2 * Copyright (C) 1998, 2001 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #ifndef _QUAGGA_BGP_TABLE_H
22 #define _QUAGGA_BGP_TABLE_H
23
24 #include "mpls.h"
25 #include "table.h"
26 #include "queue.h"
27 #include "linklist.h"
28 #include "bgpd.h"
29 #include "bgp_advertise.h"
30
31 extern void bgp_delete_listnode(struct bgp_node *node);
32
33 struct bgp_table {
34 /* table belongs to this instance */
35 struct bgp *bgp;
36
37 /* afi/safi of this table */
38 afi_t afi;
39 safi_t safi;
40
41 int lock;
42
43 struct route_table *route_table;
44 uint64_t version;
45 };
46
47 enum bgp_path_selection_reason {
48 bgp_path_selection_none,
49 bgp_path_selection_first,
50 bgp_path_selection_evpn_sticky_mac,
51 bgp_path_selection_evpn_seq,
52 bgp_path_selection_evpn_lower_ip,
53 bgp_path_selection_weight,
54 bgp_path_selection_local_pref,
55 bgp_path_selection_local_route,
56 bgp_path_selection_confed_as_path,
57 bgp_path_selection_as_path,
58 bgp_path_selection_origin,
59 bgp_path_selection_med,
60 bgp_path_selection_peer,
61 bgp_path_selection_confed,
62 bgp_path_selection_igp_metric,
63 bgp_path_selection_older,
64 bgp_path_selection_router_id,
65 bgp_path_selection_cluster_length,
66 bgp_path_selection_stale,
67 bgp_path_selection_local_configured,
68 bgp_path_selection_neighbor_ip,
69 bgp_path_selection_default,
70 };
71
72 struct bgp_node {
73 /*
74 * CAUTION
75 *
76 * These fields must be the very first fields in this structure.
77 *
78 * @see bgp_node_to_rnode
79 * @see bgp_node_from_rnode
80 */
81 ROUTE_NODE_FIELDS
82
83 struct bgp_adj_out_rb adj_out;
84
85 struct bgp_adj_in *adj_in;
86
87 struct bgp_node *prn;
88
89 STAILQ_ENTRY(bgp_node) pq;
90
91 uint64_t version;
92
93 mpls_label_t local_label;
94
95 uint8_t flags;
96 #define BGP_NODE_PROCESS_SCHEDULED (1 << 0)
97 #define BGP_NODE_USER_CLEAR (1 << 1)
98 #define BGP_NODE_LABEL_CHANGED (1 << 2)
99 #define BGP_NODE_REGISTERED_FOR_LABEL (1 << 3)
100 #define BGP_NODE_SELECT_DEFER (1 << 4)
101 /* list node pointer */
102 struct listnode *rt_node;
103 struct bgp_addpath_node_data tx_addpath;
104
105 enum bgp_path_selection_reason reason;
106 };
107
108 /*
109 * bgp_table_iter_t
110 *
111 * Structure that holds state for iterating over a bgp table.
112 */
113 typedef struct bgp_table_iter_t_ {
114 struct bgp_table *table;
115 route_table_iter_t rt_iter;
116 } bgp_table_iter_t;
117
118 extern struct bgp_table *bgp_table_init(struct bgp *bgp, afi_t, safi_t);
119 extern void bgp_table_lock(struct bgp_table *);
120 extern void bgp_table_unlock(struct bgp_table *);
121 extern void bgp_table_finish(struct bgp_table **);
122
123
124 /*
125 * bgp_node_from_rnode
126 *
127 * Returns the bgp_node structure corresponding to a route_node.
128 */
129 static inline struct bgp_node *bgp_node_from_rnode(struct route_node *rnode)
130 {
131 return (struct bgp_node *)rnode;
132 }
133
134 /*
135 * bgp_node_to_rnode
136 *
137 * Returns the route_node structure corresponding to a bgp_node.
138 */
139 static inline struct route_node *bgp_node_to_rnode(struct bgp_node *node)
140 {
141 return (struct route_node *)node;
142 }
143
144 /*
145 * bgp_node_table
146 *
147 * Returns the bgp_table that the given node is in.
148 */
149 static inline struct bgp_table *bgp_node_table(struct bgp_node *node)
150 {
151 return route_table_get_info(bgp_node_to_rnode(node)->table);
152 }
153
154 /*
155 * bgp_node_parent_nolock
156 *
157 * Gets the parent node of the given node without locking it.
158 */
159 static inline struct bgp_node *bgp_node_parent_nolock(struct bgp_node *node)
160 {
161 return bgp_node_from_rnode(node->parent);
162 }
163
164 /*
165 * bgp_unlock_node
166 */
167 static inline void bgp_unlock_node(struct bgp_node *node)
168 {
169 bgp_delete_listnode(node);
170 route_unlock_node(bgp_node_to_rnode(node));
171 }
172
173 /*
174 * bgp_table_top_nolock
175 *
176 * Gets the top node in the table without locking it.
177 *
178 * @see bgp_table_top
179 */
180 static inline struct bgp_node *
181 bgp_table_top_nolock(const struct bgp_table *const table)
182 {
183 return bgp_node_from_rnode(table->route_table->top);
184 }
185
186 /*
187 * bgp_table_top
188 */
189 static inline struct bgp_node *
190 bgp_table_top(const struct bgp_table *const table)
191 {
192 return bgp_node_from_rnode(route_top(table->route_table));
193 }
194
195 /*
196 * bgp_route_next
197 */
198 static inline struct bgp_node *bgp_route_next(struct bgp_node *node)
199 {
200 return bgp_node_from_rnode(route_next(bgp_node_to_rnode(node)));
201 }
202
203 /*
204 * bgp_route_next_until
205 */
206 static inline struct bgp_node *bgp_route_next_until(struct bgp_node *node,
207 struct bgp_node *limit)
208 {
209 struct route_node *rnode;
210
211 rnode = route_next_until(bgp_node_to_rnode(node),
212 bgp_node_to_rnode(limit));
213 return bgp_node_from_rnode(rnode);
214 }
215
216 /*
217 * bgp_node_get
218 */
219 static inline struct bgp_node *bgp_node_get(struct bgp_table *const table,
220 struct prefix *p)
221 {
222 return bgp_node_from_rnode(route_node_get(table->route_table, p));
223 }
224
225 /*
226 * bgp_node_lookup
227 */
228 static inline struct bgp_node *
229 bgp_node_lookup(const struct bgp_table *const table, struct prefix *p)
230 {
231 return bgp_node_from_rnode(route_node_lookup(table->route_table, p));
232 }
233
234 /*
235 * bgp_lock_node
236 */
237 static inline struct bgp_node *bgp_lock_node(struct bgp_node *node)
238 {
239 return bgp_node_from_rnode(route_lock_node(bgp_node_to_rnode(node)));
240 }
241
242 /*
243 * bgp_node_match
244 */
245 static inline struct bgp_node *bgp_node_match(const struct bgp_table *table,
246 struct prefix *p)
247 {
248 return bgp_node_from_rnode(route_node_match(table->route_table, p));
249 }
250
251 /*
252 * bgp_node_match_ipv4
253 */
254 static inline struct bgp_node *
255 bgp_node_match_ipv4(const struct bgp_table *table, struct in_addr *addr)
256 {
257 return bgp_node_from_rnode(
258 route_node_match_ipv4(table->route_table, addr));
259 }
260
261 /*
262 * bgp_node_match_ipv6
263 */
264 static inline struct bgp_node *
265 bgp_node_match_ipv6(const struct bgp_table *table, struct in6_addr *addr)
266 {
267 return bgp_node_from_rnode(
268 route_node_match_ipv6(table->route_table, addr));
269 }
270
271 static inline unsigned long bgp_table_count(const struct bgp_table *const table)
272 {
273 return route_table_count(table->route_table);
274 }
275
276 /*
277 * bgp_table_get_next
278 */
279 static inline struct bgp_node *bgp_table_get_next(const struct bgp_table *table,
280 struct prefix *p)
281 {
282 return bgp_node_from_rnode(route_table_get_next(table->route_table, p));
283 }
284
285 /*
286 * bgp_table_iter_init
287 */
288 static inline void bgp_table_iter_init(bgp_table_iter_t *iter,
289 struct bgp_table *table)
290 {
291 bgp_table_lock(table);
292 iter->table = table;
293 route_table_iter_init(&iter->rt_iter, table->route_table);
294 }
295
296 /*
297 * bgp_table_iter_next
298 */
299 static inline struct bgp_node *bgp_table_iter_next(bgp_table_iter_t *iter)
300 {
301 return bgp_node_from_rnode(route_table_iter_next(&iter->rt_iter));
302 }
303
304 /*
305 * bgp_table_iter_cleanup
306 */
307 static inline void bgp_table_iter_cleanup(bgp_table_iter_t *iter)
308 {
309 route_table_iter_cleanup(&iter->rt_iter);
310 bgp_table_unlock(iter->table);
311 iter->table = NULL;
312 }
313
314 /*
315 * bgp_table_iter_pause
316 */
317 static inline void bgp_table_iter_pause(bgp_table_iter_t *iter)
318 {
319 route_table_iter_pause(&iter->rt_iter);
320 }
321
322 /*
323 * bgp_table_iter_is_done
324 */
325 static inline int bgp_table_iter_is_done(bgp_table_iter_t *iter)
326 {
327 return route_table_iter_is_done(&iter->rt_iter);
328 }
329
330 /*
331 * bgp_table_iter_started
332 */
333 static inline int bgp_table_iter_started(bgp_table_iter_t *iter)
334 {
335 return route_table_iter_started(&iter->rt_iter);
336 }
337
338 /* This would benefit from a real atomic operation...
339 * until then. */
340 static inline uint64_t bgp_table_next_version(struct bgp_table *table)
341 {
342 return ++table->version;
343 }
344
345 static inline uint64_t bgp_table_version(struct bgp_table *table)
346 {
347 return table->version;
348 }
349
350 void bgp_table_range_lookup(const struct bgp_table *table, struct prefix *p,
351 uint8_t maxlen, struct list *matches);
352
353
354 static inline struct bgp_aggregate *
355 bgp_node_get_bgp_aggregate_info(struct bgp_node *node)
356 {
357 return node->info;
358 }
359
360 static inline void
361 bgp_node_set_bgp_aggregate_info(struct bgp_node *node,
362 struct bgp_aggregate *aggregate)
363 {
364 node->info = aggregate;
365 }
366
367 static inline struct bgp_distance *
368 bgp_node_get_bgp_distance_info(struct bgp_node *node)
369 {
370 return node->info;
371 }
372
373 static inline void bgp_node_set_bgp_distance_info(struct bgp_node *node,
374 struct bgp_distance *distance)
375 {
376 node->info = distance;
377 }
378
379 static inline struct bgp_static *
380 bgp_node_get_bgp_static_info(struct bgp_node *node)
381 {
382 return node->info;
383 }
384
385 static inline void bgp_node_set_bgp_static_info(struct bgp_node *node,
386 struct bgp_static *bgp_static)
387 {
388 node->info = bgp_static;
389 }
390
391 static inline struct bgp_connected_ref *
392 bgp_node_get_bgp_connected_ref_info(struct bgp_node *node)
393 {
394 return node->info;
395 }
396
397 static inline void
398 bgp_node_set_bgp_connected_ref_info(struct bgp_node *node,
399 struct bgp_connected_ref *bc)
400 {
401 node->info = bc;
402 }
403
404 static inline struct bgp_nexthop_cache *
405 bgp_node_get_bgp_nexthop_info(struct bgp_node *node)
406 {
407 return node->info;
408 }
409
410 static inline void bgp_node_set_bgp_nexthop_info(struct bgp_node *node,
411 struct bgp_nexthop_cache *bnc)
412 {
413 node->info = bnc;
414 }
415
416 static inline struct bgp_path_info *
417 bgp_node_get_bgp_path_info(struct bgp_node *node)
418 {
419 return node->info;
420 }
421
422 static inline void bgp_node_set_bgp_path_info(struct bgp_node *node,
423 struct bgp_path_info *bi)
424 {
425 node->info = bi;
426 }
427
428 static inline struct bgp_table *
429 bgp_node_get_bgp_table_info(struct bgp_node *node)
430 {
431 return node->info;
432 }
433
434 static inline void bgp_node_set_bgp_table_info(struct bgp_node *node,
435 struct bgp_table *table)
436 {
437 node->info = table;
438 }
439
440 static inline bool bgp_node_has_bgp_path_info_data(struct bgp_node *node)
441 {
442 return !!node->info;
443 }
444
445 #endif /* _QUAGGA_BGP_TABLE_H */