123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314 |
- /* BGP routing table
- Copyright (C) 1998, 2001 Kunihiro Ishiguro
- This file is part of GNU Zebra.
- GNU Zebra is free software; you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by the
- Free Software Foundation; either version 2, or (at your option) any
- later version.
- GNU Zebra is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with GNU Zebra; see the file COPYING. If not, write to the Free
- Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- 02111-1307, USA. */
- #ifndef _QUAGGA_BGP_TABLE_H
- #define _QUAGGA_BGP_TABLE_H
- #include "table.h"
- typedef enum
- {
- BGP_TABLE_MAIN,
- BGP_TABLE_RSCLIENT,
- } bgp_table_t;
- struct bgp_table
- {
- bgp_table_t type;
-
- /* afi/safi of this table */
- afi_t afi;
- safi_t safi;
-
- int lock;
- /* The owner of this 'bgp_table' structure. */
- struct peer *owner;
- struct route_table *route_table;
- };
- struct bgp_node
- {
- /*
- * CAUTION
- *
- * These fields must be the very first fields in this structure.
- *
- * @see bgp_node_to_rnode
- * @see bgp_node_from_rnode
- */
- ROUTE_NODE_FIELDS
- struct bgp_adj_out *adj_out;
- struct bgp_adj_in *adj_in;
- struct bgp_node *prn;
- u_char flags;
- #define BGP_NODE_PROCESS_SCHEDULED (1 << 0)
- #define BGP_NODE_USER_CLEAR (1 << 1)
- };
- /*
- * bgp_table_iter_t
- *
- * Structure that holds state for iterating over a bgp table.
- */
- typedef struct bgp_table_iter_t_
- {
- struct bgp_table *table;
- route_table_iter_t rt_iter;
- } bgp_table_iter_t;
- extern struct bgp_table *bgp_table_init (afi_t, safi_t);
- extern void bgp_table_lock (struct bgp_table *);
- extern void bgp_table_unlock (struct bgp_table *);
- extern void bgp_table_finish (struct bgp_table **);
- /*
- * bgp_node_from_rnode
- *
- * Returns the bgp_node structure corresponding to a route_node.
- */
- static inline struct bgp_node *
- bgp_node_from_rnode (struct route_node *rnode)
- {
- return (struct bgp_node *) rnode;
- }
- /*
- * bgp_node_to_rnode
- *
- * Returns the route_node structure corresponding to a bgp_node.
- */
- static inline struct route_node *
- bgp_node_to_rnode (struct bgp_node *node)
- {
- return (struct route_node *) node;
- }
- /*
- * bgp_node_table
- *
- * Returns the bgp_table that the given node is in.
- */
- static inline struct bgp_table *
- bgp_node_table (struct bgp_node *node)
- {
- return bgp_node_to_rnode (node)->table->info;
- }
- /*
- * bgp_node_parent_nolock
- *
- * Gets the parent node of the given node without locking it.
- */
- static inline struct bgp_node *
- bgp_node_parent_nolock (struct bgp_node *node)
- {
- return bgp_node_from_rnode (node->parent);
- }
- /*
- * bgp_unlock_node
- */
- static inline void
- bgp_unlock_node (struct bgp_node *node)
- {
- route_unlock_node (bgp_node_to_rnode (node));
- }
- /*
- * bgp_table_top_nolock
- *
- * Gets the top node in the table without locking it.
- *
- * @see bgp_table_top
- */
- static inline struct bgp_node *
- bgp_table_top_nolock (const struct bgp_table *const table)
- {
- return bgp_node_from_rnode (table->route_table->top);
- }
- /*
- * bgp_table_top
- */
- static inline struct bgp_node *
- bgp_table_top (const struct bgp_table *const table)
- {
- return bgp_node_from_rnode (route_top (table->route_table));
- }
- /*
- * bgp_route_next
- */
- static inline struct bgp_node *
- bgp_route_next (struct bgp_node *node)
- {
- return bgp_node_from_rnode (route_next (bgp_node_to_rnode (node)));
- }
- /*
- * bgp_route_next_until
- */
- static inline struct bgp_node *
- bgp_route_next_until (struct bgp_node *node, struct bgp_node *limit)
- {
- struct route_node *rnode;
- rnode = route_next_until (bgp_node_to_rnode (node),
- bgp_node_to_rnode (limit));
- return bgp_node_from_rnode (rnode);
- }
- /*
- * bgp_node_get
- */
- static inline struct bgp_node *
- bgp_node_get (struct bgp_table *const table, struct prefix *p)
- {
- return bgp_node_from_rnode (route_node_get (table->route_table, p));
- }
- /*
- * bgp_node_lookup
- */
- static inline struct bgp_node *
- bgp_node_lookup (const struct bgp_table *const table, struct prefix *p)
- {
- return bgp_node_from_rnode (route_node_lookup (table->route_table, p));
- }
- /*
- * bgp_lock_node
- */
- static inline struct bgp_node *
- bgp_lock_node (struct bgp_node *node)
- {
- return bgp_node_from_rnode (route_lock_node (bgp_node_to_rnode (node)));
- }
- /*
- * bgp_node_match
- */
- static inline struct bgp_node *
- bgp_node_match (const struct bgp_table *table, struct prefix *p)
- {
- return bgp_node_from_rnode (route_node_match (table->route_table, p));
- }
- /*
- * bgp_node_match_ipv4
- */
- static inline struct bgp_node *
- bgp_node_match_ipv4 (const struct bgp_table *table, struct in_addr *addr)
- {
- return bgp_node_from_rnode (route_node_match_ipv4 (table->route_table,
- addr));
- }
- /*
- * bgp_node_match_ipv6
- */
- static inline struct bgp_node *
- bgp_node_match_ipv6 (const struct bgp_table *table, struct in6_addr *addr)
- {
- return bgp_node_from_rnode (route_node_match_ipv6 (table->route_table,
- addr));
- }
- static inline unsigned long
- bgp_table_count (const struct bgp_table *const table)
- {
- return route_table_count (table->route_table);
- }
- /*
- * bgp_table_get_next
- */
- static inline struct bgp_node *
- bgp_table_get_next (const struct bgp_table *table, struct prefix *p)
- {
- return bgp_node_from_rnode (route_table_get_next (table->route_table, p));
- }
- /*
- * bgp_table_iter_init
- */
- static inline void
- bgp_table_iter_init (bgp_table_iter_t * iter, struct bgp_table *table)
- {
- bgp_table_lock (table);
- iter->table = table;
- route_table_iter_init (&iter->rt_iter, table->route_table);
- }
- /*
- * bgp_table_iter_next
- */
- static inline struct bgp_node *
- bgp_table_iter_next (bgp_table_iter_t * iter)
- {
- return bgp_node_from_rnode (route_table_iter_next (&iter->rt_iter));
- }
- /*
- * bgp_table_iter_cleanup
- */
- static inline void
- bgp_table_iter_cleanup (bgp_table_iter_t * iter)
- {
- route_table_iter_cleanup (&iter->rt_iter);
- bgp_table_unlock (iter->table);
- iter->table = NULL;
- }
- /*
- * bgp_table_iter_pause
- */
- static inline void
- bgp_table_iter_pause (bgp_table_iter_t * iter)
- {
- route_table_iter_pause (&iter->rt_iter);
- }
- /*
- * bgp_table_iter_is_done
- */
- static inline int
- bgp_table_iter_is_done (bgp_table_iter_t * iter)
- {
- return route_table_iter_is_done (&iter->rt_iter);
- }
- /*
- * bgp_table_iter_started
- */
- static inline int
- bgp_table_iter_started (bgp_table_iter_t * iter)
- {
- return route_table_iter_started (&iter->rt_iter);
- }
- #endif /* _QUAGGA_BGP_TABLE_H */
|