bgp_table.h 6.4 KB

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