ospf_lsa.h 12 KB

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