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