ospf6_route.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. /*
  2. * Copyright (C) 2003 Yasuhiro Ohara
  3. *
  4. * This file is part of GNU Zebra.
  5. *
  6. * GNU Zebra is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2, or (at your option) any
  9. * later version.
  10. *
  11. * GNU Zebra is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with GNU Zebra; see the file COPYING. If not, write to the
  18. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19. * Boston, MA 02111-1307, USA.
  20. */
  21. #ifndef OSPF6_ROUTE_H
  22. #define OSPF6_ROUTE_H
  23. #define OSPF6_MULTI_PATH_LIMIT 4
  24. /* Debug option */
  25. extern unsigned char conf_debug_ospf6_route;
  26. #define OSPF6_DEBUG_ROUTE_TABLE 0x01
  27. #define OSPF6_DEBUG_ROUTE_INTRA 0x02
  28. #define OSPF6_DEBUG_ROUTE_INTER 0x04
  29. #define OSPF6_DEBUG_ROUTE_MEMORY 0x80
  30. #define OSPF6_DEBUG_ROUTE_ON(level) \
  31. (conf_debug_ospf6_route |= (level))
  32. #define OSPF6_DEBUG_ROUTE_OFF(level) \
  33. (conf_debug_ospf6_route &= ~(level))
  34. #define IS_OSPF6_DEBUG_ROUTE(e) \
  35. (conf_debug_ospf6_route & OSPF6_DEBUG_ROUTE_ ## e)
  36. /* Nexthop */
  37. struct ospf6_nexthop
  38. {
  39. /* Interface index */
  40. ifindex_t ifindex;
  41. /* IP address, if any */
  42. struct in6_addr address;
  43. };
  44. #define ospf6_nexthop_is_set(x) \
  45. ((x)->ifindex || ! IN6_IS_ADDR_UNSPECIFIED (&(x)->address))
  46. #define ospf6_nexthop_is_same(a,b) \
  47. ((a)->ifindex == (b)->ifindex && \
  48. IN6_ARE_ADDR_EQUAL (&(a)->address, &(b)->address))
  49. #define ospf6_nexthop_clear(x) \
  50. do { \
  51. (x)->ifindex = 0; \
  52. memset (&(x)->address, 0, sizeof (struct in6_addr)); \
  53. } while (0)
  54. #define ospf6_nexthop_copy(a, b) \
  55. do { \
  56. (a)->ifindex = (b)->ifindex; \
  57. memcpy (&(a)->address, &(b)->address, \
  58. sizeof (struct in6_addr)); \
  59. } while (0)
  60. /* Path */
  61. struct ospf6_ls_origin
  62. {
  63. u_int16_t type;
  64. u_int32_t id;
  65. u_int32_t adv_router;
  66. };
  67. struct ospf6_path
  68. {
  69. /* Link State Origin */
  70. struct ospf6_ls_origin origin;
  71. /* Router bits */
  72. u_char router_bits;
  73. /* Optional Capabilities */
  74. u_char options[3];
  75. /* Prefix Options */
  76. u_char prefix_options;
  77. /* Associated Area */
  78. u_int32_t area_id;
  79. /* Path-type */
  80. u_char type;
  81. u_char subtype; /* only used for redistribute i.e ZEBRA_ROUTE_XXX */
  82. /* Cost */
  83. u_int8_t metric_type;
  84. u_int32_t cost;
  85. u_int32_t cost_e2;
  86. u_int32_t tag;
  87. };
  88. #define OSPF6_PATH_TYPE_NONE 0
  89. #define OSPF6_PATH_TYPE_INTRA 1
  90. #define OSPF6_PATH_TYPE_INTER 2
  91. #define OSPF6_PATH_TYPE_EXTERNAL1 3
  92. #define OSPF6_PATH_TYPE_EXTERNAL2 4
  93. #define OSPF6_PATH_TYPE_REDISTRIBUTE 5
  94. #define OSPF6_PATH_TYPE_MAX 6
  95. #include "prefix.h"
  96. #include "table.h"
  97. struct ospf6_route
  98. {
  99. struct route_node *rnode;
  100. struct ospf6_route_table *table;
  101. struct ospf6_route *prev;
  102. struct ospf6_route *next;
  103. unsigned int lock;
  104. /* Destination Type */
  105. u_char type;
  106. /* XXX: It would likely be better to use separate struct in_addr's
  107. * for the advertising router-ID and prefix IDs, instead of stuffing them
  108. * into one. See also XXX below.
  109. */
  110. /* Destination ID */
  111. struct prefix prefix;
  112. /* Time */
  113. struct timeval installed;
  114. struct timeval changed;
  115. /* flag */
  116. u_char flag;
  117. /* path */
  118. struct ospf6_path path;
  119. /* nexthop */
  120. struct ospf6_nexthop nexthop[OSPF6_MULTI_PATH_LIMIT];
  121. /* route option */
  122. void *route_option;
  123. /* link state id for advertising */
  124. u_int32_t linkstate_id;
  125. };
  126. #define OSPF6_DEST_TYPE_NONE 0
  127. #define OSPF6_DEST_TYPE_ROUTER 1
  128. #define OSPF6_DEST_TYPE_NETWORK 2
  129. #define OSPF6_DEST_TYPE_DISCARD 3
  130. #define OSPF6_DEST_TYPE_LINKSTATE 4
  131. #define OSPF6_DEST_TYPE_RANGE 5
  132. #define OSPF6_DEST_TYPE_MAX 6
  133. #define OSPF6_ROUTE_CHANGE 0x01
  134. #define OSPF6_ROUTE_ADD 0x02
  135. #define OSPF6_ROUTE_REMOVE 0x04
  136. #define OSPF6_ROUTE_BEST 0x08
  137. #define OSPF6_ROUTE_ACTIVE_SUMMARY 0x10
  138. #define OSPF6_ROUTE_DO_NOT_ADVERTISE 0x20
  139. #define OSPF6_ROUTE_WAS_REMOVED 0x40
  140. struct ospf6_route_table
  141. {
  142. int scope_type;
  143. int table_type;
  144. void *scope;
  145. /* patricia tree */
  146. struct route_table *table;
  147. u_int32_t count;
  148. /* hooks */
  149. void (*hook_add) (struct ospf6_route *);
  150. void (*hook_change) (struct ospf6_route *);
  151. void (*hook_remove) (struct ospf6_route *);
  152. };
  153. #define OSPF6_SCOPE_TYPE_NONE 0
  154. #define OSPF6_SCOPE_TYPE_GLOBAL 1
  155. #define OSPF6_SCOPE_TYPE_AREA 2
  156. #define OSPF6_SCOPE_TYPE_INTERFACE 3
  157. #define OSPF6_TABLE_TYPE_NONE 0
  158. #define OSPF6_TABLE_TYPE_ROUTES 1
  159. #define OSPF6_TABLE_TYPE_BORDER_ROUTERS 2
  160. #define OSPF6_TABLE_TYPE_CONNECTED_ROUTES 3
  161. #define OSPF6_TABLE_TYPE_EXTERNAL_ROUTES 4
  162. #define OSPF6_TABLE_TYPE_SPF_RESULTS 5
  163. #define OSPF6_TABLE_TYPE_PREFIX_RANGES 6
  164. #define OSPF6_TABLE_TYPE_SUMMARY_PREFIXES 7
  165. #define OSPF6_TABLE_TYPE_SUMMARY_ROUTERS 8
  166. #define OSPF6_ROUTE_TABLE_CREATE(s, t) \
  167. ospf6_route_table_create (OSPF6_SCOPE_TYPE_ ## s, \
  168. OSPF6_TABLE_TYPE_ ## t)
  169. extern const char *ospf6_dest_type_str[OSPF6_DEST_TYPE_MAX];
  170. extern const char *ospf6_dest_type_substr[OSPF6_DEST_TYPE_MAX];
  171. #define OSPF6_DEST_TYPE_NAME(x) \
  172. (0 < (x) && (x) < OSPF6_DEST_TYPE_MAX ? \
  173. ospf6_dest_type_str[(x)] : ospf6_dest_type_str[0])
  174. #define OSPF6_DEST_TYPE_SUBSTR(x) \
  175. (0 < (x) && (x) < OSPF6_DEST_TYPE_MAX ? \
  176. ospf6_dest_type_substr[(x)] : ospf6_dest_type_substr[0])
  177. extern const char *ospf6_path_type_str[OSPF6_PATH_TYPE_MAX];
  178. extern const char *ospf6_path_type_substr[OSPF6_PATH_TYPE_MAX];
  179. #define OSPF6_PATH_TYPE_NAME(x) \
  180. (0 < (x) && (x) < OSPF6_PATH_TYPE_MAX ? \
  181. ospf6_path_type_str[(x)] : ospf6_path_type_str[0])
  182. #define OSPF6_PATH_TYPE_SUBSTR(x) \
  183. (0 < (x) && (x) < OSPF6_PATH_TYPE_MAX ? \
  184. ospf6_path_type_substr[(x)] : ospf6_path_type_substr[0])
  185. #define OSPF6_ROUTE_ADDRESS_STR "Display the route bestmatches the address\n"
  186. #define OSPF6_ROUTE_PREFIX_STR "Display the route\n"
  187. #define OSPF6_ROUTE_MATCH_STR "Display the route matches the prefix\n"
  188. #define ospf6_route_is_prefix(p, r) \
  189. (memcmp (p, &(r)->prefix, sizeof (struct prefix)) == 0)
  190. #define ospf6_route_is_same(ra, rb) \
  191. (prefix_same (&(ra)->prefix, &(rb)->prefix))
  192. #define ospf6_route_is_same_origin(ra, rb) \
  193. ((ra)->path.area_id == (rb)->path.area_id && \
  194. memcmp (&(ra)->path.origin, &(rb)->path.origin, \
  195. sizeof (struct ospf6_ls_origin)) == 0)
  196. #define ospf6_route_is_identical(ra, rb) \
  197. ((ra)->type == (rb)->type && \
  198. memcmp (&(ra)->prefix, &(rb)->prefix, sizeof (struct prefix)) == 0 && \
  199. memcmp (&(ra)->path, &(rb)->path, sizeof (struct ospf6_path)) == 0 && \
  200. memcmp (&(ra)->nexthop, &(rb)->nexthop, \
  201. sizeof (struct ospf6_nexthop) * OSPF6_MULTI_PATH_LIMIT) == 0)
  202. #define ospf6_route_is_best(r) (CHECK_FLAG ((r)->flag, OSPF6_ROUTE_BEST))
  203. #define ospf6_linkstate_prefix_adv_router(x) \
  204. ((x)->u.lp.id.s_addr)
  205. #define ospf6_linkstate_prefix_id(x) \
  206. ((x)->u.lp.adv_router.s_addr)
  207. #define ADV_ROUTER_IN_PREFIX(x) \
  208. ((x)->u.lp.id.s_addr)
  209. #define ID_IN_PREFIX(x) \
  210. ((x)->u.lp.adv_router.s_addr)
  211. /* Function prototype */
  212. extern void ospf6_linkstate_prefix (u_int32_t adv_router, u_int32_t id,
  213. struct prefix *prefix);
  214. extern void ospf6_linkstate_prefix2str (struct prefix *prefix, char *buf,
  215. int size);
  216. extern struct ospf6_route *ospf6_route_create (void);
  217. extern void ospf6_route_delete (struct ospf6_route *);
  218. extern struct ospf6_route *ospf6_route_copy (struct ospf6_route *route);
  219. extern void ospf6_route_lock (struct ospf6_route *route);
  220. extern void ospf6_route_unlock (struct ospf6_route *route);
  221. extern struct ospf6_route *ospf6_route_lookup (struct prefix *prefix,
  222. struct ospf6_route_table *table);
  223. extern struct ospf6_route *ospf6_route_lookup_identical (struct ospf6_route *route,
  224. struct ospf6_route_table *table);
  225. extern struct ospf6_route *ospf6_route_lookup_bestmatch (struct prefix *prefix,
  226. struct ospf6_route_table *table);
  227. extern struct ospf6_route *ospf6_route_add (struct ospf6_route *route,
  228. struct ospf6_route_table *table);
  229. extern void ospf6_route_remove (struct ospf6_route *route,
  230. struct ospf6_route_table *table);
  231. extern struct ospf6_route *ospf6_route_head (struct ospf6_route_table *table);
  232. extern struct ospf6_route *ospf6_route_next (struct ospf6_route *route);
  233. extern struct ospf6_route *ospf6_route_best_next (struct ospf6_route *route);
  234. extern struct ospf6_route *ospf6_route_match_head (struct prefix *prefix,
  235. struct ospf6_route_table *table);
  236. extern struct ospf6_route *ospf6_route_match_next (struct prefix *prefix,
  237. struct ospf6_route *route);
  238. extern void ospf6_route_remove_all (struct ospf6_route_table *);
  239. extern struct ospf6_route_table *ospf6_route_table_create (int s, int t);
  240. extern void ospf6_route_table_delete (struct ospf6_route_table *);
  241. extern void ospf6_route_dump (struct ospf6_route_table *table);
  242. extern void ospf6_route_show (struct vty *vty, struct ospf6_route *route);
  243. extern void ospf6_route_show_detail (struct vty *vty, struct ospf6_route *route);
  244. extern int ospf6_route_table_show (struct vty *, int, const char *[],
  245. struct ospf6_route_table *);
  246. extern int ospf6_linkstate_table_show (struct vty *vty, int argc,
  247. const char *argv[],
  248. struct ospf6_route_table *table);
  249. extern void ospf6_brouter_show_header (struct vty *vty);
  250. extern void ospf6_brouter_show (struct vty *vty, struct ospf6_route *route);
  251. extern int config_write_ospf6_debug_route (struct vty *vty);
  252. extern void install_element_ospf6_debug_route (void);
  253. extern void ospf6_route_init (void);
  254. extern void ospf6_clean (void);
  255. #endif /* OSPF6_ROUTE_H */