ospf.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. /*
  2. * Copyright (c) 1991, 1993, 1994, 1995, 1996, 1997
  3. * The Regents of the University of California. All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that: (1) source code distributions
  7. * retain the above copyright notice and this paragraph in its entirety, (2)
  8. * distributions including binary code include the above copyright notice and
  9. * this paragraph in its entirety in the documentation or other materials
  10. * provided with the distribution, and (3) all advertising materials mentioning
  11. * features or use of this software display the following acknowledgement:
  12. * ``This product includes software developed by the University of California,
  13. * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
  14. * the University nor the names of its contributors may be used to endorse
  15. * or promote products derived from this software without specific prior
  16. * written permission.
  17. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  18. * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  19. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  20. *
  21. * OSPF support contributed by Jeffrey Honig (jch@mitchell.cit.cornell.edu)
  22. */
  23. #define OSPF_TYPE_UMD 0 /* UMd's special monitoring packets */
  24. #define OSPF_TYPE_HELLO 1 /* Hello */
  25. #define OSPF_TYPE_DD 2 /* Database Description */
  26. #define OSPF_TYPE_LS_REQ 3 /* Link State Request */
  27. #define OSPF_TYPE_LS_UPDATE 4 /* Link State Update */
  28. #define OSPF_TYPE_LS_ACK 5 /* Link State Ack */
  29. /* Options field
  30. *
  31. * +------------------------------------+
  32. * | DN | O | DC | L | N/P | MC | E | T |
  33. * +------------------------------------+
  34. *
  35. */
  36. #define OSPF_OPTION_T 0x01 /* T bit: TOS support */
  37. #define OSPF_OPTION_E 0x02 /* E bit: External routes advertised */
  38. #define OSPF_OPTION_MC 0x04 /* MC bit: Multicast capable */
  39. #define OSPF_OPTION_NP 0x08 /* N/P bit: NSSA capable */
  40. #define OSPF_OPTION_EA 0x10 /* EA bit: External Attribute capable */
  41. #define OSPF_OPTION_L 0x10 /* L bit: Packet contains LLS data block */
  42. #define OSPF_OPTION_DC 0x20 /* DC bit: Demand circuit capable */
  43. #define OSPF_OPTION_O 0x40 /* O bit: Opaque LSA capable */
  44. #define OSPF_OPTION_DN 0x80 /* DN bit: Up/Down Bit capable - draft-ietf-ospf-2547-dnbit-04 */
  45. /* ospf_authtype */
  46. #define OSPF_AUTH_NONE 0 /* No auth-data */
  47. #define OSPF_AUTH_SIMPLE 1 /* Simple password */
  48. #define OSPF_AUTH_SIMPLE_LEN 8 /* max length of simple authentication */
  49. #define OSPF_AUTH_MD5 2 /* MD5 authentication */
  50. #define OSPF_AUTH_MD5_LEN 16 /* length of MD5 authentication */
  51. /* db_flags */
  52. #define OSPF_DB_INIT 0x04
  53. #define OSPF_DB_MORE 0x02
  54. #define OSPF_DB_MASTER 0x01
  55. #define OSPF_DB_RESYNC 0x08 /* RFC4811 */
  56. /* ls_type */
  57. #define LS_TYPE_ROUTER 1 /* router link */
  58. #define LS_TYPE_NETWORK 2 /* network link */
  59. #define LS_TYPE_SUM_IP 3 /* summary link */
  60. #define LS_TYPE_SUM_ABR 4 /* summary area link */
  61. #define LS_TYPE_ASE 5 /* ASE */
  62. #define LS_TYPE_GROUP 6 /* Group membership (multicast */
  63. /* extensions 23 July 1991) */
  64. #define LS_TYPE_NSSA 7 /* rfc3101 - Not so Stubby Areas */
  65. #define LS_TYPE_OPAQUE_LL 9 /* rfc2370 - Opaque Link Local */
  66. #define LS_TYPE_OPAQUE_AL 10 /* rfc2370 - Opaque Link Local */
  67. #define LS_TYPE_OPAQUE_DW 11 /* rfc2370 - Opaque Domain Wide */
  68. #define LS_OPAQUE_TYPE_TE 1 /* rfc3630 */
  69. #define LS_OPAQUE_TYPE_GRACE 3 /* rfc3623 */
  70. #define LS_OPAQUE_TYPE_RI 4 /* draft-ietf-ospf-cap-03 */
  71. #define LS_OPAQUE_TE_TLV_ROUTER 1 /* rfc3630 */
  72. #define LS_OPAQUE_TE_TLV_LINK 2 /* rfc3630 */
  73. #define LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE 1 /* rfc3630 */
  74. #define LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID 2 /* rfc3630 */
  75. #define LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP 3 /* rfc3630 */
  76. #define LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP 4 /* rfc3630 */
  77. #define LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC 5 /* rfc3630 */
  78. #define LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW 6 /* rfc3630 */
  79. #define LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW 7 /* rfc3630 */
  80. #define LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW 8 /* rfc3630 */
  81. #define LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP 9 /* rfc3630 */
  82. #define LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID 11 /* rfc4203 */
  83. #define LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE 14 /* rfc4203 */
  84. #define LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR 15 /* rfc4203 */
  85. #define LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP 16 /* rfc4203 */
  86. #define LS_OPAQUE_TE_LINK_SUBTLV_BW_CONSTRAINTS 17 /* rfc4124 */
  87. #define LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_PTP 1 /* rfc3630 */
  88. #define LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_MA 2 /* rfc3630 */
  89. #define LS_OPAQUE_GRACE_TLV_PERIOD 1 /* rfc3623 */
  90. #define LS_OPAQUE_GRACE_TLV_REASON 2 /* rfc3623 */
  91. #define LS_OPAQUE_GRACE_TLV_INT_ADDRESS 3 /* rfc3623 */
  92. #define LS_OPAQUE_GRACE_TLV_REASON_UNKNOWN 0 /* rfc3623 */
  93. #define LS_OPAQUE_GRACE_TLV_REASON_SW_RESTART 1 /* rfc3623 */
  94. #define LS_OPAQUE_GRACE_TLV_REASON_SW_UPGRADE 2 /* rfc3623 */
  95. #define LS_OPAQUE_GRACE_TLV_REASON_CP_SWITCH 3 /* rfc3623 */
  96. #define LS_OPAQUE_RI_TLV_CAP 1 /* draft-ietf-ospf-cap-03 */
  97. /* rla_link.link_type */
  98. #define RLA_TYPE_ROUTER 1 /* point-to-point to another router */
  99. #define RLA_TYPE_TRANSIT 2 /* connection to transit network */
  100. #define RLA_TYPE_STUB 3 /* connection to stub network */
  101. #define RLA_TYPE_VIRTUAL 4 /* virtual link */
  102. /* rla_flags */
  103. #define RLA_FLAG_B 0x01
  104. #define RLA_FLAG_E 0x02
  105. #define RLA_FLAG_W1 0x04
  106. #define RLA_FLAG_W2 0x08
  107. /* sla_tosmetric breakdown */
  108. #define SLA_MASK_TOS 0x7f000000
  109. #define SLA_MASK_METRIC 0x00ffffff
  110. #define SLA_SHIFT_TOS 24
  111. /* asla_tosmetric breakdown */
  112. #define ASLA_FLAG_EXTERNAL 0x80000000
  113. #define ASLA_MASK_TOS 0x7f000000
  114. #define ASLA_SHIFT_TOS 24
  115. #define ASLA_MASK_METRIC 0x00ffffff
  116. /* multicast vertex type */
  117. #define MCLA_VERTEX_ROUTER 1
  118. #define MCLA_VERTEX_NETWORK 2
  119. /* Link-Local-Signaling */
  120. #define OSPF_LLS_HDRLEN 4U /* RFC5613 Section 2.2 */
  121. #define OSPF_LLS_EO 1 /* RFC4811, RFC4812 */
  122. #define OSPF_LLS_MD5 2 /* RFC4813 */
  123. #define OSPF_LLS_EO_LR 0x00000001 /* RFC4811 */
  124. #define OSPF_LLS_EO_RS 0x00000002 /* RFC4812 */
  125. /*
  126. * TOS metric struct (will be 0 or more in router links update)
  127. */
  128. struct tos_metric {
  129. uint8_t tos_type;
  130. uint8_t reserved;
  131. uint8_t tos_metric[2];
  132. };
  133. struct tos_link {
  134. uint8_t link_type;
  135. uint8_t link_tos_count;
  136. uint8_t tos_metric[2];
  137. };
  138. union un_tos {
  139. struct tos_link link;
  140. struct tos_metric metrics;
  141. };
  142. /* link state advertisement header */
  143. struct lsa_hdr {
  144. uint16_t ls_age;
  145. uint8_t ls_options;
  146. uint8_t ls_type;
  147. union {
  148. struct in_addr lsa_id;
  149. struct { /* opaque LSAs change the LSA-ID field */
  150. uint8_t opaque_type;
  151. uint8_t opaque_id[3];
  152. } opaque_field;
  153. } un_lsa_id;
  154. struct in_addr ls_router;
  155. uint32_t ls_seq;
  156. uint16_t ls_chksum;
  157. uint16_t ls_length;
  158. };
  159. /* link state advertisement */
  160. struct lsa {
  161. struct lsa_hdr ls_hdr;
  162. /* Link state types */
  163. union {
  164. /* Router links advertisements */
  165. struct {
  166. uint8_t rla_flags;
  167. uint8_t rla_zero[1];
  168. uint16_t rla_count;
  169. struct rlalink {
  170. struct in_addr link_id;
  171. struct in_addr link_data;
  172. union un_tos un_tos;
  173. } rla_link[1]; /* may repeat */
  174. } un_rla;
  175. /* Network links advertisements */
  176. struct {
  177. struct in_addr nla_mask;
  178. struct in_addr nla_router[1]; /* may repeat */
  179. } un_nla;
  180. /* Summary links advertisements */
  181. struct {
  182. struct in_addr sla_mask;
  183. uint32_t sla_tosmetric[1]; /* may repeat */
  184. } un_sla;
  185. /* AS external links advertisements */
  186. struct {
  187. struct in_addr asla_mask;
  188. struct aslametric {
  189. uint32_t asla_tosmetric;
  190. struct in_addr asla_forward;
  191. struct in_addr asla_tag;
  192. } asla_metric[1]; /* may repeat */
  193. } un_asla;
  194. /* Multicast group membership */
  195. struct mcla {
  196. uint32_t mcla_vtype;
  197. struct in_addr mcla_vid;
  198. } un_mcla[1];
  199. /* Opaque TE LSA */
  200. struct {
  201. uint16_t type;
  202. uint16_t length;
  203. uint8_t data[1]; /* may repeat */
  204. } un_te_lsa_tlv;
  205. /* Opaque Grace LSA */
  206. struct {
  207. uint16_t type;
  208. uint16_t length;
  209. uint8_t data[1]; /* may repeat */
  210. } un_grace_tlv;
  211. /* Opaque Router information LSA */
  212. struct {
  213. uint16_t type;
  214. uint16_t length;
  215. uint8_t data[1]; /* may repeat */
  216. } un_ri_tlv;
  217. /* Unknown LSA */
  218. struct unknown {
  219. uint8_t data[1]; /* may repeat */
  220. } un_unknown[1];
  221. } lsa_un;
  222. };
  223. #define OSPF_AUTH_SIZE 8
  224. /*
  225. * the main header
  226. */
  227. struct ospfhdr {
  228. uint8_t ospf_version;
  229. uint8_t ospf_type;
  230. uint16_t ospf_len;
  231. struct in_addr ospf_routerid;
  232. struct in_addr ospf_areaid;
  233. uint16_t ospf_chksum;
  234. uint16_t ospf_authtype;
  235. uint8_t ospf_authdata[OSPF_AUTH_SIZE];
  236. union {
  237. /* Hello packet */
  238. struct {
  239. struct in_addr hello_mask;
  240. uint16_t hello_helloint;
  241. uint8_t hello_options;
  242. uint8_t hello_priority;
  243. uint32_t hello_deadint;
  244. struct in_addr hello_dr;
  245. struct in_addr hello_bdr;
  246. struct in_addr hello_neighbor[1]; /* may repeat */
  247. } un_hello;
  248. /* Database Description packet */
  249. struct {
  250. uint16_t db_ifmtu;
  251. uint8_t db_options;
  252. uint8_t db_flags;
  253. uint32_t db_seq;
  254. struct lsa_hdr db_lshdr[1]; /* may repeat */
  255. } un_db;
  256. /* Link State Request */
  257. struct lsr {
  258. uint8_t ls_type[4];
  259. union {
  260. struct in_addr ls_stateid;
  261. struct { /* opaque LSAs change the LSA-ID field */
  262. uint8_t opaque_type;
  263. uint8_t opaque_id[3];
  264. } opaque_field;
  265. } un_ls_stateid;
  266. struct in_addr ls_router;
  267. } un_lsr[1]; /* may repeat */
  268. /* Link State Update */
  269. struct {
  270. uint32_t lsu_count;
  271. struct lsa lsu_lsa[1]; /* may repeat */
  272. } un_lsu;
  273. /* Link State Acknowledgement */
  274. struct {
  275. struct lsa_hdr lsa_lshdr[1]; /* may repeat */
  276. } un_lsa ;
  277. } ospf_un ;
  278. };
  279. #define ospf_hello ospf_un.un_hello
  280. #define ospf_db ospf_un.un_db
  281. #define ospf_lsr ospf_un.un_lsr
  282. #define ospf_lsu ospf_un.un_lsu
  283. #define ospf_lsa ospf_un.un_lsa