bgp_table.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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. /*
  53. * bgp_table_iter_t
  54. *
  55. * Structure that holds state for iterating over a bgp table.
  56. */
  57. typedef struct bgp_table_iter_t_
  58. {
  59. struct bgp_table *table;
  60. route_table_iter_t rt_iter;
  61. } bgp_table_iter_t;
  62. extern struct bgp_table *bgp_table_init (afi_t, safi_t);
  63. extern void bgp_table_lock (struct bgp_table *);
  64. extern void bgp_table_unlock (struct bgp_table *);
  65. extern void bgp_table_finish (struct bgp_table **);
  66. /*
  67. * bgp_node_from_rnode
  68. *
  69. * Returns the bgp_node structure corresponding to a route_node.
  70. */
  71. static inline struct bgp_node *
  72. bgp_node_from_rnode (struct route_node *rnode)
  73. {
  74. return (struct bgp_node *) rnode;
  75. }
  76. /*
  77. * bgp_node_to_rnode
  78. *
  79. * Returns the route_node structure corresponding to a bgp_node.
  80. */
  81. static inline struct route_node *
  82. bgp_node_to_rnode (struct bgp_node *node)
  83. {
  84. return (struct route_node *) node;
  85. }
  86. /*
  87. * bgp_node_table
  88. *
  89. * Returns the bgp_table that the given node is in.
  90. */
  91. static inline struct bgp_table *
  92. bgp_node_table (struct bgp_node *node)
  93. {
  94. return bgp_node_to_rnode (node)->table->info;
  95. }
  96. /*
  97. * bgp_node_parent_nolock
  98. *
  99. * Gets the parent node of the given node without locking it.
  100. */
  101. static inline struct bgp_node *
  102. bgp_node_parent_nolock (struct bgp_node *node)
  103. {
  104. return bgp_node_from_rnode (node->parent);
  105. }
  106. /*
  107. * bgp_unlock_node
  108. */
  109. static inline void
  110. bgp_unlock_node (struct bgp_node *node)
  111. {
  112. route_unlock_node (bgp_node_to_rnode (node));
  113. }
  114. /*
  115. * bgp_table_top_nolock
  116. *
  117. * Gets the top node in the table without locking it.
  118. *
  119. * @see bgp_table_top
  120. */
  121. static inline struct bgp_node *
  122. bgp_table_top_nolock (const struct bgp_table *const table)
  123. {
  124. return bgp_node_from_rnode (table->route_table->top);
  125. }
  126. /*
  127. * bgp_table_top
  128. */
  129. static inline struct bgp_node *
  130. bgp_table_top (const struct bgp_table *const table)
  131. {
  132. return bgp_node_from_rnode (route_top (table->route_table));
  133. }
  134. /*
  135. * bgp_route_next
  136. */
  137. static inline struct bgp_node *
  138. bgp_route_next (struct bgp_node *node)
  139. {
  140. return bgp_node_from_rnode (route_next (bgp_node_to_rnode (node)));
  141. }
  142. /*
  143. * bgp_route_next_until
  144. */
  145. static inline struct bgp_node *
  146. bgp_route_next_until (struct bgp_node *node, struct bgp_node *limit)
  147. {
  148. struct route_node *rnode;
  149. rnode = route_next_until (bgp_node_to_rnode (node),
  150. bgp_node_to_rnode (limit));
  151. return bgp_node_from_rnode (rnode);
  152. }
  153. /*
  154. * bgp_node_get
  155. */
  156. static inline struct bgp_node *
  157. bgp_node_get (struct bgp_table *const table, struct prefix *p)
  158. {
  159. return bgp_node_from_rnode (route_node_get (table->route_table, p));
  160. }
  161. /*
  162. * bgp_node_lookup
  163. */
  164. static inline struct bgp_node *
  165. bgp_node_lookup (const struct bgp_table *const table, struct prefix *p)
  166. {
  167. return bgp_node_from_rnode (route_node_lookup (table->route_table, p));
  168. }
  169. /*
  170. * bgp_lock_node
  171. */
  172. static inline struct bgp_node *
  173. bgp_lock_node (struct bgp_node *node)
  174. {
  175. return bgp_node_from_rnode (route_lock_node (bgp_node_to_rnode (node)));
  176. }
  177. /*
  178. * bgp_node_match
  179. */
  180. static inline struct bgp_node *
  181. bgp_node_match (const struct bgp_table *table, struct prefix *p)
  182. {
  183. return bgp_node_from_rnode (route_node_match (table->route_table, p));
  184. }
  185. /*
  186. * bgp_node_match_ipv4
  187. */
  188. static inline struct bgp_node *
  189. bgp_node_match_ipv4 (const struct bgp_table *table, struct in_addr *addr)
  190. {
  191. return bgp_node_from_rnode (route_node_match_ipv4 (table->route_table,
  192. addr));
  193. }
  194. /*
  195. * bgp_node_match_ipv6
  196. */
  197. static inline struct bgp_node *
  198. bgp_node_match_ipv6 (const struct bgp_table *table, struct in6_addr *addr)
  199. {
  200. return bgp_node_from_rnode (route_node_match_ipv6 (table->route_table,
  201. addr));
  202. }
  203. static inline unsigned long
  204. bgp_table_count (const struct bgp_table *const table)
  205. {
  206. return route_table_count (table->route_table);
  207. }
  208. /*
  209. * bgp_table_get_next
  210. */
  211. static inline struct bgp_node *
  212. bgp_table_get_next (const struct bgp_table *table, struct prefix *p)
  213. {
  214. return bgp_node_from_rnode (route_table_get_next (table->route_table, p));
  215. }
  216. /*
  217. * bgp_table_iter_init
  218. */
  219. static inline void
  220. bgp_table_iter_init (bgp_table_iter_t * iter, struct bgp_table *table)
  221. {
  222. bgp_table_lock (table);
  223. iter->table = table;
  224. route_table_iter_init (&iter->rt_iter, table->route_table);
  225. }
  226. /*
  227. * bgp_table_iter_next
  228. */
  229. static inline struct bgp_node *
  230. bgp_table_iter_next (bgp_table_iter_t * iter)
  231. {
  232. return bgp_node_from_rnode (route_table_iter_next (&iter->rt_iter));
  233. }
  234. /*
  235. * bgp_table_iter_cleanup
  236. */
  237. static inline void
  238. bgp_table_iter_cleanup (bgp_table_iter_t * iter)
  239. {
  240. route_table_iter_cleanup (&iter->rt_iter);
  241. bgp_table_unlock (iter->table);
  242. iter->table = NULL;
  243. }
  244. /*
  245. * bgp_table_iter_pause
  246. */
  247. static inline void
  248. bgp_table_iter_pause (bgp_table_iter_t * iter)
  249. {
  250. route_table_iter_pause (&iter->rt_iter);
  251. }
  252. /*
  253. * bgp_table_iter_is_done
  254. */
  255. static inline int
  256. bgp_table_iter_is_done (bgp_table_iter_t * iter)
  257. {
  258. return route_table_iter_is_done (&iter->rt_iter);
  259. }
  260. /*
  261. * bgp_table_iter_started
  262. */
  263. static inline int
  264. bgp_table_iter_started (bgp_table_iter_t * iter)
  265. {
  266. return route_table_iter_started (&iter->rt_iter);
  267. }
  268. #endif /* _QUAGGA_BGP_TABLE_H */