]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_table.h
bgpd: simplify bgp instance name printing
[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"
67174041 27
d62a17ae 28struct bgp_table {
29 /* afi/safi of this table */
30 afi_t afi;
31 safi_t safi;
32
33 int lock;
34
35 struct route_table *route_table;
36 uint64_t version;
718e3744 37};
38
d62a17ae 39struct bgp_node {
40 /*
41 * CAUTION
42 *
43 * These fields must be the very first fields in this structure.
44 *
45 * @see bgp_node_to_rnode
46 * @see bgp_node_from_rnode
47 */
48 ROUTE_NODE_FIELDS
718e3744 49
d62a17ae 50 struct bgp_adj_out *adj_out;
718e3744 51
d62a17ae 52 struct bgp_adj_in *adj_in;
718e3744 53
d62a17ae 54 struct bgp_node *prn;
200df115 55
aac24838
JB
56 STAILQ_ENTRY(bgp_node) pq;
57
d62a17ae 58 mpls_label_t local_label;
cd1964ff 59
d62a17ae 60 uint64_t version;
d7c0a89a 61 uint8_t flags;
200df115 62#define BGP_NODE_PROCESS_SCHEDULED (1 << 0)
8ad7271d 63#define BGP_NODE_USER_CLEAR (1 << 1)
cd1964ff 64#define BGP_NODE_LABEL_CHANGED (1 << 2)
6cf48acc 65#define BGP_NODE_REGISTERED_FOR_LABEL (1 << 3)
718e3744 66};
67
28971c8c
AS
68/*
69 * bgp_table_iter_t
d62a17ae 70 *
28971c8c
AS
71 * Structure that holds state for iterating over a bgp table.
72 */
d62a17ae 73typedef struct bgp_table_iter_t_ {
74 struct bgp_table *table;
75 route_table_iter_t rt_iter;
28971c8c
AS
76} bgp_table_iter_t;
77
d62a17ae 78extern struct bgp_table *bgp_table_init(afi_t, safi_t);
79extern void bgp_table_lock(struct bgp_table *);
80extern void bgp_table_unlock(struct bgp_table *);
81extern void bgp_table_finish(struct bgp_table **);
67174041
AS
82
83
84/*
85 * bgp_node_from_rnode
86 *
87 * Returns the bgp_node structure corresponding to a route_node.
88 */
d62a17ae 89static inline struct bgp_node *bgp_node_from_rnode(struct route_node *rnode)
67174041 90{
d62a17ae 91 return (struct bgp_node *)rnode;
67174041
AS
92}
93
94/*
95 * bgp_node_to_rnode
96 *
97 * Returns the route_node structure corresponding to a bgp_node.
98 */
d62a17ae 99static inline struct route_node *bgp_node_to_rnode(struct bgp_node *node)
67174041 100{
d62a17ae 101 return (struct route_node *)node;
67174041
AS
102}
103
104/*
105 * bgp_node_table
106 *
107 * Returns the bgp_table that the given node is in.
108 */
d62a17ae 109static inline struct bgp_table *bgp_node_table(struct bgp_node *node)
67174041 110{
d62a17ae 111 return bgp_node_to_rnode(node)->table->info;
67174041
AS
112}
113
67174041
AS
114/*
115 * bgp_node_parent_nolock
116 *
117 * Gets the parent node of the given node without locking it.
118 */
d62a17ae 119static inline struct bgp_node *bgp_node_parent_nolock(struct bgp_node *node)
67174041 120{
d62a17ae 121 return bgp_node_from_rnode(node->parent);
67174041
AS
122}
123
124/*
125 * bgp_unlock_node
126 */
d62a17ae 127static inline void bgp_unlock_node(struct bgp_node *node)
67174041 128{
d62a17ae 129 route_unlock_node(bgp_node_to_rnode(node));
67174041
AS
130}
131
132/*
133 * bgp_table_top_nolock
134 *
135 * Gets the top node in the table without locking it.
136 *
137 * @see bgp_table_top
138 */
139static inline struct bgp_node *
d62a17ae 140bgp_table_top_nolock(const struct bgp_table *const table)
67174041 141{
d62a17ae 142 return bgp_node_from_rnode(table->route_table->top);
67174041
AS
143}
144
145/*
146 * bgp_table_top
147 */
148static inline struct bgp_node *
d62a17ae 149bgp_table_top(const struct bgp_table *const table)
67174041 150{
d62a17ae 151 return bgp_node_from_rnode(route_top(table->route_table));
67174041
AS
152}
153
154/*
155 * bgp_route_next
156 */
d62a17ae 157static inline struct bgp_node *bgp_route_next(struct bgp_node *node)
67174041 158{
d62a17ae 159 return bgp_node_from_rnode(route_next(bgp_node_to_rnode(node)));
67174041
AS
160}
161
162/*
163 * bgp_route_next_until
164 */
d62a17ae 165static inline struct bgp_node *bgp_route_next_until(struct bgp_node *node,
166 struct bgp_node *limit)
67174041 167{
d62a17ae 168 struct route_node *rnode;
67174041 169
d62a17ae 170 rnode = route_next_until(bgp_node_to_rnode(node),
171 bgp_node_to_rnode(limit));
172 return bgp_node_from_rnode(rnode);
67174041
AS
173}
174
175/*
176 * bgp_node_get
177 */
d62a17ae 178static inline struct bgp_node *bgp_node_get(struct bgp_table *const table,
179 struct prefix *p)
67174041 180{
d62a17ae 181 return bgp_node_from_rnode(route_node_get(table->route_table, p));
67174041
AS
182}
183
184/*
185 * bgp_node_lookup
186 */
187static inline struct bgp_node *
d62a17ae 188bgp_node_lookup(const struct bgp_table *const table, struct prefix *p)
67174041 189{
d62a17ae 190 return bgp_node_from_rnode(route_node_lookup(table->route_table, p));
67174041
AS
191}
192
193/*
194 * bgp_lock_node
195 */
d62a17ae 196static inline struct bgp_node *bgp_lock_node(struct bgp_node *node)
67174041 197{
d62a17ae 198 return bgp_node_from_rnode(route_lock_node(bgp_node_to_rnode(node)));
67174041
AS
199}
200
201/*
202 * bgp_node_match
203 */
d62a17ae 204static inline struct bgp_node *bgp_node_match(const struct bgp_table *table,
205 struct prefix *p)
67174041 206{
d62a17ae 207 return bgp_node_from_rnode(route_node_match(table->route_table, p));
67174041
AS
208}
209
210/*
211 * bgp_node_match_ipv4
212 */
213static inline struct bgp_node *
d62a17ae 214bgp_node_match_ipv4(const struct bgp_table *table, struct in_addr *addr)
67174041 215{
d62a17ae 216 return bgp_node_from_rnode(
217 route_node_match_ipv4(table->route_table, addr));
67174041
AS
218}
219
67174041
AS
220/*
221 * bgp_node_match_ipv6
222 */
223static inline struct bgp_node *
d62a17ae 224bgp_node_match_ipv6(const struct bgp_table *table, struct in6_addr *addr)
67174041 225{
d62a17ae 226 return bgp_node_from_rnode(
227 route_node_match_ipv6(table->route_table, addr));
67174041
AS
228}
229
d62a17ae 230static inline unsigned long bgp_table_count(const struct bgp_table *const table)
67174041 231{
d62a17ae 232 return route_table_count(table->route_table);
67174041
AS
233}
234
28971c8c
AS
235/*
236 * bgp_table_get_next
237 */
d62a17ae 238static inline struct bgp_node *bgp_table_get_next(const struct bgp_table *table,
239 struct prefix *p)
28971c8c 240{
d62a17ae 241 return bgp_node_from_rnode(route_table_get_next(table->route_table, p));
28971c8c
AS
242}
243
244/*
245 * bgp_table_iter_init
246 */
d62a17ae 247static inline void bgp_table_iter_init(bgp_table_iter_t *iter,
248 struct bgp_table *table)
28971c8c 249{
d62a17ae 250 bgp_table_lock(table);
251 iter->table = table;
252 route_table_iter_init(&iter->rt_iter, table->route_table);
28971c8c
AS
253}
254
255/*
256 * bgp_table_iter_next
257 */
d62a17ae 258static inline struct bgp_node *bgp_table_iter_next(bgp_table_iter_t *iter)
28971c8c 259{
d62a17ae 260 return bgp_node_from_rnode(route_table_iter_next(&iter->rt_iter));
28971c8c
AS
261}
262
263/*
264 * bgp_table_iter_cleanup
265 */
d62a17ae 266static inline void bgp_table_iter_cleanup(bgp_table_iter_t *iter)
28971c8c 267{
d62a17ae 268 route_table_iter_cleanup(&iter->rt_iter);
269 bgp_table_unlock(iter->table);
270 iter->table = NULL;
28971c8c
AS
271}
272
273/*
274 * bgp_table_iter_pause
275 */
d62a17ae 276static inline void bgp_table_iter_pause(bgp_table_iter_t *iter)
28971c8c 277{
d62a17ae 278 route_table_iter_pause(&iter->rt_iter);
28971c8c
AS
279}
280
281/*
282 * bgp_table_iter_is_done
283 */
d62a17ae 284static inline int bgp_table_iter_is_done(bgp_table_iter_t *iter)
28971c8c 285{
d62a17ae 286 return route_table_iter_is_done(&iter->rt_iter);
28971c8c
AS
287}
288
289/*
290 * bgp_table_iter_started
291 */
d62a17ae 292static inline int bgp_table_iter_started(bgp_table_iter_t *iter)
28971c8c 293{
d62a17ae 294 return route_table_iter_started(&iter->rt_iter);
28971c8c
AS
295}
296
3f9c7369
DS
297/* This would benefit from a real atomic operation...
298 * until then. */
d62a17ae 299static inline uint64_t bgp_table_next_version(struct bgp_table *table)
3f9c7369 300{
d62a17ae 301 return ++table->version;
3f9c7369
DS
302}
303
d62a17ae 304static inline uint64_t bgp_table_version(struct bgp_table *table)
3f9c7369 305{
d62a17ae 306 return table->version;
3f9c7369
DS
307}
308
00d252cb 309#endif /* _QUAGGA_BGP_TABLE_H */