ospf_lsa.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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_ROUTER_LSA_LINK_SIZE 12U
  47. #define OSPF_ROUTER_LSA_TOS_SIZE 4U
  48. #define OSPF_MAX_LSA_SIZE 1500U
  49. /* AS-external-LSA refresh method. */
  50. #define LSA_REFRESH_IF_CHANGED 0
  51. #define LSA_REFRESH_FORCE 1
  52. /* OSPF LSA header. */
  53. struct lsa_header
  54. {
  55. u_int16_t ls_age;
  56. u_char options;
  57. u_char type;
  58. struct in_addr id;
  59. struct in_addr adv_router;
  60. u_int32_t ls_seqnum;
  61. u_int16_t checksum;
  62. u_int16_t length;
  63. };
  64. /* OSPF LSA. */
  65. struct ospf_lsa
  66. {
  67. /* LSA origination flag. */
  68. u_char flags;
  69. #define OSPF_LSA_SELF 0x01
  70. #define OSPF_LSA_SELF_CHECKED 0x02
  71. #define OSPF_LSA_RECEIVED 0x04
  72. #define OSPF_LSA_APPROVED 0x08
  73. #define OSPF_LSA_DISCARD 0x10
  74. #define OSPF_LSA_LOCAL_XLT 0x20
  75. #define OSPF_LSA_PREMATURE_AGE 0x40
  76. #define OSPF_LSA_IN_MAXAGE 0x80
  77. /* LSA data. */
  78. struct lsa_header *data;
  79. /* Received time stamp. */
  80. struct timeval tv_recv;
  81. /* Last time it was originated */
  82. struct timeval tv_orig;
  83. /* All of reference count, also lock to remove. */
  84. int lock;
  85. /* Flags for the SPF calculation. */
  86. int stat;
  87. #define LSA_SPF_NOT_EXPLORED -1
  88. #define LSA_SPF_IN_SPFTREE -2
  89. /* If stat >= 0, stat is LSA position in candidates heap. */
  90. /* References to this LSA in neighbor retransmission lists*/
  91. int retransmit_counter;
  92. /* Area the LSA belongs to, may be NULL if AS-external-LSA. */
  93. struct ospf_area *area;
  94. /* Parent LSDB. */
  95. struct ospf_lsdb *lsdb;
  96. /* Related Route. */
  97. void *route;
  98. /* Refreshement List or Queue */
  99. int refresh_list;
  100. /* For Type-9 Opaque-LSAs */
  101. struct ospf_interface *oi;
  102. };
  103. /* OSPF LSA Link Type. */
  104. #define LSA_LINK_TYPE_POINTOPOINT 1
  105. #define LSA_LINK_TYPE_TRANSIT 2
  106. #define LSA_LINK_TYPE_STUB 3
  107. #define LSA_LINK_TYPE_VIRTUALLINK 4
  108. /* OSPF Router LSA Flag. */
  109. #define ROUTER_LSA_BORDER 0x01 /* The router is an ABR */
  110. #define ROUTER_LSA_EXTERNAL 0x02 /* The router is an ASBR */
  111. #define ROUTER_LSA_VIRTUAL 0x04 /* The router has a VL in this area */
  112. #define ROUTER_LSA_NT 0x10 /* The routers always translates Type-7 */
  113. #define ROUTER_LSA_SHORTCUT 0x20 /* Shortcut-ABR specific flag */
  114. #define IS_ROUTER_LSA_VIRTUAL(x) ((x)->flags & ROUTER_LSA_VIRTUAL)
  115. #define IS_ROUTER_LSA_EXTERNAL(x) ((x)->flags & ROUTER_LSA_EXTERNAL)
  116. #define IS_ROUTER_LSA_BORDER(x) ((x)->flags & ROUTER_LSA_BORDER)
  117. #define IS_ROUTER_LSA_SHORTCUT(x) ((x)->flags & ROUTER_LSA_SHORTCUT)
  118. #define IS_ROUTER_LSA_NT(x) ((x)->flags & ROUTER_LSA_NT)
  119. /* OSPF Router-LSA Link information. */
  120. struct router_lsa_link
  121. {
  122. struct in_addr link_id;
  123. struct in_addr link_data;
  124. struct
  125. {
  126. u_char type;
  127. u_char tos_count;
  128. u_int16_t metric;
  129. } m[1];
  130. };
  131. /* OSPF Router-LSAs structure. */
  132. #define OSPF_ROUTER_LSA_MIN_SIZE 4U /* w/0 link descriptors */
  133. /* There is an edge case, when number of links in a Router-LSA may be 0 without
  134. breaking the specification. A router, which has no other links to backbone
  135. area besides one virtual link, will not put any VL descriptor blocks into
  136. the Router-LSA generated for area 0 until a full adjacency over the VL is
  137. reached (RFC2328 12.4.1.3). In this case the Router-LSA initially received
  138. by the other end of the VL will have 0 link descriptor blocks, but soon will
  139. be replaced with the next revision having 1 descriptor block. */
  140. struct router_lsa
  141. {
  142. struct lsa_header header;
  143. u_char flags;
  144. u_char zero;
  145. u_int16_t links;
  146. struct
  147. {
  148. struct in_addr link_id;
  149. struct in_addr link_data;
  150. u_char type;
  151. u_char tos;
  152. u_int16_t metric;
  153. } link[1];
  154. };
  155. /* OSPF Network-LSAs structure. */
  156. #define OSPF_NETWORK_LSA_MIN_SIZE 8U /* w/1 router-ID */
  157. struct network_lsa
  158. {
  159. struct lsa_header header;
  160. struct in_addr mask;
  161. struct in_addr routers[1];
  162. };
  163. /* OSPF Summary-LSAs structure. */
  164. #define OSPF_SUMMARY_LSA_MIN_SIZE 8U /* w/1 TOS metric block */
  165. struct summary_lsa
  166. {
  167. struct lsa_header header;
  168. struct in_addr mask;
  169. u_char tos;
  170. u_char metric[3];
  171. };
  172. /* OSPF AS-external-LSAs structure. */
  173. #define OSPF_AS_EXTERNAL_LSA_MIN_SIZE 16U /* w/1 TOS forwarding block */
  174. struct as_external_lsa
  175. {
  176. struct lsa_header header;
  177. struct in_addr mask;
  178. struct
  179. {
  180. u_char tos;
  181. u_char metric[3];
  182. struct in_addr fwd_addr;
  183. u_int32_t route_tag;
  184. } e[1];
  185. };
  186. #ifdef HAVE_OPAQUE_LSA
  187. #include "ospfd/ospf_opaque.h"
  188. #endif /* HAVE_OPAQUE_LSA */
  189. /* Macros. */
  190. #define GET_METRIC(x) get_metric(x)
  191. #define IS_EXTERNAL_METRIC(x) ((x) & 0x80)
  192. #define GET_AGE(x) (ntohs ((x)->data->ls_age) + time (NULL) - (x)->tv_recv)
  193. #define LS_AGE(x) (OSPF_LSA_MAXAGE < get_age(x) ? \
  194. OSPF_LSA_MAXAGE : get_age(x))
  195. #define IS_LSA_SELF(L) (CHECK_FLAG ((L)->flags, OSPF_LSA_SELF))
  196. #define IS_LSA_MAXAGE(L) (LS_AGE ((L)) == OSPF_LSA_MAXAGE)
  197. #define OSPF_LSA_UPDATE_DELAY 2
  198. #define OSPF_LSA_UPDATE_TIMER_ON(T,F) \
  199. if (!(T)) \
  200. (T) = thread_add_timer (master, (F), 0, 2)
  201. /* Prototypes. */
  202. /* XXX: Eek, time functions, similar are in lib/thread.c */
  203. extern struct timeval tv_adjust (struct timeval);
  204. extern int tv_ceil (struct timeval);
  205. extern int tv_floor (struct timeval);
  206. extern struct timeval int2tv (int);
  207. extern struct timeval tv_add (struct timeval, struct timeval);
  208. extern struct timeval tv_sub (struct timeval, struct timeval);
  209. extern int tv_cmp (struct timeval, struct timeval);
  210. extern int get_age (struct ospf_lsa *);
  211. extern u_int16_t ospf_lsa_checksum (struct lsa_header *);
  212. extern int ospf_lsa_checksum_valid (struct lsa_header *);
  213. extern int ospf_lsa_refresh_delay (struct ospf_lsa *);
  214. extern const char *dump_lsa_key (struct ospf_lsa *);
  215. extern u_int32_t lsa_seqnum_increment (struct ospf_lsa *);
  216. extern void lsa_header_set (struct stream *, u_char, u_char, struct in_addr,
  217. struct in_addr);
  218. extern struct ospf_neighbor *ospf_nbr_lookup_ptop (struct ospf_interface *);
  219. extern int ospf_check_nbr_status (struct ospf *);
  220. /* Prototype for LSA primitive. */
  221. extern struct ospf_lsa *ospf_lsa_new (void);
  222. extern struct ospf_lsa *ospf_lsa_dup (struct ospf_lsa *);
  223. extern void ospf_lsa_free (struct ospf_lsa *);
  224. extern struct ospf_lsa *ospf_lsa_lock (struct ospf_lsa *);
  225. extern void ospf_lsa_unlock (struct ospf_lsa **);
  226. extern void ospf_lsa_discard (struct ospf_lsa *);
  227. extern struct lsa_header *ospf_lsa_data_new (size_t);
  228. extern struct lsa_header *ospf_lsa_data_dup (struct lsa_header *);
  229. extern void ospf_lsa_data_free (struct lsa_header *);
  230. /* Prototype for various LSAs */
  231. extern int ospf_router_lsa_update (struct ospf *);
  232. extern int ospf_router_lsa_update_area (struct ospf_area *);
  233. extern void ospf_network_lsa_update (struct ospf_interface *);
  234. extern struct ospf_lsa *ospf_summary_lsa_originate (struct prefix_ipv4 *, u_int32_t,
  235. struct ospf_area *);
  236. extern struct ospf_lsa *ospf_summary_asbr_lsa_originate (struct prefix_ipv4 *,
  237. u_int32_t,
  238. struct ospf_area *);
  239. extern struct ospf_lsa *ospf_lsa_install (struct ospf *,
  240. struct ospf_interface *, struct ospf_lsa *);
  241. extern void ospf_nssa_lsa_flush (struct ospf *ospf, struct prefix_ipv4 *p);
  242. extern void ospf_external_lsa_flush (struct ospf *, u_char, struct prefix_ipv4 *,
  243. unsigned int /* , struct in_addr nexthop */);
  244. extern struct in_addr ospf_get_ip_from_ifp (struct ospf_interface *);
  245. extern struct ospf_lsa *ospf_external_lsa_originate (struct ospf *, struct external_info *);
  246. extern int ospf_external_lsa_originate_timer (struct thread *);
  247. extern int ospf_default_originate_timer (struct thread *);
  248. extern struct ospf_lsa *ospf_lsa_lookup (struct ospf_area *, u_int32_t,
  249. struct in_addr, struct in_addr);
  250. extern struct ospf_lsa *ospf_lsa_lookup_by_id (struct ospf_area *,
  251. u_int32_t,
  252. struct in_addr);
  253. extern struct ospf_lsa *ospf_lsa_lookup_by_header (struct ospf_area *,
  254. struct lsa_header *);
  255. extern int ospf_lsa_more_recent (struct ospf_lsa *, struct ospf_lsa *);
  256. extern int ospf_lsa_different (struct ospf_lsa *, struct ospf_lsa *);
  257. extern void ospf_flush_self_originated_lsas_now (struct ospf *);
  258. extern int ospf_lsa_is_self_originated (struct ospf *, struct ospf_lsa *);
  259. extern struct ospf_lsa *ospf_lsa_lookup_by_prefix (struct ospf_lsdb *, u_char,
  260. struct prefix_ipv4 *,
  261. struct in_addr);
  262. extern void ospf_lsa_maxage (struct ospf *, struct ospf_lsa *);
  263. extern u_int32_t get_metric (u_char *);
  264. extern int ospf_lsa_maxage_walker (struct thread *);
  265. extern struct ospf_lsa *ospf_lsa_refresh (struct ospf *, struct ospf_lsa *);
  266. extern void ospf_external_lsa_refresh_default (struct ospf *);
  267. extern void ospf_external_lsa_refresh_type (struct ospf *, u_char, int);
  268. extern struct ospf_lsa *ospf_external_lsa_refresh (struct ospf *,
  269. struct ospf_lsa *,
  270. struct external_info *,
  271. int);
  272. extern struct in_addr ospf_lsa_unique_id (struct ospf *, struct ospf_lsdb *, u_char,
  273. struct prefix_ipv4 *);
  274. extern void ospf_schedule_lsa_flood_area (struct ospf_area *, struct ospf_lsa *);
  275. extern void ospf_schedule_lsa_flush_area (struct ospf_area *, struct ospf_lsa *);
  276. extern void ospf_refresher_register_lsa (struct ospf *, struct ospf_lsa *);
  277. extern void ospf_refresher_unregister_lsa (struct ospf *, struct ospf_lsa *);
  278. extern int ospf_lsa_refresh_walker (struct thread *);
  279. extern void ospf_lsa_maxage_delete (struct ospf *, struct ospf_lsa *);
  280. extern void ospf_discard_from_db (struct ospf *, struct ospf_lsdb *, struct ospf_lsa*);
  281. extern int is_prefix_default (struct prefix_ipv4 *);
  282. extern int metric_type (struct ospf *, u_char);
  283. extern int metric_value (struct ospf *, u_char);
  284. extern struct in_addr ospf_get_nssa_ip (struct ospf_area *);
  285. extern int ospf_translated_nssa_compare (struct ospf_lsa *, struct ospf_lsa *);
  286. extern struct ospf_lsa *ospf_translated_nssa_refresh (struct ospf *, struct ospf_lsa *,
  287. struct ospf_lsa *);
  288. extern struct ospf_lsa *ospf_translated_nssa_originate (struct ospf *, struct ospf_lsa *);
  289. #endif /* _ZEBRA_OSPF_LSA_H */