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