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