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