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