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