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
36 /* afi/safi of this table */
42 /* The owner of this 'bgp_table' structure. */
45 struct route_table *route_table;
53 * These fields must be the very first fields in this structure.
55 * @see bgp_node_to_rnode
56 * @see bgp_node_from_rnode
60 struct bgp_adj_out *adj_out;
62 struct bgp_adj_in *adj_in;
67 #define BGP_NODE_PROCESS_SCHEDULED (1 << 0)
68 #define BGP_NODE_USER_CLEAR (1 << 1)
74 * Structure that holds state for iterating over a bgp table.
76 typedef struct bgp_table_iter_t_
78 struct bgp_table *table;
79 route_table_iter_t rt_iter;
82 extern struct bgp_table *bgp_table_init (afi_t, safi_t);
83 extern void bgp_table_lock (struct bgp_table *);
84 extern void bgp_table_unlock (struct bgp_table *);
85 extern void bgp_table_finish (struct bgp_table **);
91 * Returns the bgp_node structure corresponding to a route_node.
93 static inline struct bgp_node *
94 bgp_node_from_rnode (struct route_node *rnode)
96 return (struct bgp_node *) rnode;
102 * Returns the route_node structure corresponding to a bgp_node.
104 static inline struct route_node *
105 bgp_node_to_rnode (struct bgp_node *node)
107 return (struct route_node *) node;
113 * Returns the bgp_table that the given node is in.
115 static inline struct bgp_table *
116 bgp_node_table (struct bgp_node *node)
118 return bgp_node_to_rnode (node)->table->info;
122 * bgp_node_parent_nolock
124 * Gets the parent node of the given node without locking it.
126 static inline struct bgp_node *
127 bgp_node_parent_nolock (struct bgp_node *node)
129 return bgp_node_from_rnode (node->parent);
136 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 *
167 bgp_route_next (struct bgp_node *node)
169 return bgp_node_from_rnode (route_next (bgp_node_to_rnode (node)));
173 * bgp_route_next_until
175 static inline struct bgp_node *
176 bgp_route_next_until (struct bgp_node *node, struct bgp_node *limit)
178 struct route_node *rnode;
180 rnode = route_next_until (bgp_node_to_rnode (node),
181 bgp_node_to_rnode (limit));
182 return bgp_node_from_rnode (rnode);
188 static inline struct bgp_node *
189 bgp_node_get (struct bgp_table *const table, struct prefix *p)
191 return bgp_node_from_rnode (route_node_get (table->route_table, p));
197 static inline struct bgp_node *
198 bgp_node_lookup (const struct bgp_table *const table, struct prefix *p)
200 return bgp_node_from_rnode (route_node_lookup (table->route_table, p));
206 static inline struct bgp_node *
207 bgp_lock_node (struct bgp_node *node)
209 return bgp_node_from_rnode (route_lock_node (bgp_node_to_rnode (node)));
215 static inline struct bgp_node *
216 bgp_node_match (const struct bgp_table *table, struct prefix *p)
218 return bgp_node_from_rnode (route_node_match (table->route_table, p));
222 * bgp_node_match_ipv4
224 static inline struct bgp_node *
225 bgp_node_match_ipv4 (const struct bgp_table *table, struct in_addr *addr)
227 return bgp_node_from_rnode (route_node_match_ipv4 (table->route_table,
232 * bgp_node_match_ipv6
234 static inline struct bgp_node *
235 bgp_node_match_ipv6 (const struct bgp_table *table, struct in6_addr *addr)
237 return bgp_node_from_rnode (route_node_match_ipv6 (table->route_table,
241 static inline unsigned long
242 bgp_table_count (const struct bgp_table *const table)
244 return route_table_count (table->route_table);
250 static inline struct bgp_node *
251 bgp_table_get_next (const struct bgp_table *table, struct prefix *p)
253 return bgp_node_from_rnode (route_table_get_next (table->route_table, p));
257 * bgp_table_iter_init
260 bgp_table_iter_init (bgp_table_iter_t * iter, struct bgp_table *table)
262 bgp_table_lock (table);
264 route_table_iter_init (&iter->rt_iter, table->route_table);
268 * bgp_table_iter_next
270 static inline struct bgp_node *
271 bgp_table_iter_next (bgp_table_iter_t * iter)
273 return bgp_node_from_rnode (route_table_iter_next (&iter->rt_iter));
277 * bgp_table_iter_cleanup
280 bgp_table_iter_cleanup (bgp_table_iter_t * iter)
282 route_table_iter_cleanup (&iter->rt_iter);
283 bgp_table_unlock (iter->table);
288 * bgp_table_iter_pause
291 bgp_table_iter_pause (bgp_table_iter_t * iter)
293 route_table_iter_pause (&iter->rt_iter);
297 * bgp_table_iter_is_done
300 bgp_table_iter_is_done (bgp_table_iter_t * iter)
302 return route_table_iter_is_done (&iter->rt_iter);
306 * bgp_table_iter_started
309 bgp_table_iter_started (bgp_table_iter_t * iter)
311 return route_table_iter_started (&iter->rt_iter);
314 #endif /* _QUAGGA_BGP_TABLE_H */