bgp_table.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. /* BGP routing table
  2. Copyright (C) 1998, 2001 Kunihiro Ishiguro
  3. This file is part of GNU Zebra.
  4. GNU Zebra is free software; you can redistribute it and/or modify it
  5. under the terms of the GNU General Public License as published by the
  6. Free Software Foundation; either version 2, or (at your option) any
  7. later version.
  8. GNU Zebra is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Zebra; see the file COPYING. If not, write to the Free
  14. Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  15. 02111-1307, USA. */
  16. #ifndef _QUAGGA_BGP_TABLE_H
  17. #define _QUAGGA_BGP_TABLE_H
  18. #include "table.h"
  19. typedef enum
  20. {
  21. BGP_TABLE_MAIN,
  22. BGP_TABLE_RSCLIENT,
  23. } bgp_table_t;
  24. struct bgp_table
  25. {
  26. bgp_table_t type;
  27. /* afi/safi of this table */
  28. afi_t afi;
  29. safi_t safi;
  30. int lock;
  31. /* The owner of this 'bgp_table' structure. */
  32. struct peer *owner;
  33. struct route_table *route_table;
  34. };
  35. struct bgp_node
  36. {
  37. /*
  38. * CAUTION
  39. *
  40. * These fields must be the very first fields in this structure.
  41. *
  42. * @see bgp_node_to_rnode
  43. * @see bgp_node_from_rnode
  44. */
  45. ROUTE_NODE_FIELDS;
  46. struct bgp_adj_out *adj_out;
  47. struct bgp_adj_in *adj_in;
  48. struct bgp_node *prn;
  49. u_char flags;
  50. #define BGP_NODE_PROCESS_SCHEDULED (1 << 0)
  51. };
  52. extern struct bgp_table *bgp_table_init (afi_t, safi_t);
  53. extern void bgp_table_lock (struct bgp_table *);
  54. extern void bgp_table_unlock (struct bgp_table *);
  55. extern void bgp_table_finish (struct bgp_table **);
  56. /*
  57. * bgp_node_from_rnode
  58. *
  59. * Returns the bgp_node structure corresponding to a route_node.
  60. */
  61. static inline struct bgp_node *
  62. bgp_node_from_rnode (struct route_node *rnode)
  63. {
  64. return (struct bgp_node *) rnode;
  65. }
  66. /*
  67. * bgp_node_to_rnode
  68. *
  69. * Returns the route_node structure corresponding to a bgp_node.
  70. */
  71. static inline struct route_node *
  72. bgp_node_to_rnode (struct bgp_node *node)
  73. {
  74. return (struct route_node *) node;
  75. }
  76. /*
  77. * bgp_node_table
  78. *
  79. * Returns the bgp_table that the given node is in.
  80. */
  81. static inline struct bgp_table *
  82. bgp_node_table (struct bgp_node *node)
  83. {
  84. return bgp_node_to_rnode (node)->table->info;
  85. }
  86. /*
  87. * bgp_node_info
  88. *
  89. * Returns the 'info' pointer corresponding to a bgp node.
  90. */
  91. static inline void *
  92. bgp_node_info (const struct bgp_node *node)
  93. {
  94. return node->info;
  95. }
  96. /*
  97. * bgp_node_set_info
  98. */
  99. static inline void
  100. bgp_node_set_info (struct bgp_node *node, void *info)
  101. {
  102. node->info = info;
  103. }
  104. /*
  105. * bgp_node_prefix
  106. */
  107. static inline struct prefix *
  108. bgp_node_prefix (struct bgp_node *node)
  109. {
  110. return &node->p;
  111. }
  112. /*
  113. * bgp_node_prefixlen
  114. */
  115. static inline u_char
  116. bgp_node_prefixlen (struct bgp_node *node)
  117. {
  118. return bgp_node_prefix (node)->prefixlen;
  119. }
  120. /*
  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. * bgp_unlock_node
  132. */
  133. static inline void
  134. bgp_unlock_node (struct bgp_node *node)
  135. {
  136. route_unlock_node (bgp_node_to_rnode (node));
  137. }
  138. /*
  139. * bgp_table_top_nolock
  140. *
  141. * Gets the top node in the table without locking it.
  142. *
  143. * @see bgp_table_top
  144. */
  145. static inline struct bgp_node *
  146. bgp_table_top_nolock (const struct bgp_table *const table)
  147. {
  148. return bgp_node_from_rnode (table->route_table->top);
  149. }
  150. /*
  151. * bgp_table_top
  152. */
  153. static inline struct bgp_node *
  154. bgp_table_top (const struct bgp_table *const table)
  155. {
  156. return bgp_node_from_rnode (route_top (table->route_table));
  157. }
  158. /*
  159. * bgp_route_next
  160. */
  161. static inline struct bgp_node *
  162. bgp_route_next (struct bgp_node *node)
  163. {
  164. return bgp_node_from_rnode (route_next (bgp_node_to_rnode (node)));
  165. }
  166. /*
  167. * bgp_route_next_until
  168. */
  169. static inline struct bgp_node *
  170. bgp_route_next_until (struct bgp_node *node, struct bgp_node *limit)
  171. {
  172. struct route_node *rnode;
  173. rnode = route_next_until (bgp_node_to_rnode (node),
  174. bgp_node_to_rnode (limit));
  175. return bgp_node_from_rnode (rnode);
  176. }
  177. /*
  178. * bgp_node_get
  179. */
  180. static inline struct bgp_node *
  181. bgp_node_get (struct bgp_table *const table, struct prefix *p)
  182. {
  183. return bgp_node_from_rnode (route_node_get (table->route_table, p));
  184. }
  185. /*
  186. * bgp_node_lookup
  187. */
  188. static inline struct bgp_node *
  189. bgp_node_lookup (const struct bgp_table *const table, struct prefix *p)
  190. {
  191. return bgp_node_from_rnode (route_node_lookup (table->route_table, p));
  192. }
  193. /*
  194. * bgp_lock_node
  195. */
  196. static inline struct bgp_node *
  197. bgp_lock_node (struct bgp_node *node)
  198. {
  199. return bgp_node_from_rnode (route_lock_node (bgp_node_to_rnode (node)));
  200. }
  201. /*
  202. * bgp_node_match
  203. */
  204. static inline struct bgp_node *
  205. bgp_node_match (const struct bgp_table *table, struct prefix *p)
  206. {
  207. return bgp_node_from_rnode (route_node_match (table->route_table, p));
  208. }
  209. /*
  210. * bgp_node_match_ipv4
  211. */
  212. static inline struct bgp_node *
  213. bgp_node_match_ipv4 (const struct bgp_table *table, struct in_addr *addr)
  214. {
  215. return bgp_node_from_rnode (route_node_match_ipv4 (table->route_table,
  216. addr));
  217. }
  218. #ifdef HAVE_IPV6
  219. /*
  220. * bgp_node_match_ipv6
  221. */
  222. static inline struct bgp_node *
  223. bgp_node_match_ipv6 (const struct bgp_table *table, struct in6_addr *addr)
  224. {
  225. return bgp_node_from_rnode (route_node_match_ipv6 (table->route_table,
  226. addr));
  227. }
  228. #endif /* HAVE_IPV6 */
  229. static inline unsigned long
  230. bgp_table_count (const struct bgp_table *const table)
  231. {
  232. return route_table_count (table->route_table);
  233. }
  234. #endif /* _QUAGGA_BGP_TABLE_H */