2 * Copyright (C) 1998, 2001 Kunihiro Ishiguro
4 * This file is part of GNU Zebra.
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
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.
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
21 #ifndef _QUAGGA_BGP_TABLE_H
22 #define _QUAGGA_BGP_TABLE_H
29 #include "bgp_advertise.h"
32 /* table belongs to this instance */
35 /* afi/safi of this table */
41 struct route_table
*route_table
;
49 * These fields must be the very first fields in this structure.
51 * @see bgp_node_to_rnode
52 * @see bgp_node_from_rnode
56 struct bgp_adj_out_rb adj_out
;
58 struct bgp_adj_in
*adj_in
;
62 STAILQ_ENTRY(bgp_node
) pq
;
66 mpls_label_t local_label
;
69 #define BGP_NODE_PROCESS_SCHEDULED (1 << 0)
70 #define BGP_NODE_USER_CLEAR (1 << 1)
71 #define BGP_NODE_LABEL_CHANGED (1 << 2)
72 #define BGP_NODE_REGISTERED_FOR_LABEL (1 << 3)
74 struct bgp_addpath_node_data tx_addpath
;
80 * Structure that holds state for iterating over a bgp table.
82 typedef struct bgp_table_iter_t_
{
83 struct bgp_table
*table
;
84 route_table_iter_t rt_iter
;
87 extern struct bgp_table
*bgp_table_init(struct bgp
*bgp
, afi_t
, safi_t
);
88 extern void bgp_table_lock(struct bgp_table
*);
89 extern void bgp_table_unlock(struct bgp_table
*);
90 extern void bgp_table_finish(struct bgp_table
**);
96 * Returns the bgp_node structure corresponding to a route_node.
98 static inline struct bgp_node
*bgp_node_from_rnode(struct route_node
*rnode
)
100 return (struct bgp_node
*)rnode
;
106 * Returns the route_node structure corresponding to a bgp_node.
108 static inline struct route_node
*bgp_node_to_rnode(struct bgp_node
*node
)
110 return (struct route_node
*)node
;
116 * Returns the bgp_table that the given node is in.
118 static inline struct bgp_table
*bgp_node_table(struct bgp_node
*node
)
120 return route_table_get_info(bgp_node_to_rnode(node
)->table
);
124 * bgp_node_parent_nolock
126 * Gets the parent node of the given node without locking it.
128 static inline struct bgp_node
*bgp_node_parent_nolock(struct bgp_node
*node
)
130 return bgp_node_from_rnode(node
->parent
);
136 static inline void bgp_unlock_node(struct bgp_node
*node
)
138 route_unlock_node(bgp_node_to_rnode(node
));
142 * bgp_table_top_nolock
144 * Gets the top node in the table without locking it.
148 static inline struct bgp_node
*
149 bgp_table_top_nolock(const struct bgp_table
*const table
)
151 return bgp_node_from_rnode(table
->route_table
->top
);
157 static inline struct bgp_node
*
158 bgp_table_top(const struct bgp_table
*const table
)
160 return bgp_node_from_rnode(route_top(table
->route_table
));
166 static inline struct bgp_node
*bgp_route_next(struct bgp_node
*node
)
168 return bgp_node_from_rnode(route_next(bgp_node_to_rnode(node
)));
172 * bgp_route_next_until
174 static inline struct bgp_node
*bgp_route_next_until(struct bgp_node
*node
,
175 struct bgp_node
*limit
)
177 struct route_node
*rnode
;
179 rnode
= route_next_until(bgp_node_to_rnode(node
),
180 bgp_node_to_rnode(limit
));
181 return bgp_node_from_rnode(rnode
);
187 static inline struct bgp_node
*bgp_node_get(struct bgp_table
*const table
,
190 return bgp_node_from_rnode(route_node_get(table
->route_table
, p
));
196 static inline struct bgp_node
*
197 bgp_node_lookup(const struct bgp_table
*const table
, struct prefix
*p
)
199 return bgp_node_from_rnode(route_node_lookup(table
->route_table
, p
));
205 static inline struct bgp_node
*bgp_lock_node(struct bgp_node
*node
)
207 return bgp_node_from_rnode(route_lock_node(bgp_node_to_rnode(node
)));
213 static inline struct bgp_node
*bgp_node_match(const struct bgp_table
*table
,
216 return bgp_node_from_rnode(route_node_match(table
->route_table
, p
));
220 * bgp_node_match_ipv4
222 static inline struct bgp_node
*
223 bgp_node_match_ipv4(const struct bgp_table
*table
, struct in_addr
*addr
)
225 return bgp_node_from_rnode(
226 route_node_match_ipv4(table
->route_table
, addr
));
230 * bgp_node_match_ipv6
232 static inline struct bgp_node
*
233 bgp_node_match_ipv6(const struct bgp_table
*table
, struct in6_addr
*addr
)
235 return bgp_node_from_rnode(
236 route_node_match_ipv6(table
->route_table
, addr
));
239 static inline unsigned long bgp_table_count(const struct bgp_table
*const table
)
241 return route_table_count(table
->route_table
);
247 static inline struct bgp_node
*bgp_table_get_next(const struct bgp_table
*table
,
250 return bgp_node_from_rnode(route_table_get_next(table
->route_table
, p
));
254 * bgp_table_iter_init
256 static inline void bgp_table_iter_init(bgp_table_iter_t
*iter
,
257 struct bgp_table
*table
)
259 bgp_table_lock(table
);
261 route_table_iter_init(&iter
->rt_iter
, table
->route_table
);
265 * bgp_table_iter_next
267 static inline struct bgp_node
*bgp_table_iter_next(bgp_table_iter_t
*iter
)
269 return bgp_node_from_rnode(route_table_iter_next(&iter
->rt_iter
));
273 * bgp_table_iter_cleanup
275 static inline void bgp_table_iter_cleanup(bgp_table_iter_t
*iter
)
277 route_table_iter_cleanup(&iter
->rt_iter
);
278 bgp_table_unlock(iter
->table
);
283 * bgp_table_iter_pause
285 static inline void bgp_table_iter_pause(bgp_table_iter_t
*iter
)
287 route_table_iter_pause(&iter
->rt_iter
);
291 * bgp_table_iter_is_done
293 static inline int bgp_table_iter_is_done(bgp_table_iter_t
*iter
)
295 return route_table_iter_is_done(&iter
->rt_iter
);
299 * bgp_table_iter_started
301 static inline int bgp_table_iter_started(bgp_table_iter_t
*iter
)
303 return route_table_iter_started(&iter
->rt_iter
);
306 /* This would benefit from a real atomic operation...
308 static inline uint64_t bgp_table_next_version(struct bgp_table
*table
)
310 return ++table
->version
;
313 static inline uint64_t bgp_table_version(struct bgp_table
*table
)
315 return table
->version
;
318 void bgp_table_range_lookup(const struct bgp_table
*table
, struct prefix
*p
,
319 uint8_t maxlen
, struct list
*matches
);
322 static inline struct bgp_aggregate
*
323 bgp_node_get_bgp_aggregate_info(struct bgp_node
*node
)
329 bgp_node_set_bgp_aggregate_info(struct bgp_node
*node
,
330 struct bgp_aggregate
*aggregate
)
332 node
->info
= aggregate
;
335 static inline struct bgp_distance
*
336 bgp_node_get_bgp_distance_info(struct bgp_node
*node
)
341 static inline void bgp_node_set_bgp_distance_info(struct bgp_node
*node
,
342 struct bgp_distance
*distance
)
344 node
->info
= distance
;
347 static inline struct bgp_static
*
348 bgp_node_get_bgp_static_info(struct bgp_node
*node
)
353 static inline void bgp_node_set_bgp_static_info(struct bgp_node
*node
,
354 struct bgp_static
*bgp_static
)
356 node
->info
= bgp_static
;
359 static inline struct bgp_connected_ref
*
360 bgp_node_get_bgp_connected_ref_info(struct bgp_node
*node
)
366 bgp_node_set_bgp_connected_ref_info(struct bgp_node
*node
,
367 struct bgp_connected_ref
*bc
)
372 static inline struct bgp_nexthop_cache
*
373 bgp_node_get_bgp_nexthop_info(struct bgp_node
*node
)
378 static inline void bgp_node_set_bgp_nexthop_info(struct bgp_node
*node
,
379 struct bgp_nexthop_cache
*bnc
)
384 static inline struct bgp_path_info
*
385 bgp_node_get_bgp_path_info(struct bgp_node
*node
)
390 static inline void bgp_node_set_bgp_path_info(struct bgp_node
*node
,
391 struct bgp_path_info
*bi
)
396 static inline struct bgp_table
*
397 bgp_node_get_bgp_table_info(struct bgp_node
*node
)
402 static inline void bgp_node_set_bgp_table_info(struct bgp_node
*node
,
403 struct bgp_table
*table
)
408 static inline bool bgp_node_has_bgp_path_info_data(struct bgp_node
*node
)
413 #endif /* _QUAGGA_BGP_TABLE_H */