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
31 /* table belongs to this instance */
34 /* afi/safi of this table */
40 struct route_table
*route_table
;
48 * These fields must be the very first fields in this structure.
50 * @see bgp_node_to_rnode
51 * @see bgp_node_from_rnode
55 struct bgp_adj_out
*adj_out
;
57 struct bgp_adj_in
*adj_in
;
61 STAILQ_ENTRY(bgp_node
) pq
;
63 mpls_label_t local_label
;
67 #define BGP_NODE_PROCESS_SCHEDULED (1 << 0)
68 #define BGP_NODE_USER_CLEAR (1 << 1)
69 #define BGP_NODE_LABEL_CHANGED (1 << 2)
70 #define BGP_NODE_REGISTERED_FOR_LABEL (1 << 3)
72 struct bgp_addpath_node_data tx_addpath
;
78 * Structure that holds state for iterating over a bgp table.
80 typedef struct bgp_table_iter_t_
{
81 struct bgp_table
*table
;
82 route_table_iter_t rt_iter
;
85 extern struct bgp_table
*bgp_table_init(struct bgp
*bgp
, afi_t
, safi_t
);
86 extern void bgp_table_lock(struct bgp_table
*);
87 extern void bgp_table_unlock(struct bgp_table
*);
88 extern void bgp_table_finish(struct bgp_table
**);
94 * Returns the bgp_node structure corresponding to a route_node.
96 static inline struct bgp_node
*bgp_node_from_rnode(struct route_node
*rnode
)
98 return (struct bgp_node
*)rnode
;
104 * Returns the route_node structure corresponding to a bgp_node.
106 static inline struct route_node
*bgp_node_to_rnode(struct bgp_node
*node
)
108 return (struct route_node
*)node
;
114 * Returns the bgp_table that the given node is in.
116 static inline struct bgp_table
*bgp_node_table(struct bgp_node
*node
)
118 return route_table_get_info(bgp_node_to_rnode(node
)->table
);
122 * bgp_node_parent_nolock
124 * Gets the parent node of the given node without locking it.
126 static inline struct bgp_node
*bgp_node_parent_nolock(struct bgp_node
*node
)
128 return bgp_node_from_rnode(node
->parent
);
134 static inline void bgp_unlock_node(struct bgp_node
*node
)
136 route_unlock_node(bgp_node_to_rnode(node
));
140 * bgp_table_top_nolock
142 * Gets the top node in the table without locking it.
146 static inline struct bgp_node
*
147 bgp_table_top_nolock(const struct bgp_table
*const table
)
149 return bgp_node_from_rnode(table
->route_table
->top
);
155 static inline struct bgp_node
*
156 bgp_table_top(const struct bgp_table
*const table
)
158 return bgp_node_from_rnode(route_top(table
->route_table
));
164 static inline struct bgp_node
*bgp_route_next(struct bgp_node
*node
)
166 return bgp_node_from_rnode(route_next(bgp_node_to_rnode(node
)));
170 * bgp_route_next_until
172 static inline struct bgp_node
*bgp_route_next_until(struct bgp_node
*node
,
173 struct bgp_node
*limit
)
175 struct route_node
*rnode
;
177 rnode
= route_next_until(bgp_node_to_rnode(node
),
178 bgp_node_to_rnode(limit
));
179 return bgp_node_from_rnode(rnode
);
185 static inline struct bgp_node
*bgp_node_get(struct bgp_table
*const table
,
188 return bgp_node_from_rnode(route_node_get(table
->route_table
, p
));
194 static inline struct bgp_node
*
195 bgp_node_lookup(const struct bgp_table
*const table
, struct prefix
*p
)
197 return bgp_node_from_rnode(route_node_lookup(table
->route_table
, p
));
203 static inline struct bgp_node
*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
*bgp_node_match(const struct bgp_table
*table
,
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(
224 route_node_match_ipv4(table
->route_table
, addr
));
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(
234 route_node_match_ipv6(table
->route_table
, addr
));
237 static inline unsigned long bgp_table_count(const struct bgp_table
*const table
)
239 return route_table_count(table
->route_table
);
245 static inline struct bgp_node
*bgp_table_get_next(const struct bgp_table
*table
,
248 return bgp_node_from_rnode(route_table_get_next(table
->route_table
, p
));
252 * bgp_table_iter_init
254 static inline void bgp_table_iter_init(bgp_table_iter_t
*iter
,
255 struct bgp_table
*table
)
257 bgp_table_lock(table
);
259 route_table_iter_init(&iter
->rt_iter
, table
->route_table
);
263 * bgp_table_iter_next
265 static inline struct bgp_node
*bgp_table_iter_next(bgp_table_iter_t
*iter
)
267 return bgp_node_from_rnode(route_table_iter_next(&iter
->rt_iter
));
271 * bgp_table_iter_cleanup
273 static inline void bgp_table_iter_cleanup(bgp_table_iter_t
*iter
)
275 route_table_iter_cleanup(&iter
->rt_iter
);
276 bgp_table_unlock(iter
->table
);
281 * bgp_table_iter_pause
283 static inline void bgp_table_iter_pause(bgp_table_iter_t
*iter
)
285 route_table_iter_pause(&iter
->rt_iter
);
289 * bgp_table_iter_is_done
291 static inline int bgp_table_iter_is_done(bgp_table_iter_t
*iter
)
293 return route_table_iter_is_done(&iter
->rt_iter
);
297 * bgp_table_iter_started
299 static inline int bgp_table_iter_started(bgp_table_iter_t
*iter
)
301 return route_table_iter_started(&iter
->rt_iter
);
304 /* This would benefit from a real atomic operation...
306 static inline uint64_t bgp_table_next_version(struct bgp_table
*table
)
308 return ++table
->version
;
311 static inline uint64_t bgp_table_version(struct bgp_table
*table
)
313 return table
->version
;
316 void bgp_table_range_lookup(const struct bgp_table
*table
, struct prefix
*p
,
317 uint8_t maxlen
, struct list
*matches
);
320 static inline struct bgp_aggregate
*
321 bgp_aggregate_get_node_info(struct bgp_node
*node
)
326 static inline void bgp_aggregate_set_node_info(struct bgp_node
*node
,
327 struct bgp_aggregate
*aggregate
)
329 node
->info
= aggregate
;
332 static inline struct bgp_distance
*bgp_distance_get_node(struct bgp_node
*node
)
337 static inline void bgp_distance_set_node_info(struct bgp_node
*node
,
338 struct bgp_distance
*distance
)
340 node
->info
= distance
;
343 static inline struct bgp_static
*bgp_static_get_node_info(struct bgp_node
*node
)
348 static inline void bgp_static_set_node_info(struct bgp_node
*node
,
349 struct bgp_static
*bgp_static
)
351 node
->info
= bgp_static
;
354 static inline struct bgp_connected_ref
*
355 bgp_connected_get_node_info(struct bgp_node
*node
)
360 static inline void bgp_connected_set_node_info(struct bgp_node
*node
,
361 struct bgp_connected_ref
*bc
)
366 static inline struct bgp_nexthop_cache
*
367 bgp_nexthop_get_node_info(struct bgp_node
*node
)
372 static inline void bgp_nexthop_set_node_info(struct bgp_node
*node
,
373 struct bgp_nexthop_cache
*bnc
)
378 #endif /* _QUAGGA_BGP_TABLE_H */