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