ospf_lsa.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. /*
  2. * OSPF Link State Advertisement
  3. * Copyright (C) 1999, 2000 Toshiaki Takada
  4. *
  5. * This file is part of GNU Zebra.
  6. *
  7. * GNU Zebra is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation; either version 2, or (at your option) any
  10. * later version.
  11. *
  12. * GNU Zebra is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with GNU Zebra; see the file COPYING. If not, write to the Free
  19. * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  20. * 02111-1307, USA.
  21. */
  22. #ifndef _ZEBRA_OSPF_LSA_H
  23. #define _ZEBRA_OSPF_LSA_H
  24. #include "stream.h"
  25. /* OSPF LSA Range definition. */
  26. #define OSPF_MIN_LSA 1 /* begin range here */
  27. #if defined (HAVE_OPAQUE_LSA)
  28. #define OSPF_MAX_LSA 12
  29. #else
  30. #define OSPF_MAX_LSA 8
  31. #endif
  32. /* OSPF LSA Type definition. */
  33. #define OSPF_UNKNOWN_LSA 0
  34. #define OSPF_ROUTER_LSA 1
  35. #define OSPF_NETWORK_LSA 2
  36. #define OSPF_SUMMARY_LSA 3
  37. #define OSPF_ASBR_SUMMARY_LSA 4
  38. #define OSPF_AS_EXTERNAL_LSA 5
  39. #define OSPF_GROUP_MEMBER_LSA 6 /* Not supported. */
  40. #define OSPF_AS_NSSA_LSA 7
  41. #define OSPF_EXTERNAL_ATTRIBUTES_LSA 8 /* Not supported. */
  42. #define OSPF_OPAQUE_LINK_LSA 9
  43. #define OSPF_OPAQUE_AREA_LSA 10
  44. #define OSPF_OPAQUE_AS_LSA 11
  45. #define OSPF_LSA_HEADER_SIZE 20U
  46. #define OSPF_MAX_LSA_SIZE 1500U
  47. /* AS-external-LSA refresh method. */
  48. #define LSA_REFRESH_IF_CHANGED 0
  49. #define LSA_REFRESH_FORCE 1
  50. /* OSPF LSA header. */
  51. struct lsa_header
  52. {
  53. u_int16_t ls_age;
  54. u_char options;
  55. u_char type;
  56. struct in_addr id;
  57. struct in_addr adv_router;
  58. u_int32_t ls_seqnum;
  59. u_int16_t checksum;
  60. u_int16_t length;
  61. };
  62. /* OSPF LSA. */
  63. struct ospf_lsa
  64. {
  65. /* LSA origination flag. */
  66. u_char flags;
  67. #define OSPF_LSA_SELF 0x01
  68. #define OSPF_LSA_SELF_CHECKED 0x02
  69. #define OSPF_LSA_RECEIVED 0x04
  70. #define OSPF_LSA_APPROVED 0x08
  71. #define OSPF_LSA_DISCARD 0x10
  72. #define OSPF_LSA_LOCAL_XLT 0x20
  73. #define OSPF_LSA_PREMATURE_AGE 0x40
  74. /* LSA data. */
  75. struct lsa_header *data;
  76. /* Received time stamp. */
  77. struct timeval tv_recv;
  78. /* Last time it was originated */
  79. struct timeval tv_orig;
  80. /* All of reference count, also lock to remove. */
  81. int lock;
  82. /* Flags for the SPF calculation. */
  83. int stat;
  84. #define LSA_SPF_NOT_EXPLORED -1
  85. #define LSA_SPF_IN_SPFTREE -2
  86. /* If stat >= 0, stat is LSA position in candidates heap. */
  87. /* References to this LSA in neighbor retransmission lists*/
  88. int retransmit_counter;
  89. /* Area the LSA belongs to, may be NULL if AS-external-LSA. */
  90. struct ospf_area *area;
  91. /* Parent LSDB. */
  92. struct ospf_lsdb *lsdb;
  93. /* Related Route. */
  94. void *route;
  95. /* Refreshement List or Queue */
  96. int refresh_list;
  97. #ifdef HAVE_OPAQUE_LSA
  98. /* For Type-9 Opaque-LSAs, reference to ospf-interface is required. */
  99. struct ospf_interface *oi;
  100. #endif /* HAVE_OPAQUE_LSA */
  101. };
  102. /* OSPF LSA Link Type. */
  103. #define LSA_LINK_TYPE_POINTOPOINT 1
  104. #define LSA_LINK_TYPE_TRANSIT 2
  105. #define LSA_LINK_TYPE_STUB 3
  106. #define LSA_LINK_TYPE_VIRTUALLINK 4
  107. /* OSPF Router LSA Flag. */
  108. #define ROUTER_LSA_BORDER 0x01 /* The router is an ABR */
  109. #define ROUTER_LSA_EXTERNAL 0x02 /* The router is an ASBR */
  110. #define ROUTER_LSA_VIRTUAL 0x04 /* The router has a VL in this area */
  111. #define ROUTER_LSA_NT 0x10 /* The routers always translates Type-7 */
  112. #define ROUTER_LSA_SHORTCUT 0x20 /* Shortcut-ABR specific flag */
  113. #define IS_ROUTER_LSA_VIRTUAL(x) ((x)->flags & ROUTER_LSA_VIRTUAL)
  114. #define IS_ROUTER_LSA_EXTERNAL(x) ((x)->flags & ROUTER_LSA_EXTERNAL)
  115. #define IS_ROUTER_LSA_BORDER(x) ((x)->flags & ROUTER_LSA_BORDER)
  116. #define IS_ROUTER_LSA_SHORTCUT(x) ((x)->flags & ROUTER_LSA_SHORTCUT)
  117. #define IS_ROUTER_LSA_NT(x) ((x)->flags & ROUTER_LSA_NT)
  118. /* OSPF Router-LSA Link information. */
  119. struct router_lsa_link
  120. {
  121. struct in_addr link_id;
  122. struct in_addr link_data;
  123. struct
  124. {
  125. u_char type;
  126. u_char tos_count;
  127. u_int16_t metric;
  128. } m[1];
  129. };
  130. /* OSPF Router-LSAs structure. */
  131. struct router_lsa
  132. {
  133. struct lsa_header header;
  134. u_char flags;
  135. u_char zero;
  136. u_int16_t links;
  137. struct
  138. {
  139. struct in_addr link_id;
  140. struct in_addr link_data;
  141. u_char type;
  142. u_char tos;
  143. u_int16_t metric;
  144. } link[1];
  145. };
  146. /* OSPF Network-LSAs structure. */
  147. struct network_lsa
  148. {
  149. struct lsa_header header;
  150. struct in_addr mask;
  151. struct in_addr routers[1];
  152. };
  153. /* OSPF Summary-LSAs structure. */
  154. struct summary_lsa
  155. {
  156. struct lsa_header header;
  157. struct in_addr mask;
  158. u_char tos;
  159. u_char metric[3];
  160. };
  161. /* OSPF AS-external-LSAs structure. */
  162. struct as_external_lsa
  163. {
  164. struct lsa_header header;
  165. struct in_addr mask;
  166. struct
  167. {
  168. u_char tos;
  169. u_char metric[3];
  170. struct in_addr fwd_addr;
  171. u_int32_t route_tag;
  172. } e[1];
  173. };
  174. #ifdef HAVE_OPAQUE_LSA
  175. #include "ospfd/ospf_opaque.h"
  176. #endif /* HAVE_OPAQUE_LSA */
  177. /* Macros. */
  178. #define GET_METRIC(x) get_metric(x)
  179. #define IS_EXTERNAL_METRIC(x) ((x) & 0x80)
  180. #define GET_AGE(x) (ntohs ((x)->data->ls_age) + time (NULL) - (x)->tv_recv)
  181. #define LS_AGE(x) (OSPF_LSA_MAXAGE < get_age(x) ? \
  182. OSPF_LSA_MAXAGE : get_age(x))
  183. #define IS_LSA_SELF(L) (CHECK_FLAG ((L)->flags, OSPF_LSA_SELF))
  184. #define IS_LSA_MAXAGE(L) (LS_AGE ((L)) == OSPF_LSA_MAXAGE)
  185. #define OSPF_LSA_UPDATE_DELAY 2
  186. #define OSPF_LSA_UPDATE_TIMER_ON(T,F) \
  187. if (!(T)) \
  188. (T) = thread_add_timer (master, (F), 0, 2)
  189. /* Prototypes. */
  190. /* XXX: Eek, time functions, similar are in lib/thread.c */
  191. extern struct timeval tv_adjust (struct timeval);
  192. extern int tv_ceil (struct timeval);
  193. extern int tv_floor (struct timeval);
  194. extern struct timeval int2tv (int);
  195. extern struct timeval tv_add (struct timeval, struct timeval);
  196. extern struct timeval tv_sub (struct timeval, struct timeval);
  197. extern int tv_cmp (struct timeval, struct timeval);
  198. extern int get_age (struct ospf_lsa *);
  199. extern u_int16_t ospf_lsa_checksum (struct lsa_header *);
  200. extern int ospf_lsa_refresh_delay (struct ospf_lsa *);
  201. extern const char *dump_lsa_key (struct ospf_lsa *);
  202. extern u_int32_t lsa_seqnum_increment (struct ospf_lsa *);
  203. extern void lsa_header_set (struct stream *, u_char, u_char, struct in_addr,
  204. struct in_addr);
  205. extern struct ospf_neighbor *ospf_nbr_lookup_ptop (struct ospf_interface *);
  206. /* Prototype for LSA primitive. */
  207. extern struct ospf_lsa *ospf_lsa_new (void);
  208. extern struct ospf_lsa *ospf_lsa_dup (struct ospf_lsa *);
  209. extern void ospf_lsa_free (struct ospf_lsa *);
  210. extern struct ospf_lsa *ospf_lsa_lock (struct ospf_lsa *);
  211. extern void ospf_lsa_unlock (struct ospf_lsa *);
  212. extern void ospf_lsa_discard (struct ospf_lsa *);
  213. extern struct lsa_header *ospf_lsa_data_new (size_t);
  214. extern struct lsa_header *ospf_lsa_data_dup (struct lsa_header *);
  215. extern void ospf_lsa_data_free (struct lsa_header *);
  216. /* Prototype for various LSAs */
  217. extern struct ospf_lsa *ospf_router_lsa_originate (struct ospf_area *);
  218. extern int ospf_router_lsa_update_timer (struct thread *);
  219. extern void ospf_router_lsa_timer_add (struct ospf_area *);
  220. extern int ospf_network_lsa_refresh (struct ospf_lsa *, struct ospf_interface *);
  221. extern void ospf_network_lsa_timer_add (struct ospf_interface *);
  222. extern struct ospf_lsa *ospf_summary_lsa_originate (struct prefix_ipv4 *, u_int32_t,
  223. struct ospf_area *);
  224. extern struct ospf_lsa *ospf_summary_asbr_lsa_originate (struct prefix_ipv4 *,
  225. u_int32_t,
  226. struct ospf_area *);
  227. extern struct ospf_lsa *ospf_summary_lsa_refresh (struct ospf *, struct ospf_lsa *);
  228. extern struct ospf_lsa *ospf_summary_asbr_lsa_refresh (struct ospf *, struct ospf_lsa *);
  229. extern struct ospf_lsa *ospf_lsa_install (struct ospf *,
  230. struct ospf_interface *, struct ospf_lsa *);
  231. extern void ospf_nssa_lsa_flush (struct ospf *ospf, struct prefix_ipv4 *p);
  232. extern void ospf_external_lsa_flush (struct ospf *, u_char, struct prefix_ipv4 *,
  233. unsigned int, struct in_addr);
  234. extern struct in_addr ospf_get_ip_from_ifp (struct ospf_interface *);
  235. extern struct ospf_lsa *ospf_external_lsa_originate (struct ospf *, struct external_info *);
  236. extern int ospf_external_lsa_originate_timer (struct thread *);
  237. extern struct ospf_lsa *ospf_lsa_lookup (struct ospf_area *, u_int32_t,
  238. struct in_addr, struct in_addr);
  239. extern struct ospf_lsa *ospf_lsa_lookup_by_id (struct ospf_area *,
  240. u_int32_t,
  241. struct in_addr);
  242. extern struct ospf_lsa *ospf_lsa_lookup_by_header (struct ospf_area *,
  243. struct lsa_header *);
  244. extern int ospf_lsa_more_recent (struct ospf_lsa *, struct ospf_lsa *);
  245. extern int ospf_lsa_different (struct ospf_lsa *, struct ospf_lsa *);
  246. extern void ospf_flush_self_originated_lsas_now (struct ospf *);
  247. extern int ospf_lsa_is_self_originated (struct ospf *, struct ospf_lsa *);
  248. extern struct ospf_lsa *ospf_lsa_lookup_by_prefix (struct ospf_lsdb *, u_char,
  249. struct prefix_ipv4 *,
  250. struct in_addr);
  251. extern void ospf_lsa_maxage (struct ospf *, struct ospf_lsa *);
  252. extern u_int32_t get_metric (u_char *);
  253. extern int ospf_lsa_maxage_walker (struct thread *);
  254. extern void ospf_external_lsa_refresh_default (struct ospf *);
  255. extern void ospf_external_lsa_refresh_type (struct ospf *, u_char, int);
  256. extern void ospf_external_lsa_refresh (struct ospf *, struct ospf_lsa *,
  257. struct external_info *, int);
  258. extern struct in_addr ospf_lsa_unique_id (struct ospf *, struct ospf_lsdb *, u_char,
  259. struct prefix_ipv4 *);
  260. extern void ospf_schedule_lsa_flood_area (struct ospf_area *, struct ospf_lsa *);
  261. extern void ospf_schedule_lsa_flush_area (struct ospf_area *, struct ospf_lsa *);
  262. extern void ospf_refresher_register_lsa (struct ospf *, struct ospf_lsa *);
  263. extern void ospf_refresher_unregister_lsa (struct ospf *, struct ospf_lsa *);
  264. extern int ospf_lsa_refresh_walker (struct thread *);
  265. extern void ospf_lsa_maxage_delete (struct ospf *, struct ospf_lsa *);
  266. extern void ospf_discard_from_db (struct ospf *, struct ospf_lsdb *, struct ospf_lsa*);
  267. extern int is_prefix_default (struct prefix_ipv4 *);
  268. extern int metric_type (struct ospf *, u_char);
  269. extern int metric_value (struct ospf *, u_char);
  270. extern struct in_addr ospf_get_nssa_ip (struct ospf_area *);
  271. extern int ospf_translated_nssa_compare (struct ospf_lsa *, struct ospf_lsa *);
  272. extern struct ospf_lsa *ospf_translated_nssa_refresh (struct ospf *, struct ospf_lsa *,
  273. struct ospf_lsa *);
  274. extern struct ospf_lsa *ospf_translated_nssa_originate (struct ospf *, struct ospf_lsa *);
  275. #endif /* _ZEBRA_OSPF_LSA_H */