]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_table.h
bgpd: Cleanup bgp_aggregate_set|get function names
[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
30 struct bgp_table {
31 /* table belongs to this instance */
32 struct bgp *bgp;
33
34 /* afi/safi of this table */
35 afi_t afi;
36 safi_t safi;
37
38 int lock;
39
40 struct route_table *route_table;
41 uint64_t version;
42 };
43
44 struct bgp_node {
45 /*
46 * CAUTION
47 *
48 * These fields must be the very first fields in this structure.
49 *
50 * @see bgp_node_to_rnode
51 * @see bgp_node_from_rnode
52 */
53 ROUTE_NODE_FIELDS
54
55 struct bgp_adj_out *adj_out;
56
57 struct bgp_adj_in *adj_in;
58
59 struct bgp_node *prn;
60
61 STAILQ_ENTRY(bgp_node) pq;
62
63 uint64_t version;
64
65 mpls_label_t local_label;
66
67 uint8_t flags;
68 #define BGP_NODE_PROCESS_SCHEDULED (1 << 0)
69 #define BGP_NODE_USER_CLEAR (1 << 1)
70 #define BGP_NODE_LABEL_CHANGED (1 << 2)
71 #define BGP_NODE_REGISTERED_FOR_LABEL (1 << 3)
72
73 struct bgp_addpath_node_data tx_addpath;
74 };
75
76 /*
77 * bgp_table_iter_t
78 *
79 * Structure that holds state for iterating over a bgp table.
80 */
81 typedef struct bgp_table_iter_t_ {
82 struct bgp_table *table;
83 route_table_iter_t rt_iter;
84 } bgp_table_iter_t;
85
86 extern struct bgp_table *bgp_table_init(struct bgp *bgp, afi_t, safi_t);
87 extern void bgp_table_lock(struct bgp_table *);
88 extern void bgp_table_unlock(struct bgp_table *);
89 extern void bgp_table_finish(struct bgp_table **);
90
91
92 /*
93 * bgp_node_from_rnode
94 *
95 * Returns the bgp_node structure corresponding to a route_node.
96 */
97 static inline struct bgp_node *bgp_node_from_rnode(struct route_node *rnode)
98 {
99 return (struct bgp_node *)rnode;
100 }
101
102 /*
103 * bgp_node_to_rnode
104 *
105 * Returns the route_node structure corresponding to a bgp_node.
106 */
107 static inline struct route_node *bgp_node_to_rnode(struct bgp_node *node)
108 {
109 return (struct route_node *)node;
110 }
111
112 /*
113 * bgp_node_table
114 *
115 * Returns the bgp_table that the given node is in.
116 */
117 static inline struct bgp_table *bgp_node_table(struct bgp_node *node)
118 {
119 return route_table_get_info(bgp_node_to_rnode(node)->table);
120 }
121
122 /*
123 * bgp_node_parent_nolock
124 *
125 * Gets the parent node of the given node without locking it.
126 */
127 static inline struct bgp_node *bgp_node_parent_nolock(struct bgp_node *node)
128 {
129 return bgp_node_from_rnode(node->parent);
130 }
131
132 /*
133 * bgp_unlock_node
134 */
135 static inline void bgp_unlock_node(struct bgp_node *node)
136 {
137 route_unlock_node(bgp_node_to_rnode(node));
138 }
139
140 /*
141 * bgp_table_top_nolock
142 *
143 * Gets the top node in the table without locking it.
144 *
145 * @see bgp_table_top
146 */
147 static inline struct bgp_node *
148 bgp_table_top_nolock(const struct bgp_table *const table)
149 {
150 return bgp_node_from_rnode(table->route_table->top);
151 }
152
153 /*
154 * bgp_table_top
155 */
156 static inline struct bgp_node *
157 bgp_table_top(const struct bgp_table *const table)
158 {
159 return bgp_node_from_rnode(route_top(table->route_table));
160 }
161
162 /*
163 * bgp_route_next
164 */
165 static inline struct bgp_node *bgp_route_next(struct bgp_node *node)
166 {
167 return bgp_node_from_rnode(route_next(bgp_node_to_rnode(node)));
168 }
169
170 /*
171 * bgp_route_next_until
172 */
173 static inline struct bgp_node *bgp_route_next_until(struct bgp_node *node,
174 struct bgp_node *limit)
175 {
176 struct route_node *rnode;
177
178 rnode = route_next_until(bgp_node_to_rnode(node),
179 bgp_node_to_rnode(limit));
180 return bgp_node_from_rnode(rnode);
181 }
182
183 /*
184 * bgp_node_get
185 */
186 static inline struct bgp_node *bgp_node_get(struct bgp_table *const table,
187 struct prefix *p)
188 {
189 return bgp_node_from_rnode(route_node_get(table->route_table, p));
190 }
191
192 /*
193 * bgp_node_lookup
194 */
195 static inline struct bgp_node *
196 bgp_node_lookup(const struct bgp_table *const table, struct prefix *p)
197 {
198 return bgp_node_from_rnode(route_node_lookup(table->route_table, p));
199 }
200
201 /*
202 * bgp_lock_node
203 */
204 static inline struct bgp_node *bgp_lock_node(struct bgp_node *node)
205 {
206 return bgp_node_from_rnode(route_lock_node(bgp_node_to_rnode(node)));
207 }
208
209 /*
210 * bgp_node_match
211 */
212 static inline struct bgp_node *bgp_node_match(const struct bgp_table *table,
213 struct prefix *p)
214 {
215 return bgp_node_from_rnode(route_node_match(table->route_table, p));
216 }
217
218 /*
219 * bgp_node_match_ipv4
220 */
221 static inline struct bgp_node *
222 bgp_node_match_ipv4(const struct bgp_table *table, struct in_addr *addr)
223 {
224 return bgp_node_from_rnode(
225 route_node_match_ipv4(table->route_table, addr));
226 }
227
228 /*
229 * bgp_node_match_ipv6
230 */
231 static inline struct bgp_node *
232 bgp_node_match_ipv6(const struct bgp_table *table, struct in6_addr *addr)
233 {
234 return bgp_node_from_rnode(
235 route_node_match_ipv6(table->route_table, addr));
236 }
237
238 static inline unsigned long bgp_table_count(const struct bgp_table *const table)
239 {
240 return route_table_count(table->route_table);
241 }
242
243 /*
244 * bgp_table_get_next
245 */
246 static inline struct bgp_node *bgp_table_get_next(const struct bgp_table *table,
247 struct prefix *p)
248 {
249 return bgp_node_from_rnode(route_table_get_next(table->route_table, p));
250 }
251
252 /*
253 * bgp_table_iter_init
254 */
255 static inline void bgp_table_iter_init(bgp_table_iter_t *iter,
256 struct bgp_table *table)
257 {
258 bgp_table_lock(table);
259 iter->table = table;
260 route_table_iter_init(&iter->rt_iter, table->route_table);
261 }
262
263 /*
264 * bgp_table_iter_next
265 */
266 static inline struct bgp_node *bgp_table_iter_next(bgp_table_iter_t *iter)
267 {
268 return bgp_node_from_rnode(route_table_iter_next(&iter->rt_iter));
269 }
270
271 /*
272 * bgp_table_iter_cleanup
273 */
274 static inline void bgp_table_iter_cleanup(bgp_table_iter_t *iter)
275 {
276 route_table_iter_cleanup(&iter->rt_iter);
277 bgp_table_unlock(iter->table);
278 iter->table = NULL;
279 }
280
281 /*
282 * bgp_table_iter_pause
283 */
284 static inline void bgp_table_iter_pause(bgp_table_iter_t *iter)
285 {
286 route_table_iter_pause(&iter->rt_iter);
287 }
288
289 /*
290 * bgp_table_iter_is_done
291 */
292 static inline int bgp_table_iter_is_done(bgp_table_iter_t *iter)
293 {
294 return route_table_iter_is_done(&iter->rt_iter);
295 }
296
297 /*
298 * bgp_table_iter_started
299 */
300 static inline int bgp_table_iter_started(bgp_table_iter_t *iter)
301 {
302 return route_table_iter_started(&iter->rt_iter);
303 }
304
305 /* This would benefit from a real atomic operation...
306 * until then. */
307 static inline uint64_t bgp_table_next_version(struct bgp_table *table)
308 {
309 return ++table->version;
310 }
311
312 static inline uint64_t bgp_table_version(struct bgp_table *table)
313 {
314 return table->version;
315 }
316
317 void bgp_table_range_lookup(const struct bgp_table *table, struct prefix *p,
318 uint8_t maxlen, struct list *matches);
319
320
321 static inline struct bgp_aggregate *
322 bgp_node_get_bgp_aggregate_info(struct bgp_node *node)
323 {
324 return node->info;
325 }
326
327 static inline void
328 bgp_node_set_bgp_aggregate_info(struct bgp_node *node,
329 struct bgp_aggregate *aggregate)
330 {
331 node->info = aggregate;
332 }
333
334 static inline struct bgp_distance *bgp_distance_get_node(struct bgp_node *node)
335 {
336 return node->info;
337 }
338
339 static inline void bgp_distance_set_node_info(struct bgp_node *node,
340 struct bgp_distance *distance)
341 {
342 node->info = distance;
343 }
344
345 static inline struct bgp_static *bgp_static_get_node_info(struct bgp_node *node)
346 {
347 return node->info;
348 }
349
350 static inline void bgp_static_set_node_info(struct bgp_node *node,
351 struct bgp_static *bgp_static)
352 {
353 node->info = bgp_static;
354 }
355
356 static inline struct bgp_connected_ref *
357 bgp_connected_get_node_info(struct bgp_node *node)
358 {
359 return node->info;
360 }
361
362 static inline void bgp_connected_set_node_info(struct bgp_node *node,
363 struct bgp_connected_ref *bc)
364 {
365 node->info = bc;
366 }
367
368 static inline struct bgp_nexthop_cache *
369 bgp_node_get_bgp_nexthop_info(struct bgp_node *node)
370 {
371 return node->info;
372 }
373
374 static inline void bgp_node_set_bgp_nexthop_info(struct bgp_node *node,
375 struct bgp_nexthop_cache *bnc)
376 {
377 node->info = bnc;
378 }
379
380 static inline struct bgp_path_info *
381 bgp_node_get_bgp_path_info(struct bgp_node *node)
382 {
383 return node->info;
384 }
385
386 static inline void bgp_node_set_bgp_path_info(struct bgp_node *node,
387 struct bgp_path_info *bi)
388 {
389 node->info = bi;
390 }
391
392 static inline struct bgp_table *
393 bgp_node_get_bgp_table_info(struct bgp_node *node)
394 {
395 return node->info;
396 }
397
398 static inline void bgp_node_set_bgp_table_info(struct bgp_node *node,
399 struct bgp_table *table)
400 {
401 node->info = table;
402 }
403
404 static inline bool bgp_node_has_bgp_path_info_data(struct bgp_node *node)
405 {
406 return !!node->info;
407 }
408
409 #endif /* _QUAGGA_BGP_TABLE_H */