ospf6_route.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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. unsigned int 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. };
  87. #define OSPF6_PATH_TYPE_NONE 0
  88. #define OSPF6_PATH_TYPE_INTRA 1
  89. #define OSPF6_PATH_TYPE_INTER 2
  90. #define OSPF6_PATH_TYPE_EXTERNAL1 3
  91. #define OSPF6_PATH_TYPE_EXTERNAL2 4
  92. #define OSPF6_PATH_TYPE_REDISTRIBUTE 5
  93. #define OSPF6_PATH_TYPE_MAX 6
  94. #include "prefix.h"
  95. #include "table.h"
  96. struct ospf6_route
  97. {
  98. struct route_node *rnode;
  99. struct ospf6_route_table *table;
  100. struct ospf6_route *prev;
  101. struct ospf6_route *next;
  102. unsigned int lock;
  103. /* Destination Type */
  104. u_char type;
  105. /* Destination ID */
  106. struct prefix prefix;
  107. /* Time */
  108. struct timeval installed;
  109. struct timeval changed;
  110. /* flag */
  111. u_char flag;
  112. /* path */
  113. struct ospf6_path path;
  114. /* nexthop */
  115. struct ospf6_nexthop nexthop[OSPF6_MULTI_PATH_LIMIT];
  116. /* route option */
  117. void *route_option;
  118. /* link state id for advertising */
  119. u_int32_t linkstate_id;
  120. };
  121. #define OSPF6_DEST_TYPE_NONE 0
  122. #define OSPF6_DEST_TYPE_ROUTER 1
  123. #define OSPF6_DEST_TYPE_NETWORK 2
  124. #define OSPF6_DEST_TYPE_DISCARD 3
  125. #define OSPF6_DEST_TYPE_LINKSTATE 4
  126. #define OSPF6_DEST_TYPE_RANGE 5
  127. #define OSPF6_DEST_TYPE_MAX 6
  128. #define OSPF6_ROUTE_CHANGE 0x01
  129. #define OSPF6_ROUTE_ADD 0x02
  130. #define OSPF6_ROUTE_REMOVE 0x04
  131. #define OSPF6_ROUTE_BEST 0x08
  132. #define OSPF6_ROUTE_ACTIVE_SUMMARY 0x10
  133. #define OSPF6_ROUTE_DO_NOT_ADVERTISE 0x20
  134. #define OSPF6_ROUTE_WAS_REMOVED 0x40
  135. struct ospf6_route_table
  136. {
  137. int scope_type;
  138. int table_type;
  139. void *scope;
  140. /* patricia tree */
  141. struct route_table *table;
  142. u_int32_t count;
  143. /* hooks */
  144. void (*hook_add) (struct ospf6_route *);
  145. void (*hook_change) (struct ospf6_route *);
  146. void (*hook_remove) (struct ospf6_route *);
  147. };
  148. #define OSPF6_SCOPE_TYPE_NONE 0
  149. #define OSPF6_SCOPE_TYPE_GLOBAL 1
  150. #define OSPF6_SCOPE_TYPE_AREA 2
  151. #define OSPF6_SCOPE_TYPE_INTERFACE 3
  152. #define OSPF6_TABLE_TYPE_NONE 0
  153. #define OSPF6_TABLE_TYPE_ROUTES 1
  154. #define OSPF6_TABLE_TYPE_BORDER_ROUTERS 2
  155. #define OSPF6_TABLE_TYPE_CONNECTED_ROUTES 3
  156. #define OSPF6_TABLE_TYPE_EXTERNAL_ROUTES 4
  157. #define OSPF6_TABLE_TYPE_SPF_RESULTS 5
  158. #define OSPF6_TABLE_TYPE_PREFIX_RANGES 6
  159. #define OSPF6_TABLE_TYPE_SUMMARY_PREFIXES 7
  160. #define OSPF6_TABLE_TYPE_SUMMARY_ROUTERS 8
  161. #define OSPF6_ROUTE_TABLE_CREATE(s, t) \
  162. ospf6_route_table_create (OSPF6_SCOPE_TYPE_ ## s, \
  163. OSPF6_TABLE_TYPE_ ## t)
  164. extern const char *ospf6_dest_type_str[OSPF6_DEST_TYPE_MAX];
  165. extern const char *ospf6_dest_type_substr[OSPF6_DEST_TYPE_MAX];
  166. #define OSPF6_DEST_TYPE_NAME(x) \
  167. (0 < (x) && (x) < OSPF6_DEST_TYPE_MAX ? \
  168. ospf6_dest_type_str[(x)] : ospf6_dest_type_str[0])
  169. #define OSPF6_DEST_TYPE_SUBSTR(x) \
  170. (0 < (x) && (x) < OSPF6_DEST_TYPE_MAX ? \
  171. ospf6_dest_type_substr[(x)] : ospf6_dest_type_substr[0])
  172. extern const char *ospf6_path_type_str[OSPF6_PATH_TYPE_MAX];
  173. extern const char *ospf6_path_type_substr[OSPF6_PATH_TYPE_MAX];
  174. #define OSPF6_PATH_TYPE_NAME(x) \
  175. (0 < (x) && (x) < OSPF6_PATH_TYPE_MAX ? \
  176. ospf6_path_type_str[(x)] : ospf6_path_type_str[0])
  177. #define OSPF6_PATH_TYPE_SUBSTR(x) \
  178. (0 < (x) && (x) < OSPF6_PATH_TYPE_MAX ? \
  179. ospf6_path_type_substr[(x)] : ospf6_path_type_substr[0])
  180. #define OSPF6_ROUTE_ADDRESS_STR "Display the route bestmatches the address\n"
  181. #define OSPF6_ROUTE_PREFIX_STR "Display the route\n"
  182. #define OSPF6_ROUTE_MATCH_STR "Display the route matches the prefix\n"
  183. #define ospf6_route_is_prefix(p, r) \
  184. (memcmp (p, &(r)->prefix, sizeof (struct prefix)) == 0)
  185. #define ospf6_route_is_same(ra, rb) \
  186. (prefix_same (&(ra)->prefix, &(rb)->prefix))
  187. #define ospf6_route_is_same_origin(ra, rb) \
  188. ((ra)->path.area_id == (rb)->path.area_id && \
  189. memcmp (&(ra)->path.origin, &(rb)->path.origin, \
  190. sizeof (struct ospf6_ls_origin)) == 0)
  191. #define ospf6_route_is_identical(ra, rb) \
  192. ((ra)->type == (rb)->type && \
  193. memcmp (&(ra)->prefix, &(rb)->prefix, sizeof (struct prefix)) == 0 && \
  194. memcmp (&(ra)->path, &(rb)->path, sizeof (struct ospf6_path)) == 0 && \
  195. memcmp (&(ra)->nexthop, &(rb)->nexthop, \
  196. sizeof (struct ospf6_nexthop) * OSPF6_MULTI_PATH_LIMIT) == 0)
  197. #define ospf6_route_is_best(r) (CHECK_FLAG ((r)->flag, OSPF6_ROUTE_BEST))
  198. #define ospf6_linkstate_prefix_adv_router(x) \
  199. (*(u_int32_t *)(&(x)->u.prefix6.s6_addr[0]))
  200. #define ospf6_linkstate_prefix_id(x) \
  201. (*(u_int32_t *)(&(x)->u.prefix6.s6_addr[4]))
  202. #define ADV_ROUTER_IN_PREFIX(x) \
  203. (*(u_int32_t *)(&(x)->u.prefix6.s6_addr[0]))
  204. #define ID_IN_PREFIX(x) \
  205. (*(u_int32_t *)(&(x)->u.prefix6.s6_addr[4]))
  206. /* Function prototype */
  207. extern void ospf6_linkstate_prefix (u_int32_t adv_router, u_int32_t id,
  208. struct prefix *prefix);
  209. extern void ospf6_linkstate_prefix2str (struct prefix *prefix, char *buf,
  210. int size);
  211. extern struct ospf6_route *ospf6_route_create (void);
  212. extern void ospf6_route_delete (struct ospf6_route *);
  213. extern struct ospf6_route *ospf6_route_copy (struct ospf6_route *route);
  214. extern void ospf6_route_lock (struct ospf6_route *route);
  215. extern void ospf6_route_unlock (struct ospf6_route *route);
  216. extern struct ospf6_route *ospf6_route_lookup (struct prefix *prefix,
  217. struct ospf6_route_table *table);
  218. extern struct ospf6_route *ospf6_route_lookup_identical (struct ospf6_route *route,
  219. struct ospf6_route_table *table);
  220. extern struct ospf6_route *ospf6_route_lookup_bestmatch (struct prefix *prefix,
  221. struct ospf6_route_table *table);
  222. extern struct ospf6_route *ospf6_route_add (struct ospf6_route *route,
  223. struct ospf6_route_table *table);
  224. extern void ospf6_route_remove (struct ospf6_route *route,
  225. struct ospf6_route_table *table);
  226. extern struct ospf6_route *ospf6_route_head (struct ospf6_route_table *table);
  227. extern struct ospf6_route *ospf6_route_next (struct ospf6_route *route);
  228. extern struct ospf6_route *ospf6_route_best_next (struct ospf6_route *route);
  229. extern struct ospf6_route *ospf6_route_match_head (struct prefix *prefix,
  230. struct ospf6_route_table *table);
  231. extern struct ospf6_route *ospf6_route_match_next (struct prefix *prefix,
  232. struct ospf6_route *route);
  233. extern void ospf6_route_remove_all (struct ospf6_route_table *);
  234. extern struct ospf6_route_table *ospf6_route_table_create (int s, int t);
  235. extern void ospf6_route_table_delete (struct ospf6_route_table *);
  236. extern void ospf6_route_dump (struct ospf6_route_table *table);
  237. extern void ospf6_route_show (struct vty *vty, struct ospf6_route *route);
  238. extern void ospf6_route_show_detail (struct vty *vty, struct ospf6_route *route);
  239. extern int ospf6_route_table_show (struct vty *, int, const char *[],
  240. struct ospf6_route_table *);
  241. extern int ospf6_linkstate_table_show (struct vty *vty, int argc,
  242. const char *argv[],
  243. struct ospf6_route_table *table);
  244. extern void ospf6_brouter_show_header (struct vty *vty);
  245. extern void ospf6_brouter_show (struct vty *vty, struct ospf6_route *route);
  246. extern int config_write_ospf6_debug_route (struct vty *vty);
  247. extern void install_element_ospf6_debug_route (void);
  248. extern void ospf6_route_init (void);
  249. #endif /* OSPF6_ROUTE_H */