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"
32 /* table belongs to this instance */
35 /* afi/safi of this table */
41 struct route_table
*route_table
;
45 enum bgp_path_selection_reason
{
46 bgp_path_selection_none
,
47 bgp_path_selection_first
,
48 bgp_path_selection_evpn_sticky_mac
,
49 bgp_path_selection_evpn_seq
,
50 bgp_path_selection_evpn_lower_ip
,
51 bgp_path_selection_weight
,
52 bgp_path_selection_local_pref
,
53 bgp_path_selection_local_route
,
54 bgp_path_selection_confed_as_path
,
55 bgp_path_selection_as_path
,
56 bgp_path_selection_origin
,
57 bgp_path_selection_med
,
58 bgp_path_selection_peer
,
59 bgp_path_selection_confed
,
60 bgp_path_selection_igp_metric
,
61 bgp_path_selection_older
,
62 bgp_path_selection_router_id
,
63 bgp_path_selection_cluster_length
,
64 bgp_path_selection_stale
,
65 bgp_path_selection_local_configured
,
66 bgp_path_selection_neighbor_ip
,
67 bgp_path_selection_default
,
74 * These fields must be the very first fields in this structure.
76 * @see bgp_node_to_rnode
77 * @see bgp_node_from_rnode
81 struct bgp_adj_out_rb adj_out
;
83 struct bgp_adj_in
*adj_in
;
87 STAILQ_ENTRY(bgp_node
) pq
;
91 mpls_label_t local_label
;
94 #define BGP_NODE_PROCESS_SCHEDULED (1 << 0)
95 #define BGP_NODE_USER_CLEAR (1 << 1)
96 #define BGP_NODE_LABEL_CHANGED (1 << 2)
97 #define BGP_NODE_REGISTERED_FOR_LABEL (1 << 3)
99 struct bgp_addpath_node_data tx_addpath
;
101 enum bgp_path_selection_reason reason
;
107 * Structure that holds state for iterating over a bgp table.
109 typedef struct bgp_table_iter_t_
{
110 struct bgp_table
*table
;
111 route_table_iter_t rt_iter
;
114 extern struct bgp_table
*bgp_table_init(struct bgp
*bgp
, afi_t
, safi_t
);
115 extern void bgp_table_lock(struct bgp_table
*);
116 extern void bgp_table_unlock(struct bgp_table
*);
117 extern void bgp_table_finish(struct bgp_table
**);
121 * bgp_node_from_rnode
123 * Returns the bgp_node structure corresponding to a route_node.
125 static inline struct bgp_node
*bgp_node_from_rnode(struct route_node
*rnode
)
127 return (struct bgp_node
*)rnode
;
133 * Returns the route_node structure corresponding to a bgp_node.
135 static inline struct route_node
*bgp_node_to_rnode(struct bgp_node
*node
)
137 return (struct route_node
*)node
;
143 * Returns the bgp_table that the given node is in.
145 static inline struct bgp_table
*bgp_node_table(struct bgp_node
*node
)
147 return route_table_get_info(bgp_node_to_rnode(node
)->table
);
151 * bgp_node_parent_nolock
153 * Gets the parent node of the given node without locking it.
155 static inline struct bgp_node
*bgp_node_parent_nolock(struct bgp_node
*node
)
157 return bgp_node_from_rnode(node
->parent
);
163 static inline void bgp_unlock_node(struct bgp_node
*node
)
165 route_unlock_node(bgp_node_to_rnode(node
));
169 * bgp_table_top_nolock
171 * Gets the top node in the table without locking it.
175 static inline struct bgp_node
*
176 bgp_table_top_nolock(const struct bgp_table
*const table
)
178 return bgp_node_from_rnode(table
->route_table
->top
);
184 static inline struct bgp_node
*
185 bgp_table_top(const struct bgp_table
*const table
)
187 return bgp_node_from_rnode(route_top(table
->route_table
));
193 static inline struct bgp_node
*bgp_route_next(struct bgp_node
*node
)
195 return bgp_node_from_rnode(route_next(bgp_node_to_rnode(node
)));
199 * bgp_route_next_until
201 static inline struct bgp_node
*bgp_route_next_until(struct bgp_node
*node
,
202 struct bgp_node
*limit
)
204 struct route_node
*rnode
;
206 rnode
= route_next_until(bgp_node_to_rnode(node
),
207 bgp_node_to_rnode(limit
));
208 return bgp_node_from_rnode(rnode
);
214 static inline struct bgp_node
*bgp_node_get(struct bgp_table
*const table
,
217 return bgp_node_from_rnode(route_node_get(table
->route_table
, p
));
223 static inline struct bgp_node
*
224 bgp_node_lookup(const struct bgp_table
*const table
, struct prefix
*p
)
226 return bgp_node_from_rnode(route_node_lookup(table
->route_table
, p
));
232 static inline struct bgp_node
*bgp_lock_node(struct bgp_node
*node
)
234 return bgp_node_from_rnode(route_lock_node(bgp_node_to_rnode(node
)));
240 static inline struct bgp_node
*bgp_node_match(const struct bgp_table
*table
,
243 return bgp_node_from_rnode(route_node_match(table
->route_table
, p
));
247 * bgp_node_match_ipv4
249 static inline struct bgp_node
*
250 bgp_node_match_ipv4(const struct bgp_table
*table
, struct in_addr
*addr
)
252 return bgp_node_from_rnode(
253 route_node_match_ipv4(table
->route_table
, addr
));
257 * bgp_node_match_ipv6
259 static inline struct bgp_node
*
260 bgp_node_match_ipv6(const struct bgp_table
*table
, struct in6_addr
*addr
)
262 return bgp_node_from_rnode(
263 route_node_match_ipv6(table
->route_table
, addr
));
266 static inline unsigned long bgp_table_count(const struct bgp_table
*const table
)
268 return route_table_count(table
->route_table
);
274 static inline struct bgp_node
*bgp_table_get_next(const struct bgp_table
*table
,
277 return bgp_node_from_rnode(route_table_get_next(table
->route_table
, p
));
281 * bgp_table_iter_init
283 static inline void bgp_table_iter_init(bgp_table_iter_t
*iter
,
284 struct bgp_table
*table
)
286 bgp_table_lock(table
);
288 route_table_iter_init(&iter
->rt_iter
, table
->route_table
);
292 * bgp_table_iter_next
294 static inline struct bgp_node
*bgp_table_iter_next(bgp_table_iter_t
*iter
)
296 return bgp_node_from_rnode(route_table_iter_next(&iter
->rt_iter
));
300 * bgp_table_iter_cleanup
302 static inline void bgp_table_iter_cleanup(bgp_table_iter_t
*iter
)
304 route_table_iter_cleanup(&iter
->rt_iter
);
305 bgp_table_unlock(iter
->table
);
310 * bgp_table_iter_pause
312 static inline void bgp_table_iter_pause(bgp_table_iter_t
*iter
)
314 route_table_iter_pause(&iter
->rt_iter
);
318 * bgp_table_iter_is_done
320 static inline int bgp_table_iter_is_done(bgp_table_iter_t
*iter
)
322 return route_table_iter_is_done(&iter
->rt_iter
);
326 * bgp_table_iter_started
328 static inline int bgp_table_iter_started(bgp_table_iter_t
*iter
)
330 return route_table_iter_started(&iter
->rt_iter
);
333 /* This would benefit from a real atomic operation...
335 static inline uint64_t bgp_table_next_version(struct bgp_table
*table
)
337 return ++table
->version
;
340 static inline uint64_t bgp_table_version(struct bgp_table
*table
)
342 return table
->version
;
345 void bgp_table_range_lookup(const struct bgp_table
*table
, struct prefix
*p
,
346 uint8_t maxlen
, struct list
*matches
);
349 static inline struct bgp_aggregate
*
350 bgp_node_get_bgp_aggregate_info(struct bgp_node
*node
)
356 bgp_node_set_bgp_aggregate_info(struct bgp_node
*node
,
357 struct bgp_aggregate
*aggregate
)
359 node
->info
= aggregate
;
362 static inline struct bgp_distance
*
363 bgp_node_get_bgp_distance_info(struct bgp_node
*node
)
368 static inline void bgp_node_set_bgp_distance_info(struct bgp_node
*node
,
369 struct bgp_distance
*distance
)
371 node
->info
= distance
;
374 static inline struct bgp_static
*
375 bgp_node_get_bgp_static_info(struct bgp_node
*node
)
380 static inline void bgp_node_set_bgp_static_info(struct bgp_node
*node
,
381 struct bgp_static
*bgp_static
)
383 node
->info
= bgp_static
;
386 static inline struct bgp_connected_ref
*
387 bgp_node_get_bgp_connected_ref_info(struct bgp_node
*node
)
393 bgp_node_set_bgp_connected_ref_info(struct bgp_node
*node
,
394 struct bgp_connected_ref
*bc
)
399 static inline struct bgp_nexthop_cache
*
400 bgp_node_get_bgp_nexthop_info(struct bgp_node
*node
)
405 static inline void bgp_node_set_bgp_nexthop_info(struct bgp_node
*node
,
406 struct bgp_nexthop_cache
*bnc
)
411 static inline struct bgp_path_info
*
412 bgp_node_get_bgp_path_info(struct bgp_node
*node
)
417 static inline void bgp_node_set_bgp_path_info(struct bgp_node
*node
,
418 struct bgp_path_info
*bi
)
423 static inline struct bgp_table
*
424 bgp_node_get_bgp_table_info(struct bgp_node
*node
)
429 static inline void bgp_node_set_bgp_table_info(struct bgp_node
*node
,
430 struct bgp_table
*table
)
435 static inline bool bgp_node_has_bgp_path_info_data(struct bgp_node
*node
)
440 #endif /* _QUAGGA_BGP_TABLE_H */