paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1 | /* BGP routing table |
| 2 | Copyright (C) 1998, 2001 Kunihiro Ishiguro |
| 3 | |
| 4 | This file is part of GNU Zebra. |
| 5 | |
| 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 |
| 9 | later version. |
| 10 | |
| 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. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with GNU Zebra; see the file COPYING. If not, write to the Free |
| 18 | Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 19 | 02111-1307, USA. */ |
| 20 | |
paul | 00d252c | 2005-05-23 14:19:54 +0000 | [diff] [blame] | 21 | #ifndef _QUAGGA_BGP_TABLE_H |
| 22 | #define _QUAGGA_BGP_TABLE_H |
| 23 | |
Avneesh Sachdev | 6717404 | 2012-08-17 08:19:49 -0700 | [diff] [blame] | 24 | #include "table.h" |
| 25 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 26 | typedef enum |
| 27 | { |
| 28 | BGP_TABLE_MAIN, |
| 29 | BGP_TABLE_RSCLIENT, |
| 30 | } bgp_table_t; |
| 31 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 32 | struct bgp_table |
| 33 | { |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 34 | bgp_table_t type; |
Paul Jakma | 64e580a | 2006-02-21 01:09:01 +0000 | [diff] [blame] | 35 | |
| 36 | /* afi/safi of this table */ |
| 37 | afi_t afi; |
| 38 | safi_t safi; |
| 39 | |
Chris Caputo | 228da42 | 2009-07-18 05:44:03 +0000 | [diff] [blame] | 40 | int lock; |
| 41 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 42 | /* The owner of this 'bgp_table' structure. */ |
Chris Caputo | 228da42 | 2009-07-18 05:44:03 +0000 | [diff] [blame] | 43 | struct peer *owner; |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 44 | |
Avneesh Sachdev | 6717404 | 2012-08-17 08:19:49 -0700 | [diff] [blame] | 45 | struct route_table *route_table; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 46 | }; |
| 47 | |
| 48 | struct bgp_node |
| 49 | { |
Avneesh Sachdev | 6717404 | 2012-08-17 08:19:49 -0700 | [diff] [blame] | 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 | */ |
David Lamparter | b7d5021 | 2015-03-03 08:53:18 +0100 | [diff] [blame] | 58 | ROUTE_NODE_FIELDS |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 59 | |
| 60 | struct bgp_adj_out *adj_out; |
| 61 | |
| 62 | struct bgp_adj_in *adj_in; |
| 63 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 64 | struct bgp_node *prn; |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 65 | |
| 66 | u_char flags; |
| 67 | #define BGP_NODE_PROCESS_SCHEDULED (1 << 0) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 68 | }; |
| 69 | |
Avneesh Sachdev | 28971c8 | 2012-08-17 08:19:50 -0700 | [diff] [blame] | 70 | /* |
| 71 | * bgp_table_iter_t |
| 72 | * |
| 73 | * Structure that holds state for iterating over a bgp table. |
| 74 | */ |
| 75 | typedef struct bgp_table_iter_t_ |
| 76 | { |
| 77 | struct bgp_table *table; |
| 78 | route_table_iter_t rt_iter; |
| 79 | } bgp_table_iter_t; |
| 80 | |
Paul Jakma | 64e580a | 2006-02-21 01:09:01 +0000 | [diff] [blame] | 81 | extern struct bgp_table *bgp_table_init (afi_t, safi_t); |
Chris Caputo | 228da42 | 2009-07-18 05:44:03 +0000 | [diff] [blame] | 82 | extern void bgp_table_lock (struct bgp_table *); |
| 83 | extern void bgp_table_unlock (struct bgp_table *); |
Paul Jakma | b608d5b | 2008-07-02 02:12:07 +0000 | [diff] [blame] | 84 | extern void bgp_table_finish (struct bgp_table **); |
Avneesh Sachdev | 6717404 | 2012-08-17 08:19:49 -0700 | [diff] [blame] | 85 | |
| 86 | |
| 87 | /* |
| 88 | * bgp_node_from_rnode |
| 89 | * |
| 90 | * Returns the bgp_node structure corresponding to a route_node. |
| 91 | */ |
| 92 | static inline struct bgp_node * |
| 93 | bgp_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 | */ |
| 103 | static inline struct route_node * |
| 104 | bgp_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 | */ |
| 114 | static inline struct bgp_table * |
| 115 | bgp_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 | */ |
| 125 | static inline void * |
| 126 | bgp_node_info (const struct bgp_node *node) |
| 127 | { |
| 128 | return node->info; |
| 129 | } |
| 130 | |
| 131 | /* |
| 132 | * bgp_node_set_info |
| 133 | */ |
| 134 | static inline void |
| 135 | bgp_node_set_info (struct bgp_node *node, void *info) |
| 136 | { |
| 137 | node->info = info; |
| 138 | } |
| 139 | |
| 140 | /* |
| 141 | * bgp_node_prefix |
| 142 | */ |
| 143 | static inline struct prefix * |
| 144 | bgp_node_prefix (struct bgp_node *node) |
| 145 | { |
| 146 | return &node->p; |
| 147 | } |
| 148 | |
| 149 | /* |
| 150 | * bgp_node_prefixlen |
| 151 | */ |
| 152 | static inline u_char |
| 153 | bgp_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 | */ |
| 163 | static inline struct bgp_node * |
| 164 | bgp_node_parent_nolock (struct bgp_node *node) |
| 165 | { |
| 166 | return bgp_node_from_rnode (node->parent); |
| 167 | } |
| 168 | |
| 169 | /* |
| 170 | * bgp_unlock_node |
| 171 | */ |
| 172 | static inline void |
| 173 | bgp_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 | */ |
| 185 | static inline struct bgp_node * |
| 186 | bgp_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 | */ |
| 194 | static inline struct bgp_node * |
| 195 | bgp_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 | */ |
| 203 | static inline struct bgp_node * |
| 204 | bgp_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 | */ |
| 212 | static inline struct bgp_node * |
| 213 | bgp_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 | */ |
| 225 | static inline struct bgp_node * |
| 226 | bgp_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 | */ |
| 234 | static inline struct bgp_node * |
| 235 | bgp_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 | */ |
| 243 | static inline struct bgp_node * |
| 244 | bgp_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 | */ |
| 252 | static inline struct bgp_node * |
| 253 | bgp_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 | */ |
| 261 | static inline struct bgp_node * |
| 262 | bgp_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 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 268 | #ifdef HAVE_IPV6 |
Avneesh Sachdev | 6717404 | 2012-08-17 08:19:49 -0700 | [diff] [blame] | 269 | |
| 270 | /* |
| 271 | * bgp_node_match_ipv6 |
| 272 | */ |
| 273 | static inline struct bgp_node * |
| 274 | bgp_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 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 280 | #endif /* HAVE_IPV6 */ |
Avneesh Sachdev | 6717404 | 2012-08-17 08:19:49 -0700 | [diff] [blame] | 281 | |
| 282 | static inline unsigned long |
| 283 | bgp_table_count (const struct bgp_table *const table) |
| 284 | { |
| 285 | return route_table_count (table->route_table); |
| 286 | } |
| 287 | |
Avneesh Sachdev | 28971c8 | 2012-08-17 08:19:50 -0700 | [diff] [blame] | 288 | /* |
| 289 | * bgp_table_get_next |
| 290 | */ |
| 291 | static inline struct bgp_node * |
| 292 | bgp_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 | */ |
| 300 | static inline void |
| 301 | bgp_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 | */ |
| 311 | static inline struct bgp_node * |
| 312 | bgp_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 | */ |
| 320 | static inline void |
| 321 | bgp_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 | */ |
| 331 | static inline void |
| 332 | bgp_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 | */ |
| 340 | static inline int |
| 341 | bgp_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 | */ |
| 349 | static inline int |
| 350 | bgp_table_iter_started (bgp_table_iter_t * iter) |
| 351 | { |
| 352 | return route_table_iter_started (&iter->rt_iter); |
| 353 | } |
| 354 | |
paul | 00d252c | 2005-05-23 14:19:54 +0000 | [diff] [blame] | 355 | #endif /* _QUAGGA_BGP_TABLE_H */ |