1/* BGP routing table 2 Copyright (C) 1998, 2001 Kunihiro Ishiguro 3 4This file is part of GNU Zebra. 5 6GNU Zebra is free software; you can redistribute it and/or modify it 7under the terms of the GNU General Public License as published by the 8Free Software Foundation; either version 2, or (at your option) any 9later version. 10 11GNU Zebra is distributed in the hope that it will be useful, but 12WITHOUT ANY WARRANTY; without even the implied warranty of 13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14General Public License for more details. 15 16You should have received a copy of the GNU General Public License 17along with GNU Zebra; see the file COPYING. If not, write to the Free 18Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 1902111-1307, USA. */ 20 21#ifndef _QUAGGA_BGP_TABLE_H 22#define _QUAGGA_BGP_TABLE_H 23 24#include "table.h" 25 26typedef enum 27{ 28 BGP_TABLE_MAIN, 29 BGP_TABLE_RSCLIENT, 30} bgp_table_t; 31 32struct bgp_table 33{ 34 bgp_table_t type; 35 36 /* afi/safi of this table */ 37 afi_t afi; 38 safi_t safi; 39 40 int lock; 41 42 /* The owner of this 'bgp_table' structure. */ 43 struct peer *owner; 44 45 struct route_table *route_table; 46}; 47 48struct bgp_node 49{ 50 /* 51 * CAUTION 52 * 53 * These fields must be the very first fields in this structure. 54 * 55 * @see bgp_node_to_rnode 56 * @see bgp_node_from_rnode 57 */ 58 ROUTE_NODE_FIELDS; 59 60 struct bgp_adj_out *adj_out; 61 62 struct bgp_adj_in *adj_in; 63 64 struct bgp_node *prn; 65 66 u_char flags; 67#define BGP_NODE_PROCESS_SCHEDULED (1 << 0) 68}; 69 70/* 71 * bgp_table_iter_t 72 * 73 * Structure that holds state for iterating over a bgp table. 74 */ 75typedef struct bgp_table_iter_t_ 76{ 77 struct bgp_table *table; 78 route_table_iter_t rt_iter; 79} bgp_table_iter_t; 80 81extern struct bgp_table *bgp_table_init (afi_t, safi_t); 82extern void bgp_table_lock (struct bgp_table *); 83extern void bgp_table_unlock (struct bgp_table *); 84extern void bgp_table_finish (struct bgp_table **); 85 86 87/* 88 * bgp_node_from_rnode 89 * 90 * Returns the bgp_node structure corresponding to a route_node. 91 */ 92static inline struct bgp_node * 93bgp_node_from_rnode (struct route_node *rnode) 94{ 95 return (struct bgp_node *) rnode; 96} 97 98/* 99 * bgp_node_to_rnode 100 * 101 * Returns the route_node structure corresponding to a bgp_node. 102 */ 103static inline struct route_node * 104bgp_node_to_rnode (struct bgp_node *node) 105{ 106 return (struct route_node *) node; 107} 108 109/* 110 * bgp_node_table 111 * 112 * Returns the bgp_table that the given node is in. 113 */ 114static inline struct bgp_table * 115bgp_node_table (struct bgp_node *node) 116{ 117 return bgp_node_to_rnode (node)->table->info; 118} 119 120/* 121 * bgp_node_info 122 * 123 * Returns the 'info' pointer corresponding to a bgp node. 124 */ 125static inline void * 126bgp_node_info (const struct bgp_node *node) 127{ 128 return node->info; 129} 130 131/* 132 * bgp_node_set_info 133 */ 134static inline void 135bgp_node_set_info (struct bgp_node *node, void *info) 136{ 137 node->info = info; 138} 139 140/* 141 * bgp_node_prefix 142 */ 143static inline struct prefix * 144bgp_node_prefix (struct bgp_node *node) 145{ 146 return &node->p; 147} 148 149/* 150 * bgp_node_prefixlen 151 */ 152static inline u_char 153bgp_node_prefixlen (struct bgp_node *node) 154{ 155 return bgp_node_prefix (node)->prefixlen; 156} 157 158/* 159 * bgp_node_parent_nolock 160 * 161 * Gets the parent node of the given node without locking it. 162 */ 163static inline struct bgp_node * 164bgp_node_parent_nolock (struct bgp_node *node) 165{ 166 return bgp_node_from_rnode (node->parent); 167} 168 169/* 170 * bgp_unlock_node 171 */ 172static inline void 173bgp_unlock_node (struct bgp_node *node) 174{ 175 route_unlock_node (bgp_node_to_rnode (node)); 176} 177 178/* 179 * bgp_table_top_nolock 180 * 181 * Gets the top node in the table without locking it. 182 * 183 * @see bgp_table_top 184 */ 185static inline struct bgp_node * 186bgp_table_top_nolock (const struct bgp_table *const table) 187{ 188 return bgp_node_from_rnode (table->route_table->top); 189} 190 191/* 192 * bgp_table_top 193 */ 194static inline struct bgp_node * 195bgp_table_top (const struct bgp_table *const table) 196{ 197 return bgp_node_from_rnode (route_top (table->route_table)); 198} 199 200/* 201 * bgp_route_next 202 */ 203static inline struct bgp_node * 204bgp_route_next (struct bgp_node *node) 205{ 206 return bgp_node_from_rnode (route_next (bgp_node_to_rnode (node))); 207} 208 209/* 210 * bgp_route_next_until 211 */ 212static inline struct bgp_node * 213bgp_route_next_until (struct bgp_node *node, struct bgp_node *limit) 214{ 215 struct route_node *rnode; 216 217 rnode = route_next_until (bgp_node_to_rnode (node), 218 bgp_node_to_rnode (limit)); 219 return bgp_node_from_rnode (rnode); 220} 221 222/* 223 * bgp_node_get 224 */ 225static inline struct bgp_node * 226bgp_node_get (struct bgp_table *const table, struct prefix *p) 227{ 228 return bgp_node_from_rnode (route_node_get (table->route_table, p)); 229} 230 231/* 232 * bgp_node_lookup 233 */ 234static inline struct bgp_node * 235bgp_node_lookup (const struct bgp_table *const table, struct prefix *p) 236{ 237 return bgp_node_from_rnode (route_node_lookup (table->route_table, p)); 238} 239 240/* 241 * bgp_lock_node 242 */ 243static inline struct bgp_node * 244bgp_lock_node (struct bgp_node *node) 245{ 246 return bgp_node_from_rnode (route_lock_node (bgp_node_to_rnode (node))); 247} 248 249/* 250 * bgp_node_match 251 */ 252static inline struct bgp_node * 253bgp_node_match (const struct bgp_table *table, struct prefix *p) 254{ 255 return bgp_node_from_rnode (route_node_match (table->route_table, p)); 256} 257 258/* 259 * bgp_node_match_ipv4 260 */ 261static inline struct bgp_node * 262bgp_node_match_ipv4 (const struct bgp_table *table, struct in_addr *addr) 263{ 264 return bgp_node_from_rnode (route_node_match_ipv4 (table->route_table, 265 addr)); 266} 267 268#ifdef HAVE_IPV6 269 270/* 271 * bgp_node_match_ipv6 272 */ 273static inline struct bgp_node * 274bgp_node_match_ipv6 (const struct bgp_table *table, struct in6_addr *addr) 275{ 276 return bgp_node_from_rnode (route_node_match_ipv6 (table->route_table, 277 addr)); 278} 279 280#endif /* HAVE_IPV6 */ 281 282static inline unsigned long 283bgp_table_count (const struct bgp_table *const table) 284{ 285 return route_table_count (table->route_table); 286} 287 288/* 289 * bgp_table_get_next 290 */ 291static inline struct bgp_node * 292bgp_table_get_next (const struct bgp_table *table, struct prefix *p) 293{ 294 return bgp_node_from_rnode (route_table_get_next (table->route_table, p)); 295} 296 297/* 298 * bgp_table_iter_init 299 */ 300static inline void 301bgp_table_iter_init (bgp_table_iter_t * iter, struct bgp_table *table) 302{ 303 bgp_table_lock (table); 304 iter->table = table; 305 route_table_iter_init (&iter->rt_iter, table->route_table); 306} 307 308/* 309 * bgp_table_iter_next 310 */ 311static inline struct bgp_node * 312bgp_table_iter_next (bgp_table_iter_t * iter) 313{ 314 return bgp_node_from_rnode (route_table_iter_next (&iter->rt_iter)); 315} 316 317/* 318 * bgp_table_iter_cleanup 319 */ 320static inline void 321bgp_table_iter_cleanup (bgp_table_iter_t * iter) 322{ 323 route_table_iter_cleanup (&iter->rt_iter); 324 bgp_table_unlock (iter->table); 325 iter->table = NULL; 326} 327 328/* 329 * bgp_table_iter_pause 330 */ 331static inline void 332bgp_table_iter_pause (bgp_table_iter_t * iter) 333{ 334 route_table_iter_pause (&iter->rt_iter); 335} 336 337/* 338 * bgp_table_iter_is_done 339 */ 340static inline int 341bgp_table_iter_is_done (bgp_table_iter_t * iter) 342{ 343 return route_table_iter_is_done (&iter->rt_iter); 344} 345 346/* 347 * bgp_table_iter_started 348 */ 349static inline int 350bgp_table_iter_started (bgp_table_iter_t * iter) 351{ 352 return route_table_iter_started (&iter->rt_iter); 353} 354 355#endif /* _QUAGGA_BGP_TABLE_H */ 356