]> The Tcpdump Group git mirrors - tcpdump/blob - print-isoclns.c
remove redundant ND_TCHECK, let GET_ routines handle checks
[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
739 if (ndo->ndo_eflag)
740 ND_PRINT("OSI NLPID %s (0x%02x): ",
741 tok2str(nlpid_values, "Unknown", GET_U_1(p)),
742 GET_U_1(p));
743
744 switch (GET_U_1(p)) {
745
746 case NLPID_CLNP:
747 if (!clnp_print(ndo, p, length))
748 print_unknown_data(ndo, p, "\n\t", length);
749 break;
750
751 case NLPID_ESIS:
752 esis_print(ndo, p, length);
753 return;
754
755 case NLPID_ISIS:
756 if (!isis_print(ndo, p, length))
757 print_unknown_data(ndo, p, "\n\t", length);
758 break;
759
760 case NLPID_NULLNS:
761 ND_PRINT("%slength: %u", ndo->ndo_eflag ? "" : ", ", length);
762 break;
763
764 case NLPID_Q933:
765 q933_print(ndo, p + 1, length - 1);
766 break;
767
768 case NLPID_IP:
769 ip_print(ndo, p + 1, length - 1);
770 break;
771
772 case NLPID_IP6:
773 ip6_print(ndo, p + 1, length - 1);
774 break;
775
776 case NLPID_PPP:
777 ppp_print(ndo, p + 1, length - 1);
778 break;
779
780 default:
781 if (!ndo->ndo_eflag)
782 ND_PRINT("OSI NLPID 0x%02x unknown", GET_U_1(p));
783 ND_PRINT("%slength: %u", ndo->ndo_eflag ? "" : ", ", length);
784 if (length > 1)
785 print_unknown_data(ndo, p, "\n\t", length);
786 break;
787 }
788 }
789
790 #define CLNP_PDU_ER 1
791 #define CLNP_PDU_DT 28
792 #define CLNP_PDU_MD 29
793 #define CLNP_PDU_ERQ 30
794 #define CLNP_PDU_ERP 31
795
796 static const struct tok clnp_pdu_values[] = {
797 { CLNP_PDU_ER, "Error Report"},
798 { CLNP_PDU_MD, "MD"},
799 { CLNP_PDU_DT, "Data"},
800 { CLNP_PDU_ERQ, "Echo Request"},
801 { CLNP_PDU_ERP, "Echo Response"},
802 { 0, NULL }
803 };
804
805 struct clnp_header_t {
806 nd_uint8_t nlpid;
807 nd_uint8_t length_indicator;
808 nd_uint8_t version;
809 nd_uint8_t lifetime; /* units of 500ms */
810 nd_uint8_t type;
811 nd_uint16_t segment_length;
812 nd_uint16_t cksum;
813 };
814
815 struct clnp_segment_header_t {
816 nd_uint16_t data_unit_id;
817 nd_uint16_t segment_offset;
818 nd_uint16_t total_length;
819 };
820
821 /*
822 * clnp_print
823 * Decode CLNP packets. Return 0 on error.
824 */
825
826 static int
827 clnp_print(netdissect_options *ndo,
828 const uint8_t *pptr, u_int length)
829 {
830 const uint8_t *optr,*source_address,*dest_address;
831 u_int li,li_remaining,tlen,nsap_offset,source_address_length,dest_address_length, clnp_pdu_type, clnp_flags;
832 const struct clnp_header_t *clnp_header;
833 const struct clnp_segment_header_t *clnp_segment_header;
834 uint8_t rfd_error,rfd_error_major,rfd_error_minor;
835
836 ndo->ndo_protocol = "clnp";
837 clnp_header = (const struct clnp_header_t *) pptr;
838 ND_TCHECK_SIZE(clnp_header);
839
840 li = GET_U_1(clnp_header->length_indicator);
841 li_remaining = li;
842 optr = pptr;
843
844 if (!ndo->ndo_eflag)
845 nd_print_protocol_caps(ndo);
846
847 /*
848 * Sanity checking of the header.
849 */
850
851 if (GET_U_1(clnp_header->version) != CLNP_VERSION) {
852 ND_PRINT("version %u packet not supported",
853 GET_U_1(clnp_header->version));
854 return (0);
855 }
856
857 if (li > length) {
858 ND_PRINT(" length indicator(%u) > PDU size (%u)!", li, length);
859 return (0);
860 }
861
862 if (li < sizeof(struct clnp_header_t)) {
863 ND_PRINT(" length indicator %u < min PDU size:", li);
864 while (pptr < ndo->ndo_snapend) {
865 ND_PRINT("%02X", GET_U_1(pptr));
866 pptr++;
867 }
868 return (0);
869 }
870
871 /* FIXME further header sanity checking */
872
873 clnp_pdu_type = GET_U_1(clnp_header->type) & CLNP_PDU_TYPE_MASK;
874 clnp_flags = GET_U_1(clnp_header->type) & CLNP_FLAG_MASK;
875
876 pptr += sizeof(struct clnp_header_t);
877 li_remaining -= sizeof(struct clnp_header_t);
878
879 if (li_remaining < 1) {
880 ND_PRINT("li < size of fixed part of CLNP header and addresses");
881 return (0);
882 }
883 dest_address_length = GET_U_1(pptr);
884 pptr += 1;
885 li_remaining -= 1;
886 if (li_remaining < dest_address_length) {
887 ND_PRINT("li < size of fixed part of CLNP header and addresses");
888 return (0);
889 }
890 ND_TCHECK_LEN(pptr, dest_address_length);
891 dest_address = pptr;
892 pptr += dest_address_length;
893 li_remaining -= dest_address_length;
894
895 if (li_remaining < 1) {
896 ND_PRINT("li < size of fixed part of CLNP header and addresses");
897 return (0);
898 }
899 source_address_length = GET_U_1(pptr);
900 pptr += 1;
901 li_remaining -= 1;
902 if (li_remaining < source_address_length) {
903 ND_PRINT("li < size of fixed part of CLNP header and addresses");
904 return (0);
905 }
906 ND_TCHECK_LEN(pptr, source_address_length);
907 source_address = pptr;
908 pptr += source_address_length;
909 li_remaining -= source_address_length;
910
911 if (ndo->ndo_vflag < 1) {
912 ND_PRINT("%s%s > %s, %s, length %u",
913 ndo->ndo_eflag ? "" : ", ",
914 GET_ISONSAP_STRING(source_address, source_address_length),
915 GET_ISONSAP_STRING(dest_address, dest_address_length),
916 tok2str(clnp_pdu_values,"unknown (%u)",clnp_pdu_type),
917 length);
918 return (1);
919 }
920 ND_PRINT("%slength %u", ndo->ndo_eflag ? "" : ", ", length);
921
922 ND_PRINT("\n\t%s PDU, hlen: %u, v: %u, lifetime: %u.%us, Segment PDU length: %u, checksum: 0x%04x",
923 tok2str(clnp_pdu_values, "unknown (%u)",clnp_pdu_type),
924 GET_U_1(clnp_header->length_indicator),
925 GET_U_1(clnp_header->version),
926 GET_U_1(clnp_header->lifetime)/2,
927 (GET_U_1(clnp_header->lifetime)%2)*5,
928 GET_BE_U_2(clnp_header->segment_length),
929 GET_BE_U_2(clnp_header->cksum));
930
931 osi_print_cksum(ndo, optr, GET_BE_U_2(clnp_header->cksum), 7,
932 GET_U_1(clnp_header->length_indicator));
933
934 ND_PRINT("\n\tFlags [%s]",
935 bittok2str(clnp_flag_values, "none", clnp_flags));
936
937 ND_PRINT("\n\tsource address (length %u): %s\n\tdest address (length %u): %s",
938 source_address_length,
939 GET_ISONSAP_STRING(source_address, source_address_length),
940 dest_address_length,
941 GET_ISONSAP_STRING(dest_address, dest_address_length));
942
943 if (clnp_flags & CLNP_SEGMENT_PART) {
944 if (li_remaining < sizeof(struct clnp_segment_header_t)) {
945 ND_PRINT("li < size of fixed part of CLNP header, addresses, and segment part");
946 return (0);
947 }
948 clnp_segment_header = (const struct clnp_segment_header_t *) pptr;
949 ND_TCHECK_SIZE(clnp_segment_header);
950 ND_PRINT("\n\tData Unit ID: 0x%04x, Segment Offset: %u, Total PDU Length: %u",
951 GET_BE_U_2(clnp_segment_header->data_unit_id),
952 GET_BE_U_2(clnp_segment_header->segment_offset),
953 GET_BE_U_2(clnp_segment_header->total_length));
954 pptr+=sizeof(struct clnp_segment_header_t);
955 li_remaining-=sizeof(struct clnp_segment_header_t);
956 }
957
958 /* now walk the options */
959 while (li_remaining != 0) {
960 u_int op, opli;
961 const uint8_t *tptr;
962
963 if (li_remaining < 2) {
964 ND_PRINT(", bad opts/li");
965 return (0);
966 }
967 op = GET_U_1(pptr);
968 opli = GET_U_1(pptr + 1);
969 pptr += 2;
970 li_remaining -= 2;
971 if (opli > li_remaining) {
972 ND_PRINT(", opt (%u) too long", op);
973 return (0);
974 }
975 ND_TCHECK_LEN(pptr, opli);
976 li_remaining -= opli;
977 tptr = pptr;
978 tlen = opli;
979
980 ND_PRINT("\n\t %s Option #%u, length %u, value: ",
981 tok2str(clnp_option_values,"Unknown",op),
982 op,
983 opli);
984
985 /*
986 * We've already checked that the entire option is present
987 * in the captured packet with the ND_TCHECK_LEN() call.
988 * Therefore, we don't need to do ND_TCHECK()/ND_TCHECK_LEN()
989 * checks.
990 * We do, however, need to check tlen, to make sure we
991 * don't run past the end of the option.
992 */
993 switch (op) {
994
995
996 case CLNP_OPTION_ROUTE_RECORDING: /* those two options share the format */
997 case CLNP_OPTION_SOURCE_ROUTING:
998 if (tlen < 2) {
999 ND_PRINT(", bad opt len");
1000 return (0);
1001 }
1002 ND_PRINT("%s %s",
1003 tok2str(clnp_option_sr_rr_values,"Unknown",GET_U_1(tptr)),
1004 tok2str(clnp_option_sr_rr_string_values, "Unknown Option %u", op));
1005 nsap_offset=GET_U_1(tptr + 1);
1006 if (nsap_offset == 0) {
1007 ND_PRINT(" Bad NSAP offset (0)");
1008 break;
1009 }
1010 nsap_offset-=1; /* offset to nsap list */
1011 if (nsap_offset > tlen) {
1012 ND_PRINT(" Bad NSAP offset (past end of option)");
1013 break;
1014 }
1015 tptr+=nsap_offset;
1016 tlen-=nsap_offset;
1017 while (tlen > 0) {
1018 source_address_length=GET_U_1(tptr);
1019 if (tlen < source_address_length+1) {
1020 ND_PRINT("\n\t NSAP address goes past end of option");
1021 break;
1022 }
1023 if (source_address_length > 0) {
1024 source_address=(tptr+1);
1025 ND_PRINT("\n\t NSAP address (length %u): %s",
1026 source_address_length,
1027 GET_ISONSAP_STRING(source_address, source_address_length));
1028 }
1029 tlen-=source_address_length+1;
1030 }
1031 break;
1032
1033 case CLNP_OPTION_PRIORITY:
1034 if (tlen < 1) {
1035 ND_PRINT(", bad opt len");
1036 return (0);
1037 }
1038 ND_PRINT("0x%1x", GET_U_1(tptr)&0x0f);
1039 break;
1040
1041 case CLNP_OPTION_QOS_MAINTENANCE:
1042 if (tlen < 1) {
1043 ND_PRINT(", bad opt len");
1044 return (0);
1045 }
1046 ND_PRINT("\n\t Format Code: %s",
1047 tok2str(clnp_option_scope_values, "Reserved", GET_U_1(tptr) & CLNP_OPTION_SCOPE_MASK));
1048
1049 if ((GET_U_1(tptr)&CLNP_OPTION_SCOPE_MASK) == CLNP_OPTION_SCOPE_GLOBAL)
1050 ND_PRINT("\n\t QoS Flags [%s]",
1051 bittok2str(clnp_option_qos_global_values,
1052 "none",
1053 GET_U_1(tptr)&CLNP_OPTION_OPTION_QOS_MASK));
1054 break;
1055
1056 case CLNP_OPTION_SECURITY:
1057 if (tlen < 2) {
1058 ND_PRINT(", bad opt len");
1059 return (0);
1060 }
1061 ND_PRINT("\n\t Format Code: %s, Security-Level %u",
1062 tok2str(clnp_option_scope_values,"Reserved",GET_U_1(tptr)&CLNP_OPTION_SCOPE_MASK),
1063 GET_U_1(tptr + 1));
1064 break;
1065
1066 case CLNP_OPTION_DISCARD_REASON:
1067 if (tlen < 1) {
1068 ND_PRINT(", bad opt len");
1069 return (0);
1070 }
1071 rfd_error = GET_U_1(tptr);
1072 rfd_error_major = (rfd_error&0xf0) >> 4;
1073 rfd_error_minor = rfd_error&0x0f;
1074 ND_PRINT("\n\t Class: %s Error (0x%01x), %s (0x%01x)",
1075 tok2str(clnp_option_rfd_class_values,"Unknown",rfd_error_major),
1076 rfd_error_major,
1077 tok2str(clnp_option_rfd_error_class[rfd_error_major],"Unknown",rfd_error_minor),
1078 rfd_error_minor);
1079 break;
1080
1081 case CLNP_OPTION_PADDING:
1082 ND_PRINT("padding data");
1083 break;
1084
1085 /*
1086 * FIXME those are the defined Options that lack a decoder
1087 * you are welcome to contribute code ;-)
1088 */
1089
1090 default:
1091 print_unknown_data(ndo, tptr, "\n\t ", opli);
1092 break;
1093 }
1094 if (ndo->ndo_vflag > 1)
1095 print_unknown_data(ndo, pptr, "\n\t ", opli);
1096 pptr += opli;
1097 }
1098
1099 switch (clnp_pdu_type) {
1100
1101 case CLNP_PDU_ER: /* fall through */
1102 case CLNP_PDU_ERP:
1103 if (GET_U_1(pptr) == NLPID_CLNP) {
1104 ND_PRINT("\n\t-----original packet-----\n\t");
1105 /* FIXME recursion protection */
1106 clnp_print(ndo, pptr, length - li);
1107 break;
1108 }
1109
1110 /* The cases above break from the switch block if they see and print
1111 * a CLNP header in the Data part. For an Error Report PDU this is
1112 * described in Section 7.9.6 of ITU X.233 (1997 E), also known as
1113 * ISO/IEC 8473-1:1998(E). It is not clear why in this code the same
1114 * applies to an Echo Response PDU, as the standard does not specify
1115 * the contents -- could be a proprietary extension or a bug. In either
1116 * case, if the Data part does not contain a CLNP header, its structure
1117 * is considered unknown and the decoding falls through to print the
1118 * contents as-is.
1119 */
1120 ND_FALL_THROUGH;
1121
1122 case CLNP_PDU_DT:
1123 case CLNP_PDU_MD:
1124 case CLNP_PDU_ERQ:
1125
1126 default:
1127 /* dump the PDU specific data */
1128 if (length > ND_BYTES_BETWEEN(pptr, optr)) {
1129 ND_PRINT("\n\t undecoded non-header data, length %u", length-li);
1130 print_unknown_data(ndo, pptr, "\n\t ", length - ND_BYTES_BETWEEN(pptr, optr));
1131 }
1132 }
1133
1134 return (1);
1135
1136 trunc:
1137 nd_print_trunc(ndo);
1138 return (1);
1139
1140 }
1141
1142
1143 #define ESIS_PDU_REDIRECT 6
1144 #define ESIS_PDU_ESH 2
1145 #define ESIS_PDU_ISH 4
1146
1147 static const struct tok esis_pdu_values[] = {
1148 { ESIS_PDU_REDIRECT, "redirect"},
1149 { ESIS_PDU_ESH, "ESH"},
1150 { ESIS_PDU_ISH, "ISH"},
1151 { 0, NULL }
1152 };
1153
1154 struct esis_header_t {
1155 nd_uint8_t nlpid;
1156 nd_uint8_t length_indicator;
1157 nd_uint8_t version;
1158 nd_byte reserved;
1159 nd_uint8_t type;
1160 nd_uint16_t holdtime;
1161 nd_uint16_t cksum;
1162 };
1163
1164 static void
1165 esis_print(netdissect_options *ndo,
1166 const uint8_t *pptr, u_int length)
1167 {
1168 const uint8_t *optr;
1169 u_int li, version, esis_pdu_type, source_address_length, source_address_number;
1170 const struct esis_header_t *esis_header;
1171
1172 ndo->ndo_protocol = "esis";
1173 if (!ndo->ndo_eflag)
1174 ND_PRINT("ES-IS");
1175
1176 if (length <= 2) {
1177 ND_PRINT(ndo->ndo_qflag ? "bad pkt!" : "no header at all!");
1178 return;
1179 }
1180
1181 esis_header = (const struct esis_header_t *) pptr;
1182 ND_TCHECK_SIZE(esis_header);
1183 li = GET_U_1(esis_header->length_indicator);
1184 optr = pptr;
1185
1186 /*
1187 * Sanity checking of the header.
1188 */
1189
1190 if (GET_U_1(esis_header->nlpid) != NLPID_ESIS) {
1191 ND_PRINT(" nlpid 0x%02x packet not supported",
1192 GET_U_1(esis_header->nlpid));
1193 return;
1194 }
1195
1196 version = GET_U_1(esis_header->version);
1197 if (version != ESIS_VERSION) {
1198 ND_PRINT(" version %u packet not supported", version);
1199 return;
1200 }
1201
1202 if (li > length) {
1203 ND_PRINT(" length indicator(%u) > PDU size (%u)!", li, length);
1204 return;
1205 }
1206
1207 if (li < sizeof(struct esis_header_t) + 2) {
1208 ND_PRINT(" length indicator %u < min PDU size:", li);
1209 while (pptr < ndo->ndo_snapend) {
1210 ND_PRINT("%02X", GET_U_1(pptr));
1211 pptr++;
1212 }
1213 return;
1214 }
1215
1216 esis_pdu_type = GET_U_1(esis_header->type) & ESIS_PDU_TYPE_MASK;
1217
1218 if (ndo->ndo_vflag < 1) {
1219 ND_PRINT("%s%s, length %u",
1220 ndo->ndo_eflag ? "" : ", ",
1221 tok2str(esis_pdu_values,"unknown type (%u)",esis_pdu_type),
1222 length);
1223 return;
1224 } else
1225 ND_PRINT("%slength %u\n\t%s (%u)",
1226 ndo->ndo_eflag ? "" : ", ",
1227 length,
1228 tok2str(esis_pdu_values,"unknown type: %u", esis_pdu_type),
1229 esis_pdu_type);
1230
1231 ND_PRINT(", v: %u%s", version, version == ESIS_VERSION ? "" : "unsupported" );
1232 ND_PRINT(", checksum: 0x%04x", GET_BE_U_2(esis_header->cksum));
1233
1234 osi_print_cksum(ndo, pptr, GET_BE_U_2(esis_header->cksum), 7,
1235 li);
1236
1237 ND_PRINT(", holding time: %us, length indicator: %u",
1238 GET_BE_U_2(esis_header->holdtime), li);
1239
1240 if (ndo->ndo_vflag > 1)
1241 print_unknown_data(ndo, optr, "\n\t", sizeof(struct esis_header_t));
1242
1243 pptr += sizeof(struct esis_header_t);
1244 li -= sizeof(struct esis_header_t);
1245
1246 switch (esis_pdu_type) {
1247 case ESIS_PDU_REDIRECT: {
1248 const uint8_t *dst, *snpa, *neta;
1249 u_int dstl, snpal, netal;
1250
1251 ND_TCHECK_1(pptr);
1252 if (li < 1) {
1253 ND_PRINT(", bad redirect/li");
1254 return;
1255 }
1256 dstl = GET_U_1(pptr);
1257 pptr++;
1258 li--;
1259 ND_TCHECK_LEN(pptr, dstl);
1260 if (li < dstl) {
1261 ND_PRINT(", bad redirect/li");
1262 return;
1263 }
1264 dst = pptr;
1265 pptr += dstl;
1266 li -= dstl;
1267 ND_PRINT("\n\t %s", GET_ISONSAP_STRING(dst, dstl));
1268
1269 ND_TCHECK_1(pptr);
1270 if (li < 1) {
1271 ND_PRINT(", bad redirect/li");
1272 return;
1273 }
1274 snpal = GET_U_1(pptr);
1275 pptr++;
1276 li--;
1277 ND_TCHECK_LEN(pptr, snpal);
1278 if (li < snpal) {
1279 ND_PRINT(", bad redirect/li");
1280 return;
1281 }
1282 snpa = pptr;
1283 pptr += snpal;
1284 li -= snpal;
1285 ND_TCHECK_1(pptr);
1286 if (li < 1) {
1287 ND_PRINT(", bad redirect/li");
1288 return;
1289 }
1290 netal = GET_U_1(pptr);
1291 pptr++;
1292 ND_TCHECK_LEN(pptr, netal);
1293 if (li < netal) {
1294 ND_PRINT(", bad redirect/li");
1295 return;
1296 }
1297 neta = pptr;
1298 pptr += netal;
1299 li -= netal;
1300
1301 if (snpal == MAC_ADDR_LEN)
1302 ND_PRINT("\n\t SNPA (length: %u): %s",
1303 snpal,
1304 GET_ETHERADDR_STRING(snpa));
1305 else
1306 ND_PRINT("\n\t SNPA (length: %u): %s",
1307 snpal,
1308 GET_LINKADDR_STRING(snpa, LINKADDR_OTHER, snpal));
1309 if (netal != 0)
1310 ND_PRINT("\n\t NET (length: %u) %s",
1311 netal,
1312 GET_ISONSAP_STRING(neta, netal));
1313 break;
1314 }
1315
1316 case ESIS_PDU_ESH:
1317 ND_TCHECK_1(pptr);
1318 if (li < 1) {
1319 ND_PRINT(", bad esh/li");
1320 return;
1321 }
1322 source_address_number = GET_U_1(pptr);
1323 pptr++;
1324 li--;
1325
1326 ND_PRINT("\n\t Number of Source Addresses: %u", source_address_number);
1327
1328 while (source_address_number > 0) {
1329 ND_TCHECK_1(pptr);
1330 if (li < 1) {
1331 ND_PRINT(", bad esh/li");
1332 return;
1333 }
1334 source_address_length = GET_U_1(pptr);
1335 pptr++;
1336 li--;
1337
1338 ND_TCHECK_LEN(pptr, source_address_length);
1339 if (li < source_address_length) {
1340 ND_PRINT(", bad esh/li");
1341 return;
1342 }
1343 ND_PRINT("\n\t NET (length: %u): %s",
1344 source_address_length,
1345 GET_ISONSAP_STRING(pptr, source_address_length));
1346 pptr += source_address_length;
1347 li -= source_address_length;
1348 source_address_number--;
1349 }
1350
1351 break;
1352
1353 case ESIS_PDU_ISH: {
1354 ND_TCHECK_1(pptr);
1355 if (li < 1) {
1356 ND_PRINT(", bad ish/li");
1357 return;
1358 }
1359 source_address_length = GET_U_1(pptr);
1360 pptr++;
1361 li--;
1362 ND_TCHECK_LEN(pptr, source_address_length);
1363 if (li < source_address_length) {
1364 ND_PRINT(", bad ish/li");
1365 return;
1366 }
1367 ND_PRINT("\n\t NET (length: %u): %s", source_address_length, GET_ISONSAP_STRING(pptr, source_address_length));
1368 pptr += source_address_length;
1369 li -= source_address_length;
1370 break;
1371 }
1372
1373 default:
1374 if (ndo->ndo_vflag <= 1) {
1375 /*
1376 * If there's at least one byte to print, print
1377 * it/them.
1378 */
1379 if (ND_TTEST_LEN(pptr, 1))
1380 print_unknown_data(ndo, pptr, "\n\t ", ND_BYTES_AVAILABLE_AFTER(pptr));
1381 }
1382 return;
1383 }
1384
1385 /* now walk the options */
1386 while (li != 0) {
1387 u_int op, opli;
1388 const uint8_t *tptr;
1389
1390 if (li < 2) {
1391 ND_PRINT(", bad opts/li");
1392 return;
1393 }
1394 op = GET_U_1(pptr);
1395 opli = GET_U_1(pptr + 1);
1396 pptr += 2;
1397 li -= 2;
1398 if (opli > li) {
1399 ND_PRINT(", opt (%u) too long", op);
1400 return;
1401 }
1402 li -= opli;
1403 tptr = pptr;
1404
1405 ND_PRINT("\n\t %s Option #%u, length %u, value: ",
1406 tok2str(esis_option_values,"Unknown",op),
1407 op,
1408 opli);
1409
1410 switch (op) {
1411
1412 case ESIS_OPTION_ES_CONF_TIME:
1413 if (opli == 2) {
1414 ND_TCHECK_2(pptr);
1415 ND_PRINT("%us", GET_BE_U_2(tptr));
1416 } else
1417 ND_PRINT("(bad length)");
1418 break;
1419
1420 case ESIS_OPTION_PROTOCOLS:
1421 while (opli>0) {
1422 ND_PRINT("%s (0x%02x)",
1423 tok2str(nlpid_values,
1424 "unknown",
1425 GET_U_1(tptr)),
1426 GET_U_1(tptr));
1427 if (opli>1) /* further NPLIDs ? - put comma */
1428 ND_PRINT(", ");
1429 tptr++;
1430 opli--;
1431 }
1432 break;
1433
1434 /*
1435 * FIXME those are the defined Options that lack a decoder
1436 * you are welcome to contribute code ;-)
1437 */
1438
1439 case ESIS_OPTION_QOS_MAINTENANCE:
1440 case ESIS_OPTION_SECURITY:
1441 case ESIS_OPTION_PRIORITY:
1442 case ESIS_OPTION_ADDRESS_MASK:
1443 case ESIS_OPTION_SNPA_MASK:
1444
1445 default:
1446 print_unknown_data(ndo, tptr, "\n\t ", opli);
1447 break;
1448 }
1449 if (ndo->ndo_vflag > 1)
1450 print_unknown_data(ndo, pptr, "\n\t ", opli);
1451 pptr += opli;
1452 }
1453 return;
1454
1455 trunc:
1456 nd_print_trunc(ndo);
1457 }
1458
1459 static void
1460 isis_print_mcid(netdissect_options *ndo,
1461 const struct isis_spb_mcid *mcid)
1462 {
1463 int i;
1464
1465 ND_TCHECK_SIZE(mcid);
1466 ND_PRINT("ID: %u, Name: ", GET_U_1(mcid->format_id));
1467
1468 if (nd_printzp(ndo, mcid->name, 32, ndo->ndo_snapend))
1469 goto trunc;
1470
1471 ND_PRINT("\n\t Lvl: %u", GET_BE_U_2(mcid->revision_lvl));
1472
1473 ND_PRINT(", Digest: ");
1474
1475 for(i=0;i<16;i++)
1476 ND_PRINT("%.2x ", mcid->digest[i]);
1477 return;
1478
1479 trunc:
1480 nd_print_trunc(ndo);
1481 }
1482
1483 static int
1484 isis_print_mt_port_cap_subtlv(netdissect_options *ndo,
1485 const uint8_t *tptr, u_int len)
1486 {
1487 u_int stlv_type, stlv_len;
1488 const struct isis_subtlv_spb_mcid *subtlv_spb_mcid;
1489 int i;
1490
1491 while (len > 2)
1492 {
1493 stlv_type = GET_U_1(tptr);
1494 stlv_len = GET_U_1(tptr + 1);
1495
1496 /* first lets see if we know the subTLVs name*/
1497 ND_PRINT("\n\t %s subTLV #%u, length: %u",
1498 tok2str(isis_mt_port_cap_subtlv_values, "unknown", stlv_type),
1499 stlv_type,
1500 stlv_len);
1501
1502 tptr += 2;
1503 /*len -= TLV_TYPE_LEN_OFFSET;*/
1504 len -= 2;
1505
1506 /* Make sure the subTLV fits within the space left */
1507 if (len < stlv_len)
1508 goto subtlv_too_long;
1509 /* Make sure the entire subTLV is in the captured data */
1510 ND_TCHECK_LEN(tptr, stlv_len);
1511
1512 switch (stlv_type)
1513 {
1514 case ISIS_SUBTLV_SPB_MCID:
1515 {
1516 if (stlv_len < ISIS_SUBTLV_SPB_MCID_MIN_LEN)
1517 goto subtlv_too_short;
1518
1519 subtlv_spb_mcid = (const struct isis_subtlv_spb_mcid *)tptr;
1520
1521 ND_PRINT("\n\t MCID: ");
1522 isis_print_mcid(ndo, &(subtlv_spb_mcid->mcid));
1523
1524 /*tptr += SPB_MCID_MIN_LEN;
1525 len -= SPB_MCID_MIN_LEN; */
1526
1527 ND_PRINT("\n\t AUX-MCID: ");
1528 isis_print_mcid(ndo, &(subtlv_spb_mcid->aux_mcid));
1529
1530 /*tptr += SPB_MCID_MIN_LEN;
1531 len -= SPB_MCID_MIN_LEN; */
1532 tptr += ISIS_SUBTLV_SPB_MCID_MIN_LEN;
1533 len -= ISIS_SUBTLV_SPB_MCID_MIN_LEN;
1534 stlv_len -= ISIS_SUBTLV_SPB_MCID_MIN_LEN;
1535
1536 break;
1537 }
1538
1539 case ISIS_SUBTLV_SPB_DIGEST:
1540 {
1541 if (stlv_len < ISIS_SUBTLV_SPB_DIGEST_MIN_LEN)
1542 goto subtlv_too_short;
1543
1544 ND_PRINT("\n\t RES: %u V: %u A: %u D: %u",
1545 (GET_U_1(tptr) >> 5),
1546 ((GET_U_1(tptr) >> 4) & 0x01),
1547 ((GET_U_1(tptr) >> 2) & 0x03),
1548 (GET_U_1(tptr) & 0x03));
1549
1550 tptr++;
1551
1552 ND_PRINT("\n\t Digest: ");
1553
1554 for(i=1;i<=8; i++)
1555 {
1556 ND_PRINT("%08x ", GET_BE_U_4(tptr));
1557 if (i%4 == 0 && i != 8)
1558 ND_PRINT("\n\t ");
1559 tptr += 4;
1560 }
1561
1562 len -= ISIS_SUBTLV_SPB_DIGEST_MIN_LEN;
1563 stlv_len -= ISIS_SUBTLV_SPB_DIGEST_MIN_LEN;
1564
1565 break;
1566 }
1567
1568 case ISIS_SUBTLV_SPB_BVID:
1569 {
1570 while (stlv_len != 0)
1571 {
1572 if (stlv_len < 4)
1573 goto subtlv_too_short;
1574 ND_PRINT("\n\t ECT: %08x",
1575 GET_BE_U_4(tptr));
1576
1577 tptr += 4;
1578 len -= 4;
1579 stlv_len -= 4;
1580
1581 if (stlv_len < 2)
1582 goto subtlv_too_short;
1583 ND_PRINT(" BVID: %u, U:%01x M:%01x ",
1584 (GET_BE_U_2(tptr) >> 4) ,
1585 (GET_BE_U_2(tptr) >> 3) & 0x01,
1586 (GET_BE_U_2(tptr) >> 2) & 0x01);
1587
1588 tptr += 2;
1589 len -= 2;
1590 stlv_len -= 2;
1591 }
1592
1593 break;
1594 }
1595
1596 default:
1597 break;
1598 }
1599 tptr += stlv_len;
1600 len -= stlv_len;
1601 }
1602 return (0);
1603
1604 trunc:
1605 nd_print_trunc(ndo);
1606 return (1);
1607
1608 subtlv_too_long:
1609 ND_PRINT(" (> containing TLV length)");
1610 return (1);
1611
1612 subtlv_too_short:
1613 ND_PRINT(" (too short)");
1614 return (1);
1615 }
1616
1617 static int
1618 isis_print_mt_capability_subtlv(netdissect_options *ndo,
1619 const uint8_t *tptr, u_int len)
1620 {
1621 u_int stlv_type, stlv_len, treecount;
1622
1623 while (len > 2)
1624 {
1625 stlv_type = GET_U_1(tptr);
1626 stlv_len = GET_U_1(tptr + 1);
1627 tptr += 2;
1628 len -= 2;
1629
1630 /* first lets see if we know the subTLVs name*/
1631 ND_PRINT("\n\t %s subTLV #%u, length: %u",
1632 tok2str(isis_mt_capability_subtlv_values, "unknown", stlv_type),
1633 stlv_type,
1634 stlv_len);
1635
1636 /* Make sure the subTLV fits within the space left */
1637 if (len < stlv_len)
1638 goto subtlv_too_long;
1639 /* Make sure the entire subTLV is in the captured data */
1640 ND_TCHECK_LEN(tptr, stlv_len);
1641
1642 switch (stlv_type)
1643 {
1644 case ISIS_SUBTLV_SPB_INSTANCE:
1645 if (stlv_len < ISIS_SUBTLV_SPB_INSTANCE_MIN_LEN)
1646 goto subtlv_too_short;
1647
1648 ND_PRINT("\n\t CIST Root-ID: %08x", GET_BE_U_4(tptr));
1649 tptr += 4;
1650 ND_PRINT(" %08x", GET_BE_U_4(tptr));
1651 tptr += 4;
1652 ND_PRINT(", Path Cost: %08x", GET_BE_U_4(tptr));
1653 tptr += 4;
1654 ND_PRINT(", Prio: %u", GET_BE_U_2(tptr));
1655 tptr += 2;
1656 ND_PRINT("\n\t RES: %u",
1657 GET_BE_U_2(tptr) >> 5);
1658 ND_PRINT(", V: %u",
1659 (GET_BE_U_2(tptr) >> 4) & 0x0001);
1660 ND_PRINT(", SPSource-ID: %u",
1661 (GET_BE_U_4(tptr) & 0x000fffff));
1662 tptr += 4;
1663 ND_PRINT(", No of Trees: %x", GET_U_1(tptr));
1664
1665 treecount = GET_U_1(tptr);
1666 tptr++;
1667
1668 len -= ISIS_SUBTLV_SPB_INSTANCE_MIN_LEN;
1669 stlv_len -= ISIS_SUBTLV_SPB_INSTANCE_MIN_LEN;
1670
1671 while (treecount)
1672 {
1673 if (stlv_len < ISIS_SUBTLV_SPB_INSTANCE_VLAN_TUPLE_LEN)
1674 goto trunc;
1675
1676 ND_PRINT("\n\t U:%u, M:%u, A:%u, RES:%u",
1677 GET_U_1(tptr) >> 7,
1678 (GET_U_1(tptr) >> 6) & 0x01,
1679 (GET_U_1(tptr) >> 5) & 0x01,
1680 (GET_U_1(tptr) & 0x1f));
1681
1682 tptr++;
1683
1684 ND_PRINT(", ECT: %08x", GET_BE_U_4(tptr));
1685
1686 tptr += 4;
1687
1688 ND_PRINT(", BVID: %u, SPVID: %u",
1689 (GET_BE_U_3(tptr) >> 12) & 0x000fff,
1690 GET_BE_U_3(tptr) & 0x000fff);
1691
1692 tptr += 3;
1693 len -= ISIS_SUBTLV_SPB_INSTANCE_VLAN_TUPLE_LEN;
1694 stlv_len -= ISIS_SUBTLV_SPB_INSTANCE_VLAN_TUPLE_LEN;
1695 treecount--;
1696 }
1697
1698 break;
1699
1700 case ISIS_SUBTLV_SPBM_SI:
1701 if (stlv_len < 8)
1702 goto trunc;
1703
1704 ND_PRINT("\n\t BMAC: %08x", GET_BE_U_4(tptr));
1705 tptr += 4;
1706 ND_PRINT("%04x", GET_BE_U_2(tptr));
1707 tptr += 2;
1708
1709 ND_PRINT(", RES: %u, VID: %u", GET_BE_U_2(tptr) >> 12,
1710 (GET_BE_U_2(tptr)) & 0x0fff);
1711
1712 tptr += 2;
1713 len -= 8;
1714 stlv_len -= 8;
1715
1716 while (stlv_len >= 4) {
1717 ND_PRINT("\n\t T: %u, R: %u, RES: %u, ISID: %u",
1718 (GET_BE_U_4(tptr) >> 31),
1719 (GET_BE_U_4(tptr) >> 30) & 0x01,
1720 (GET_BE_U_4(tptr) >> 24) & 0x03f,
1721 (GET_BE_U_4(tptr)) & 0x0ffffff);
1722
1723 tptr += 4;
1724 len -= 4;
1725 stlv_len -= 4;
1726 }
1727
1728 break;
1729
1730 default:
1731 break;
1732 }
1733 tptr += stlv_len;
1734 len -= stlv_len;
1735 }
1736 return (0);
1737
1738 trunc:
1739 nd_print_trunc(ndo);
1740 return (1);
1741
1742 subtlv_too_long:
1743 ND_PRINT(" (> containing TLV length)");
1744 return (1);
1745
1746 subtlv_too_short:
1747 ND_PRINT(" (too short)");
1748 return (1);
1749 }
1750
1751 /* shared routine for printing system, node and lsp-ids */
1752 static char *
1753 isis_print_id(netdissect_options *ndo, const uint8_t *cp, u_int id_len)
1754 {
1755 u_int i;
1756 static char id[sizeof("xxxx.xxxx.xxxx.yy-zz")];
1757 char *pos = id;
1758 u_int sysid_len;
1759
1760 sysid_len = SYSTEM_ID_LEN;
1761 if (sysid_len > id_len)
1762 sysid_len = id_len;
1763 for (i = 1; i <= sysid_len; i++) {
1764 snprintf(pos, sizeof(id) - (pos - id), "%02x", GET_U_1(cp));
1765 cp++;
1766 pos += strlen(pos);
1767 if (i == 2 || i == 4)
1768 *pos++ = '.';
1769 }
1770 if (id_len >= NODE_ID_LEN) {
1771 snprintf(pos, sizeof(id) - (pos - id), ".%02x", GET_U_1(cp));
1772 cp++;
1773 pos += strlen(pos);
1774 }
1775 if (id_len == LSP_ID_LEN)
1776 snprintf(pos, sizeof(id) - (pos - id), "-%02x", GET_U_1(cp));
1777 return (id);
1778 }
1779
1780 /* print the 4-byte metric block which is common found in the old-style TLVs */
1781 static int
1782 isis_print_metric_block(netdissect_options *ndo,
1783 const struct isis_metric_block *isis_metric_block)
1784 {
1785 ND_PRINT(", Default Metric: %u, %s",
1786 ISIS_LSP_TLV_METRIC_VALUE(isis_metric_block->metric_default),
1787 ISIS_LSP_TLV_METRIC_IE(isis_metric_block->metric_default) ? "External" : "Internal");
1788 if (!ISIS_LSP_TLV_METRIC_SUPPORTED(isis_metric_block->metric_delay))
1789 ND_PRINT("\n\t\t Delay Metric: %u, %s",
1790 ISIS_LSP_TLV_METRIC_VALUE(isis_metric_block->metric_delay),
1791 ISIS_LSP_TLV_METRIC_IE(isis_metric_block->metric_delay) ? "External" : "Internal");
1792 if (!ISIS_LSP_TLV_METRIC_SUPPORTED(isis_metric_block->metric_expense))
1793 ND_PRINT("\n\t\t Expense Metric: %u, %s",
1794 ISIS_LSP_TLV_METRIC_VALUE(isis_metric_block->metric_expense),
1795 ISIS_LSP_TLV_METRIC_IE(isis_metric_block->metric_expense) ? "External" : "Internal");
1796 if (!ISIS_LSP_TLV_METRIC_SUPPORTED(isis_metric_block->metric_error))
1797 ND_PRINT("\n\t\t Error Metric: %u, %s",
1798 ISIS_LSP_TLV_METRIC_VALUE(isis_metric_block->metric_error),
1799 ISIS_LSP_TLV_METRIC_IE(isis_metric_block->metric_error) ? "External" : "Internal");
1800
1801 return(1); /* everything is ok */
1802 }
1803
1804 static int
1805 isis_print_tlv_ip_reach(netdissect_options *ndo,
1806 const uint8_t *cp, const char *ident, u_int length)
1807 {
1808 int prefix_len;
1809 const struct isis_tlv_ip_reach *tlv_ip_reach;
1810
1811 tlv_ip_reach = (const struct isis_tlv_ip_reach *)cp;
1812
1813 while (length > 0) {
1814 if ((size_t)length < sizeof(*tlv_ip_reach)) {
1815 ND_PRINT("short IPv4 Reachability (%u vs %zu)",
1816 length,
1817 sizeof(*tlv_ip_reach));
1818 return (0);
1819 }
1820
1821 ND_TCHECK_SIZE(tlv_ip_reach);
1822
1823 prefix_len = mask2plen(GET_IPV4_TO_HOST_ORDER(tlv_ip_reach->mask));
1824
1825 if (prefix_len == -1)
1826 ND_PRINT("%sIPv4 prefix: %s mask %s",
1827 ident,
1828 GET_IPADDR_STRING(tlv_ip_reach->prefix),
1829 GET_IPADDR_STRING(tlv_ip_reach->mask));
1830 else
1831 ND_PRINT("%sIPv4 prefix: %15s/%u",
1832 ident,
1833 GET_IPADDR_STRING(tlv_ip_reach->prefix),
1834 prefix_len);
1835
1836 ND_PRINT(", Distribution: %s, Metric: %u, %s",
1837 ISIS_LSP_TLV_METRIC_UPDOWN(tlv_ip_reach->isis_metric_block.metric_default) ? "down" : "up",
1838 ISIS_LSP_TLV_METRIC_VALUE(tlv_ip_reach->isis_metric_block.metric_default),
1839 ISIS_LSP_TLV_METRIC_IE(tlv_ip_reach->isis_metric_block.metric_default) ? "External" : "Internal");
1840
1841 if (!ISIS_LSP_TLV_METRIC_SUPPORTED(tlv_ip_reach->isis_metric_block.metric_delay))
1842 ND_PRINT("%s Delay Metric: %u, %s",
1843 ident,
1844 ISIS_LSP_TLV_METRIC_VALUE(tlv_ip_reach->isis_metric_block.metric_delay),
1845 ISIS_LSP_TLV_METRIC_IE(tlv_ip_reach->isis_metric_block.metric_delay) ? "External" : "Internal");
1846
1847 if (!ISIS_LSP_TLV_METRIC_SUPPORTED(tlv_ip_reach->isis_metric_block.metric_expense))
1848 ND_PRINT("%s Expense Metric: %u, %s",
1849 ident,
1850 ISIS_LSP_TLV_METRIC_VALUE(tlv_ip_reach->isis_metric_block.metric_expense),
1851 ISIS_LSP_TLV_METRIC_IE(tlv_ip_reach->isis_metric_block.metric_expense) ? "External" : "Internal");
1852
1853 if (!ISIS_LSP_TLV_METRIC_SUPPORTED(tlv_ip_reach->isis_metric_block.metric_error))
1854 ND_PRINT("%s Error Metric: %u, %s",
1855 ident,
1856 ISIS_LSP_TLV_METRIC_VALUE(tlv_ip_reach->isis_metric_block.metric_error),
1857 ISIS_LSP_TLV_METRIC_IE(tlv_ip_reach->isis_metric_block.metric_error) ? "External" : "Internal");
1858
1859 length -= sizeof(struct isis_tlv_ip_reach);
1860 tlv_ip_reach++;
1861 }
1862 return (1);
1863 trunc:
1864 return 0;
1865 }
1866
1867 /*
1868 * this is the common IP-REACH subTLV decoder it is called
1869 * from various EXTD-IP REACH TLVs (135,235,236,237)
1870 */
1871
1872 static int
1873 isis_print_ip_reach_subtlv(netdissect_options *ndo,
1874 const uint8_t *tptr, u_int subt, u_int subl,
1875 const char *ident)
1876 {
1877 /* first lets see if we know the subTLVs name*/
1878 ND_PRINT("%s%s subTLV #%u, length: %u",
1879 ident, tok2str(isis_ext_ip_reach_subtlv_values, "unknown", subt),
1880 subt, subl);
1881
1882 ND_TCHECK_LEN(tptr, subl);
1883
1884 switch(subt) {
1885 case ISIS_SUBTLV_EXTD_IP_REACH_MGMT_PREFIX_COLOR: /* fall through */
1886 case ISIS_SUBTLV_EXTD_IP_REACH_ADMIN_TAG32:
1887 while (subl >= 4) {
1888 ND_PRINT(", 0x%08x (=%u)",
1889 GET_BE_U_4(tptr),
1890 GET_BE_U_4(tptr));
1891 tptr+=4;
1892 subl-=4;
1893 }
1894 break;
1895 case ISIS_SUBTLV_EXTD_IP_REACH_ADMIN_TAG64:
1896 while (subl >= 8) {
1897 ND_PRINT(", 0x%08x%08x",
1898 GET_BE_U_4(tptr),
1899 GET_BE_U_4(tptr + 4));
1900 tptr+=8;
1901 subl-=8;
1902 }
1903 break;
1904 case ISIS_SUBTLV_EXTD_IP_REACH_PREFIX_SID:
1905 {
1906 uint8_t algo, flags;
1907 uint32_t sid;
1908
1909 flags = GET_U_1(tptr);
1910 algo = GET_U_1(tptr+1);
1911
1912 if (flags & ISIS_PREFIX_SID_FLAG_V) {
1913 if (subl < 5)
1914 goto trunc;
1915 sid = GET_BE_U_3(tptr+2);
1916 tptr+=5;
1917 subl-=5;
1918 } else {
1919 if (subl < 6)
1920 goto trunc;
1921 sid = GET_BE_U_4(tptr+2);
1922 tptr+=6;
1923 subl-=6;
1924 }
1925
1926 ND_PRINT(", Flags [%s], Algo %s (%u), %s %u",
1927 bittok2str(prefix_sid_flag_values, "None", flags),
1928 tok2str(prefix_sid_algo_values, "Unknown", algo), algo,
1929 flags & ISIS_PREFIX_SID_FLAG_V ? "label" : "index",
1930 sid);
1931 }
1932 break;
1933 default:
1934 if (!print_unknown_data(ndo, tptr, "\n\t\t ", subl))
1935 return(0);
1936 break;
1937 }
1938 return(1);
1939
1940 trunc:
1941 nd_print_trunc(ndo);
1942 return(0);
1943 }
1944
1945 /*
1946 * this is the common IS-REACH decoder it is called
1947 * from various EXTD-IS REACH style TLVs (22,24,222)
1948 */
1949
1950 static int
1951 isis_print_ext_is_reach(netdissect_options *ndo,
1952 const uint8_t *tptr, const char *ident, u_int tlv_type,
1953 u_int tlv_remaining)
1954 {
1955 char ident_buffer[20];
1956 u_int subtlv_type,subtlv_len,subtlv_sum_len;
1957 int proc_bytes = 0; /* how many bytes did we process ? */
1958 u_int te_class,priority_level,gmpls_switch_cap;
1959 union { /* int to float conversion buffer for several subTLVs */
1960 float f;
1961 uint32_t i;
1962 } bw;
1963
1964 ND_TCHECK_LEN(tptr, NODE_ID_LEN);
1965 if (tlv_remaining < NODE_ID_LEN)
1966 return(0);
1967
1968 ND_PRINT("%sIS Neighbor: %s", ident, isis_print_id(ndo, tptr, NODE_ID_LEN));
1969 tptr+=NODE_ID_LEN;
1970 tlv_remaining-=NODE_ID_LEN;
1971 proc_bytes+=NODE_ID_LEN;
1972
1973 if (tlv_type != ISIS_TLV_IS_ALIAS_ID) { /* the Alias TLV Metric field is implicit 0 */
1974 ND_TCHECK_3(tptr);
1975 if (tlv_remaining < 3)
1976 return(0);
1977 ND_PRINT(", Metric: %u", GET_BE_U_3(tptr));
1978 tptr+=3;
1979 tlv_remaining-=3;
1980 proc_bytes+=3;
1981 }
1982
1983 ND_TCHECK_1(tptr);
1984 if (tlv_remaining < 1)
1985 return(0);
1986 subtlv_sum_len=GET_U_1(tptr); /* read out subTLV length */
1987 tptr++;
1988 tlv_remaining--;
1989 proc_bytes++;
1990 ND_PRINT(", %ssub-TLVs present",subtlv_sum_len ? "" : "no ");
1991 if (subtlv_sum_len) {
1992 ND_PRINT(" (%u)", subtlv_sum_len);
1993 /* prepend the indent string */
1994 snprintf(ident_buffer, sizeof(ident_buffer), "%s ",ident);
1995 ident = ident_buffer;
1996 while (subtlv_sum_len != 0) {
1997 ND_TCHECK_2(tptr);
1998 if (tlv_remaining < 2) {
1999 ND_PRINT("%sRemaining data in TLV shorter than a subTLV header",ident);
2000 proc_bytes += tlv_remaining;
2001 break;
2002 }
2003 if (subtlv_sum_len < 2) {
2004 ND_PRINT("%sRemaining data in subTLVs shorter than a subTLV header",ident);
2005 proc_bytes += subtlv_sum_len;
2006 break;
2007 }
2008 subtlv_type=GET_U_1(tptr);
2009 subtlv_len=GET_U_1(tptr + 1);
2010 tptr += 2;
2011 tlv_remaining -= 2;
2012 subtlv_sum_len -= 2;
2013 proc_bytes += 2;
2014 ND_PRINT("%s%s subTLV #%u, length: %u",
2015 ident, tok2str(isis_ext_is_reach_subtlv_values, "unknown", subtlv_type),
2016 subtlv_type, subtlv_len);
2017
2018 if (subtlv_sum_len < subtlv_len) {
2019 ND_PRINT(" (remaining data in subTLVs shorter than the current subTLV)");
2020 proc_bytes += subtlv_sum_len;
2021 break;
2022 }
2023
2024 if (tlv_remaining < subtlv_len) {
2025 ND_PRINT(" (> remaining tlv length)");
2026 proc_bytes += tlv_remaining;
2027 break;
2028 }
2029
2030 ND_TCHECK_LEN(tptr, subtlv_len);
2031
2032 switch(subtlv_type) {
2033 case ISIS_SUBTLV_EXT_IS_REACH_ADMIN_GROUP:
2034 case ISIS_SUBTLV_EXT_IS_REACH_LINK_LOCAL_REMOTE_ID:
2035 case ISIS_SUBTLV_EXT_IS_REACH_LINK_REMOTE_ID:
2036 if (subtlv_len >= 4) {
2037 ND_PRINT(", 0x%08x", GET_BE_U_4(tptr));
2038 if (subtlv_len == 8) /* rfc4205 */
2039 ND_PRINT(", 0x%08x", GET_BE_U_4(tptr + 4));
2040 }
2041 break;
2042 case ISIS_SUBTLV_EXT_IS_REACH_IPV4_INTF_ADDR:
2043 case ISIS_SUBTLV_EXT_IS_REACH_IPV4_NEIGHBOR_ADDR:
2044 if (subtlv_len >= sizeof(nd_ipv4))
2045 ND_PRINT(", %s", GET_IPADDR_STRING(tptr));
2046 break;
2047 case ISIS_SUBTLV_EXT_IS_REACH_MAX_LINK_BW :
2048 case ISIS_SUBTLV_EXT_IS_REACH_RESERVABLE_BW:
2049 if (subtlv_len >= 4) {
2050 bw.i = GET_BE_U_4(tptr);
2051 ND_PRINT(", %.3f Mbps", bw.f * 8 / 1000000);
2052 }
2053 break;
2054 case ISIS_SUBTLV_EXT_IS_REACH_UNRESERVED_BW :
2055 if (subtlv_len >= 32) {
2056 for (te_class = 0; te_class < 8; te_class++) {
2057 bw.i = GET_BE_U_4(tptr);
2058 ND_PRINT("%s TE-Class %u: %.3f Mbps",
2059 ident,
2060 te_class,
2061 bw.f * 8 / 1000000);
2062 tptr += 4;
2063 subtlv_len -= 4;
2064 subtlv_sum_len -= 4;
2065 proc_bytes += 4;
2066 }
2067 }
2068 break;
2069 case ISIS_SUBTLV_EXT_IS_REACH_BW_CONSTRAINTS: /* fall through */
2070 case ISIS_SUBTLV_EXT_IS_REACH_BW_CONSTRAINTS_OLD:
2071 if (subtlv_len == 0)
2072 break;
2073 ND_PRINT("%sBandwidth Constraints Model ID: %s (%u)",
2074 ident,
2075 tok2str(diffserv_te_bc_values, "unknown", GET_U_1(tptr)),
2076 GET_U_1(tptr));
2077 tptr++;
2078 subtlv_len--;
2079 subtlv_sum_len--;
2080 proc_bytes++;
2081 /* decode BCs until the subTLV ends */
2082 for (te_class = 0; subtlv_len != 0; te_class++) {
2083 if (subtlv_len < 4)
2084 break;
2085 bw.i = GET_BE_U_4(tptr);
2086 ND_PRINT("%s Bandwidth constraint CT%u: %.3f Mbps",
2087 ident,
2088 te_class,
2089 bw.f * 8 / 1000000);
2090 tptr += 4;
2091 subtlv_len -= 4;
2092 subtlv_sum_len -= 4;
2093 proc_bytes += 4;
2094 }
2095 break;
2096 case ISIS_SUBTLV_EXT_IS_REACH_TE_METRIC:
2097 if (subtlv_len >= 3)
2098 ND_PRINT(", %u", GET_BE_U_3(tptr));
2099 break;
2100 case ISIS_SUBTLV_EXT_IS_REACH_LINK_ATTRIBUTE:
2101 if (subtlv_len == 2) {
2102 ND_PRINT(", [ %s ] (0x%04x)",
2103 bittok2str(isis_subtlv_link_attribute_values,
2104 "Unknown",
2105 GET_BE_U_2(tptr)),
2106 GET_BE_U_2(tptr));
2107 }
2108 break;
2109 case ISIS_SUBTLV_EXT_IS_REACH_LINK_PROTECTION_TYPE:
2110 if (subtlv_len >= 2) {
2111 ND_PRINT(", %s, Priority %u",
2112 bittok2str(gmpls_link_prot_values, "none", GET_U_1(tptr)),
2113 GET_U_1(tptr + 1));
2114 }
2115 break;
2116 case ISIS_SUBTLV_SPB_METRIC:
2117 if (subtlv_len >= 6) {
2118 ND_PRINT(", LM: %u", GET_BE_U_3(tptr));
2119 tptr += 3;
2120 subtlv_len -= 3;
2121 subtlv_sum_len -= 3;
2122 proc_bytes += 3;
2123 ND_PRINT(", P: %u", GET_U_1(tptr));
2124 tptr++;
2125 subtlv_len--;
2126 subtlv_sum_len--;
2127 proc_bytes++;
2128 ND_PRINT(", P-ID: %u", GET_BE_U_2(tptr));
2129 }
2130 break;
2131 case ISIS_SUBTLV_EXT_IS_REACH_INTF_SW_CAP_DESCR:
2132 if (subtlv_len >= 36) {
2133 gmpls_switch_cap = GET_U_1(tptr);
2134 ND_PRINT("%s Interface Switching Capability:%s",
2135 ident,
2136 tok2str(gmpls_switch_cap_values, "Unknown", gmpls_switch_cap));
2137 ND_PRINT(", LSP Encoding: %s",
2138 tok2str(gmpls_encoding_values, "Unknown", GET_U_1((tptr + 1))));
2139 tptr += 4;
2140 subtlv_len -= 4;
2141 subtlv_sum_len -= 4;
2142 proc_bytes += 4;
2143 ND_PRINT("%s Max LSP Bandwidth:", ident);
2144 for (priority_level = 0; priority_level < 8; priority_level++) {
2145 bw.i = GET_BE_U_4(tptr);
2146 ND_PRINT("%s priority level %u: %.3f Mbps",
2147 ident,
2148 priority_level,
2149 bw.f * 8 / 1000000);
2150 tptr += 4;
2151 subtlv_len -= 4;
2152 subtlv_sum_len -= 4;
2153 proc_bytes += 4;
2154 }
2155 switch (gmpls_switch_cap) {
2156 case GMPLS_PSC1:
2157 case GMPLS_PSC2:
2158 case GMPLS_PSC3:
2159 case GMPLS_PSC4:
2160 if (subtlv_len < 6)
2161 break;
2162 bw.i = GET_BE_U_4(tptr);
2163 ND_PRINT("%s Min LSP Bandwidth: %.3f Mbps", ident, bw.f * 8 / 1000000);
2164 ND_PRINT("%s Interface MTU: %u", ident,
2165 GET_BE_U_2(tptr + 4));
2166 break;
2167 case GMPLS_TSC:
2168 if (subtlv_len < 8)
2169 break;
2170 bw.i = GET_BE_U_4(tptr);
2171 ND_PRINT("%s Min LSP Bandwidth: %.3f Mbps", ident, bw.f * 8 / 1000000);
2172 ND_PRINT("%s Indication %s", ident,
2173 tok2str(gmpls_switch_cap_tsc_indication_values, "Unknown (%u)", GET_U_1((tptr + 4))));
2174 break;
2175 default:
2176 /* there is some optional stuff left to decode but this is as of yet
2177 not specified so just lets hexdump what is left */
2178 if (subtlv_len != 0) {
2179 if (!print_unknown_data(ndo, tptr, "\n\t\t ", subtlv_len))
2180 return(0);
2181 }
2182 }
2183 }
2184 break;
2185 case ISIS_SUBTLV_EXT_IS_REACH_LAN_ADJ_SEGMENT_ID:
2186 if (subtlv_len >= 8) {
2187 ND_PRINT("%s Flags: [%s]", ident,
2188 bittok2str(isis_lan_adj_sid_flag_values,
2189 "none",
2190 GET_U_1(tptr)));
2191 int vflag = (GET_U_1(tptr) & 0x20) ? 1:0;
2192 int lflag = (GET_U_1(tptr) & 0x10) ? 1:0;
2193 tptr++;
2194 subtlv_len--;
2195 subtlv_sum_len--;
2196 proc_bytes++;
2197 ND_PRINT("%s Weight: %u", ident, GET_U_1(tptr));
2198 tptr++;
2199 subtlv_len--;
2200 subtlv_sum_len--;
2201 proc_bytes++;
2202 if(subtlv_len>=SYSTEM_ID_LEN) {
2203 ND_TCHECK_LEN(tptr, SYSTEM_ID_LEN);
2204 ND_PRINT("%s Neighbor System-ID: %s", ident,
2205 isis_print_id(ndo, tptr, SYSTEM_ID_LEN));
2206 }
2207 /* RFC 8667 section 2.2.2 */
2208 /* if V-flag is set to 1 and L-flag is set to 1 ==> 3 octet label */
2209 /* if V-flag is set to 0 and L-flag is set to 0 ==> 4 octet index */
2210 if (vflag && lflag) {
2211 ND_PRINT("%s Label: %u",
2212 ident, GET_BE_U_3(tptr+SYSTEM_ID_LEN));
2213 } else if ((!vflag) && (!lflag)) {
2214 ND_PRINT("%s Index: %u",
2215 ident, GET_BE_U_4(tptr+SYSTEM_ID_LEN));
2216 } else
2217 nd_print_invalid(ndo);
2218 }
2219 break;
2220 default:
2221 if (!print_unknown_data(ndo, tptr, "\n\t\t ", subtlv_len))
2222 return(0);
2223 break;
2224 }
2225
2226 tptr += subtlv_len;
2227 tlv_remaining -= subtlv_len;
2228 subtlv_sum_len -= subtlv_len;
2229 proc_bytes += subtlv_len;
2230 }
2231 }
2232 return(proc_bytes);
2233
2234 trunc:
2235 return(0);
2236 }
2237
2238 /*
2239 * this is the common Multi Topology ID decoder
2240 * it is called from various MT-TLVs (222,229,235,237)
2241 */
2242
2243 static uint8_t
2244 isis_print_mtid(netdissect_options *ndo,
2245 const uint8_t *tptr, const char *ident, u_int tlv_remaining)
2246 {
2247 if (tlv_remaining < 2)
2248 goto trunc;
2249
2250 ND_PRINT("%s%s",
2251 ident,
2252 tok2str(isis_mt_values,
2253 "Reserved for IETF Consensus",
2254 ISIS_MASK_MTID(GET_BE_U_2(tptr))));
2255
2256 ND_PRINT(" Topology (0x%03x), Flags: [%s]",
2257 ISIS_MASK_MTID(GET_BE_U_2(tptr)),
2258 bittok2str(isis_mt_flag_values, "none",ISIS_MASK_MTFLAGS(GET_BE_U_2(tptr))));
2259
2260 return(2);
2261 trunc:
2262 return 0;
2263 }
2264
2265 /*
2266 * this is the common extended IP reach decoder
2267 * it is called from TLVs (135,235,236,237)
2268 * we process the TLV and optional subTLVs and return
2269 * the amount of processed bytes
2270 */
2271
2272 static u_int
2273 isis_print_extd_ip_reach(netdissect_options *ndo,
2274 const uint8_t *tptr, const char *ident, uint16_t afi)
2275 {
2276 char ident_buffer[20];
2277 uint8_t prefix[sizeof(nd_ipv6)]; /* shared copy buffer for IPv4 and IPv6 prefixes */
2278 u_int metric, status_byte, bit_length, byte_length, sublen, processed, subtlvtype, subtlvlen;
2279
2280 metric = GET_BE_U_4(tptr);
2281 processed=4;
2282 tptr+=4;
2283
2284 if (afi == AF_INET) {
2285 status_byte=GET_U_1(tptr);
2286 tptr++;
2287 bit_length = status_byte&0x3f;
2288 if (bit_length > 32) {
2289 ND_PRINT("%sIPv4 prefix: bad bit length %u",
2290 ident,
2291 bit_length);
2292 return (0);
2293 }
2294 processed++;
2295 } else if (afi == AF_INET6) {
2296 status_byte=GET_U_1(tptr);
2297 bit_length=GET_U_1(tptr + 1);
2298 if (bit_length > 128) {
2299 ND_PRINT("%sIPv6 prefix: bad bit length %u",
2300 ident,
2301 bit_length);
2302 return (0);
2303 }
2304 tptr+=2;
2305 processed+=2;
2306 } else
2307 return (0); /* somebody is fooling us */
2308
2309 byte_length = (bit_length + 7) / 8; /* prefix has variable length encoding */
2310
2311 ND_TCHECK_LEN(tptr, byte_length);
2312 memset(prefix, 0, sizeof(prefix)); /* clear the copy buffer */
2313 memcpy(prefix,tptr,byte_length); /* copy as much as is stored in the TLV */
2314 tptr+=byte_length;
2315 processed+=byte_length;
2316
2317 if (afi == AF_INET)
2318 ND_PRINT("%sIPv4 prefix: %15s/%u",
2319 ident,
2320 ipaddr_string(ndo, prefix), /* local buffer, not packet data; don't use GET_IPADDR_STRING() */
2321 bit_length);
2322 else if (afi == AF_INET6)
2323 ND_PRINT("%sIPv6 prefix: %s/%u",
2324 ident,
2325 ip6addr_string(ndo, prefix), /* local buffer, not packet data; don't use GET_IP6ADDR_STRING() */
2326 bit_length);
2327
2328 ND_PRINT(", Distribution: %s, Metric: %u",
2329 ISIS_MASK_TLV_EXTD_IP_UPDOWN(status_byte) ? "down" : "up",
2330 metric);
2331
2332 if (afi == AF_INET && ISIS_MASK_TLV_EXTD_IP_SUBTLV(status_byte))
2333 ND_PRINT(", sub-TLVs present");
2334 else if (afi == AF_INET6)
2335 ND_PRINT(", %s%s",
2336 ISIS_MASK_TLV_EXTD_IP6_IE(status_byte) ? "External" : "Internal",
2337 ISIS_MASK_TLV_EXTD_IP6_SUBTLV(status_byte) ? ", sub-TLVs present" : "");
2338
2339 if ((afi == AF_INET && ISIS_MASK_TLV_EXTD_IP_SUBTLV(status_byte))
2340 || (afi == AF_INET6 && ISIS_MASK_TLV_EXTD_IP6_SUBTLV(status_byte))
2341 ) {
2342 /* assume that one prefix can hold more
2343 than one subTLV - therefore the first byte must reflect
2344 the aggregate bytecount of the subTLVs for this prefix
2345 */
2346 sublen=GET_U_1(tptr);
2347 tptr++;
2348 processed+=sublen+1;
2349 ND_PRINT(" (%u)", sublen); /* print out subTLV length */
2350
2351 while (sublen>0) {
2352 subtlvtype=GET_U_1(tptr);
2353 subtlvlen=GET_U_1(tptr + 1);
2354 tptr+=2;
2355 /* prepend the indent string */
2356 snprintf(ident_buffer, sizeof(ident_buffer), "%s ",ident);
2357 if (!isis_print_ip_reach_subtlv(ndo, tptr, subtlvtype, subtlvlen, ident_buffer))
2358 return(0);
2359 tptr+=subtlvlen;
2360 sublen-=(subtlvlen+2);
2361 }
2362 }
2363 return (processed);
2364 trunc:
2365 return 0;
2366 }
2367
2368 static void
2369 isis_print_router_cap_subtlv(netdissect_options *ndo, const uint8_t *tptr, uint8_t tlen)
2370 {
2371 uint8_t subt, subl;
2372
2373 while (tlen >= 2) {
2374 subt = GET_U_1(tptr);
2375 subl = GET_U_1(tptr+1);
2376 tlen -= 2;
2377 tptr += 2;
2378
2379 /* first lets see if we know the subTLVs name*/
2380 ND_PRINT("\n\t\t%s subTLV #%u, length: %u",
2381 tok2str(isis_router_capability_subtlv_values, "unknown", subt),
2382 subt, subl);
2383
2384 /*
2385 * Boundary check.
2386 */
2387 if (subl > tlen) {
2388 break;
2389 }
2390 ND_TCHECK_LEN(tptr, subl);
2391
2392 switch (subt) {
2393 case ISIS_SUBTLV_ROUTER_CAP_SR:
2394 {
2395 uint8_t flags, sid_tlen, sid_type, sid_len;
2396 uint32_t range;
2397 const uint8_t *sid_ptr;
2398
2399 flags = GET_U_1(tptr);
2400 range = GET_BE_U_3(tptr+1);
2401 ND_PRINT(", Flags [%s], Range %u",
2402 bittok2str(isis_router_capability_sr_flags, "None", flags),
2403 range);
2404 sid_ptr = tptr + 4;
2405 sid_tlen = subl - 4;
2406
2407 while (sid_tlen >= 5) {
2408 sid_type = GET_U_1(sid_ptr);
2409 sid_len = GET_U_1(sid_ptr+1);
2410 sid_tlen -= 2;
2411 sid_ptr += 2;
2412
2413 /*
2414 * Boundary check.
2415 */
2416 if (sid_len > sid_tlen) {
2417 break;
2418 }
2419
2420 switch (sid_type) {
2421 case 1:
2422 if (sid_len == 3) {
2423 ND_PRINT(", SID value %u", GET_BE_U_3(sid_ptr));
2424 } else if (sid_len == 4) {
2425 ND_PRINT(", SID value %u", GET_BE_U_4(sid_ptr));
2426 } else {
2427 ND_PRINT(", Unknown SID length%u", sid_len);
2428 }
2429 break;
2430 default:
2431 print_unknown_data(ndo, sid_ptr, "\n\t\t ", sid_len);
2432 }
2433
2434 sid_ptr += sid_len;
2435 sid_tlen -= sid_len;
2436 }
2437 }
2438 break;
2439 default:
2440 print_unknown_data(ndo, tptr, "\n\t\t", subl);
2441 break;
2442 }
2443
2444 tlen -= subl;
2445 tptr += subl;
2446 }
2447 trunc:
2448 return;
2449 }
2450
2451 /*
2452 * Clear checksum and lifetime prior to signature verification.
2453 */
2454 static void
2455 isis_clear_checksum_lifetime(void *header)
2456 {
2457 struct isis_lsp_header *header_lsp = (struct isis_lsp_header *) header;
2458
2459 header_lsp->checksum[0] = 0;
2460 header_lsp->checksum[1] = 0;
2461 header_lsp->remaining_lifetime[0] = 0;
2462 header_lsp->remaining_lifetime[1] = 0;
2463 }
2464
2465 /*
2466 * isis_print
2467 * Decode IS-IS packets. Return 0 on error.
2468 */
2469
2470 #define INVALID_OR_DECREMENT(length,decr) \
2471 if ((length) < (decr)) { \
2472 ND_PRINT(" [packet length %u < %zu]", (length), (decr)); \
2473 nd_print_invalid(ndo); \
2474 return 1; \
2475 } \
2476 length -= (decr);
2477
2478 static int
2479 isis_print(netdissect_options *ndo,
2480 const uint8_t *p, u_int length)
2481 {
2482 const struct isis_common_header *isis_header;
2483
2484 const struct isis_iih_lan_header *header_iih_lan;
2485 const struct isis_iih_ptp_header *header_iih_ptp;
2486 const struct isis_lsp_header *header_lsp;
2487 const struct isis_csnp_header *header_csnp;
2488 const struct isis_psnp_header *header_psnp;
2489
2490 const struct isis_tlv_lsp *tlv_lsp;
2491 const struct isis_tlv_ptp_adj *tlv_ptp_adj;
2492 const struct isis_tlv_is_reach *tlv_is_reach;
2493 const struct isis_tlv_es_reach *tlv_es_reach;
2494
2495 uint8_t version, pdu_version, fixed_len;
2496 uint8_t pdu_type, pdu_max_area, max_area, pdu_id_length, id_length, tlv_type, tlv_len, tlen, alen, prefix_len;
2497 u_int ext_is_len, ext_ip_len;
2498 uint8_t mt_len;
2499 uint8_t isis_subtlv_idrp;
2500 const uint8_t *optr, *pptr, *tptr;
2501 u_int packet_len;
2502 u_short pdu_len, key_id;
2503 u_int i,vendor_id, num_vals;
2504 uint8_t auth_type;
2505 uint8_t num_system_ids;
2506 int sigcheck;
2507
2508 ndo->ndo_protocol = "isis";
2509 packet_len=length;
2510 optr = p; /* initialize the _o_riginal pointer to the packet start -
2511 need it for parsing the checksum TLV and authentication
2512 TLV verification */
2513 isis_header = (const struct isis_common_header *)p;
2514 ND_TCHECK_SIZE(isis_header);
2515 if (length < ISIS_COMMON_HEADER_SIZE)
2516 goto trunc;
2517 pptr = p+(ISIS_COMMON_HEADER_SIZE);
2518 header_iih_lan = (const struct isis_iih_lan_header *)pptr;
2519 header_iih_ptp = (const struct isis_iih_ptp_header *)pptr;
2520 header_lsp = (const struct isis_lsp_header *)pptr;
2521 header_csnp = (const struct isis_csnp_header *)pptr;
2522 header_psnp = (const struct isis_psnp_header *)pptr;
2523
2524 if (!ndo->ndo_eflag)
2525 ND_PRINT("IS-IS");
2526
2527 /*
2528 * Sanity checking of the header.
2529 */
2530
2531 version = GET_U_1(isis_header->version);
2532 if (version != ISIS_VERSION) {
2533 ND_PRINT("version %u packet not supported", version);
2534 return (0);
2535 }
2536
2537 pdu_id_length = GET_U_1(isis_header->id_length);
2538 if ((pdu_id_length != SYSTEM_ID_LEN) && (pdu_id_length != 0)) {
2539 ND_PRINT("system ID length of %u is not supported",
2540 pdu_id_length);
2541 return (0);
2542 }
2543
2544 pdu_version = GET_U_1(isis_header->pdu_version);
2545 if (pdu_version != ISIS_VERSION) {
2546 ND_PRINT("version %u packet not supported", pdu_version);
2547 return (0);
2548 }
2549
2550 fixed_len = GET_U_1(isis_header->fixed_len);
2551 if (length < fixed_len) {
2552 ND_PRINT("fixed header length %u > packet length %u", fixed_len, length);
2553 return (0);
2554 }
2555
2556 if (fixed_len < ISIS_COMMON_HEADER_SIZE) {
2557 ND_PRINT("fixed header length %u < minimum header size %u", fixed_len, (u_int)ISIS_COMMON_HEADER_SIZE);
2558 return (0);
2559 }
2560
2561 pdu_max_area = GET_U_1(isis_header->max_area);
2562 switch(pdu_max_area) {
2563 case 0:
2564 max_area = 3; /* silly shit */
2565 break;
2566 case 255:
2567 ND_PRINT("bad packet -- 255 areas");
2568 return (0);
2569 default:
2570 max_area = pdu_max_area;
2571 break;
2572 }
2573
2574 switch(pdu_id_length) {
2575 case 0:
2576 id_length = 6; /* silly shit again */
2577 break;
2578 case 1: /* 1-8 are valid sys-ID lengths */
2579 case 2:
2580 case 3:
2581 case 4:
2582 case 5:
2583 case 6:
2584 case 7:
2585 case 8:
2586 id_length = pdu_id_length;
2587 break;
2588 case 255:
2589 id_length = 0; /* entirely useless */
2590 break;
2591 default:
2592 id_length = pdu_id_length;
2593 break;
2594 }
2595
2596 /* toss any non 6-byte sys-ID len PDUs */
2597 if (id_length != 6 ) {
2598 ND_PRINT("bad packet -- illegal sys-ID length (%u)", id_length);
2599 return (0);
2600 }
2601
2602 pdu_type = GET_U_1(isis_header->pdu_type);
2603
2604 /* in non-verbose mode print the basic PDU Type plus PDU specific brief information*/
2605 if (ndo->ndo_vflag == 0) {
2606 ND_PRINT("%s%s",
2607 ndo->ndo_eflag ? "" : ", ",
2608 tok2str(isis_pdu_values, "unknown PDU-Type %u", pdu_type));
2609 } else {
2610 /* ok they seem to want to know everything - lets fully decode it */
2611 ND_PRINT("%slength %u", ndo->ndo_eflag ? "" : ", ", length);
2612
2613 ND_PRINT("\n\t%s, hlen: %u, v: %u, pdu-v: %u, sys-id-len: %u (%u), max-area: %u (%u)",
2614 tok2str(isis_pdu_values,
2615 "unknown, type %u",
2616 pdu_type),
2617 fixed_len,
2618 version,
2619 pdu_version,
2620 id_length,
2621 pdu_id_length,
2622 max_area,
2623 pdu_max_area);
2624
2625 if (ndo->ndo_vflag > 1) {
2626 if (!print_unknown_data(ndo, optr, "\n\t", 8)) /* provide the _o_riginal pointer */
2627 return (0); /* for optionally debugging the common header */
2628 }
2629 }
2630
2631 switch (pdu_type) {
2632
2633 case ISIS_PDU_L1_LAN_IIH:
2634 case ISIS_PDU_L2_LAN_IIH:
2635 if (fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_LAN_HEADER_SIZE)) {
2636 ND_PRINT(", bogus fixed header length %u should be %zu",
2637 fixed_len, ISIS_COMMON_HEADER_SIZE+ISIS_IIH_LAN_HEADER_SIZE);
2638 return (0);
2639 }
2640 ND_TCHECK_SIZE(header_iih_lan);
2641 if (length < ISIS_COMMON_HEADER_SIZE+ISIS_IIH_LAN_HEADER_SIZE)
2642 goto trunc;
2643 if (ndo->ndo_vflag == 0) {
2644 ND_PRINT(", src-id %s",
2645 isis_print_id(ndo, header_iih_lan->source_id, SYSTEM_ID_LEN));
2646 ND_PRINT(", lan-id %s, prio %u",
2647 isis_print_id(ndo, header_iih_lan->lan_id,NODE_ID_LEN),
2648 GET_U_1(header_iih_lan->priority));
2649 ND_PRINT(", length %u", length);
2650 return (1);
2651 }
2652 pdu_len=GET_BE_U_2(header_iih_lan->pdu_len);
2653 if (packet_len>pdu_len) {
2654 packet_len=pdu_len; /* do TLV decoding as long as it makes sense */
2655 length=pdu_len;
2656 }
2657
2658 ND_PRINT("\n\t source-id: %s, holding time: %us, Flags: [%s]",
2659 isis_print_id(ndo, header_iih_lan->source_id,SYSTEM_ID_LEN),
2660 GET_BE_U_2(header_iih_lan->holding_time),
2661 tok2str(isis_iih_circuit_type_values,
2662 "unknown circuit type 0x%02x",
2663 GET_U_1(header_iih_lan->circuit_type)));
2664
2665 ND_PRINT("\n\t lan-id: %s, Priority: %u, PDU length: %u",
2666 isis_print_id(ndo, header_iih_lan->lan_id, NODE_ID_LEN),
2667 GET_U_1(header_iih_lan->priority) & ISIS_LAN_PRIORITY_MASK,
2668 pdu_len);
2669
2670 if (ndo->ndo_vflag > 1) {
2671 if (!print_unknown_data(ndo, pptr, "\n\t ", ISIS_IIH_LAN_HEADER_SIZE))
2672 return (0);
2673 }
2674
2675 INVALID_OR_DECREMENT(packet_len,ISIS_COMMON_HEADER_SIZE+ISIS_IIH_LAN_HEADER_SIZE);
2676 pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_LAN_HEADER_SIZE);
2677 break;
2678
2679 case ISIS_PDU_PTP_IIH:
2680 if (fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_PTP_HEADER_SIZE)) {
2681 ND_PRINT(", bogus fixed header length %u should be %zu",
2682 fixed_len, ISIS_COMMON_HEADER_SIZE+ISIS_IIH_PTP_HEADER_SIZE);
2683 return (0);
2684 }
2685 ND_TCHECK_SIZE(header_iih_ptp);
2686 if (length < ISIS_COMMON_HEADER_SIZE+ISIS_IIH_PTP_HEADER_SIZE)
2687 goto trunc;
2688 if (ndo->ndo_vflag == 0) {
2689 ND_PRINT(", src-id %s", isis_print_id(ndo, header_iih_ptp->source_id, SYSTEM_ID_LEN));
2690 ND_PRINT(", length %u", length);
2691 return (1);
2692 }
2693 pdu_len=GET_BE_U_2(header_iih_ptp->pdu_len);
2694 if (packet_len>pdu_len) {
2695 packet_len=pdu_len; /* do TLV decoding as long as it makes sense */
2696 length=pdu_len;
2697 }
2698
2699 ND_PRINT("\n\t source-id: %s, holding time: %us, Flags: [%s]",
2700 isis_print_id(ndo, header_iih_ptp->source_id,SYSTEM_ID_LEN),
2701 GET_BE_U_2(header_iih_ptp->holding_time),
2702 tok2str(isis_iih_circuit_type_values,
2703 "unknown circuit type 0x%02x",
2704 GET_U_1(header_iih_ptp->circuit_type)));
2705
2706 ND_PRINT("\n\t circuit-id: 0x%02x, PDU length: %u",
2707 GET_U_1(header_iih_ptp->circuit_id),
2708 pdu_len);
2709
2710 if (ndo->ndo_vflag > 1) {
2711 if (!print_unknown_data(ndo, pptr, "\n\t ", ISIS_IIH_PTP_HEADER_SIZE))
2712 return (0);
2713 }
2714 INVALID_OR_DECREMENT(packet_len,ISIS_COMMON_HEADER_SIZE+ISIS_IIH_PTP_HEADER_SIZE);
2715 pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_PTP_HEADER_SIZE);
2716 break;
2717
2718 case ISIS_PDU_L1_LSP:
2719 case ISIS_PDU_L2_LSP:
2720 if (fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_LSP_HEADER_SIZE)) {
2721 ND_PRINT(", bogus fixed header length %u should be %zu",
2722 fixed_len, ISIS_LSP_HEADER_SIZE);
2723 return (0);
2724 }
2725 ND_TCHECK_SIZE(header_lsp);
2726 if (length < ISIS_COMMON_HEADER_SIZE+ISIS_LSP_HEADER_SIZE)
2727 goto trunc;
2728 if (ndo->ndo_vflag == 0) {
2729 ND_PRINT(", lsp-id %s, seq 0x%08x, lifetime %5us",
2730 isis_print_id(ndo, header_lsp->lsp_id, LSP_ID_LEN),
2731 GET_BE_U_4(header_lsp->sequence_number),
2732 GET_BE_U_2(header_lsp->remaining_lifetime));
2733 ND_PRINT(", length %u", length);
2734 return (1);
2735 }
2736 pdu_len=GET_BE_U_2(header_lsp->pdu_len);
2737 if (packet_len>pdu_len) {
2738 packet_len=pdu_len; /* do TLV decoding as long as it makes sense */
2739 length=pdu_len;
2740 }
2741
2742 ND_PRINT("\n\t lsp-id: %s, seq: 0x%08x, lifetime: %5us\n\t chksum: 0x%04x",
2743 isis_print_id(ndo, header_lsp->lsp_id, LSP_ID_LEN),
2744 GET_BE_U_4(header_lsp->sequence_number),
2745 GET_BE_U_2(header_lsp->remaining_lifetime),
2746 GET_BE_U_2(header_lsp->checksum));
2747
2748 osi_print_cksum(ndo, (const uint8_t *)header_lsp->lsp_id,
2749 GET_BE_U_2(header_lsp->checksum),
2750 12, length-12);
2751
2752 ND_PRINT(", PDU length: %u, Flags: [ %s",
2753 pdu_len,
2754 ISIS_MASK_LSP_OL_BIT(header_lsp->typeblock) ? "Overload bit set, " : "");
2755
2756 if (ISIS_MASK_LSP_ATT_BITS(header_lsp->typeblock)) {
2757 ND_PRINT("%s", ISIS_MASK_LSP_ATT_DEFAULT_BIT(header_lsp->typeblock) ? "default " : "");
2758 ND_PRINT("%s", ISIS_MASK_LSP_ATT_DELAY_BIT(header_lsp->typeblock) ? "delay " : "");
2759 ND_PRINT("%s", ISIS_MASK_LSP_ATT_EXPENSE_BIT(header_lsp->typeblock) ? "expense " : "");
2760 ND_PRINT("%s", ISIS_MASK_LSP_ATT_ERROR_BIT(header_lsp->typeblock) ? "error " : "");
2761 ND_PRINT("ATT bit set, ");
2762 }
2763 ND_PRINT("%s", ISIS_MASK_LSP_PARTITION_BIT(header_lsp->typeblock) ? "P bit set, " : "");
2764 ND_PRINT("%s ]", tok2str(isis_lsp_istype_values, "Unknown(0x%x)",
2765 ISIS_MASK_LSP_ISTYPE_BITS(header_lsp->typeblock)));
2766
2767 if (ndo->ndo_vflag > 1) {
2768 if (!print_unknown_data(ndo, pptr, "\n\t ", ISIS_LSP_HEADER_SIZE))
2769 return (0);
2770 }
2771
2772 INVALID_OR_DECREMENT(packet_len,ISIS_COMMON_HEADER_SIZE+ISIS_LSP_HEADER_SIZE);
2773 pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_LSP_HEADER_SIZE);
2774 break;
2775
2776 case ISIS_PDU_L1_CSNP:
2777 case ISIS_PDU_L2_CSNP:
2778 if (fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_CSNP_HEADER_SIZE)) {
2779 ND_PRINT(", bogus fixed header length %u should be %zu",
2780 fixed_len, ISIS_COMMON_HEADER_SIZE+ISIS_CSNP_HEADER_SIZE);
2781 return (0);
2782 }
2783 ND_TCHECK_SIZE(header_csnp);
2784 if (length < ISIS_COMMON_HEADER_SIZE+ISIS_CSNP_HEADER_SIZE)
2785 goto trunc;
2786 if (ndo->ndo_vflag == 0) {
2787 ND_PRINT(", src-id %s", isis_print_id(ndo, header_csnp->source_id, NODE_ID_LEN));
2788 ND_PRINT(", length %u", length);
2789 return (1);
2790 }
2791 pdu_len=GET_BE_U_2(header_csnp->pdu_len);
2792 if (packet_len>pdu_len) {
2793 packet_len=pdu_len; /* do TLV decoding as long as it makes sense */
2794 length=pdu_len;
2795 }
2796
2797 ND_PRINT("\n\t source-id: %s, PDU length: %u",
2798 isis_print_id(ndo, header_csnp->source_id, NODE_ID_LEN),
2799 pdu_len);
2800 ND_PRINT("\n\t start lsp-id: %s",
2801 isis_print_id(ndo, header_csnp->start_lsp_id, LSP_ID_LEN));
2802 ND_PRINT("\n\t end lsp-id: %s",
2803 isis_print_id(ndo, header_csnp->end_lsp_id, LSP_ID_LEN));
2804
2805 if (ndo->ndo_vflag > 1) {
2806 if (!print_unknown_data(ndo, pptr, "\n\t ", ISIS_CSNP_HEADER_SIZE))
2807 return (0);
2808 }
2809
2810 INVALID_OR_DECREMENT(packet_len,ISIS_COMMON_HEADER_SIZE+ISIS_CSNP_HEADER_SIZE);
2811 pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_CSNP_HEADER_SIZE);
2812 break;
2813
2814 case ISIS_PDU_L1_PSNP:
2815 case ISIS_PDU_L2_PSNP:
2816 if (fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_PSNP_HEADER_SIZE)) {
2817 ND_PRINT("- bogus fixed header length %u should be %zu",
2818 fixed_len, ISIS_COMMON_HEADER_SIZE+ISIS_PSNP_HEADER_SIZE);
2819 return (0);
2820 }
2821 ND_TCHECK_SIZE(header_psnp);
2822 if (length < ISIS_COMMON_HEADER_SIZE+ISIS_PSNP_HEADER_SIZE)
2823 goto trunc;
2824 if (ndo->ndo_vflag == 0) {
2825 ND_PRINT(", src-id %s", isis_print_id(ndo, header_psnp->source_id, NODE_ID_LEN));
2826 ND_PRINT(", length %u", length);
2827 return (1);
2828 }
2829 pdu_len=GET_BE_U_2(header_psnp->pdu_len);
2830 if (packet_len>pdu_len) {
2831 packet_len=pdu_len; /* do TLV decoding as long as it makes sense */
2832 length=pdu_len;
2833 }
2834
2835 ND_PRINT("\n\t source-id: %s, PDU length: %u",
2836 isis_print_id(ndo, header_psnp->source_id, NODE_ID_LEN),
2837 pdu_len);
2838
2839 if (ndo->ndo_vflag > 1) {
2840 if (!print_unknown_data(ndo, pptr, "\n\t ", ISIS_PSNP_HEADER_SIZE))
2841 return (0);
2842 }
2843
2844 INVALID_OR_DECREMENT(packet_len,ISIS_COMMON_HEADER_SIZE+ISIS_PSNP_HEADER_SIZE);
2845 pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_PSNP_HEADER_SIZE);
2846 break;
2847
2848 default:
2849 if (ndo->ndo_vflag == 0) {
2850 ND_PRINT(", length %u", length);
2851 return (1);
2852 }
2853 (void)print_unknown_data(ndo, pptr, "\n\t ", length);
2854 return (0);
2855 }
2856
2857 /*
2858 * Now print the TLV's.
2859 */
2860
2861 while (packet_len > 0) {
2862 ND_TCHECK_2(pptr);
2863 if (packet_len < 2)
2864 goto trunc;
2865 tlv_type = GET_U_1(pptr);
2866 tlv_len = GET_U_1(pptr + 1);
2867 pptr += 2;
2868 packet_len -= 2;
2869 tlen = tlv_len; /* copy temporary len & pointer to packet data */
2870 tptr = pptr;
2871
2872 /* first lets see if we know the TLVs name*/
2873 ND_PRINT("\n\t %s TLV #%u, length: %u",
2874 tok2str(isis_tlv_values,
2875 "unknown",
2876 tlv_type),
2877 tlv_type,
2878 tlv_len);
2879
2880 if (packet_len < tlv_len)
2881 goto trunc;
2882
2883 /* now check if we have a decoder otherwise do a hexdump at the end*/
2884 switch (tlv_type) {
2885 case ISIS_TLV_AREA_ADDR:
2886 while (tlen != 0) {
2887 alen = GET_U_1(tptr);
2888 tptr++;
2889 tlen--;
2890 if (tlen < alen)
2891 goto tlv_trunc;
2892 ND_PRINT("\n\t Area address (length: %u): %s",
2893 alen,
2894 GET_ISONSAP_STRING(tptr, alen));
2895 tptr += alen;
2896 tlen -= alen;
2897 }
2898 break;
2899 case ISIS_TLV_ISNEIGH:
2900 while (tlen != 0) {
2901 if (tlen < MAC_ADDR_LEN)
2902 goto tlv_trunc;
2903 ND_TCHECK_LEN(tptr, MAC_ADDR_LEN);
2904 ND_PRINT("\n\t SNPA: %s", isis_print_id(ndo, tptr, MAC_ADDR_LEN));
2905 tlen -= MAC_ADDR_LEN;
2906 tptr += MAC_ADDR_LEN;
2907 }
2908 break;
2909
2910 case ISIS_TLV_INSTANCE_ID:
2911 if (tlen < 4)
2912 goto tlv_trunc;
2913 num_vals = (tlen-2)/2;
2914 ND_PRINT("\n\t Instance ID: %u, ITIDs(%u)%s ",
2915 GET_BE_U_2(tptr), num_vals,
2916 num_vals ? ":" : "");
2917 tptr += 2;
2918 tlen -= 2;
2919 for (i=0; i < num_vals; i++) {
2920 ND_PRINT("%u", GET_BE_U_2(tptr));
2921 if (i < (num_vals - 1)) {
2922 ND_PRINT(", ");
2923 }
2924 tptr += 2;
2925 tlen -= 2;
2926 }
2927 break;
2928
2929 case ISIS_TLV_PADDING:
2930 break;
2931
2932 case ISIS_TLV_MT_IS_REACH:
2933 mt_len = isis_print_mtid(ndo, tptr, "\n\t ", tlen);
2934 if (mt_len == 0) /* did something go wrong ? */
2935 goto trunc;
2936 tptr+=mt_len;
2937 tlen-=mt_len;
2938 while (tlen != 0) {
2939 ext_is_len = isis_print_ext_is_reach(ndo, tptr, "\n\t ", tlv_type, tlen);
2940 if (ext_is_len == 0) /* did something go wrong ? */
2941 goto trunc;
2942 if (tlen < ext_is_len) {
2943 ND_PRINT(" [remaining tlv length %u < %u]", tlen, ext_is_len);
2944 nd_print_invalid(ndo);
2945 break;
2946 }
2947 tlen-=(uint8_t)ext_is_len;
2948 tptr+=(uint8_t)ext_is_len;
2949 }
2950 break;
2951
2952 case ISIS_TLV_IS_ALIAS_ID:
2953 while (tlen != 0) {
2954 ext_is_len = isis_print_ext_is_reach(ndo, tptr, "\n\t ", tlv_type, tlen);
2955 if (ext_is_len == 0) /* did something go wrong ? */
2956 goto trunc;
2957 if (tlen < ext_is_len) {
2958 ND_PRINT(" [remaining tlv length %u < %u]", tlen, ext_is_len);
2959 nd_print_invalid(ndo);
2960 break;
2961 }
2962 tlen-=(uint8_t)ext_is_len;
2963 tptr+=(uint8_t)ext_is_len;
2964 }
2965 break;
2966
2967 case ISIS_TLV_EXT_IS_REACH:
2968 while (tlen != 0) {
2969 ext_is_len = isis_print_ext_is_reach(ndo, tptr, "\n\t ", tlv_type, tlen);
2970 if (ext_is_len == 0) /* did something go wrong ? */
2971 goto trunc;
2972 if (tlen < ext_is_len) {
2973 ND_PRINT(" [remaining tlv length %u < %u]", tlen, ext_is_len);
2974 nd_print_invalid(ndo);
2975 break;
2976 }
2977 tlen-=(uint8_t)ext_is_len;
2978 tptr+=(uint8_t)ext_is_len;
2979 }
2980 break;
2981 case ISIS_TLV_IS_REACH:
2982 if (tlen < 1)
2983 goto tlv_trunc;
2984 ND_PRINT("\n\t %s",
2985 tok2str(isis_is_reach_virtual_values,
2986 "bogus virtual flag 0x%02x",
2987 GET_U_1(tptr)));
2988 tptr++;
2989 tlen--;
2990 tlv_is_reach = (const struct isis_tlv_is_reach *)tptr;
2991 while (tlen != 0) {
2992 if (tlen < sizeof(struct isis_tlv_is_reach))
2993 goto tlv_trunc;
2994 ND_TCHECK_SIZE(tlv_is_reach);
2995 ND_PRINT("\n\t IS Neighbor: %s",
2996 isis_print_id(ndo, tlv_is_reach->neighbor_nodeid, NODE_ID_LEN));
2997 isis_print_metric_block(ndo, &tlv_is_reach->isis_metric_block);
2998 tlen -= sizeof(struct isis_tlv_is_reach);
2999 tlv_is_reach++;
3000 }
3001 break;
3002
3003 case ISIS_TLV_ESNEIGH:
3004 tlv_es_reach = (const struct isis_tlv_es_reach *)tptr;
3005 while (tlen != 0) {
3006 if (tlen < sizeof(struct isis_tlv_es_reach))
3007 goto tlv_trunc;
3008 ND_TCHECK_SIZE(tlv_es_reach);
3009 ND_PRINT("\n\t ES Neighbor: %s",
3010 isis_print_id(ndo, tlv_es_reach->neighbor_sysid, SYSTEM_ID_LEN));
3011 isis_print_metric_block(ndo, &tlv_es_reach->isis_metric_block);
3012 tlen -= sizeof(struct isis_tlv_es_reach);
3013 tlv_es_reach++;
3014 }
3015 break;
3016
3017 /* those two TLVs share the same format */
3018 case ISIS_TLV_INT_IP_REACH:
3019 case ISIS_TLV_EXT_IP_REACH:
3020 if (!isis_print_tlv_ip_reach(ndo, pptr, "\n\t ", tlv_len))
3021 return (1);
3022 break;
3023
3024 case ISIS_TLV_EXTD_IP_REACH:
3025 while (tlen != 0) {
3026 ext_ip_len = isis_print_extd_ip_reach(ndo, tptr, "\n\t ", AF_INET);
3027 if (ext_ip_len == 0) /* did something go wrong ? */
3028 goto trunc;
3029 if (tlen < ext_ip_len) {
3030 ND_PRINT(" [remaining tlv length %u < %u]", tlen, ext_ip_len);
3031 nd_print_invalid(ndo);
3032 break;
3033 }
3034 tlen-=(uint8_t)ext_ip_len;
3035 tptr+=(uint8_t)ext_ip_len;
3036 }
3037 break;
3038
3039 case ISIS_TLV_MT_IP_REACH:
3040 mt_len = isis_print_mtid(ndo, tptr, "\n\t ", tlen);
3041 if (mt_len == 0) { /* did something go wrong ? */
3042 goto trunc;
3043 }
3044 tptr+=mt_len;
3045 tlen-=mt_len;
3046
3047 while (tlen != 0) {
3048 ext_ip_len = isis_print_extd_ip_reach(ndo, tptr, "\n\t ", AF_INET);
3049 if (ext_ip_len == 0) /* did something go wrong ? */
3050 goto trunc;
3051 if (tlen < ext_ip_len) {
3052 ND_PRINT(" [remaining tlv length %u < %u]", tlen, ext_ip_len);
3053 nd_print_invalid(ndo);
3054 break;
3055 }
3056 tlen-=(uint8_t)ext_ip_len;
3057 tptr+=(uint8_t)ext_ip_len;
3058 }
3059 break;
3060
3061 case ISIS_TLV_IP6_REACH:
3062 while (tlen != 0) {
3063 ext_ip_len = isis_print_extd_ip_reach(ndo, tptr, "\n\t ", AF_INET6);
3064 if (ext_ip_len == 0) /* did something go wrong ? */
3065 goto trunc;
3066 if (tlen < ext_ip_len) {
3067 ND_PRINT(" [remaining tlv length %u < %u]", tlen, ext_ip_len);
3068 nd_print_invalid(ndo);
3069 break;
3070 }
3071 tlen-=(uint8_t)ext_ip_len;
3072 tptr+=(uint8_t)ext_ip_len;
3073 }
3074 break;
3075
3076 case ISIS_TLV_MT_IP6_REACH:
3077 mt_len = isis_print_mtid(ndo, tptr, "\n\t ", tlen);
3078 if (mt_len == 0) { /* did something go wrong ? */
3079 goto trunc;
3080 }
3081 tptr+=mt_len;
3082 tlen-=mt_len;
3083
3084 while (tlen != 0) {
3085 ext_ip_len = isis_print_extd_ip_reach(ndo, tptr, "\n\t ", AF_INET6);
3086 if (ext_ip_len == 0) /* did something go wrong ? */
3087 goto trunc;
3088 if (tlen < ext_ip_len) {
3089 ND_PRINT(" [remaining tlv length %u < %u]", tlen, ext_ip_len);
3090 nd_print_invalid(ndo);
3091 break;
3092 }
3093 tlen-=(uint8_t)ext_ip_len;
3094 tptr+=(uint8_t)ext_ip_len;
3095 }
3096 break;
3097
3098 case ISIS_TLV_IP6ADDR:
3099 while (tlen != 0) {
3100 if (tlen < sizeof(nd_ipv6))
3101 goto tlv_trunc;
3102 ND_PRINT("\n\t IPv6 interface address: %s",
3103 GET_IP6ADDR_STRING(tptr));
3104
3105 tptr += sizeof(nd_ipv6);
3106 tlen -= sizeof(nd_ipv6);
3107 }
3108 break;
3109 case ISIS_TLV_AUTH:
3110 if (tlen < 1)
3111 goto tlv_trunc;
3112 auth_type = GET_U_1(tptr);
3113 tptr++;
3114 tlen--;
3115
3116 ND_PRINT("\n\t %s: ",
3117 tok2str(isis_subtlv_auth_values,
3118 "unknown Authentication type 0x%02x",
3119 auth_type));
3120
3121 switch (auth_type) {
3122 case ISIS_SUBTLV_AUTH_SIMPLE:
3123 if (nd_printzp(ndo, tptr, tlen, ndo->ndo_snapend))
3124 goto trunc;
3125 break;
3126 case ISIS_SUBTLV_AUTH_MD5:
3127 for(i=0;i<tlen;i++) {
3128 ND_PRINT("%02x", GET_U_1(tptr + i));
3129 }
3130 if (tlen != ISIS_SUBTLV_AUTH_MD5_LEN)
3131 ND_PRINT(", (invalid subTLV) ");
3132
3133 sigcheck = signature_verify(ndo, optr, length, tptr,
3134 isis_clear_checksum_lifetime,
3135 header_lsp);
3136 ND_PRINT(" (%s)", tok2str(signature_check_values, "Unknown", sigcheck));
3137
3138 break;
3139 case ISIS_SUBTLV_AUTH_GENERIC:
3140 if (tlen < 2)
3141 goto tlv_trunc;
3142 key_id = GET_BE_U_2(tptr);
3143 ND_PRINT("%u, password: ", key_id);
3144 tptr += 2;
3145 tlen -= 2;
3146 for(i=0;i<tlen;i++) {
3147 ND_PRINT("%02x", GET_U_1(tptr + i));
3148 }
3149 break;
3150 case ISIS_SUBTLV_AUTH_PRIVATE:
3151 default:
3152 if (!print_unknown_data(ndo, tptr, "\n\t\t ", tlen))
3153 return(0);
3154 break;
3155 }
3156 break;
3157
3158 case ISIS_TLV_PTP_ADJ:
3159 tlv_ptp_adj = (const struct isis_tlv_ptp_adj *)tptr;
3160 if(tlen>=1) {
3161 ND_PRINT("\n\t Adjacency State: %s (%u)",
3162 tok2str(isis_ptp_adjancey_values, "unknown", GET_U_1(tptr)),
3163 GET_U_1(tptr));
3164 tlen--;
3165 }
3166 if(tlen>sizeof(tlv_ptp_adj->extd_local_circuit_id)) {
3167 ND_PRINT("\n\t Extended Local circuit-ID: 0x%08x",
3168 GET_BE_U_4(tlv_ptp_adj->extd_local_circuit_id));
3169 tlen-=sizeof(tlv_ptp_adj->extd_local_circuit_id);
3170 }
3171 if(tlen>=SYSTEM_ID_LEN) {
3172 ND_TCHECK_LEN(tlv_ptp_adj->neighbor_sysid, SYSTEM_ID_LEN);
3173 ND_PRINT("\n\t Neighbor System-ID: %s",
3174 isis_print_id(ndo, tlv_ptp_adj->neighbor_sysid, SYSTEM_ID_LEN));
3175 tlen-=SYSTEM_ID_LEN;
3176 }
3177 if(tlen>=sizeof(tlv_ptp_adj->neighbor_extd_local_circuit_id)) {
3178 ND_PRINT("\n\t Neighbor Extended Local circuit-ID: 0x%08x",
3179 GET_BE_U_4(tlv_ptp_adj->neighbor_extd_local_circuit_id));
3180 }
3181 break;
3182
3183 case ISIS_TLV_PROTOCOLS:
3184 ND_PRINT("\n\t NLPID(s): ");
3185 while (tlen != 0) {
3186 ND_PRINT("%s (0x%02x)",
3187 tok2str(nlpid_values,
3188 "unknown",
3189 GET_U_1(tptr)),
3190 GET_U_1(tptr));
3191 if (tlen>1) /* further NPLIDs ? - put comma */
3192 ND_PRINT(", ");
3193 tptr++;
3194 tlen--;
3195 }
3196 break;
3197
3198 case ISIS_TLV_MT_PORT_CAP:
3199 {
3200 if (tlen < 2)
3201 goto tlv_trunc;
3202
3203 ND_PRINT("\n\t RES: %u, MTID(s): %u",
3204 (GET_BE_U_2(tptr) >> 12),
3205 (GET_BE_U_2(tptr) & 0x0fff));
3206
3207 tptr += 2;
3208 tlen -= 2;
3209
3210 if (tlen)
3211 isis_print_mt_port_cap_subtlv(ndo, tptr, tlen);
3212
3213 break;
3214 }
3215
3216 case ISIS_TLV_MT_CAPABILITY:
3217 if (tlen < 2)
3218 goto tlv_trunc;
3219
3220 ND_PRINT("\n\t O: %u, RES: %u, MTID(s): %u",
3221 (GET_BE_U_2(tptr) >> 15) & 0x01,
3222 (GET_BE_U_2(tptr) >> 12) & 0x07,
3223 GET_BE_U_2(tptr) & 0x0fff);
3224
3225 tptr += 2;
3226 tlen -= 2;
3227
3228 if (tlen)
3229 isis_print_mt_capability_subtlv(ndo, tptr, tlen);
3230
3231 break;
3232
3233 case ISIS_TLV_TE_ROUTER_ID:
3234 if (tlen < sizeof(nd_ipv4))
3235 goto tlv_trunc;
3236 ND_PRINT("\n\t Traffic Engineering Router ID: %s", GET_IPADDR_STRING(pptr));
3237 break;
3238
3239 case ISIS_TLV_IPADDR:
3240 while (tlen != 0) {
3241 if (tlen < sizeof(nd_ipv4))
3242 goto tlv_trunc;
3243 ND_PRINT("\n\t IPv4 interface address: %s", GET_IPADDR_STRING(tptr));
3244 tptr += sizeof(nd_ipv4);
3245 tlen -= sizeof(nd_ipv4);
3246 }
3247 break;
3248
3249 case ISIS_TLV_HOSTNAME:
3250 ND_PRINT("\n\t Hostname: ");
3251 if (nd_printzp(ndo, tptr, tlen, ndo->ndo_snapend))
3252 goto trunc;
3253 break;
3254
3255 case ISIS_TLV_SHARED_RISK_GROUP:
3256 if (tlen < NODE_ID_LEN)
3257 break;
3258 ND_TCHECK_LEN(tptr, NODE_ID_LEN);
3259 ND_PRINT("\n\t IS Neighbor: %s", isis_print_id(ndo, tptr, NODE_ID_LEN));
3260 tptr+=NODE_ID_LEN;
3261 tlen-=NODE_ID_LEN;
3262
3263 if (tlen < 1)
3264 break;
3265 ND_PRINT(", Flags: [%s]",
3266 ISIS_MASK_TLV_SHARED_RISK_GROUP(GET_U_1(tptr)) ? "numbered" : "unnumbered");
3267 tptr++;
3268 tlen--;
3269
3270 if (tlen < sizeof(nd_ipv4))
3271 break;
3272 ND_PRINT("\n\t IPv4 interface address: %s", GET_IPADDR_STRING(tptr));
3273 tptr+=sizeof(nd_ipv4);
3274 tlen-=sizeof(nd_ipv4);
3275
3276 if (tlen < sizeof(nd_ipv4))
3277 break;
3278 ND_PRINT("\n\t IPv4 neighbor address: %s", GET_IPADDR_STRING(tptr));
3279 tptr+=sizeof(nd_ipv4);
3280 tlen-=sizeof(nd_ipv4);
3281
3282 while (tlen != 0) {
3283 if (tlen < 4)
3284 goto tlv_trunc;
3285 ND_PRINT("\n\t Link-ID: 0x%08x", GET_BE_U_4(tptr));
3286 tptr+=4;
3287 tlen-=4;
3288 }
3289 break;
3290
3291 case ISIS_TLV_LSP:
3292 tlv_lsp = (const struct isis_tlv_lsp *)tptr;
3293 while (tlen != 0) {
3294 if (tlen < sizeof(struct isis_tlv_lsp))
3295 goto tlv_trunc;
3296 ND_TCHECK_1(tlv_lsp->lsp_id + LSP_ID_LEN - 1);
3297 ND_PRINT("\n\t lsp-id: %s",
3298 isis_print_id(ndo, tlv_lsp->lsp_id, LSP_ID_LEN));
3299 ND_PRINT(", seq: 0x%08x",
3300 GET_BE_U_4(tlv_lsp->sequence_number));
3301 ND_PRINT(", lifetime: %5ds",
3302 GET_BE_U_2(tlv_lsp->remaining_lifetime));
3303 ND_PRINT(", chksum: 0x%04x", GET_BE_U_2(tlv_lsp->checksum));
3304 tlen-=sizeof(struct isis_tlv_lsp);
3305 tlv_lsp++;
3306 }
3307 break;
3308
3309 case ISIS_TLV_CHECKSUM:
3310 if (tlen < ISIS_TLV_CHECKSUM_MINLEN)
3311 break;
3312 ND_TCHECK_LEN(tptr, ISIS_TLV_CHECKSUM_MINLEN);
3313 ND_PRINT("\n\t checksum: 0x%04x ", GET_BE_U_2(tptr));
3314 /* do not attempt to verify the checksum if it is zero
3315 * most likely a HMAC-MD5 TLV is also present and
3316 * to avoid conflicts the checksum TLV is zeroed.
3317 * see rfc3358 for details
3318 */
3319 osi_print_cksum(ndo, optr, GET_BE_U_2(tptr), (int)(tptr-optr),
3320 length);
3321 break;
3322
3323 case ISIS_TLV_POI:
3324 if (tlen < 1)
3325 goto tlv_trunc;
3326 num_system_ids = GET_U_1(tptr);
3327 tptr++;
3328 tlen--;
3329 if (num_system_ids == 0) {
3330 /* Not valid */
3331 ND_PRINT(" No system IDs supplied");
3332 } else {
3333 if (tlen < SYSTEM_ID_LEN)
3334 goto tlv_trunc;
3335 ND_TCHECK_LEN(tptr, SYSTEM_ID_LEN);
3336 ND_PRINT("\n\t Purge Originator System-ID: %s",
3337 isis_print_id(ndo, tptr, SYSTEM_ID_LEN));
3338 tptr += SYSTEM_ID_LEN;
3339 tlen -= SYSTEM_ID_LEN;
3340
3341 if (num_system_ids > 1) {
3342 if (tlen < SYSTEM_ID_LEN)
3343 goto tlv_trunc;
3344 ND_TCHECK_LEN(tptr, SYSTEM_ID_LEN);
3345 ND_TCHECK_LEN(tptr, 2 * SYSTEM_ID_LEN + 1);
3346 ND_PRINT("\n\t Received from System-ID: %s",
3347 isis_print_id(ndo, tptr, SYSTEM_ID_LEN));
3348 }
3349 }
3350 break;
3351
3352 case ISIS_TLV_MT_SUPPORTED:
3353 while (tlen != 0) {
3354 /* length can only be a multiple of 2, otherwise there is
3355 something broken -> so decode down until length is 1 */
3356 if (tlen!=1) {
3357 mt_len = isis_print_mtid(ndo, tptr, "\n\t ", tlen);
3358 if (mt_len == 0) /* did something go wrong ? */
3359 goto trunc;
3360 tptr+=mt_len;
3361 tlen-=mt_len;
3362 } else {
3363 ND_PRINT("\n\t invalid MT-ID");
3364 break;
3365 }
3366 }
3367 break;
3368
3369 case ISIS_TLV_RESTART_SIGNALING:
3370 /* first attempt to decode the flags */
3371 if (tlen < ISIS_TLV_RESTART_SIGNALING_FLAGLEN)
3372 break;
3373 ND_TCHECK_LEN(tptr, ISIS_TLV_RESTART_SIGNALING_FLAGLEN);
3374 ND_PRINT("\n\t Flags [%s]",
3375 bittok2str(isis_restart_flag_values, "none", GET_U_1(tptr)));
3376 tptr+=ISIS_TLV_RESTART_SIGNALING_FLAGLEN;
3377 tlen-=ISIS_TLV_RESTART_SIGNALING_FLAGLEN;
3378
3379 /* is there anything other than the flags field? */
3380 if (tlen == 0)
3381 break;
3382
3383 if (tlen < ISIS_TLV_RESTART_SIGNALING_HOLDTIMELEN)
3384 break;
3385 ND_TCHECK_LEN(tptr, ISIS_TLV_RESTART_SIGNALING_HOLDTIMELEN);
3386
3387 ND_PRINT(", Remaining holding time %us", GET_BE_U_2(tptr));
3388 tptr+=ISIS_TLV_RESTART_SIGNALING_HOLDTIMELEN;
3389 tlen-=ISIS_TLV_RESTART_SIGNALING_HOLDTIMELEN;
3390
3391 /* is there an additional sysid field present ?*/
3392 if (tlen == SYSTEM_ID_LEN) {
3393 ND_TCHECK_LEN(tptr, SYSTEM_ID_LEN);
3394 ND_PRINT(", for %s", isis_print_id(ndo, tptr,SYSTEM_ID_LEN));
3395 }
3396 break;
3397
3398 case ISIS_TLV_IDRP_INFO:
3399 if (tlen < 1)
3400 break;
3401 isis_subtlv_idrp = GET_U_1(tptr);
3402 ND_PRINT("\n\t Inter-Domain Information Type: %s",
3403 tok2str(isis_subtlv_idrp_values,
3404 "Unknown (0x%02x)",
3405 isis_subtlv_idrp));
3406 tptr++;
3407 tlen--;
3408 switch (isis_subtlv_idrp) {
3409 case ISIS_SUBTLV_IDRP_ASN:
3410 if (tlen < 2)
3411 goto tlv_trunc;
3412 ND_PRINT("AS Number: %u", GET_BE_U_2(tptr));
3413 break;
3414 case ISIS_SUBTLV_IDRP_LOCAL:
3415 case ISIS_SUBTLV_IDRP_RES:
3416 default:
3417 if (!print_unknown_data(ndo, tptr, "\n\t ", tlen))
3418 return(0);
3419 break;
3420 }
3421 break;
3422
3423 case ISIS_TLV_LSP_BUFFERSIZE:
3424 if (tlen < 2)
3425 break;
3426 ND_PRINT("\n\t LSP Buffersize: %u", GET_BE_U_2(tptr));
3427 break;
3428
3429 case ISIS_TLV_PART_DIS:
3430 while (tlen != 0) {
3431 if (tlen < SYSTEM_ID_LEN)
3432 goto tlv_trunc;
3433 ND_TCHECK_LEN(tptr, SYSTEM_ID_LEN);
3434 ND_PRINT("\n\t %s", isis_print_id(ndo, tptr, SYSTEM_ID_LEN));
3435 tptr+=SYSTEM_ID_LEN;
3436 tlen-=SYSTEM_ID_LEN;
3437 }
3438 break;
3439
3440 case ISIS_TLV_PREFIX_NEIGH:
3441 if (tlen < sizeof(struct isis_metric_block))
3442 break;
3443 ND_TCHECK_LEN(tptr, sizeof(struct isis_metric_block));
3444 ND_PRINT("\n\t Metric Block");
3445 isis_print_metric_block(ndo, (const struct isis_metric_block *)tptr);
3446 tptr+=sizeof(struct isis_metric_block);
3447 tlen-=sizeof(struct isis_metric_block);
3448
3449 while (tlen != 0) {
3450 prefix_len=GET_U_1(tptr); /* read out prefix length in semioctets*/
3451 tptr++;
3452 tlen--;
3453 if (prefix_len < 2) {
3454 ND_PRINT("\n\t\tAddress: prefix length %u < 2", prefix_len);
3455 break;
3456 }
3457 if (tlen < prefix_len/2)
3458 break;
3459 ND_PRINT("\n\t\tAddress: %s/%u",
3460 GET_ISONSAP_STRING(tptr, prefix_len / 2), prefix_len * 4);
3461 tptr+=prefix_len/2;
3462 tlen-=prefix_len/2;
3463 }
3464 break;
3465
3466 case ISIS_TLV_IIH_SEQNR:
3467 if (tlen < 4)
3468 break;
3469 ND_PRINT("\n\t Sequence number: %u", GET_BE_U_4(tptr));
3470 break;
3471
3472 case ISIS_TLV_ROUTER_CAPABILITY:
3473 if (tlen < 5) {
3474 ND_PRINT(" [object length %u < 5]", tlen);
3475 nd_print_invalid(ndo);
3476 break;
3477 }
3478 ND_PRINT("\n\t Router-ID %s", GET_IPADDR_STRING(tptr));
3479 ND_PRINT(", Flags [%s]",
3480 bittok2str(isis_tlv_router_capability_flags, "none", GET_U_1(tptr+4)));
3481
3482 /* Optional set of sub-TLV */
3483 if (tlen > 5) {
3484 isis_print_router_cap_subtlv(ndo, tptr+5, tlen-5);
3485 }
3486 break;
3487
3488 case ISIS_TLV_VENDOR_PRIVATE:
3489 if (tlen < 3)
3490 break;
3491 vendor_id = GET_BE_U_3(tptr);
3492 ND_PRINT("\n\t Vendor: %s (%u)",
3493 tok2str(oui_values, "Unknown", vendor_id),
3494 vendor_id);
3495 tptr+=3;
3496 tlen-=3;
3497 if (tlen != 0) /* hexdump the rest */
3498 if (!print_unknown_data(ndo, tptr, "\n\t\t", tlen))
3499 return(0);
3500 break;
3501 /*
3502 * FIXME those are the defined TLVs that lack a decoder
3503 * you are welcome to contribute code ;-)
3504 */
3505
3506 case ISIS_TLV_DECNET_PHASE4:
3507 case ISIS_TLV_LUCENT_PRIVATE:
3508 case ISIS_TLV_IPAUTH:
3509 case ISIS_TLV_NORTEL_PRIVATE1:
3510 case ISIS_TLV_NORTEL_PRIVATE2:
3511
3512 default:
3513 if (ndo->ndo_vflag <= 1) {
3514 if (!print_unknown_data(ndo, pptr, "\n\t\t", tlv_len))
3515 return(0);
3516 }
3517 break;
3518 }
3519 tlv_trunc:
3520 /* do we want to see an additionally hexdump ? */
3521 if (ndo->ndo_vflag> 1) {
3522 if (!print_unknown_data(ndo, pptr, "\n\t ", tlv_len))
3523 return(0);
3524 }
3525
3526 pptr += tlv_len;
3527 packet_len -= tlv_len;
3528 }
3529
3530 if (packet_len != 0) {
3531 ND_PRINT("\n\t %u straggler bytes", packet_len);
3532 }
3533 return (1);
3534
3535 trunc:
3536 nd_print_trunc(ndo);
3537 return (1);
3538 }
3539
3540 static void
3541 osi_print_cksum(netdissect_options *ndo, const uint8_t *pptr,
3542 uint16_t checksum, int checksum_offset, u_int length)
3543 {
3544 uint16_t calculated_checksum;
3545
3546 /* do not attempt to verify the checksum if it is zero,
3547 * if the offset is nonsense,
3548 * or the base pointer is not sane
3549 */
3550 if (!checksum
3551 || checksum_offset < 0
3552 || !ND_TTEST_2(pptr + checksum_offset)
3553 || (u_int)checksum_offset > length
3554 || !ND_TTEST_LEN(pptr, length)) {
3555 ND_PRINT(" (unverified)");
3556 } else {
3557 #if 0
3558 ND_PRINT("\nosi_print_cksum: %p %d %u\n", pptr, checksum_offset, length);
3559 #endif
3560 calculated_checksum = create_osi_cksum(pptr, checksum_offset, length);
3561 if (checksum == calculated_checksum) {
3562 ND_PRINT(" (correct)");
3563 } else {
3564 ND_PRINT(" (incorrect should be 0x%04x)", calculated_checksum);
3565 }
3566 }
3567 }