print-ospf.c 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209
  1. /*
  2. * Copyright (c) 1992, 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. /* \summary: Open Shortest Path First (OSPF) printer */
  24. #ifdef HAVE_CONFIG_H
  25. #include "config.h"
  26. #endif
  27. #include <netdissect-stdinc.h>
  28. #include "netdissect.h"
  29. #include "addrtoname.h"
  30. #include "extract.h"
  31. #include "gmpls.h"
  32. #include "ospf.h"
  33. static const char tstr[] = " [|ospf2]";
  34. static const struct tok ospf_option_values[] = {
  35. { OSPF_OPTION_T, "MultiTopology" }, /* draft-ietf-ospf-mt-09 */
  36. { OSPF_OPTION_E, "External" },
  37. { OSPF_OPTION_MC, "Multicast" },
  38. { OSPF_OPTION_NP, "NSSA" },
  39. { OSPF_OPTION_L, "LLS" },
  40. { OSPF_OPTION_DC, "Demand Circuit" },
  41. { OSPF_OPTION_O, "Opaque" },
  42. { OSPF_OPTION_DN, "Up/Down" },
  43. { 0, NULL }
  44. };
  45. static const struct tok ospf_authtype_values[] = {
  46. { OSPF_AUTH_NONE, "none" },
  47. { OSPF_AUTH_SIMPLE, "simple" },
  48. { OSPF_AUTH_MD5, "MD5" },
  49. { 0, NULL }
  50. };
  51. static const struct tok ospf_rla_flag_values[] = {
  52. { RLA_FLAG_B, "ABR" },
  53. { RLA_FLAG_E, "ASBR" },
  54. { RLA_FLAG_W1, "Virtual" },
  55. { RLA_FLAG_W2, "W2" },
  56. { 0, NULL }
  57. };
  58. static const struct tok type2str[] = {
  59. { OSPF_TYPE_UMD, "UMD" },
  60. { OSPF_TYPE_HELLO, "Hello" },
  61. { OSPF_TYPE_DD, "Database Description" },
  62. { OSPF_TYPE_LS_REQ, "LS-Request" },
  63. { OSPF_TYPE_LS_UPDATE, "LS-Update" },
  64. { OSPF_TYPE_LS_ACK, "LS-Ack" },
  65. { 0, NULL }
  66. };
  67. static const struct tok lsa_values[] = {
  68. { LS_TYPE_ROUTER, "Router" },
  69. { LS_TYPE_NETWORK, "Network" },
  70. { LS_TYPE_SUM_IP, "Summary" },
  71. { LS_TYPE_SUM_ABR, "ASBR Summary" },
  72. { LS_TYPE_ASE, "External" },
  73. { LS_TYPE_GROUP, "Multicast Group" },
  74. { LS_TYPE_NSSA, "NSSA" },
  75. { LS_TYPE_OPAQUE_LL, "Link Local Opaque" },
  76. { LS_TYPE_OPAQUE_AL, "Area Local Opaque" },
  77. { LS_TYPE_OPAQUE_DW, "Domain Wide Opaque" },
  78. { 0, NULL }
  79. };
  80. static const struct tok ospf_dd_flag_values[] = {
  81. { OSPF_DB_INIT, "Init" },
  82. { OSPF_DB_MORE, "More" },
  83. { OSPF_DB_MASTER, "Master" },
  84. { OSPF_DB_RESYNC, "OOBResync" },
  85. { 0, NULL }
  86. };
  87. static const struct tok lsa_opaque_values[] = {
  88. { LS_OPAQUE_TYPE_TE, "Traffic Engineering" },
  89. { LS_OPAQUE_TYPE_GRACE, "Graceful restart" },
  90. { LS_OPAQUE_TYPE_RI, "Router Information" },
  91. { 0, NULL }
  92. };
  93. static const struct tok lsa_opaque_te_tlv_values[] = {
  94. { LS_OPAQUE_TE_TLV_ROUTER, "Router Address" },
  95. { LS_OPAQUE_TE_TLV_LINK, "Link" },
  96. { 0, NULL }
  97. };
  98. static const struct tok lsa_opaque_te_link_tlv_subtlv_values[] = {
  99. { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE, "Link Type" },
  100. { LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID, "Link ID" },
  101. { LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP, "Local Interface IP address" },
  102. { LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP, "Remote Interface IP address" },
  103. { LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC, "Traffic Engineering Metric" },
  104. { LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW, "Maximum Bandwidth" },
  105. { LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW, "Maximum Reservable Bandwidth" },
  106. { LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW, "Unreserved Bandwidth" },
  107. { LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP, "Administrative Group" },
  108. { LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID, "Link Local/Remote Identifier" },
  109. { LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE, "Link Protection Type" },
  110. { LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR, "Interface Switching Capability" },
  111. { LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP, "Shared Risk Link Group" },
  112. { LS_OPAQUE_TE_LINK_SUBTLV_BW_CONSTRAINTS, "Bandwidth Constraints" },
  113. { 0, NULL }
  114. };
  115. static const struct tok lsa_opaque_grace_tlv_values[] = {
  116. { LS_OPAQUE_GRACE_TLV_PERIOD, "Grace Period" },
  117. { LS_OPAQUE_GRACE_TLV_REASON, "Graceful restart Reason" },
  118. { LS_OPAQUE_GRACE_TLV_INT_ADDRESS, "IPv4 interface address" },
  119. { 0, NULL }
  120. };
  121. static const struct tok lsa_opaque_grace_tlv_reason_values[] = {
  122. { LS_OPAQUE_GRACE_TLV_REASON_UNKNOWN, "Unknown" },
  123. { LS_OPAQUE_GRACE_TLV_REASON_SW_RESTART, "Software Restart" },
  124. { LS_OPAQUE_GRACE_TLV_REASON_SW_UPGRADE, "Software Reload/Upgrade" },
  125. { LS_OPAQUE_GRACE_TLV_REASON_CP_SWITCH, "Control Processor Switch" },
  126. { 0, NULL }
  127. };
  128. static const struct tok lsa_opaque_te_tlv_link_type_sub_tlv_values[] = {
  129. { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_PTP, "Point-to-point" },
  130. { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_MA, "Multi-Access" },
  131. { 0, NULL }
  132. };
  133. static const struct tok lsa_opaque_ri_tlv_values[] = {
  134. { LS_OPAQUE_RI_TLV_CAP, "Router Capabilities" },
  135. { 0, NULL }
  136. };
  137. static const struct tok lsa_opaque_ri_tlv_cap_values[] = {
  138. { 1, "Reserved" },
  139. { 2, "Reserved" },
  140. { 4, "Reserved" },
  141. { 8, "Reserved" },
  142. { 16, "graceful restart capable" },
  143. { 32, "graceful restart helper" },
  144. { 64, "Stub router support" },
  145. { 128, "Traffic engineering" },
  146. { 256, "p2p over LAN" },
  147. { 512, "path computation server" },
  148. { 0, NULL }
  149. };
  150. static const struct tok ospf_lls_tlv_values[] = {
  151. { OSPF_LLS_EO, "Extended Options" },
  152. { OSPF_LLS_MD5, "MD5 Authentication" },
  153. { 0, NULL }
  154. };
  155. static const struct tok ospf_lls_eo_options[] = {
  156. { OSPF_LLS_EO_LR, "LSDB resync" },
  157. { OSPF_LLS_EO_RS, "Restart" },
  158. { 0, NULL }
  159. };
  160. int
  161. ospf_print_grace_lsa(netdissect_options *ndo,
  162. const uint8_t *tptr, u_int ls_length)
  163. {
  164. u_int tlv_type, tlv_length;
  165. while (ls_length > 0) {
  166. ND_TCHECK2(*tptr, 4);
  167. if (ls_length < 4) {
  168. ND_PRINT((ndo, "\n\t Remaining LS length %u < 4", ls_length));
  169. return -1;
  170. }
  171. tlv_type = EXTRACT_16BITS(tptr);
  172. tlv_length = EXTRACT_16BITS(tptr+2);
  173. tptr+=4;
  174. ls_length-=4;
  175. ND_PRINT((ndo, "\n\t %s TLV (%u), length %u, value: ",
  176. tok2str(lsa_opaque_grace_tlv_values,"unknown",tlv_type),
  177. tlv_type,
  178. tlv_length));
  179. if (tlv_length > ls_length) {
  180. ND_PRINT((ndo, "\n\t Bogus length %u > %u", tlv_length,
  181. ls_length));
  182. return -1;
  183. }
  184. /* Infinite loop protection. */
  185. if (tlv_type == 0 || tlv_length ==0) {
  186. return -1;
  187. }
  188. ND_TCHECK2(*tptr, tlv_length);
  189. switch(tlv_type) {
  190. case LS_OPAQUE_GRACE_TLV_PERIOD:
  191. if (tlv_length != 4) {
  192. ND_PRINT((ndo, "\n\t Bogus length %u != 4", tlv_length));
  193. return -1;
  194. }
  195. ND_PRINT((ndo, "%us", EXTRACT_32BITS(tptr)));
  196. break;
  197. case LS_OPAQUE_GRACE_TLV_REASON:
  198. if (tlv_length != 1) {
  199. ND_PRINT((ndo, "\n\t Bogus length %u != 1", tlv_length));
  200. return -1;
  201. }
  202. ND_PRINT((ndo, "%s (%u)",
  203. tok2str(lsa_opaque_grace_tlv_reason_values, "Unknown", *tptr),
  204. *tptr));
  205. break;
  206. case LS_OPAQUE_GRACE_TLV_INT_ADDRESS:
  207. if (tlv_length != 4) {
  208. ND_PRINT((ndo, "\n\t Bogus length %u != 4", tlv_length));
  209. return -1;
  210. }
  211. ND_PRINT((ndo, "%s", ipaddr_string(ndo, tptr)));
  212. break;
  213. default:
  214. if (ndo->ndo_vflag <= 1) {
  215. if (!print_unknown_data(ndo, tptr, "\n\t ", tlv_length))
  216. return -1;
  217. }
  218. break;
  219. }
  220. /* in OSPF everything has to be 32-bit aligned, including TLVs */
  221. if (tlv_length%4 != 0)
  222. tlv_length+=4-(tlv_length%4);
  223. ls_length-=tlv_length;
  224. tptr+=tlv_length;
  225. }
  226. return 0;
  227. trunc:
  228. return -1;
  229. }
  230. int
  231. ospf_print_te_lsa(netdissect_options *ndo,
  232. const uint8_t *tptr, u_int ls_length)
  233. {
  234. u_int tlv_type, tlv_length, subtlv_type, subtlv_length;
  235. u_int priority_level, te_class, count_srlg;
  236. union { /* int to float conversion buffer for several subTLVs */
  237. float f;
  238. uint32_t i;
  239. } bw;
  240. while (ls_length != 0) {
  241. ND_TCHECK2(*tptr, 4);
  242. if (ls_length < 4) {
  243. ND_PRINT((ndo, "\n\t Remaining LS length %u < 4", ls_length));
  244. return -1;
  245. }
  246. tlv_type = EXTRACT_16BITS(tptr);
  247. tlv_length = EXTRACT_16BITS(tptr+2);
  248. tptr+=4;
  249. ls_length-=4;
  250. ND_PRINT((ndo, "\n\t %s TLV (%u), length: %u",
  251. tok2str(lsa_opaque_te_tlv_values,"unknown",tlv_type),
  252. tlv_type,
  253. tlv_length));
  254. if (tlv_length > ls_length) {
  255. ND_PRINT((ndo, "\n\t Bogus length %u > %u", tlv_length,
  256. ls_length));
  257. return -1;
  258. }
  259. /* Infinite loop protection. */
  260. if (tlv_type == 0 || tlv_length ==0) {
  261. return -1;
  262. }
  263. switch(tlv_type) {
  264. case LS_OPAQUE_TE_TLV_LINK:
  265. while (tlv_length >= sizeof(subtlv_type) + sizeof(subtlv_length)) {
  266. if (tlv_length < 4) {
  267. ND_PRINT((ndo, "\n\t Remaining TLV length %u < 4",
  268. tlv_length));
  269. return -1;
  270. }
  271. ND_TCHECK2(*tptr, 4);
  272. subtlv_type = EXTRACT_16BITS(tptr);
  273. subtlv_length = EXTRACT_16BITS(tptr+2);
  274. tptr+=4;
  275. tlv_length-=4;
  276. /* Infinite loop protection */
  277. if (subtlv_type == 0 || subtlv_length == 0)
  278. goto invalid;
  279. ND_PRINT((ndo, "\n\t %s subTLV (%u), length: %u",
  280. tok2str(lsa_opaque_te_link_tlv_subtlv_values,"unknown",subtlv_type),
  281. subtlv_type,
  282. subtlv_length));
  283. ND_TCHECK2(*tptr, subtlv_length);
  284. switch(subtlv_type) {
  285. case LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP:
  286. if (subtlv_length != 4) {
  287. ND_PRINT((ndo, " != 4"));
  288. goto invalid;
  289. }
  290. ND_PRINT((ndo, ", 0x%08x", EXTRACT_32BITS(tptr)));
  291. break;
  292. case LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID:
  293. case LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID:
  294. if (subtlv_length != 4 && subtlv_length != 8) {
  295. ND_PRINT((ndo, " != 4 && != 8"));
  296. goto invalid;
  297. }
  298. ND_PRINT((ndo, ", %s (0x%08x)",
  299. ipaddr_string(ndo, tptr),
  300. EXTRACT_32BITS(tptr)));
  301. if (subtlv_length == 8) /* rfc4203 */
  302. ND_PRINT((ndo, ", %s (0x%08x)",
  303. ipaddr_string(ndo, tptr+4),
  304. EXTRACT_32BITS(tptr + 4)));
  305. break;
  306. case LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP:
  307. case LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP:
  308. if (subtlv_length != 4) {
  309. ND_PRINT((ndo, " != 4"));
  310. goto invalid;
  311. }
  312. ND_PRINT((ndo, ", %s", ipaddr_string(ndo, tptr)));
  313. break;
  314. case LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW:
  315. case LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW:
  316. if (subtlv_length != 4) {
  317. ND_PRINT((ndo, " != 4"));
  318. goto invalid;
  319. }
  320. bw.i = EXTRACT_32BITS(tptr);
  321. ND_PRINT((ndo, ", %.3f Mbps", bw.f * 8 / 1000000));
  322. break;
  323. case LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW:
  324. if (subtlv_length != 32) {
  325. ND_PRINT((ndo, " != 32"));
  326. goto invalid;
  327. }
  328. for (te_class = 0; te_class < 8; te_class++) {
  329. bw.i = EXTRACT_32BITS(tptr+te_class*4);
  330. ND_PRINT((ndo, "\n\t\tTE-Class %u: %.3f Mbps",
  331. te_class,
  332. bw.f * 8 / 1000000));
  333. }
  334. break;
  335. case LS_OPAQUE_TE_LINK_SUBTLV_BW_CONSTRAINTS:
  336. if (subtlv_length < 4) {
  337. ND_PRINT((ndo, " < 4"));
  338. goto invalid;
  339. }
  340. /* BC Model Id (1 octet) + Reserved (3 octets) */
  341. ND_PRINT((ndo, "\n\t\tBandwidth Constraints Model ID: %s (%u)",
  342. tok2str(diffserv_te_bc_values, "unknown", *tptr),
  343. *tptr));
  344. if (subtlv_length % 4 != 0) {
  345. ND_PRINT((ndo, "\n\t\tlength %u != N x 4", subtlv_length));
  346. goto invalid;
  347. }
  348. if (subtlv_length > 36) {
  349. ND_PRINT((ndo, "\n\t\tlength %u > 36", subtlv_length));
  350. goto invalid;
  351. }
  352. /* decode BCs until the subTLV ends */
  353. for (te_class = 0; te_class < (subtlv_length-4)/4; te_class++) {
  354. bw.i = EXTRACT_32BITS(tptr+4+te_class*4);
  355. ND_PRINT((ndo, "\n\t\t Bandwidth constraint CT%u: %.3f Mbps",
  356. te_class,
  357. bw.f * 8 / 1000000));
  358. }
  359. break;
  360. case LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC:
  361. if (subtlv_length != 4) {
  362. ND_PRINT((ndo, " != 4"));
  363. goto invalid;
  364. }
  365. ND_PRINT((ndo, ", Metric %u", EXTRACT_32BITS(tptr)));
  366. break;
  367. case LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE:
  368. /* Protection Cap (1 octet) + Reserved ((3 octets) */
  369. if (subtlv_length != 4) {
  370. ND_PRINT((ndo, " != 4"));
  371. goto invalid;
  372. }
  373. ND_PRINT((ndo, ", %s",
  374. bittok2str(gmpls_link_prot_values, "none", *tptr)));
  375. break;
  376. case LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR:
  377. if (subtlv_length < 36) {
  378. ND_PRINT((ndo, " < 36"));
  379. goto invalid;
  380. }
  381. /* Switching Cap (1 octet) + Encoding (1) + Reserved (2) */
  382. ND_PRINT((ndo, "\n\t\tInterface Switching Capability: %s",
  383. tok2str(gmpls_switch_cap_values, "Unknown", *(tptr))));
  384. ND_PRINT((ndo, "\n\t\tLSP Encoding: %s\n\t\tMax LSP Bandwidth:",
  385. tok2str(gmpls_encoding_values, "Unknown", *(tptr + 1))));
  386. for (priority_level = 0; priority_level < 8; priority_level++) {
  387. bw.i = EXTRACT_32BITS(tptr+4+(priority_level*4));
  388. ND_PRINT((ndo, "\n\t\t priority level %d: %.3f Mbps",
  389. priority_level,
  390. bw.f * 8 / 1000000));
  391. }
  392. break;
  393. case LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE:
  394. if (subtlv_length != 1) {
  395. ND_PRINT((ndo, " != 1"));
  396. goto invalid;
  397. }
  398. ND_PRINT((ndo, ", %s (%u)",
  399. tok2str(lsa_opaque_te_tlv_link_type_sub_tlv_values,"unknown",*tptr),
  400. *tptr));
  401. break;
  402. case LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP:
  403. if (subtlv_length % 4 != 0) {
  404. ND_PRINT((ndo, " != N x 4"));
  405. goto invalid;
  406. }
  407. count_srlg = subtlv_length / 4;
  408. if (count_srlg != 0)
  409. ND_PRINT((ndo, "\n\t\t Shared risk group: "));
  410. while (count_srlg > 0) {
  411. bw.i = EXTRACT_32BITS(tptr);
  412. ND_PRINT((ndo, "%d", bw.i));
  413. tptr+=4;
  414. count_srlg--;
  415. if (count_srlg > 0)
  416. ND_PRINT((ndo, ", "));
  417. }
  418. break;
  419. default:
  420. if (ndo->ndo_vflag <= 1) {
  421. if (!print_unknown_data(ndo, tptr, "\n\t\t", subtlv_length))
  422. return -1;
  423. }
  424. break;
  425. }
  426. /* in OSPF everything has to be 32-bit aligned, including subTLVs */
  427. if (subtlv_length%4 != 0)
  428. subtlv_length+=4-(subtlv_length%4);
  429. tlv_length-=subtlv_length;
  430. tptr+=subtlv_length;
  431. }
  432. break;
  433. case LS_OPAQUE_TE_TLV_ROUTER:
  434. if (tlv_length < 4) {
  435. ND_PRINT((ndo, "\n\t TLV length %u < 4", tlv_length));
  436. return -1;
  437. }
  438. ND_TCHECK2(*tptr, 4);
  439. ND_PRINT((ndo, ", %s", ipaddr_string(ndo, tptr)));
  440. break;
  441. default:
  442. if (ndo->ndo_vflag <= 1) {
  443. if (!print_unknown_data(ndo, tptr, "\n\t ", tlv_length))
  444. return -1;
  445. }
  446. break;
  447. }
  448. /* in OSPF everything has to be 32-bit aligned, including TLVs */
  449. if (tlv_length%4 != 0)
  450. tlv_length+=4-(tlv_length%4);
  451. ls_length-=tlv_length;
  452. tptr+=tlv_length;
  453. }
  454. return 0;
  455. trunc:
  456. return -1;
  457. invalid:
  458. ND_PRINT((ndo, "%s", istr));
  459. return -1;
  460. }
  461. static int
  462. ospf_print_lshdr(netdissect_options *ndo,
  463. register const struct lsa_hdr *lshp)
  464. {
  465. u_int ls_length;
  466. ND_TCHECK(lshp->ls_length);
  467. ls_length = EXTRACT_16BITS(&lshp->ls_length);
  468. if (ls_length < sizeof(struct lsa_hdr)) {
  469. ND_PRINT((ndo, "\n\t Bogus length %u < header (%lu)", ls_length,
  470. (unsigned long)sizeof(struct lsa_hdr)));
  471. return(-1);
  472. }
  473. ND_TCHECK(lshp->ls_seq); /* XXX - ls_length check checked this */
  474. ND_PRINT((ndo, "\n\t Advertising Router %s, seq 0x%08x, age %us, length %u",
  475. ipaddr_string(ndo, &lshp->ls_router),
  476. EXTRACT_32BITS(&lshp->ls_seq),
  477. EXTRACT_16BITS(&lshp->ls_age),
  478. ls_length - (u_int)sizeof(struct lsa_hdr)));
  479. ND_TCHECK(lshp->ls_type); /* XXX - ls_length check checked this */
  480. switch (lshp->ls_type) {
  481. /* the LSA header for opaque LSAs was slightly changed */
  482. case LS_TYPE_OPAQUE_LL:
  483. case LS_TYPE_OPAQUE_AL:
  484. case LS_TYPE_OPAQUE_DW:
  485. ND_PRINT((ndo, "\n\t %s LSA (%d), Opaque-Type %s LSA (%u), Opaque-ID %u",
  486. tok2str(lsa_values,"unknown",lshp->ls_type),
  487. lshp->ls_type,
  488. tok2str(lsa_opaque_values,
  489. "unknown",
  490. *(&lshp->un_lsa_id.opaque_field.opaque_type)),
  491. *(&lshp->un_lsa_id.opaque_field.opaque_type),
  492. EXTRACT_24BITS(&lshp->un_lsa_id.opaque_field.opaque_id)
  493. ));
  494. break;
  495. /* all other LSA types use regular style LSA headers */
  496. default:
  497. ND_PRINT((ndo, "\n\t %s LSA (%d), LSA-ID: %s",
  498. tok2str(lsa_values,"unknown",lshp->ls_type),
  499. lshp->ls_type,
  500. ipaddr_string(ndo, &lshp->un_lsa_id.lsa_id)));
  501. break;
  502. }
  503. ND_TCHECK(lshp->ls_options); /* XXX - ls_length check checked this */
  504. ND_PRINT((ndo, "\n\t Options: [%s]", bittok2str(ospf_option_values, "none", lshp->ls_options)));
  505. return (ls_length);
  506. trunc:
  507. return (-1);
  508. }
  509. /* draft-ietf-ospf-mt-09 */
  510. static const struct tok ospf_topology_values[] = {
  511. { 0, "default" },
  512. { 1, "multicast" },
  513. { 2, "management" },
  514. { 0, NULL }
  515. };
  516. /*
  517. * Print all the per-topology metrics.
  518. */
  519. static int
  520. ospf_print_tos_metrics(netdissect_options *ndo,
  521. const union un_tos *tos)
  522. {
  523. int metric_count;
  524. int toscount;
  525. toscount = tos->link.link_tos_count+1;
  526. metric_count = 0;
  527. /*
  528. * All but the first metric contain a valid topology id.
  529. */
  530. while (toscount > 0) {
  531. ND_TCHECK(*tos);
  532. ND_PRINT((ndo, "\n\t\ttopology %s (%u), metric %u",
  533. tok2str(ospf_topology_values, "Unknown",
  534. metric_count ? tos->metrics.tos_type : 0),
  535. metric_count ? tos->metrics.tos_type : 0,
  536. EXTRACT_16BITS(&tos->metrics.tos_metric)));
  537. metric_count++;
  538. tos++;
  539. toscount--;
  540. }
  541. return 0;
  542. trunc:
  543. return 1;
  544. }
  545. /*
  546. * Print a single link state advertisement. If truncated or if LSA length
  547. * field is less than the length of the LSA header, return NULl, else
  548. * return pointer to data past end of LSA.
  549. */
  550. static const uint8_t *
  551. ospf_print_lsa(netdissect_options *ndo,
  552. register const struct lsa *lsap)
  553. {
  554. register const uint8_t *ls_end;
  555. register const struct rlalink *rlp;
  556. register const struct in_addr *ap;
  557. register const struct aslametric *almp;
  558. register const struct mcla *mcp;
  559. register const uint32_t *lp;
  560. register int j, tlv_type, tlv_length, topology;
  561. register int ls_length;
  562. const uint8_t *tptr;
  563. tptr = (const uint8_t *)lsap->lsa_un.un_unknown; /* squelch compiler warnings */
  564. ls_length = ospf_print_lshdr(ndo, &lsap->ls_hdr);
  565. if (ls_length == -1)
  566. return(NULL);
  567. ls_end = (const uint8_t *)lsap + ls_length;
  568. ls_length -= sizeof(struct lsa_hdr);
  569. switch (lsap->ls_hdr.ls_type) {
  570. case LS_TYPE_ROUTER:
  571. ND_TCHECK(lsap->lsa_un.un_rla.rla_flags);
  572. ND_PRINT((ndo, "\n\t Router LSA Options: [%s]",
  573. bittok2str(ospf_rla_flag_values, "none", lsap->lsa_un.un_rla.rla_flags)));
  574. ND_TCHECK(lsap->lsa_un.un_rla.rla_count);
  575. j = EXTRACT_16BITS(&lsap->lsa_un.un_rla.rla_count);
  576. ND_TCHECK(lsap->lsa_un.un_rla.rla_link);
  577. rlp = lsap->lsa_un.un_rla.rla_link;
  578. while (j--) {
  579. ND_TCHECK(*rlp);
  580. switch (rlp->un_tos.link.link_type) {
  581. case RLA_TYPE_VIRTUAL:
  582. ND_PRINT((ndo, "\n\t Virtual Link: Neighbor Router-ID: %s, Interface Address: %s",
  583. ipaddr_string(ndo, &rlp->link_id),
  584. ipaddr_string(ndo, &rlp->link_data)));
  585. break;
  586. case RLA_TYPE_ROUTER:
  587. ND_PRINT((ndo, "\n\t Neighbor Router-ID: %s, Interface Address: %s",
  588. ipaddr_string(ndo, &rlp->link_id),
  589. ipaddr_string(ndo, &rlp->link_data)));
  590. break;
  591. case RLA_TYPE_TRANSIT:
  592. ND_PRINT((ndo, "\n\t Neighbor Network-ID: %s, Interface Address: %s",
  593. ipaddr_string(ndo, &rlp->link_id),
  594. ipaddr_string(ndo, &rlp->link_data)));
  595. break;
  596. case RLA_TYPE_STUB:
  597. ND_PRINT((ndo, "\n\t Stub Network: %s, Mask: %s",
  598. ipaddr_string(ndo, &rlp->link_id),
  599. ipaddr_string(ndo, &rlp->link_data)));
  600. break;
  601. default:
  602. ND_PRINT((ndo, "\n\t Unknown Router Link Type (%u)",
  603. rlp->un_tos.link.link_type));
  604. return (ls_end);
  605. }
  606. if (ospf_print_tos_metrics(ndo, &rlp->un_tos))
  607. goto trunc;
  608. rlp = (const struct rlalink *)((const u_char *)(rlp + 1) +
  609. ((rlp->un_tos.link.link_tos_count) * sizeof(union un_tos)));
  610. }
  611. break;
  612. case LS_TYPE_NETWORK:
  613. ND_TCHECK(lsap->lsa_un.un_nla.nla_mask);
  614. ND_PRINT((ndo, "\n\t Mask %s\n\t Connected Routers:",
  615. ipaddr_string(ndo, &lsap->lsa_un.un_nla.nla_mask)));
  616. ap = lsap->lsa_un.un_nla.nla_router;
  617. while ((const u_char *)ap < ls_end) {
  618. ND_TCHECK(*ap);
  619. ND_PRINT((ndo, "\n\t %s", ipaddr_string(ndo, ap)));
  620. ++ap;
  621. }
  622. break;
  623. case LS_TYPE_SUM_IP:
  624. ND_TCHECK(lsap->lsa_un.un_nla.nla_mask);
  625. ND_PRINT((ndo, "\n\t Mask %s",
  626. ipaddr_string(ndo, &lsap->lsa_un.un_sla.sla_mask)));
  627. ND_TCHECK(lsap->lsa_un.un_sla.sla_tosmetric);
  628. lp = lsap->lsa_un.un_sla.sla_tosmetric;
  629. while ((const u_char *)lp < ls_end) {
  630. register uint32_t ul;
  631. ND_TCHECK(*lp);
  632. ul = EXTRACT_32BITS(lp);
  633. topology = (ul & SLA_MASK_TOS) >> SLA_SHIFT_TOS;
  634. ND_PRINT((ndo, "\n\t\ttopology %s (%u) metric %d",
  635. tok2str(ospf_topology_values, "Unknown", topology),
  636. topology,
  637. ul & SLA_MASK_METRIC));
  638. ++lp;
  639. }
  640. break;
  641. case LS_TYPE_SUM_ABR:
  642. ND_TCHECK(lsap->lsa_un.un_sla.sla_tosmetric);
  643. lp = lsap->lsa_un.un_sla.sla_tosmetric;
  644. while ((const u_char *)lp < ls_end) {
  645. register uint32_t ul;
  646. ND_TCHECK(*lp);
  647. ul = EXTRACT_32BITS(lp);
  648. topology = (ul & SLA_MASK_TOS) >> SLA_SHIFT_TOS;
  649. ND_PRINT((ndo, "\n\t\ttopology %s (%u) metric %d",
  650. tok2str(ospf_topology_values, "Unknown", topology),
  651. topology,
  652. ul & SLA_MASK_METRIC));
  653. ++lp;
  654. }
  655. break;
  656. case LS_TYPE_ASE:
  657. case LS_TYPE_NSSA: /* fall through - those LSAs share the same format */
  658. ND_TCHECK(lsap->lsa_un.un_nla.nla_mask);
  659. ND_PRINT((ndo, "\n\t Mask %s",
  660. ipaddr_string(ndo, &lsap->lsa_un.un_asla.asla_mask)));
  661. ND_TCHECK(lsap->lsa_un.un_sla.sla_tosmetric);
  662. almp = lsap->lsa_un.un_asla.asla_metric;
  663. while ((const u_char *)almp < ls_end) {
  664. register uint32_t ul;
  665. ND_TCHECK(almp->asla_tosmetric);
  666. ul = EXTRACT_32BITS(&almp->asla_tosmetric);
  667. topology = ((ul & ASLA_MASK_TOS) >> ASLA_SHIFT_TOS);
  668. ND_PRINT((ndo, "\n\t\ttopology %s (%u), type %d, metric",
  669. tok2str(ospf_topology_values, "Unknown", topology),
  670. topology,
  671. (ul & ASLA_FLAG_EXTERNAL) ? 2 : 1));
  672. if ((ul & ASLA_MASK_METRIC) == 0xffffff)
  673. ND_PRINT((ndo, " infinite"));
  674. else
  675. ND_PRINT((ndo, " %d", (ul & ASLA_MASK_METRIC)));
  676. ND_TCHECK(almp->asla_forward);
  677. if (almp->asla_forward.s_addr) {
  678. ND_PRINT((ndo, ", forward %s", ipaddr_string(ndo, &almp->asla_forward)));
  679. }
  680. ND_TCHECK(almp->asla_tag);
  681. if (almp->asla_tag.s_addr) {
  682. ND_PRINT((ndo, ", tag %s", ipaddr_string(ndo, &almp->asla_tag)));
  683. }
  684. ++almp;
  685. }
  686. break;
  687. case LS_TYPE_GROUP:
  688. /* Multicast extensions as of 23 July 1991 */
  689. mcp = lsap->lsa_un.un_mcla;
  690. while ((const u_char *)mcp < ls_end) {
  691. ND_TCHECK(mcp->mcla_vid);
  692. switch (EXTRACT_32BITS(&mcp->mcla_vtype)) {
  693. case MCLA_VERTEX_ROUTER:
  694. ND_PRINT((ndo, "\n\t Router Router-ID %s",
  695. ipaddr_string(ndo, &mcp->mcla_vid)));
  696. break;
  697. case MCLA_VERTEX_NETWORK:
  698. ND_PRINT((ndo, "\n\t Network Designated Router %s",
  699. ipaddr_string(ndo, &mcp->mcla_vid)));
  700. break;
  701. default:
  702. ND_PRINT((ndo, "\n\t unknown VertexType (%u)",
  703. EXTRACT_32BITS(&mcp->mcla_vtype)));
  704. break;
  705. }
  706. ++mcp;
  707. }
  708. break;
  709. case LS_TYPE_OPAQUE_LL: /* fall through */
  710. case LS_TYPE_OPAQUE_AL:
  711. case LS_TYPE_OPAQUE_DW:
  712. switch (*(&lsap->ls_hdr.un_lsa_id.opaque_field.opaque_type)) {
  713. case LS_OPAQUE_TYPE_RI:
  714. tptr = (const uint8_t *)(&lsap->lsa_un.un_ri_tlv.type);
  715. while (ls_length != 0) {
  716. ND_TCHECK2(*tptr, 4);
  717. if (ls_length < 4) {
  718. ND_PRINT((ndo, "\n\t Remaining LS length %u < 4", ls_length));
  719. return(ls_end);
  720. }
  721. tlv_type = EXTRACT_16BITS(tptr);
  722. tlv_length = EXTRACT_16BITS(tptr+2);
  723. tptr+=4;
  724. ls_length-=4;
  725. ND_PRINT((ndo, "\n\t %s TLV (%u), length: %u, value: ",
  726. tok2str(lsa_opaque_ri_tlv_values,"unknown",tlv_type),
  727. tlv_type,
  728. tlv_length));
  729. if (tlv_length > ls_length) {
  730. ND_PRINT((ndo, "\n\t Bogus length %u > %u", tlv_length,
  731. ls_length));
  732. return(ls_end);
  733. }
  734. ND_TCHECK2(*tptr, tlv_length);
  735. switch(tlv_type) {
  736. case LS_OPAQUE_RI_TLV_CAP:
  737. if (tlv_length != 4) {
  738. ND_PRINT((ndo, "\n\t Bogus length %u != 4", tlv_length));
  739. return(ls_end);
  740. }
  741. ND_PRINT((ndo, "Capabilities: %s",
  742. bittok2str(lsa_opaque_ri_tlv_cap_values, "Unknown", EXTRACT_32BITS(tptr))));
  743. break;
  744. default:
  745. if (ndo->ndo_vflag <= 1) {
  746. if (!print_unknown_data(ndo, tptr, "\n\t ", tlv_length))
  747. return(ls_end);
  748. }
  749. break;
  750. }
  751. tptr+=tlv_length;
  752. ls_length-=tlv_length;
  753. }
  754. break;
  755. case LS_OPAQUE_TYPE_GRACE:
  756. if (ospf_print_grace_lsa(ndo, (const uint8_t *)(&lsap->lsa_un.un_grace_tlv.type),
  757. ls_length) == -1) {
  758. return(ls_end);
  759. }
  760. break;
  761. case LS_OPAQUE_TYPE_TE:
  762. if (ospf_print_te_lsa(ndo, (const uint8_t *)(&lsap->lsa_un.un_te_lsa_tlv.type),
  763. ls_length) == -1) {
  764. return(ls_end);
  765. }
  766. break;
  767. default:
  768. if (ndo->ndo_vflag <= 1) {
  769. if (!print_unknown_data(ndo, (const uint8_t *)lsap->lsa_un.un_unknown,
  770. "\n\t ", ls_length))
  771. return(ls_end);
  772. }
  773. break;
  774. }
  775. }
  776. /* do we want to see an additionally hexdump ? */
  777. if (ndo->ndo_vflag> 1)
  778. if (!print_unknown_data(ndo, (const uint8_t *)lsap->lsa_un.un_unknown,
  779. "\n\t ", ls_length)) {
  780. return(ls_end);
  781. }
  782. return (ls_end);
  783. trunc:
  784. return (NULL);
  785. }
  786. static int
  787. ospf_decode_lls(netdissect_options *ndo,
  788. register const struct ospfhdr *op, register u_int length)
  789. {
  790. register const u_char *dptr;
  791. register const u_char *dataend;
  792. register u_int length2;
  793. register uint16_t lls_type, lls_len;
  794. register uint32_t lls_flags;
  795. switch (op->ospf_type) {
  796. case OSPF_TYPE_HELLO:
  797. if (!(op->ospf_hello.hello_options & OSPF_OPTION_L))
  798. return (0);
  799. break;
  800. case OSPF_TYPE_DD:
  801. if (!(op->ospf_db.db_options & OSPF_OPTION_L))
  802. return (0);
  803. break;
  804. default:
  805. return (0);
  806. }
  807. /* dig deeper if LLS data is available; see RFC4813 */
  808. length2 = EXTRACT_16BITS(&op->ospf_len);
  809. dptr = (const u_char *)op + length2;
  810. dataend = (const u_char *)op + length;
  811. if (EXTRACT_16BITS(&op->ospf_authtype) == OSPF_AUTH_MD5) {
  812. dptr = dptr + op->ospf_authdata[3];
  813. length2 += op->ospf_authdata[3];
  814. }
  815. if (length2 >= length) {
  816. ND_PRINT((ndo, "\n\t[LLS truncated]"));
  817. return (1);
  818. }
  819. ND_TCHECK2(*dptr, 2);
  820. ND_PRINT((ndo, "\n\t LLS: checksum: 0x%04x", (u_int)EXTRACT_16BITS(dptr)));
  821. dptr += 2;
  822. ND_TCHECK2(*dptr, 2);
  823. length2 = EXTRACT_16BITS(dptr);
  824. ND_PRINT((ndo, ", length: %u", length2));
  825. dptr += 2;
  826. ND_TCHECK(*dptr);
  827. while (dptr < dataend) {
  828. ND_TCHECK2(*dptr, 2);
  829. lls_type = EXTRACT_16BITS(dptr);
  830. ND_PRINT((ndo, "\n\t %s (%u)",
  831. tok2str(ospf_lls_tlv_values,"Unknown TLV",lls_type),
  832. lls_type));
  833. dptr += 2;
  834. ND_TCHECK2(*dptr, 2);
  835. lls_len = EXTRACT_16BITS(dptr);
  836. ND_PRINT((ndo, ", length: %u", lls_len));
  837. dptr += 2;
  838. switch (lls_type) {
  839. case OSPF_LLS_EO:
  840. if (lls_len != 4) {
  841. ND_PRINT((ndo, " [should be 4]"));
  842. lls_len = 4;
  843. }
  844. ND_TCHECK2(*dptr, 4);
  845. lls_flags = EXTRACT_32BITS(dptr);
  846. ND_PRINT((ndo, "\n\t Options: 0x%08x [%s]", lls_flags,
  847. bittok2str(ospf_lls_eo_options, "?", lls_flags)));
  848. break;
  849. case OSPF_LLS_MD5:
  850. if (lls_len != 20) {
  851. ND_PRINT((ndo, " [should be 20]"));
  852. lls_len = 20;
  853. }
  854. ND_TCHECK2(*dptr, 4);
  855. ND_PRINT((ndo, "\n\t Sequence number: 0x%08x", EXTRACT_32BITS(dptr)));
  856. break;
  857. }
  858. dptr += lls_len;
  859. }
  860. return (0);
  861. trunc:
  862. return (1);
  863. }
  864. static int
  865. ospf_decode_v2(netdissect_options *ndo,
  866. register const struct ospfhdr *op, register const u_char *dataend)
  867. {
  868. register const struct in_addr *ap;
  869. register const struct lsr *lsrp;
  870. register const struct lsa_hdr *lshp;
  871. register const struct lsa *lsap;
  872. register uint32_t lsa_count,lsa_count_max;
  873. switch (op->ospf_type) {
  874. case OSPF_TYPE_UMD:
  875. /*
  876. * Rob Coltun's special monitoring packets;
  877. * do nothing
  878. */
  879. break;
  880. case OSPF_TYPE_HELLO:
  881. ND_TCHECK(op->ospf_hello.hello_options);
  882. ND_PRINT((ndo, "\n\tOptions [%s]",
  883. bittok2str(ospf_option_values,"none",op->ospf_hello.hello_options)));
  884. ND_TCHECK(op->ospf_hello.hello_deadint);
  885. ND_PRINT((ndo, "\n\t Hello Timer %us, Dead Timer %us, Mask %s, Priority %u",
  886. EXTRACT_16BITS(&op->ospf_hello.hello_helloint),
  887. EXTRACT_32BITS(&op->ospf_hello.hello_deadint),
  888. ipaddr_string(ndo, &op->ospf_hello.hello_mask),
  889. op->ospf_hello.hello_priority));
  890. ND_TCHECK(op->ospf_hello.hello_dr);
  891. if (op->ospf_hello.hello_dr.s_addr != 0)
  892. ND_PRINT((ndo, "\n\t Designated Router %s",
  893. ipaddr_string(ndo, &op->ospf_hello.hello_dr)));
  894. ND_TCHECK(op->ospf_hello.hello_bdr);
  895. if (op->ospf_hello.hello_bdr.s_addr != 0)
  896. ND_PRINT((ndo, ", Backup Designated Router %s",
  897. ipaddr_string(ndo, &op->ospf_hello.hello_bdr)));
  898. ap = op->ospf_hello.hello_neighbor;
  899. if ((const u_char *)ap < dataend)
  900. ND_PRINT((ndo, "\n\t Neighbor List:"));
  901. while ((const u_char *)ap < dataend) {
  902. ND_TCHECK(*ap);
  903. ND_PRINT((ndo, "\n\t %s", ipaddr_string(ndo, ap)));
  904. ++ap;
  905. }
  906. break; /* HELLO */
  907. case OSPF_TYPE_DD:
  908. ND_TCHECK(op->ospf_db.db_options);
  909. ND_PRINT((ndo, "\n\tOptions [%s]",
  910. bittok2str(ospf_option_values, "none", op->ospf_db.db_options)));
  911. ND_TCHECK(op->ospf_db.db_flags);
  912. ND_PRINT((ndo, ", DD Flags [%s]",
  913. bittok2str(ospf_dd_flag_values, "none", op->ospf_db.db_flags)));
  914. ND_TCHECK(op->ospf_db.db_ifmtu);
  915. if (op->ospf_db.db_ifmtu) {
  916. ND_PRINT((ndo, ", MTU: %u", EXTRACT_16BITS(&op->ospf_db.db_ifmtu)));
  917. }
  918. ND_TCHECK(op->ospf_db.db_seq);
  919. ND_PRINT((ndo, ", Sequence: 0x%08x", EXTRACT_32BITS(&op->ospf_db.db_seq)));
  920. /* Print all the LS adv's */
  921. lshp = op->ospf_db.db_lshdr;
  922. while (((const u_char *)lshp < dataend) && ospf_print_lshdr(ndo, lshp) != -1) {
  923. ++lshp;
  924. }
  925. break;
  926. case OSPF_TYPE_LS_REQ:
  927. lsrp = op->ospf_lsr;
  928. while ((const u_char *)lsrp < dataend) {
  929. ND_TCHECK(*lsrp);
  930. ND_PRINT((ndo, "\n\t Advertising Router: %s, %s LSA (%u)",
  931. ipaddr_string(ndo, &lsrp->ls_router),
  932. tok2str(lsa_values,"unknown",EXTRACT_32BITS(lsrp->ls_type)),
  933. EXTRACT_32BITS(&lsrp->ls_type)));
  934. switch (EXTRACT_32BITS(lsrp->ls_type)) {
  935. /* the LSA header for opaque LSAs was slightly changed */
  936. case LS_TYPE_OPAQUE_LL:
  937. case LS_TYPE_OPAQUE_AL:
  938. case LS_TYPE_OPAQUE_DW:
  939. ND_PRINT((ndo, ", Opaque-Type: %s LSA (%u), Opaque-ID: %u",
  940. tok2str(lsa_opaque_values, "unknown",lsrp->un_ls_stateid.opaque_field.opaque_type),
  941. lsrp->un_ls_stateid.opaque_field.opaque_type,
  942. EXTRACT_24BITS(&lsrp->un_ls_stateid.opaque_field.opaque_id)));
  943. break;
  944. default:
  945. ND_PRINT((ndo, ", LSA-ID: %s",
  946. ipaddr_string(ndo, &lsrp->un_ls_stateid.ls_stateid)));
  947. break;
  948. }
  949. ++lsrp;
  950. }
  951. break;
  952. case OSPF_TYPE_LS_UPDATE:
  953. lsap = op->ospf_lsu.lsu_lsa;
  954. ND_TCHECK(op->ospf_lsu.lsu_count);
  955. lsa_count_max = EXTRACT_32BITS(&op->ospf_lsu.lsu_count);
  956. ND_PRINT((ndo, ", %d LSA%s", lsa_count_max, PLURAL_SUFFIX(lsa_count_max)));
  957. for (lsa_count=1;lsa_count <= lsa_count_max;lsa_count++) {
  958. ND_PRINT((ndo, "\n\t LSA #%u", lsa_count));
  959. lsap = (const struct lsa *)ospf_print_lsa(ndo, lsap);
  960. if (lsap == NULL)
  961. goto trunc;
  962. }
  963. break;
  964. case OSPF_TYPE_LS_ACK:
  965. lshp = op->ospf_lsa.lsa_lshdr;
  966. while (ospf_print_lshdr(ndo, lshp) != -1) {
  967. ++lshp;
  968. }
  969. break;
  970. default:
  971. break;
  972. }
  973. return (0);
  974. trunc:
  975. return (1);
  976. }
  977. void
  978. ospf_print(netdissect_options *ndo,
  979. register const u_char *bp, register u_int length,
  980. const u_char *bp2 _U_)
  981. {
  982. register const struct ospfhdr *op;
  983. register const u_char *dataend;
  984. register const char *cp;
  985. op = (const struct ospfhdr *)bp;
  986. /* XXX Before we do anything else, strip off the MD5 trailer */
  987. ND_TCHECK(op->ospf_authtype);
  988. if (EXTRACT_16BITS(&op->ospf_authtype) == OSPF_AUTH_MD5) {
  989. length -= OSPF_AUTH_MD5_LEN;
  990. ndo->ndo_snapend -= OSPF_AUTH_MD5_LEN;
  991. }
  992. /* If the type is valid translate it, or just print the type */
  993. /* value. If it's not valid, say so and return */
  994. ND_TCHECK(op->ospf_type);
  995. cp = tok2str(type2str, "unknown LS-type", op->ospf_type);
  996. ND_PRINT((ndo, "OSPFv%u, %s, length %u", op->ospf_version, cp, length));
  997. if (*cp == 'u')
  998. return;
  999. if (!ndo->ndo_vflag) { /* non verbose - so lets bail out here */
  1000. return;
  1001. }
  1002. ND_TCHECK(op->ospf_len);
  1003. if (length != EXTRACT_16BITS(&op->ospf_len)) {
  1004. ND_PRINT((ndo, " [len %d]", EXTRACT_16BITS(&op->ospf_len)));
  1005. }
  1006. if (length > EXTRACT_16BITS(&op->ospf_len)) {
  1007. dataend = bp + EXTRACT_16BITS(&op->ospf_len);
  1008. } else {
  1009. dataend = bp + length;
  1010. }
  1011. ND_TCHECK(op->ospf_routerid);
  1012. ND_PRINT((ndo, "\n\tRouter-ID %s", ipaddr_string(ndo, &op->ospf_routerid)));
  1013. ND_TCHECK(op->ospf_areaid);
  1014. if (op->ospf_areaid.s_addr != 0)
  1015. ND_PRINT((ndo, ", Area %s", ipaddr_string(ndo, &op->ospf_areaid)));
  1016. else
  1017. ND_PRINT((ndo, ", Backbone Area"));
  1018. if (ndo->ndo_vflag) {
  1019. /* Print authentication data (should we really do this?) */
  1020. ND_TCHECK2(op->ospf_authdata[0], sizeof(op->ospf_authdata));
  1021. ND_PRINT((ndo, ", Authentication Type: %s (%u)",
  1022. tok2str(ospf_authtype_values, "unknown", EXTRACT_16BITS(&op->ospf_authtype)),
  1023. EXTRACT_16BITS(&op->ospf_authtype)));
  1024. switch (EXTRACT_16BITS(&op->ospf_authtype)) {
  1025. case OSPF_AUTH_NONE:
  1026. break;
  1027. case OSPF_AUTH_SIMPLE:
  1028. ND_PRINT((ndo, "\n\tSimple text password: "));
  1029. safeputs(ndo, op->ospf_authdata, OSPF_AUTH_SIMPLE_LEN);
  1030. break;
  1031. case OSPF_AUTH_MD5:
  1032. ND_PRINT((ndo, "\n\tKey-ID: %u, Auth-Length: %u, Crypto Sequence Number: 0x%08x",
  1033. *((op->ospf_authdata) + 2),
  1034. *((op->ospf_authdata) + 3),
  1035. EXTRACT_32BITS((op->ospf_authdata) + 4)));
  1036. break;
  1037. default:
  1038. return;
  1039. }
  1040. }
  1041. /* Do rest according to version. */
  1042. switch (op->ospf_version) {
  1043. case 2:
  1044. /* ospf version 2 */
  1045. if (ospf_decode_v2(ndo, op, dataend))
  1046. goto trunc;
  1047. if (length > EXTRACT_16BITS(&op->ospf_len)) {
  1048. if (ospf_decode_lls(ndo, op, length))
  1049. goto trunc;
  1050. }
  1051. break;
  1052. default:
  1053. ND_PRINT((ndo, " ospf [version %d]", op->ospf_version));
  1054. break;
  1055. } /* end switch on version */
  1056. return;
  1057. trunc:
  1058. ND_PRINT((ndo, "%s", tstr));
  1059. }