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