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