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"
36 /* table belongs to this instance */
39 /* afi/safi of this table */
45 /* soft_reconfig_table in progress */
46 bool soft_reconfig_init
;
47 struct thread
*soft_reconfig_thread
;
49 /* list of peers on which soft_reconfig_table has to run */
50 struct list
*soft_reconfig_peers
;
52 struct route_table
*route_table
;
56 enum bgp_path_selection_reason
{
57 bgp_path_selection_none
,
58 bgp_path_selection_first
,
59 bgp_path_selection_evpn_sticky_mac
,
60 bgp_path_selection_evpn_seq
,
61 bgp_path_selection_evpn_local_path
,
62 bgp_path_selection_evpn_non_proxy
,
63 bgp_path_selection_evpn_lower_ip
,
64 bgp_path_selection_weight
,
65 bgp_path_selection_local_pref
,
66 bgp_path_selection_accept_own
,
67 bgp_path_selection_local_route
,
68 bgp_path_selection_aigp
,
69 bgp_path_selection_confed_as_path
,
70 bgp_path_selection_as_path
,
71 bgp_path_selection_origin
,
72 bgp_path_selection_med
,
73 bgp_path_selection_peer
,
74 bgp_path_selection_confed
,
75 bgp_path_selection_igp_metric
,
76 bgp_path_selection_older
,
77 bgp_path_selection_router_id
,
78 bgp_path_selection_cluster_length
,
79 bgp_path_selection_stale
,
80 bgp_path_selection_local_configured
,
81 bgp_path_selection_neighbor_ip
,
82 bgp_path_selection_default
,
89 * These fields must be the very first fields in this structure.
91 * @see bgp_node_to_rnode
92 * @see bgp_node_from_rnode
96 struct bgp_adj_out_rb adj_out
;
98 struct bgp_adj_in
*adj_in
;
100 struct bgp_dest
*pdest
;
102 STAILQ_ENTRY(bgp_dest
) pq
;
106 mpls_label_t local_label
;
109 #define BGP_NODE_PROCESS_SCHEDULED (1 << 0)
110 #define BGP_NODE_USER_CLEAR (1 << 1)
111 #define BGP_NODE_LABEL_CHANGED (1 << 2)
112 #define BGP_NODE_REGISTERED_FOR_LABEL (1 << 3)
113 #define BGP_NODE_SELECT_DEFER (1 << 4)
114 #define BGP_NODE_FIB_INSTALL_PENDING (1 << 5)
115 #define BGP_NODE_FIB_INSTALLED (1 << 6)
116 #define BGP_NODE_LABEL_REQUESTED (1 << 7)
117 #define BGP_NODE_SOFT_RECONFIG (1 << 8)
119 struct bgp_addpath_node_data tx_addpath
;
121 enum bgp_path_selection_reason reason
;
124 extern void bgp_delete_listnode(struct bgp_dest
*dest
);
128 * Structure that holds state for iterating over a bgp table.
130 typedef struct bgp_table_iter_t_
{
131 struct bgp_table
*table
;
132 route_table_iter_t rt_iter
;
135 extern struct bgp_table
*bgp_table_init(struct bgp
*bgp
, afi_t
, safi_t
);
136 extern void bgp_table_lock(struct bgp_table
*);
137 extern void bgp_table_unlock(struct bgp_table
*);
138 extern void bgp_table_finish(struct bgp_table
**);
139 extern void bgp_dest_unlock_node(struct bgp_dest
*dest
);
140 extern struct bgp_dest
*bgp_dest_lock_node(struct bgp_dest
*dest
);
141 extern const char *bgp_dest_get_prefix_str(struct bgp_dest
*dest
);
145 * bgp_dest_from_rnode
147 * Returns the bgp_dest structure corresponding to a route_node.
149 static inline struct bgp_dest
*bgp_dest_from_rnode(struct route_node
*rnode
)
151 return (struct bgp_dest
*)rnode
;
157 * Returns the route_node structure corresponding to a bgp_dest.
159 static inline struct route_node
*bgp_dest_to_rnode(const struct bgp_dest
*dest
)
161 return (struct route_node
*)dest
;
167 * Returns the bgp_table that the given dest is in.
169 static inline struct bgp_table
*bgp_dest_table(struct bgp_dest
*dest
)
171 return route_table_get_info(bgp_dest_to_rnode(dest
)->table
);
175 * bgp_dest_parent_nolock
177 * Gets the parent dest of the given node without locking it.
179 static inline struct bgp_dest
*bgp_dest_parent_nolock(struct bgp_dest
*dest
)
181 struct route_node
*rn
= bgp_dest_to_rnode(dest
)->parent
;
183 return bgp_dest_from_rnode(rn
);
187 * bgp_table_top_nolock
189 * Gets the top dest in the table without locking it.
193 static inline struct bgp_dest
*
194 bgp_table_top_nolock(const struct bgp_table
*const table
)
196 return bgp_dest_from_rnode(table
->route_table
->top
);
202 static inline struct bgp_dest
*
203 bgp_table_top(const struct bgp_table
*const table
)
205 return bgp_dest_from_rnode(route_top(table
->route_table
));
211 static inline struct bgp_dest
*bgp_route_next(struct bgp_dest
*dest
)
213 return bgp_dest_from_rnode(route_next(bgp_dest_to_rnode(dest
)));
217 * bgp_route_next_until
219 static inline struct bgp_dest
*bgp_route_next_until(struct bgp_dest
*dest
,
220 struct bgp_dest
*limit
)
222 struct route_node
*rnode
;
224 rnode
= route_next_until(bgp_dest_to_rnode(dest
),
225 bgp_dest_to_rnode(limit
));
227 return bgp_dest_from_rnode(rnode
);
233 static inline struct bgp_dest
*bgp_node_get(struct bgp_table
*const table
,
234 const struct prefix
*p
)
236 return bgp_dest_from_rnode(route_node_get(table
->route_table
, p
));
242 static inline struct bgp_dest
*
243 bgp_node_lookup(const struct bgp_table
*const table
, const struct prefix
*p
)
245 struct route_node
*rn
= route_node_lookup(table
->route_table
, p
);
247 return bgp_dest_from_rnode(rn
);
253 static inline struct bgp_dest
*bgp_node_match(const struct bgp_table
*table
,
254 const struct prefix
*p
)
256 struct route_node
*rn
= route_node_match(table
->route_table
, p
);
258 return bgp_dest_from_rnode(rn
);
261 static inline unsigned long bgp_table_count(const struct bgp_table
*const table
)
263 return route_table_count(table
->route_table
);
269 static inline struct bgp_dest
*bgp_table_get_next(const struct bgp_table
*table
,
270 const struct prefix
*p
)
272 return bgp_dest_from_rnode(route_table_get_next(table
->route_table
, p
));
275 /* This would benefit from a real atomic operation...
277 static inline uint64_t bgp_table_next_version(struct bgp_table
*table
)
279 return ++table
->version
;
282 static inline uint64_t bgp_table_version(struct bgp_table
*table
)
284 return table
->version
;
287 /* Find the subtree of the prefix p
289 * This will return the first node that belongs the the subtree of p. Including
290 * p itself, if it is in the tree.
292 * If the subtree is not present in the table, NULL is returned.
294 struct bgp_dest
*bgp_table_subtree_lookup(const struct bgp_table
*table
,
295 const struct prefix
*p
);
297 static inline struct bgp_aggregate
*
298 bgp_dest_get_bgp_aggregate_info(struct bgp_dest
*dest
)
300 return dest
? dest
->info
: NULL
;
304 bgp_dest_set_bgp_aggregate_info(struct bgp_dest
*dest
,
305 struct bgp_aggregate
*aggregate
)
307 dest
->info
= aggregate
;
310 static inline struct bgp_distance
*
311 bgp_dest_get_bgp_distance_info(struct bgp_dest
*dest
)
313 return dest
? dest
->info
: NULL
;
316 static inline void bgp_dest_set_bgp_distance_info(struct bgp_dest
*dest
,
317 struct bgp_distance
*distance
)
319 dest
->info
= distance
;
322 static inline struct bgp_static
*
323 bgp_dest_get_bgp_static_info(struct bgp_dest
*dest
)
325 return dest
? dest
->info
: NULL
;
328 static inline void bgp_dest_set_bgp_static_info(struct bgp_dest
*dest
,
329 struct bgp_static
*bgp_static
)
331 dest
->info
= bgp_static
;
334 static inline struct bgp_connected_ref
*
335 bgp_dest_get_bgp_connected_ref_info(struct bgp_dest
*dest
)
337 return dest
? dest
->info
: NULL
;
341 bgp_dest_set_bgp_connected_ref_info(struct bgp_dest
*dest
,
342 struct bgp_connected_ref
*bc
)
347 static inline struct bgp_nexthop_cache
*
348 bgp_dest_get_bgp_nexthop_info(struct bgp_dest
*dest
)
350 return dest
? dest
->info
: NULL
;
353 static inline void bgp_dest_set_bgp_nexthop_info(struct bgp_dest
*dest
,
354 struct bgp_nexthop_cache
*bnc
)
359 static inline struct bgp_path_info
*
360 bgp_dest_get_bgp_path_info(struct bgp_dest
*dest
)
362 return dest
? dest
->info
: NULL
;
365 static inline void bgp_dest_set_bgp_path_info(struct bgp_dest
*dest
,
366 struct bgp_path_info
*bi
)
371 static inline struct bgp_table
*
372 bgp_dest_get_bgp_table_info(struct bgp_dest
*dest
)
377 static inline void bgp_dest_set_bgp_table_info(struct bgp_dest
*dest
,
378 struct bgp_table
*table
)
383 static inline bool bgp_dest_has_bgp_path_info_data(struct bgp_dest
*dest
)
388 static inline const struct prefix
*bgp_dest_get_prefix(const struct bgp_dest
*dest
)
393 static inline unsigned int bgp_dest_get_lock_count(const struct bgp_dest
*dest
)
398 #ifdef _FRR_ATTRIBUTE_PRINTFRR
399 #pragma FRR printfrr_ext "%pRN" (struct bgp_node *)
400 #pragma FRR printfrr_ext "%pBD" (struct bgp_dest *)
403 #endif /* _QUAGGA_BGP_TABLE_H */