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 | /* |
Avneesh Sachdev | 6717404 | 2012-08-17 08:19:49 -0700 | [diff] [blame] | 121 | * bgp_node_parent_nolock |
| 122 | * |
| 123 | * Gets the parent node of the given node without locking it. |
| 124 | */ |
| 125 | static inline struct bgp_node * |
| 126 | bgp_node_parent_nolock (struct bgp_node *node) |
| 127 | { |
| 128 | return bgp_node_from_rnode (node->parent); |
| 129 | } |
| 130 | |
| 131 | /* |
| 132 | * bgp_unlock_node |
| 133 | */ |
| 134 | static inline void |
| 135 | bgp_unlock_node (struct bgp_node *node) |
| 136 | { |
| 137 | route_unlock_node (bgp_node_to_rnode (node)); |
| 138 | } |
| 139 | |
| 140 | /* |
| 141 | * bgp_table_top_nolock |
| 142 | * |
| 143 | * Gets the top node in the table without locking it. |
| 144 | * |
| 145 | * @see bgp_table_top |
| 146 | */ |
| 147 | static inline struct bgp_node * |
| 148 | bgp_table_top_nolock (const struct bgp_table *const table) |
| 149 | { |
| 150 | return bgp_node_from_rnode (table->route_table->top); |
| 151 | } |
| 152 | |
| 153 | /* |
| 154 | * bgp_table_top |
| 155 | */ |
| 156 | static inline struct bgp_node * |
| 157 | bgp_table_top (const struct bgp_table *const table) |
| 158 | { |
| 159 | return bgp_node_from_rnode (route_top (table->route_table)); |
| 160 | } |
| 161 | |
| 162 | /* |
| 163 | * bgp_route_next |
| 164 | */ |
| 165 | static inline struct bgp_node * |
| 166 | bgp_route_next (struct bgp_node *node) |
| 167 | { |
| 168 | return bgp_node_from_rnode (route_next (bgp_node_to_rnode (node))); |
| 169 | } |
| 170 | |
| 171 | /* |
| 172 | * bgp_route_next_until |
| 173 | */ |
| 174 | static inline struct bgp_node * |
| 175 | bgp_route_next_until (struct bgp_node *node, struct bgp_node *limit) |
| 176 | { |
| 177 | struct route_node *rnode; |
| 178 | |
| 179 | rnode = route_next_until (bgp_node_to_rnode (node), |
| 180 | bgp_node_to_rnode (limit)); |
| 181 | return bgp_node_from_rnode (rnode); |
| 182 | } |
| 183 | |
| 184 | /* |
| 185 | * bgp_node_get |
| 186 | */ |
| 187 | static inline struct bgp_node * |
| 188 | bgp_node_get (struct bgp_table *const table, struct prefix *p) |
| 189 | { |
| 190 | return bgp_node_from_rnode (route_node_get (table->route_table, p)); |
| 191 | } |
| 192 | |
| 193 | /* |
| 194 | * bgp_node_lookup |
| 195 | */ |
| 196 | static inline struct bgp_node * |
| 197 | bgp_node_lookup (const struct bgp_table *const table, struct prefix *p) |
| 198 | { |
| 199 | return bgp_node_from_rnode (route_node_lookup (table->route_table, p)); |
| 200 | } |
| 201 | |
| 202 | /* |
| 203 | * bgp_lock_node |
| 204 | */ |
| 205 | static inline struct bgp_node * |
| 206 | bgp_lock_node (struct bgp_node *node) |
| 207 | { |
| 208 | return bgp_node_from_rnode (route_lock_node (bgp_node_to_rnode (node))); |
| 209 | } |
| 210 | |
| 211 | /* |
| 212 | * bgp_node_match |
| 213 | */ |
| 214 | static inline struct bgp_node * |
| 215 | bgp_node_match (const struct bgp_table *table, struct prefix *p) |
| 216 | { |
| 217 | return bgp_node_from_rnode (route_node_match (table->route_table, p)); |
| 218 | } |
| 219 | |
| 220 | /* |
| 221 | * bgp_node_match_ipv4 |
| 222 | */ |
| 223 | static inline struct bgp_node * |
| 224 | bgp_node_match_ipv4 (const struct bgp_table *table, struct in_addr *addr) |
| 225 | { |
| 226 | return bgp_node_from_rnode (route_node_match_ipv4 (table->route_table, |
| 227 | addr)); |
| 228 | } |
| 229 | |
Avneesh Sachdev | 6717404 | 2012-08-17 08:19:49 -0700 | [diff] [blame] | 230 | /* |
| 231 | * bgp_node_match_ipv6 |
| 232 | */ |
| 233 | static inline struct bgp_node * |
| 234 | bgp_node_match_ipv6 (const struct bgp_table *table, struct in6_addr *addr) |
| 235 | { |
| 236 | return bgp_node_from_rnode (route_node_match_ipv6 (table->route_table, |
| 237 | addr)); |
| 238 | } |
| 239 | |
Avneesh Sachdev | 6717404 | 2012-08-17 08:19:49 -0700 | [diff] [blame] | 240 | static inline unsigned long |
| 241 | bgp_table_count (const struct bgp_table *const table) |
| 242 | { |
| 243 | return route_table_count (table->route_table); |
| 244 | } |
| 245 | |
Avneesh Sachdev | 28971c8 | 2012-08-17 08:19:50 -0700 | [diff] [blame] | 246 | /* |
| 247 | * bgp_table_get_next |
| 248 | */ |
| 249 | static inline struct bgp_node * |
| 250 | bgp_table_get_next (const struct bgp_table *table, struct prefix *p) |
| 251 | { |
| 252 | return bgp_node_from_rnode (route_table_get_next (table->route_table, p)); |
| 253 | } |
| 254 | |
| 255 | /* |
| 256 | * bgp_table_iter_init |
| 257 | */ |
| 258 | static inline void |
| 259 | bgp_table_iter_init (bgp_table_iter_t * iter, struct bgp_table *table) |
| 260 | { |
| 261 | bgp_table_lock (table); |
| 262 | iter->table = table; |
| 263 | route_table_iter_init (&iter->rt_iter, table->route_table); |
| 264 | } |
| 265 | |
| 266 | /* |
| 267 | * bgp_table_iter_next |
| 268 | */ |
| 269 | static inline struct bgp_node * |
| 270 | bgp_table_iter_next (bgp_table_iter_t * iter) |
| 271 | { |
| 272 | return bgp_node_from_rnode (route_table_iter_next (&iter->rt_iter)); |
| 273 | } |
| 274 | |
| 275 | /* |
| 276 | * bgp_table_iter_cleanup |
| 277 | */ |
| 278 | static inline void |
| 279 | bgp_table_iter_cleanup (bgp_table_iter_t * iter) |
| 280 | { |
| 281 | route_table_iter_cleanup (&iter->rt_iter); |
| 282 | bgp_table_unlock (iter->table); |
| 283 | iter->table = NULL; |
| 284 | } |
| 285 | |
| 286 | /* |
| 287 | * bgp_table_iter_pause |
| 288 | */ |
| 289 | static inline void |
| 290 | bgp_table_iter_pause (bgp_table_iter_t * iter) |
| 291 | { |
| 292 | route_table_iter_pause (&iter->rt_iter); |
| 293 | } |
| 294 | |
| 295 | /* |
| 296 | * bgp_table_iter_is_done |
| 297 | */ |
| 298 | static inline int |
| 299 | bgp_table_iter_is_done (bgp_table_iter_t * iter) |
| 300 | { |
| 301 | return route_table_iter_is_done (&iter->rt_iter); |
| 302 | } |
| 303 | |
| 304 | /* |
| 305 | * bgp_table_iter_started |
| 306 | */ |
| 307 | static inline int |
| 308 | bgp_table_iter_started (bgp_table_iter_t * iter) |
| 309 | { |
| 310 | return route_table_iter_started (&iter->rt_iter); |
| 311 | } |
| 312 | |
paul | 00d252c | 2005-05-23 14:19:54 +0000 | [diff] [blame] | 313 | #endif /* _QUAGGA_BGP_TABLE_H */ |