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