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
24 /* XXX BEGIN TEMPORARY COMPAT */
25 #define bgp_dest bgp_node
26 /* XXX END TEMPORARY COMPAT */
33 #include "bgp_advertise.h"
34 #include "bgpd/bgp_trace.h"
37 /* table belongs to this instance */
40 /* afi/safi of this table */
46 /* soft_reconfig_table in progress */
47 bool soft_reconfig_init
;
48 struct thread
*soft_reconfig_thread
;
50 /* list of peers on which soft_reconfig_table has to run */
51 struct list
*soft_reconfig_peers
;
53 struct route_table
*route_table
;
57 enum bgp_path_selection_reason
{
58 bgp_path_selection_none
,
59 bgp_path_selection_first
,
60 bgp_path_selection_evpn_sticky_mac
,
61 bgp_path_selection_evpn_seq
,
62 bgp_path_selection_evpn_local_path
,
63 bgp_path_selection_evpn_non_proxy
,
64 bgp_path_selection_evpn_lower_ip
,
65 bgp_path_selection_weight
,
66 bgp_path_selection_local_pref
,
67 bgp_path_selection_local_route
,
68 bgp_path_selection_confed_as_path
,
69 bgp_path_selection_as_path
,
70 bgp_path_selection_origin
,
71 bgp_path_selection_med
,
72 bgp_path_selection_peer
,
73 bgp_path_selection_confed
,
74 bgp_path_selection_igp_metric
,
75 bgp_path_selection_older
,
76 bgp_path_selection_router_id
,
77 bgp_path_selection_cluster_length
,
78 bgp_path_selection_stale
,
79 bgp_path_selection_local_configured
,
80 bgp_path_selection_neighbor_ip
,
81 bgp_path_selection_default
,
88 * These fields must be the very first fields in this structure.
90 * @see bgp_node_to_rnode
91 * @see bgp_node_from_rnode
95 struct bgp_adj_out_rb adj_out
;
97 struct bgp_adj_in
*adj_in
;
99 struct bgp_dest
*pdest
;
101 STAILQ_ENTRY(bgp_dest
) pq
;
105 mpls_label_t local_label
;
108 #define BGP_NODE_PROCESS_SCHEDULED (1 << 0)
109 #define BGP_NODE_USER_CLEAR (1 << 1)
110 #define BGP_NODE_LABEL_CHANGED (1 << 2)
111 #define BGP_NODE_REGISTERED_FOR_LABEL (1 << 3)
112 #define BGP_NODE_SELECT_DEFER (1 << 4)
113 #define BGP_NODE_FIB_INSTALL_PENDING (1 << 5)
114 #define BGP_NODE_FIB_INSTALLED (1 << 6)
115 #define BGP_NODE_LABEL_REQUESTED (1 << 7)
116 #define BGP_NODE_SOFT_RECONFIG (1 << 8)
118 struct bgp_addpath_node_data tx_addpath
;
120 enum bgp_path_selection_reason reason
;
123 extern void bgp_delete_listnode(struct bgp_dest
*dest
);
127 * Structure that holds state for iterating over a bgp table.
129 typedef struct bgp_table_iter_t_
{
130 struct bgp_table
*table
;
131 route_table_iter_t rt_iter
;
134 extern struct bgp_table
*bgp_table_init(struct bgp
*bgp
, afi_t
, safi_t
);
135 extern void bgp_table_lock(struct bgp_table
*);
136 extern void bgp_table_unlock(struct bgp_table
*);
137 extern void bgp_table_finish(struct bgp_table
**);
141 * bgp_dest_from_rnode
143 * Returns the bgp_dest structure corresponding to a route_node.
145 static inline struct bgp_dest
*bgp_dest_from_rnode(struct route_node
*rnode
)
147 return (struct bgp_dest
*)rnode
;
153 * Returns the route_node structure corresponding to a bgp_dest.
155 static inline struct route_node
*bgp_dest_to_rnode(const struct bgp_dest
*dest
)
157 return (struct route_node
*)dest
;
163 * Returns the bgp_table that the given dest is in.
165 static inline struct bgp_table
*bgp_dest_table(struct bgp_dest
*dest
)
167 return route_table_get_info(bgp_dest_to_rnode(dest
)->table
);
171 * bgp_dest_parent_nolock
173 * Gets the parent dest of the given node without locking it.
175 static inline struct bgp_dest
*bgp_dest_parent_nolock(struct bgp_dest
*dest
)
177 struct route_node
*rn
= bgp_dest_to_rnode(dest
)->parent
;
179 return bgp_dest_from_rnode(rn
);
183 * bgp_dest_unlock_node
185 static inline void bgp_dest_unlock_node(struct bgp_dest
*dest
)
187 frrtrace(1, frr_bgp
, bgp_dest_unlock
, dest
);
188 bgp_delete_listnode(dest
);
189 route_unlock_node(bgp_dest_to_rnode(dest
));
193 * bgp_table_top_nolock
195 * Gets the top dest in the table without locking it.
199 static inline struct bgp_dest
*
200 bgp_table_top_nolock(const struct bgp_table
*const table
)
202 return bgp_dest_from_rnode(table
->route_table
->top
);
208 static inline struct bgp_dest
*
209 bgp_table_top(const struct bgp_table
*const table
)
211 return bgp_dest_from_rnode(route_top(table
->route_table
));
217 static inline struct bgp_dest
*bgp_route_next(struct bgp_dest
*dest
)
219 return bgp_dest_from_rnode(route_next(bgp_dest_to_rnode(dest
)));
223 * bgp_route_next_until
225 static inline struct bgp_dest
*bgp_route_next_until(struct bgp_dest
*dest
,
226 struct bgp_dest
*limit
)
228 struct route_node
*rnode
;
230 rnode
= route_next_until(bgp_dest_to_rnode(dest
),
231 bgp_dest_to_rnode(limit
));
233 return bgp_dest_from_rnode(rnode
);
239 static inline struct bgp_dest
*bgp_node_get(struct bgp_table
*const table
,
240 const struct prefix
*p
)
242 return bgp_dest_from_rnode(route_node_get(table
->route_table
, p
));
248 static inline struct bgp_dest
*
249 bgp_node_lookup(const struct bgp_table
*const table
, const struct prefix
*p
)
251 struct route_node
*rn
= route_node_lookup(table
->route_table
, p
);
253 return bgp_dest_from_rnode(rn
);
259 static inline struct bgp_dest
*bgp_dest_lock_node(struct bgp_dest
*dest
)
261 frrtrace(1, frr_bgp
, bgp_dest_lock
, dest
);
262 struct route_node
*rn
= route_lock_node(bgp_dest_to_rnode(dest
));
264 return bgp_dest_from_rnode(rn
);
270 static inline struct bgp_dest
*bgp_node_match(const struct bgp_table
*table
,
271 const struct prefix
*p
)
273 struct route_node
*rn
= route_node_match(table
->route_table
, p
);
275 return bgp_dest_from_rnode(rn
);
279 * bgp_node_match_ipv4
281 static inline struct bgp_dest
*
282 bgp_node_match_ipv4(const struct bgp_table
*table
, struct in_addr
*addr
)
284 struct route_node
*rn
= route_node_match_ipv4(table
->route_table
, addr
);
286 return bgp_dest_from_rnode(rn
);
290 * bgp_node_match_ipv6
292 static inline struct bgp_dest
*
293 bgp_node_match_ipv6(const struct bgp_table
*table
, struct in6_addr
*addr
)
295 struct route_node
*rn
= route_node_match_ipv6(table
->route_table
, addr
);
297 return bgp_dest_from_rnode(rn
);
300 static inline unsigned long bgp_table_count(const struct bgp_table
*const table
)
302 return route_table_count(table
->route_table
);
308 static inline struct bgp_dest
*bgp_table_get_next(const struct bgp_table
*table
,
309 const struct prefix
*p
)
311 return bgp_dest_from_rnode(route_table_get_next(table
->route_table
, p
));
315 * bgp_table_iter_init
317 static inline void bgp_table_iter_init(bgp_table_iter_t
*iter
,
318 struct bgp_table
*table
)
320 bgp_table_lock(table
);
322 route_table_iter_init(&iter
->rt_iter
, table
->route_table
);
326 * bgp_table_iter_next
328 static inline struct bgp_dest
*bgp_table_iter_next(bgp_table_iter_t
*iter
)
330 return bgp_dest_from_rnode(route_table_iter_next(&iter
->rt_iter
));
334 * bgp_table_iter_cleanup
336 static inline void bgp_table_iter_cleanup(bgp_table_iter_t
*iter
)
338 route_table_iter_cleanup(&iter
->rt_iter
);
339 bgp_table_unlock(iter
->table
);
344 * bgp_table_iter_pause
346 static inline void bgp_table_iter_pause(bgp_table_iter_t
*iter
)
348 route_table_iter_pause(&iter
->rt_iter
);
352 * bgp_table_iter_is_done
354 static inline int bgp_table_iter_is_done(bgp_table_iter_t
*iter
)
356 return route_table_iter_is_done(&iter
->rt_iter
);
360 * bgp_table_iter_started
362 static inline int bgp_table_iter_started(bgp_table_iter_t
*iter
)
364 return route_table_iter_started(&iter
->rt_iter
);
367 /* This would benefit from a real atomic operation...
369 static inline uint64_t bgp_table_next_version(struct bgp_table
*table
)
371 return ++table
->version
;
374 static inline uint64_t bgp_table_version(struct bgp_table
*table
)
376 return table
->version
;
379 /* Find the subtree of the prefix p
381 * This will return the first node that belongs the the subtree of p. Including
382 * p itself, if it is in the tree.
384 * If the subtree is not present in the table, NULL is returned.
386 struct bgp_dest
*bgp_table_subtree_lookup(const struct bgp_table
*table
,
387 const struct prefix
*p
);
389 static inline struct bgp_aggregate
*
390 bgp_dest_get_bgp_aggregate_info(struct bgp_dest
*dest
)
392 return dest
? dest
->info
: NULL
;
396 bgp_dest_set_bgp_aggregate_info(struct bgp_dest
*dest
,
397 struct bgp_aggregate
*aggregate
)
399 dest
->info
= aggregate
;
402 static inline struct bgp_distance
*
403 bgp_dest_get_bgp_distance_info(struct bgp_dest
*dest
)
405 return dest
? dest
->info
: NULL
;
408 static inline void bgp_dest_set_bgp_distance_info(struct bgp_dest
*dest
,
409 struct bgp_distance
*distance
)
411 dest
->info
= distance
;
414 static inline struct bgp_static
*
415 bgp_dest_get_bgp_static_info(struct bgp_dest
*dest
)
417 return dest
? dest
->info
: NULL
;
420 static inline void bgp_dest_set_bgp_static_info(struct bgp_dest
*dest
,
421 struct bgp_static
*bgp_static
)
423 dest
->info
= bgp_static
;
426 static inline struct bgp_connected_ref
*
427 bgp_dest_get_bgp_connected_ref_info(struct bgp_dest
*dest
)
429 return dest
? dest
->info
: NULL
;
433 bgp_dest_set_bgp_connected_ref_info(struct bgp_dest
*dest
,
434 struct bgp_connected_ref
*bc
)
439 static inline struct bgp_nexthop_cache
*
440 bgp_dest_get_bgp_nexthop_info(struct bgp_dest
*dest
)
442 return dest
? dest
->info
: NULL
;
445 static inline void bgp_dest_set_bgp_nexthop_info(struct bgp_dest
*dest
,
446 struct bgp_nexthop_cache
*bnc
)
451 static inline struct bgp_path_info
*
452 bgp_dest_get_bgp_path_info(struct bgp_dest
*dest
)
454 return dest
? dest
->info
: NULL
;
457 static inline void bgp_dest_set_bgp_path_info(struct bgp_dest
*dest
,
458 struct bgp_path_info
*bi
)
463 static inline struct bgp_table
*
464 bgp_dest_get_bgp_table_info(struct bgp_dest
*dest
)
469 static inline void bgp_dest_set_bgp_table_info(struct bgp_dest
*dest
,
470 struct bgp_table
*table
)
475 static inline bool bgp_dest_has_bgp_path_info_data(struct bgp_dest
*dest
)
480 static inline const struct prefix
*bgp_dest_get_prefix(const struct bgp_dest
*dest
)
485 static inline unsigned int bgp_dest_get_lock_count(const struct bgp_dest
*dest
)
490 #ifdef _FRR_ATTRIBUTE_PRINTFRR
491 #pragma FRR printfrr_ext "%pRN" (struct bgp_node *)
492 #pragma FRR printfrr_ext "%pBD" (struct bgp_dest *)
495 #endif /* _QUAGGA_BGP_TABLE_H */