]> The Tcpdump Group git mirrors - tcpdump/blob - print-isoclns.c
661aa062e874fff067ff25c464f307a6af39814b
[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(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 printf (", P-ID: %u", EXTRACT_16BITS(++tptr));
1814 }
1815 break;
1816 case ISIS_SUBTLV_EXT_IS_REACH_INTF_SW_CAP_DESCR:
1817 if (subl >= 36) {
1818 gmpls_switch_cap = *tptr;
1819 printf("%s Interface Switching Capability:%s",
1820 ident,
1821 tok2str(gmpls_switch_cap_values, "Unknown", gmpls_switch_cap));
1822 printf(", LSP Encoding: %s",
1823 tok2str(gmpls_encoding_values, "Unknown", *(tptr+1)));
1824 tptr+=4;
1825 printf("%s Max LSP Bandwidth:",ident);
1826 for (priority_level = 0; priority_level < 8; priority_level++) {
1827 bw.i = EXTRACT_32BITS(tptr);
1828 printf("%s priority level %d: %.3f Mbps",
1829 ident,
1830 priority_level,
1831 bw.f*8/1000000 );
1832 tptr+=4;
1833 }
1834 subl-=36;
1835 switch (gmpls_switch_cap) {
1836 case GMPLS_PSC1:
1837 case GMPLS_PSC2:
1838 case GMPLS_PSC3:
1839 case GMPLS_PSC4:
1840 bw.i = EXTRACT_32BITS(tptr);
1841 printf("%s Min LSP Bandwidth: %.3f Mbps", ident, bw.f*8/1000000);
1842 printf("%s Interface MTU: %u", ident, EXTRACT_16BITS(tptr+4));
1843 break;
1844 case GMPLS_TSC:
1845 bw.i = EXTRACT_32BITS(tptr);
1846 printf("%s Min LSP Bandwidth: %.3f Mbps", ident, bw.f*8/1000000);
1847 printf("%s Indication %s", ident,
1848 tok2str(gmpls_switch_cap_tsc_indication_values, "Unknown (%u)", *(tptr+4)));
1849 break;
1850 default:
1851 /* there is some optional stuff left to decode but this is as of yet
1852 not specified so just lets hexdump what is left */
1853 if(subl>0){
1854 if(!print_unknown_data(gndo,tptr,"\n\t\t ",
1855 subl))
1856 return(0);
1857 }
1858 }
1859 }
1860 break;
1861 default:
1862 if(!print_unknown_data(gndo,tptr,"\n\t\t ",
1863 subl))
1864 return(0);
1865 break;
1866 }
1867 return(1);
1868
1869 trunctlv:
1870 printf("%spacket exceeded snapshot",ident);
1871 return(0);
1872 }
1873
1874
1875 /*
1876 * this is the common IS-REACH decoder it is called
1877 * from various EXTD-IS REACH style TLVs (22,24,222)
1878 */
1879
1880 static int
1881 isis_print_ext_is_reach (const u_int8_t *tptr,const char *ident, int tlv_type) {
1882
1883 char ident_buffer[20];
1884 int subtlv_type,subtlv_len,subtlv_sum_len;
1885 int proc_bytes = 0; /* how many bytes did we process ? */
1886
1887 if (!TTEST2(*tptr, NODE_ID_LEN))
1888 return(0);
1889
1890 printf("%sIS Neighbor: %s", ident, isis_print_id(tptr, NODE_ID_LEN));
1891 tptr+=(NODE_ID_LEN);
1892
1893 if (tlv_type != ISIS_TLV_IS_ALIAS_ID) { /* the Alias TLV Metric field is implicit 0 */
1894 if (!TTEST2(*tptr, 3)) /* and is therefore skipped */
1895 return(0);
1896 printf(", Metric: %d",EXTRACT_24BITS(tptr));
1897 tptr+=3;
1898 }
1899
1900 if (!TTEST2(*tptr, 1))
1901 return(0);
1902 subtlv_sum_len=*(tptr++); /* read out subTLV length */
1903 proc_bytes=NODE_ID_LEN+3+1;
1904 printf(", %ssub-TLVs present",subtlv_sum_len ? "" : "no ");
1905 if (subtlv_sum_len) {
1906 printf(" (%u)",subtlv_sum_len);
1907 while (subtlv_sum_len>0) {
1908 if (!TTEST2(*tptr,2))
1909 return(0);
1910 subtlv_type=*(tptr++);
1911 subtlv_len=*(tptr++);
1912 /* prepend the ident string */
1913 snprintf(ident_buffer, sizeof(ident_buffer), "%s ",ident);
1914 if(!isis_print_is_reach_subtlv(tptr,subtlv_type,subtlv_len,ident_buffer))
1915 return(0);
1916 tptr+=subtlv_len;
1917 subtlv_sum_len-=(subtlv_len+2);
1918 proc_bytes+=(subtlv_len+2);
1919 }
1920 }
1921 return(proc_bytes);
1922 }
1923
1924 /*
1925 * this is the common Multi Topology ID decoder
1926 * it is called from various MT-TLVs (222,229,235,237)
1927 */
1928
1929 static int
1930 isis_print_mtid (const u_int8_t *tptr,const char *ident) {
1931
1932 if (!TTEST2(*tptr, 2))
1933 return(0);
1934
1935 printf("%s%s",
1936 ident,
1937 tok2str(isis_mt_values,
1938 "Reserved for IETF Consensus",
1939 ISIS_MASK_MTID(EXTRACT_16BITS(tptr))));
1940
1941 printf(" Topology (0x%03x), Flags: [%s]",
1942 ISIS_MASK_MTID(EXTRACT_16BITS(tptr)),
1943 bittok2str(isis_mt_flag_values, "none",ISIS_MASK_MTFLAGS(EXTRACT_16BITS(tptr))));
1944
1945 return(2);
1946 }
1947
1948 /*
1949 * this is the common extended IP reach decoder
1950 * it is called from TLVs (135,235,236,237)
1951 * we process the TLV and optional subTLVs and return
1952 * the amount of processed bytes
1953 */
1954
1955 static int
1956 isis_print_extd_ip_reach (const u_int8_t *tptr, const char *ident, u_int16_t afi) {
1957
1958 char ident_buffer[20];
1959 #ifdef INET6
1960 u_int8_t prefix[sizeof(struct in6_addr)]; /* shared copy buffer for IPv4 and IPv6 prefixes */
1961 #else
1962 u_int8_t prefix[sizeof(struct in_addr)]; /* shared copy buffer for IPv4 prefixes */
1963 #endif
1964 u_int metric, status_byte, bit_length, byte_length, sublen, processed, subtlvtype, subtlvlen;
1965
1966 if (!TTEST2(*tptr, 4))
1967 return (0);
1968 metric = EXTRACT_32BITS(tptr);
1969 processed=4;
1970 tptr+=4;
1971
1972 if (afi == AF_INET) {
1973 if (!TTEST2(*tptr, 1)) /* fetch status byte */
1974 return (0);
1975 status_byte=*(tptr++);
1976 bit_length = status_byte&0x3f;
1977 if (bit_length > 32) {
1978 printf("%sIPv4 prefix: bad bit length %u",
1979 ident,
1980 bit_length);
1981 return (0);
1982 }
1983 processed++;
1984 #ifdef INET6
1985 } else if (afi == AF_INET6) {
1986 if (!TTEST2(*tptr, 1)) /* fetch status & prefix_len byte */
1987 return (0);
1988 status_byte=*(tptr++);
1989 bit_length=*(tptr++);
1990 if (bit_length > 128) {
1991 printf("%sIPv6 prefix: bad bit length %u",
1992 ident,
1993 bit_length);
1994 return (0);
1995 }
1996 processed+=2;
1997 #endif
1998 } else
1999 return (0); /* somebody is fooling us */
2000
2001 byte_length = (bit_length + 7) / 8; /* prefix has variable length encoding */
2002
2003 if (!TTEST2(*tptr, byte_length))
2004 return (0);
2005 memset(prefix, 0, sizeof prefix); /* clear the copy buffer */
2006 memcpy(prefix,tptr,byte_length); /* copy as much as is stored in the TLV */
2007 tptr+=byte_length;
2008 processed+=byte_length;
2009
2010 if (afi == AF_INET)
2011 printf("%sIPv4 prefix: %15s/%u",
2012 ident,
2013 ipaddr_string(prefix),
2014 bit_length);
2015 #ifdef INET6
2016 if (afi == AF_INET6)
2017 printf("%sIPv6 prefix: %s/%u",
2018 ident,
2019 ip6addr_string(prefix),
2020 bit_length);
2021 #endif
2022
2023 printf(", Distribution: %s, Metric: %u",
2024 ISIS_MASK_TLV_EXTD_IP_UPDOWN(status_byte) ? "down" : "up",
2025 metric);
2026
2027 if (afi == AF_INET && ISIS_MASK_TLV_EXTD_IP_SUBTLV(status_byte))
2028 printf(", sub-TLVs present");
2029 #ifdef INET6
2030 if (afi == AF_INET6)
2031 printf(", %s%s",
2032 ISIS_MASK_TLV_EXTD_IP6_IE(status_byte) ? "External" : "Internal",
2033 ISIS_MASK_TLV_EXTD_IP6_SUBTLV(status_byte) ? ", sub-TLVs present" : "");
2034 #endif
2035
2036 if ((afi == AF_INET && ISIS_MASK_TLV_EXTD_IP_SUBTLV(status_byte))
2037 #ifdef INET6
2038 || (afi == AF_INET6 && ISIS_MASK_TLV_EXTD_IP6_SUBTLV(status_byte))
2039 #endif
2040 ) {
2041 /* assume that one prefix can hold more
2042 than one subTLV - therefore the first byte must reflect
2043 the aggregate bytecount of the subTLVs for this prefix
2044 */
2045 if (!TTEST2(*tptr, 1))
2046 return (0);
2047 sublen=*(tptr++);
2048 processed+=sublen+1;
2049 printf(" (%u)",sublen); /* print out subTLV length */
2050
2051 while (sublen>0) {
2052 if (!TTEST2(*tptr,2))
2053 return (0);
2054 subtlvtype=*(tptr++);
2055 subtlvlen=*(tptr++);
2056 /* prepend the ident string */
2057 snprintf(ident_buffer, sizeof(ident_buffer), "%s ",ident);
2058 if(!isis_print_ip_reach_subtlv(tptr,subtlvtype,subtlvlen,ident_buffer))
2059 return(0);
2060 tptr+=subtlvlen;
2061 sublen-=(subtlvlen+2);
2062 }
2063 }
2064 return (processed);
2065 }
2066
2067 /*
2068 * isis_print
2069 * Decode IS-IS packets. Return 0 on error.
2070 */
2071
2072 static int isis_print (const u_int8_t *p, u_int length)
2073 {
2074 const struct isis_common_header *isis_header;
2075
2076 const struct isis_iih_lan_header *header_iih_lan;
2077 const struct isis_iih_ptp_header *header_iih_ptp;
2078 struct isis_lsp_header *header_lsp;
2079 const struct isis_csnp_header *header_csnp;
2080 const struct isis_psnp_header *header_psnp;
2081
2082 const struct isis_tlv_lsp *tlv_lsp;
2083 const struct isis_tlv_ptp_adj *tlv_ptp_adj;
2084 const struct isis_tlv_is_reach *tlv_is_reach;
2085 const struct isis_tlv_es_reach *tlv_es_reach;
2086
2087 u_int8_t pdu_type, max_area, id_length, tlv_type, tlv_len, tmp, alen, lan_alen, prefix_len;
2088 u_int8_t ext_is_len, ext_ip_len, mt_len;
2089 const u_int8_t *optr, *pptr, *tptr;
2090 u_short packet_len,pdu_len, key_id;
2091 u_int i,vendor_id;
2092 int sigcheck;
2093
2094 packet_len=length;
2095 optr = p; /* initialize the _o_riginal pointer to the packet start -
2096 need it for parsing the checksum TLV and authentication
2097 TLV verification */
2098 isis_header = (const struct isis_common_header *)p;
2099 TCHECK(*isis_header);
2100 pptr = p+(ISIS_COMMON_HEADER_SIZE);
2101 header_iih_lan = (const struct isis_iih_lan_header *)pptr;
2102 header_iih_ptp = (const struct isis_iih_ptp_header *)pptr;
2103 header_lsp = (struct isis_lsp_header *)pptr;
2104 header_csnp = (const struct isis_csnp_header *)pptr;
2105 header_psnp = (const struct isis_psnp_header *)pptr;
2106
2107 if (!eflag)
2108 printf("IS-IS");
2109
2110 /*
2111 * Sanity checking of the header.
2112 */
2113
2114 if (isis_header->version != ISIS_VERSION) {
2115 printf("version %d packet not supported", isis_header->version);
2116 return (0);
2117 }
2118
2119 if ((isis_header->id_length != SYSTEM_ID_LEN) && (isis_header->id_length != 0)) {
2120 printf("system ID length of %d is not supported",
2121 isis_header->id_length);
2122 return (0);
2123 }
2124
2125 if (isis_header->pdu_version != ISIS_VERSION) {
2126 printf("version %d packet not supported", isis_header->pdu_version);
2127 return (0);
2128 }
2129
2130 max_area = isis_header->max_area;
2131 switch(max_area) {
2132 case 0:
2133 max_area = 3; /* silly shit */
2134 break;
2135 case 255:
2136 printf("bad packet -- 255 areas");
2137 return (0);
2138 default:
2139 break;
2140 }
2141
2142 id_length = isis_header->id_length;
2143 switch(id_length) {
2144 case 0:
2145 id_length = 6; /* silly shit again */
2146 break;
2147 case 1: /* 1-8 are valid sys-ID lenghts */
2148 case 2:
2149 case 3:
2150 case 4:
2151 case 5:
2152 case 6:
2153 case 7:
2154 case 8:
2155 break;
2156 case 255:
2157 id_length = 0; /* entirely useless */
2158 break;
2159 default:
2160 break;
2161 }
2162
2163 /* toss any non 6-byte sys-ID len PDUs */
2164 if (id_length != 6 ) {
2165 printf("bad packet -- illegal sys-ID length (%u)", id_length);
2166 return (0);
2167 }
2168
2169 pdu_type=isis_header->pdu_type;
2170
2171 /* in non-verbose mode print the basic PDU Type plus PDU specific brief information*/
2172 if (vflag < 1) {
2173 printf("%s%s",
2174 eflag ? "" : ", ",
2175 tok2str(isis_pdu_values,"unknown PDU-Type %u",pdu_type));
2176
2177 switch (pdu_type) {
2178
2179 case ISIS_PDU_L1_LAN_IIH:
2180 case ISIS_PDU_L2_LAN_IIH:
2181 printf(", src-id %s",
2182 isis_print_id(header_iih_lan->source_id,SYSTEM_ID_LEN));
2183 printf(", lan-id %s, prio %u",
2184 isis_print_id(header_iih_lan->lan_id,NODE_ID_LEN),
2185 header_iih_lan->priority);
2186 break;
2187 case ISIS_PDU_PTP_IIH:
2188 printf(", src-id %s", isis_print_id(header_iih_ptp->source_id,SYSTEM_ID_LEN));
2189 break;
2190 case ISIS_PDU_L1_LSP:
2191 case ISIS_PDU_L2_LSP:
2192 printf(", lsp-id %s, seq 0x%08x, lifetime %5us",
2193 isis_print_id(header_lsp->lsp_id, LSP_ID_LEN),
2194 EXTRACT_32BITS(header_lsp->sequence_number),
2195 EXTRACT_16BITS(header_lsp->remaining_lifetime));
2196 break;
2197 case ISIS_PDU_L1_CSNP:
2198 case ISIS_PDU_L2_CSNP:
2199 printf(", src-id %s", isis_print_id(header_csnp->source_id,NODE_ID_LEN));
2200 break;
2201 case ISIS_PDU_L1_PSNP:
2202 case ISIS_PDU_L2_PSNP:
2203 printf(", src-id %s", isis_print_id(header_psnp->source_id,NODE_ID_LEN));
2204 break;
2205
2206 }
2207 printf(", length %u", length);
2208
2209 return(1);
2210 }
2211
2212 /* ok they seem to want to know everything - lets fully decode it */
2213 printf("%slength %u", eflag ? "" : ", ",length);
2214
2215 printf("\n\t%s, hlen: %u, v: %u, pdu-v: %u, sys-id-len: %u (%u), max-area: %u (%u)",
2216 tok2str(isis_pdu_values,
2217 "unknown, type %u",
2218 pdu_type),
2219 isis_header->fixed_len,
2220 isis_header->version,
2221 isis_header->pdu_version,
2222 id_length,
2223 isis_header->id_length,
2224 max_area,
2225 isis_header->max_area);
2226
2227 if (vflag > 1) {
2228 if(!print_unknown_data(gndo,optr,"\n\t",8)) /* provide the _o_riginal pointer */
2229 return(0); /* for optionally debugging the common header */
2230 }
2231
2232 switch (pdu_type) {
2233
2234 case ISIS_PDU_L1_LAN_IIH:
2235 case ISIS_PDU_L2_LAN_IIH:
2236 if (isis_header->fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_LAN_HEADER_SIZE)) {
2237 printf(", bogus fixed header length %u should be %lu",
2238 isis_header->fixed_len, (unsigned long)ISIS_IIH_LAN_HEADER_SIZE);
2239 return (0);
2240 }
2241
2242 pdu_len=EXTRACT_16BITS(header_iih_lan->pdu_len);
2243 if (packet_len>pdu_len) {
2244 packet_len=pdu_len; /* do TLV decoding as long as it makes sense */
2245 length=pdu_len;
2246 }
2247
2248 TCHECK(*header_iih_lan);
2249 printf("\n\t source-id: %s, holding time: %us, Flags: [%s]",
2250 isis_print_id(header_iih_lan->source_id,SYSTEM_ID_LEN),
2251 EXTRACT_16BITS(header_iih_lan->holding_time),
2252 tok2str(isis_iih_circuit_type_values,
2253 "unknown circuit type 0x%02x",
2254 header_iih_lan->circuit_type));
2255
2256 printf("\n\t lan-id: %s, Priority: %u, PDU length: %u",
2257 isis_print_id(header_iih_lan->lan_id, NODE_ID_LEN),
2258 (header_iih_lan->priority) & ISIS_LAN_PRIORITY_MASK,
2259 pdu_len);
2260
2261 if (vflag > 1) {
2262 if(!print_unknown_data(gndo,pptr,"\n\t ",ISIS_IIH_LAN_HEADER_SIZE))
2263 return(0);
2264 }
2265
2266 packet_len -= (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_LAN_HEADER_SIZE);
2267 pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_LAN_HEADER_SIZE);
2268 break;
2269
2270 case ISIS_PDU_PTP_IIH:
2271 if (isis_header->fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_PTP_HEADER_SIZE)) {
2272 printf(", bogus fixed header length %u should be %lu",
2273 isis_header->fixed_len, (unsigned long)ISIS_IIH_PTP_HEADER_SIZE);
2274 return (0);
2275 }
2276
2277 pdu_len=EXTRACT_16BITS(header_iih_ptp->pdu_len);
2278 if (packet_len>pdu_len) {
2279 packet_len=pdu_len; /* do TLV decoding as long as it makes sense */
2280 length=pdu_len;
2281 }
2282
2283 TCHECK(*header_iih_ptp);
2284 printf("\n\t source-id: %s, holding time: %us, Flags: [%s]",
2285 isis_print_id(header_iih_ptp->source_id,SYSTEM_ID_LEN),
2286 EXTRACT_16BITS(header_iih_ptp->holding_time),
2287 tok2str(isis_iih_circuit_type_values,
2288 "unknown circuit type 0x%02x",
2289 header_iih_ptp->circuit_type));
2290
2291 printf("\n\t circuit-id: 0x%02x, PDU length: %u",
2292 header_iih_ptp->circuit_id,
2293 pdu_len);
2294
2295 if (vflag > 1) {
2296 if(!print_unknown_data(gndo,pptr,"\n\t ",ISIS_IIH_PTP_HEADER_SIZE))
2297 return(0);
2298 }
2299
2300 packet_len -= (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_PTP_HEADER_SIZE);
2301 pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_PTP_HEADER_SIZE);
2302 break;
2303
2304 case ISIS_PDU_L1_LSP:
2305 case ISIS_PDU_L2_LSP:
2306 if (isis_header->fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_LSP_HEADER_SIZE)) {
2307 printf(", bogus fixed header length %u should be %lu",
2308 isis_header->fixed_len, (unsigned long)ISIS_LSP_HEADER_SIZE);
2309 return (0);
2310 }
2311
2312 pdu_len=EXTRACT_16BITS(header_lsp->pdu_len);
2313 if (packet_len>pdu_len) {
2314 packet_len=pdu_len; /* do TLV decoding as long as it makes sense */
2315 length=pdu_len;
2316 }
2317
2318 TCHECK(*header_lsp);
2319 printf("\n\t lsp-id: %s, seq: 0x%08x, lifetime: %5us\n\t chksum: 0x%04x",
2320 isis_print_id(header_lsp->lsp_id, LSP_ID_LEN),
2321 EXTRACT_32BITS(header_lsp->sequence_number),
2322 EXTRACT_16BITS(header_lsp->remaining_lifetime),
2323 EXTRACT_16BITS(header_lsp->checksum));
2324
2325
2326 osi_print_cksum((u_int8_t *)header_lsp->lsp_id,
2327 EXTRACT_16BITS(header_lsp->checksum), 12, length-12);
2328
2329 /*
2330 * Clear checksum and lifetime prior to signature verification.
2331 */
2332 header_lsp->checksum[0] = 0;
2333 header_lsp->checksum[1] = 0;
2334 header_lsp->remaining_lifetime[0] = 0;
2335 header_lsp->remaining_lifetime[1] = 0;
2336
2337
2338 printf(", PDU length: %u, Flags: [ %s",
2339 pdu_len,
2340 ISIS_MASK_LSP_OL_BIT(header_lsp->typeblock) ? "Overload bit set, " : "");
2341
2342 if (ISIS_MASK_LSP_ATT_BITS(header_lsp->typeblock)) {
2343 printf("%s", ISIS_MASK_LSP_ATT_DEFAULT_BIT(header_lsp->typeblock) ? "default " : "");
2344 printf("%s", ISIS_MASK_LSP_ATT_DELAY_BIT(header_lsp->typeblock) ? "delay " : "");
2345 printf("%s", ISIS_MASK_LSP_ATT_EXPENSE_BIT(header_lsp->typeblock) ? "expense " : "");
2346 printf("%s", ISIS_MASK_LSP_ATT_ERROR_BIT(header_lsp->typeblock) ? "error " : "");
2347 printf("ATT bit set, ");
2348 }
2349 printf("%s", ISIS_MASK_LSP_PARTITION_BIT(header_lsp->typeblock) ? "P bit set, " : "");
2350 printf("%s ]", tok2str(isis_lsp_istype_values,"Unknown(0x%x)",ISIS_MASK_LSP_ISTYPE_BITS(header_lsp->typeblock)));
2351
2352 if (vflag > 1) {
2353 if(!print_unknown_data(gndo,pptr,"\n\t ",ISIS_LSP_HEADER_SIZE))
2354 return(0);
2355 }
2356
2357 packet_len -= (ISIS_COMMON_HEADER_SIZE+ISIS_LSP_HEADER_SIZE);
2358 pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_LSP_HEADER_SIZE);
2359 break;
2360
2361 case ISIS_PDU_L1_CSNP:
2362 case ISIS_PDU_L2_CSNP:
2363 if (isis_header->fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_CSNP_HEADER_SIZE)) {
2364 printf(", bogus fixed header length %u should be %lu",
2365 isis_header->fixed_len, (unsigned long)ISIS_CSNP_HEADER_SIZE);
2366 return (0);
2367 }
2368
2369 pdu_len=EXTRACT_16BITS(header_csnp->pdu_len);
2370 if (packet_len>pdu_len) {
2371 packet_len=pdu_len; /* do TLV decoding as long as it makes sense */
2372 length=pdu_len;
2373 }
2374
2375 TCHECK(*header_csnp);
2376 printf("\n\t source-id: %s, PDU length: %u",
2377 isis_print_id(header_csnp->source_id, NODE_ID_LEN),
2378 pdu_len);
2379 printf("\n\t start lsp-id: %s",
2380 isis_print_id(header_csnp->start_lsp_id, LSP_ID_LEN));
2381 printf("\n\t end lsp-id: %s",
2382 isis_print_id(header_csnp->end_lsp_id, LSP_ID_LEN));
2383
2384 if (vflag > 1) {
2385 if(!print_unknown_data(gndo,pptr,"\n\t ",ISIS_CSNP_HEADER_SIZE))
2386 return(0);
2387 }
2388
2389 packet_len -= (ISIS_COMMON_HEADER_SIZE+ISIS_CSNP_HEADER_SIZE);
2390 pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_CSNP_HEADER_SIZE);
2391 break;
2392
2393 case ISIS_PDU_L1_PSNP:
2394 case ISIS_PDU_L2_PSNP:
2395 if (isis_header->fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_PSNP_HEADER_SIZE)) {
2396 printf("- bogus fixed header length %u should be %lu",
2397 isis_header->fixed_len, (unsigned long)ISIS_PSNP_HEADER_SIZE);
2398 return (0);
2399 }
2400
2401 pdu_len=EXTRACT_16BITS(header_psnp->pdu_len);
2402 if (packet_len>pdu_len) {
2403 packet_len=pdu_len; /* do TLV decoding as long as it makes sense */
2404 length=pdu_len;
2405 }
2406
2407 TCHECK(*header_psnp);
2408 printf("\n\t source-id: %s, PDU length: %u",
2409 isis_print_id(header_psnp->source_id, NODE_ID_LEN),
2410 pdu_len);
2411
2412 if (vflag > 1) {
2413 if(!print_unknown_data(gndo,pptr,"\n\t ",ISIS_PSNP_HEADER_SIZE))
2414 return(0);
2415 }
2416
2417 packet_len -= (ISIS_COMMON_HEADER_SIZE+ISIS_PSNP_HEADER_SIZE);
2418 pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_PSNP_HEADER_SIZE);
2419 break;
2420
2421 default:
2422 if(!print_unknown_data(gndo,pptr,"\n\t ",length))
2423 return(0);
2424 return (0);
2425 }
2426
2427 /*
2428 * Now print the TLV's.
2429 */
2430
2431 while (packet_len >= 2) {
2432 if (pptr == snapend) {
2433 return (1);
2434 }
2435
2436 if (!TTEST2(*pptr, 2)) {
2437 printf("\n\t\t packet exceeded snapshot (%ld) bytes",
2438 (long)(pptr-snapend));
2439 return (1);
2440 }
2441 tlv_type = *pptr++;
2442 tlv_len = *pptr++;
2443 tmp =tlv_len; /* copy temporary len & pointer to packet data */
2444 tptr = pptr;
2445 packet_len -= 2;
2446 if (tlv_len > packet_len) {
2447 break;
2448 }
2449
2450 /* first lets see if we know the TLVs name*/
2451 printf("\n\t %s TLV #%u, length: %u",
2452 tok2str(isis_tlv_values,
2453 "unknown",
2454 tlv_type),
2455 tlv_type,
2456 tlv_len);
2457
2458 if (tlv_len == 0) /* something is malformed */
2459 continue;
2460
2461 /* now check if we have a decoder otherwise do a hexdump at the end*/
2462 switch (tlv_type) {
2463 case ISIS_TLV_AREA_ADDR:
2464 if (!TTEST2(*tptr, 1))
2465 goto trunctlv;
2466 alen = *tptr++;
2467 while (tmp && alen < tmp) {
2468 printf("\n\t Area address (length: %u): %s",
2469 alen,
2470 isonsap_string(tptr,alen));
2471 tptr += alen;
2472 tmp -= alen + 1;
2473 if (tmp==0) /* if this is the last area address do not attemt a boundary check */
2474 break;
2475 if (!TTEST2(*tptr, 1))
2476 goto trunctlv;
2477 alen = *tptr++;
2478 }
2479 break;
2480 case ISIS_TLV_ISNEIGH:
2481 while (tmp >= ETHER_ADDR_LEN) {
2482 if (!TTEST2(*tptr, ETHER_ADDR_LEN))
2483 goto trunctlv;
2484 printf("\n\t SNPA: %s",isis_print_id(tptr,ETHER_ADDR_LEN));
2485 tmp -= ETHER_ADDR_LEN;
2486 tptr += ETHER_ADDR_LEN;
2487 }
2488 break;
2489
2490 case ISIS_TLV_ISNEIGH_VARLEN:
2491 if (!TTEST2(*tptr, 1) || tmp < 3) /* min. TLV length */
2492 goto trunctlv;
2493 lan_alen = *tptr++; /* LAN address length */
2494 if (lan_alen == 0) {
2495 printf("\n\t LAN address length 0 bytes (invalid)");
2496 break;
2497 }
2498 tmp --;
2499 printf("\n\t LAN address length %u bytes ",lan_alen);
2500 while (tmp >= lan_alen) {
2501 if (!TTEST2(*tptr, lan_alen))
2502 goto trunctlv;
2503 printf("\n\t\tIS Neighbor: %s",isis_print_id(tptr,lan_alen));
2504 tmp -= lan_alen;
2505 tptr +=lan_alen;
2506 }
2507 break;
2508
2509 case ISIS_TLV_PADDING:
2510 break;
2511
2512 case ISIS_TLV_MT_IS_REACH:
2513 mt_len = isis_print_mtid(tptr, "\n\t ");
2514 if (mt_len == 0) /* did something go wrong ? */
2515 goto trunctlv;
2516 tptr+=mt_len;
2517 tmp-=mt_len;
2518 while (tmp >= 2+NODE_ID_LEN+3+1) {
2519 ext_is_len = isis_print_ext_is_reach(tptr,"\n\t ",tlv_type);
2520 if (ext_is_len == 0) /* did something go wrong ? */
2521 goto trunctlv;
2522
2523 tmp-=ext_is_len;
2524 tptr+=ext_is_len;
2525 }
2526 break;
2527
2528 case ISIS_TLV_IS_ALIAS_ID:
2529 while (tmp >= NODE_ID_LEN+1) { /* is it worth attempting a decode ? */
2530 ext_is_len = isis_print_ext_is_reach(tptr,"\n\t ",tlv_type);
2531 if (ext_is_len == 0) /* did something go wrong ? */
2532 goto trunctlv;
2533 tmp-=ext_is_len;
2534 tptr+=ext_is_len;
2535 }
2536 break;
2537
2538 case ISIS_TLV_EXT_IS_REACH:
2539 while (tmp >= NODE_ID_LEN+3+1) { /* is it worth attempting a decode ? */
2540 ext_is_len = isis_print_ext_is_reach(tptr,"\n\t ",tlv_type);
2541 if (ext_is_len == 0) /* did something go wrong ? */
2542 goto trunctlv;
2543 tmp-=ext_is_len;
2544 tptr+=ext_is_len;
2545 }
2546 break;
2547 case ISIS_TLV_IS_REACH:
2548 if (!TTEST2(*tptr,1)) /* check if there is one byte left to read out the virtual flag */
2549 goto trunctlv;
2550 printf("\n\t %s",
2551 tok2str(isis_is_reach_virtual_values,
2552 "bogus virtual flag 0x%02x",
2553 *tptr++));
2554 tlv_is_reach = (const struct isis_tlv_is_reach *)tptr;
2555 while (tmp >= sizeof(struct isis_tlv_is_reach)) {
2556 if (!TTEST(*tlv_is_reach))
2557 goto trunctlv;
2558 printf("\n\t IS Neighbor: %s",
2559 isis_print_id(tlv_is_reach->neighbor_nodeid, NODE_ID_LEN));
2560 isis_print_metric_block(&tlv_is_reach->isis_metric_block);
2561 tmp -= sizeof(struct isis_tlv_is_reach);
2562 tlv_is_reach++;
2563 }
2564 break;
2565
2566 case ISIS_TLV_ESNEIGH:
2567 tlv_es_reach = (const struct isis_tlv_es_reach *)tptr;
2568 while (tmp >= sizeof(struct isis_tlv_es_reach)) {
2569 if (!TTEST(*tlv_es_reach))
2570 goto trunctlv;
2571 printf("\n\t ES Neighbor: %s",
2572 isis_print_id(tlv_es_reach->neighbor_sysid,SYSTEM_ID_LEN));
2573 isis_print_metric_block(&tlv_es_reach->isis_metric_block);
2574 tmp -= sizeof(struct isis_tlv_es_reach);
2575 tlv_es_reach++;
2576 }
2577 break;
2578
2579 /* those two TLVs share the same format */
2580 case ISIS_TLV_INT_IP_REACH:
2581 case ISIS_TLV_EXT_IP_REACH:
2582 if (!isis_print_tlv_ip_reach(pptr, "\n\t ", tlv_len))
2583 return (1);
2584 break;
2585
2586 case ISIS_TLV_EXTD_IP_REACH:
2587 while (tmp>0) {
2588 ext_ip_len = isis_print_extd_ip_reach(tptr, "\n\t ", AF_INET);
2589 if (ext_ip_len == 0) /* did something go wrong ? */
2590 goto trunctlv;
2591 tptr+=ext_ip_len;
2592 tmp-=ext_ip_len;
2593 }
2594 break;
2595
2596 case ISIS_TLV_MT_IP_REACH:
2597 mt_len = isis_print_mtid(tptr, "\n\t ");
2598 if (mt_len == 0) { /* did something go wrong ? */
2599 goto trunctlv;
2600 }
2601 tptr+=mt_len;
2602 tmp-=mt_len;
2603
2604 while (tmp>0) {
2605 ext_ip_len = isis_print_extd_ip_reach(tptr, "\n\t ", AF_INET);
2606 if (ext_ip_len == 0) /* did something go wrong ? */
2607 goto trunctlv;
2608 tptr+=ext_ip_len;
2609 tmp-=ext_ip_len;
2610 }
2611 break;
2612
2613 #ifdef INET6
2614 case ISIS_TLV_IP6_REACH:
2615 while (tmp>0) {
2616 ext_ip_len = isis_print_extd_ip_reach(tptr, "\n\t ", AF_INET6);
2617 if (ext_ip_len == 0) /* did something go wrong ? */
2618 goto trunctlv;
2619 tptr+=ext_ip_len;
2620 tmp-=ext_ip_len;
2621 }
2622 break;
2623
2624 case ISIS_TLV_MT_IP6_REACH:
2625 mt_len = isis_print_mtid(tptr, "\n\t ");
2626 if (mt_len == 0) { /* did something go wrong ? */
2627 goto trunctlv;
2628 }
2629 tptr+=mt_len;
2630 tmp-=mt_len;
2631
2632 while (tmp>0) {
2633 ext_ip_len = isis_print_extd_ip_reach(tptr, "\n\t ", AF_INET6);
2634 if (ext_ip_len == 0) /* did something go wrong ? */
2635 goto trunctlv;
2636 tptr+=ext_ip_len;
2637 tmp-=ext_ip_len;
2638 }
2639 break;
2640
2641 case ISIS_TLV_IP6ADDR:
2642 while (tmp>=sizeof(struct in6_addr)) {
2643 if (!TTEST2(*tptr, sizeof(struct in6_addr)))
2644 goto trunctlv;
2645
2646 printf("\n\t IPv6 interface address: %s",
2647 ip6addr_string(tptr));
2648
2649 tptr += sizeof(struct in6_addr);
2650 tmp -= sizeof(struct in6_addr);
2651 }
2652 break;
2653 #endif
2654 case ISIS_TLV_AUTH:
2655 if (!TTEST2(*tptr, 1))
2656 goto trunctlv;
2657
2658 printf("\n\t %s: ",
2659 tok2str(isis_subtlv_auth_values,
2660 "unknown Authentication type 0x%02x",
2661 *tptr));
2662
2663 switch (*tptr) {
2664 case ISIS_SUBTLV_AUTH_SIMPLE:
2665 for(i=1;i<tlv_len;i++) {
2666 if (!TTEST2(*(tptr+i), 1))
2667 goto trunctlv;
2668 printf("%c",*(tptr+i));
2669 }
2670 break;
2671 case ISIS_SUBTLV_AUTH_MD5:
2672 for(i=1;i<tlv_len;i++) {
2673 if (!TTEST2(*(tptr+i), 1))
2674 goto trunctlv;
2675 printf("%02x",*(tptr+i));
2676 }
2677 if (tlv_len != ISIS_SUBTLV_AUTH_MD5_LEN+1)
2678 printf(", (malformed subTLV) ");
2679
2680 #ifdef HAVE_LIBCRYPTO
2681 sigcheck = signature_verify(optr, length,
2682 (unsigned char *)tptr + 1);
2683 #else
2684 sigcheck = CANT_CHECK_SIGNATURE;
2685 #endif
2686 printf(" (%s)", tok2str(signature_check_values, "Unknown", sigcheck));
2687
2688 break;
2689 case ISIS_SUBTLV_AUTH_GENERIC:
2690 key_id = EXTRACT_16BITS((tptr+1));
2691 printf("%u, password: ", key_id);
2692 for(i=1 + sizeof(u_int16_t);i<tlv_len;i++) {
2693 if (!TTEST2(*(tptr+i), 1))
2694 goto trunctlv;
2695 printf("%02x",*(tptr+i));
2696 }
2697 break;
2698 case ISIS_SUBTLV_AUTH_PRIVATE:
2699 default:
2700 if(!print_unknown_data(gndo,tptr+1,"\n\t\t ",tlv_len-1))
2701 return(0);
2702 break;
2703 }
2704 break;
2705
2706 case ISIS_TLV_PTP_ADJ:
2707 tlv_ptp_adj = (const struct isis_tlv_ptp_adj *)tptr;
2708 if(tmp>=1) {
2709 if (!TTEST2(*tptr, 1))
2710 goto trunctlv;
2711 printf("\n\t Adjacency State: %s (%u)",
2712 tok2str(isis_ptp_adjancey_values, "unknown", *tptr),
2713 *tptr);
2714 tmp--;
2715 }
2716 if(tmp>sizeof(tlv_ptp_adj->extd_local_circuit_id)) {
2717 if (!TTEST2(tlv_ptp_adj->extd_local_circuit_id,
2718 sizeof(tlv_ptp_adj->extd_local_circuit_id)))
2719 goto trunctlv;
2720 printf("\n\t Extended Local circuit-ID: 0x%08x",
2721 EXTRACT_32BITS(tlv_ptp_adj->extd_local_circuit_id));
2722 tmp-=sizeof(tlv_ptp_adj->extd_local_circuit_id);
2723 }
2724 if(tmp>=SYSTEM_ID_LEN) {
2725 if (!TTEST2(tlv_ptp_adj->neighbor_sysid, SYSTEM_ID_LEN))
2726 goto trunctlv;
2727 printf("\n\t Neighbor System-ID: %s",
2728 isis_print_id(tlv_ptp_adj->neighbor_sysid,SYSTEM_ID_LEN));
2729 tmp-=SYSTEM_ID_LEN;
2730 }
2731 if(tmp>=sizeof(tlv_ptp_adj->neighbor_extd_local_circuit_id)) {
2732 if (!TTEST2(tlv_ptp_adj->neighbor_extd_local_circuit_id,
2733 sizeof(tlv_ptp_adj->neighbor_extd_local_circuit_id)))
2734 goto trunctlv;
2735 printf("\n\t Neighbor Extended Local circuit-ID: 0x%08x",
2736 EXTRACT_32BITS(tlv_ptp_adj->neighbor_extd_local_circuit_id));
2737 }
2738 break;
2739
2740 case ISIS_TLV_PROTOCOLS:
2741 printf("\n\t NLPID(s): ");
2742 while (tmp>0) {
2743 if (!TTEST2(*(tptr), 1))
2744 goto trunctlv;
2745 printf("%s (0x%02x)",
2746 tok2str(nlpid_values,
2747 "unknown",
2748 *tptr),
2749 *tptr);
2750 if (tmp>1) /* further NPLIDs ? - put comma */
2751 printf(", ");
2752 tptr++;
2753 tmp--;
2754 }
2755 break;
2756
2757 case ISIS_TLV_MT_PORT_CAP:
2758 {
2759 if (!TTEST2(*(tptr), 2))
2760 goto trunctlv;
2761
2762 printf("\n\t RES: %d, MTID(s): %d",
2763 (EXTRACT_16BITS (tptr) >> 12),
2764 (EXTRACT_16BITS (tptr) & 0x0fff));
2765
2766 tmp = tmp-2;
2767 tptr = tptr+2;
2768
2769 if (tmp)
2770 isis_print_mt_port_cap_subtlv (tptr, tmp);
2771
2772 break;
2773 }
2774
2775 case ISIS_TLV_MT_CAPABILITY:
2776
2777 if (!TTEST2(*(tptr), 2))
2778 goto trunctlv;
2779
2780 printf("\n\t O: %d, RES: %d, MTID(s): %d",
2781 (EXTRACT_16BITS(tptr) >> 15) & 0x01,
2782 (EXTRACT_16BITS(tptr) >> 12) & 0x07,
2783 EXTRACT_16BITS(tptr) & 0x0fff);
2784
2785 tmp = tmp-2;
2786 tptr = tptr+2;
2787
2788 if (tmp)
2789 isis_print_mt_capability_subtlv (tptr, tmp);
2790
2791 break;
2792
2793 case ISIS_TLV_TE_ROUTER_ID:
2794 if (!TTEST2(*pptr, sizeof(struct in_addr)))
2795 goto trunctlv;
2796 printf("\n\t Traffic Engineering Router ID: %s", ipaddr_string(pptr));
2797 break;
2798
2799 case ISIS_TLV_IPADDR:
2800 while (tmp>=sizeof(struct in_addr)) {
2801 if (!TTEST2(*tptr, sizeof(struct in_addr)))
2802 goto trunctlv;
2803 printf("\n\t IPv4 interface address: %s", ipaddr_string(tptr));
2804 tptr += sizeof(struct in_addr);
2805 tmp -= sizeof(struct in_addr);
2806 }
2807 break;
2808
2809 case ISIS_TLV_HOSTNAME:
2810 printf("\n\t Hostname: ");
2811 while (tmp>0) {
2812 if (!TTEST2(*tptr, 1))
2813 goto trunctlv;
2814 printf("%c",*tptr++);
2815 tmp--;
2816 }
2817 break;
2818
2819 case ISIS_TLV_SHARED_RISK_GROUP:
2820 if (tmp < NODE_ID_LEN)
2821 break;
2822 if (!TTEST2(*tptr, NODE_ID_LEN))
2823 goto trunctlv;
2824 printf("\n\t IS Neighbor: %s", isis_print_id(tptr, NODE_ID_LEN));
2825 tptr+=(NODE_ID_LEN);
2826 tmp-=(NODE_ID_LEN);
2827
2828 if (tmp < 1)
2829 break;
2830 if (!TTEST2(*tptr, 1))
2831 goto trunctlv;
2832 printf(", Flags: [%s]", ISIS_MASK_TLV_SHARED_RISK_GROUP(*tptr++) ? "numbered" : "unnumbered");
2833 tmp--;
2834
2835 if (tmp < sizeof(struct in_addr))
2836 break;
2837 if (!TTEST2(*tptr,sizeof(struct in_addr)))
2838 goto trunctlv;
2839 printf("\n\t IPv4 interface address: %s", ipaddr_string(tptr));
2840 tptr+=sizeof(struct in_addr);
2841 tmp-=sizeof(struct in_addr);
2842
2843 if (tmp < sizeof(struct in_addr))
2844 break;
2845 if (!TTEST2(*tptr,sizeof(struct in_addr)))
2846 goto trunctlv;
2847 printf("\n\t IPv4 neighbor address: %s", ipaddr_string(tptr));
2848 tptr+=sizeof(struct in_addr);
2849 tmp-=sizeof(struct in_addr);
2850
2851 while (tmp>=4) {
2852 if (!TTEST2(*tptr, 4))
2853 goto trunctlv;
2854 printf("\n\t Link-ID: 0x%08x", EXTRACT_32BITS(tptr));
2855 tptr+=4;
2856 tmp-=4;
2857 }
2858 break;
2859
2860 case ISIS_TLV_LSP:
2861 tlv_lsp = (const struct isis_tlv_lsp *)tptr;
2862 while(tmp>=sizeof(struct isis_tlv_lsp)) {
2863 if (!TTEST((tlv_lsp->lsp_id)[LSP_ID_LEN-1]))
2864 goto trunctlv;
2865 printf("\n\t lsp-id: %s",
2866 isis_print_id(tlv_lsp->lsp_id, LSP_ID_LEN));
2867 if (!TTEST2(tlv_lsp->sequence_number, 4))
2868 goto trunctlv;
2869 printf(", seq: 0x%08x",EXTRACT_32BITS(tlv_lsp->sequence_number));
2870 if (!TTEST2(tlv_lsp->remaining_lifetime, 2))
2871 goto trunctlv;
2872 printf(", lifetime: %5ds",EXTRACT_16BITS(tlv_lsp->remaining_lifetime));
2873 if (!TTEST2(tlv_lsp->checksum, 2))
2874 goto trunctlv;
2875 printf(", chksum: 0x%04x",EXTRACT_16BITS(tlv_lsp->checksum));
2876 tmp-=sizeof(struct isis_tlv_lsp);
2877 tlv_lsp++;
2878 }
2879 break;
2880
2881 case ISIS_TLV_CHECKSUM:
2882 if (tmp < ISIS_TLV_CHECKSUM_MINLEN)
2883 break;
2884 if (!TTEST2(*tptr, ISIS_TLV_CHECKSUM_MINLEN))
2885 goto trunctlv;
2886 printf("\n\t checksum: 0x%04x ", EXTRACT_16BITS(tptr));
2887 /* do not attempt to verify the checksum if it is zero
2888 * most likely a HMAC-MD5 TLV is also present and
2889 * to avoid conflicts the checksum TLV is zeroed.
2890 * see rfc3358 for details
2891 */
2892 osi_print_cksum(optr, EXTRACT_16BITS(tptr), tptr-optr, length);
2893 break;
2894
2895 case ISIS_TLV_MT_SUPPORTED:
2896 if (tmp < ISIS_TLV_MT_SUPPORTED_MINLEN)
2897 break;
2898 while (tmp>1) {
2899 /* length can only be a multiple of 2, otherwise there is
2900 something broken -> so decode down until length is 1 */
2901 if (tmp!=1) {
2902 mt_len = isis_print_mtid(tptr, "\n\t ");
2903 if (mt_len == 0) /* did something go wrong ? */
2904 goto trunctlv;
2905 tptr+=mt_len;
2906 tmp-=mt_len;
2907 } else {
2908 printf("\n\t malformed MT-ID");
2909 break;
2910 }
2911 }
2912 break;
2913
2914 case ISIS_TLV_RESTART_SIGNALING:
2915 /* first attempt to decode the flags */
2916 if (tmp < ISIS_TLV_RESTART_SIGNALING_FLAGLEN)
2917 break;
2918 if (!TTEST2(*tptr, ISIS_TLV_RESTART_SIGNALING_FLAGLEN))
2919 goto trunctlv;
2920 printf("\n\t Flags [%s]",
2921 bittok2str(isis_restart_flag_values, "none", *tptr));
2922 tptr+=ISIS_TLV_RESTART_SIGNALING_FLAGLEN;
2923 tmp-=ISIS_TLV_RESTART_SIGNALING_FLAGLEN;
2924
2925 /* is there anything other than the flags field? */
2926 if (tmp == 0)
2927 break;
2928
2929 if (tmp < ISIS_TLV_RESTART_SIGNALING_HOLDTIMELEN)
2930 break;
2931 if (!TTEST2(*tptr, ISIS_TLV_RESTART_SIGNALING_HOLDTIMELEN))
2932 goto trunctlv;
2933
2934 printf(", Remaining holding time %us", EXTRACT_16BITS(tptr));
2935 tptr+=ISIS_TLV_RESTART_SIGNALING_HOLDTIMELEN;
2936 tmp-=ISIS_TLV_RESTART_SIGNALING_HOLDTIMELEN;
2937
2938 /* is there an additional sysid field present ?*/
2939 if (tmp == SYSTEM_ID_LEN) {
2940 if (!TTEST2(*tptr, SYSTEM_ID_LEN))
2941 goto trunctlv;
2942 printf(", for %s",isis_print_id(tptr,SYSTEM_ID_LEN));
2943 }
2944 break;
2945
2946 case ISIS_TLV_IDRP_INFO:
2947 if (tmp < ISIS_TLV_IDRP_INFO_MINLEN)
2948 break;
2949 if (!TTEST2(*tptr, ISIS_TLV_IDRP_INFO_MINLEN))
2950 goto trunctlv;
2951 printf("\n\t Inter-Domain Information Type: %s",
2952 tok2str(isis_subtlv_idrp_values,
2953 "Unknown (0x%02x)",
2954 *tptr));
2955 switch (*tptr++) {
2956 case ISIS_SUBTLV_IDRP_ASN:
2957 if (!TTEST2(*tptr, 2)) /* fetch AS number */
2958 goto trunctlv;
2959 printf("AS Number: %u",EXTRACT_16BITS(tptr));
2960 break;
2961 case ISIS_SUBTLV_IDRP_LOCAL:
2962 case ISIS_SUBTLV_IDRP_RES:
2963 default:
2964 if(!print_unknown_data(gndo,tptr,"\n\t ",tlv_len-1))
2965 return(0);
2966 break;
2967 }
2968 break;
2969
2970 case ISIS_TLV_LSP_BUFFERSIZE:
2971 if (tmp < ISIS_TLV_LSP_BUFFERSIZE_MINLEN)
2972 break;
2973 if (!TTEST2(*tptr, ISIS_TLV_LSP_BUFFERSIZE_MINLEN))
2974 goto trunctlv;
2975 printf("\n\t LSP Buffersize: %u",EXTRACT_16BITS(tptr));
2976 break;
2977
2978 case ISIS_TLV_PART_DIS:
2979 while (tmp >= SYSTEM_ID_LEN) {
2980 if (!TTEST2(*tptr, SYSTEM_ID_LEN))
2981 goto trunctlv;
2982 printf("\n\t %s",isis_print_id(tptr,SYSTEM_ID_LEN));
2983 tptr+=SYSTEM_ID_LEN;
2984 tmp-=SYSTEM_ID_LEN;
2985 }
2986 break;
2987
2988 case ISIS_TLV_PREFIX_NEIGH:
2989 if (tmp < sizeof(struct isis_metric_block))
2990 break;
2991 if (!TTEST2(*tptr, sizeof(struct isis_metric_block)))
2992 goto trunctlv;
2993 printf("\n\t Metric Block");
2994 isis_print_metric_block((const struct isis_metric_block *)tptr);
2995 tptr+=sizeof(struct isis_metric_block);
2996 tmp-=sizeof(struct isis_metric_block);
2997
2998 while(tmp>0) {
2999 if (!TTEST2(*tptr, 1))
3000 goto trunctlv;
3001 prefix_len=*tptr++; /* read out prefix length in semioctets*/
3002 if (prefix_len < 2) {
3003 printf("\n\t\tAddress: prefix length %u < 2", prefix_len);
3004 break;
3005 }
3006 tmp--;
3007 if (tmp < prefix_len/2)
3008 break;
3009 if (!TTEST2(*tptr, prefix_len/2))
3010 goto trunctlv;
3011 printf("\n\t\tAddress: %s/%u",
3012 isonsap_string(tptr,prefix_len/2),
3013 prefix_len*4);
3014 tptr+=prefix_len/2;
3015 tmp-=prefix_len/2;
3016 }
3017 break;
3018
3019 case ISIS_TLV_IIH_SEQNR:
3020 if (tmp < ISIS_TLV_IIH_SEQNR_MINLEN)
3021 break;
3022 if (!TTEST2(*tptr, ISIS_TLV_IIH_SEQNR_MINLEN)) /* check if four bytes are on the wire */
3023 goto trunctlv;
3024 printf("\n\t Sequence number: %u", EXTRACT_32BITS(tptr) );
3025 break;
3026
3027 case ISIS_TLV_VENDOR_PRIVATE:
3028 if (tmp < ISIS_TLV_VENDOR_PRIVATE_MINLEN)
3029 break;
3030 if (!TTEST2(*tptr, ISIS_TLV_VENDOR_PRIVATE_MINLEN)) /* check if enough byte for a full oui */
3031 goto trunctlv;
3032 vendor_id = EXTRACT_24BITS(tptr);
3033 printf("\n\t Vendor: %s (%u)",
3034 tok2str(oui_values,"Unknown",vendor_id),
3035 vendor_id);
3036 tptr+=3;
3037 tmp-=3;
3038 if (tmp > 0) /* hexdump the rest */
3039 if(!print_unknown_data(gndo,tptr,"\n\t\t",tmp))
3040 return(0);
3041 break;
3042 /*
3043 * FIXME those are the defined TLVs that lack a decoder
3044 * you are welcome to contribute code ;-)
3045 */
3046
3047 case ISIS_TLV_DECNET_PHASE4:
3048 case ISIS_TLV_LUCENT_PRIVATE:
3049 case ISIS_TLV_IPAUTH:
3050 case ISIS_TLV_NORTEL_PRIVATE1:
3051 case ISIS_TLV_NORTEL_PRIVATE2:
3052
3053 default:
3054 if (vflag <= 1) {
3055 if(!print_unknown_data(gndo,pptr,"\n\t\t",tlv_len))
3056 return(0);
3057 }
3058 break;
3059 }
3060 /* do we want to see an additionally hexdump ? */
3061 if (vflag> 1) {
3062 if(!print_unknown_data(gndo,pptr,"\n\t ",tlv_len))
3063 return(0);
3064 }
3065
3066 pptr += tlv_len;
3067 packet_len -= tlv_len;
3068 }
3069
3070 if (packet_len != 0) {
3071 printf("\n\t %u straggler bytes", packet_len);
3072 }
3073 return (1);
3074
3075 trunc:
3076 fputs("[|isis]", stdout);
3077 return (1);
3078
3079 trunctlv:
3080 printf("\n\t\t packet exceeded snapshot");
3081 return(1);
3082 }
3083
3084 static void
3085 osi_print_cksum (const u_int8_t *pptr, u_int16_t checksum,
3086 u_int checksum_offset, u_int length)
3087 {
3088 u_int16_t calculated_checksum;
3089
3090 /* do not attempt to verify the checksum if it is zero */
3091 if (!checksum) {
3092 printf("(unverified)");
3093 } else {
3094 calculated_checksum = create_osi_cksum(pptr, checksum_offset, length);
3095 if (checksum == calculated_checksum) {
3096 printf(" (correct)");
3097 } else {
3098 printf(" (incorrect should be 0x%04x)", calculated_checksum);
3099 }
3100 }
3101 }
3102
3103 /*
3104 * Local Variables:
3105 * c-style: whitesmith
3106 * c-basic-offset: 8
3107 * End:
3108 */