blob: ff42399f1a463c0d3954f2bf4dffb698fd430c6b [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* 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
paul00d252c2005-05-23 14:19:54 +000021#ifndef _QUAGGA_BGP_TABLE_H
22#define _QUAGGA_BGP_TABLE_H
23
Avneesh Sachdev67174042012-08-17 08:19:49 -070024#include "table.h"
25
paulfee0f4c2004-09-13 05:12:46 +000026typedef enum
27{
28 BGP_TABLE_MAIN,
29 BGP_TABLE_RSCLIENT,
30} bgp_table_t;
31
paul718e3742002-12-13 20:15:29 +000032struct bgp_table
33{
paulfee0f4c2004-09-13 05:12:46 +000034 bgp_table_t type;
Paul Jakma64e580a2006-02-21 01:09:01 +000035
36 /* afi/safi of this table */
37 afi_t afi;
38 safi_t safi;
39
Chris Caputo228da422009-07-18 05:44:03 +000040 int lock;
41
paulfee0f4c2004-09-13 05:12:46 +000042 /* The owner of this 'bgp_table' structure. */
Chris Caputo228da422009-07-18 05:44:03 +000043 struct peer *owner;
paulfee0f4c2004-09-13 05:12:46 +000044
Avneesh Sachdev67174042012-08-17 08:19:49 -070045 struct route_table *route_table;
paul718e3742002-12-13 20:15:29 +000046};
47
48struct bgp_node
49{
Avneesh Sachdev67174042012-08-17 08:19:49 -070050 /*
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;
paul718e3742002-12-13 20:15:29 +000059
60 struct bgp_adj_out *adj_out;
61
62 struct bgp_adj_in *adj_in;
63
paul718e3742002-12-13 20:15:29 +000064 struct bgp_node *prn;
paul200df112005-06-01 11:17:05 +000065
66 u_char flags;
67#define BGP_NODE_PROCESS_SCHEDULED (1 << 0)
paul718e3742002-12-13 20:15:29 +000068};
69
Paul Jakma64e580a2006-02-21 01:09:01 +000070extern struct bgp_table *bgp_table_init (afi_t, safi_t);
Chris Caputo228da422009-07-18 05:44:03 +000071extern void bgp_table_lock (struct bgp_table *);
72extern void bgp_table_unlock (struct bgp_table *);
Paul Jakmab608d5b2008-07-02 02:12:07 +000073extern void bgp_table_finish (struct bgp_table **);
Avneesh Sachdev67174042012-08-17 08:19:49 -070074
75
76/*
77 * bgp_node_from_rnode
78 *
79 * Returns the bgp_node structure corresponding to a route_node.
80 */
81static inline struct bgp_node *
82bgp_node_from_rnode (struct route_node *rnode)
83{
84 return (struct bgp_node *) rnode;
85}
86
87/*
88 * bgp_node_to_rnode
89 *
90 * Returns the route_node structure corresponding to a bgp_node.
91 */
92static inline struct route_node *
93bgp_node_to_rnode (struct bgp_node *node)
94{
95 return (struct route_node *) node;
96}
97
98/*
99 * bgp_node_table
100 *
101 * Returns the bgp_table that the given node is in.
102 */
103static inline struct bgp_table *
104bgp_node_table (struct bgp_node *node)
105{
106 return bgp_node_to_rnode (node)->table->info;
107}
108
109/*
110 * bgp_node_info
111 *
112 * Returns the 'info' pointer corresponding to a bgp node.
113 */
114static inline void *
115bgp_node_info (const struct bgp_node *node)
116{
117 return node->info;
118}
119
120/*
121 * bgp_node_set_info
122 */
123static inline void
124bgp_node_set_info (struct bgp_node *node, void *info)
125{
126 node->info = info;
127}
128
129/*
130 * bgp_node_prefix
131 */
132static inline struct prefix *
133bgp_node_prefix (struct bgp_node *node)
134{
135 return &node->p;
136}
137
138/*
139 * bgp_node_prefixlen
140 */
141static inline u_char
142bgp_node_prefixlen (struct bgp_node *node)
143{
144 return bgp_node_prefix (node)->prefixlen;
145}
146
147/*
148 * bgp_node_parent_nolock
149 *
150 * Gets the parent node of the given node without locking it.
151 */
152static inline struct bgp_node *
153bgp_node_parent_nolock (struct bgp_node *node)
154{
155 return bgp_node_from_rnode (node->parent);
156}
157
158/*
159 * bgp_unlock_node
160 */
161static inline void
162bgp_unlock_node (struct bgp_node *node)
163{
164 route_unlock_node (bgp_node_to_rnode (node));
165}
166
167/*
168 * bgp_table_top_nolock
169 *
170 * Gets the top node in the table without locking it.
171 *
172 * @see bgp_table_top
173 */
174static inline struct bgp_node *
175bgp_table_top_nolock (const struct bgp_table *const table)
176{
177 return bgp_node_from_rnode (table->route_table->top);
178}
179
180/*
181 * bgp_table_top
182 */
183static inline struct bgp_node *
184bgp_table_top (const struct bgp_table *const table)
185{
186 return bgp_node_from_rnode (route_top (table->route_table));
187}
188
189/*
190 * bgp_route_next
191 */
192static inline struct bgp_node *
193bgp_route_next (struct bgp_node *node)
194{
195 return bgp_node_from_rnode (route_next (bgp_node_to_rnode (node)));
196}
197
198/*
199 * bgp_route_next_until
200 */
201static inline struct bgp_node *
202bgp_route_next_until (struct bgp_node *node, struct bgp_node *limit)
203{
204 struct route_node *rnode;
205
206 rnode = route_next_until (bgp_node_to_rnode (node),
207 bgp_node_to_rnode (limit));
208 return bgp_node_from_rnode (rnode);
209}
210
211/*
212 * bgp_node_get
213 */
214static inline struct bgp_node *
215bgp_node_get (struct bgp_table *const table, struct prefix *p)
216{
217 return bgp_node_from_rnode (route_node_get (table->route_table, p));
218}
219
220/*
221 * bgp_node_lookup
222 */
223static inline struct bgp_node *
224bgp_node_lookup (const struct bgp_table *const table, struct prefix *p)
225{
226 return bgp_node_from_rnode (route_node_lookup (table->route_table, p));
227}
228
229/*
230 * bgp_lock_node
231 */
232static inline struct bgp_node *
233bgp_lock_node (struct bgp_node *node)
234{
235 return bgp_node_from_rnode (route_lock_node (bgp_node_to_rnode (node)));
236}
237
238/*
239 * bgp_node_match
240 */
241static inline struct bgp_node *
242bgp_node_match (const struct bgp_table *table, struct prefix *p)
243{
244 return bgp_node_from_rnode (route_node_match (table->route_table, p));
245}
246
247/*
248 * bgp_node_match_ipv4
249 */
250static inline struct bgp_node *
251bgp_node_match_ipv4 (const struct bgp_table *table, struct in_addr *addr)
252{
253 return bgp_node_from_rnode (route_node_match_ipv4 (table->route_table,
254 addr));
255}
256
paul718e3742002-12-13 20:15:29 +0000257#ifdef HAVE_IPV6
Avneesh Sachdev67174042012-08-17 08:19:49 -0700258
259/*
260 * bgp_node_match_ipv6
261 */
262static inline struct bgp_node *
263bgp_node_match_ipv6 (const struct bgp_table *table, struct in6_addr *addr)
264{
265 return bgp_node_from_rnode (route_node_match_ipv6 (table->route_table,
266 addr));
267}
268
paul718e3742002-12-13 20:15:29 +0000269#endif /* HAVE_IPV6 */
Avneesh Sachdev67174042012-08-17 08:19:49 -0700270
271static inline unsigned long
272bgp_table_count (const struct bgp_table *const table)
273{
274 return route_table_count (table->route_table);
275}
276
paul00d252c2005-05-23 14:19:54 +0000277#endif /* _QUAGGA_BGP_TABLE_H */