ospf_packet.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * OSPF Sending and Receiving OSPF Packets.
  3. * Copyright (C) 1999 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_PACKET_H
  23. #define _ZEBRA_OSPF_PACKET_H
  24. #define OSPF_HEADER_SIZE 24U
  25. #define OSPF_AUTH_SIMPLE_SIZE 8U
  26. #define OSPF_AUTH_MD5_SIZE 16U
  27. #define OSPF_MAX_PACKET_SIZE 65535U /* includes IP Header size. */
  28. #define OSPF_HELLO_MIN_SIZE 20U /* not including neighbors */
  29. #define OSPF_DB_DESC_MIN_SIZE 8U
  30. #define OSPF_LS_REQ_MIN_SIZE 0U
  31. #define OSPF_LS_UPD_MIN_SIZE 4U
  32. #define OSPF_LS_ACK_MIN_SIZE 0U
  33. #define OSPF_MSG_HELLO 1 /* OSPF Hello Message. */
  34. #define OSPF_MSG_DB_DESC 2 /* OSPF Database Descriptoin Message. */
  35. #define OSPF_MSG_LS_REQ 3 /* OSPF Link State Request Message. */
  36. #define OSPF_MSG_LS_UPD 4 /* OSPF Link State Update Message. */
  37. #define OSPF_MSG_LS_ACK 5 /* OSPF Link State Acknoledgement Message. */
  38. #define OSPF_SEND_PACKET_DIRECT 1
  39. #define OSPF_SEND_PACKET_INDIRECT 2
  40. #define OSPF_SEND_PACKET_LOOP 3
  41. #define OSPF_HELLO_REPLY_DELAY 1
  42. /* Return values of functions involved in packet verification, see ospf6d. */
  43. #define MSG_OK 0
  44. #define MSG_NG 1
  45. struct ospf_packet
  46. {
  47. struct ospf_packet *next;
  48. /* Pointer to data stream. */
  49. struct stream *s;
  50. /* IP destination address. */
  51. struct in_addr dst;
  52. /* OSPF packet length. */
  53. u_int16_t length;
  54. };
  55. /* OSPF packet queue structure. */
  56. struct ospf_fifo
  57. {
  58. unsigned long count;
  59. struct ospf_packet *head;
  60. struct ospf_packet *tail;
  61. };
  62. /* OSPF packet header structure. */
  63. struct ospf_header
  64. {
  65. u_char version; /* OSPF Version. */
  66. u_char type; /* Packet Type. */
  67. u_int16_t length; /* Packet Length. */
  68. struct in_addr router_id; /* Router ID. */
  69. struct in_addr area_id; /* Area ID. */
  70. u_int16_t checksum; /* Check Sum. */
  71. u_int16_t auth_type; /* Authentication Type. */
  72. /* Authentication Data. */
  73. union
  74. {
  75. /* Simple Authentication. */
  76. u_char auth_data [OSPF_AUTH_SIMPLE_SIZE];
  77. /* Cryptographic Authentication. */
  78. struct
  79. {
  80. u_int16_t zero; /* Should be 0. */
  81. u_char key_id; /* Key ID. */
  82. u_char auth_data_len; /* Auth Data Length. */
  83. u_int32_t crypt_seqnum; /* Cryptographic Sequence Number. */
  84. } crypt;
  85. } u;
  86. };
  87. /* OSPF Hello body format. */
  88. struct ospf_hello
  89. {
  90. struct in_addr network_mask;
  91. u_int16_t hello_interval;
  92. u_char options;
  93. u_char priority;
  94. u_int32_t dead_interval;
  95. struct in_addr d_router;
  96. struct in_addr bd_router;
  97. struct in_addr neighbors[1];
  98. };
  99. /* OSPF Database Description body format. */
  100. struct ospf_db_desc
  101. {
  102. u_int16_t mtu;
  103. u_char options;
  104. u_char flags;
  105. u_int32_t dd_seqnum;
  106. };
  107. struct ospf_ls_update
  108. {
  109. u_int32_t num_lsas;
  110. };
  111. /* Macros. */
  112. /* XXX Perhaps obsolete; function in ospf_packet.c */
  113. #define OSPF_PACKET_MAX(oi) ospf_packet_max (oi)
  114. #define OSPF_OUTPUT_PNT(S) ((S)->data + (S)->putp)
  115. #define OSPF_OUTPUT_LENGTH(S) ((S)->endp)
  116. #define IS_SET_DD_MS(X) ((X) & OSPF_DD_FLAG_MS)
  117. #define IS_SET_DD_M(X) ((X) & OSPF_DD_FLAG_M)
  118. #define IS_SET_DD_I(X) ((X) & OSPF_DD_FLAG_I)
  119. #define IS_SET_DD_ALL(X) ((X) & OSPF_DD_FLAG_ALL)
  120. /* Prototypes. */
  121. extern void ospf_output_forward (struct stream *, int);
  122. extern struct ospf_packet *ospf_packet_new (size_t);
  123. extern void ospf_packet_free (struct ospf_packet *);
  124. extern struct ospf_fifo *ospf_fifo_new (void);
  125. extern void ospf_fifo_push (struct ospf_fifo *, struct ospf_packet *);
  126. extern struct ospf_packet *ospf_fifo_pop (struct ospf_fifo *);
  127. extern struct ospf_packet *ospf_fifo_head (struct ospf_fifo *);
  128. extern void ospf_fifo_flush (struct ospf_fifo *);
  129. extern void ospf_fifo_free (struct ospf_fifo *);
  130. extern void ospf_packet_add (struct ospf_interface *, struct ospf_packet *);
  131. extern void ospf_packet_delete (struct ospf_interface *);
  132. extern struct stream *ospf_stream_dup (struct stream *);
  133. extern struct ospf_packet *ospf_packet_dup (struct ospf_packet *);
  134. extern int ospf_read (struct thread *);
  135. extern void ospf_hello_send (struct ospf_interface *);
  136. extern void ospf_db_desc_send (struct ospf_neighbor *);
  137. extern void ospf_db_desc_resend (struct ospf_neighbor *);
  138. extern void ospf_ls_req_send (struct ospf_neighbor *);
  139. extern void ospf_ls_upd_send_lsa (struct ospf_neighbor *, struct ospf_lsa *,
  140. int);
  141. extern void ospf_ls_upd_send (struct ospf_neighbor *, struct list *, int);
  142. extern void ospf_ls_ack_send (struct ospf_neighbor *, struct ospf_lsa *);
  143. extern void ospf_ls_ack_send_delayed (struct ospf_interface *);
  144. extern void ospf_ls_retransmit (struct ospf_interface *, struct ospf_lsa *);
  145. extern void ospf_ls_req_event (struct ospf_neighbor *);
  146. extern int ospf_ls_upd_timer (struct thread *);
  147. extern int ospf_ls_ack_timer (struct thread *);
  148. extern int ospf_poll_timer (struct thread *);
  149. extern int ospf_hello_reply_timer (struct thread *);
  150. extern const struct message ospf_packet_type_str[];
  151. extern const size_t ospf_packet_type_str_max;
  152. #endif /* _ZEBRA_OSPF_PACKET_H */