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