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 * $FreeBSD$ 27 */ 28 29 #ifndef lint 30 static const char rcsid[] _U_ = 31 "@(#) $Header: /tcpdump/master/tcpdump/print-isoclns.c,v 1.133.2.19 2005/09/20 10:15:22 hannes Exp $ (LBL)"; 32 #endif 33 34 #ifdef HAVE_CONFIG_H 35 #include "config.h" 36 #endif 37 38 #include <tcpdump-stdinc.h> 39 40 #include <stdio.h> 41 #include <string.h> 42 43 #include "interface.h" 44 #include "addrtoname.h" 45 #include "ethertype.h" 46 #include "ether.h" 47 #include "nlpid.h" 48 #include "extract.h" 49 #include "gmpls.h" 50 #include "oui.h" 51 52 #define IPV4 1 /* AFI value */ 53 #define IPV6 2 /* AFI value */ 54 55 /* 56 * IS-IS is defined in ISO 10589. Look there for protocol definitions. 57 */ 58 59 #define SYSTEM_ID_LEN ETHER_ADDR_LEN 60 #define NODE_ID_LEN SYSTEM_ID_LEN+1 61 #define LSP_ID_LEN SYSTEM_ID_LEN+2 62 63 #define ISIS_VERSION 1 64 #define ESIS_VERSION 1 65 #define CLNP_VERSION 1 66 67 #define ISIS_PDU_TYPE_MASK 0x1F 68 #define ESIS_PDU_TYPE_MASK 0x1F 69 #define CLNP_PDU_TYPE_MASK 0x1F 70 #define CLNP_FLAG_MASK 0xE0 71 #define ISIS_LAN_PRIORITY_MASK 0x7F 72 73 #define ISIS_PDU_L1_LAN_IIH 15 74 #define ISIS_PDU_L2_LAN_IIH 16 75 #define ISIS_PDU_PTP_IIH 17 76 #define ISIS_PDU_L1_LSP 18 77 #define ISIS_PDU_L2_LSP 20 78 #define ISIS_PDU_L1_CSNP 24 79 #define ISIS_PDU_L2_CSNP 25 80 #define ISIS_PDU_L1_PSNP 26 81 #define ISIS_PDU_L2_PSNP 27 82 83 static struct tok isis_pdu_values[] = { 84 { ISIS_PDU_L1_LAN_IIH, "L1 Lan IIH"}, 85 { ISIS_PDU_L2_LAN_IIH, "L2 Lan IIH"}, 86 { ISIS_PDU_PTP_IIH, "p2p IIH"}, 87 { ISIS_PDU_L1_LSP, "L1 LSP"}, 88 { ISIS_PDU_L2_LSP, "L2 LSP"}, 89 { ISIS_PDU_L1_CSNP, "L1 CSNP"}, 90 { ISIS_PDU_L2_CSNP, "L2 CSNP"}, 91 { ISIS_PDU_L1_PSNP, "L1 PSNP"}, 92 { ISIS_PDU_L2_PSNP, "L2 PSNP"}, 93 { 0, NULL} 94 }; 95 96 /* 97 * A TLV is a tuple of a type, length and a value and is normally used for 98 * encoding information in all sorts of places. This is an enumeration of 99 * the well known types. 100 * 101 * list taken from rfc3359 plus some memory from veterans ;-) 102 */ 103 104 #define ISIS_TLV_AREA_ADDR 1 /* iso10589 */ 105 #define ISIS_TLV_IS_REACH 2 /* iso10589 */ 106 #define ISIS_TLV_ESNEIGH 3 /* iso10589 */ 107 #define ISIS_TLV_PART_DIS 4 /* iso10589 */ 108 #define ISIS_TLV_PREFIX_NEIGH 5 /* iso10589 */ 109 #define ISIS_TLV_ISNEIGH 6 /* iso10589 */ 110 #define ISIS_TLV_ISNEIGH_VARLEN 7 /* iso10589 */ 111 #define ISIS_TLV_PADDING 8 /* iso10589 */ 112 #define ISIS_TLV_LSP 9 /* iso10589 */ 113 #define ISIS_TLV_AUTH 10 /* iso10589, rfc3567 */ 114 #define ISIS_TLV_CHECKSUM 12 /* rfc3358 */ 115 #define ISIS_TLV_CHECKSUM_MINLEN 2 116 #define ISIS_TLV_LSP_BUFFERSIZE 14 /* iso10589 rev2 */ 117 #define ISIS_TLV_LSP_BUFFERSIZE_MINLEN 2 118 #define ISIS_TLV_EXT_IS_REACH 22 /* draft-ietf-isis-traffic-05 */ 119 #define ISIS_TLV_IS_ALIAS_ID 24 /* draft-ietf-isis-ext-lsp-frags-02 */ 120 #define ISIS_TLV_DECNET_PHASE4 42 121 #define ISIS_TLV_LUCENT_PRIVATE 66 122 #define ISIS_TLV_INT_IP_REACH 128 /* rfc1195, rfc2966 */ 123 #define ISIS_TLV_PROTOCOLS 129 /* rfc1195 */ 124 #define ISIS_TLV_EXT_IP_REACH 130 /* rfc1195, rfc2966 */ 125 #define ISIS_TLV_IDRP_INFO 131 /* rfc1195 */ 126 #define ISIS_TLV_IDRP_INFO_MINLEN 1 127 #define ISIS_TLV_IPADDR 132 /* rfc1195 */ 128 #define ISIS_TLV_IPAUTH 133 /* rfc1195 */ 129 #define ISIS_TLV_TE_ROUTER_ID 134 /* draft-ietf-isis-traffic-05 */ 130 #define ISIS_TLV_EXTD_IP_REACH 135 /* draft-ietf-isis-traffic-05 */ 131 #define ISIS_TLV_HOSTNAME 137 /* rfc2763 */ 132 #define ISIS_TLV_SHARED_RISK_GROUP 138 /* draft-ietf-isis-gmpls-extensions */ 133 #define ISIS_TLV_NORTEL_PRIVATE1 176 134 #define ISIS_TLV_NORTEL_PRIVATE2 177 135 #define ISIS_TLV_RESTART_SIGNALING 211 /* rfc3847 */ 136 #define ISIS_TLV_RESTART_SIGNALING_FLAGLEN 1 137 #define ISIS_TLV_RESTART_SIGNALING_HOLDTIMELEN 2 138 #define ISIS_TLV_MT_IS_REACH 222 /* draft-ietf-isis-wg-multi-topology-05 */ 139 #define ISIS_TLV_MT_SUPPORTED 229 /* draft-ietf-isis-wg-multi-topology-05 */ 140 #define ISIS_TLV_MT_SUPPORTED_MINLEN 2 141 #define ISIS_TLV_IP6ADDR 232 /* draft-ietf-isis-ipv6-02 */ 142 #define ISIS_TLV_MT_IP_REACH 235 /* draft-ietf-isis-wg-multi-topology-05 */ 143 #define ISIS_TLV_IP6_REACH 236 /* draft-ietf-isis-ipv6-02 */ 144 #define ISIS_TLV_MT_IP6_REACH 237 /* draft-ietf-isis-wg-multi-topology-05 */ 145 #define ISIS_TLV_PTP_ADJ 240 /* rfc3373 */ 146 #define ISIS_TLV_IIH_SEQNR 241 /* draft-shen-isis-iih-sequence-00 */ 147 #define ISIS_TLV_IIH_SEQNR_MINLEN 4 148 #define ISIS_TLV_VENDOR_PRIVATE 250 /* draft-ietf-isis-experimental-tlv-01 */ 149 #define ISIS_TLV_VENDOR_PRIVATE_MINLEN 3 150 151 static struct tok isis_tlv_values[] = { 152 { ISIS_TLV_AREA_ADDR, "Area address(es)"}, 153 { ISIS_TLV_IS_REACH, "IS Reachability"}, 154 { ISIS_TLV_ESNEIGH, "ES Neighbor(s)"}, 155 { ISIS_TLV_PART_DIS, "Partition DIS"}, 156 { ISIS_TLV_PREFIX_NEIGH, "Prefix Neighbors"}, 157 { ISIS_TLV_ISNEIGH, "IS Neighbor(s)"}, 158 { ISIS_TLV_ISNEIGH_VARLEN, "IS Neighbor(s) (variable length)"}, 159 { ISIS_TLV_PADDING, "Padding"}, 160 { ISIS_TLV_LSP, "LSP entries"}, 161 { ISIS_TLV_AUTH, "Authentication"}, 162 { ISIS_TLV_CHECKSUM, "Checksum"}, 163 { ISIS_TLV_LSP_BUFFERSIZE, "LSP Buffersize"}, 164 { ISIS_TLV_EXT_IS_REACH, "Extended IS Reachability"}, 165 { ISIS_TLV_IS_ALIAS_ID, "IS Alias ID"}, 166 { ISIS_TLV_DECNET_PHASE4, "DECnet Phase IV"}, 167 { ISIS_TLV_LUCENT_PRIVATE, "Lucent Proprietary"}, 168 { ISIS_TLV_INT_IP_REACH, "IPv4 Internal Reachability"}, 169 { ISIS_TLV_PROTOCOLS, "Protocols supported"}, 170 { ISIS_TLV_EXT_IP_REACH, "IPv4 External Reachability"}, 171 { ISIS_TLV_IDRP_INFO, "Inter-Domain Information Type"}, 172 { ISIS_TLV_IPADDR, "IPv4 Interface address(es)"}, 173 { ISIS_TLV_IPAUTH, "IPv4 authentication (deprecated)"}, 174 { ISIS_TLV_TE_ROUTER_ID, "Traffic Engineering Router ID"}, 175 { ISIS_TLV_EXTD_IP_REACH, "Extended IPv4 Reachability"}, 176 { ISIS_TLV_SHARED_RISK_GROUP, "Shared Risk Link Group"}, 177 { ISIS_TLV_NORTEL_PRIVATE1, "Nortel Proprietary"}, 178 { ISIS_TLV_NORTEL_PRIVATE2, "Nortel Proprietary"}, 179 { ISIS_TLV_HOSTNAME, "Hostname"}, 180 { ISIS_TLV_RESTART_SIGNALING, "Restart Signaling"}, 181 { ISIS_TLV_MT_IS_REACH, "Multi Topology IS Reachability"}, 182 { ISIS_TLV_MT_SUPPORTED, "Multi Topology"}, 183 { ISIS_TLV_IP6ADDR, "IPv6 Interface address(es)"}, 184 { ISIS_TLV_MT_IP_REACH, "Multi-Topology IPv4 Reachability"}, 185 { ISIS_TLV_IP6_REACH, "IPv6 reachability"}, 186 { ISIS_TLV_MT_IP6_REACH, "Multi-Topology IP6 Reachability"}, 187 { ISIS_TLV_PTP_ADJ, "Point-to-point Adjacency State"}, 188 { ISIS_TLV_IIH_SEQNR, "Hello PDU Sequence Number"}, 189 { ISIS_TLV_VENDOR_PRIVATE, "Vendor Private"}, 190 { 0, NULL } 191 }; 192 193 #define ESIS_OPTION_PROTOCOLS 129 194 #define ESIS_OPTION_QOS_MAINTENANCE 195 /* iso9542 */ 195 #define ESIS_OPTION_SECURITY 197 /* iso9542 */ 196 #define ESIS_OPTION_ES_CONF_TIME 198 /* iso9542 */ 197 #define ESIS_OPTION_PRIORITY 205 /* iso9542 */ 198 #define ESIS_OPTION_ADDRESS_MASK 225 /* iso9542 */ 199 #define ESIS_OPTION_SNPA_MASK 226 /* iso9542 */ 200 201 static struct tok esis_option_values[] = { 202 { ESIS_OPTION_PROTOCOLS, "Protocols supported"}, 203 { ESIS_OPTION_QOS_MAINTENANCE, "QoS Maintenance" }, 204 { ESIS_OPTION_SECURITY, "Security" }, 205 { ESIS_OPTION_ES_CONF_TIME, "ES Configuration Time" }, 206 { ESIS_OPTION_PRIORITY, "Priority" }, 207 { ESIS_OPTION_ADDRESS_MASK, "Addressk Mask" }, 208 { ESIS_OPTION_SNPA_MASK, "SNPA Mask" }, 209 { 0, NULL } 210 }; 211 212 #define CLNP_OPTION_DISCARD_REASON 193 213 #define CLNP_OPTION_QOS_MAINTENANCE 195 /* iso8473 */ 214 #define CLNP_OPTION_SECURITY 197 /* iso8473 */ 215 #define CLNP_OPTION_SOURCE_ROUTING 200 /* iso8473 */ 216 #define CLNP_OPTION_ROUTE_RECORDING 203 /* iso8473 */ 217 #define CLNP_OPTION_PADDING 204 /* iso8473 */ 218 #define CLNP_OPTION_PRIORITY 205 /* iso8473 */ 219 220 static struct tok clnp_option_values[] = { 221 { CLNP_OPTION_DISCARD_REASON, "Discard Reason"}, 222 { CLNP_OPTION_PRIORITY, "Priority"}, 223 { CLNP_OPTION_QOS_MAINTENANCE, "QoS Maintenance"}, 224 { CLNP_OPTION_SECURITY, "Security"}, 225 { CLNP_OPTION_SOURCE_ROUTING, "Source Routing"}, 226 { CLNP_OPTION_ROUTE_RECORDING, "Route Recording"}, 227 { CLNP_OPTION_PADDING, "Padding"}, 228 { 0, NULL } 229 }; 230 231 static struct tok clnp_option_rfd_class_values[] = { 232 { 0x0, "General"}, 233 { 0x8, "Address"}, 234 { 0x9, "Source Routeing"}, 235 { 0xa, "Lifetime"}, 236 { 0xb, "PDU Discarded"}, 237 { 0xc, "Reassembly"}, 238 { 0, NULL } 239 }; 240 241 static struct tok clnp_option_rfd_general_values[] = { 242 { 0x0, "Reason not specified"}, 243 { 0x1, "Protocol procedure error"}, 244 { 0x2, "Incorrect checksum"}, 245 { 0x3, "PDU discarded due to congestion"}, 246 { 0x4, "Header syntax error (cannot be parsed)"}, 247 { 0x5, "Segmentation needed but not permitted"}, 248 { 0x6, "Incomplete PDU received"}, 249 { 0x7, "Duplicate option"}, 250 { 0, NULL } 251 }; 252 253 static struct tok clnp_option_rfd_address_values[] = { 254 { 0x0, "Destination address unreachable"}, 255 { 0x1, "Destination address unknown"}, 256 { 0, NULL } 257 }; 258 259 static struct tok clnp_option_rfd_source_routeing_values[] = { 260 { 0x0, "Unspecified source routeing error"}, 261 { 0x1, "Syntax error in source routeing field"}, 262 { 0x2, "Unknown address in source routeing field"}, 263 { 0x3, "Path not acceptable"}, 264 { 0, NULL } 265 }; 266 267 static struct tok clnp_option_rfd_lifetime_values[] = { 268 { 0x0, "Lifetime expired while data unit in transit"}, 269 { 0x1, "Lifetime expired during reassembly"}, 270 { 0, NULL } 271 }; 272 273 static struct tok clnp_option_rfd_pdu_discard_values[] = { 274 { 0x0, "Unsupported option not specified"}, 275 { 0x1, "Unsupported protocol version"}, 276 { 0x2, "Unsupported security option"}, 277 { 0x3, "Unsupported source routeing option"}, 278 { 0x4, "Unsupported recording of route option"}, 279 { 0, NULL } 280 }; 281 282 static struct tok clnp_option_rfd_reassembly_values[] = { 283 { 0x0, "Reassembly interference"}, 284 { 0, NULL } 285 }; 286 287 /* array of 16 error-classes */ 288 static struct tok *clnp_option_rfd_error_class[] = { 289 clnp_option_rfd_general_values, 290 NULL, 291 NULL, 292 NULL, 293 NULL, 294 NULL, 295 NULL, 296 NULL, 297 clnp_option_rfd_address_values, 298 clnp_option_rfd_source_routeing_values, 299 clnp_option_rfd_lifetime_values, 300 clnp_option_rfd_pdu_discard_values, 301 clnp_option_rfd_reassembly_values, 302 NULL, 303 NULL, 304 NULL 305 }; 306 307 #define CLNP_OPTION_OPTION_QOS_MASK 0x3f 308 #define CLNP_OPTION_SCOPE_MASK 0xc0 309 #define CLNP_OPTION_SCOPE_SA_SPEC 0x40 310 #define CLNP_OPTION_SCOPE_DA_SPEC 0x80 311 #define CLNP_OPTION_SCOPE_GLOBAL 0xc0 312 313 static struct tok clnp_option_scope_values[] = { 314 { CLNP_OPTION_SCOPE_SA_SPEC, "Source Address Specific"}, 315 { CLNP_OPTION_SCOPE_DA_SPEC, "Destination Address Specific"}, 316 { CLNP_OPTION_SCOPE_GLOBAL, "Globally unique"}, 317 { 0, NULL } 318 }; 319 320 static struct tok clnp_option_sr_rr_values[] = { 321 { 0x0, "partial"}, 322 { 0x1, "complete"}, 323 { 0, NULL } 324 }; 325 326 static struct tok clnp_option_sr_rr_string_values[] = { 327 { CLNP_OPTION_SOURCE_ROUTING, "source routing"}, 328 { CLNP_OPTION_ROUTE_RECORDING, "recording of route in progress"}, 329 { 0, NULL } 330 }; 331 332 static struct tok clnp_option_qos_global_values[] = { 333 { 0x20, "reserved"}, 334 { 0x10, "sequencing vs. delay"}, 335 { 0x08, "congested"}, 336 { 0x04, "delay vs. cost"}, 337 { 0x02, "error vs. delay"}, 338 { 0x01, "error vs. cost"}, 339 { 0, NULL } 340 }; 341 342 #define ISIS_SUBTLV_EXT_IS_REACH_ADMIN_GROUP 3 /* draft-ietf-isis-traffic-05 */ 343 #define ISIS_SUBTLV_EXT_IS_REACH_LINK_LOCAL_REMOTE_ID 4 /* draft-ietf-isis-gmpls-extensions */ 344 #define ISIS_SUBTLV_EXT_IS_REACH_LINK_REMOTE_ID 5 /* draft-ietf-isis-traffic-05 */ 345 #define ISIS_SUBTLV_EXT_IS_REACH_IPV4_INTF_ADDR 6 /* draft-ietf-isis-traffic-05 */ 346 #define ISIS_SUBTLV_EXT_IS_REACH_IPV4_NEIGHBOR_ADDR 8 /* draft-ietf-isis-traffic-05 */ 347 #define ISIS_SUBTLV_EXT_IS_REACH_MAX_LINK_BW 9 /* draft-ietf-isis-traffic-05 */ 348 #define ISIS_SUBTLV_EXT_IS_REACH_RESERVABLE_BW 10 /* draft-ietf-isis-traffic-05 */ 349 #define ISIS_SUBTLV_EXT_IS_REACH_UNRESERVED_BW 11 /* rfc4124 */ 350 #define ISIS_SUBTLV_EXT_IS_REACH_BW_CONSTRAINTS_OLD 12 /* draft-ietf-tewg-diff-te-proto-06 */ 351 #define ISIS_SUBTLV_EXT_IS_REACH_TE_METRIC 18 /* draft-ietf-isis-traffic-05 */ 352 #define ISIS_SUBTLV_EXT_IS_REACH_LINK_PROTECTION_TYPE 20 /* draft-ietf-isis-gmpls-extensions */ 353 #define ISIS_SUBTLV_EXT_IS_REACH_INTF_SW_CAP_DESCR 21 /* draft-ietf-isis-gmpls-extensions */ 354 #define ISIS_SUBTLV_EXT_IS_REACH_BW_CONSTRAINTS 22 /* rfc4124 */ 355 356 static struct tok isis_ext_is_reach_subtlv_values[] = { 357 { ISIS_SUBTLV_EXT_IS_REACH_ADMIN_GROUP, "Administrative groups" }, 358 { ISIS_SUBTLV_EXT_IS_REACH_LINK_LOCAL_REMOTE_ID, "Link Local/Remote Identifier" }, 359 { ISIS_SUBTLV_EXT_IS_REACH_LINK_REMOTE_ID, "Link Remote Identifier" }, 360 { ISIS_SUBTLV_EXT_IS_REACH_IPV4_INTF_ADDR, "IPv4 interface address" }, 361 { ISIS_SUBTLV_EXT_IS_REACH_IPV4_NEIGHBOR_ADDR, "IPv4 neighbor address" }, 362 { ISIS_SUBTLV_EXT_IS_REACH_MAX_LINK_BW, "Maximum link bandwidth" }, 363 { ISIS_SUBTLV_EXT_IS_REACH_RESERVABLE_BW, "Reservable link bandwidth" }, 364 { ISIS_SUBTLV_EXT_IS_REACH_UNRESERVED_BW, "Unreserved bandwidth" }, 365 { ISIS_SUBTLV_EXT_IS_REACH_TE_METRIC, "Traffic Engineering Metric" }, 366 { ISIS_SUBTLV_EXT_IS_REACH_LINK_PROTECTION_TYPE, "Link Protection Type" }, 367 { ISIS_SUBTLV_EXT_IS_REACH_INTF_SW_CAP_DESCR, "Interface Switching Capability" }, 368 { ISIS_SUBTLV_EXT_IS_REACH_BW_CONSTRAINTS_OLD, "Bandwidth Constraints (old)" }, 369 { ISIS_SUBTLV_EXT_IS_REACH_BW_CONSTRAINTS, "Bandwidth Constraints" }, 370 { 250, "Reserved for cisco specific extensions" }, 371 { 251, "Reserved for cisco specific extensions" }, 372 { 252, "Reserved for cisco specific extensions" }, 373 { 253, "Reserved for cisco specific extensions" }, 374 { 254, "Reserved for cisco specific extensions" }, 375 { 255, "Reserved for future expansion" }, 376 { 0, NULL } 377 }; 378 379 #define ISIS_SUBTLV_EXTD_IP_REACH_ADMIN_TAG32 1 /* draft-ietf-isis-admin-tags-01 */ 380 #define ISIS_SUBTLV_EXTD_IP_REACH_ADMIN_TAG64 2 /* draft-ietf-isis-admin-tags-01 */ 381 #define ISIS_SUBTLV_EXTD_IP_REACH_MGMT_PREFIX_COLOR 117 /* draft-ietf-isis-wg-multi-topology-05 */ 382 383 static struct tok isis_ext_ip_reach_subtlv_values[] = { 384 { ISIS_SUBTLV_EXTD_IP_REACH_ADMIN_TAG32, "32-Bit Administrative tag" }, 385 { ISIS_SUBTLV_EXTD_IP_REACH_ADMIN_TAG64, "64-Bit Administrative tag" }, 386 { ISIS_SUBTLV_EXTD_IP_REACH_MGMT_PREFIX_COLOR, "Management Prefix Color" }, 387 { 0, NULL } 388 }; 389 390 #define ISIS_SUBTLV_AUTH_SIMPLE 1 391 #define ISIS_SUBTLV_AUTH_MD5 54 392 #define ISIS_SUBTLV_AUTH_MD5_LEN 16 393 #define ISIS_SUBTLV_AUTH_PRIVATE 255 394 395 static struct tok isis_subtlv_auth_values[] = { 396 { ISIS_SUBTLV_AUTH_SIMPLE, "simple text password"}, 397 { ISIS_SUBTLV_AUTH_MD5, "HMAC-MD5 password"}, 398 { ISIS_SUBTLV_AUTH_PRIVATE, "Routing Domain private password"}, 399 { 0, NULL } 400 }; 401 402 #define ISIS_SUBTLV_IDRP_RES 0 403 #define ISIS_SUBTLV_IDRP_LOCAL 1 404 #define ISIS_SUBTLV_IDRP_ASN 2 405 406 static struct tok isis_subtlv_idrp_values[] = { 407 { ISIS_SUBTLV_IDRP_RES, "Reserved"}, 408 { ISIS_SUBTLV_IDRP_LOCAL, "Routing-Domain Specific"}, 409 { ISIS_SUBTLV_IDRP_ASN, "AS Number Tag"}, 410 { 0, NULL} 411 }; 412 413 #define CLNP_SEGMENT_PART 0x80 414 #define CLNP_MORE_SEGMENTS 0x40 415 #define CLNP_REQUEST_ER 0x20 416 417 static struct tok clnp_flag_values[] = { 418 { CLNP_SEGMENT_PART, "Segmentation permitted"}, 419 { CLNP_MORE_SEGMENTS, "more Segments"}, 420 { CLNP_REQUEST_ER, "request Error Report"}, 421 { 0, NULL} 422 }; 423 424 #define ISIS_MASK_LSP_OL_BIT(x) ((x)&0x4) 425 #define ISIS_MASK_LSP_ISTYPE_BITS(x) ((x)&0x3) 426 #define ISIS_MASK_LSP_PARTITION_BIT(x) ((x)&0x80) 427 #define ISIS_MASK_LSP_ATT_BITS(x) ((x)&0x78) 428 #define ISIS_MASK_LSP_ATT_ERROR_BIT(x) ((x)&0x40) 429 #define ISIS_MASK_LSP_ATT_EXPENSE_BIT(x) ((x)&0x20) 430 #define ISIS_MASK_LSP_ATT_DELAY_BIT(x) ((x)&0x10) 431 #define ISIS_MASK_LSP_ATT_DEFAULT_BIT(x) ((x)&0x8) 432 433 #define ISIS_MASK_MTID(x) ((x)&0x0fff) 434 #define ISIS_MASK_MTFLAGS(x) ((x)&0xf000) 435 436 static struct tok isis_mt_flag_values[] = { 437 { 0x4000, "sub-TLVs present"}, 438 { 0x8000, "ATT bit set"}, 439 { 0, NULL} 440 }; 441 442 #define ISIS_MASK_TLV_EXTD_IP_UPDOWN(x) ((x)&0x80) 443 #define ISIS_MASK_TLV_EXTD_IP_SUBTLV(x) ((x)&0x40) 444 445 #define ISIS_MASK_TLV_EXTD_IP6_IE(x) ((x)&0x40) 446 #define ISIS_MASK_TLV_EXTD_IP6_SUBTLV(x) ((x)&0x20) 447 448 #define ISIS_LSP_TLV_METRIC_SUPPORTED(x) ((x)&0x80) 449 #define ISIS_LSP_TLV_METRIC_IE(x) ((x)&0x40) 450 #define ISIS_LSP_TLV_METRIC_UPDOWN(x) ((x)&0x80) 451 #define ISIS_LSP_TLV_METRIC_VALUE(x) ((x)&0x3f) 452 453 #define ISIS_MASK_TLV_SHARED_RISK_GROUP(x) ((x)&0x1) 454 455 static struct tok isis_mt_values[] = { 456 { 0, "IPv4 unicast"}, 457 { 1, "In-Band Management"}, 458 { 2, "IPv6 unicast"}, 459 { 3, "Multicast"}, 460 { 4095, "Development, Experimental or Proprietary"}, 461 { 0, NULL } 462 }; 463 464 static struct tok isis_iih_circuit_type_values[] = { 465 { 1, "Level 1 only"}, 466 { 2, "Level 2 only"}, 467 { 3, "Level 1, Level 2"}, 468 { 0, NULL} 469 }; 470 471 #define ISIS_LSP_TYPE_UNUSED0 0 472 #define ISIS_LSP_TYPE_LEVEL_1 1 473 #define ISIS_LSP_TYPE_UNUSED2 2 474 #define ISIS_LSP_TYPE_LEVEL_2 3 475 476 static struct tok isis_lsp_istype_values[] = { 477 { ISIS_LSP_TYPE_UNUSED0, "Unused 0x0 (invalid)"}, 478 { ISIS_LSP_TYPE_LEVEL_1, "L1 IS"}, 479 { ISIS_LSP_TYPE_UNUSED2, "Unused 0x2 (invalid)"}, 480 { ISIS_LSP_TYPE_LEVEL_2, "L1L2 IS"}, 481 { 0, NULL } 482 }; 483 484 /* 485 * Katz's point to point adjacency TLV uses codes to tell us the state of 486 * the remote adjacency. Enumerate them. 487 */ 488 489 #define ISIS_PTP_ADJ_UP 0 490 #define ISIS_PTP_ADJ_INIT 1 491 #define ISIS_PTP_ADJ_DOWN 2 492 493 static struct tok isis_ptp_adjancey_values[] = { 494 { ISIS_PTP_ADJ_UP, "Up" }, 495 { ISIS_PTP_ADJ_INIT, "Initializing" }, 496 { ISIS_PTP_ADJ_DOWN, "Down" }, 497 { 0, NULL} 498 }; 499 500 struct isis_tlv_ptp_adj { 501 u_int8_t adjacency_state; 502 u_int8_t extd_local_circuit_id[4]; 503 u_int8_t neighbor_sysid[SYSTEM_ID_LEN]; 504 u_int8_t neighbor_extd_local_circuit_id[4]; 505 }; 506 507 static int osi_cksum(const u_int8_t *, u_int); 508 static int clnp_print(const u_int8_t *, u_int); 509 static void esis_print(const u_int8_t *, u_int); 510 static int isis_print(const u_int8_t *, u_int); 511 512 struct isis_metric_block { 513 u_int8_t metric_default; 514 u_int8_t metric_delay; 515 u_int8_t metric_expense; 516 u_int8_t metric_error; 517 }; 518 519 struct isis_tlv_is_reach { 520 struct isis_metric_block isis_metric_block; 521 u_int8_t neighbor_nodeid[NODE_ID_LEN]; 522 }; 523 524 struct isis_tlv_es_reach { 525 struct isis_metric_block isis_metric_block; 526 u_int8_t neighbor_sysid[SYSTEM_ID_LEN]; 527 }; 528 529 struct isis_tlv_ip_reach { 530 struct isis_metric_block isis_metric_block; 531 u_int8_t prefix[4]; 532 u_int8_t mask[4]; 533 }; 534 535 static struct tok isis_is_reach_virtual_values[] = { 536 { 0, "IsNotVirtual"}, 537 { 1, "IsVirtual"}, 538 { 0, NULL } 539 }; 540 541 static struct tok isis_restart_flag_values[] = { 542 { 0x1, "Restart Request"}, 543 { 0x2, "Restart Acknowledgement"}, 544 { 0x4, "Suppress adjacency advertisement"}, 545 { 0, NULL } 546 }; 547 548 struct isis_common_header { 549 u_int8_t nlpid; 550 u_int8_t fixed_len; 551 u_int8_t version; /* Protocol version */ 552 u_int8_t id_length; 553 u_int8_t pdu_type; /* 3 MSbits are reserved */ 554 u_int8_t pdu_version; /* Packet format version */ 555 u_int8_t reserved; 556 u_int8_t max_area; 557 }; 558 559 struct isis_iih_lan_header { 560 u_int8_t circuit_type; 561 u_int8_t source_id[SYSTEM_ID_LEN]; 562 u_int8_t holding_time[2]; 563 u_int8_t pdu_len[2]; 564 u_int8_t priority; 565 u_int8_t lan_id[NODE_ID_LEN]; 566 }; 567 568 struct isis_iih_ptp_header { 569 u_int8_t circuit_type; 570 u_int8_t source_id[SYSTEM_ID_LEN]; 571 u_int8_t holding_time[2]; 572 u_int8_t pdu_len[2]; 573 u_int8_t circuit_id; 574 }; 575 576 struct isis_lsp_header { 577 u_int8_t pdu_len[2]; 578 u_int8_t remaining_lifetime[2]; 579 u_int8_t lsp_id[LSP_ID_LEN]; 580 u_int8_t sequence_number[4]; 581 u_int8_t checksum[2]; 582 u_int8_t typeblock; 583 }; 584 585 struct isis_csnp_header { 586 u_int8_t pdu_len[2]; 587 u_int8_t source_id[NODE_ID_LEN]; 588 u_int8_t start_lsp_id[LSP_ID_LEN]; 589 u_int8_t end_lsp_id[LSP_ID_LEN]; 590 }; 591 592 struct isis_psnp_header { 593 u_int8_t pdu_len[2]; 594 u_int8_t source_id[NODE_ID_LEN]; 595 }; 596 597 struct isis_tlv_lsp { 598 u_int8_t remaining_lifetime[2]; 599 u_int8_t lsp_id[LSP_ID_LEN]; 600 u_int8_t sequence_number[4]; 601 u_int8_t checksum[2]; 602 }; 603 604 #define ISIS_COMMON_HEADER_SIZE (sizeof(struct isis_common_header)) 605 #define ISIS_IIH_LAN_HEADER_SIZE (sizeof(struct isis_iih_lan_header)) 606 #define ISIS_IIH_PTP_HEADER_SIZE (sizeof(struct isis_iih_ptp_header)) 607 #define ISIS_LSP_HEADER_SIZE (sizeof(struct isis_lsp_header)) 608 #define ISIS_CSNP_HEADER_SIZE (sizeof(struct isis_csnp_header)) 609 #define ISIS_PSNP_HEADER_SIZE (sizeof(struct isis_psnp_header)) 610 611 void isoclns_print(const u_int8_t *p, u_int length, u_int caplen) 612 { 613 const struct isis_common_header *header; 614 615 header = (const struct isis_common_header *)p; 616 617 if (caplen <= 1) { /* enough bytes on the wire ? */ 618 printf("|OSI"); 619 return; 620 } 621 622 if (eflag) 623 printf("OSI NLPID %s (0x%02x): ", 624 tok2str(nlpid_values,"Unknown",*p), 625 *p); 626 627 switch (*p) { 628 629 case NLPID_CLNP: 630 if (!clnp_print(p, length)) 631 print_unknown_data(p,"\n\t",caplen); 632 break; 633 634 case NLPID_ESIS: 635 esis_print(p, length); 636 return; 637 638 case NLPID_ISIS: 639 if (!isis_print(p, length)) 640 print_unknown_data(p,"\n\t",caplen); 641 break; 642 643 case NLPID_NULLNS: 644 (void)printf("%slength: %u", 645 eflag ? "" : ", ", 646 length); 647 break; 648 649 case NLPID_Q933: 650 q933_print(p+1, length-1); 651 break; 652 653 case NLPID_IP: 654 ip_print(gndo, p+1, length-1); 655 break; 656 657 #ifdef INET6 658 case NLPID_IP6: 659 ip6_print(p+1, length-1); 660 break; 661 #endif 662 663 case NLPID_PPP: 664 ppp_print(p+1, length-1); 665 break; 666 667 default: 668 if (!eflag) 669 printf("OSI NLPID 0x%02x unknown",*p); 670 (void)printf("%slength: %u", 671 eflag ? "" : ", ", 672 length); 673 if (caplen > 1) 674 print_unknown_data(p,"\n\t",caplen); 675 break; 676 } 677 } 678 679 #define CLNP_PDU_ER 1 680 #define CLNP_PDU_DT 28 681 #define CLNP_PDU_MD 29 682 #define CLNP_PDU_ERQ 30 683 #define CLNP_PDU_ERP 31 684 685 static struct tok clnp_pdu_values[] = { 686 { CLNP_PDU_ER, "Error Report"}, 687 { CLNP_PDU_MD, "MD"}, 688 { CLNP_PDU_DT, "Data"}, 689 { CLNP_PDU_ERQ, "Echo Request"}, 690 { CLNP_PDU_ERP, "Echo Response"}, 691 { 0, NULL } 692 }; 693 694 struct clnp_header_t { 695 u_int8_t nlpid; 696 u_int8_t length_indicator; 697 u_int8_t version; 698 u_int8_t lifetime; /* units of 500ms */ 699 u_int8_t type; 700 u_int8_t segment_length[2]; 701 u_int8_t cksum[2]; 702 }; 703 704 struct clnp_segment_header_t { 705 u_int8_t data_unit_id[2]; 706 u_int8_t segment_offset[2]; 707 u_int8_t total_length[2]; 708 }; 709 710 /* 711 * clnp_print 712 * Decode CLNP packets. Return 0 on error. 713 */ 714 715 static int clnp_print (const u_int8_t *pptr, u_int length) 716 { 717 const u_int8_t *optr,*source_address,*dest_address; 718 u_int li,tlen,nsap_offset,source_address_length,dest_address_length, clnp_pdu_type, clnp_flags; 719 const struct clnp_header_t *clnp_header; 720 const struct clnp_segment_header_t *clnp_segment_header; 721 u_int8_t rfd_error_major,rfd_error_minor; 722 723 clnp_header = (const struct clnp_header_t *) pptr; 724 TCHECK(*clnp_header); 725 726 li = clnp_header->length_indicator; 727 optr = pptr; 728 729 if (!eflag) 730 printf("CLNP"); 731 732 /* 733 * Sanity checking of the header. 734 */ 735 736 if (clnp_header->version != CLNP_VERSION) { 737 printf("version %d packet not supported", clnp_header->version); 738 return (0); 739 } 740 741 /* FIXME further header sanity checking */ 742 743 clnp_pdu_type = clnp_header->type & CLNP_PDU_TYPE_MASK; 744 clnp_flags = clnp_header->type & CLNP_FLAG_MASK; 745 746 pptr += sizeof(struct clnp_header_t); 747 li -= sizeof(struct clnp_header_t); 748 dest_address_length = *pptr; 749 dest_address = pptr + 1; 750 751 pptr += (1 + dest_address_length); 752 li -= (1 + dest_address_length); 753 source_address_length = *pptr; 754 source_address = pptr +1; 755 756 pptr += (1 + source_address_length); 757 li -= (1 + source_address_length); 758 759 if (vflag < 1) { 760 printf("%s%s > %s, %s, length %u", 761 eflag ? "" : ", ", 762 isonsap_string(source_address, source_address_length), 763 isonsap_string(dest_address, dest_address_length), 764 tok2str(clnp_pdu_values,"unknown (%u)",clnp_pdu_type), 765 length); 766 return (1); 767 } 768 printf("%slength %u",eflag ? "" : ", ",length); 769 770 printf("\n\t%s PDU, hlen: %u, v: %u, lifetime: %u.%us, Segment PDU length: %u, checksum: 0x%04x ", 771 tok2str(clnp_pdu_values, "unknown (%u)",clnp_pdu_type), 772 clnp_header->length_indicator, 773 clnp_header->version, 774 clnp_header->lifetime/2, 775 (clnp_header->lifetime%2)*5, 776 EXTRACT_16BITS(clnp_header->segment_length), 777 EXTRACT_16BITS(clnp_header->cksum)); 778 779 /* do not attempt to verify the checksum if it is zero */ 780 if (EXTRACT_16BITS(clnp_header->cksum) == 0) 781 printf("(unverified)"); 782 else printf("(%s)", osi_cksum(optr, clnp_header->length_indicator) ? "incorrect" : "correct"); 783 784 printf("\n\tFlags [%s]", 785 bittok2str(clnp_flag_values,"none",clnp_flags)); 786 787 printf("\n\tsource address (length %u): %s\n\tdest address (length %u): %s", 788 source_address_length, 789 isonsap_string(source_address, source_address_length), 790 dest_address_length, 791 isonsap_string(dest_address,dest_address_length)); 792 793 if (clnp_flags & CLNP_SEGMENT_PART) { 794 clnp_segment_header = (const struct clnp_segment_header_t *) pptr; 795 TCHECK(*clnp_segment_header); 796 printf("\n\tData Unit ID: 0x%04x, Segment Offset: %u, Total PDU Length: %u", 797 EXTRACT_16BITS(clnp_segment_header->data_unit_id), 798 EXTRACT_16BITS(clnp_segment_header->segment_offset), 799 EXTRACT_16BITS(clnp_segment_header->total_length)); 800 pptr+=sizeof(const struct clnp_segment_header_t); 801 li-=sizeof(const struct clnp_segment_header_t); 802 } 803 804 /* now walk the options */ 805 while (li >= 2) { 806 u_int op, opli; 807 const u_int8_t *tptr; 808 809 TCHECK2(*pptr, 2); 810 if (li < 2) { 811 printf(", bad opts/li"); 812 return (0); 813 } 814 op = *pptr++; 815 opli = *pptr++; 816 li -= 2; 817 TCHECK2(*pptr, opli); 818 if (opli > li) { 819 printf(", opt (%d) too long", op); 820 return (0); 821 } 822 li -= opli; 823 tptr = pptr; 824 tlen = opli; 825 826 printf("\n\t %s Option #%u, length %u, value: ", 827 tok2str(clnp_option_values,"Unknown",op), 828 op, 829 opli); 830 831 switch (op) { 832 833 834 case CLNP_OPTION_ROUTE_RECORDING: /* those two options share the format */ 835 case CLNP_OPTION_SOURCE_ROUTING: 836 printf("%s %s", 837 tok2str(clnp_option_sr_rr_values,"Unknown",*tptr), 838 tok2str(clnp_option_sr_rr_string_values,"Unknown Option %u",op)); 839 nsap_offset=*(tptr+1); 840 if (nsap_offset == 0) { 841 printf(" Bad NSAP offset (0)"); 842 break; 843 } 844 nsap_offset-=1; /* offset to nsap list */ 845 if (nsap_offset > tlen) { 846 printf(" Bad NSAP offset (past end of option)"); 847 break; 848 } 849 tptr+=nsap_offset; 850 tlen-=nsap_offset; 851 while (tlen > 0) { 852 source_address_length=*tptr; 853 if (tlen < source_address_length+1) { 854 printf("\n\t NSAP address goes past end of option"); 855 break; 856 } 857 if (source_address_length > 0) { 858 source_address=(tptr+1); 859 TCHECK2(*source_address, source_address_length); 860 printf("\n\t NSAP address (length %u): %s", 861 source_address_length, 862 isonsap_string(source_address, source_address_length)); 863 } 864 tlen-=source_address_length+1; 865 } 866 break; 867 868 case CLNP_OPTION_PRIORITY: 869 printf("0x%1x", *tptr&0x0f); 870 break; 871 872 case CLNP_OPTION_QOS_MAINTENANCE: 873 printf("\n\t Format Code: %s", 874 tok2str(clnp_option_scope_values,"Reserved",*tptr&CLNP_OPTION_SCOPE_MASK)); 875 876 if ((*tptr&CLNP_OPTION_SCOPE_MASK) == CLNP_OPTION_SCOPE_GLOBAL) 877 printf("\n\t QoS Flags [%s]", 878 bittok2str(clnp_option_qos_global_values, 879 "none", 880 *tptr&CLNP_OPTION_OPTION_QOS_MASK)); 881 break; 882 883 case CLNP_OPTION_SECURITY: 884 printf("\n\t Format Code: %s, Security-Level %u", 885 tok2str(clnp_option_scope_values,"Reserved",*tptr&CLNP_OPTION_SCOPE_MASK), 886 *(tptr+1)); 887 break; 888 889 case CLNP_OPTION_DISCARD_REASON: 890 rfd_error_major = (*tptr&0xf0) >> 4; 891 rfd_error_minor = *tptr&0x0f; 892 printf("\n\t Class: %s Error (0x%01x), %s (0x%01x)", 893 tok2str(clnp_option_rfd_class_values,"Unknown",rfd_error_major), 894 rfd_error_major, 895 tok2str(clnp_option_rfd_error_class[rfd_error_major],"Unknown",rfd_error_minor), 896 rfd_error_minor); 897 break; 898 899 case CLNP_OPTION_PADDING: 900 printf("padding data"); 901 break; 902 903 /* 904 * FIXME those are the defined Options that lack a decoder 905 * you are welcome to contribute code ;-) 906 */ 907 908 default: 909 print_unknown_data(tptr,"\n\t ",opli); 910 break; 911 } 912 if (vflag > 1) 913 print_unknown_data(pptr,"\n\t ",opli); 914 pptr += opli; 915 } 916 917 switch (clnp_pdu_type) { 918 919 case CLNP_PDU_ER: /* fall through */ 920 case CLNP_PDU_ERP: 921 TCHECK(*pptr); 922 if (*(pptr) == NLPID_CLNP) { 923 printf("\n\t-----original packet-----\n\t"); 924 /* FIXME recursion protection */ 925 clnp_print(pptr, length-clnp_header->length_indicator); 926 break; 927 } 928 929 case CLNP_PDU_DT: 930 case CLNP_PDU_MD: 931 case CLNP_PDU_ERQ: 932 933 default: 934 /* dump the PDU specific data */ 935 if (length-(pptr-optr) > 0) { 936 printf("\n\t undecoded non-header data, length %u",length-clnp_header->length_indicator); 937 print_unknown_data(pptr,"\n\t ",length-(pptr-optr)); 938 } 939 } 940 941 return (1); 942 943 trunc: 944 fputs("[|clnp]", stdout); 945 return (1); 946 947 } 948 949 950 #define ESIS_PDU_REDIRECT 6 951 #define ESIS_PDU_ESH 2 952 #define ESIS_PDU_ISH 4 953 954 static struct tok esis_pdu_values[] = { 955 { ESIS_PDU_REDIRECT, "redirect"}, 956 { ESIS_PDU_ESH, "ESH"}, 957 { ESIS_PDU_ISH, "ISH"}, 958 { 0, NULL } 959 }; 960 961 struct esis_header_t { 962 u_int8_t nlpid; 963 u_int8_t length_indicator; 964 u_int8_t version; 965 u_int8_t reserved; 966 u_int8_t type; 967 u_int8_t holdtime[2]; 968 u_int8_t cksum[2]; 969 }; 970 971 static void 972 esis_print(const u_int8_t *pptr, u_int length) 973 { 974 const u_int8_t *optr; 975 u_int li,esis_pdu_type,source_address_length, source_address_number; 976 const struct esis_header_t *esis_header; 977 978 if (!eflag) 979 printf("ES-IS"); 980 981 if (length <= 2) { 982 if (qflag) 983 printf("bad pkt!"); 984 else 985 printf("no header at all!"); 986 return; 987 } 988 989 esis_header = (const struct esis_header_t *) pptr; 990 TCHECK(*esis_header); 991 li = esis_header->length_indicator; 992 optr = pptr; 993 994 /* 995 * Sanity checking of the header. 996 */ 997 998 if (esis_header->nlpid != NLPID_ESIS) { 999 printf(" nlpid 0x%02x packet not supported", esis_header->nlpid); 1000 return; 1001 } 1002 1003 if (esis_header->version != ESIS_VERSION) { 1004 printf(" version %d packet not supported", esis_header->version); 1005 return; 1006 } 1007 1008 if (li > length) { 1009 printf(" length indicator(%d) > PDU size (%d)!", li, length); 1010 return; 1011 } 1012 1013 if (li < sizeof(struct esis_header_t) + 2) { 1014 printf(" length indicator < min PDU size %d:", li); 1015 while (--length != 0) 1016 printf("%02X", *pptr++); 1017 return; 1018 } 1019 1020 esis_pdu_type = esis_header->type & ESIS_PDU_TYPE_MASK; 1021 1022 if (vflag < 1) { 1023 printf("%s%s, length %u", 1024 eflag ? "" : ", ", 1025 tok2str(esis_pdu_values,"unknown type (%u)",esis_pdu_type), 1026 length); 1027 return; 1028 } else 1029 printf("%slength %u\n\t%s (%u)", 1030 eflag ? "" : ", ", 1031 length, 1032 tok2str(esis_pdu_values,"unknown type: %u", esis_pdu_type), 1033 esis_pdu_type); 1034 1035 printf(", v: %u%s", esis_header->version, esis_header->version == ESIS_VERSION ? "" : "unsupported" ); 1036 printf(", checksum: 0x%04x ", EXTRACT_16BITS(esis_header->cksum)); 1037 /* do not attempt to verify the checksum if it is zero */ 1038 if (EXTRACT_16BITS(esis_header->cksum) == 0) 1039 printf("(unverified)"); 1040 else 1041 printf("(%s)", osi_cksum(pptr, li) ? "incorrect" : "correct"); 1042 1043 printf(", holding time: %us, length indicator: %u",EXTRACT_16BITS(esis_header->holdtime),li); 1044 1045 if (vflag > 1) 1046 print_unknown_data(optr,"\n\t",sizeof(struct esis_header_t)); 1047 1048 pptr += sizeof(struct esis_header_t); 1049 li -= sizeof(struct esis_header_t); 1050 1051 switch (esis_pdu_type) { 1052 case ESIS_PDU_REDIRECT: { 1053 const u_int8_t *dst, *snpa, *neta; 1054 u_int dstl, snpal, netal; 1055 1056 TCHECK(*pptr); 1057 if (li < 1) { 1058 printf(", bad redirect/li"); 1059 return; 1060 } 1061 dstl = *pptr; 1062 pptr++; 1063 li--; 1064 TCHECK2(*pptr, dstl); 1065 if (li < dstl) { 1066 printf(", bad redirect/li"); 1067 return; 1068 } 1069 dst = pptr; 1070 pptr += dstl; 1071 li -= dstl; 1072 printf("\n\t %s", isonsap_string(dst,dstl)); 1073 1074 TCHECK(*pptr); 1075 if (li < 1) { 1076 printf(", bad redirect/li"); 1077 return; 1078 } 1079 snpal = *pptr; 1080 pptr++; 1081 li--; 1082 TCHECK2(*pptr, snpal); 1083 if (li < snpal) { 1084 printf(", bad redirect/li"); 1085 return; 1086 } 1087 snpa = pptr; 1088 pptr += snpal; 1089 li -= snpal; 1090 TCHECK(*pptr); 1091 if (li < 1) { 1092 printf(", bad redirect/li"); 1093 return; 1094 } 1095 netal = *pptr; 1096 pptr++; 1097 TCHECK2(*pptr, netal); 1098 if (li < netal) { 1099 printf(", bad redirect/li"); 1100 return; 1101 } 1102 neta = pptr; 1103 pptr += netal; 1104 li -= netal; 1105 1106 if (netal == 0) 1107 printf("\n\t %s", etheraddr_string(snpa)); 1108 else 1109 printf("\n\t %s", isonsap_string(neta,netal)); 1110 break; 1111 } 1112 1113 case ESIS_PDU_ESH: 1114 TCHECK(*pptr); 1115 if (li < 1) { 1116 printf(", bad esh/li"); 1117 return; 1118 } 1119 source_address_number = *pptr; 1120 pptr++; 1121 li--; 1122 1123 printf("\n\t Number of Source Addresses: %u", source_address_number); 1124 1125 while (source_address_number > 0) { 1126 TCHECK(*pptr); 1127 if (li < 1) { 1128 printf(", bad esh/li"); 1129 return; 1130 } 1131 source_address_length = *pptr; 1132 pptr++; 1133 li--; 1134 1135 TCHECK2(*pptr, source_address_length); 1136 if (li < source_address_length) { 1137 printf(", bad esh/li"); 1138 return; 1139 } 1140 printf("\n\t NET (length: %u): %s", 1141 source_address_length, 1142 isonsap_string(pptr,source_address_length)); 1143 pptr += source_address_length; 1144 li -= source_address_length; 1145 source_address_number--; 1146 } 1147 1148 break; 1149 1150 case ESIS_PDU_ISH: { 1151 TCHECK(*pptr); 1152 if (li < 1) { 1153 printf(", bad ish/li"); 1154 return; 1155 } 1156 source_address_length = *pptr; 1157 pptr++; 1158 li--; 1159 TCHECK2(*pptr, source_address_length); 1160 if (li < source_address_length) { 1161 printf(", bad ish/li"); 1162 return; 1163 } 1164 printf("\n\t NET (length: %u): %s", source_address_length, isonsap_string(pptr, source_address_length)); 1165 pptr += source_address_length; 1166 li -= source_address_length; 1167 break; 1168 } 1169 1170 default: 1171 if (vflag <= 1) { 1172 if (pptr < snapend) 1173 print_unknown_data(pptr,"\n\t ",snapend-pptr); 1174 } 1175 return; 1176 } 1177 1178 /* now walk the options */ 1179 while (li >= 2) { 1180 u_int op, opli; 1181 const u_int8_t *tptr; 1182 1183 TCHECK2(*pptr, 2); 1184 if (li < 2) { 1185 printf(", bad opts/li"); 1186 return; 1187 } 1188 op = *pptr++; 1189 opli = *pptr++; 1190 li -= 2; 1191 if (opli > li) { 1192 printf(", opt (%d) too long", op); 1193 return; 1194 } 1195 li -= opli; 1196 tptr = pptr; 1197 1198 printf("\n\t %s Option #%u, length %u, value: ", 1199 tok2str(esis_option_values,"Unknown",op), 1200 op, 1201 opli); 1202 1203 switch (op) { 1204 1205 case ESIS_OPTION_ES_CONF_TIME: 1206 TCHECK2(*pptr, 2); 1207 printf("%us", EXTRACT_16BITS(tptr)); 1208 break; 1209 1210 case ESIS_OPTION_PROTOCOLS: 1211 while (opli>0) { 1212 TCHECK(*pptr); 1213 printf("%s (0x%02x)", 1214 tok2str(nlpid_values, 1215 "unknown", 1216 *tptr), 1217 *tptr); 1218 if (opli>1) /* further NPLIDs ? - put comma */ 1219 printf(", "); 1220 tptr++; 1221 opli--; 1222 } 1223 break; 1224 1225 /* 1226 * FIXME those are the defined Options that lack a decoder 1227 * you are welcome to contribute code ;-) 1228 */ 1229 1230 case ESIS_OPTION_QOS_MAINTENANCE: 1231 case ESIS_OPTION_SECURITY: 1232 case ESIS_OPTION_PRIORITY: 1233 case ESIS_OPTION_ADDRESS_MASK: 1234 case ESIS_OPTION_SNPA_MASK: 1235 1236 default: 1237 print_unknown_data(tptr,"\n\t ",opli); 1238 break; 1239 } 1240 if (vflag > 1) 1241 print_unknown_data(pptr,"\n\t ",opli); 1242 pptr += opli; 1243 } 1244 trunc: 1245 return; 1246 } 1247 1248 /* shared routine for printing system, node and lsp-ids */ 1249 static char * 1250 isis_print_id(const u_int8_t *cp, int id_len) 1251 { 1252 int i; 1253 static char id[sizeof("xxxx.xxxx.xxxx.yy-zz")]; 1254 char *pos = id; 1255 1256 for (i = 1; i <= SYSTEM_ID_LEN; i++) { 1257 snprintf(pos, sizeof(id) - (pos - id), "%02x", *cp++); 1258 pos += strlen(pos); 1259 if (i == 2 || i == 4) 1260 *pos++ = '.'; 1261 } 1262 if (id_len >= NODE_ID_LEN) { 1263 snprintf(pos, sizeof(id) - (pos - id), ".%02x", *cp++); 1264 pos += strlen(pos); 1265 } 1266 if (id_len == LSP_ID_LEN) 1267 snprintf(pos, sizeof(id) - (pos - id), "-%02x", *cp); 1268 return (id); 1269 } 1270 1271 /* print the 4-byte metric block which is common found in the old-style TLVs */ 1272 static int 1273 isis_print_metric_block (const struct isis_metric_block *isis_metric_block) 1274 { 1275 printf(", Default Metric: %d, %s", 1276 ISIS_LSP_TLV_METRIC_VALUE(isis_metric_block->metric_default), 1277 ISIS_LSP_TLV_METRIC_IE(isis_metric_block->metric_default) ? "External" : "Internal"); 1278 if (!ISIS_LSP_TLV_METRIC_SUPPORTED(isis_metric_block->metric_delay)) 1279 printf("\n\t\t Delay Metric: %d, %s", 1280 ISIS_LSP_TLV_METRIC_VALUE(isis_metric_block->metric_delay), 1281 ISIS_LSP_TLV_METRIC_IE(isis_metric_block->metric_delay) ? "External" : "Internal"); 1282 if (!ISIS_LSP_TLV_METRIC_SUPPORTED(isis_metric_block->metric_expense)) 1283 printf("\n\t\t Expense Metric: %d, %s", 1284 ISIS_LSP_TLV_METRIC_VALUE(isis_metric_block->metric_expense), 1285 ISIS_LSP_TLV_METRIC_IE(isis_metric_block->metric_expense) ? "External" : "Internal"); 1286 if (!ISIS_LSP_TLV_METRIC_SUPPORTED(isis_metric_block->metric_error)) 1287 printf("\n\t\t Error Metric: %d, %s", 1288 ISIS_LSP_TLV_METRIC_VALUE(isis_metric_block->metric_error), 1289 ISIS_LSP_TLV_METRIC_IE(isis_metric_block->metric_error) ? "External" : "Internal"); 1290 1291 return(1); /* everything is ok */ 1292 } 1293 1294 static int 1295 isis_print_tlv_ip_reach (const u_int8_t *cp, const char *ident, int length) 1296 { 1297 int prefix_len; 1298 const struct isis_tlv_ip_reach *tlv_ip_reach; 1299 1300 tlv_ip_reach = (const struct isis_tlv_ip_reach *)cp; 1301 1302 while (length > 0) { 1303 if ((size_t)length < sizeof(*tlv_ip_reach)) { 1304 printf("short IPv4 Reachability (%d vs %lu)", 1305 length, 1306 (unsigned long)sizeof(*tlv_ip_reach)); 1307 return (0); 1308 } 1309 1310 if (!TTEST(*tlv_ip_reach)) 1311 return (0); 1312 1313 prefix_len = mask2plen(EXTRACT_32BITS(tlv_ip_reach->mask)); 1314 1315 if (prefix_len == -1) 1316 printf("%sIPv4 prefix: %s mask %s", 1317 ident, 1318 ipaddr_string((tlv_ip_reach->prefix)), 1319 ipaddr_string((tlv_ip_reach->mask))); 1320 else 1321 printf("%sIPv4 prefix: %15s/%u", 1322 ident, 1323 ipaddr_string((tlv_ip_reach->prefix)), 1324 prefix_len); 1325 1326 printf(", Distribution: %s, Metric: %u, %s", 1327 ISIS_LSP_TLV_METRIC_UPDOWN(tlv_ip_reach->isis_metric_block.metric_default) ? "down" : "up", 1328 ISIS_LSP_TLV_METRIC_VALUE(tlv_ip_reach->isis_metric_block.metric_default), 1329 ISIS_LSP_TLV_METRIC_IE(tlv_ip_reach->isis_metric_block.metric_default) ? "External" : "Internal"); 1330 1331 if (!ISIS_LSP_TLV_METRIC_SUPPORTED(tlv_ip_reach->isis_metric_block.metric_delay)) 1332 printf("%s Delay Metric: %u, %s", 1333 ident, 1334 ISIS_LSP_TLV_METRIC_VALUE(tlv_ip_reach->isis_metric_block.metric_delay), 1335 ISIS_LSP_TLV_METRIC_IE(tlv_ip_reach->isis_metric_block.metric_delay) ? "External" : "Internal"); 1336 1337 if (!ISIS_LSP_TLV_METRIC_SUPPORTED(tlv_ip_reach->isis_metric_block.metric_expense)) 1338 printf("%s Expense Metric: %u, %s", 1339 ident, 1340 ISIS_LSP_TLV_METRIC_VALUE(tlv_ip_reach->isis_metric_block.metric_expense), 1341 ISIS_LSP_TLV_METRIC_IE(tlv_ip_reach->isis_metric_block.metric_expense) ? "External" : "Internal"); 1342 1343 if (!ISIS_LSP_TLV_METRIC_SUPPORTED(tlv_ip_reach->isis_metric_block.metric_error)) 1344 printf("%s Error Metric: %u, %s", 1345 ident, 1346 ISIS_LSP_TLV_METRIC_VALUE(tlv_ip_reach->isis_metric_block.metric_error), 1347 ISIS_LSP_TLV_METRIC_IE(tlv_ip_reach->isis_metric_block.metric_error) ? "External" : "Internal"); 1348 1349 length -= sizeof(struct isis_tlv_ip_reach); 1350 tlv_ip_reach++; 1351 } 1352 return (1); 1353 } 1354 1355 /* 1356 * this is the common IP-REACH subTLV decoder it is called 1357 * from various EXTD-IP REACH TLVs (135,235,236,237) 1358 */ 1359 1360 static int 1361 isis_print_ip_reach_subtlv (const u_int8_t *tptr,int subt,int subl,const char *ident) { 1362 1363 /* first lets see if we know the subTLVs name*/ 1364 printf("%s%s subTLV #%u, length: %u", 1365 ident, 1366 tok2str(isis_ext_ip_reach_subtlv_values, 1367 "unknown", 1368 subt), 1369 subt, 1370 subl); 1371 1372 if (!TTEST2(*tptr,subl)) 1373 goto trunctlv; 1374 1375 switch(subt) { 1376 case ISIS_SUBTLV_EXTD_IP_REACH_MGMT_PREFIX_COLOR: /* fall through */ 1377 case ISIS_SUBTLV_EXTD_IP_REACH_ADMIN_TAG32: 1378 while (subl >= 4) { 1379 printf(", 0x%08x (=%u)", 1380 EXTRACT_32BITS(tptr), 1381 EXTRACT_32BITS(tptr)); 1382 tptr+=4; 1383 subl-=4; 1384 } 1385 break; 1386 case ISIS_SUBTLV_EXTD_IP_REACH_ADMIN_TAG64: 1387 while (subl >= 8) { 1388 printf(", 0x%08x%08x", 1389 EXTRACT_32BITS(tptr), 1390 EXTRACT_32BITS(tptr+4)); 1391 tptr+=8; 1392 subl-=8; 1393 } 1394 break; 1395 default: 1396 if(!print_unknown_data(tptr,"\n\t\t ", 1397 subl)) 1398 return(0); 1399 break; 1400 } 1401 return(1); 1402 1403 trunctlv: 1404 printf("%spacket exceeded snapshot",ident); 1405 return(0); 1406 } 1407 1408 /* 1409 * this is the common IS-REACH subTLV decoder it is called 1410 * from isis_print_ext_is_reach() 1411 */ 1412 1413 static int 1414 isis_print_is_reach_subtlv (const u_int8_t *tptr,u_int subt,u_int subl,const char *ident) { 1415 1416 u_int te_class,priority_level; 1417 union { /* int to float conversion buffer for several subTLVs */ 1418 float f; 1419 u_int32_t i; 1420 } bw; 1421 1422 /* first lets see if we know the subTLVs name*/ 1423 printf("%s%s subTLV #%u, length: %u", 1424 ident, 1425 tok2str(isis_ext_is_reach_subtlv_values, 1426 "unknown", 1427 subt), 1428 subt, 1429 subl); 1430 1431 if (!TTEST2(*tptr,subl)) 1432 goto trunctlv; 1433 1434 switch(subt) { 1435 case ISIS_SUBTLV_EXT_IS_REACH_ADMIN_GROUP: 1436 case ISIS_SUBTLV_EXT_IS_REACH_LINK_LOCAL_REMOTE_ID: 1437 case ISIS_SUBTLV_EXT_IS_REACH_LINK_REMOTE_ID: 1438 if (subl >= 4) { 1439 printf(", 0x%08x", EXTRACT_32BITS(tptr)); 1440 if (subl == 8) /* draft-ietf-isis-gmpls-extensions */ 1441 printf(", 0x%08x", EXTRACT_32BITS(tptr+4)); 1442 } 1443 break; 1444 case ISIS_SUBTLV_EXT_IS_REACH_IPV4_INTF_ADDR: 1445 case ISIS_SUBTLV_EXT_IS_REACH_IPV4_NEIGHBOR_ADDR: 1446 if (subl >= sizeof(struct in_addr)) 1447 printf(", %s", ipaddr_string(tptr)); 1448 break; 1449 case ISIS_SUBTLV_EXT_IS_REACH_MAX_LINK_BW : 1450 case ISIS_SUBTLV_EXT_IS_REACH_RESERVABLE_BW: 1451 if (subl >= 4) { 1452 bw.i = EXTRACT_32BITS(tptr); 1453 printf(", %.3f Mbps", bw.f*8/1000000 ); 1454 } 1455 break; 1456 case ISIS_SUBTLV_EXT_IS_REACH_UNRESERVED_BW : 1457 if (subl >= 32) { 1458 for (te_class = 0; te_class < 8; te_class++) { 1459 bw.i = EXTRACT_32BITS(tptr); 1460 printf("%s TE-Class %u: %.3f Mbps", 1461 ident, 1462 te_class, 1463 bw.f*8/1000000 ); 1464 tptr+=4; 1465 } 1466 } 1467 break; 1468 case ISIS_SUBTLV_EXT_IS_REACH_BW_CONSTRAINTS: /* fall through */ 1469 case ISIS_SUBTLV_EXT_IS_REACH_BW_CONSTRAINTS_OLD: 1470 printf("%sBandwidth Constraints Model ID: %s (%u)", 1471 ident, 1472 tok2str(diffserv_te_bc_values, "unknown", *tptr), 1473 *tptr); 1474 tptr++; 1475 /* decode BCs until the subTLV ends */ 1476 for (te_class = 0; te_class < (subl-1)/4; te_class++) { 1477 bw.i = EXTRACT_32BITS(tptr); 1478 printf("%s Bandwidth constraint CT%u: %.3f Mbps", 1479 ident, 1480 te_class, 1481 bw.f*8/1000000 ); 1482 tptr+=4; 1483 } 1484 break; 1485 case ISIS_SUBTLV_EXT_IS_REACH_TE_METRIC: 1486 if (subl >= 3) 1487 printf(", %u", EXTRACT_24BITS(tptr)); 1488 break; 1489 case ISIS_SUBTLV_EXT_IS_REACH_LINK_PROTECTION_TYPE: 1490 if (subl >= 2) { 1491 printf(", %s, Priority %u", 1492 bittok2str(gmpls_link_prot_values, "none", *tptr), 1493 *(tptr+1)); 1494 } 1495 break; 1496 case ISIS_SUBTLV_EXT_IS_REACH_INTF_SW_CAP_DESCR: 1497 if (subl >= 36) { 1498 printf("%s Interface Switching Capability:%s", 1499 ident, 1500 tok2str(gmpls_switch_cap_values, "Unknown", *(tptr))); 1501 printf(", LSP Encoding: %s", 1502 tok2str(gmpls_encoding_values, "Unknown", *(tptr+1))); 1503 tptr+=4; 1504 printf("%s Max LSP Bandwidth:",ident); 1505 for (priority_level = 0; priority_level < 8; priority_level++) { 1506 bw.i = EXTRACT_32BITS(tptr); 1507 printf("%s priority level %d: %.3f Mbps", 1508 ident, 1509 priority_level, 1510 bw.f*8/1000000 ); 1511 tptr+=4; 1512 } 1513 subl-=36; 1514 /* there is some optional stuff left to decode but this is as of yet 1515 not specified so just lets hexdump what is left */ 1516 if(subl>0){ 1517 if(!print_unknown_data(tptr,"\n\t\t ", 1518 subl)) 1519 return(0); 1520 } 1521 } 1522 break; 1523 default: 1524 if(!print_unknown_data(tptr,"\n\t\t ", 1525 subl)) 1526 return(0); 1527 break; 1528 } 1529 return(1); 1530 1531 trunctlv: 1532 printf("%spacket exceeded snapshot",ident); 1533 return(0); 1534 } 1535 1536 1537 /* 1538 * this is the common IS-REACH decoder it is called 1539 * from various EXTD-IS REACH style TLVs (22,24,222) 1540 */ 1541 1542 static int 1543 isis_print_ext_is_reach (const u_int8_t *tptr,const char *ident, int tlv_type) { 1544 1545 char ident_buffer[20]; 1546 int subtlv_type,subtlv_len,subtlv_sum_len; 1547 int proc_bytes = 0; /* how many bytes did we process ? */ 1548 1549 if (!TTEST2(*tptr, NODE_ID_LEN)) 1550 return(0); 1551 1552 printf("%sIS Neighbor: %s", ident, isis_print_id(tptr, NODE_ID_LEN)); 1553 tptr+=(NODE_ID_LEN); 1554 1555 if (tlv_type != ISIS_TLV_IS_ALIAS_ID) { /* the Alias TLV Metric field is implicit 0 */ 1556 if (!TTEST2(*tptr, 3)) /* and is therefore skipped */ 1557 return(0); 1558 printf(", Metric: %d",EXTRACT_24BITS(tptr)); 1559 tptr+=3; 1560 } 1561 1562 if (!TTEST2(*tptr, 1)) 1563 return(0); 1564 subtlv_sum_len=*(tptr++); /* read out subTLV length */ 1565 proc_bytes=NODE_ID_LEN+3+1; 1566 printf(", %ssub-TLVs present",subtlv_sum_len ? "" : "no "); 1567 if (subtlv_sum_len) { 1568 printf(" (%u)",subtlv_sum_len); 1569 while (subtlv_sum_len>0) { 1570 if (!TTEST2(*tptr,2)) 1571 return(0); 1572 subtlv_type=*(tptr++); 1573 subtlv_len=*(tptr++); 1574 /* prepend the ident string */ 1575 snprintf(ident_buffer, sizeof(ident_buffer), "%s ",ident); 1576 if(!isis_print_is_reach_subtlv(tptr,subtlv_type,subtlv_len,ident_buffer)) 1577 return(0); 1578 tptr+=subtlv_len; 1579 subtlv_sum_len-=(subtlv_len+2); 1580 proc_bytes+=(subtlv_len+2); 1581 } 1582 } 1583 return(proc_bytes); 1584 } 1585 1586 /* 1587 * this is the common Multi Topology ID decoder 1588 * it is called from various MT-TLVs (222,229,235,237) 1589 */ 1590 1591 static int 1592 isis_print_mtid (const u_int8_t *tptr,const char *ident) { 1593 1594 if (!TTEST2(*tptr, 2)) 1595 return(0); 1596 1597 printf("%s%s", 1598 ident, 1599 tok2str(isis_mt_values, 1600 "Reserved for IETF Consensus", 1601 ISIS_MASK_MTID(EXTRACT_16BITS(tptr)))); 1602 1603 printf(" Topology (0x%03x), Flags: [%s]", 1604 ISIS_MASK_MTID(EXTRACT_16BITS(tptr)), 1605 bittok2str(isis_mt_flag_values, "none",ISIS_MASK_MTFLAGS(EXTRACT_16BITS(tptr)))); 1606 1607 return(2); 1608 } 1609 1610 /* 1611 * this is the common extended IP reach decoder 1612 * it is called from TLVs (135,235,236,237) 1613 * we process the TLV and optional subTLVs and return 1614 * the amount of processed bytes 1615 */ 1616 1617 static int 1618 isis_print_extd_ip_reach (const u_int8_t *tptr, const char *ident, u_int16_t afi) { 1619 1620 char ident_buffer[20]; 1621 u_int8_t prefix[sizeof(struct in6_addr)]; /* shared copy buffer for IPv4 and IPv6 prefixes */ 1622 u_int metric, status_byte, bit_length, byte_length, sublen, processed, subtlvtype, subtlvlen; 1623 1624 if (!TTEST2(*tptr, 4)) 1625 return (0); 1626 metric = EXTRACT_32BITS(tptr); 1627 processed=4; 1628 tptr+=4; 1629 1630 if (afi == IPV4) { 1631 if (!TTEST2(*tptr, 1)) /* fetch status byte */ 1632 return (0); 1633 status_byte=*(tptr++); 1634 bit_length = status_byte&0x3f; 1635 processed++; 1636 #ifdef INET6 1637 } else if (afi == IPV6) { 1638 if (!TTEST2(*tptr, 1)) /* fetch status & prefix_len byte */ 1639 return (0); 1640 status_byte=*(tptr++); 1641 bit_length=*(tptr++); 1642 processed+=2; 1643 #endif 1644 } else 1645 return (0); /* somebody is fooling us */ 1646 1647 byte_length = (bit_length + 7) / 8; /* prefix has variable length encoding */ 1648 1649 if (!TTEST2(*tptr, byte_length)) 1650 return (0); 1651 memset(prefix, 0, sizeof(struct in6_addr)); /* clear the copy buffer */ 1652 memcpy(prefix,tptr,byte_length); /* copy as much as is stored in the TLV */ 1653 tptr+=byte_length; 1654 processed+=byte_length; 1655 1656 if (afi == IPV4) 1657 printf("%sIPv4 prefix: %15s/%u", 1658 ident, 1659 ipaddr_string(prefix), 1660 bit_length); 1661 #ifdef INET6 1662 if (afi == IPV6) 1663 printf("%sIPv6 prefix: %s/%u", 1664 ident, 1665 ip6addr_string(prefix), 1666 bit_length); 1667 #endif 1668 1669 printf(", Distribution: %s, Metric: %u", 1670 ISIS_MASK_TLV_EXTD_IP_UPDOWN(status_byte) ? "down" : "up", 1671 metric); 1672 1673 if (afi == IPV4 && ISIS_MASK_TLV_EXTD_IP_SUBTLV(status_byte)) 1674 printf(", sub-TLVs present"); 1675 #ifdef INET6 1676 if (afi == IPV6) 1677 printf(", %s%s", 1678 ISIS_MASK_TLV_EXTD_IP6_IE(status_byte) ? "External" : "Internal", 1679 ISIS_MASK_TLV_EXTD_IP6_SUBTLV(status_byte) ? ", sub-TLVs present" : ""); 1680 #endif 1681 1682 if ((ISIS_MASK_TLV_EXTD_IP_SUBTLV(status_byte) && afi == IPV4) || 1683 (ISIS_MASK_TLV_EXTD_IP6_SUBTLV(status_byte) && afi == IPV6)) { 1684 /* assume that one prefix can hold more 1685 than one subTLV - therefore the first byte must reflect 1686 the aggregate bytecount of the subTLVs for this prefix 1687 */ 1688 if (!TTEST2(*tptr, 1)) 1689 return (0); 1690 sublen=*(tptr++); 1691 processed+=sublen+1; 1692 printf(" (%u)",sublen); /* print out subTLV length */ 1693 1694 while (sublen>0) { 1695 if (!TTEST2(*tptr,2)) 1696 return (0); 1697 subtlvtype=*(tptr++); 1698 subtlvlen=*(tptr++); 1699 /* prepend the ident string */ 1700 snprintf(ident_buffer, sizeof(ident_buffer), "%s ",ident); 1701 if(!isis_print_ip_reach_subtlv(tptr,subtlvtype,subtlvlen,ident_buffer)) 1702 return(0); 1703 tptr+=subtlvlen; 1704 sublen-=(subtlvlen+2); 1705 } 1706 } 1707 return (processed); 1708 } 1709 1710 /* 1711 * isis_print 1712 * Decode IS-IS packets. Return 0 on error. 1713 */ 1714 1715 static int isis_print (const u_int8_t *p, u_int length) 1716 { 1717 const struct isis_common_header *isis_header; 1718 1719 const struct isis_iih_lan_header *header_iih_lan; 1720 const struct isis_iih_ptp_header *header_iih_ptp; 1721 const struct isis_lsp_header *header_lsp; 1722 const struct isis_csnp_header *header_csnp; 1723 const struct isis_psnp_header *header_psnp; 1724 1725 const struct isis_tlv_lsp *tlv_lsp; 1726 const struct isis_tlv_ptp_adj *tlv_ptp_adj; 1727 const struct isis_tlv_is_reach *tlv_is_reach; 1728 const struct isis_tlv_es_reach *tlv_es_reach; 1729 1730 u_int8_t pdu_type, max_area, id_length, tlv_type, tlv_len, tmp, alen, lan_alen, prefix_len; 1731 u_int8_t ext_is_len, ext_ip_len, mt_len; 1732 const u_int8_t *optr, *pptr, *tptr; 1733 u_short packet_len,pdu_len; 1734 u_int i,vendor_id; 1735 1736 packet_len=length; 1737 optr = p; /* initialize the _o_riginal pointer to the packet start - 1738 need it for parsing the checksum TLV */ 1739 isis_header = (const struct isis_common_header *)p; 1740 TCHECK(*isis_header); 1741 pptr = p+(ISIS_COMMON_HEADER_SIZE); 1742 header_iih_lan = (const struct isis_iih_lan_header *)pptr; 1743 header_iih_ptp = (const struct isis_iih_ptp_header *)pptr; 1744 header_lsp = (const struct isis_lsp_header *)pptr; 1745 header_csnp = (const struct isis_csnp_header *)pptr; 1746 header_psnp = (const struct isis_psnp_header *)pptr; 1747 1748 if (!eflag) 1749 printf("IS-IS"); 1750 1751 /* 1752 * Sanity checking of the header. 1753 */ 1754 1755 if (isis_header->version != ISIS_VERSION) { 1756 printf("version %d packet not supported", isis_header->version); 1757 return (0); 1758 } 1759 1760 if ((isis_header->id_length != SYSTEM_ID_LEN) && (isis_header->id_length != 0)) { 1761 printf("system ID length of %d is not supported", 1762 isis_header->id_length); 1763 return (0); 1764 } 1765 1766 if (isis_header->pdu_version != ISIS_VERSION) { 1767 printf("version %d packet not supported", isis_header->pdu_version); 1768 return (0); 1769 } 1770 1771 max_area = isis_header->max_area; 1772 switch(max_area) { 1773 case 0: 1774 max_area = 3; /* silly shit */ 1775 break; 1776 case 255: 1777 printf("bad packet -- 255 areas"); 1778 return (0); 1779 default: 1780 break; 1781 } 1782 1783 id_length = isis_header->id_length; 1784 switch(id_length) { 1785 case 0: 1786 id_length = 6; /* silly shit again */ 1787 break; 1788 case 1: /* 1-8 are valid sys-ID lenghts */ 1789 case 2: 1790 case 3: 1791 case 4: 1792 case 5: 1793 case 6: 1794 case 7: 1795 case 8: 1796 break; 1797 case 255: 1798 id_length = 0; /* entirely useless */ 1799 break; 1800 default: 1801 break; 1802 } 1803 1804 /* toss any non 6-byte sys-ID len PDUs */ 1805 if (id_length != 6 ) { 1806 printf("bad packet -- illegal sys-ID length (%u)", id_length); 1807 return (0); 1808 } 1809 1810 pdu_type=isis_header->pdu_type; 1811 1812 /* in non-verbose mode print the basic PDU Type plus PDU specific brief information*/ 1813 if (vflag < 1) { 1814 printf("%s%s", 1815 eflag ? "" : ", ", 1816 tok2str(isis_pdu_values,"unknown PDU-Type %u",pdu_type)); 1817 1818 switch (pdu_type) { 1819 1820 case ISIS_PDU_L1_LAN_IIH: 1821 case ISIS_PDU_L2_LAN_IIH: 1822 printf(", src-id %s", 1823 isis_print_id(header_iih_lan->source_id,SYSTEM_ID_LEN)); 1824 printf(", lan-id %s, prio %u", 1825 isis_print_id(header_iih_lan->lan_id,NODE_ID_LEN), 1826 header_iih_lan->priority); 1827 break; 1828 case ISIS_PDU_PTP_IIH: 1829 printf(", src-id %s", isis_print_id(header_iih_ptp->source_id,SYSTEM_ID_LEN)); 1830 break; 1831 case ISIS_PDU_L1_LSP: 1832 case ISIS_PDU_L2_LSP: 1833 printf(", lsp-id %s, seq 0x%08x, lifetime %5us", 1834 isis_print_id(header_lsp->lsp_id, LSP_ID_LEN), 1835 EXTRACT_32BITS(header_lsp->sequence_number), 1836 EXTRACT_16BITS(header_lsp->remaining_lifetime)); 1837 break; 1838 case ISIS_PDU_L1_CSNP: 1839 case ISIS_PDU_L2_CSNP: 1840 printf(", src-id %s", isis_print_id(header_csnp->source_id,NODE_ID_LEN)); 1841 break; 1842 case ISIS_PDU_L1_PSNP: 1843 case ISIS_PDU_L2_PSNP: 1844 printf(", src-id %s", isis_print_id(header_psnp->source_id,NODE_ID_LEN)); 1845 break; 1846 1847 } 1848 printf(", length %u", length); 1849 1850 return(1); 1851 } 1852 1853 /* ok they seem to want to know everything - lets fully decode it */ 1854 printf("%slength %u", eflag ? "" : ", ",length); 1855 1856 printf("\n\t%s, hlen: %u, v: %u, pdu-v: %u, sys-id-len: %u (%u), max-area: %u (%u)", 1857 tok2str(isis_pdu_values, 1858 "unknown, type %u", 1859 pdu_type), 1860 isis_header->fixed_len, 1861 isis_header->version, 1862 isis_header->pdu_version, 1863 id_length, 1864 isis_header->id_length, 1865 max_area, 1866 isis_header->max_area); 1867 1868 if (vflag > 1) { 1869 if(!print_unknown_data(optr,"\n\t",8)) /* provide the _o_riginal pointer */ 1870 return(0); /* for optionally debugging the common header */ 1871 } 1872 1873 switch (pdu_type) { 1874 1875 case ISIS_PDU_L1_LAN_IIH: 1876 case ISIS_PDU_L2_LAN_IIH: 1877 if (isis_header->fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_LAN_HEADER_SIZE)) { 1878 printf(", bogus fixed header length %u should be %lu", 1879 isis_header->fixed_len, (unsigned long)ISIS_IIH_LAN_HEADER_SIZE); 1880 return (0); 1881 } 1882 1883 pdu_len=EXTRACT_16BITS(header_iih_lan->pdu_len); 1884 if (packet_len>pdu_len) { 1885 packet_len=pdu_len; /* do TLV decoding as long as it makes sense */ 1886 length=pdu_len; 1887 } 1888 1889 TCHECK(*header_iih_lan); 1890 printf("\n\t source-id: %s, holding time: %us, Flags: [%s]", 1891 isis_print_id(header_iih_lan->source_id,SYSTEM_ID_LEN), 1892 EXTRACT_16BITS(header_iih_lan->holding_time), 1893 tok2str(isis_iih_circuit_type_values, 1894 "unknown circuit type 0x%02x", 1895 header_iih_lan->circuit_type)); 1896 1897 printf("\n\t lan-id: %s, Priority: %u, PDU length: %u", 1898 isis_print_id(header_iih_lan->lan_id, NODE_ID_LEN), 1899 (header_iih_lan->priority) & ISIS_LAN_PRIORITY_MASK, 1900 pdu_len); 1901 1902 if (vflag > 1) { 1903 if(!print_unknown_data(pptr,"\n\t ",ISIS_IIH_LAN_HEADER_SIZE)) 1904 return(0); 1905 } 1906 1907 packet_len -= (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_LAN_HEADER_SIZE); 1908 pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_LAN_HEADER_SIZE); 1909 break; 1910 1911 case ISIS_PDU_PTP_IIH: 1912 if (isis_header->fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_PTP_HEADER_SIZE)) { 1913 printf(", bogus fixed header length %u should be %lu", 1914 isis_header->fixed_len, (unsigned long)ISIS_IIH_PTP_HEADER_SIZE); 1915 return (0); 1916 } 1917 1918 pdu_len=EXTRACT_16BITS(header_iih_ptp->pdu_len); 1919 if (packet_len>pdu_len) { 1920 packet_len=pdu_len; /* do TLV decoding as long as it makes sense */ 1921 length=pdu_len; 1922 } 1923 1924 TCHECK(*header_iih_ptp); 1925 printf("\n\t source-id: %s, holding time: %us, Flags: [%s]", 1926 isis_print_id(header_iih_ptp->source_id,SYSTEM_ID_LEN), 1927 EXTRACT_16BITS(header_iih_ptp->holding_time), 1928 tok2str(isis_iih_circuit_type_values, 1929 "unknown circuit type 0x%02x", 1930 header_iih_ptp->circuit_type)); 1931 1932 printf("\n\t circuit-id: 0x%02x, PDU length: %u", 1933 header_iih_ptp->circuit_id, 1934 pdu_len); 1935 1936 if (vflag > 1) { 1937 if(!print_unknown_data(pptr,"\n\t ",ISIS_IIH_PTP_HEADER_SIZE)) 1938 return(0); 1939 } 1940 1941 packet_len -= (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_PTP_HEADER_SIZE); 1942 pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_PTP_HEADER_SIZE); 1943 break; 1944 1945 case ISIS_PDU_L1_LSP: 1946 case ISIS_PDU_L2_LSP: 1947 if (isis_header->fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_LSP_HEADER_SIZE)) { 1948 printf(", bogus fixed header length %u should be %lu", 1949 isis_header->fixed_len, (unsigned long)ISIS_LSP_HEADER_SIZE); 1950 return (0); 1951 } 1952 1953 pdu_len=EXTRACT_16BITS(header_lsp->pdu_len); 1954 if (packet_len>pdu_len) { 1955 packet_len=pdu_len; /* do TLV decoding as long as it makes sense */ 1956 length=pdu_len; 1957 } 1958 1959 TCHECK(*header_lsp); 1960 printf("\n\t lsp-id: %s, seq: 0x%08x, lifetime: %5us\n\t chksum: 0x%04x", 1961 isis_print_id(header_lsp->lsp_id, LSP_ID_LEN), 1962 EXTRACT_32BITS(header_lsp->sequence_number), 1963 EXTRACT_16BITS(header_lsp->remaining_lifetime), 1964 EXTRACT_16BITS(header_lsp->checksum)); 1965 1966 /* if this is a purge do not attempt to verify the checksum */ 1967 if ( EXTRACT_16BITS(header_lsp->remaining_lifetime) == 0 && 1968 EXTRACT_16BITS(header_lsp->checksum) == 0) 1969 printf(" (purged)"); 1970 else 1971 /* verify the checksum - 1972 * checking starts at the lsp-id field at byte position [12] 1973 * hence the length needs to be reduced by 12 bytes */ 1974 printf(" (%s)", (osi_cksum((u_int8_t *)header_lsp->lsp_id, length-12)) ? "incorrect" : "correct"); 1975 1976 printf(", PDU length: %u, Flags: [ %s", 1977 pdu_len, 1978 ISIS_MASK_LSP_OL_BIT(header_lsp->typeblock) ? "Overload bit set, " : ""); 1979 1980 if (ISIS_MASK_LSP_ATT_BITS(header_lsp->typeblock)) { 1981 printf("%s", ISIS_MASK_LSP_ATT_DEFAULT_BIT(header_lsp->typeblock) ? "default " : ""); 1982 printf("%s", ISIS_MASK_LSP_ATT_DELAY_BIT(header_lsp->typeblock) ? "delay " : ""); 1983 printf("%s", ISIS_MASK_LSP_ATT_EXPENSE_BIT(header_lsp->typeblock) ? "expense " : ""); 1984 printf("%s", ISIS_MASK_LSP_ATT_ERROR_BIT(header_lsp->typeblock) ? "error " : ""); 1985 printf("ATT bit set, "); 1986 } 1987 printf("%s", ISIS_MASK_LSP_PARTITION_BIT(header_lsp->typeblock) ? "P bit set, " : ""); 1988 printf("%s ]", tok2str(isis_lsp_istype_values,"Unknown(0x%x)",ISIS_MASK_LSP_ISTYPE_BITS(header_lsp->typeblock))); 1989 1990 if (vflag > 1) { 1991 if(!print_unknown_data(pptr,"\n\t ",ISIS_LSP_HEADER_SIZE)) 1992 return(0); 1993 } 1994 1995 packet_len -= (ISIS_COMMON_HEADER_SIZE+ISIS_LSP_HEADER_SIZE); 1996 pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_LSP_HEADER_SIZE); 1997 break; 1998 1999 case ISIS_PDU_L1_CSNP: 2000 case ISIS_PDU_L2_CSNP: 2001 if (isis_header->fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_CSNP_HEADER_SIZE)) { 2002 printf(", bogus fixed header length %u should be %lu", 2003 isis_header->fixed_len, (unsigned long)ISIS_CSNP_HEADER_SIZE); 2004 return (0); 2005 } 2006 2007 pdu_len=EXTRACT_16BITS(header_csnp->pdu_len); 2008 if (packet_len>pdu_len) { 2009 packet_len=pdu_len; /* do TLV decoding as long as it makes sense */ 2010 length=pdu_len; 2011 } 2012 2013 TCHECK(*header_csnp); 2014 printf("\n\t source-id: %s, PDU length: %u", 2015 isis_print_id(header_csnp->source_id, NODE_ID_LEN), 2016 pdu_len); 2017 printf("\n\t start lsp-id: %s", 2018 isis_print_id(header_csnp->start_lsp_id, LSP_ID_LEN)); 2019 printf("\n\t end lsp-id: %s", 2020 isis_print_id(header_csnp->end_lsp_id, LSP_ID_LEN)); 2021 2022 if (vflag > 1) { 2023 if(!print_unknown_data(pptr,"\n\t ",ISIS_CSNP_HEADER_SIZE)) 2024 return(0); 2025 } 2026 2027 packet_len -= (ISIS_COMMON_HEADER_SIZE+ISIS_CSNP_HEADER_SIZE); 2028 pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_CSNP_HEADER_SIZE); 2029 break; 2030 2031 case ISIS_PDU_L1_PSNP: 2032 case ISIS_PDU_L2_PSNP: 2033 if (isis_header->fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_PSNP_HEADER_SIZE)) { 2034 printf("- bogus fixed header length %u should be %lu", 2035 isis_header->fixed_len, (unsigned long)ISIS_PSNP_HEADER_SIZE); 2036 return (0); 2037 } 2038 2039 pdu_len=EXTRACT_16BITS(header_psnp->pdu_len); 2040 if (packet_len>pdu_len) { 2041 packet_len=pdu_len; /* do TLV decoding as long as it makes sense */ 2042 length=pdu_len; 2043 } 2044 2045 TCHECK(*header_psnp); 2046 printf("\n\t source-id: %s, PDU length: %u", 2047 isis_print_id(header_psnp->source_id, NODE_ID_LEN), 2048 pdu_len); 2049 2050 if (vflag > 1) { 2051 if(!print_unknown_data(pptr,"\n\t ",ISIS_PSNP_HEADER_SIZE)) 2052 return(0); 2053 } 2054 2055 packet_len -= (ISIS_COMMON_HEADER_SIZE+ISIS_PSNP_HEADER_SIZE); 2056 pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_PSNP_HEADER_SIZE); 2057 break; 2058 2059 default: 2060 if(!print_unknown_data(pptr,"\n\t ",length)) 2061 return(0); 2062 return (0); 2063 } 2064 2065 /* 2066 * Now print the TLV's. 2067 */ 2068 2069 while (packet_len >= 2) { 2070 if (pptr == snapend) { 2071 return (1); 2072 } 2073 2074 if (!TTEST2(*pptr, 2)) { 2075 printf("\n\t\t packet exceeded snapshot (%ld) bytes", 2076 (long)(pptr-snapend)); 2077 return (1); 2078 } 2079 tlv_type = *pptr++; 2080 tlv_len = *pptr++; 2081 tmp =tlv_len; /* copy temporary len & pointer to packet data */ 2082 tptr = pptr; 2083 packet_len -= 2; 2084 if (tlv_len > packet_len) { 2085 break; 2086 } 2087 2088 /* first lets see if we know the TLVs name*/ 2089 printf("\n\t %s TLV #%u, length: %u", 2090 tok2str(isis_tlv_values, 2091 "unknown", 2092 tlv_type), 2093 tlv_type, 2094 tlv_len); 2095 2096 if (tlv_len == 0) /* something is malformed */ 2097 break; 2098 2099 /* now check if we have a decoder otherwise do a hexdump at the end*/ 2100 switch (tlv_type) { 2101 case ISIS_TLV_AREA_ADDR: 2102 if (!TTEST2(*tptr, 1)) 2103 goto trunctlv; 2104 alen = *tptr++; 2105 while (tmp && alen < tmp) { 2106 printf("\n\t Area address (length: %u): %s", 2107 alen, 2108 isonsap_string(tptr,alen)); 2109 tptr += alen; 2110 tmp -= alen + 1; 2111 if (tmp==0) /* if this is the last area address do not attemt a boundary check */ 2112 break; 2113 if (!TTEST2(*tptr, 1)) 2114 goto trunctlv; 2115 alen = *tptr++; 2116 } 2117 break; 2118 case ISIS_TLV_ISNEIGH: 2119 while (tmp >= ETHER_ADDR_LEN) { 2120 if (!TTEST2(*tptr, ETHER_ADDR_LEN)) 2121 goto trunctlv; 2122 printf("\n\t SNPA: %s",isis_print_id(tptr,ETHER_ADDR_LEN)); 2123 tmp -= ETHER_ADDR_LEN; 2124 tptr += ETHER_ADDR_LEN; 2125 } 2126 break; 2127 2128 case ISIS_TLV_ISNEIGH_VARLEN: 2129 if (!TTEST2(*tptr, 1) || tmp < 3) /* min. TLV length */ 2130 goto trunctlv; 2131 lan_alen = *tptr++; /* LAN address length */ 2132 if (lan_alen == 0) { 2133 printf("\n\t LAN address length 0 bytes (invalid)"); 2134 break; 2135 } 2136 tmp --; 2137 printf("\n\t LAN address length %u bytes ",lan_alen); 2138 while (tmp >= lan_alen) { 2139 if (!TTEST2(*tptr, lan_alen)) 2140 goto trunctlv; 2141 printf("\n\t\tIS Neighbor: %s",isis_print_id(tptr,lan_alen)); 2142 tmp -= lan_alen; 2143 tptr +=lan_alen; 2144 } 2145 break; 2146 2147 case ISIS_TLV_PADDING: 2148 break; 2149 2150 case ISIS_TLV_MT_IS_REACH: 2151 while (tmp >= 2+NODE_ID_LEN+3+1) { 2152 mt_len = isis_print_mtid(tptr, "\n\t "); 2153 if (mt_len == 0) /* did something go wrong ? */ 2154 goto trunctlv; 2155 tptr+=mt_len; 2156 tmp-=mt_len; 2157 2158 ext_is_len = isis_print_ext_is_reach(tptr,"\n\t ",tlv_type); 2159 if (ext_is_len == 0) /* did something go wrong ? */ 2160 goto trunctlv; 2161 2162 tmp-=ext_is_len; 2163 tptr+=ext_is_len; 2164 } 2165 break; 2166 2167 case ISIS_TLV_IS_ALIAS_ID: 2168 while (tmp >= NODE_ID_LEN+1) { /* is it worth attempting a decode ? */ 2169 ext_is_len = isis_print_ext_is_reach(tptr,"\n\t ",tlv_type); 2170 if (ext_is_len == 0) /* did something go wrong ? */ 2171 goto trunctlv; 2172 tmp-=ext_is_len; 2173 tptr+=ext_is_len; 2174 } 2175 break; 2176 2177 case ISIS_TLV_EXT_IS_REACH: 2178 while (tmp >= NODE_ID_LEN+3+1) { /* is it worth attempting a decode ? */ 2179 ext_is_len = isis_print_ext_is_reach(tptr,"\n\t ",tlv_type); 2180 if (ext_is_len == 0) /* did something go wrong ? */ 2181 goto trunctlv; 2182 tmp-=ext_is_len; 2183 tptr+=ext_is_len; 2184 } 2185 break; 2186 case ISIS_TLV_IS_REACH: 2187 if (!TTEST2(*tptr,1)) /* check if there is one byte left to read out the virtual flag */ 2188 goto trunctlv; 2189 printf("\n\t %s", 2190 tok2str(isis_is_reach_virtual_values, 2191 "bogus virtual flag 0x%02x", 2192 *tptr++)); 2193 tlv_is_reach = (const struct isis_tlv_is_reach *)tptr; 2194 while (tmp >= sizeof(struct isis_tlv_is_reach)) { 2195 if (!TTEST(*tlv_is_reach)) 2196 goto trunctlv; 2197 printf("\n\t IS Neighbor: %s", 2198 isis_print_id(tlv_is_reach->neighbor_nodeid, NODE_ID_LEN)); 2199 isis_print_metric_block(&tlv_is_reach->isis_metric_block); 2200 tmp -= sizeof(struct isis_tlv_is_reach); 2201 tlv_is_reach++; 2202 } 2203 break; 2204 2205 case ISIS_TLV_ESNEIGH: 2206 tlv_es_reach = (const struct isis_tlv_es_reach *)tptr; 2207 while (tmp >= sizeof(struct isis_tlv_es_reach)) { 2208 if (!TTEST(*tlv_es_reach)) 2209 goto trunctlv; 2210 printf("\n\t ES Neighbor: %s", 2211 isis_print_id(tlv_es_reach->neighbor_sysid,SYSTEM_ID_LEN)); 2212 isis_print_metric_block(&tlv_es_reach->isis_metric_block); 2213 tmp -= sizeof(struct isis_tlv_es_reach); 2214 tlv_es_reach++; 2215 } 2216 break; 2217 2218 /* those two TLVs share the same format */ 2219 case ISIS_TLV_INT_IP_REACH: 2220 case ISIS_TLV_EXT_IP_REACH: 2221 if (!isis_print_tlv_ip_reach(pptr, "\n\t ", tlv_len)) 2222 return (1); 2223 break; 2224 2225 case ISIS_TLV_EXTD_IP_REACH: 2226 while (tmp>0) { 2227 ext_ip_len = isis_print_extd_ip_reach(tptr, "\n\t ", IPV4); 2228 if (ext_ip_len == 0) /* did something go wrong ? */ 2229 goto trunctlv; 2230 tptr+=ext_ip_len; 2231 tmp-=ext_ip_len; 2232 } 2233 break; 2234 2235 case ISIS_TLV_MT_IP_REACH: 2236 while (tmp>0) { 2237 mt_len = isis_print_mtid(tptr, "\n\t "); 2238 if (mt_len == 0) /* did something go wrong ? */ 2239 goto trunctlv; 2240 tptr+=mt_len; 2241 tmp-=mt_len; 2242 2243 ext_ip_len = isis_print_extd_ip_reach(tptr, "\n\t ", IPV4); 2244 if (ext_ip_len == 0) /* did something go wrong ? */ 2245 goto trunctlv; 2246 tptr+=ext_ip_len; 2247 tmp-=ext_ip_len; 2248 } 2249 break; 2250 2251 #ifdef INET6 2252 case ISIS_TLV_IP6_REACH: 2253 while (tmp>0) { 2254 ext_ip_len = isis_print_extd_ip_reach(tptr, "\n\t ", IPV6); 2255 if (ext_ip_len == 0) /* did something go wrong ? */ 2256 goto trunctlv; 2257 tptr+=ext_ip_len; 2258 tmp-=ext_ip_len; 2259 } 2260 break; 2261 2262 case ISIS_TLV_MT_IP6_REACH: 2263 while (tmp>0) { 2264 mt_len = isis_print_mtid(tptr, "\n\t "); 2265 if (mt_len == 0) /* did something go wrong ? */ 2266 goto trunctlv; 2267 tptr+=mt_len; 2268 tmp-=mt_len; 2269 2270 ext_ip_len = isis_print_extd_ip_reach(tptr, "\n\t ", IPV6); 2271 if (ext_ip_len == 0) /* did something go wrong ? */ 2272 goto trunctlv; 2273 tptr+=ext_ip_len; 2274 tmp-=ext_ip_len; 2275 } 2276 break; 2277 2278 case ISIS_TLV_IP6ADDR: 2279 while (tmp>=sizeof(struct in6_addr)) { 2280 if (!TTEST2(*tptr, sizeof(struct in6_addr))) 2281 goto trunctlv; 2282 2283 printf("\n\t IPv6 interface address: %s", 2284 ip6addr_string(tptr)); 2285 2286 tptr += sizeof(struct in6_addr); 2287 tmp -= sizeof(struct in6_addr); 2288 } 2289 break; 2290 #endif 2291 case ISIS_TLV_AUTH: 2292 if (!TTEST2(*tptr, 1)) 2293 goto trunctlv; 2294 2295 printf("\n\t %s: ", 2296 tok2str(isis_subtlv_auth_values, 2297 "unknown Authentication type 0x%02x", 2298 *tptr)); 2299 2300 switch (*tptr) { 2301 case ISIS_SUBTLV_AUTH_SIMPLE: 2302 for(i=1;i<tlv_len;i++) { 2303 if (!TTEST2(*(tptr+i), 1)) 2304 goto trunctlv; 2305 printf("%c",*(tptr+i)); 2306 } 2307 break; 2308 case ISIS_SUBTLV_AUTH_MD5: 2309 for(i=1;i<tlv_len;i++) { 2310 if (!TTEST2(*(tptr+i), 1)) 2311 goto trunctlv; 2312 printf("%02x",*(tptr+i)); 2313 } 2314 if (tlv_len != ISIS_SUBTLV_AUTH_MD5_LEN+1) 2315 printf(", (malformed subTLV) "); 2316 break; 2317 case ISIS_SUBTLV_AUTH_PRIVATE: 2318 default: 2319 if(!print_unknown_data(tptr+1,"\n\t\t ",tlv_len-1)) 2320 return(0); 2321 break; 2322 } 2323 break; 2324 2325 case ISIS_TLV_PTP_ADJ: 2326 tlv_ptp_adj = (const struct isis_tlv_ptp_adj *)tptr; 2327 if(tmp>=1) { 2328 if (!TTEST2(*tptr, 1)) 2329 goto trunctlv; 2330 printf("\n\t Adjacency State: %s (%u)", 2331 tok2str(isis_ptp_adjancey_values, "unknown", *tptr), 2332 *tptr); 2333 tmp--; 2334 } 2335 if(tmp>sizeof(tlv_ptp_adj->extd_local_circuit_id)) { 2336 if (!TTEST2(tlv_ptp_adj->extd_local_circuit_id, 2337 sizeof(tlv_ptp_adj->extd_local_circuit_id))) 2338 goto trunctlv; 2339 printf("\n\t Extended Local circuit-ID: 0x%08x", 2340 EXTRACT_32BITS(tlv_ptp_adj->extd_local_circuit_id)); 2341 tmp-=sizeof(tlv_ptp_adj->extd_local_circuit_id); 2342 } 2343 if(tmp>=SYSTEM_ID_LEN) { 2344 if (!TTEST2(tlv_ptp_adj->neighbor_sysid, SYSTEM_ID_LEN)) 2345 goto trunctlv; 2346 printf("\n\t Neighbor System-ID: %s", 2347 isis_print_id(tlv_ptp_adj->neighbor_sysid,SYSTEM_ID_LEN)); 2348 tmp-=SYSTEM_ID_LEN; 2349 } 2350 if(tmp>=sizeof(tlv_ptp_adj->neighbor_extd_local_circuit_id)) { 2351 if (!TTEST2(tlv_ptp_adj->neighbor_extd_local_circuit_id, 2352 sizeof(tlv_ptp_adj->neighbor_extd_local_circuit_id))) 2353 goto trunctlv; 2354 printf("\n\t Neighbor Extended Local circuit-ID: 0x%08x", 2355 EXTRACT_32BITS(tlv_ptp_adj->neighbor_extd_local_circuit_id)); 2356 } 2357 break; 2358 2359 case ISIS_TLV_PROTOCOLS: 2360 printf("\n\t NLPID(s): "); 2361 while (tmp>0) { 2362 if (!TTEST2(*(tptr), 1)) 2363 goto trunctlv; 2364 printf("%s (0x%02x)", 2365 tok2str(nlpid_values, 2366 "unknown", 2367 *tptr), 2368 *tptr); 2369 if (tmp>1) /* further NPLIDs ? - put comma */ 2370 printf(", "); 2371 tptr++; 2372 tmp--; 2373 } 2374 break; 2375 2376 case ISIS_TLV_TE_ROUTER_ID: 2377 if (!TTEST2(*pptr, sizeof(struct in_addr))) 2378 goto trunctlv; 2379 printf("\n\t Traffic Engineering Router ID: %s", ipaddr_string(pptr)); 2380 break; 2381 2382 case ISIS_TLV_IPADDR: 2383 while (tmp>=sizeof(struct in_addr)) { 2384 if (!TTEST2(*tptr, sizeof(struct in_addr))) 2385 goto trunctlv; 2386 printf("\n\t IPv4 interface address: %s", ipaddr_string(tptr)); 2387 tptr += sizeof(struct in_addr); 2388 tmp -= sizeof(struct in_addr); 2389 } 2390 break; 2391 2392 case ISIS_TLV_HOSTNAME: 2393 printf("\n\t Hostname: "); 2394 while (tmp>0) { 2395 if (!TTEST2(*tptr, 1)) 2396 goto trunctlv; 2397 printf("%c",*tptr++); 2398 tmp--; 2399 } 2400 break; 2401 2402 case ISIS_TLV_SHARED_RISK_GROUP: 2403 if (tmp < NODE_ID_LEN) 2404 break; 2405 if (!TTEST2(*tptr, NODE_ID_LEN)) 2406 goto trunctlv; 2407 printf("\n\t IS Neighbor: %s", isis_print_id(tptr, NODE_ID_LEN)); 2408 tptr+=(NODE_ID_LEN); 2409 tmp-=(NODE_ID_LEN); 2410 2411 if (tmp < 1) 2412 break; 2413 if (!TTEST2(*tptr, 1)) 2414 goto trunctlv; 2415 printf(", Flags: [%s]", ISIS_MASK_TLV_SHARED_RISK_GROUP(*tptr++) ? "numbered" : "unnumbered"); 2416 tmp--; 2417 2418 if (tmp < sizeof(struct in_addr)) 2419 break; 2420 if (!TTEST2(*tptr,sizeof(struct in_addr))) 2421 goto trunctlv; 2422 printf("\n\t IPv4 interface address: %s", ipaddr_string(tptr)); 2423 tptr+=sizeof(struct in_addr); 2424 tmp-=sizeof(struct in_addr); 2425 2426 if (tmp < sizeof(struct in_addr)) 2427 break; 2428 if (!TTEST2(*tptr,sizeof(struct in_addr))) 2429 goto trunctlv; 2430 printf("\n\t IPv4 neighbor address: %s", ipaddr_string(tptr)); 2431 tptr+=sizeof(struct in_addr); 2432 tmp-=sizeof(struct in_addr); 2433 2434 while (tmp>=4) { 2435 if (!TTEST2(*tptr, 4)) 2436 goto trunctlv; 2437 printf("\n\t Link-ID: 0x%08x", EXTRACT_32BITS(tptr)); 2438 tptr+=4; 2439 tmp-=4; 2440 } 2441 break; 2442 2443 case ISIS_TLV_LSP: 2444 tlv_lsp = (const struct isis_tlv_lsp *)tptr; 2445 while(tmp>=sizeof(struct isis_tlv_lsp)) { 2446 if (!TTEST((tlv_lsp->lsp_id)[LSP_ID_LEN-1])) 2447 goto trunctlv; 2448 printf("\n\t lsp-id: %s", 2449 isis_print_id(tlv_lsp->lsp_id, LSP_ID_LEN)); 2450 if (!TTEST2(tlv_lsp->sequence_number, 4)) 2451 goto trunctlv; 2452 printf(", seq: 0x%08x",EXTRACT_32BITS(tlv_lsp->sequence_number)); 2453 if (!TTEST2(tlv_lsp->remaining_lifetime, 2)) 2454 goto trunctlv; 2455 printf(", lifetime: %5ds",EXTRACT_16BITS(tlv_lsp->remaining_lifetime)); 2456 if (!TTEST2(tlv_lsp->checksum, 2)) 2457 goto trunctlv; 2458 printf(", chksum: 0x%04x",EXTRACT_16BITS(tlv_lsp->checksum)); 2459 tmp-=sizeof(struct isis_tlv_lsp); 2460 tlv_lsp++; 2461 } 2462 break; 2463 2464 case ISIS_TLV_CHECKSUM: 2465 if (tmp < ISIS_TLV_CHECKSUM_MINLEN) 2466 break; 2467 if (!TTEST2(*tptr, ISIS_TLV_CHECKSUM_MINLEN)) 2468 goto trunctlv; 2469 printf("\n\t checksum: 0x%04x ", EXTRACT_16BITS(tptr)); 2470 /* do not attempt to verify the checksum if it is zero 2471 * most likely a HMAC-MD5 TLV is also present and 2472 * to avoid conflicts the checksum TLV is zeroed. 2473 * see rfc3358 for details 2474 */ 2475 if (EXTRACT_16BITS(tptr) == 0) 2476 printf("(unverified)"); 2477 else printf("(%s)", osi_cksum(optr, length) ? "incorrect" : "correct"); 2478 break; 2479 2480 case ISIS_TLV_MT_SUPPORTED: 2481 if (tmp < ISIS_TLV_MT_SUPPORTED_MINLEN) 2482 break; 2483 while (tmp>1) { 2484 /* length can only be a multiple of 2, otherwise there is 2485 something broken -> so decode down until length is 1 */ 2486 if (tmp!=1) { 2487 mt_len = isis_print_mtid(tptr, "\n\t "); 2488 if (mt_len == 0) /* did something go wrong ? */ 2489 goto trunctlv; 2490 tptr+=mt_len; 2491 tmp-=mt_len; 2492 } else { 2493 printf("\n\t malformed MT-ID"); 2494 break; 2495 } 2496 } 2497 break; 2498 2499 case ISIS_TLV_RESTART_SIGNALING: 2500 /* first attempt to decode the flags */ 2501 if (tmp < ISIS_TLV_RESTART_SIGNALING_FLAGLEN) 2502 break; 2503 if (!TTEST2(*tptr, ISIS_TLV_RESTART_SIGNALING_FLAGLEN)) 2504 goto trunctlv; 2505 printf("\n\t Flags [%s]", 2506 bittok2str(isis_restart_flag_values, "none", *tptr)); 2507 tptr+=ISIS_TLV_RESTART_SIGNALING_FLAGLEN; 2508 tmp-=ISIS_TLV_RESTART_SIGNALING_FLAGLEN; 2509 2510 /* is there anything other than the flags field? */ 2511 if (tmp == 0) 2512 break; 2513 2514 if (tmp < ISIS_TLV_RESTART_SIGNALING_HOLDTIMELEN) 2515 break; 2516 if (!TTEST2(*tptr, ISIS_TLV_RESTART_SIGNALING_HOLDTIMELEN)) 2517 goto trunctlv; 2518 2519 printf(", Remaining holding time %us", EXTRACT_16BITS(tptr+1)); 2520 tptr+=ISIS_TLV_RESTART_SIGNALING_HOLDTIMELEN; 2521 tmp-=ISIS_TLV_RESTART_SIGNALING_HOLDTIMELEN; 2522 2523 /* is there an additional sysid field present ?*/ 2524 if (tmp == SYSTEM_ID_LEN) { 2525 if (!TTEST2(*tptr, SYSTEM_ID_LEN)) 2526 goto trunctlv; 2527 printf(", for %s",isis_print_id(tptr,SYSTEM_ID_LEN)); 2528 } 2529 break; 2530 2531 case ISIS_TLV_IDRP_INFO: 2532 if (tmp < ISIS_TLV_IDRP_INFO_MINLEN) 2533 break; 2534 if (!TTEST2(*tptr, ISIS_TLV_IDRP_INFO_MINLEN)) 2535 goto trunctlv; 2536 printf("\n\t Inter-Domain Information Type: %s", 2537 tok2str(isis_subtlv_idrp_values, 2538 "Unknown (0x%02x)", 2539 *tptr)); 2540 switch (*tptr++) { 2541 case ISIS_SUBTLV_IDRP_ASN: 2542 if (!TTEST2(*tptr, 2)) /* fetch AS number */ 2543 goto trunctlv; 2544 printf("AS Number: %u",EXTRACT_16BITS(tptr)); 2545 break; 2546 case ISIS_SUBTLV_IDRP_LOCAL: 2547 case ISIS_SUBTLV_IDRP_RES: 2548 default: 2549 if(!print_unknown_data(tptr,"\n\t ",tlv_len-1)) 2550 return(0); 2551 break; 2552 } 2553 break; 2554 2555 case ISIS_TLV_LSP_BUFFERSIZE: 2556 if (tmp < ISIS_TLV_LSP_BUFFERSIZE_MINLEN) 2557 break; 2558 if (!TTEST2(*tptr, ISIS_TLV_LSP_BUFFERSIZE_MINLEN)) 2559 goto trunctlv; 2560 printf("\n\t LSP Buffersize: %u",EXTRACT_16BITS(tptr)); 2561 break; 2562 2563 case ISIS_TLV_PART_DIS: 2564 while (tmp >= SYSTEM_ID_LEN) { 2565 if (!TTEST2(*tptr, SYSTEM_ID_LEN)) 2566 goto trunctlv; 2567 printf("\n\t %s",isis_print_id(tptr,SYSTEM_ID_LEN)); 2568 tptr+=SYSTEM_ID_LEN; 2569 tmp-=SYSTEM_ID_LEN; 2570 } 2571 break; 2572 2573 case ISIS_TLV_PREFIX_NEIGH: 2574 if (tmp < sizeof(struct isis_metric_block)) 2575 break; 2576 if (!TTEST2(*tptr, sizeof(struct isis_metric_block))) 2577 goto trunctlv; 2578 printf("\n\t Metric Block"); 2579 isis_print_metric_block((const struct isis_metric_block *)tptr); 2580 tptr+=sizeof(struct isis_metric_block); 2581 tmp-=sizeof(struct isis_metric_block); 2582 2583 while(tmp>0) { 2584 if (!TTEST2(*tptr, 1)) 2585 goto trunctlv; 2586 prefix_len=*tptr++; /* read out prefix length in semioctets*/ 2587 if (prefix_len < 2) { 2588 printf("\n\t\tAddress: prefix length %u < 2", prefix_len); 2589 break; 2590 } 2591 tmp--; 2592 if (tmp < prefix_len/2) 2593 break; 2594 if (!TTEST2(*tptr, prefix_len/2)) 2595 goto trunctlv; 2596 printf("\n\t\tAddress: %s/%u", 2597 isonsap_string(tptr,prefix_len/2), 2598 prefix_len*4); 2599 tptr+=prefix_len/2; 2600 tmp-=prefix_len/2; 2601 } 2602 break; 2603 2604 case ISIS_TLV_IIH_SEQNR: 2605 if (tmp < ISIS_TLV_IIH_SEQNR_MINLEN) 2606 break; 2607 if (!TTEST2(*tptr, ISIS_TLV_IIH_SEQNR_MINLEN)) /* check if four bytes are on the wire */ 2608 goto trunctlv; 2609 printf("\n\t Sequence number: %u", EXTRACT_32BITS(tptr) ); 2610 break; 2611 2612 case ISIS_TLV_VENDOR_PRIVATE: 2613 if (tmp < ISIS_TLV_VENDOR_PRIVATE_MINLEN) 2614 break; 2615 if (!TTEST2(*tptr, ISIS_TLV_VENDOR_PRIVATE_MINLEN)) /* check if enough byte for a full oui */ 2616 goto trunctlv; 2617 vendor_id = EXTRACT_24BITS(tptr); 2618 printf("\n\t Vendor: %s (%u)", 2619 tok2str(oui_values,"Unknown",vendor_id), 2620 vendor_id); 2621 tptr+=3; 2622 tmp-=3; 2623 if (tmp > 0) /* hexdump the rest */ 2624 if(!print_unknown_data(tptr,"\n\t\t",tmp)) 2625 return(0); 2626 break; 2627 /* 2628 * FIXME those are the defined TLVs that lack a decoder 2629 * you are welcome to contribute code ;-) 2630 */ 2631 2632 case ISIS_TLV_DECNET_PHASE4: 2633 case ISIS_TLV_LUCENT_PRIVATE: 2634 case ISIS_TLV_IPAUTH: 2635 case ISIS_TLV_NORTEL_PRIVATE1: 2636 case ISIS_TLV_NORTEL_PRIVATE2: 2637 2638 default: 2639 if (vflag <= 1) { 2640 if(!print_unknown_data(pptr,"\n\t\t",tlv_len)) 2641 return(0); 2642 } 2643 break; 2644 } 2645 /* do we want to see an additionally hexdump ? */ 2646 if (vflag> 1) { 2647 if(!print_unknown_data(pptr,"\n\t ",tlv_len)) 2648 return(0); 2649 } 2650 2651 pptr += tlv_len; 2652 packet_len -= tlv_len; 2653 } 2654 2655 if (packet_len != 0) { 2656 printf("\n\t %u straggler bytes", packet_len); 2657 } 2658 return (1); 2659 2660 trunc: 2661 fputs("[|isis]", stdout); 2662 return (1); 2663 2664 trunctlv: 2665 printf("\n\t\t packet exceeded snapshot"); 2666 return(1); 2667 } 2668 2669 /* 2670 * Verify the checksum. See 8473-1, Appendix C, section C.4. 2671 */ 2672 2673 static int 2674 osi_cksum(const u_int8_t *tptr, u_int len) 2675 { 2676 int32_t c0 = 0, c1 = 0; 2677 2678 while ((int)--len >= 0) { 2679 c0 += *tptr++; 2680 c0 %= 255; 2681 c1 += c0; 2682 c1 %= 255; 2683 } 2684 return (c0 | c1); 2685 } 2686 2687 2688 /* 2689 * Local Variables: 2690 * c-style: whitesmith 2691 * c-basic-offset: 8 2692 * End: 2693 */ 2694