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