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 /* afi/safi of this table */
35 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
;
57 mpls_label_t local_label
;
61 #define BGP_NODE_PROCESS_SCHEDULED (1 << 0)
62 #define BGP_NODE_USER_CLEAR (1 << 1)
63 #define BGP_NODE_LABEL_CHANGED (1 << 2)
64 #define BGP_NODE_REGISTERED_FOR_LABEL (1 << 3)
70 * Structure that holds state for iterating over a bgp table.
72 typedef struct bgp_table_iter_t_
74 struct bgp_table
*table
;
75 route_table_iter_t rt_iter
;
78 extern struct bgp_table
*bgp_table_init (afi_t
, safi_t
);
79 extern void bgp_table_lock (struct bgp_table
*);
80 extern void bgp_table_unlock (struct bgp_table
*);
81 extern void bgp_table_finish (struct bgp_table
**);
87 * Returns the bgp_node structure corresponding to a route_node.
89 static inline struct bgp_node
*
90 bgp_node_from_rnode (struct route_node
*rnode
)
92 return (struct bgp_node
*) rnode
;
98 * Returns the route_node structure corresponding to a bgp_node.
100 static inline struct route_node
*
101 bgp_node_to_rnode (struct bgp_node
*node
)
103 return (struct route_node
*) node
;
109 * Returns the bgp_table that the given node is in.
111 static inline struct bgp_table
*
112 bgp_node_table (struct bgp_node
*node
)
114 return bgp_node_to_rnode (node
)->table
->info
;
118 * bgp_node_parent_nolock
120 * Gets the parent node of the given node without locking it.
122 static inline struct bgp_node
*
123 bgp_node_parent_nolock (struct bgp_node
*node
)
125 return bgp_node_from_rnode (node
->parent
);
132 bgp_unlock_node (struct bgp_node
*node
)
134 route_unlock_node (bgp_node_to_rnode (node
));
138 * bgp_table_top_nolock
140 * Gets the top node in the table without locking it.
144 static inline struct bgp_node
*
145 bgp_table_top_nolock (const struct bgp_table
*const table
)
147 return bgp_node_from_rnode (table
->route_table
->top
);
153 static inline struct bgp_node
*
154 bgp_table_top (const struct bgp_table
*const table
)
156 return bgp_node_from_rnode (route_top (table
->route_table
));
162 static inline struct bgp_node
*
163 bgp_route_next (struct bgp_node
*node
)
165 return bgp_node_from_rnode (route_next (bgp_node_to_rnode (node
)));
169 * bgp_route_next_until
171 static inline struct bgp_node
*
172 bgp_route_next_until (struct bgp_node
*node
, struct bgp_node
*limit
)
174 struct route_node
*rnode
;
176 rnode
= route_next_until (bgp_node_to_rnode (node
),
177 bgp_node_to_rnode (limit
));
178 return bgp_node_from_rnode (rnode
);
184 static inline struct bgp_node
*
185 bgp_node_get (struct bgp_table
*const table
, struct prefix
*p
)
187 return bgp_node_from_rnode (route_node_get (table
->route_table
, p
));
193 static inline struct bgp_node
*
194 bgp_node_lookup (const struct bgp_table
*const table
, struct prefix
*p
)
196 return bgp_node_from_rnode (route_node_lookup (table
->route_table
, p
));
202 static inline struct bgp_node
*
203 bgp_lock_node (struct bgp_node
*node
)
205 return bgp_node_from_rnode (route_lock_node (bgp_node_to_rnode (node
)));
211 static inline struct bgp_node
*
212 bgp_node_match (const struct bgp_table
*table
, struct prefix
*p
)
214 return bgp_node_from_rnode (route_node_match (table
->route_table
, p
));
218 * bgp_node_match_ipv4
220 static inline struct bgp_node
*
221 bgp_node_match_ipv4 (const struct bgp_table
*table
, struct in_addr
*addr
)
223 return bgp_node_from_rnode (route_node_match_ipv4 (table
->route_table
,
228 * bgp_node_match_ipv6
230 static inline struct bgp_node
*
231 bgp_node_match_ipv6 (const struct bgp_table
*table
, struct in6_addr
*addr
)
233 return bgp_node_from_rnode (route_node_match_ipv6 (table
->route_table
,
237 static inline unsigned long
238 bgp_table_count (const struct bgp_table
*const table
)
240 return route_table_count (table
->route_table
);
246 static inline struct bgp_node
*
247 bgp_table_get_next (const struct bgp_table
*table
, struct prefix
*p
)
249 return bgp_node_from_rnode (route_table_get_next (table
->route_table
, p
));
253 * bgp_table_iter_init
256 bgp_table_iter_init (bgp_table_iter_t
* iter
, struct bgp_table
*table
)
258 bgp_table_lock (table
);
260 route_table_iter_init (&iter
->rt_iter
, table
->route_table
);
264 * bgp_table_iter_next
266 static inline struct bgp_node
*
267 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
276 bgp_table_iter_cleanup (bgp_table_iter_t
* iter
)
278 route_table_iter_cleanup (&iter
->rt_iter
);
279 bgp_table_unlock (iter
->table
);
284 * bgp_table_iter_pause
287 bgp_table_iter_pause (bgp_table_iter_t
* iter
)
289 route_table_iter_pause (&iter
->rt_iter
);
293 * bgp_table_iter_is_done
296 bgp_table_iter_is_done (bgp_table_iter_t
* iter
)
298 return route_table_iter_is_done (&iter
->rt_iter
);
302 * bgp_table_iter_started
305 bgp_table_iter_started (bgp_table_iter_t
* iter
)
307 return route_table_iter_started (&iter
->rt_iter
);
310 /* This would benefit from a real atomic operation...
312 static inline uint64_t
313 bgp_table_next_version (struct bgp_table
*table
)
315 return ++table
->version
;
318 static inline uint64_t
319 bgp_table_version (struct bgp_table
*table
)
321 return table
->version
;
324 #endif /* _QUAGGA_BGP_TABLE_H */