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