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