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
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
21 #ifndef _QUAGGA_BGP_TABLE_H
22 #define _QUAGGA_BGP_TABLE_H
27 /* afi/safi of this table */
33 /* The owner of this 'bgp_table' structure. */
36 struct route_table
*route_table
;
44 * These fields must be the very first fields in this structure.
46 * @see bgp_node_to_rnode
47 * @see bgp_node_from_rnode
51 struct bgp_adj_out
*adj_out
;
53 struct bgp_adj_in
*adj_in
;
59 #define BGP_NODE_PROCESS_SCHEDULED (1 << 0)
60 #define BGP_NODE_USER_CLEAR (1 << 1)
66 * Structure that holds state for iterating over a bgp table.
68 typedef struct bgp_table_iter_t_
{
69 struct bgp_table
*table
;
70 route_table_iter_t rt_iter
;
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
**);
82 * Returns the bgp_node structure corresponding to a route_node.
84 static inline struct bgp_node
*bgp_node_from_rnode(struct route_node
*rnode
)
86 return (struct bgp_node
*)rnode
;
92 * Returns the route_node structure corresponding to a bgp_node.
94 static inline struct route_node
*bgp_node_to_rnode(struct bgp_node
*node
)
96 return (struct route_node
*)node
;
102 * Returns the bgp_table that the given node is in.
104 static inline struct bgp_table
*bgp_node_table(struct bgp_node
*node
)
106 return bgp_node_to_rnode(node
)->table
->info
;
110 * bgp_node_parent_nolock
112 * Gets the parent node of the given node without locking it.
114 static inline struct bgp_node
*bgp_node_parent_nolock(struct bgp_node
*node
)
116 return bgp_node_from_rnode(node
->parent
);
122 static inline void bgp_unlock_node(struct bgp_node
*node
)
124 route_unlock_node(bgp_node_to_rnode(node
));
128 * bgp_table_top_nolock
130 * Gets the top node in the table without locking it.
134 static inline struct bgp_node
*
135 bgp_table_top_nolock(const struct bgp_table
*const table
)
137 return bgp_node_from_rnode(table
->route_table
->top
);
143 static inline struct bgp_node
*
144 bgp_table_top(const struct bgp_table
*const table
)
146 return bgp_node_from_rnode(route_top(table
->route_table
));
152 static inline struct bgp_node
*bgp_route_next(struct bgp_node
*node
)
154 return bgp_node_from_rnode(route_next(bgp_node_to_rnode(node
)));
158 * bgp_route_next_until
160 static inline struct bgp_node
*bgp_route_next_until(struct bgp_node
*node
,
161 struct bgp_node
*limit
)
163 struct route_node
*rnode
;
165 rnode
= route_next_until(bgp_node_to_rnode(node
),
166 bgp_node_to_rnode(limit
));
167 return bgp_node_from_rnode(rnode
);
173 static inline struct bgp_node
*bgp_node_get(struct bgp_table
*const table
,
176 return bgp_node_from_rnode(route_node_get(table
->route_table
, p
));
182 static inline struct bgp_node
*
183 bgp_node_lookup(const struct bgp_table
*const table
, struct prefix
*p
)
185 return bgp_node_from_rnode(route_node_lookup(table
->route_table
, p
));
191 static inline struct bgp_node
*bgp_lock_node(struct bgp_node
*node
)
193 return bgp_node_from_rnode(route_lock_node(bgp_node_to_rnode(node
)));
199 static inline struct bgp_node
*bgp_node_match(const struct bgp_table
*table
,
202 return bgp_node_from_rnode(route_node_match(table
->route_table
, p
));
206 * bgp_node_match_ipv4
208 static inline struct bgp_node
*
209 bgp_node_match_ipv4(const struct bgp_table
*table
, struct in_addr
*addr
)
211 return bgp_node_from_rnode(
212 route_node_match_ipv4(table
->route_table
, addr
));
216 * bgp_node_match_ipv6
218 static inline struct bgp_node
*
219 bgp_node_match_ipv6(const struct bgp_table
*table
, struct in6_addr
*addr
)
221 return bgp_node_from_rnode(
222 route_node_match_ipv6(table
->route_table
, addr
));
225 static inline unsigned long bgp_table_count(const struct bgp_table
*const table
)
227 return route_table_count(table
->route_table
);
233 static inline struct bgp_node
*bgp_table_get_next(const struct bgp_table
*table
,
236 return bgp_node_from_rnode(route_table_get_next(table
->route_table
, p
));
240 * bgp_table_iter_init
242 static inline void bgp_table_iter_init(bgp_table_iter_t
*iter
,
243 struct bgp_table
*table
)
245 bgp_table_lock(table
);
247 route_table_iter_init(&iter
->rt_iter
, table
->route_table
);
251 * bgp_table_iter_next
253 static inline struct bgp_node
*bgp_table_iter_next(bgp_table_iter_t
*iter
)
255 return bgp_node_from_rnode(route_table_iter_next(&iter
->rt_iter
));
259 * bgp_table_iter_cleanup
261 static inline void bgp_table_iter_cleanup(bgp_table_iter_t
*iter
)
263 route_table_iter_cleanup(&iter
->rt_iter
);
264 bgp_table_unlock(iter
->table
);
269 * bgp_table_iter_pause
271 static inline void bgp_table_iter_pause(bgp_table_iter_t
*iter
)
273 route_table_iter_pause(&iter
->rt_iter
);
277 * bgp_table_iter_is_done
279 static inline int bgp_table_iter_is_done(bgp_table_iter_t
*iter
)
281 return route_table_iter_is_done(&iter
->rt_iter
);
285 * bgp_table_iter_started
287 static inline int bgp_table_iter_started(bgp_table_iter_t
*iter
)
289 return route_table_iter_started(&iter
->rt_iter
);
292 /* This would benefit from a real atomic operation...
294 static inline uint64_t bgp_table_next_version(struct bgp_table
*table
)
296 return ++table
->version
;
299 static inline uint64_t bgp_table_version(struct bgp_table
*table
)
301 return table
->version
;
304 #endif /* _QUAGGA_BGP_TABLE_H */