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