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