ospf6_lsa.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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_LSA_H
  22. #define OSPF6_LSA_H
  23. /* Debug option */
  24. extern unsigned char conf_debug_ospf6_lsa;
  25. #define OSPF6_DEBUG_LSA_SEND 0x01
  26. #define OSPF6_DEBUG_LSA_RECV 0x02
  27. #define OSPF6_DEBUG_LSA_ORIGINATE 0x04
  28. #define OSPF6_DEBUG_LSA_TIMER 0x08
  29. #define OSPF6_DEBUG_LSA_DATABASE 0x10
  30. #define OSPF6_DEBUG_LSA_MEMORY 0x80
  31. #define OSPF6_DEBUG_LSA_ALL 0x9f
  32. #define OSPF6_DEBUG_LSA_DEFAULT 0x0f
  33. #define OSPF6_DEBUG_LSA_ON(level) \
  34. (conf_debug_ospf6_lsa |= (level))
  35. #define OSPF6_DEBUG_LSA_OFF(level) \
  36. (conf_debug_ospf6_lsa &= ~(level))
  37. #define IS_OSPF6_DEBUG_LSA(e) \
  38. (conf_debug_ospf6_lsa & OSPF6_DEBUG_LSA_ ## e)
  39. /* LSA definition */
  40. #define OSPF6_MAX_LSASIZE 4096
  41. /* Type */
  42. #define OSPF6_LSTYPE_UNKNOWN 0x0000
  43. #define OSPF6_LSTYPE_ROUTER 0x2001
  44. #define OSPF6_LSTYPE_NETWORK 0x2002
  45. #define OSPF6_LSTYPE_INTER_PREFIX 0x2003
  46. #define OSPF6_LSTYPE_INTER_ROUTER 0x2004
  47. #define OSPF6_LSTYPE_AS_EXTERNAL 0x4005
  48. #define OSPF6_LSTYPE_GROUP_MEMBERSHIP 0x2006
  49. #define OSPF6_LSTYPE_TYPE_7 0x2007
  50. #define OSPF6_LSTYPE_LINK 0x0008
  51. #define OSPF6_LSTYPE_INTRA_PREFIX 0x2009
  52. #define OSPF6_LSTYPE_SIZE 0x000a
  53. /* Masks for LS Type : RFC 2740 A.4.2.1 "LS type" */
  54. #define OSPF6_LSTYPE_UBIT_MASK 0x8000
  55. #define OSPF6_LSTYPE_SCOPE_MASK 0x6000
  56. #define OSPF6_LSTYPE_FCODE_MASK 0x1fff
  57. /* LSA scope */
  58. #define OSPF6_LSA_SCOPE_LINKLOCAL 0x0000
  59. #define OSPF6_LSA_SCOPE_AREA 0x2000
  60. #define OSPF6_LSA_SCOPE_AS 0x4000
  61. #define OSPF6_LSA_SCOPE_RESERVED 0x6000
  62. #define OSPF6_LSA_SCOPE(type) \
  63. (ntohs (type) & OSPF6_LSTYPE_SCOPE_MASK)
  64. /* LSA Header */
  65. struct ospf6_lsa_header
  66. {
  67. u_int16_t age; /* LS age */
  68. u_int16_t type; /* LS type */
  69. u_int32_t id; /* Link State ID */
  70. u_int32_t adv_router; /* Advertising Router */
  71. u_int32_t seqnum; /* LS sequence number */
  72. u_int16_t checksum; /* LS checksum */
  73. u_int16_t length; /* LSA length */
  74. };
  75. #define OSPF6_LSA_HEADER_END(h) \
  76. ((caddr_t)(h) + sizeof (struct ospf6_lsa_header))
  77. #define OSPF6_LSA_SIZE(h) \
  78. (ntohs (((struct ospf6_lsa_header *) (h))->length))
  79. #define OSPF6_LSA_END(h) \
  80. ((caddr_t)(h) + ntohs (((struct ospf6_lsa_header *) (h))->length))
  81. #define OSPF6_LSA_IS_TYPE(t, L) \
  82. ((L)->header->type == htons (OSPF6_LSTYPE_ ## t) ? 1 : 0)
  83. #define OSPF6_LSA_IS_SAME(L1, L2) \
  84. ((L1)->header->adv_router == (L2)->header->adv_router && \
  85. (L1)->header->id == (L2)->header->id && \
  86. (L1)->header->type == (L2)->header->type)
  87. #define OSPF6_LSA_IS_MATCH(t, i, a, L) \
  88. ((L)->header->adv_router == (a) && (L)->header->id == (i) && \
  89. (L)->header->type == (t))
  90. #define OSPF6_LSA_IS_DIFFER(L1, L2) ospf6_lsa_is_differ (L1, L2)
  91. #define OSPF6_LSA_IS_MAXAGE(L) (ospf6_lsa_age_current (L) == MAXAGE)
  92. #define OSPF6_LSA_IS_CHANGED(L1, L2) ospf6_lsa_is_changed (L1, L2)
  93. struct ospf6_lsa
  94. {
  95. char name[64]; /* dump string */
  96. struct ospf6_lsa *prev;
  97. struct ospf6_lsa *next;
  98. unsigned char lock; /* reference counter */
  99. unsigned char flag; /* special meaning (e.g. floodback) */
  100. struct timeval birth; /* tv_sec when LS age 0 */
  101. struct timeval installed; /* used by MinLSArrival check */
  102. struct timeval originated; /* used by MinLSInterval check */
  103. struct thread *expire;
  104. struct thread *refresh; /* For self-originated LSA */
  105. void *scope; /* pointer to scope data structure */
  106. int headeronly; /* indicate this is LS header only */
  107. int onretrans;
  108. /* lsa instance */
  109. struct ospf6_lsa_header *header;
  110. };
  111. #define OSPF6_LSA_FLOODBACK 0x01
  112. #define OSPF6_LSA_DUPLICATE 0x02
  113. #define OSPF6_LSA_IMPLIEDACK 0x04
  114. #define OSPF6_LSA_REFRESH 0x08
  115. struct ospf6_lstype
  116. {
  117. char *name;
  118. int (*reoriginate) (struct ospf6_lsa *);
  119. int (*show) (struct vty *, struct ospf6_lsa *);
  120. };
  121. extern struct ospf6_lstype ospf6_lstype[OSPF6_LSTYPE_SIZE];
  122. #define OSPF6_LSTYPE_INDEX(type) \
  123. (((type) & OSPF6_LSTYPE_FCODE_MASK) < OSPF6_LSTYPE_SIZE ? \
  124. ((type) & OSPF6_LSTYPE_FCODE_MASK) : OSPF6_LSTYPE_UNKNOWN)
  125. #if 0
  126. extern char *ospf6_lstype_str[OSPF6_LSTYPE_SIZE];
  127. #define OSPF6_LSTYPE_NAME(type) \
  128. ((ntohs (type) & OSPF6_LSTYPE_FCODE_MASK) < OSPF6_LSTYPE_SIZE ? \
  129. ospf6_lstype_str[ntohs (type) & OSPF6_LSTYPE_FCODE_MASK] : \
  130. ospf6_lstype_str[OSPF6_LSTYPE_UNKNOWN])
  131. #else /*0*/
  132. #define OSPF6_LSTYPE_NAME(type) (ospf6_lstype_name (type))
  133. #endif /*0*/
  134. /* Macro for LSA Origination */
  135. /* void (CONTINUE_IF_...) (struct prefix *addr); */
  136. #define CONTINUE_IF_ADDRESS_LINKLOCAL(addr)\
  137. if (IN6_IS_ADDR_LINKLOCAL (&(addr)->u.prefix6)) \
  138. { \
  139. char buf[64]; \
  140. prefix2str (addr, buf, sizeof (buf)); \
  141. if (IS_OSPF6_DEBUG_LSA (ORIGINATE)) \
  142. zlog_info ("Filter out Linklocal: %s", buf); \
  143. continue; \
  144. }
  145. #define CONTINUE_IF_ADDRESS_UNSPECIFIED(addr) \
  146. if (IN6_IS_ADDR_UNSPECIFIED (&(addr)->u.prefix6)) \
  147. { \
  148. char buf[64]; \
  149. prefix2str (addr, buf, sizeof (buf)); \
  150. if (IS_OSPF6_DEBUG_LSA (ORIGINATE)) \
  151. zlog_info ("Filter out Unspecified: %s", buf); \
  152. continue; \
  153. }
  154. #define CONTINUE_IF_ADDRESS_LOOPBACK(addr) \
  155. if (IN6_IS_ADDR_LOOPBACK (&(addr)->u.prefix6)) \
  156. { \
  157. char buf[64]; \
  158. prefix2str (addr, buf, sizeof (buf)); \
  159. if (IS_OSPF6_DEBUG_LSA (ORIGINATE)) \
  160. zlog_info ("Filter out Loopback: %s", buf); \
  161. continue; \
  162. }
  163. #define CONTINUE_IF_ADDRESS_V4COMPAT(addr) \
  164. if (IN6_IS_ADDR_V4COMPAT (&(addr)->u.prefix6)) \
  165. { \
  166. char buf[64]; \
  167. prefix2str (addr, buf, sizeof (buf)); \
  168. if (IS_OSPF6_DEBUG_LSA (ORIGINATE)) \
  169. zlog_info ("Filter out V4Compat: %s", buf); \
  170. continue; \
  171. }
  172. #define CONTINUE_IF_ADDRESS_V4MAPPED(addr) \
  173. if (IN6_IS_ADDR_V4MAPPED (&(addr)->u.prefix6)) \
  174. { \
  175. char buf[64]; \
  176. prefix2str (addr, buf, sizeof (buf)); \
  177. if (IS_OSPF6_DEBUG_LSA (ORIGINATE)) \
  178. zlog_info ("Filter out V4Mapped: %s", buf); \
  179. continue; \
  180. }
  181. /* Function Prototypes */
  182. char *ospf6_lstype_name (u_int16_t type);
  183. int ospf6_lsa_is_differ (struct ospf6_lsa *lsa1, struct ospf6_lsa *lsa2);
  184. int ospf6_lsa_is_changed (struct ospf6_lsa *lsa1, struct ospf6_lsa *lsa2);
  185. u_int16_t ospf6_lsa_age_current (struct ospf6_lsa *);
  186. void ospf6_lsa_age_update_to_send (struct ospf6_lsa *, u_int32_t);
  187. void ospf6_lsa_premature_aging (struct ospf6_lsa *);
  188. int ospf6_lsa_compare (struct ospf6_lsa *, struct ospf6_lsa *);
  189. char *ospf6_lsa_printbuf (struct ospf6_lsa *lsa, char *buf, int size);
  190. void ospf6_lsa_header_print_raw (struct ospf6_lsa_header *header);
  191. void ospf6_lsa_header_print (struct ospf6_lsa *lsa);
  192. void ospf6_lsa_show (struct vty *vty, struct ospf6_lsa *lsa);
  193. void ospf6_lsa_show_summary_header (struct vty *vty);
  194. void ospf6_lsa_show_summary (struct vty *vty, struct ospf6_lsa *lsa);
  195. void ospf6_lsa_show_dump (struct vty *vty, struct ospf6_lsa *lsa);
  196. void ospf6_lsa_show_internal (struct vty *vty, struct ospf6_lsa *lsa);
  197. u_int32_t ospf6_lsa_new_seqnum (u_int16_t type, u_int32_t id,
  198. u_int32_t adv_router, void *scope);
  199. struct ospf6_lsa *ospf6_lsa_create (struct ospf6_lsa_header *header);
  200. struct ospf6_lsa *ospf6_lsa_create_headeronly (struct ospf6_lsa_header *header);
  201. void ospf6_lsa_delete (struct ospf6_lsa *lsa);
  202. struct ospf6_lsa *ospf6_lsa_copy (struct ospf6_lsa *);
  203. void ospf6_lsa_lock (struct ospf6_lsa *);
  204. void ospf6_lsa_unlock (struct ospf6_lsa *);
  205. void ospf6_lsa_originate (struct ospf6_lsa *);
  206. void ospf6_lsa_re_originate (struct ospf6_lsa *lsa);
  207. int ospf6_lsa_expire (struct thread *);
  208. int ospf6_lsa_refresh (struct thread *);
  209. unsigned short ospf6_lsa_checksum (struct ospf6_lsa_header *);
  210. int ospf6_lsa_prohibited_duration (u_int16_t type, u_int32_t id,
  211. u_int32_t adv_router, void *scope);
  212. void ospf6_lsa_init ();
  213. int config_write_ospf6_debug_lsa (struct vty *vty);
  214. void install_element_ospf6_debug_lsa ();
  215. #endif /* OSPF6_LSA_H */