blob: 8e963aeeeb8456849d1d2859cc8e5d04783a6cda [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* BGP routing table
2 Copyright (C) 1998, 2001 Kunihiro Ishiguro
3
4This file is part of GNU Zebra.
5
6GNU Zebra is free software; you can redistribute it and/or modify it
7under the terms of the GNU General Public License as published by the
8Free Software Foundation; either version 2, or (at your option) any
9later version.
10
11GNU Zebra is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Zebra; see the file COPYING. If not, write to the Free
18Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1902111-1307, USA. */
20
paul00d252c2005-05-23 14:19:54 +000021#ifndef _QUAGGA_BGP_TABLE_H
22#define _QUAGGA_BGP_TABLE_H
23
Avneesh Sachdev67174042012-08-17 08:19:49 -070024#include "table.h"
25
paulfee0f4c2004-09-13 05:12:46 +000026typedef enum
27{
28 BGP_TABLE_MAIN,
29 BGP_TABLE_RSCLIENT,
30} bgp_table_t;
31
paul718e3742002-12-13 20:15:29 +000032struct bgp_table
33{
paulfee0f4c2004-09-13 05:12:46 +000034 bgp_table_t type;
Paul Jakma64e580a2006-02-21 01:09:01 +000035
36 /* afi/safi of this table */
37 afi_t afi;
38 safi_t safi;
39
Chris Caputo228da422009-07-18 05:44:03 +000040 int lock;
41
paulfee0f4c2004-09-13 05:12:46 +000042 /* The owner of this 'bgp_table' structure. */
Chris Caputo228da422009-07-18 05:44:03 +000043 struct peer *owner;
paulfee0f4c2004-09-13 05:12:46 +000044
Avneesh Sachdev67174042012-08-17 08:19:49 -070045 struct route_table *route_table;
paul718e3742002-12-13 20:15:29 +000046};
47
48struct bgp_node
49{
Avneesh Sachdev67174042012-08-17 08:19:49 -070050 /*
51 * CAUTION
52 *
53 * These fields must be the very first fields in this structure.
54 *
55 * @see bgp_node_to_rnode
56 * @see bgp_node_from_rnode
57 */
David Lamparterb7d50212015-03-03 08:53:18 +010058 ROUTE_NODE_FIELDS
paul718e3742002-12-13 20:15:29 +000059
60 struct bgp_adj_out *adj_out;
61
62 struct bgp_adj_in *adj_in;
63
paul718e3742002-12-13 20:15:29 +000064 struct bgp_node *prn;
paul200df112005-06-01 11:17:05 +000065
66 u_char flags;
67#define BGP_NODE_PROCESS_SCHEDULED (1 << 0)
Daniel Walton325fcfb2015-05-19 17:58:10 -070068#define BGP_NODE_USER_CLEAR (1 << 1)
paul718e3742002-12-13 20:15:29 +000069};
70
Avneesh Sachdev28971c82012-08-17 08:19:50 -070071/*
72 * bgp_table_iter_t
73 *
74 * Structure that holds state for iterating over a bgp table.
75 */
76typedef struct bgp_table_iter_t_
77{
78 struct bgp_table *table;
79 route_table_iter_t rt_iter;
80} bgp_table_iter_t;
81
Paul Jakma64e580a2006-02-21 01:09:01 +000082extern struct bgp_table *bgp_table_init (afi_t, safi_t);
Chris Caputo228da422009-07-18 05:44:03 +000083extern void bgp_table_lock (struct bgp_table *);
84extern void bgp_table_unlock (struct bgp_table *);
Paul Jakmab608d5b2008-07-02 02:12:07 +000085extern void bgp_table_finish (struct bgp_table **);
Avneesh Sachdev67174042012-08-17 08:19:49 -070086
87
88/*
89 * bgp_node_from_rnode
90 *
91 * Returns the bgp_node structure corresponding to a route_node.
92 */
93static inline struct bgp_node *
94bgp_node_from_rnode (struct route_node *rnode)
95{
96 return (struct bgp_node *) rnode;
97}
98
99/*
100 * bgp_node_to_rnode
101 *
102 * Returns the route_node structure corresponding to a bgp_node.
103 */
104static inline struct route_node *
105bgp_node_to_rnode (struct bgp_node *node)
106{
107 return (struct route_node *) node;
108}
109
110/*
111 * bgp_node_table
112 *
113 * Returns the bgp_table that the given node is in.
114 */
115static inline struct bgp_table *
116bgp_node_table (struct bgp_node *node)
117{
118 return bgp_node_to_rnode (node)->table->info;
119}
120
121/*
Avneesh Sachdev67174042012-08-17 08:19:49 -0700122 * bgp_node_parent_nolock
123 *
124 * Gets the parent node of the given node without locking it.
125 */
126static inline struct bgp_node *
127bgp_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
136bgp_unlock_node (struct bgp_node *node)
137{
138 route_unlock_node (bgp_node_to_rnode (node));
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 *
149bgp_table_top_nolock (const struct bgp_table *const table)
150{
151 return bgp_node_from_rnode (table->route_table->top);
152}
153
154/*
155 * bgp_table_top
156 */
157static inline struct bgp_node *
158bgp_table_top (const struct bgp_table *const table)
159{
160 return bgp_node_from_rnode (route_top (table->route_table));
161}
162
163/*
164 * bgp_route_next
165 */
166static inline struct bgp_node *
167bgp_route_next (struct bgp_node *node)
168{
169 return bgp_node_from_rnode (route_next (bgp_node_to_rnode (node)));
170}
171
172/*
173 * bgp_route_next_until
174 */
175static inline struct bgp_node *
176bgp_route_next_until (struct bgp_node *node, struct bgp_node *limit)
177{
178 struct route_node *rnode;
179
180 rnode = route_next_until (bgp_node_to_rnode (node),
181 bgp_node_to_rnode (limit));
182 return bgp_node_from_rnode (rnode);
183}
184
185/*
186 * bgp_node_get
187 */
188static inline struct bgp_node *
189bgp_node_get (struct bgp_table *const table, struct prefix *p)
190{
191 return bgp_node_from_rnode (route_node_get (table->route_table, p));
192}
193
194/*
195 * bgp_node_lookup
196 */
197static inline struct bgp_node *
198bgp_node_lookup (const struct bgp_table *const table, struct prefix *p)
199{
200 return bgp_node_from_rnode (route_node_lookup (table->route_table, p));
201}
202
203/*
204 * bgp_lock_node
205 */
206static inline struct bgp_node *
207bgp_lock_node (struct bgp_node *node)
208{
209 return bgp_node_from_rnode (route_lock_node (bgp_node_to_rnode (node)));
210}
211
212/*
213 * bgp_node_match
214 */
215static inline struct bgp_node *
216bgp_node_match (const struct bgp_table *table, struct prefix *p)
217{
218 return bgp_node_from_rnode (route_node_match (table->route_table, p));
219}
220
221/*
222 * bgp_node_match_ipv4
223 */
224static inline struct bgp_node *
225bgp_node_match_ipv4 (const struct bgp_table *table, struct in_addr *addr)
226{
227 return bgp_node_from_rnode (route_node_match_ipv4 (table->route_table,
228 addr));
229}
230
Avneesh Sachdev67174042012-08-17 08:19:49 -0700231/*
232 * bgp_node_match_ipv6
233 */
234static inline struct bgp_node *
235bgp_node_match_ipv6 (const struct bgp_table *table, struct in6_addr *addr)
236{
237 return bgp_node_from_rnode (route_node_match_ipv6 (table->route_table,
238 addr));
239}
240
Avneesh Sachdev67174042012-08-17 08:19:49 -0700241static inline unsigned long
242bgp_table_count (const struct bgp_table *const table)
243{
244 return route_table_count (table->route_table);
245}
246
Avneesh Sachdev28971c82012-08-17 08:19:50 -0700247/*
248 * bgp_table_get_next
249 */
250static inline struct bgp_node *
251bgp_table_get_next (const struct bgp_table *table, struct prefix *p)
252{
253 return bgp_node_from_rnode (route_table_get_next (table->route_table, p));
254}
255
256/*
257 * bgp_table_iter_init
258 */
259static inline void
260bgp_table_iter_init (bgp_table_iter_t * iter, struct bgp_table *table)
261{
262 bgp_table_lock (table);
263 iter->table = table;
264 route_table_iter_init (&iter->rt_iter, table->route_table);
265}
266
267/*
268 * bgp_table_iter_next
269 */
270static inline struct bgp_node *
271bgp_table_iter_next (bgp_table_iter_t * iter)
272{
273 return bgp_node_from_rnode (route_table_iter_next (&iter->rt_iter));
274}
275
276/*
277 * bgp_table_iter_cleanup
278 */
279static inline void
280bgp_table_iter_cleanup (bgp_table_iter_t * iter)
281{
282 route_table_iter_cleanup (&iter->rt_iter);
283 bgp_table_unlock (iter->table);
284 iter->table = NULL;
285}
286
287/*
288 * bgp_table_iter_pause
289 */
290static inline void
291bgp_table_iter_pause (bgp_table_iter_t * iter)
292{
293 route_table_iter_pause (&iter->rt_iter);
294}
295
296/*
297 * bgp_table_iter_is_done
298 */
299static inline int
300bgp_table_iter_is_done (bgp_table_iter_t * iter)
301{
302 return route_table_iter_is_done (&iter->rt_iter);
303}
304
305/*
306 * bgp_table_iter_started
307 */
308static inline int
309bgp_table_iter_started (bgp_table_iter_t * iter)
310{
311 return route_table_iter_started (&iter->rt_iter);
312}
313
paul00d252c2005-05-23 14:19:54 +0000314#endif /* _QUAGGA_BGP_TABLE_H */