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