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"
31 extern void bgp_delete_listnode(struct bgp_node
*node
);
34 /* table belongs to this instance */
37 /* afi/safi of this table */
43 struct route_table
*route_table
;
47 enum bgp_path_selection_reason
{
48 bgp_path_selection_none
,
49 bgp_path_selection_first
,
50 bgp_path_selection_evpn_sticky_mac
,
51 bgp_path_selection_evpn_seq
,
52 bgp_path_selection_evpn_lower_ip
,
53 bgp_path_selection_weight
,
54 bgp_path_selection_local_pref
,
55 bgp_path_selection_local_route
,
56 bgp_path_selection_confed_as_path
,
57 bgp_path_selection_as_path
,
58 bgp_path_selection_origin
,
59 bgp_path_selection_med
,
60 bgp_path_selection_peer
,
61 bgp_path_selection_confed
,
62 bgp_path_selection_igp_metric
,
63 bgp_path_selection_older
,
64 bgp_path_selection_router_id
,
65 bgp_path_selection_cluster_length
,
66 bgp_path_selection_stale
,
67 bgp_path_selection_local_configured
,
68 bgp_path_selection_neighbor_ip
,
69 bgp_path_selection_default
,
76 * These fields must be the very first fields in this structure.
78 * @see bgp_node_to_rnode
79 * @see bgp_node_from_rnode
83 struct bgp_adj_out_rb adj_out
;
85 struct bgp_adj_in
*adj_in
;
89 STAILQ_ENTRY(bgp_node
) pq
;
93 mpls_label_t local_label
;
96 #define BGP_NODE_PROCESS_SCHEDULED (1 << 0)
97 #define BGP_NODE_USER_CLEAR (1 << 1)
98 #define BGP_NODE_LABEL_CHANGED (1 << 2)
99 #define BGP_NODE_REGISTERED_FOR_LABEL (1 << 3)
100 #define BGP_NODE_SELECT_DEFER (1 << 4)
101 /* list node pointer */
102 struct listnode
*rt_node
;
103 struct bgp_addpath_node_data tx_addpath
;
105 enum bgp_path_selection_reason reason
;
111 * Structure that holds state for iterating over a bgp table.
113 typedef struct bgp_table_iter_t_
{
114 struct bgp_table
*table
;
115 route_table_iter_t rt_iter
;
118 extern struct bgp_table
*bgp_table_init(struct bgp
*bgp
, afi_t
, safi_t
);
119 extern void bgp_table_lock(struct bgp_table
*);
120 extern void bgp_table_unlock(struct bgp_table
*);
121 extern void bgp_table_finish(struct bgp_table
**);
125 * bgp_node_from_rnode
127 * Returns the bgp_node structure corresponding to a route_node.
129 static inline struct bgp_node
*bgp_node_from_rnode(struct route_node
*rnode
)
131 return (struct bgp_node
*)rnode
;
137 * Returns the route_node structure corresponding to a bgp_node.
139 static inline struct route_node
*bgp_node_to_rnode(struct bgp_node
*node
)
141 return (struct route_node
*)node
;
147 * Returns the bgp_table that the given node is in.
149 static inline struct bgp_table
*bgp_node_table(struct bgp_node
*node
)
151 return route_table_get_info(bgp_node_to_rnode(node
)->table
);
155 * bgp_node_parent_nolock
157 * Gets the parent node of the given node without locking it.
159 static inline struct bgp_node
*bgp_node_parent_nolock(struct bgp_node
*node
)
161 return bgp_node_from_rnode(node
->parent
);
167 static inline void bgp_unlock_node(struct bgp_node
*node
)
169 bgp_delete_listnode(node
);
170 route_unlock_node(bgp_node_to_rnode(node
));
174 * bgp_table_top_nolock
176 * Gets the top node in the table without locking it.
180 static inline struct bgp_node
*
181 bgp_table_top_nolock(const struct bgp_table
*const table
)
183 return bgp_node_from_rnode(table
->route_table
->top
);
189 static inline struct bgp_node
*
190 bgp_table_top(const struct bgp_table
*const table
)
192 return bgp_node_from_rnode(route_top(table
->route_table
));
198 static inline struct bgp_node
*bgp_route_next(struct bgp_node
*node
)
200 return bgp_node_from_rnode(route_next(bgp_node_to_rnode(node
)));
204 * bgp_route_next_until
206 static inline struct bgp_node
*bgp_route_next_until(struct bgp_node
*node
,
207 struct bgp_node
*limit
)
209 struct route_node
*rnode
;
211 rnode
= route_next_until(bgp_node_to_rnode(node
),
212 bgp_node_to_rnode(limit
));
213 return bgp_node_from_rnode(rnode
);
219 static inline struct bgp_node
*bgp_node_get(struct bgp_table
*const table
,
222 return bgp_node_from_rnode(route_node_get(table
->route_table
, p
));
228 static inline struct bgp_node
*
229 bgp_node_lookup(const struct bgp_table
*const table
, struct prefix
*p
)
231 return bgp_node_from_rnode(route_node_lookup(table
->route_table
, p
));
237 static inline struct bgp_node
*bgp_lock_node(struct bgp_node
*node
)
239 return bgp_node_from_rnode(route_lock_node(bgp_node_to_rnode(node
)));
245 static inline struct bgp_node
*bgp_node_match(const struct bgp_table
*table
,
248 return bgp_node_from_rnode(route_node_match(table
->route_table
, p
));
252 * bgp_node_match_ipv4
254 static inline struct bgp_node
*
255 bgp_node_match_ipv4(const struct bgp_table
*table
, struct in_addr
*addr
)
257 return bgp_node_from_rnode(
258 route_node_match_ipv4(table
->route_table
, addr
));
262 * bgp_node_match_ipv6
264 static inline struct bgp_node
*
265 bgp_node_match_ipv6(const struct bgp_table
*table
, struct in6_addr
*addr
)
267 return bgp_node_from_rnode(
268 route_node_match_ipv6(table
->route_table
, addr
));
271 static inline unsigned long bgp_table_count(const struct bgp_table
*const table
)
273 return route_table_count(table
->route_table
);
279 static inline struct bgp_node
*bgp_table_get_next(const struct bgp_table
*table
,
282 return bgp_node_from_rnode(route_table_get_next(table
->route_table
, p
));
286 * bgp_table_iter_init
288 static inline void bgp_table_iter_init(bgp_table_iter_t
*iter
,
289 struct bgp_table
*table
)
291 bgp_table_lock(table
);
293 route_table_iter_init(&iter
->rt_iter
, table
->route_table
);
297 * bgp_table_iter_next
299 static inline struct bgp_node
*bgp_table_iter_next(bgp_table_iter_t
*iter
)
301 return bgp_node_from_rnode(route_table_iter_next(&iter
->rt_iter
));
305 * bgp_table_iter_cleanup
307 static inline void bgp_table_iter_cleanup(bgp_table_iter_t
*iter
)
309 route_table_iter_cleanup(&iter
->rt_iter
);
310 bgp_table_unlock(iter
->table
);
315 * bgp_table_iter_pause
317 static inline void bgp_table_iter_pause(bgp_table_iter_t
*iter
)
319 route_table_iter_pause(&iter
->rt_iter
);
323 * bgp_table_iter_is_done
325 static inline int bgp_table_iter_is_done(bgp_table_iter_t
*iter
)
327 return route_table_iter_is_done(&iter
->rt_iter
);
331 * bgp_table_iter_started
333 static inline int bgp_table_iter_started(bgp_table_iter_t
*iter
)
335 return route_table_iter_started(&iter
->rt_iter
);
338 /* This would benefit from a real atomic operation...
340 static inline uint64_t bgp_table_next_version(struct bgp_table
*table
)
342 return ++table
->version
;
345 static inline uint64_t bgp_table_version(struct bgp_table
*table
)
347 return table
->version
;
350 void bgp_table_range_lookup(const struct bgp_table
*table
, struct prefix
*p
,
351 uint8_t maxlen
, struct list
*matches
);
354 static inline struct bgp_aggregate
*
355 bgp_node_get_bgp_aggregate_info(struct bgp_node
*node
)
361 bgp_node_set_bgp_aggregate_info(struct bgp_node
*node
,
362 struct bgp_aggregate
*aggregate
)
364 node
->info
= aggregate
;
367 static inline struct bgp_distance
*
368 bgp_node_get_bgp_distance_info(struct bgp_node
*node
)
373 static inline void bgp_node_set_bgp_distance_info(struct bgp_node
*node
,
374 struct bgp_distance
*distance
)
376 node
->info
= distance
;
379 static inline struct bgp_static
*
380 bgp_node_get_bgp_static_info(struct bgp_node
*node
)
385 static inline void bgp_node_set_bgp_static_info(struct bgp_node
*node
,
386 struct bgp_static
*bgp_static
)
388 node
->info
= bgp_static
;
391 static inline struct bgp_connected_ref
*
392 bgp_node_get_bgp_connected_ref_info(struct bgp_node
*node
)
398 bgp_node_set_bgp_connected_ref_info(struct bgp_node
*node
,
399 struct bgp_connected_ref
*bc
)
404 static inline struct bgp_nexthop_cache
*
405 bgp_node_get_bgp_nexthop_info(struct bgp_node
*node
)
410 static inline void bgp_node_set_bgp_nexthop_info(struct bgp_node
*node
,
411 struct bgp_nexthop_cache
*bnc
)
416 static inline struct bgp_path_info
*
417 bgp_node_get_bgp_path_info(struct bgp_node
*node
)
422 static inline void bgp_node_set_bgp_path_info(struct bgp_node
*node
,
423 struct bgp_path_info
*bi
)
428 static inline struct bgp_table
*
429 bgp_node_get_bgp_table_info(struct bgp_node
*node
)
434 static inline void bgp_node_set_bgp_table_info(struct bgp_node
*node
,
435 struct bgp_table
*table
)
440 static inline bool bgp_node_has_bgp_path_info_data(struct bgp_node
*node
)
445 #endif /* _QUAGGA_BGP_TABLE_H */