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