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