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