]> git.proxmox.com Git - mirror_frr.git/blame_incremental - bgpd/bgp_table.h
Merge pull request #3444 from donaldsharp/adj_stuff
[mirror_frr.git] / bgpd / bgp_table.h
... / ...
CommitLineData
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
31struct bgp_table {
32 /* table belongs to this instance */
33 struct bgp *bgp;
34
35 /* afi/safi of this table */
36 afi_t afi;
37 safi_t safi;
38
39 int lock;
40
41 struct route_table *route_table;
42 uint64_t version;
43};
44
45struct bgp_node {
46 /*
47 * CAUTION
48 *
49 * These fields must be the very first fields in this structure.
50 *
51 * @see bgp_node_to_rnode
52 * @see bgp_node_from_rnode
53 */
54 ROUTE_NODE_FIELDS
55
56 struct bgp_adj_out_rb adj_out;
57
58 struct bgp_adj_in *adj_in;
59
60 struct bgp_node *prn;
61
62 STAILQ_ENTRY(bgp_node) pq;
63
64 mpls_label_t local_label;
65
66 uint64_t version;
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 */
81typedef struct bgp_table_iter_t_ {
82 struct bgp_table *table;
83 route_table_iter_t rt_iter;
84} bgp_table_iter_t;
85
86extern struct bgp_table *bgp_table_init(struct bgp *bgp, afi_t, safi_t);
87extern void bgp_table_lock(struct bgp_table *);
88extern void bgp_table_unlock(struct bgp_table *);
89extern 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 */
97static 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 */
107static 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 */
117static 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 */
127static 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 */
135static 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 */
147static inline struct bgp_node *
148bgp_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 */
156static inline struct bgp_node *
157bgp_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 */
165static 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 */
173static 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 */
186static 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 */
195static inline struct bgp_node *
196bgp_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 */
204static 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 */
212static 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 */
221static inline struct bgp_node *
222bgp_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 */
231static inline struct bgp_node *
232bgp_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
238static 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 */
246static 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 */
255static 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 */
266static 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 */
274static 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 */
284static 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 */
292static 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 */
300static 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. */
307static inline uint64_t bgp_table_next_version(struct bgp_table *table)
308{
309 return ++table->version;
310}
311
312static inline uint64_t bgp_table_version(struct bgp_table *table)
313{
314 return table->version;
315}
316
317void bgp_table_range_lookup(const struct bgp_table *table, struct prefix *p,
318 uint8_t maxlen, struct list *matches);
319
320
321static inline struct bgp_aggregate *
322bgp_aggregate_get_node_info(struct bgp_node *node)
323{
324 return node->info;
325}
326
327static inline void bgp_aggregate_set_node_info(struct bgp_node *node,
328 struct bgp_aggregate *aggregate)
329{
330 node->info = aggregate;
331}
332
333static inline struct bgp_distance *bgp_distance_get_node(struct bgp_node *node)
334{
335 return node->info;
336}
337
338static inline void bgp_distance_set_node_info(struct bgp_node *node,
339 struct bgp_distance *distance)
340{
341 node->info = distance;
342}
343
344static inline struct bgp_static *bgp_static_get_node_info(struct bgp_node *node)
345{
346 return node->info;
347}
348
349static inline void bgp_static_set_node_info(struct bgp_node *node,
350 struct bgp_static *bgp_static)
351{
352 node->info = bgp_static;
353}
354
355static inline struct bgp_connected_ref *
356bgp_connected_get_node_info(struct bgp_node *node)
357{
358 return node->info;
359}
360
361static inline void bgp_connected_set_node_info(struct bgp_node *node,
362 struct bgp_connected_ref *bc)
363{
364 node->info = bc;
365}
366
367static inline struct bgp_nexthop_cache *
368bgp_nexthop_get_node_info(struct bgp_node *node)
369{
370 return node->info;
371}
372
373static inline void bgp_nexthop_set_node_info(struct bgp_node *node,
374 struct bgp_nexthop_cache *bnc)
375{
376 node->info = bnc;
377}
378
379#endif /* _QUAGGA_BGP_TABLE_H */