PageRenderTime 108ms CodeModel.GetById 23ms RepoModel.GetById 2ms app.codeStats 0ms

/external/tcpdump/print-isoclns.c

https://gitlab.com/brian0218/rk3066_r-box_android4.2.2_sdk
C | 1459 lines | 1186 code | 196 blank | 77 comment | 103 complexity | 2cc0b47658d5aeddd0b7e8c84c6e5424 MD5 | raw file
  1. /*
  2. * Copyright (c) 1992, 1993, 1994, 1995, 1996
  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. * Original code by Matt Thomas, Digital Equipment Corporation
  22. *
  23. * Extensively modified by Hannes Gredler (hannes@juniper.net) for more
  24. * complete IS-IS & CLNP support.
  25. */
  26. #ifndef lint
  27. static const char rcsid[] _U_ =
  28. "@(#) $Header: /tcpdump/master/tcpdump/print-isoclns.c,v 1.133.2.25 2007/03/02 09:20:27 hannes Exp $ (LBL)";
  29. #endif
  30. #ifdef HAVE_CONFIG_H
  31. #include "config.h"
  32. #endif
  33. #include <tcpdump-stdinc.h>
  34. #include <stdio.h>
  35. #include <string.h>
  36. #include "interface.h"
  37. #include "addrtoname.h"
  38. #include "ethertype.h"
  39. #include "ether.h"
  40. #include "nlpid.h"
  41. #include "extract.h"
  42. #include "gmpls.h"
  43. #include "oui.h"
  44. #define IPV4 1 /* AFI value */
  45. #define IPV6 2 /* AFI value */
  46. /*
  47. * IS-IS is defined in ISO 10589. Look there for protocol definitions.
  48. */
  49. #define SYSTEM_ID_LEN ETHER_ADDR_LEN
  50. #define NODE_ID_LEN SYSTEM_ID_LEN+1
  51. #define LSP_ID_LEN SYSTEM_ID_LEN+2
  52. #define ISIS_VERSION 1
  53. #define ESIS_VERSION 1
  54. #define CLNP_VERSION 1
  55. #define ISIS_PDU_TYPE_MASK 0x1F
  56. #define ESIS_PDU_TYPE_MASK 0x1F
  57. #define CLNP_PDU_TYPE_MASK 0x1F
  58. #define CLNP_FLAG_MASK 0xE0
  59. #define ISIS_LAN_PRIORITY_MASK 0x7F
  60. #define ISIS_PDU_L1_LAN_IIH 15
  61. #define ISIS_PDU_L2_LAN_IIH 16
  62. #define ISIS_PDU_PTP_IIH 17
  63. #define ISIS_PDU_L1_LSP 18
  64. #define ISIS_PDU_L2_LSP 20
  65. #define ISIS_PDU_L1_CSNP 24
  66. #define ISIS_PDU_L2_CSNP 25
  67. #define ISIS_PDU_L1_PSNP 26
  68. #define ISIS_PDU_L2_PSNP 27
  69. static struct tok isis_pdu_values[] = {
  70. { ISIS_PDU_L1_LAN_IIH, "L1 Lan IIH"},
  71. { ISIS_PDU_L2_LAN_IIH, "L2 Lan IIH"},
  72. { ISIS_PDU_PTP_IIH, "p2p IIH"},
  73. { ISIS_PDU_L1_LSP, "L1 LSP"},
  74. { ISIS_PDU_L2_LSP, "L2 LSP"},
  75. { ISIS_PDU_L1_CSNP, "L1 CSNP"},
  76. { ISIS_PDU_L2_CSNP, "L2 CSNP"},
  77. { ISIS_PDU_L1_PSNP, "L1 PSNP"},
  78. { ISIS_PDU_L2_PSNP, "L2 PSNP"},
  79. { 0, NULL}
  80. };
  81. /*
  82. * A TLV is a tuple of a type, length and a value and is normally used for
  83. * encoding information in all sorts of places. This is an enumeration of
  84. * the well known types.
  85. *
  86. * list taken from rfc3359 plus some memory from veterans ;-)
  87. */
  88. #define ISIS_TLV_AREA_ADDR 1 /* iso10589 */
  89. #define ISIS_TLV_IS_REACH 2 /* iso10589 */
  90. #define ISIS_TLV_ESNEIGH 3 /* iso10589 */
  91. #define ISIS_TLV_PART_DIS 4 /* iso10589 */
  92. #define ISIS_TLV_PREFIX_NEIGH 5 /* iso10589 */
  93. #define ISIS_TLV_ISNEIGH 6 /* iso10589 */
  94. #define ISIS_TLV_ISNEIGH_VARLEN 7 /* iso10589 */
  95. #define ISIS_TLV_PADDING 8 /* iso10589 */
  96. #define ISIS_TLV_LSP 9 /* iso10589 */
  97. #define ISIS_TLV_AUTH 10 /* iso10589, rfc3567 */
  98. #define ISIS_TLV_CHECKSUM 12 /* rfc3358 */
  99. #define ISIS_TLV_CHECKSUM_MINLEN 2
  100. #define ISIS_TLV_LSP_BUFFERSIZE 14 /* iso10589 rev2 */
  101. #define ISIS_TLV_LSP_BUFFERSIZE_MINLEN 2
  102. #define ISIS_TLV_EXT_IS_REACH 22 /* draft-ietf-isis-traffic-05 */
  103. #define ISIS_TLV_IS_ALIAS_ID 24 /* draft-ietf-isis-ext-lsp-frags-02 */
  104. #define ISIS_TLV_DECNET_PHASE4 42
  105. #define ISIS_TLV_LUCENT_PRIVATE 66
  106. #define ISIS_TLV_INT_IP_REACH 128 /* rfc1195, rfc2966 */
  107. #define ISIS_TLV_PROTOCOLS 129 /* rfc1195 */
  108. #define ISIS_TLV_EXT_IP_REACH 130 /* rfc1195, rfc2966 */
  109. #define ISIS_TLV_IDRP_INFO 131 /* rfc1195 */
  110. #define ISIS_TLV_IDRP_INFO_MINLEN 1
  111. #define ISIS_TLV_IPADDR 132 /* rfc1195 */
  112. #define ISIS_TLV_IPAUTH 133 /* rfc1195 */
  113. #define ISIS_TLV_TE_ROUTER_ID 134 /* draft-ietf-isis-traffic-05 */
  114. #define ISIS_TLV_EXTD_IP_REACH 135 /* draft-ietf-isis-traffic-05 */
  115. #define ISIS_TLV_HOSTNAME 137 /* rfc2763 */
  116. #define ISIS_TLV_SHARED_RISK_GROUP 138 /* draft-ietf-isis-gmpls-extensions */
  117. #define ISIS_TLV_NORTEL_PRIVATE1 176
  118. #define ISIS_TLV_NORTEL_PRIVATE2 177
  119. #define ISIS_TLV_RESTART_SIGNALING 211 /* rfc3847 */
  120. #define ISIS_TLV_RESTART_SIGNALING_FLAGLEN 1
  121. #define ISIS_TLV_RESTART_SIGNALING_HOLDTIMELEN 2
  122. #define ISIS_TLV_MT_IS_REACH 222 /* draft-ietf-isis-wg-multi-topology-05 */
  123. #define ISIS_TLV_MT_SUPPORTED 229 /* draft-ietf-isis-wg-multi-topology-05 */
  124. #define ISIS_TLV_MT_SUPPORTED_MINLEN 2
  125. #define ISIS_TLV_IP6ADDR 232 /* draft-ietf-isis-ipv6-02 */
  126. #define ISIS_TLV_MT_IP_REACH 235 /* draft-ietf-isis-wg-multi-topology-05 */
  127. #define ISIS_TLV_IP6_REACH 236 /* draft-ietf-isis-ipv6-02 */
  128. #define ISIS_TLV_MT_IP6_REACH 237 /* draft-ietf-isis-wg-multi-topology-05 */
  129. #define ISIS_TLV_PTP_ADJ 240 /* rfc3373 */
  130. #define ISIS_TLV_IIH_SEQNR 241 /* draft-shen-isis-iih-sequence-00 */
  131. #define ISIS_TLV_IIH_SEQNR_MINLEN 4
  132. #define ISIS_TLV_VENDOR_PRIVATE 250 /* draft-ietf-isis-experimental-tlv-01 */
  133. #define ISIS_TLV_VENDOR_PRIVATE_MINLEN 3
  134. static struct tok isis_tlv_values[] = {
  135. { ISIS_TLV_AREA_ADDR, "Area address(es)"},
  136. { ISIS_TLV_IS_REACH, "IS Reachability"},
  137. { ISIS_TLV_ESNEIGH, "ES Neighbor(s)"},
  138. { ISIS_TLV_PART_DIS, "Partition DIS"},
  139. { ISIS_TLV_PREFIX_NEIGH, "Prefix Neighbors"},
  140. { ISIS_TLV_ISNEIGH, "IS Neighbor(s)"},
  141. { ISIS_TLV_ISNEIGH_VARLEN, "IS Neighbor(s) (variable length)"},
  142. { ISIS_TLV_PADDING, "Padding"},
  143. { ISIS_TLV_LSP, "LSP entries"},
  144. { ISIS_TLV_AUTH, "Authentication"},
  145. { ISIS_TLV_CHECKSUM, "Checksum"},
  146. { ISIS_TLV_LSP_BUFFERSIZE, "LSP Buffersize"},
  147. { ISIS_TLV_EXT_IS_REACH, "Extended IS Reachability"},
  148. { ISIS_TLV_IS_ALIAS_ID, "IS Alias ID"},
  149. { ISIS_TLV_DECNET_PHASE4, "DECnet Phase IV"},
  150. { ISIS_TLV_LUCENT_PRIVATE, "Lucent Proprietary"},
  151. { ISIS_TLV_INT_IP_REACH, "IPv4 Internal Reachability"},
  152. { ISIS_TLV_PROTOCOLS, "Protocols supported"},
  153. { ISIS_TLV_EXT_IP_REACH, "IPv4 External Reachability"},
  154. { ISIS_TLV_IDRP_INFO, "Inter-Domain Information Type"},
  155. { ISIS_TLV_IPADDR, "IPv4 Interface address(es)"},
  156. { ISIS_TLV_IPAUTH, "IPv4 authentication (deprecated)"},
  157. { ISIS_TLV_TE_ROUTER_ID, "Traffic Engineering Router ID"},
  158. { ISIS_TLV_EXTD_IP_REACH, "Extended IPv4 Reachability"},
  159. { ISIS_TLV_SHARED_RISK_GROUP, "Shared Risk Link Group"},
  160. { ISIS_TLV_NORTEL_PRIVATE1, "Nortel Proprietary"},
  161. { ISIS_TLV_NORTEL_PRIVATE2, "Nortel Proprietary"},
  162. { ISIS_TLV_HOSTNAME, "Hostname"},
  163. { ISIS_TLV_RESTART_SIGNALING, "Restart Signaling"},
  164. { ISIS_TLV_MT_IS_REACH, "Multi Topology IS Reachability"},
  165. { ISIS_TLV_MT_SUPPORTED, "Multi Topology"},
  166. { ISIS_TLV_IP6ADDR, "IPv6 Interface address(es)"},
  167. { ISIS_TLV_MT_IP_REACH, "Multi-Topology IPv4 Reachability"},
  168. { ISIS_TLV_IP6_REACH, "IPv6 reachability"},
  169. { ISIS_TLV_MT_IP6_REACH, "Multi-Topology IP6 Reachability"},
  170. { ISIS_TLV_PTP_ADJ, "Point-to-point Adjacency State"},
  171. { ISIS_TLV_IIH_SEQNR, "Hello PDU Sequence Number"},
  172. { ISIS_TLV_VENDOR_PRIVATE, "Vendor Private"},
  173. { 0, NULL }
  174. };
  175. #define ESIS_OPTION_PROTOCOLS 129
  176. #define ESIS_OPTION_QOS_MAINTENANCE 195 /* iso9542 */
  177. #define ESIS_OPTION_SECURITY 197 /* iso9542 */
  178. #define ESIS_OPTION_ES_CONF_TIME 198 /* iso9542 */
  179. #define ESIS_OPTION_PRIORITY 205 /* iso9542 */
  180. #define ESIS_OPTION_ADDRESS_MASK 225 /* iso9542 */
  181. #define ESIS_OPTION_SNPA_MASK 226 /* iso9542 */
  182. static struct tok esis_option_values[] = {
  183. { ESIS_OPTION_PROTOCOLS, "Protocols supported"},
  184. { ESIS_OPTION_QOS_MAINTENANCE, "QoS Maintenance" },
  185. { ESIS_OPTION_SECURITY, "Security" },
  186. { ESIS_OPTION_ES_CONF_TIME, "ES Configuration Time" },
  187. { ESIS_OPTION_PRIORITY, "Priority" },
  188. { ESIS_OPTION_ADDRESS_MASK, "Addressk Mask" },
  189. { ESIS_OPTION_SNPA_MASK, "SNPA Mask" },
  190. { 0, NULL }
  191. };
  192. #define CLNP_OPTION_DISCARD_REASON 193
  193. #define CLNP_OPTION_QOS_MAINTENANCE 195 /* iso8473 */
  194. #define CLNP_OPTION_SECURITY 197 /* iso8473 */
  195. #define CLNP_OPTION_SOURCE_ROUTING 200 /* iso8473 */
  196. #define CLNP_OPTION_ROUTE_RECORDING 203 /* iso8473 */
  197. #define CLNP_OPTION_PADDING 204 /* iso8473 */
  198. #define CLNP_OPTION_PRIORITY 205 /* iso8473 */
  199. static struct tok clnp_option_values[] = {
  200. { CLNP_OPTION_DISCARD_REASON, "Discard Reason"},
  201. { CLNP_OPTION_PRIORITY, "Priority"},
  202. { CLNP_OPTION_QOS_MAINTENANCE, "QoS Maintenance"},
  203. { CLNP_OPTION_SECURITY, "Security"},
  204. { CLNP_OPTION_SOURCE_ROUTING, "Source Routing"},
  205. { CLNP_OPTION_ROUTE_RECORDING, "Route Recording"},
  206. { CLNP_OPTION_PADDING, "Padding"},
  207. { 0, NULL }
  208. };
  209. static struct tok clnp_option_rfd_class_values[] = {
  210. { 0x0, "General"},
  211. { 0x8, "Address"},
  212. { 0x9, "Source Routeing"},
  213. { 0xa, "Lifetime"},
  214. { 0xb, "PDU Discarded"},
  215. { 0xc, "Reassembly"},
  216. { 0, NULL }
  217. };
  218. static struct tok clnp_option_rfd_general_values[] = {
  219. { 0x0, "Reason not specified"},
  220. { 0x1, "Protocol procedure error"},
  221. { 0x2, "Incorrect checksum"},
  222. { 0x3, "PDU discarded due to congestion"},
  223. { 0x4, "Header syntax error (cannot be parsed)"},
  224. { 0x5, "Segmentation needed but not permitted"},
  225. { 0x6, "Incomplete PDU received"},
  226. { 0x7, "Duplicate option"},
  227. { 0, NULL }
  228. };
  229. static struct tok clnp_option_rfd_address_values[] = {
  230. { 0x0, "Destination address unreachable"},
  231. { 0x1, "Destination address unknown"},
  232. { 0, NULL }
  233. };
  234. static struct tok clnp_option_rfd_source_routeing_values[] = {
  235. { 0x0, "Unspecified source routeing error"},
  236. { 0x1, "Syntax error in source routeing field"},
  237. { 0x2, "Unknown address in source routeing field"},
  238. { 0x3, "Path not acceptable"},
  239. { 0, NULL }
  240. };
  241. static struct tok clnp_option_rfd_lifetime_values[] = {
  242. { 0x0, "Lifetime expired while data unit in transit"},
  243. { 0x1, "Lifetime expired during reassembly"},
  244. { 0, NULL }
  245. };
  246. static struct tok clnp_option_rfd_pdu_discard_values[] = {
  247. { 0x0, "Unsupported option not specified"},
  248. { 0x1, "Unsupported protocol version"},
  249. { 0x2, "Unsupported security option"},
  250. { 0x3, "Unsupported source routeing option"},
  251. { 0x4, "Unsupported recording of route option"},
  252. { 0, NULL }
  253. };
  254. static struct tok clnp_option_rfd_reassembly_values[] = {
  255. { 0x0, "Reassembly interference"},
  256. { 0, NULL }
  257. };
  258. /* array of 16 error-classes */
  259. static struct tok *clnp_option_rfd_error_class[] = {
  260. clnp_option_rfd_general_values,
  261. NULL,
  262. NULL,
  263. NULL,
  264. NULL,
  265. NULL,
  266. NULL,
  267. NULL,
  268. clnp_option_rfd_address_values,
  269. clnp_option_rfd_source_routeing_values,
  270. clnp_option_rfd_lifetime_values,
  271. clnp_option_rfd_pdu_discard_values,
  272. clnp_option_rfd_reassembly_values,
  273. NULL,
  274. NULL,
  275. NULL
  276. };
  277. #define CLNP_OPTION_OPTION_QOS_MASK 0x3f
  278. #define CLNP_OPTION_SCOPE_MASK 0xc0
  279. #define CLNP_OPTION_SCOPE_SA_SPEC 0x40
  280. #define CLNP_OPTION_SCOPE_DA_SPEC 0x80
  281. #define CLNP_OPTION_SCOPE_GLOBAL 0xc0
  282. static struct tok clnp_option_scope_values[] = {
  283. { CLNP_OPTION_SCOPE_SA_SPEC, "Source Address Specific"},
  284. { CLNP_OPTION_SCOPE_DA_SPEC, "Destination Address Specific"},
  285. { CLNP_OPTION_SCOPE_GLOBAL, "Globally unique"},
  286. { 0, NULL }
  287. };
  288. static struct tok clnp_option_sr_rr_values[] = {
  289. { 0x0, "partial"},
  290. { 0x1, "complete"},
  291. { 0, NULL }
  292. };
  293. static struct tok clnp_option_sr_rr_string_values[] = {
  294. { CLNP_OPTION_SOURCE_ROUTING, "source routing"},
  295. { CLNP_OPTION_ROUTE_RECORDING, "recording of route in progress"},
  296. { 0, NULL }
  297. };
  298. static struct tok clnp_option_qos_global_values[] = {
  299. { 0x20, "reserved"},
  300. { 0x10, "sequencing vs. delay"},
  301. { 0x08, "congested"},
  302. { 0x04, "delay vs. cost"},
  303. { 0x02, "error vs. delay"},
  304. { 0x01, "error vs. cost"},
  305. { 0, NULL }
  306. };
  307. #define ISIS_SUBTLV_EXT_IS_REACH_ADMIN_GROUP 3 /* draft-ietf-isis-traffic-05 */
  308. #define ISIS_SUBTLV_EXT_IS_REACH_LINK_LOCAL_REMOTE_ID 4 /* draft-ietf-isis-gmpls-extensions */
  309. #define ISIS_SUBTLV_EXT_IS_REACH_LINK_REMOTE_ID 5 /* draft-ietf-isis-traffic-05 */
  310. #define ISIS_SUBTLV_EXT_IS_REACH_IPV4_INTF_ADDR 6 /* draft-ietf-isis-traffic-05 */
  311. #define ISIS_SUBTLV_EXT_IS_REACH_IPV4_NEIGHBOR_ADDR 8 /* draft-ietf-isis-traffic-05 */
  312. #define ISIS_SUBTLV_EXT_IS_REACH_MAX_LINK_BW 9 /* draft-ietf-isis-traffic-05 */
  313. #define ISIS_SUBTLV_EXT_IS_REACH_RESERVABLE_BW 10 /* draft-ietf-isis-traffic-05 */
  314. #define ISIS_SUBTLV_EXT_IS_REACH_UNRESERVED_BW 11 /* rfc4124 */
  315. #define ISIS_SUBTLV_EXT_IS_REACH_BW_CONSTRAINTS_OLD 12 /* draft-ietf-tewg-diff-te-proto-06 */
  316. #define ISIS_SUBTLV_EXT_IS_REACH_TE_METRIC 18 /* draft-ietf-isis-traffic-05 */
  317. #define ISIS_SUBTLV_EXT_IS_REACH_LINK_PROTECTION_TYPE 20 /* draft-ietf-isis-gmpls-extensions */
  318. #define ISIS_SUBTLV_EXT_IS_REACH_INTF_SW_CAP_DESCR 21 /* draft-ietf-isis-gmpls-extensions */
  319. #define ISIS_SUBTLV_EXT_IS_REACH_BW_CONSTRAINTS 22 /* rfc4124 */
  320. static struct tok isis_ext_is_reach_subtlv_values[] = {
  321. { ISIS_SUBTLV_EXT_IS_REACH_ADMIN_GROUP, "Administrative groups" },
  322. { ISIS_SUBTLV_EXT_IS_REACH_LINK_LOCAL_REMOTE_ID, "Link Local/Remote Identifier" },
  323. { ISIS_SUBTLV_EXT_IS_REACH_LINK_REMOTE_ID, "Link Remote Identifier" },
  324. { ISIS_SUBTLV_EXT_IS_REACH_IPV4_INTF_ADDR, "IPv4 interface address" },
  325. { ISIS_SUBTLV_EXT_IS_REACH_IPV4_NEIGHBOR_ADDR, "IPv4 neighbor address" },
  326. { ISIS_SUBTLV_EXT_IS_REACH_MAX_LINK_BW, "Maximum link bandwidth" },
  327. { ISIS_SUBTLV_EXT_IS_REACH_RESERVABLE_BW, "Reservable link bandwidth" },
  328. { ISIS_SUBTLV_EXT_IS_REACH_UNRESERVED_BW, "Unreserved bandwidth" },
  329. { ISIS_SUBTLV_EXT_IS_REACH_TE_METRIC, "Traffic Engineering Metric" },
  330. { ISIS_SUBTLV_EXT_IS_REACH_LINK_PROTECTION_TYPE, "Link Protection Type" },
  331. { ISIS_SUBTLV_EXT_IS_REACH_INTF_SW_CAP_DESCR, "Interface Switching Capability" },
  332. { ISIS_SUBTLV_EXT_IS_REACH_BW_CONSTRAINTS_OLD, "Bandwidth Constraints (old)" },
  333. { ISIS_SUBTLV_EXT_IS_REACH_BW_CONSTRAINTS, "Bandwidth Constraints" },
  334. { 250, "Reserved for cisco specific extensions" },
  335. { 251, "Reserved for cisco specific extensions" },
  336. { 252, "Reserved for cisco specific extensions" },
  337. { 253, "Reserved for cisco specific extensions" },
  338. { 254, "Reserved for cisco specific extensions" },
  339. { 255, "Reserved for future expansion" },
  340. { 0, NULL }
  341. };
  342. #define ISIS_SUBTLV_EXTD_IP_REACH_ADMIN_TAG32 1 /* draft-ietf-isis-admin-tags-01 */
  343. #define ISIS_SUBTLV_EXTD_IP_REACH_ADMIN_TAG64 2 /* draft-ietf-isis-admin-tags-01 */
  344. #define ISIS_SUBTLV_EXTD_IP_REACH_MGMT_PREFIX_COLOR 117 /* draft-ietf-isis-wg-multi-topology-05 */
  345. static struct tok isis_ext_ip_reach_subtlv_values[] = {
  346. { ISIS_SUBTLV_EXTD_IP_REACH_ADMIN_TAG32, "32-Bit Administrative tag" },
  347. { ISIS_SUBTLV_EXTD_IP_REACH_ADMIN_TAG64, "64-Bit Administrative tag" },
  348. { ISIS_SUBTLV_EXTD_IP_REACH_MGMT_PREFIX_COLOR, "Management Prefix Color" },
  349. { 0, NULL }
  350. };
  351. #define ISIS_SUBTLV_AUTH_SIMPLE 1
  352. #define ISIS_SUBTLV_AUTH_MD5 54
  353. #define ISIS_SUBTLV_AUTH_MD5_LEN 16
  354. #define ISIS_SUBTLV_AUTH_PRIVATE 255
  355. static struct tok isis_subtlv_auth_values[] = {
  356. { ISIS_SUBTLV_AUTH_SIMPLE, "simple text password"},
  357. { ISIS_SUBTLV_AUTH_MD5, "HMAC-MD5 password"},
  358. { ISIS_SUBTLV_AUTH_PRIVATE, "Routing Domain private password"},
  359. { 0, NULL }
  360. };
  361. #define ISIS_SUBTLV_IDRP_RES 0
  362. #define ISIS_SUBTLV_IDRP_LOCAL 1
  363. #define ISIS_SUBTLV_IDRP_ASN 2
  364. static struct tok isis_subtlv_idrp_values[] = {
  365. { ISIS_SUBTLV_IDRP_RES, "Reserved"},
  366. { ISIS_SUBTLV_IDRP_LOCAL, "Routing-Domain Specific"},
  367. { ISIS_SUBTLV_IDRP_ASN, "AS Number Tag"},
  368. { 0, NULL}
  369. };
  370. #define CLNP_SEGMENT_PART 0x80
  371. #define CLNP_MORE_SEGMENTS 0x40
  372. #define CLNP_REQUEST_ER 0x20
  373. static struct tok clnp_flag_values[] = {
  374. { CLNP_SEGMENT_PART, "Segmentation permitted"},
  375. { CLNP_MORE_SEGMENTS, "more Segments"},
  376. { CLNP_REQUEST_ER, "request Error Report"},
  377. { 0, NULL}
  378. };
  379. #define ISIS_MASK_LSP_OL_BIT(x) ((x)&0x4)
  380. #define ISIS_MASK_LSP_ISTYPE_BITS(x) ((x)&0x3)
  381. #define ISIS_MASK_LSP_PARTITION_BIT(x) ((x)&0x80)
  382. #define ISIS_MASK_LSP_ATT_BITS(x) ((x)&0x78)
  383. #define ISIS_MASK_LSP_ATT_ERROR_BIT(x) ((x)&0x40)
  384. #define ISIS_MASK_LSP_ATT_EXPENSE_BIT(x) ((x)&0x20)
  385. #define ISIS_MASK_LSP_ATT_DELAY_BIT(x) ((x)&0x10)
  386. #define ISIS_MASK_LSP_ATT_DEFAULT_BIT(x) ((x)&0x8)
  387. #define ISIS_MASK_MTID(x) ((x)&0x0fff)
  388. #define ISIS_MASK_MTFLAGS(x) ((x)&0xf000)
  389. static struct tok isis_mt_flag_values[] = {
  390. { 0x4000, "sub-TLVs present"},
  391. { 0x8000, "ATT bit set"},
  392. { 0, NULL}
  393. };
  394. #define ISIS_MASK_TLV_EXTD_IP_UPDOWN(x) ((x)&0x80)
  395. #define ISIS_MASK_TLV_EXTD_IP_SUBTLV(x) ((x)&0x40)
  396. #define ISIS_MASK_TLV_EXTD_IP6_IE(x) ((x)&0x40)
  397. #define ISIS_MASK_TLV_EXTD_IP6_SUBTLV(x) ((x)&0x20)
  398. #define ISIS_LSP_TLV_METRIC_SUPPORTED(x) ((x)&0x80)
  399. #define ISIS_LSP_TLV_METRIC_IE(x) ((x)&0x40)
  400. #define ISIS_LSP_TLV_METRIC_UPDOWN(x) ((x)&0x80)
  401. #define ISIS_LSP_TLV_METRIC_VALUE(x) ((x)&0x3f)
  402. #define ISIS_MASK_TLV_SHARED_RISK_GROUP(x) ((x)&0x1)
  403. static struct tok isis_mt_values[] = {
  404. { 0, "IPv4 unicast"},
  405. { 1, "In-Band Management"},
  406. { 2, "IPv6 unicast"},
  407. { 3, "Multicast"},
  408. { 4095, "Development, Experimental or Proprietary"},
  409. { 0, NULL }
  410. };
  411. static struct tok isis_iih_circuit_type_values[] = {
  412. { 1, "Level 1 only"},
  413. { 2, "Level 2 only"},
  414. { 3, "Level 1, Level 2"},
  415. { 0, NULL}
  416. };
  417. #define ISIS_LSP_TYPE_UNUSED0 0
  418. #define ISIS_LSP_TYPE_LEVEL_1 1
  419. #define ISIS_LSP_TYPE_UNUSED2 2
  420. #define ISIS_LSP_TYPE_LEVEL_2 3
  421. static struct tok isis_lsp_istype_values[] = {
  422. { ISIS_LSP_TYPE_UNUSED0, "Unused 0x0 (invalid)"},
  423. { ISIS_LSP_TYPE_LEVEL_1, "L1 IS"},
  424. { ISIS_LSP_TYPE_UNUSED2, "Unused 0x2 (invalid)"},
  425. { ISIS_LSP_TYPE_LEVEL_2, "L2 IS"},
  426. { 0, NULL }
  427. };
  428. /*
  429. * Katz's point to point adjacency TLV uses codes to tell us the state of
  430. * the remote adjacency. Enumerate them.
  431. */
  432. #define ISIS_PTP_ADJ_UP 0
  433. #define ISIS_PTP_ADJ_INIT 1
  434. #define ISIS_PTP_ADJ_DOWN 2
  435. static struct tok isis_ptp_adjancey_values[] = {
  436. { ISIS_PTP_ADJ_UP, "Up" },
  437. { ISIS_PTP_ADJ_INIT, "Initializing" },
  438. { ISIS_PTP_ADJ_DOWN, "Down" },
  439. { 0, NULL}
  440. };
  441. struct isis_tlv_ptp_adj {
  442. u_int8_t adjacency_state;
  443. u_int8_t extd_local_circuit_id[4];
  444. u_int8_t neighbor_sysid[SYSTEM_ID_LEN];
  445. u_int8_t neighbor_extd_local_circuit_id[4];
  446. };
  447. static int osi_cksum(const u_int8_t *, u_int);
  448. static int clnp_print(const u_int8_t *, u_int);
  449. static void esis_print(const u_int8_t *, u_int);
  450. static int isis_print(const u_int8_t *, u_int);
  451. struct isis_metric_block {
  452. u_int8_t metric_default;
  453. u_int8_t metric_delay;
  454. u_int8_t metric_expense;
  455. u_int8_t metric_error;
  456. };
  457. struct isis_tlv_is_reach {
  458. struct isis_metric_block isis_metric_block;
  459. u_int8_t neighbor_nodeid[NODE_ID_LEN];
  460. };
  461. struct isis_tlv_es_reach {
  462. struct isis_metric_block isis_metric_block;
  463. u_int8_t neighbor_sysid[SYSTEM_ID_LEN];
  464. };
  465. struct isis_tlv_ip_reach {
  466. struct isis_metric_block isis_metric_block;
  467. u_int8_t prefix[4];
  468. u_int8_t mask[4];
  469. };
  470. static struct tok isis_is_reach_virtual_values[] = {
  471. { 0, "IsNotVirtual"},
  472. { 1, "IsVirtual"},
  473. { 0, NULL }
  474. };
  475. static struct tok isis_restart_flag_values[] = {
  476. { 0x1, "Restart Request"},
  477. { 0x2, "Restart Acknowledgement"},
  478. { 0x4, "Suppress adjacency advertisement"},
  479. { 0, NULL }
  480. };
  481. struct isis_common_header {
  482. u_int8_t nlpid;
  483. u_int8_t fixed_len;
  484. u_int8_t version; /* Protocol version */
  485. u_int8_t id_length;
  486. u_int8_t pdu_type; /* 3 MSbits are reserved */
  487. u_int8_t pdu_version; /* Packet format version */
  488. u_int8_t reserved;
  489. u_int8_t max_area;
  490. };
  491. struct isis_iih_lan_header {
  492. u_int8_t circuit_type;
  493. u_int8_t source_id[SYSTEM_ID_LEN];
  494. u_int8_t holding_time[2];
  495. u_int8_t pdu_len[2];
  496. u_int8_t priority;
  497. u_int8_t lan_id[NODE_ID_LEN];
  498. };
  499. struct isis_iih_ptp_header {
  500. u_int8_t circuit_type;
  501. u_int8_t source_id[SYSTEM_ID_LEN];
  502. u_int8_t holding_time[2];
  503. u_int8_t pdu_len[2];
  504. u_int8_t circuit_id;
  505. };
  506. struct isis_lsp_header {
  507. u_int8_t pdu_len[2];
  508. u_int8_t remaining_lifetime[2];
  509. u_int8_t lsp_id[LSP_ID_LEN];
  510. u_int8_t sequence_number[4];
  511. u_int8_t checksum[2];
  512. u_int8_t typeblock;
  513. };
  514. struct isis_csnp_header {
  515. u_int8_t pdu_len[2];
  516. u_int8_t source_id[NODE_ID_LEN];
  517. u_int8_t start_lsp_id[LSP_ID_LEN];
  518. u_int8_t end_lsp_id[LSP_ID_LEN];
  519. };
  520. struct isis_psnp_header {
  521. u_int8_t pdu_len[2];
  522. u_int8_t source_id[NODE_ID_LEN];
  523. };
  524. struct isis_tlv_lsp {
  525. u_int8_t remaining_lifetime[2];
  526. u_int8_t lsp_id[LSP_ID_LEN];
  527. u_int8_t sequence_number[4];
  528. u_int8_t checksum[2];
  529. };
  530. #define ISIS_COMMON_HEADER_SIZE (sizeof(struct isis_common_header))
  531. #define ISIS_IIH_LAN_HEADER_SIZE (sizeof(struct isis_iih_lan_header))
  532. #define ISIS_IIH_PTP_HEADER_SIZE (sizeof(struct isis_iih_ptp_header))
  533. #define ISIS_LSP_HEADER_SIZE (sizeof(struct isis_lsp_header))
  534. #define ISIS_CSNP_HEADER_SIZE (sizeof(struct isis_csnp_header))
  535. #define ISIS_PSNP_HEADER_SIZE (sizeof(struct isis_psnp_header))
  536. void isoclns_print(const u_int8_t *p, u_int length, u_int caplen)
  537. {
  538. const struct isis_common_header *header;
  539. header = (const struct isis_common_header *)p;
  540. if (caplen <= 1) { /* enough bytes on the wire ? */
  541. printf("|OSI");
  542. return;
  543. }
  544. if (eflag)
  545. printf("OSI NLPID %s (0x%02x): ",
  546. tok2str(nlpid_values,"Unknown",*p),
  547. *p);
  548. switch (*p) {
  549. case NLPID_CLNP:
  550. if (!clnp_print(p, length))
  551. print_unknown_data(p,"\n\t",caplen);
  552. break;
  553. case NLPID_ESIS:
  554. esis_print(p, length);
  555. return;
  556. case NLPID_ISIS:
  557. if (!isis_print(p, length))
  558. print_unknown_data(p,"\n\t",caplen);
  559. break;
  560. case NLPID_NULLNS:
  561. (void)printf("%slength: %u",
  562. eflag ? "" : ", ",
  563. length);
  564. break;
  565. case NLPID_Q933:
  566. q933_print(p+1, length-1);
  567. break;
  568. case NLPID_IP:
  569. ip_print(gndo, p+1, length-1);
  570. break;
  571. #ifdef INET6
  572. case NLPID_IP6:
  573. ip6_print(p+1, length-1);
  574. break;
  575. #endif
  576. case NLPID_PPP:
  577. ppp_print(p+1, length-1);
  578. break;
  579. default:
  580. if (!eflag)
  581. printf("OSI NLPID 0x%02x unknown",*p);
  582. (void)printf("%slength: %u",
  583. eflag ? "" : ", ",
  584. length);
  585. if (caplen > 1)
  586. print_unknown_data(p,"\n\t",caplen);
  587. break;
  588. }
  589. }
  590. #define CLNP_PDU_ER 1
  591. #define CLNP_PDU_DT 28
  592. #define CLNP_PDU_MD 29
  593. #define CLNP_PDU_ERQ 30
  594. #define CLNP_PDU_ERP 31
  595. static struct tok clnp_pdu_values[] = {
  596. { CLNP_PDU_ER, "Error Report"},
  597. { CLNP_PDU_MD, "MD"},
  598. { CLNP_PDU_DT, "Data"},
  599. { CLNP_PDU_ERQ, "Echo Request"},
  600. { CLNP_PDU_ERP, "Echo Response"},
  601. { 0, NULL }
  602. };
  603. struct clnp_header_t {
  604. u_int8_t nlpid;
  605. u_int8_t length_indicator;
  606. u_int8_t version;
  607. u_int8_t lifetime; /* units of 500ms */
  608. u_int8_t type;
  609. u_int8_t segment_length[2];
  610. u_int8_t cksum[2];
  611. };
  612. struct clnp_segment_header_t {
  613. u_int8_t data_unit_id[2];
  614. u_int8_t segment_offset[2];
  615. u_int8_t total_length[2];
  616. };
  617. /*
  618. * clnp_print
  619. * Decode CLNP packets. Return 0 on error.
  620. */
  621. static int clnp_print (const u_int8_t *pptr, u_int length)
  622. {
  623. const u_int8_t *optr,*source_address,*dest_address;
  624. u_int li,tlen,nsap_offset,source_address_length,dest_address_length, clnp_pdu_type, clnp_flags;
  625. const struct clnp_header_t *clnp_header;
  626. const struct clnp_segment_header_t *clnp_segment_header;
  627. u_int8_t rfd_error_major,rfd_error_minor;
  628. clnp_header = (const struct clnp_header_t *) pptr;
  629. TCHECK(*clnp_header);
  630. li = clnp_header->length_indicator;
  631. optr = pptr;
  632. if (!eflag)
  633. printf("CLNP");
  634. /*
  635. * Sanity checking of the header.
  636. */
  637. if (clnp_header->version != CLNP_VERSION) {
  638. printf("version %d packet not supported", clnp_header->version);
  639. return (0);
  640. }
  641. /* FIXME further header sanity checking */
  642. clnp_pdu_type = clnp_header->type & CLNP_PDU_TYPE_MASK;
  643. clnp_flags = clnp_header->type & CLNP_FLAG_MASK;
  644. pptr += sizeof(struct clnp_header_t);
  645. li -= sizeof(struct clnp_header_t);
  646. dest_address_length = *pptr;
  647. dest_address = pptr + 1;
  648. pptr += (1 + dest_address_length);
  649. li -= (1 + dest_address_length);
  650. source_address_length = *pptr;
  651. source_address = pptr +1;
  652. pptr += (1 + source_address_length);
  653. li -= (1 + source_address_length);
  654. if (vflag < 1) {
  655. printf("%s%s > %s, %s, length %u",
  656. eflag ? "" : ", ",
  657. isonsap_string(source_address, source_address_length),
  658. isonsap_string(dest_address, dest_address_length),
  659. tok2str(clnp_pdu_values,"unknown (%u)",clnp_pdu_type),
  660. length);
  661. return (1);
  662. }
  663. printf("%slength %u",eflag ? "" : ", ",length);
  664. printf("\n\t%s PDU, hlen: %u, v: %u, lifetime: %u.%us, Segment PDU length: %u, checksum: 0x%04x ",
  665. tok2str(clnp_pdu_values, "unknown (%u)",clnp_pdu_type),
  666. clnp_header->length_indicator,
  667. clnp_header->version,
  668. clnp_header->lifetime/2,
  669. (clnp_header->lifetime%2)*5,
  670. EXTRACT_16BITS(clnp_header->segment_length),
  671. EXTRACT_16BITS(clnp_header->cksum));
  672. /* do not attempt to verify the checksum if it is zero */
  673. if (EXTRACT_16BITS(clnp_header->cksum) == 0)
  674. printf("(unverified)");
  675. else printf("(%s)", osi_cksum(optr, clnp_header->length_indicator) ? "incorrect" : "correct");
  676. printf("\n\tFlags [%s]",
  677. bittok2str(clnp_flag_values,"none",clnp_flags));
  678. printf("\n\tsource address (length %u): %s\n\tdest address (length %u): %s",
  679. source_address_length,
  680. isonsap_string(source_address, source_address_length),
  681. dest_address_length,
  682. isonsap_string(dest_address,dest_address_length));
  683. if (clnp_flags & CLNP_SEGMENT_PART) {
  684. clnp_segment_header = (const struct clnp_segment_header_t *) pptr;
  685. TCHECK(*clnp_segment_header);
  686. printf("\n\tData Unit ID: 0x%04x, Segment Offset: %u, Total PDU Length: %u",
  687. EXTRACT_16BITS(clnp_segment_header->data_unit_id),
  688. EXTRACT_16BITS(clnp_segment_header->segment_offset),
  689. EXTRACT_16BITS(clnp_segment_header->total_length));
  690. pptr+=sizeof(const struct clnp_segment_header_t);
  691. li-=sizeof(const struct clnp_segment_header_t);
  692. }
  693. /* now walk the options */
  694. while (li >= 2) {
  695. u_int op, opli;
  696. const u_int8_t *tptr;
  697. TCHECK2(*pptr, 2);
  698. if (li < 2) {
  699. printf(", bad opts/li");
  700. return (0);
  701. }
  702. op = *pptr++;
  703. opli = *pptr++;
  704. li -= 2;
  705. TCHECK2(*pptr, opli);
  706. if (opli > li) {
  707. printf(", opt (%d) too long", op);
  708. return (0);
  709. }
  710. li -= opli;
  711. tptr = pptr;
  712. tlen = opli;
  713. printf("\n\t %s Option #%u, length %u, value: ",
  714. tok2str(clnp_option_values,"Unknown",op),
  715. op,
  716. opli);
  717. switch (op) {
  718. case CLNP_OPTION_ROUTE_RECORDING: /* those two options share the format */
  719. case CLNP_OPTION_SOURCE_ROUTING:
  720. printf("%s %s",
  721. tok2str(clnp_option_sr_rr_values,"Unknown",*tptr),
  722. tok2str(clnp_option_sr_rr_string_values,"Unknown Option %u",op));
  723. nsap_offset=*(tptr+1);
  724. if (nsap_offset == 0) {
  725. printf(" Bad NSAP offset (0)");
  726. break;
  727. }
  728. nsap_offset-=1; /* offset to nsap list */
  729. if (nsap_offset > tlen) {
  730. printf(" Bad NSAP offset (past end of option)");
  731. break;
  732. }
  733. tptr+=nsap_offset;
  734. tlen-=nsap_offset;
  735. while (tlen > 0) {
  736. source_address_length=*tptr;
  737. if (tlen < source_address_length+1) {
  738. printf("\n\t NSAP address goes past end of option");
  739. break;
  740. }
  741. if (source_address_length > 0) {
  742. source_address=(tptr+1);
  743. TCHECK2(*source_address, source_address_length);
  744. printf("\n\t NSAP address (length %u): %s",
  745. source_address_length,
  746. isonsap_string(source_address, source_address_length));
  747. }
  748. tlen-=source_address_length+1;
  749. }
  750. break;
  751. case CLNP_OPTION_PRIORITY:
  752. printf("0x%1x", *tptr&0x0f);
  753. break;
  754. case CLNP_OPTION_QOS_MAINTENANCE:
  755. printf("\n\t Format Code: %s",
  756. tok2str(clnp_option_scope_values,"Reserved",*tptr&CLNP_OPTION_SCOPE_MASK));
  757. if ((*tptr&CLNP_OPTION_SCOPE_MASK) == CLNP_OPTION_SCOPE_GLOBAL)
  758. printf("\n\t QoS Flags [%s]",
  759. bittok2str(clnp_option_qos_global_values,
  760. "none",
  761. *tptr&CLNP_OPTION_OPTION_QOS_MASK));
  762. break;
  763. case CLNP_OPTION_SECURITY:
  764. printf("\n\t Format Code: %s, Security-Level %u",
  765. tok2str(clnp_option_scope_values,"Reserved",*tptr&CLNP_OPTION_SCOPE_MASK),
  766. *(tptr+1));
  767. break;
  768. case CLNP_OPTION_DISCARD_REASON:
  769. rfd_error_major = (*tptr&0xf0) >> 4;
  770. rfd_error_minor = *tptr&0x0f;
  771. printf("\n\t Class: %s Error (0x%01x), %s (0x%01x)",
  772. tok2str(clnp_option_rfd_class_values,"Unknown",rfd_error_major),
  773. rfd_error_major,
  774. tok2str(clnp_option_rfd_error_class[rfd_error_major],"Unknown",rfd_error_minor),
  775. rfd_error_minor);
  776. break;
  777. case CLNP_OPTION_PADDING:
  778. printf("padding data");
  779. break;
  780. /*
  781. * FIXME those are the defined Options that lack a decoder
  782. * you are welcome to contribute code ;-)
  783. */
  784. default:
  785. print_unknown_data(tptr,"\n\t ",opli);
  786. break;
  787. }
  788. if (vflag > 1)
  789. print_unknown_data(pptr,"\n\t ",opli);
  790. pptr += opli;
  791. }
  792. switch (clnp_pdu_type) {
  793. case CLNP_PDU_ER: /* fall through */
  794. case CLNP_PDU_ERP:
  795. TCHECK(*pptr);
  796. if (*(pptr) == NLPID_CLNP) {
  797. printf("\n\t-----original packet-----\n\t");
  798. /* FIXME recursion protection */
  799. clnp_print(pptr, length-clnp_header->length_indicator);
  800. break;
  801. }
  802. case CLNP_PDU_DT:
  803. case CLNP_PDU_MD:
  804. case CLNP_PDU_ERQ:
  805. default:
  806. /* dump the PDU specific data */
  807. if (length-(pptr-optr) > 0) {
  808. printf("\n\t undecoded non-header data, length %u",length-clnp_header->length_indicator);
  809. print_unknown_data(pptr,"\n\t ",length-(pptr-optr));
  810. }
  811. }
  812. return (1);
  813. trunc:
  814. fputs("[|clnp]", stdout);
  815. return (1);
  816. }
  817. #define ESIS_PDU_REDIRECT 6
  818. #define ESIS_PDU_ESH 2
  819. #define ESIS_PDU_ISH 4
  820. static struct tok esis_pdu_values[] = {
  821. { ESIS_PDU_REDIRECT, "redirect"},
  822. { ESIS_PDU_ESH, "ESH"},
  823. { ESIS_PDU_ISH, "ISH"},
  824. { 0, NULL }
  825. };
  826. struct esis_header_t {
  827. u_int8_t nlpid;
  828. u_int8_t length_indicator;
  829. u_int8_t version;
  830. u_int8_t reserved;
  831. u_int8_t type;
  832. u_int8_t holdtime[2];
  833. u_int8_t cksum[2];
  834. };
  835. static void
  836. esis_print(const u_int8_t *pptr, u_int length)
  837. {
  838. const u_int8_t *optr;
  839. u_int li,esis_pdu_type,source_address_length, source_address_number;
  840. const struct esis_header_t *esis_header;
  841. if (!eflag)
  842. printf("ES-IS");
  843. if (length <= 2) {
  844. if (qflag)
  845. printf("bad pkt!");
  846. else
  847. printf("no header at all!");
  848. return;
  849. }
  850. esis_header = (const struct esis_header_t *) pptr;
  851. TCHECK(*esis_header);
  852. li = esis_header->length_indicator;
  853. optr = pptr;
  854. /*
  855. * Sanity checking of the header.
  856. */
  857. if (esis_header->nlpid != NLPID_ESIS) {
  858. printf(" nlpid 0x%02x packet not supported", esis_header->nlpid);
  859. return;
  860. }
  861. if (esis_header->version != ESIS_VERSION) {
  862. printf(" version %d packet not supported", esis_header->version);
  863. return;
  864. }
  865. if (li > length) {
  866. printf(" length indicator(%d) > PDU size (%d)!", li, length);
  867. return;
  868. }
  869. if (li < sizeof(struct esis_header_t) + 2) {
  870. printf(" length indicator < min PDU size %d:", li);
  871. while (--length != 0)
  872. printf("%02X", *pptr++);
  873. return;
  874. }
  875. esis_pdu_type = esis_header->type & ESIS_PDU_TYPE_MASK;
  876. if (vflag < 1) {
  877. printf("%s%s, length %u",
  878. eflag ? "" : ", ",
  879. tok2str(esis_pdu_values,"unknown type (%u)",esis_pdu_type),
  880. length);
  881. return;
  882. } else
  883. printf("%slength %u\n\t%s (%u)",
  884. eflag ? "" : ", ",
  885. length,
  886. tok2str(esis_pdu_values,"unknown type: %u", esis_pdu_type),
  887. esis_pdu_type);
  888. printf(", v: %u%s", esis_header->version, esis_header->version == ESIS_VERSION ? "" : "unsupported" );
  889. printf(", checksum: 0x%04x ", EXTRACT_16BITS(esis_header->cksum));
  890. /* do not attempt to verify the checksum if it is zero */
  891. if (EXTRACT_16BITS(esis_header->cksum) == 0)
  892. printf("(unverified)");
  893. else
  894. printf("(%s)", osi_cksum(pptr, li) ? "incorrect" : "correct");
  895. printf(", holding time: %us, length indicator: %u",EXTRACT_16BITS(esis_header->holdtime),li);
  896. if (vflag > 1)
  897. print_unknown_data(optr,"\n\t",sizeof(struct esis_header_t));
  898. pptr += sizeof(struct esis_header_t);
  899. li -= sizeof(struct esis_header_t);
  900. switch (esis_pdu_type) {
  901. case ESIS_PDU_REDIRECT: {
  902. const u_int8_t *dst, *snpa, *neta;
  903. u_int dstl, snpal, netal;
  904. TCHECK(*pptr);
  905. if (li < 1) {
  906. printf(", bad redirect/li");
  907. return;
  908. }
  909. dstl = *pptr;
  910. pptr++;
  911. li--;
  912. TCHECK2(*pptr, dstl);
  913. if (li < dstl) {
  914. printf(", bad redirect/li");
  915. return;
  916. }
  917. dst = pptr;
  918. pptr += dstl;
  919. li -= dstl;
  920. printf("\n\t %s", isonsap_string(dst,dstl));
  921. TCHECK(*pptr);
  922. if (li < 1) {
  923. printf(", bad redirect/li");
  924. return;
  925. }
  926. snpal = *pptr;
  927. pptr++;
  928. li--;
  929. TCHECK2(*pptr, snpal);
  930. if (li < snpal) {
  931. printf(", bad redirect/li");
  932. return;
  933. }
  934. snpa = pptr;
  935. pptr += snpal;
  936. li -= snpal;
  937. TCHECK(*pptr);
  938. if (li < 1) {
  939. printf(", bad redirect/li");
  940. return;
  941. }
  942. netal = *pptr;
  943. pptr++;
  944. TCHECK2(*pptr, netal);
  945. if (li < netal) {
  946. printf(", bad redirect/li");
  947. return;
  948. }
  949. neta = pptr;
  950. pptr += netal;
  951. li -= netal;
  952. if (netal == 0)
  953. printf("\n\t %s", etheraddr_string(snpa));
  954. else
  955. printf("\n\t %s", isonsap_string(neta,netal));
  956. break;
  957. }
  958. case ESIS_PDU_ESH:
  959. TCHECK(*pptr);
  960. if (li < 1) {
  961. printf(", bad esh/li");
  962. return;
  963. }
  964. source_address_number = *pptr;
  965. pptr++;
  966. li--;
  967. printf("\n\t Number of Source Addresses: %u", source_address_number);
  968. while (source_address_number > 0) {
  969. TCHECK(*pptr);
  970. if (li < 1) {
  971. printf(", bad esh/li");
  972. return;
  973. }
  974. source_address_length = *pptr;
  975. pptr++;
  976. li--;
  977. TCHECK2(*pptr, source_address_length);
  978. if (li < source_address_length) {
  979. printf(", bad esh/li");
  980. return;
  981. }
  982. printf("\n\t NET (length: %u): %s",
  983. source_address_length,
  984. isonsap_string(pptr,source_address_length));
  985. pptr += source_address_length;
  986. li -= source_address_length;
  987. source_address_number--;
  988. }
  989. break;
  990. case ESIS_PDU_ISH: {
  991. TCHECK(*pptr);
  992. if (li < 1) {
  993. printf(", bad ish/li");
  994. return;
  995. }
  996. source_address_length = *pptr;
  997. pptr++;
  998. li--;
  999. TCHECK2(*pptr, source_address_length);
  1000. if (li < source_address_length) {
  1001. printf(", bad ish/li");
  1002. return;
  1003. }
  1004. printf("\n\t NET (length: %u): %s", source_address_length, isonsap_string(pptr, source_address_length));
  1005. pptr += source_address_length;
  1006. li -= source_address_length;
  1007. break;
  1008. }
  1009. default:
  1010. if (vflag <= 1) {
  1011. if (pptr < snapend)
  1012. print_unknown_data(pptr,"\n\t ",snapend-pptr);
  1013. }
  1014. return;
  1015. }
  1016. /* now walk the options */
  1017. while (li >= 2) {
  1018. u_int op, opli;
  1019. const u_int8_t *tptr;
  1020. TCHECK2(*pptr, 2);
  1021. if (li < 2) {
  1022. printf(", bad opts/li");
  1023. return;
  1024. }
  1025. op = *pptr++;
  1026. opli = *pptr++;
  1027. li -= 2;
  1028. if (opli > li) {
  1029. printf(", opt (%d) too long", op);
  1030. return;
  1031. }
  1032. li -= opli;
  1033. tptr = pptr;
  1034. printf("\n\t %s Option #%u, length %u, value: ",
  1035. tok2str(esis_option_values,"Unknown",op),
  1036. op,
  1037. opli);
  1038. switch (op) {
  1039. case ESIS_OPTION_ES_CONF_TIME:
  1040. TCHECK2(*pptr, 2);
  1041. printf("%us", EXTRACT_16BITS(tptr));
  1042. break;
  1043. case ESIS_OPTION_PROTOCOLS:
  1044. while (opli>0) {
  1045. TCHECK(*pptr);
  1046. printf("%s (0x%02x)",
  1047. tok2str(nlpid_values,
  1048. "unknown",
  1049. *tptr),
  1050. *tptr);
  1051. if (opli>1) /* further NPLIDs ? - put comma */
  1052. printf(", ");
  1053. tptr++;
  1054. opli--;
  1055. }
  1056. break;
  1057. /*
  1058. * FIXME those are the defined Options that lack a decoder
  1059. * you are welcome to contribute code ;-)
  1060. */
  1061. case ESIS_OPTION_QOS_MAINTENANCE:
  1062. case ESIS_OPTION_SECURITY:
  1063. case ESIS_OPTION_PRIORITY:
  1064. case ESIS_OPTION_ADDRESS_MASK:
  1065. case ESIS_OPTION_SNPA_MASK:
  1066. default:
  1067. print_unknown_data(tptr,"\n\t ",opli);
  1068. break;
  1069. }
  1070. if (vflag > 1)
  1071. print_unknown_data(pptr,"\n\t ",opli);
  1072. pptr += opli;
  1073. }
  1074. trunc:
  1075. return;
  1076. }
  1077. /* shared routine for printing system, node and lsp-ids */
  1078. static char *
  1079. isis_print_id(const u_int8_t *cp, int id_len)
  1080. {
  1081. int i;
  1082. static char id[sizeof("xxxx.xxxx.xxxx.yy-zz")];
  1083. char *pos = id;
  1084. for (i = 1; i <= SYSTEM_ID_LEN; i++) {
  1085. snprintf(pos, sizeof(id) - (pos - id), "%02x", *cp++);
  1086. pos += strlen(pos);
  1087. if (i == 2 || i == 4)
  1088. *pos++ = '.';
  1089. }
  1090. if (id_len >= NODE_ID_LEN) {
  1091. snprintf(pos, sizeof(id) - (pos - id), ".%02x", *cp++);
  1092. pos += strlen(pos);
  1093. }
  1094. if (id_len == LSP_ID_LEN)
  1095. snprintf(pos, sizeof(id) - (pos - id), "-%02x", *cp);
  1096. return (id);
  1097. }
  1098. /* print the 4-byte metric block which is common found in the old-style TLVs */
  1099. static int
  1100. isis_print_metric_block (const struct isis_metric_block *isis_metric_block)
  1101. {
  1102. printf(", Default Metric: %d, %s",
  1103. ISIS_LSP_TLV_METRIC_VALUE(isis_metric_block->metric_default),
  1104. ISIS_LSP_TLV_METRIC_IE(isis_metric_block->metric_default) ? "External" : "Internal");
  1105. if (!ISIS_LSP_TLV_METRIC_SUPPORTED(isis_metric_block->metric_delay))
  1106. printf("\n\t\t Delay Metric: %d, %s",
  1107. ISIS_LSP_TLV_METRIC_VALUE(isis_metric_block->metric_delay),
  1108. ISIS_LSP_TLV_METRIC_IE(isis_metric_block->metric_delay) ? "External" : "Internal");
  1109. if (!ISIS_LSP_TLV_METRIC_SUPPORTED(isis_metric_block->metric_expense))
  1110. printf("\n\t\t Expense Metric: %d, %s",
  1111. ISIS_LSP_TLV_METRIC_VALUE(isis_metric_block->metric_expense),
  1112. ISIS_LSP_TLV_METRIC_IE(isis_metric_block->metric_expense) ? "External" : "Internal");
  1113. if (!ISIS_LSP_TLV_METRIC_SUPPORTED(isis_metric_block->metric_error))
  1114. printf("\n\t\t Error Metric: %d, %s",
  1115. ISIS_LSP_TLV_METRIC_VALUE(isis_metric_block->metric_error),
  1116. ISIS_LSP_TLV_METRIC_IE(isis_metric_block->metric_error) ? "External" : "Internal");
  1117. return(1); /* everything is ok */
  1118. }
  1119. static int
  1120. isis_print_tlv_ip_reach (const u_int8_t *cp, const char *ident, int length)
  1121. {
  1122. int prefix_len;
  1123. const struct isis_tlv_ip_reach *tlv_ip_reach;
  1124. tlv_ip_reach = (const struct isis_tlv_ip_reach *)cp;
  1125. while (length > 0) {
  1126. if ((size_t)length < sizeof(*tlv_ip_reach)) {
  1127. printf("short IPv4 Reachability (%d vs %lu)",
  1128. length,
  1129. (unsigned long)sizeof(*tlv_ip_reach));
  1130. return (0);
  1131. }
  1132. if (!TTEST(*tlv_ip_reach))
  1133. return (0);
  1134. prefix_len = mask2plen(EXTRACT_32BITS(tlv_ip_reach->mask));
  1135. if (prefix_len == -1)
  1136. printf("%sIPv4 prefix: %s mask %s",
  1137. ident,
  1138. ipaddr_string((tlv_ip_reach->prefix)),
  1139. ipaddr_string((tlv_ip_reach->mask)));
  1140. else
  1141. printf("%sIPv4 prefix: %15s/%u",
  1142. ident,
  1143. ipaddr_string((tlv_ip_reach->prefix)),
  1144. prefix_len);
  1145. printf(", Distribution: %s, Metric: %u, %s",
  1146. ISIS_LSP_TLV_METRIC_UPDOWN(tlv_ip_reach->isis_metric_block.metric_default) ? "down" : "up",
  1147. ISIS_LSP_TLV_METRIC_VALUE(tlv_ip_reach->isis_metric_block.metric_default),
  1148. ISIS_LSP_TLV_METRIC_IE(tlv_ip_reach->isis_metric_block.metric_default) ? "External" : "Internal");
  1149. if (!ISIS_LSP_TLV_METRIC_SUPPORTED(tlv_ip_reach->isis_metric_block.metric_delay))
  1150. printf("%s Delay Metric: %u, %s",
  1151. ident,
  1152. ISIS_LSP_TLV_METRIC_VALUE(tlv_ip_reach->isis_metric_block.metric_delay),
  1153. ISIS_LSP_TLV_METRIC_IE(tlv_ip_reach->isis_metric_block.metric_delay) ? "External" : "Internal");
  1154. if (!ISIS_LSP_TLV_METRIC_SUPPORTED(tlv_ip_reach->isis_metric_block.metric_expense))
  1155. printf("%s Expense Metric: %u, %s",
  1156. ident,
  1157. ISIS_LSP_TLV_METRIC_VALUE(tlv_ip_reach->isis_metric_block.metric_expense),
  1158. ISIS_LSP_TLV_METRIC_IE(tlv_ip_reach->isis_metric_block.metric_expense) ? "External" : "Internal");
  1159. if (!ISIS_LSP_TLV_METRIC_SUPPORTED(tlv_ip_reach->isis_metric_block.metric_error))
  1160. printf("%s Error Metric: %u, %s",
  1161. ident,
  1162. ISIS_LSP_TLV_METRIC_VALUE(tlv_ip_reach->isis_metric_block.metric_error),
  1163. ISIS_LSP_TLV_METRIC_IE(tlv_ip_reach->isis_metric_block.metric_error) ? "External" : "Internal");
  1164. length -= sizeof(struct isis_tlv_ip_reach);
  1165. tlv_ip_reach++;
  1166. }
  1167. return (1);
  1168. }
  1169. /*
  1170. * this is the common IP-REACH subTLV decoder it is called
  1171. * from various EXTD-IP REACH TLVs (135,235,236,237)
  1172. */
  1173. static int
  1174. isis_print_ip_reach_subtlv (const u_int8_t *tptr,int subt,int subl,const char *ident) {
  1175. /* first lets see if we know the subTLVs name*/
  1176. printf("%s%s subTLV #%u, length: %u",
  1177. ident,
  1178. tok2str(isis_ext_ip_reach_subtlv_values,
  1179. "unknown",
  1180. subt),
  1181. subt,
  1182. subl);
  1183. if (!TTEST2(*tptr,subl))
  1184. goto trunctlv;
  1185. switch(subt) {
  1186. case ISIS_SUBTLV_EXTD_IP_REACH_MGMT_PREFIX_COLOR: /* fall through */
  1187. case ISIS_SUBTLV_EXTD_IP_REACH_ADMIN_TAG32:
  1188. while (subl >= 4) {
  1189. printf(", 0x%08x (=%u)",
  1190. EXTRACT_32BITS(tptr),
  1191. EXTRACT_32BITS(tptr));
  1192. tptr+=4;
  1193. subl-=4;
  1194. }
  1195. break;
  1196. case ISIS_SUBTLV_EXTD_IP_REACH_ADMIN_TAG64:
  1197. while (subl >= 8) {
  1198. printf(", 0x%08x%08x",
  1199. EXTRACT_32BITS(tptr),
  1200. EXTRACT_32BITS(tptr+4));
  1201. tptr+=8;
  1202. subl-=8;
  1203. }
  1204. break;
  1205. default:
  1206. if(!print_unknown_data(tptr,"\n\t\t ",
  1207. subl))
  1208. return(0);
  1209. break;
  1210. }
  1211. return(1);
  1212. trunctlv:
  1213. printf("%spacket exceeded snapshot",ident);
  1214. return(0);
  1215. }
  1216. /*
  1217. * this is the common IS-REACH subTLV decoder it is called
  1218. * from isis_print_ext_is_reach()
  1219. */
  1220. static int
  1221. isis_print_is_reach_subtlv (const u_int8_t *tptr,u_int subt,u_int subl,const char *ident) {
  1222. u_int te_class,priority_level;
  1223. union { /* int to float conversion buffer for several subTLVs */
  1224. float f;
  1225. u_int32_t i;
  1226. } bw;
  1227. /* first lets see if we know the subTLVs name*/
  1228. printf("%s%s subTLV #%u, length: %u",
  1229. ident,
  1230. tok2str(isis_ext_is_reach_subtlv_values,
  1231. "unknown",
  1232. subt),
  1233. subt,
  1234. subl);
  1235. if (!TTEST2(*tptr,subl))
  1236. goto trunctlv;
  1237. switch(subt) {
  1238. case ISIS_SUBTLV_EXT_IS_REACH_ADMIN_GROUP:
  1239. case ISIS_SUBTLV_EXT_IS_REACH_LINK_LOCAL_REMOTE_ID:
  1240. case ISIS_SUBTLV_EXT_IS_REACH_LINK_REMOTE_ID:
  1241. if (subl >= 4) {
  1242. printf(", 0x%08x", EXTRACT_32BITS(tptr));
  1243. if (subl == 8) /* draft-ietf-isis-gmpls-extensions */
  1244. printf(", 0x%08x", EXTRACT_32BITS(tptr+4));
  1245. }
  1246. break;
  1247. case ISIS_SUBTLV_EXT_IS_REACH_IPV4_INTF_ADDR:
  1248. case ISIS_SUBTLV_EXT_IS_REACH_IPV4_NEIGHBOR_ADDR:
  1249. if (subl >= sizeof(struct in_addr))
  1250. printf(", %s", ipaddr_string(tptr));
  1251. break;
  1252. case ISIS_SUBTLV_EXT_IS_REACH_MAX_LINK_BW :
  1253. case ISIS_SUBTLV_EXT_IS_REACH_RESERVABLE_BW:
  1254. if (subl >= 4) {
  1255. bw.i = EXTRACT_32BITS(tptr);
  1256. printf(", %.3f Mbps", bw.f*8/1000000 );
  1257. }
  1258. break;
  1259. case ISIS_SUBTLV_EXT_IS_REACH_UNRESERVED_BW :
  1260. if (subl >= 32) {
  1261. for (te_class = 0; te_class < 8; te_class++) {
  1262. bw.i = EXTRACT_32BITS(tptr);
  1263. printf("%s TE-Class %u: %.3f Mbps",