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