ospf6_lsa.h 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. #define OSPF6_LSA_DEBUG 0x01
  25. #define OSPF6_LSA_DEBUG_ORIGINATE 0x02
  26. #define OSPF6_LSA_DEBUG_EXAMIN 0x04
  27. #define OSPF6_LSA_DEBUG_FLOOD 0x08
  28. #define IS_OSPF6_DEBUG_LSA(name) \
  29. (ospf6_lstype_debug (htons (OSPF6_LSTYPE_ ## name)) & \
  30. OSPF6_LSA_DEBUG)
  31. #define IS_OSPF6_DEBUG_ORIGINATE(name) \
  32. (ospf6_lstype_debug (htons (OSPF6_LSTYPE_ ## name)) & \
  33. OSPF6_LSA_DEBUG_ORIGINATE)
  34. #define IS_OSPF6_DEBUG_EXAMIN(name) \
  35. (ospf6_lstype_debug (htons (OSPF6_LSTYPE_ ## name)) & \
  36. OSPF6_LSA_DEBUG_EXAMIN)
  37. #define IS_OSPF6_DEBUG_LSA_TYPE(type) \
  38. (ospf6_lstype_debug (type) & OSPF6_LSA_DEBUG)
  39. #define IS_OSPF6_DEBUG_ORIGINATE_TYPE(type) \
  40. (ospf6_lstype_debug (type) & OSPF6_LSA_DEBUG_ORIGINATE)
  41. #define IS_OSPF6_DEBUG_EXAMIN_TYPE(type) \
  42. (ospf6_lstype_debug (type) & OSPF6_LSA_DEBUG_EXAMIN)
  43. #define IS_OSPF6_DEBUG_FLOOD_TYPE(type) \
  44. (ospf6_lstype_debug (type) & OSPF6_LSA_DEBUG_FLOOD)
  45. /* LSA definition */
  46. #define OSPF6_MAX_LSASIZE 4096
  47. /* Type */
  48. #define OSPF6_LSTYPE_UNKNOWN 0x0000
  49. #define OSPF6_LSTYPE_ROUTER 0x2001
  50. #define OSPF6_LSTYPE_NETWORK 0x2002
  51. #define OSPF6_LSTYPE_INTER_PREFIX 0x2003
  52. #define OSPF6_LSTYPE_INTER_ROUTER 0x2004
  53. #define OSPF6_LSTYPE_AS_EXTERNAL 0x4005
  54. #define OSPF6_LSTYPE_GROUP_MEMBERSHIP 0x2006
  55. #define OSPF6_LSTYPE_TYPE_7 0x2007
  56. #define OSPF6_LSTYPE_LINK 0x0008
  57. #define OSPF6_LSTYPE_INTRA_PREFIX 0x2009
  58. #define OSPF6_LSTYPE_SIZE 0x000a
  59. /* Masks for LS Type : RFC 2740 A.4.2.1 "LS type" */
  60. #define OSPF6_LSTYPE_UBIT_MASK 0x8000
  61. #define OSPF6_LSTYPE_SCOPE_MASK 0x6000
  62. #define OSPF6_LSTYPE_FCODE_MASK 0x1fff
  63. /* LSA scope */
  64. #define OSPF6_SCOPE_LINKLOCAL 0x0000
  65. #define OSPF6_SCOPE_AREA 0x2000
  66. #define OSPF6_SCOPE_AS 0x4000
  67. #define OSPF6_SCOPE_RESERVED 0x6000
  68. /* XXX U-bit handling should be treated here */
  69. #define OSPF6_LSA_SCOPE(type) \
  70. (ntohs (type) & OSPF6_LSTYPE_SCOPE_MASK)
  71. /* LSA Header */
  72. #define OSPF6_LSA_HEADER_SIZE 20U
  73. struct ospf6_lsa_header
  74. {
  75. u_int16_t age; /* LS age */
  76. u_int16_t type; /* LS type */
  77. u_int32_t id; /* Link State ID */
  78. u_int32_t adv_router; /* Advertising Router */
  79. u_int32_t seqnum; /* LS sequence number */
  80. u_int16_t checksum; /* LS checksum */
  81. u_int16_t length; /* LSA length */
  82. };
  83. #define OSPF6_LSA_HEADER_END(h) \
  84. ((caddr_t)(h) + sizeof (struct ospf6_lsa_header))
  85. #define OSPF6_LSA_SIZE(h) \
  86. (ntohs (((struct ospf6_lsa_header *) (h))->length))
  87. #define OSPF6_LSA_END(h) \
  88. ((caddr_t)(h) + ntohs (((struct ospf6_lsa_header *) (h))->length))
  89. #define OSPF6_LSA_IS_TYPE(t, L) \
  90. ((L)->header->type == htons (OSPF6_LSTYPE_ ## t) ? 1 : 0)
  91. #define OSPF6_LSA_IS_SAME(L1, L2) \
  92. ((L1)->header->adv_router == (L2)->header->adv_router && \
  93. (L1)->header->id == (L2)->header->id && \
  94. (L1)->header->type == (L2)->header->type)
  95. #define OSPF6_LSA_IS_MATCH(t, i, a, L) \
  96. ((L)->header->adv_router == (a) && (L)->header->id == (i) && \
  97. (L)->header->type == (t))
  98. #define OSPF6_LSA_IS_DIFFER(L1, L2) ospf6_lsa_is_differ (L1, L2)
  99. #define OSPF6_LSA_IS_MAXAGE(L) (ospf6_lsa_age_current (L) == OSPF_LSA_MAXAGE)
  100. #define OSPF6_LSA_IS_CHANGED(L1, L2) ospf6_lsa_is_changed (L1, L2)
  101. #define OSPF6_LSA_IS_SEQWRAP(L) ((L)->header->seqnum == htonl(OSPF_MAX_SEQUENCE_NUMBER + 1))
  102. struct ospf6_lsa
  103. {
  104. char name[64]; /* dump string */
  105. struct route_node *rn;
  106. unsigned char lock; /* reference counter */
  107. unsigned char flag; /* special meaning (e.g. floodback) */
  108. struct timeval birth; /* tv_sec when LS age 0 */
  109. struct timeval originated; /* used by MinLSInterval check */
  110. struct timeval received; /* used by MinLSArrival check */
  111. struct timeval installed;
  112. struct thread *expire;
  113. struct thread *refresh; /* For self-originated LSA */
  114. int retrans_count;
  115. struct ospf6_lsdb *lsdb;
  116. /* lsa instance */
  117. struct ospf6_lsa_header *header;
  118. };
  119. #define OSPF6_LSA_HEADERONLY 0x01
  120. #define OSPF6_LSA_FLOODBACK 0x02
  121. #define OSPF6_LSA_DUPLICATE 0x04
  122. #define OSPF6_LSA_IMPLIEDACK 0x08
  123. #define OSPF6_LSA_SEQWRAPPED 0x20
  124. struct ospf6_lsa_handler
  125. {
  126. u_int16_t type; /* host byte order */
  127. const char *name;
  128. const char *short_name;
  129. int (*show) (struct vty *, struct ospf6_lsa *);
  130. char *(*get_prefix_str) (struct ospf6_lsa *, char *buf, int buflen, int pos);
  131. u_char debug;
  132. };
  133. extern struct ospf6_lsa_handler unknown_handler;
  134. #define OSPF6_LSA_IS_KNOWN(type) \
  135. (ospf6_get_lsa_handler (type) != &unknown_handler ? 1 : 0)
  136. /* Macro for LSA Origination */
  137. /* addr is (struct prefix *) */
  138. #define CONTINUE_IF_ADDRESS_LINKLOCAL(debug,addr) \
  139. if (IN6_IS_ADDR_LINKLOCAL (&(addr)->u.prefix6)) \
  140. { \
  141. char buf[64]; \
  142. prefix2str (addr, buf, sizeof (buf)); \
  143. if (debug) \
  144. zlog_debug ("Filter out Linklocal: %s", buf); \
  145. continue; \
  146. }
  147. #define CONTINUE_IF_ADDRESS_UNSPECIFIED(debug,addr) \
  148. if (IN6_IS_ADDR_UNSPECIFIED (&(addr)->u.prefix6)) \
  149. { \
  150. char buf[64]; \
  151. prefix2str (addr, buf, sizeof (buf)); \
  152. if (debug) \
  153. zlog_debug ("Filter out Unspecified: %s", buf);\
  154. continue; \
  155. }
  156. #define CONTINUE_IF_ADDRESS_LOOPBACK(debug,addr) \
  157. if (IN6_IS_ADDR_LOOPBACK (&(addr)->u.prefix6)) \
  158. { \
  159. char buf[64]; \
  160. prefix2str (addr, buf, sizeof (buf)); \
  161. if (debug) \
  162. zlog_debug ("Filter out Loopback: %s", buf); \
  163. continue; \
  164. }
  165. #define CONTINUE_IF_ADDRESS_V4COMPAT(debug,addr) \
  166. if (IN6_IS_ADDR_V4COMPAT (&(addr)->u.prefix6)) \
  167. { \
  168. char buf[64]; \
  169. prefix2str (addr, buf, sizeof (buf)); \
  170. if (debug) \
  171. zlog_debug ("Filter out V4Compat: %s", buf); \
  172. continue; \
  173. }
  174. #define CONTINUE_IF_ADDRESS_V4MAPPED(debug,addr) \
  175. if (IN6_IS_ADDR_V4MAPPED (&(addr)->u.prefix6)) \
  176. { \
  177. char buf[64]; \
  178. prefix2str (addr, buf, sizeof (buf)); \
  179. if (debug) \
  180. zlog_debug ("Filter out V4Mapped: %s", buf); \
  181. continue; \
  182. }
  183. /* Function Prototypes */
  184. extern const char *ospf6_lstype_name (u_int16_t type);
  185. extern const char *ospf6_lstype_short_name (u_int16_t type);
  186. extern u_char ospf6_lstype_debug (u_int16_t type);
  187. extern int ospf6_lsa_is_differ (struct ospf6_lsa *lsa1, struct ospf6_lsa *lsa2);
  188. extern int ospf6_lsa_is_changed (struct ospf6_lsa *lsa1, struct ospf6_lsa *lsa2);
  189. extern u_int16_t ospf6_lsa_age_current (struct ospf6_lsa *);
  190. extern void ospf6_lsa_age_update_to_send (struct ospf6_lsa *, u_int32_t);
  191. extern void ospf6_lsa_premature_aging (struct ospf6_lsa *);
  192. extern int ospf6_lsa_compare (struct ospf6_lsa *, struct ospf6_lsa *);
  193. extern char *ospf6_lsa_printbuf (struct ospf6_lsa *lsa, char *buf, int size);
  194. extern void ospf6_lsa_header_print_raw (struct ospf6_lsa_header *header);
  195. extern void ospf6_lsa_header_print (struct ospf6_lsa *lsa);
  196. extern void ospf6_lsa_show_summary_header (struct vty *vty);
  197. extern void ospf6_lsa_show_summary (struct vty *vty, struct ospf6_lsa *lsa);
  198. extern void ospf6_lsa_show_dump (struct vty *vty, struct ospf6_lsa *lsa);
  199. extern void ospf6_lsa_show_internal (struct vty *vty, struct ospf6_lsa *lsa);
  200. extern void ospf6_lsa_show (struct vty *vty, struct ospf6_lsa *lsa);
  201. extern struct ospf6_lsa *ospf6_lsa_create (struct ospf6_lsa_header *header);
  202. extern struct ospf6_lsa *ospf6_lsa_create_headeronly (struct ospf6_lsa_header *header);
  203. extern void ospf6_lsa_delete (struct ospf6_lsa *lsa);
  204. extern struct ospf6_lsa *ospf6_lsa_copy (struct ospf6_lsa *);
  205. extern void ospf6_lsa_lock (struct ospf6_lsa *);
  206. extern void ospf6_lsa_unlock (struct ospf6_lsa *);
  207. extern int ospf6_lsa_expire (struct thread *);
  208. extern int ospf6_lsa_refresh (struct thread *);
  209. extern unsigned short ospf6_lsa_checksum (struct ospf6_lsa_header *);
  210. extern int ospf6_lsa_checksum_valid (struct ospf6_lsa_header *);
  211. extern int ospf6_lsa_prohibited_duration (u_int16_t type, u_int32_t id,
  212. u_int32_t adv_router, void *scope);
  213. extern void ospf6_install_lsa_handler (struct ospf6_lsa_handler *handler);
  214. extern struct ospf6_lsa_handler *ospf6_get_lsa_handler (u_int16_t type);
  215. extern void ospf6_lsa_init (void);
  216. extern void ospf6_lsa_terminate (void);
  217. extern int config_write_ospf6_debug_lsa (struct vty *vty);
  218. extern void install_element_ospf6_debug_lsa (void);
  219. #endif /* OSPF6_LSA_H */