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