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