]> The Tcpdump Group git mirrors - tcpdump/blob - print-isoclns.c
check against min. TLV length / get if logic right
[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.136 2005-04-25 10:41:06 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 #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 li = esis_header->length_indicator;
876 optr = pptr;
877
878 /*
879 * Sanity checking of the header.
880 */
881
882 if (esis_header->nlpid != NLPID_ESIS) {
883 printf(" nlpid 0x%02x packet not supported", esis_header->nlpid);
884 return;
885 }
886
887 if (esis_header->version != ESIS_VERSION) {
888 printf(" version %d packet not supported", esis_header->version);
889 return;
890 }
891
892 if (li > length) {
893 printf(" length indicator(%d) > PDU size (%d)!", li, length);
894 return;
895 }
896
897 if (li < sizeof(struct esis_header_t) + 2) {
898 printf(" length indicator < min PDU size %d:", li);
899 while (--length != 0)
900 printf("%02X", *pptr++);
901 return;
902 }
903
904 esis_pdu_type = esis_header->type & ESIS_PDU_TYPE_MASK;
905
906 if (vflag < 1) {
907 printf("%s%s, length %u",
908 eflag ? "" : ", ",
909 tok2str(esis_pdu_values,"unknown type (%u)",esis_pdu_type),
910 length);
911 return;
912 } else
913 printf("%slength %u\n\t%s (%u)",
914 eflag ? "" : ", ",
915 length,
916 tok2str(esis_pdu_values,"unknown type: %u", esis_pdu_type),
917 esis_pdu_type);
918
919 printf(", v: %u%s", esis_header->version, esis_header->version == ESIS_VERSION ? "" : "unsupported" );
920 printf(", checksum: 0x%04x ", EXTRACT_16BITS(esis_header->cksum));
921 /* do not attempt to verify the checksum if it is zero */
922 if (EXTRACT_16BITS(esis_header->cksum) == 0)
923 printf("(unverified)");
924 else printf("(%s)", osi_cksum(pptr, li) ? "incorrect" : "correct");
925
926 printf(", holding time: %us, length indicator: %u",EXTRACT_16BITS(esis_header->holdtime),li);
927
928 if (vflag > 1)
929 print_unknown_data(optr,"\n\t",sizeof(struct esis_header_t));
930
931 pptr += sizeof(struct esis_header_t);
932 li -= sizeof(struct esis_header_t);
933
934 switch (esis_pdu_type) {
935 case ESIS_PDU_REDIRECT: {
936 const u_int8_t *dst, *snpa, *tptr;
937
938 dst = pptr; pptr += *pptr + 1;
939 if (pptr > snapend)
940 return;
941 printf("\n\t %s", isonsap_string(dst+1,*dst));
942 snpa = pptr; pptr += *pptr + 1;
943 tptr = pptr; pptr += *pptr + 1;
944 if (pptr > snapend)
945 return;
946
947 if (tptr[0] == 0)
948 printf("\n\t %s", etheraddr_string(&snpa[1]));
949 else
950 printf("\n\t %s", isonsap_string(tptr+1,*tptr));
951 break;
952 }
953
954 case ESIS_PDU_ESH:
955 source_address_number = *pptr;
956 pptr++;
957 li--;
958
959 printf("\n\t Number of Source Addresses: %u", source_address_number);
960
961 while (source_address_number > 0) {
962 source_address_length = *pptr;
963 printf("\n\t NET (length: %u): %s",
964 source_address_length,
965 isonsap_string(pptr+1,source_address_length));
966
967 pptr += source_address_length+1;
968 li -= source_address_length+1;
969 source_address_number--;
970 }
971
972 break;
973
974 case ESIS_PDU_ISH: {
975 source_address_length = *pptr;
976 printf("\n\t NET (length: %u): %s", source_address_length, isonsap_string(pptr+1, source_address_length));
977 pptr += source_address_length+1;
978 li -= source_address_length +1;
979 break;
980 }
981
982 default:
983 if (vflag <= 1) {
984 if (pptr < snapend)
985 print_unknown_data(pptr,"\n\t ",snapend-pptr);
986 }
987 return;
988 }
989
990 /* now walk the options */
991 while (li >= 2) {
992 u_int op, opli;
993 const u_int8_t *tptr;
994
995 if (snapend - pptr < 2)
996 return;
997 if (li < 2) {
998 printf(", bad opts/li");
999 return;
1000 }
1001 op = *pptr++;
1002 opli = *pptr++;
1003 li -= 2;
1004 if (opli > li) {
1005 printf(", opt (%d) too long", op);
1006 return;
1007 }
1008 li -= opli;
1009 tptr = pptr;
1010
1011 if (snapend < pptr)
1012 return;
1013
1014 printf("\n\t %s Option #%u, length %u, value: ",
1015 tok2str(esis_option_values,"Unknown",op),
1016 op,
1017 opli);
1018
1019 switch (op) {
1020
1021 case ESIS_OPTION_ES_CONF_TIME:
1022 printf("%us", EXTRACT_16BITS(tptr));
1023 break;
1024
1025
1026 case ESIS_OPTION_PROTOCOLS:
1027 while (opli>0) {
1028 printf("%s (0x%02x)",
1029 tok2str(nlpid_values,
1030 "unknown",
1031 *tptr),
1032 *tptr);
1033 if (opli>1) /* further NPLIDs ? - put comma */
1034 printf(", ");
1035 tptr++;
1036 opli--;
1037 }
1038 break;
1039
1040 /*
1041 * FIXME those are the defined Options that lack a decoder
1042 * you are welcome to contribute code ;-)
1043 */
1044
1045 case ESIS_OPTION_QOS_MAINTENANCE:
1046 case ESIS_OPTION_SECURITY:
1047 case ESIS_OPTION_PRIORITY:
1048 case ESIS_OPTION_ADDRESS_MASK:
1049 case ESIS_OPTION_SNPA_MASK:
1050
1051 default:
1052 print_unknown_data(tptr,"\n\t ",opli);
1053 break;
1054 }
1055 if (vflag > 1)
1056 print_unknown_data(pptr,"\n\t ",opli);
1057 pptr += opli;
1058 }
1059 }
1060
1061 /* shared routine for printing system, node and lsp-ids */
1062 static char *
1063 isis_print_id(const u_int8_t *cp, int id_len)
1064 {
1065 int i;
1066 static char id[sizeof("xxxx.xxxx.xxxx.yy-zz")];
1067 char *pos = id;
1068
1069 for (i = 1; i <= SYSTEM_ID_LEN; i++) {
1070 snprintf(pos, sizeof(id) - (pos - id), "%02x", *cp++);
1071 pos += strlen(pos);
1072 if (i == 2 || i == 4)
1073 *pos++ = '.';
1074 }
1075 if (id_len >= NODE_ID_LEN) {
1076 snprintf(pos, sizeof(id) - (pos - id), ".%02x", *cp++);
1077 pos += strlen(pos);
1078 }
1079 if (id_len == LSP_ID_LEN)
1080 snprintf(pos, sizeof(id) - (pos - id), "-%02x", *cp);
1081 return (id);
1082 }
1083
1084 /* print the 4-byte metric block which is common found in the old-style TLVs */
1085 static int
1086 isis_print_metric_block (const struct isis_metric_block *isis_metric_block)
1087 {
1088 printf(", Default Metric: %d, %s",
1089 ISIS_LSP_TLV_METRIC_VALUE(isis_metric_block->metric_default),
1090 ISIS_LSP_TLV_METRIC_IE(isis_metric_block->metric_default) ? "External" : "Internal");
1091 if (!ISIS_LSP_TLV_METRIC_SUPPORTED(isis_metric_block->metric_delay))
1092 printf("\n\t\t Delay Metric: %d, %s",
1093 ISIS_LSP_TLV_METRIC_VALUE(isis_metric_block->metric_delay),
1094 ISIS_LSP_TLV_METRIC_IE(isis_metric_block->metric_delay) ? "External" : "Internal");
1095 if (!ISIS_LSP_TLV_METRIC_SUPPORTED(isis_metric_block->metric_expense))
1096 printf("\n\t\t Expense Metric: %d, %s",
1097 ISIS_LSP_TLV_METRIC_VALUE(isis_metric_block->metric_expense),
1098 ISIS_LSP_TLV_METRIC_IE(isis_metric_block->metric_expense) ? "External" : "Internal");
1099 if (!ISIS_LSP_TLV_METRIC_SUPPORTED(isis_metric_block->metric_error))
1100 printf("\n\t\t Error Metric: %d, %s",
1101 ISIS_LSP_TLV_METRIC_VALUE(isis_metric_block->metric_error),
1102 ISIS_LSP_TLV_METRIC_IE(isis_metric_block->metric_error) ? "External" : "Internal");
1103
1104 return(1); /* everything is ok */
1105 }
1106
1107 static int
1108 isis_print_tlv_ip_reach (const u_int8_t *cp, const char *ident, int length)
1109 {
1110 int prefix_len;
1111 const struct isis_tlv_ip_reach *tlv_ip_reach;
1112
1113 tlv_ip_reach = (const struct isis_tlv_ip_reach *)cp;
1114
1115 while (length > 0) {
1116 if ((size_t)length < sizeof(*tlv_ip_reach)) {
1117 printf("short IPv4 Reachability (%d vs %lu)",
1118 length,
1119 (unsigned long)sizeof(*tlv_ip_reach));
1120 return (0);
1121 }
1122
1123 if (!TTEST(*tlv_ip_reach))
1124 return (0);
1125
1126 prefix_len = mask2plen(EXTRACT_32BITS(tlv_ip_reach->mask));
1127
1128 if (prefix_len == -1)
1129 printf("%sIPv4 prefix: %s mask %s",
1130 ident,
1131 ipaddr_string((tlv_ip_reach->prefix)),
1132 ipaddr_string((tlv_ip_reach->mask)));
1133 else
1134 printf("%sIPv4 prefix: %15s/%u",
1135 ident,
1136 ipaddr_string((tlv_ip_reach->prefix)),
1137 prefix_len);
1138
1139 printf(", Distribution: %s, Metric: %u, %s",
1140 ISIS_LSP_TLV_METRIC_UPDOWN(tlv_ip_reach->isis_metric_block.metric_default) ? "down" : "up",
1141 ISIS_LSP_TLV_METRIC_VALUE(tlv_ip_reach->isis_metric_block.metric_default),
1142 ISIS_LSP_TLV_METRIC_IE(tlv_ip_reach->isis_metric_block.metric_default) ? "External" : "Internal");
1143
1144 if (!ISIS_LSP_TLV_METRIC_SUPPORTED(tlv_ip_reach->isis_metric_block.metric_delay))
1145 printf("%s Delay Metric: %u, %s",
1146 ident,
1147 ISIS_LSP_TLV_METRIC_VALUE(tlv_ip_reach->isis_metric_block.metric_delay),
1148 ISIS_LSP_TLV_METRIC_IE(tlv_ip_reach->isis_metric_block.metric_delay) ? "External" : "Internal");
1149
1150 if (!ISIS_LSP_TLV_METRIC_SUPPORTED(tlv_ip_reach->isis_metric_block.metric_expense))
1151 printf("%s Expense Metric: %u, %s",
1152 ident,
1153 ISIS_LSP_TLV_METRIC_VALUE(tlv_ip_reach->isis_metric_block.metric_expense),
1154 ISIS_LSP_TLV_METRIC_IE(tlv_ip_reach->isis_metric_block.metric_expense) ? "External" : "Internal");
1155
1156 if (!ISIS_LSP_TLV_METRIC_SUPPORTED(tlv_ip_reach->isis_metric_block.metric_error))
1157 printf("%s Error Metric: %u, %s",
1158 ident,
1159 ISIS_LSP_TLV_METRIC_VALUE(tlv_ip_reach->isis_metric_block.metric_error),
1160 ISIS_LSP_TLV_METRIC_IE(tlv_ip_reach->isis_metric_block.metric_error) ? "External" : "Internal");
1161
1162 length -= sizeof(struct isis_tlv_ip_reach);
1163 tlv_ip_reach++;
1164 }
1165 return (1);
1166 }
1167
1168 /*
1169 * this is the common IP-REACH subTLV decoder it is called
1170 * from various EXTD-IP REACH TLVs (135,235,236,237)
1171 */
1172
1173 static int
1174 isis_print_ip_reach_subtlv (const u_int8_t *tptr,int subt,int subl,const char *ident) {
1175
1176 /* first lets see if we know the subTLVs name*/
1177 printf("%s%s subTLV #%u, length: %u",
1178 ident,
1179 tok2str(isis_ext_ip_reach_subtlv_values,
1180 "unknown",
1181 subt),
1182 subt,
1183 subl);
1184
1185 if (!TTEST2(*tptr,subl))
1186 goto trunctlv;
1187
1188 switch(subt) {
1189 case ISIS_SUBTLV_EXTD_IP_REACH_MGMT_PREFIX_COLOR: /* fall through */
1190 case ISIS_SUBTLV_EXTD_IP_REACH_ADMIN_TAG32:
1191 while (subl >= 4) {
1192 printf(", 0x%08x (=%u)",
1193 EXTRACT_32BITS(tptr),
1194 EXTRACT_32BITS(tptr));
1195 tptr+=4;
1196 subl-=4;
1197 }
1198 break;
1199 case ISIS_SUBTLV_EXTD_IP_REACH_ADMIN_TAG64:
1200 while (subl >= 8) {
1201 printf(", 0x%08x%08x",
1202 EXTRACT_32BITS(tptr),
1203 EXTRACT_32BITS(tptr+4));
1204 tptr+=8;
1205 subl-=8;
1206 }
1207 break;
1208 default:
1209 if(!print_unknown_data(tptr,"\n\t\t ",
1210 subl))
1211 return(0);
1212 break;
1213 }
1214 return(1);
1215
1216 trunctlv:
1217 printf("%spacket exceeded snapshot",ident);
1218 return(0);
1219 }
1220
1221 /*
1222 * this is the common IS-REACH subTLV decoder it is called
1223 * from isis_print_ext_is_reach()
1224 */
1225
1226 static int
1227 isis_print_is_reach_subtlv (const u_int8_t *tptr,int subt,int subl,const char *ident) {
1228
1229 int priority_level,bandwidth_constraint;
1230 union { /* int to float conversion buffer for several subTLVs */
1231 float f;
1232 u_int32_t i;
1233 } bw;
1234
1235 /* first lets see if we know the subTLVs name*/
1236 printf("%s%s subTLV #%u, length: %u",
1237 ident,
1238 tok2str(isis_ext_is_reach_subtlv_values,
1239 "unknown",
1240 subt),
1241 subt,
1242 subl);
1243
1244 if (!TTEST2(*tptr,subl))
1245 goto trunctlv;
1246
1247 switch(subt) {
1248 case ISIS_SUBTLV_EXT_IS_REACH_ADMIN_GROUP:
1249 case ISIS_SUBTLV_EXT_IS_REACH_LINK_LOCAL_REMOTE_ID:
1250 case ISIS_SUBTLV_EXT_IS_REACH_LINK_REMOTE_ID:
1251 if (subl >= 4) {
1252 printf(", 0x%08x", EXTRACT_32BITS(tptr));
1253 if (subl == 8) /* draft-ietf-isis-gmpls-extensions */
1254 printf(", 0x%08x", EXTRACT_32BITS(tptr+4));
1255 }
1256 break;
1257 case ISIS_SUBTLV_EXT_IS_REACH_IPV4_INTF_ADDR:
1258 case ISIS_SUBTLV_EXT_IS_REACH_IPV4_NEIGHBOR_ADDR:
1259 if (subl >= 4)
1260 printf(", %s", ipaddr_string(tptr));
1261 break;
1262 case ISIS_SUBTLV_EXT_IS_REACH_MAX_LINK_BW :
1263 case ISIS_SUBTLV_EXT_IS_REACH_RESERVABLE_BW:
1264 if (subl >= 4) {
1265 bw.i = EXTRACT_32BITS(tptr);
1266 printf(", %.3f Mbps", bw.f*8/1000000 );
1267 }
1268 break;
1269 case ISIS_SUBTLV_EXT_IS_REACH_UNRESERVED_BW :
1270 if (subl >= 32) {
1271 for (priority_level = 0; priority_level < 8; priority_level++) {
1272 bw.i = EXTRACT_32BITS(tptr);
1273 printf("%s priority level %d: %.3f Mbps",
1274 ident,
1275 priority_level,
1276 bw.f*8/1000000 );
1277 tptr+=4;
1278 }
1279 }
1280 break;
1281 case ISIS_SUBTLV_EXT_IS_REACH_DIFFSERV_TE:
1282 printf("%sBandwidth Constraints Model ID: %s (%u)",
1283 ident,
1284 tok2str(diffserv_te_bc_values, "unknown", *tptr),
1285 *tptr);
1286 tptr++;
1287 /* decode BCs until the subTLV ends */
1288 for (bandwidth_constraint = 0; bandwidth_constraint < (subl-1)/4; bandwidth_constraint++) {
1289 bw.i = EXTRACT_32BITS(tptr);
1290 printf("%s Bandwidth constraint %d: %.3f Mbps",
1291 ident,
1292 bandwidth_constraint,
1293 bw.f*8/1000000 );
1294 tptr+=4;
1295 }
1296 break;
1297 case ISIS_SUBTLV_EXT_IS_REACH_TE_METRIC:
1298 if (subl >= 3)
1299 printf(", %u", EXTRACT_24BITS(tptr));
1300 break;
1301 case ISIS_SUBTLV_EXT_IS_REACH_LINK_PROTECTION_TYPE:
1302 if (subl >= 2) {
1303 printf(", %s, Priority %u",
1304 bittok2str(gmpls_link_prot_values, "none", *tptr),
1305 *(tptr+1));
1306 }
1307 break;
1308 case ISIS_SUBTLV_EXT_IS_REACH_INTF_SW_CAP_DESCR:
1309 if (subl >= 36) {
1310 printf("%s Interface Switching Capability:%s",
1311 ident,
1312 tok2str(gmpls_switch_cap_values, "Unknown", *(tptr)));
1313 printf(", LSP Encoding: %s",
1314 tok2str(gmpls_encoding_values, "Unknown", *(tptr+1)));
1315 tptr+=4;
1316 printf("%s Max LSP Bandwidth:",ident);
1317 for (priority_level = 0; priority_level < 8; priority_level++) {
1318 bw.i = EXTRACT_32BITS(tptr);
1319 printf("%s priority level %d: %.3f Mbps",
1320 ident,
1321 priority_level,
1322 bw.f*8/1000000 );
1323 tptr+=4;
1324 }
1325 subl-=36;
1326 /* there is some optional stuff left to decode but this is as of yet
1327 not specified so just lets hexdump what is left */
1328 if(subl>0){
1329 if(!print_unknown_data(tptr,"\n\t\t ",
1330 subl-36))
1331 return(0);
1332 }
1333 }
1334 break;
1335 default:
1336 if(!print_unknown_data(tptr,"\n\t\t ",
1337 subl))
1338 return(0);
1339 break;
1340 }
1341 return(1);
1342
1343 trunctlv:
1344 printf("%spacket exceeded snapshot",ident);
1345 return(0);
1346 }
1347
1348
1349 /*
1350 * this is the common IS-REACH decoder it is called
1351 * from various EXTD-IS REACH style TLVs (22,24,222)
1352 */
1353
1354 static int
1355 isis_print_ext_is_reach (const u_int8_t *tptr,const char *ident, int tlv_type) {
1356
1357 char ident_buffer[20];
1358 int subtlv_type,subtlv_len,subtlv_sum_len;
1359 int proc_bytes = 0; /* how many bytes did we process ? */
1360
1361 if (!TTEST2(*tptr, NODE_ID_LEN))
1362 return(0);
1363
1364 printf("%sIS Neighbor: %s", ident, isis_print_id(tptr, NODE_ID_LEN));
1365 tptr+=(NODE_ID_LEN);
1366
1367 if (tlv_type != ISIS_TLV_IS_ALIAS_ID) { /* the Alias TLV Metric field is implicit 0 */
1368 if (!TTEST2(*tptr, 3)) /* and is therefore skipped */
1369 return(0);
1370 printf(", Metric: %d",EXTRACT_24BITS(tptr));
1371 tptr+=3;
1372 }
1373
1374 if (!TTEST2(*tptr, 1))
1375 return(0);
1376 subtlv_sum_len=*(tptr++); /* read out subTLV length */
1377 proc_bytes=NODE_ID_LEN+3+1;
1378 printf(", %ssub-TLVs present",subtlv_sum_len ? "" : "no ");
1379 if (subtlv_sum_len) {
1380 printf(" (%u)",subtlv_sum_len);
1381 while (subtlv_sum_len>0) {
1382 if (!TTEST2(*tptr,2))
1383 return(0);
1384 subtlv_type=*(tptr++);
1385 subtlv_len=*(tptr++);
1386 /* prepend the ident string */
1387 snprintf(ident_buffer, sizeof(ident_buffer), "%s ",ident);
1388 if(!isis_print_is_reach_subtlv(tptr,subtlv_type,subtlv_len,ident_buffer))
1389 return(0);
1390 tptr+=subtlv_len;
1391 subtlv_sum_len-=(subtlv_len+2);
1392 proc_bytes+=(subtlv_len+2);
1393 }
1394 }
1395 return(proc_bytes);
1396 }
1397
1398 /*
1399 * this is the common Multi Topology ID decoder
1400 * it is called from various MT-TLVs (222,229,235,237)
1401 */
1402
1403 static int
1404 isis_print_mtid (const u_int8_t *tptr,const char *ident) {
1405
1406 if (!TTEST2(*tptr, 2))
1407 return(0);
1408
1409 printf("%s%s",
1410 ident,
1411 tok2str(isis_mt_values,
1412 "Reserved for IETF Consensus",
1413 ISIS_MASK_MTID(EXTRACT_16BITS(tptr))));
1414
1415 printf(" Topology (0x%03x), Flags: [%s]",
1416 ISIS_MASK_MTID(EXTRACT_16BITS(tptr)),
1417 bittok2str(isis_mt_flag_values, "none",ISIS_MASK_MTFLAGS(EXTRACT_16BITS(tptr))));
1418
1419 return(2);
1420 }
1421
1422 /*
1423 * this is the common extended IP reach decoder
1424 * it is called from TLVs (135,235,236,237)
1425 * we process the TLV and optional subTLVs and return
1426 * the amount of processed bytes
1427 */
1428
1429 static int
1430 isis_print_extd_ip_reach (const u_int8_t *tptr, const char *ident, u_int16_t afi) {
1431
1432 char ident_buffer[20];
1433 u_int8_t prefix[16]; /* shared copy buffer for IPv4 and IPv6 prefixes */
1434 u_int metric, status_byte, bit_length, byte_length, sublen, processed, subtlvtype, subtlvlen;
1435
1436 if (!TTEST2(*tptr, 4))
1437 return (0);
1438 metric = EXTRACT_32BITS(tptr);
1439 processed=4;
1440 tptr+=4;
1441
1442 if (afi == IPV4) {
1443 if (!TTEST2(*tptr, 1)) /* fetch status byte */
1444 return (0);
1445 status_byte=*(tptr++);
1446 bit_length = status_byte&0x3f;
1447 processed++;
1448 #ifdef INET6
1449 } else if (afi == IPV6) {
1450 if (!TTEST2(*tptr, 1)) /* fetch status & prefix_len byte */
1451 return (0);
1452 status_byte=*(tptr++);
1453 bit_length=*(tptr++);
1454 processed+=2;
1455 #endif
1456 } else
1457 return (0); /* somebody is fooling us */
1458
1459 byte_length = (bit_length + 7) / 8; /* prefix has variable length encoding */
1460
1461 if (!TTEST2(*tptr, byte_length))
1462 return (0);
1463 memset(prefix, 0, 16); /* clear the copy buffer */
1464 memcpy(prefix,tptr,byte_length); /* copy as much as is stored in the TLV */
1465 tptr+=byte_length;
1466 processed+=byte_length;
1467
1468 if (afi == IPV4)
1469 printf("%sIPv4 prefix: %15s/%u",
1470 ident,
1471 ipaddr_string(prefix),
1472 bit_length);
1473 #ifdef INET6
1474 if (afi == IPV6)
1475 printf("%sIPv6 prefix: %s/%u",
1476 ident,
1477 ip6addr_string(prefix),
1478 bit_length);
1479 #endif
1480
1481 printf(", Distribution: %s, Metric: %u",
1482 ISIS_MASK_TLV_EXTD_IP_UPDOWN(status_byte) ? "down" : "up",
1483 metric);
1484
1485 if (afi == IPV4 && ISIS_MASK_TLV_EXTD_IP_SUBTLV(status_byte))
1486 printf(", sub-TLVs present");
1487 #ifdef INET6
1488 if (afi == IPV6)
1489 printf(", %s%s",
1490 ISIS_MASK_TLV_EXTD_IP6_IE(status_byte) ? "External" : "Internal",
1491 ISIS_MASK_TLV_EXTD_IP6_SUBTLV(status_byte) ? ", sub-TLVs present" : "");
1492 #endif
1493
1494 if ((ISIS_MASK_TLV_EXTD_IP_SUBTLV(status_byte) && afi == IPV4) ||
1495 (ISIS_MASK_TLV_EXTD_IP6_SUBTLV(status_byte) && afi == IPV6)) {
1496 /* assume that one prefix can hold more
1497 than one subTLV - therefore the first byte must reflect
1498 the aggregate bytecount of the subTLVs for this prefix
1499 */
1500 if (!TTEST2(*tptr, 1))
1501 return (0);
1502 sublen=*(tptr++);
1503 processed+=sublen+1;
1504 printf(" (%u)",sublen); /* print out subTLV length */
1505
1506 while (sublen>0) {
1507 if (!TTEST2(*tptr,2))
1508 return (0);
1509 subtlvtype=*(tptr++);
1510 subtlvlen=*(tptr++);
1511 /* prepend the ident string */
1512 snprintf(ident_buffer, sizeof(ident_buffer), "%s ",ident);
1513 if(!isis_print_ip_reach_subtlv(tptr,subtlvtype,subtlvlen,ident_buffer))
1514 return(0);
1515 tptr+=subtlvlen;
1516 sublen-=(subtlvlen+2);
1517 }
1518 }
1519 return (processed);
1520 }
1521
1522 /*
1523 * isis_print
1524 * Decode IS-IS packets. Return 0 on error.
1525 */
1526
1527 static int isis_print (const u_int8_t *p, u_int length)
1528 {
1529 const struct isis_common_header *isis_header;
1530
1531 const struct isis_iih_lan_header *header_iih_lan;
1532 const struct isis_iih_ptp_header *header_iih_ptp;
1533 const struct isis_lsp_header *header_lsp;
1534 const struct isis_csnp_header *header_csnp;
1535 const struct isis_psnp_header *header_psnp;
1536
1537 const struct isis_tlv_lsp *tlv_lsp;
1538 const struct isis_tlv_ptp_adj *tlv_ptp_adj;
1539 const struct isis_tlv_is_reach *tlv_is_reach;
1540 const struct isis_tlv_es_reach *tlv_es_reach;
1541
1542 u_int8_t pdu_type, max_area, id_length, tlv_type, tlv_len, tmp, alen, lan_alen, prefix_len;
1543 u_int8_t ext_is_len, ext_ip_len, mt_len;
1544 const u_int8_t *optr, *pptr, *tptr;
1545 u_short packet_len,pdu_len;
1546 u_int i,vendor_id;
1547
1548 packet_len=length;
1549 optr = p; /* initialize the _o_riginal pointer to the packet start -
1550 need it for parsing the checksum TLV */
1551 isis_header = (const struct isis_common_header *)p;
1552 TCHECK(*isis_header);
1553 pptr = p+(ISIS_COMMON_HEADER_SIZE);
1554 header_iih_lan = (const struct isis_iih_lan_header *)pptr;
1555 header_iih_ptp = (const struct isis_iih_ptp_header *)pptr;
1556 header_lsp = (const struct isis_lsp_header *)pptr;
1557 header_csnp = (const struct isis_csnp_header *)pptr;
1558 header_psnp = (const struct isis_psnp_header *)pptr;
1559
1560 if (!eflag)
1561 printf("IS-IS");
1562
1563 /*
1564 * Sanity checking of the header.
1565 */
1566
1567 if (isis_header->version != ISIS_VERSION) {
1568 printf("version %d packet not supported", isis_header->version);
1569 return (0);
1570 }
1571
1572 if ((isis_header->id_length != SYSTEM_ID_LEN) && (isis_header->id_length != 0)) {
1573 printf("system ID length of %d is not supported",
1574 isis_header->id_length);
1575 return (0);
1576 }
1577
1578 if (isis_header->pdu_version != ISIS_VERSION) {
1579 printf("version %d packet not supported", isis_header->pdu_version);
1580 return (0);
1581 }
1582
1583 max_area = isis_header->max_area;
1584 switch(max_area) {
1585 case 0:
1586 max_area = 3; /* silly shit */
1587 break;
1588 case 255:
1589 printf("bad packet -- 255 areas");
1590 return (0);
1591 default:
1592 break;
1593 }
1594
1595 id_length = isis_header->id_length;
1596 switch(id_length) {
1597 case 0:
1598 id_length = 6; /* silly shit again */
1599 break;
1600 case 1: /* 1-8 are valid sys-ID lenghts */
1601 case 2:
1602 case 3:
1603 case 4:
1604 case 5:
1605 case 6:
1606 case 7:
1607 case 8:
1608 break;
1609 case 255:
1610 id_length = 0; /* entirely useless */
1611 break;
1612 default:
1613 break;
1614 }
1615
1616 /* toss any non 6-byte sys-ID len PDUs */
1617 if (id_length != 6 ) {
1618 printf("bad packet -- illegal sys-ID length (%u)", id_length);
1619 return (0);
1620 }
1621
1622 pdu_type=isis_header->pdu_type;
1623
1624 /* in non-verbose mode print the basic PDU Type plus PDU specific brief information*/
1625 if (vflag < 1) {
1626 printf("%s%s",
1627 eflag ? "" : ", ",
1628 tok2str(isis_pdu_values,"unknown PDU-Type %u",pdu_type));
1629
1630 switch (pdu_type) {
1631
1632 case ISIS_PDU_L1_LAN_IIH:
1633 case ISIS_PDU_L2_LAN_IIH:
1634 printf(", src-id %s",
1635 isis_print_id(header_iih_lan->source_id,SYSTEM_ID_LEN));
1636 printf(", lan-id %s, prio %u",
1637 isis_print_id(header_iih_lan->lan_id,NODE_ID_LEN),
1638 header_iih_lan->priority);
1639 break;
1640 case ISIS_PDU_PTP_IIH:
1641 printf(", src-id %s", isis_print_id(header_iih_ptp->source_id,SYSTEM_ID_LEN));
1642 break;
1643 case ISIS_PDU_L1_LSP:
1644 case ISIS_PDU_L2_LSP:
1645 printf(", lsp-id %s, seq 0x%08x, lifetime %5us",
1646 isis_print_id(header_lsp->lsp_id, LSP_ID_LEN),
1647 EXTRACT_32BITS(header_lsp->sequence_number),
1648 EXTRACT_16BITS(header_lsp->remaining_lifetime));
1649 break;
1650 case ISIS_PDU_L1_CSNP:
1651 case ISIS_PDU_L2_CSNP:
1652 printf(", src-id %s", isis_print_id(header_csnp->source_id,NODE_ID_LEN));
1653 break;
1654 case ISIS_PDU_L1_PSNP:
1655 case ISIS_PDU_L2_PSNP:
1656 printf(", src-id %s", isis_print_id(header_psnp->source_id,NODE_ID_LEN));
1657 break;
1658
1659 }
1660 printf(", length %u", length);
1661
1662 return(1);
1663 }
1664
1665 /* ok they seem to want to know everything - lets fully decode it */
1666 printf("%slength %u", eflag ? "" : ", ",length);
1667
1668 printf("\n\t%s, hlen: %u, v: %u, pdu-v: %u, sys-id-len: %u (%u), max-area: %u (%u)",
1669 tok2str(isis_pdu_values,
1670 "unknown, type %u",
1671 pdu_type),
1672 isis_header->fixed_len,
1673 isis_header->version,
1674 isis_header->pdu_version,
1675 id_length,
1676 isis_header->id_length,
1677 max_area,
1678 isis_header->max_area);
1679
1680 if (vflag > 1) {
1681 if(!print_unknown_data(optr,"\n\t",8)) /* provide the _o_riginal pointer */
1682 return(0); /* for optionally debugging the common header */
1683 }
1684
1685 switch (pdu_type) {
1686
1687 case ISIS_PDU_L1_LAN_IIH:
1688 case ISIS_PDU_L2_LAN_IIH:
1689 if (isis_header->fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_LAN_HEADER_SIZE)) {
1690 printf(", bogus fixed header length %u should be %lu",
1691 isis_header->fixed_len, (unsigned long)ISIS_IIH_LAN_HEADER_SIZE);
1692 return (0);
1693 }
1694
1695 pdu_len=EXTRACT_16BITS(header_iih_lan->pdu_len);
1696 if (packet_len>pdu_len) {
1697 packet_len=pdu_len; /* do TLV decoding as long as it makes sense */
1698 length=pdu_len;
1699 }
1700
1701 TCHECK(*header_iih_lan);
1702 printf("\n\t source-id: %s, holding time: %us, Flags: [%s]",
1703 isis_print_id(header_iih_lan->source_id,SYSTEM_ID_LEN),
1704 EXTRACT_16BITS(header_iih_lan->holding_time),
1705 tok2str(isis_iih_circuit_type_values,
1706 "unknown circuit type 0x%02x",
1707 header_iih_lan->circuit_type));
1708
1709 printf("\n\t lan-id: %s, Priority: %u, PDU length: %u",
1710 isis_print_id(header_iih_lan->lan_id, NODE_ID_LEN),
1711 (header_iih_lan->priority) & ISIS_LAN_PRIORITY_MASK,
1712 pdu_len);
1713
1714 if (vflag > 1) {
1715 if(!print_unknown_data(pptr,"\n\t ",ISIS_IIH_LAN_HEADER_SIZE))
1716 return(0);
1717 }
1718
1719 packet_len -= (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_LAN_HEADER_SIZE);
1720 pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_LAN_HEADER_SIZE);
1721 break;
1722
1723 case ISIS_PDU_PTP_IIH:
1724 if (isis_header->fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_PTP_HEADER_SIZE)) {
1725 printf(", bogus fixed header length %u should be %lu",
1726 isis_header->fixed_len, (unsigned long)ISIS_IIH_PTP_HEADER_SIZE);
1727 return (0);
1728 }
1729
1730 pdu_len=EXTRACT_16BITS(header_iih_ptp->pdu_len);
1731 if (packet_len>pdu_len) {
1732 packet_len=pdu_len; /* do TLV decoding as long as it makes sense */
1733 length=pdu_len;
1734 }
1735
1736 TCHECK(*header_iih_ptp);
1737 printf("\n\t source-id: %s, holding time: %us, Flags: [%s]",
1738 isis_print_id(header_iih_ptp->source_id,SYSTEM_ID_LEN),
1739 EXTRACT_16BITS(header_iih_ptp->holding_time),
1740 tok2str(isis_iih_circuit_type_values,
1741 "unknown circuit type 0x%02x",
1742 header_iih_ptp->circuit_type));
1743
1744 printf("\n\t circuit-id: 0x%02x, PDU length: %u",
1745 header_iih_ptp->circuit_id,
1746 pdu_len);
1747
1748 if (vflag > 1) {
1749 if(!print_unknown_data(pptr,"\n\t ",ISIS_IIH_PTP_HEADER_SIZE))
1750 return(0);
1751 }
1752
1753 packet_len -= (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_PTP_HEADER_SIZE);
1754 pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_PTP_HEADER_SIZE);
1755 break;
1756
1757 case ISIS_PDU_L1_LSP:
1758 case ISIS_PDU_L2_LSP:
1759 if (isis_header->fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_LSP_HEADER_SIZE)) {
1760 printf(", bogus fixed header length %u should be %lu",
1761 isis_header->fixed_len, (unsigned long)ISIS_LSP_HEADER_SIZE);
1762 return (0);
1763 }
1764
1765 pdu_len=EXTRACT_16BITS(header_lsp->pdu_len);
1766 if (packet_len>pdu_len) {
1767 packet_len=pdu_len; /* do TLV decoding as long as it makes sense */
1768 length=pdu_len;
1769 }
1770
1771 TCHECK(*header_lsp);
1772 printf("\n\t lsp-id: %s, seq: 0x%08x, lifetime: %5us\n\t chksum: 0x%04x",
1773 isis_print_id(header_lsp->lsp_id, LSP_ID_LEN),
1774 EXTRACT_32BITS(header_lsp->sequence_number),
1775 EXTRACT_16BITS(header_lsp->remaining_lifetime),
1776 EXTRACT_16BITS(header_lsp->checksum));
1777
1778 /* if this is a purge do not attempt to verify the checksum */
1779 if ( EXTRACT_16BITS(header_lsp->remaining_lifetime) == 0 &&
1780 EXTRACT_16BITS(header_lsp->checksum) == 0)
1781 printf(" (purged)");
1782 else
1783 /* verify the checksum -
1784 * checking starts at the lsp-id field at byte position [12]
1785 * hence the length needs to be reduced by 12 bytes */
1786 printf(" (%s)", (osi_cksum((u_int8_t *)header_lsp->lsp_id, length-12)) ? "incorrect" : "correct");
1787
1788 printf(", PDU length: %u, Flags: [ %s",
1789 pdu_len,
1790 ISIS_MASK_LSP_OL_BIT(header_lsp->typeblock) ? "Overload bit set, " : "");
1791
1792 if (ISIS_MASK_LSP_ATT_BITS(header_lsp->typeblock)) {
1793 printf("%s", ISIS_MASK_LSP_ATT_DEFAULT_BIT(header_lsp->typeblock) ? "default " : "");
1794 printf("%s", ISIS_MASK_LSP_ATT_DELAY_BIT(header_lsp->typeblock) ? "delay " : "");
1795 printf("%s", ISIS_MASK_LSP_ATT_EXPENSE_BIT(header_lsp->typeblock) ? "expense " : "");
1796 printf("%s", ISIS_MASK_LSP_ATT_ERROR_BIT(header_lsp->typeblock) ? "error " : "");
1797 printf("ATT bit set, ");
1798 }
1799 printf("%s", ISIS_MASK_LSP_PARTITION_BIT(header_lsp->typeblock) ? "P bit set, " : "");
1800 printf("%s ]", tok2str(isis_lsp_istype_values,"Unknown(0x%x)",ISIS_MASK_LSP_ISTYPE_BITS(header_lsp->typeblock)));
1801
1802 if (vflag > 1) {
1803 if(!print_unknown_data(pptr,"\n\t ",ISIS_LSP_HEADER_SIZE))
1804 return(0);
1805 }
1806
1807 packet_len -= (ISIS_COMMON_HEADER_SIZE+ISIS_LSP_HEADER_SIZE);
1808 pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_LSP_HEADER_SIZE);
1809 break;
1810
1811 case ISIS_PDU_L1_CSNP:
1812 case ISIS_PDU_L2_CSNP:
1813 if (isis_header->fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_CSNP_HEADER_SIZE)) {
1814 printf(", bogus fixed header length %u should be %lu",
1815 isis_header->fixed_len, (unsigned long)ISIS_CSNP_HEADER_SIZE);
1816 return (0);
1817 }
1818
1819 pdu_len=EXTRACT_16BITS(header_csnp->pdu_len);
1820 if (packet_len>pdu_len) {
1821 packet_len=pdu_len; /* do TLV decoding as long as it makes sense */
1822 length=pdu_len;
1823 }
1824
1825 TCHECK(*header_csnp);
1826 printf("\n\t source-id: %s, PDU length: %u",
1827 isis_print_id(header_csnp->source_id, NODE_ID_LEN),
1828 pdu_len);
1829 printf("\n\t start lsp-id: %s",
1830 isis_print_id(header_csnp->start_lsp_id, LSP_ID_LEN));
1831 printf("\n\t end lsp-id: %s",
1832 isis_print_id(header_csnp->end_lsp_id, LSP_ID_LEN));
1833
1834 if (vflag > 1) {
1835 if(!print_unknown_data(pptr,"\n\t ",ISIS_CSNP_HEADER_SIZE))
1836 return(0);
1837 }
1838
1839 packet_len -= (ISIS_COMMON_HEADER_SIZE+ISIS_CSNP_HEADER_SIZE);
1840 pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_CSNP_HEADER_SIZE);
1841 break;
1842
1843 case ISIS_PDU_L1_PSNP:
1844 case ISIS_PDU_L2_PSNP:
1845 if (isis_header->fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_PSNP_HEADER_SIZE)) {
1846 printf("- bogus fixed header length %u should be %lu",
1847 isis_header->fixed_len, (unsigned long)ISIS_PSNP_HEADER_SIZE);
1848 return (0);
1849 }
1850
1851 pdu_len=EXTRACT_16BITS(header_psnp->pdu_len);
1852 if (packet_len>pdu_len) {
1853 packet_len=pdu_len; /* do TLV decoding as long as it makes sense */
1854 length=pdu_len;
1855 }
1856
1857 TCHECK(*header_psnp);
1858 printf("\n\t source-id: %s, PDU length: %u",
1859 isis_print_id(header_psnp->source_id, NODE_ID_LEN),
1860 pdu_len);
1861
1862 if (vflag > 1) {
1863 if(!print_unknown_data(pptr,"\n\t ",ISIS_PSNP_HEADER_SIZE))
1864 return(0);
1865 }
1866
1867 packet_len -= (ISIS_COMMON_HEADER_SIZE+ISIS_PSNP_HEADER_SIZE);
1868 pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_PSNP_HEADER_SIZE);
1869 break;
1870
1871 default:
1872 if(!print_unknown_data(pptr,"\n\t ",length))
1873 return(0);
1874 return (0);
1875 }
1876
1877 /*
1878 * Now print the TLV's.
1879 */
1880
1881 while (packet_len >= 2) {
1882 if (pptr == snapend) {
1883 return (1);
1884 }
1885
1886 if (!TTEST2(*pptr, 2)) {
1887 printf("\n\t\t packet exceeded snapshot (%ld) bytes",
1888 (long)(pptr-snapend));
1889 return (1);
1890 }
1891 tlv_type = *pptr++;
1892 tlv_len = *pptr++;
1893 tmp =tlv_len; /* copy temporary len & pointer to packet data */
1894 tptr = pptr;
1895 packet_len -= 2;
1896 if (tlv_len > packet_len) {
1897 break;
1898 }
1899
1900 /* first lets see if we know the TLVs name*/
1901 printf("\n\t %s TLV #%u, length: %u",
1902 tok2str(isis_tlv_values,
1903 "unknown",
1904 tlv_type),
1905 tlv_type,
1906 tlv_len);
1907
1908 if (tlv_len == 0) /* something is malformed */
1909 break;
1910
1911 /* now check if we have a decoder otherwise do a hexdump at the end*/
1912 switch (tlv_type) {
1913 case ISIS_TLV_AREA_ADDR:
1914 if (!TTEST2(*tptr, 1))
1915 goto trunctlv;
1916 alen = *tptr++;
1917 while (tmp && alen < tmp) {
1918 printf("\n\t Area address (length: %u): %s",
1919 alen,
1920 isonsap_string(tptr,alen));
1921 tptr += alen;
1922 tmp -= alen + 1;
1923 if (tmp==0) /* if this is the last area address do not attemt a boundary check */
1924 break;
1925 if (!TTEST2(*tptr, 1))
1926 goto trunctlv;
1927 alen = *tptr++;
1928 }
1929 break;
1930 case ISIS_TLV_ISNEIGH:
1931 while (tmp >= ETHER_ADDR_LEN) {
1932 if (!TTEST2(*tptr, ETHER_ADDR_LEN))
1933 goto trunctlv;
1934 printf("\n\t SNPA: %s",isis_print_id(tptr,ETHER_ADDR_LEN));
1935 tmp -= ETHER_ADDR_LEN;
1936 tptr += ETHER_ADDR_LEN;
1937 }
1938 break;
1939
1940 case ISIS_TLV_ISNEIGH_VARLEN:
1941 if (!TTEST2(*tptr, 1) || tmp < 3) /* min. TLV length */
1942 goto trunctlv;
1943 lan_alen = *tptr++; /* LAN address length */
1944 if (lan_alen == 0) {
1945 printf("\n\t LAN address length 0 bytes (invalid)");
1946 break;
1947 }
1948 tmp --;
1949 printf("\n\t LAN address length %u bytes ",lan_alen);
1950 while (tmp >= lan_alen) {
1951 if (!TTEST2(*tptr, lan_alen))
1952 goto trunctlv;
1953 printf("\n\t\tIS Neighbor: %s",isis_print_id(tptr,lan_alen));
1954 tmp -= lan_alen;
1955 tptr +=lan_alen;
1956 }
1957 break;
1958
1959 case ISIS_TLV_PADDING:
1960 break;
1961
1962 case ISIS_TLV_MT_IS_REACH:
1963 while (tmp >= 2+NODE_ID_LEN+3+1) {
1964 mt_len = isis_print_mtid(tptr, "\n\t ");
1965 if (mt_len == 0) /* did something go wrong ? */
1966 goto trunctlv;
1967 tptr+=mt_len;
1968 tmp-=mt_len;
1969
1970 ext_is_len = isis_print_ext_is_reach(tptr,"\n\t ",tlv_type);
1971 if (ext_is_len == 0) /* did something go wrong ? */
1972 goto trunctlv;
1973
1974 tmp-=ext_is_len;
1975 tptr+=ext_is_len;
1976 }
1977 break;
1978
1979 case ISIS_TLV_IS_ALIAS_ID:
1980 while (tmp >= NODE_ID_LEN+1) { /* is it worth attempting a decode ? */
1981 ext_is_len = isis_print_ext_is_reach(tptr,"\n\t ",tlv_type);
1982 if (ext_is_len == 0) /* did something go wrong ? */
1983 goto trunctlv;
1984 tmp-=ext_is_len;
1985 tptr+=ext_is_len;
1986 }
1987 break;
1988
1989 case ISIS_TLV_EXT_IS_REACH:
1990 while (tmp >= NODE_ID_LEN+3+1) { /* is it worth attempting a decode ? */
1991 ext_is_len = isis_print_ext_is_reach(tptr,"\n\t ",tlv_type);
1992 if (ext_is_len == 0) /* did something go wrong ? */
1993 goto trunctlv;
1994 tmp-=ext_is_len;
1995 tptr+=ext_is_len;
1996 }
1997 break;
1998 case ISIS_TLV_IS_REACH:
1999 if (!TTEST2(*tptr,1)) /* check if there is one byte left to read out the virtual flag */
2000 goto trunctlv;
2001 printf("\n\t %s",
2002 tok2str(isis_is_reach_virtual_values,
2003 "bogus virtual flag 0x%02x",
2004 *tptr++));
2005 tlv_is_reach = (const struct isis_tlv_is_reach *)tptr;
2006 while (tmp >= sizeof(struct isis_tlv_is_reach)) {
2007 if (!TTEST(*tlv_is_reach))
2008 goto trunctlv;
2009 printf("\n\t IS Neighbor: %s",
2010 isis_print_id(tlv_is_reach->neighbor_nodeid, NODE_ID_LEN));
2011 isis_print_metric_block(&tlv_is_reach->isis_metric_block);
2012 tmp -= sizeof(struct isis_tlv_is_reach);
2013 tlv_is_reach++;
2014 }
2015 break;
2016
2017 case ISIS_TLV_ESNEIGH:
2018 tlv_es_reach = (const struct isis_tlv_es_reach *)tptr;
2019 while (tmp >= sizeof(struct isis_tlv_es_reach)) {
2020 if (!TTEST(*tlv_es_reach))
2021 goto trunctlv;
2022 printf("\n\t ES Neighbor: %s",
2023 isis_print_id(tlv_es_reach->neighbor_sysid,SYSTEM_ID_LEN));
2024 isis_print_metric_block(&tlv_es_reach->isis_metric_block);
2025 tmp -= sizeof(struct isis_tlv_es_reach);
2026 tlv_es_reach++;
2027 }
2028 break;
2029
2030 /* those two TLVs share the same format */
2031 case ISIS_TLV_INT_IP_REACH:
2032 case ISIS_TLV_EXT_IP_REACH:
2033 if (!isis_print_tlv_ip_reach(pptr, "\n\t ", tlv_len))
2034 return (1);
2035 break;
2036
2037 case ISIS_TLV_EXTD_IP_REACH:
2038 while (tmp>0) {
2039 ext_ip_len = isis_print_extd_ip_reach(tptr, "\n\t ", IPV4);
2040 if (ext_ip_len == 0) /* did something go wrong ? */
2041 goto trunctlv;
2042 tptr+=ext_ip_len;
2043 tmp-=ext_ip_len;
2044 }
2045 break;
2046
2047 case ISIS_TLV_MT_IP_REACH:
2048 while (tmp>0) {
2049 mt_len = isis_print_mtid(tptr, "\n\t ");
2050 if (mt_len == 0) /* did something go wrong ? */
2051 goto trunctlv;
2052 tptr+=mt_len;
2053 tmp-=mt_len;
2054
2055 ext_ip_len = isis_print_extd_ip_reach(tptr, "\n\t ", IPV4);
2056 if (ext_ip_len == 0) /* did something go wrong ? */
2057 goto trunctlv;
2058 tptr+=ext_ip_len;
2059 tmp-=ext_ip_len;
2060 }
2061 break;
2062
2063 #ifdef INET6
2064 case ISIS_TLV_IP6_REACH:
2065 while (tmp>0) {
2066 ext_ip_len = isis_print_extd_ip_reach(tptr, "\n\t ", IPV6);
2067 if (ext_ip_len == 0) /* did something go wrong ? */
2068 goto trunctlv;
2069 tptr+=ext_ip_len;
2070 tmp-=ext_ip_len;
2071 }
2072 break;
2073
2074 case ISIS_TLV_MT_IP6_REACH:
2075 while (tmp>0) {
2076 mt_len = isis_print_mtid(tptr, "\n\t ");
2077 if (mt_len == 0) /* did something go wrong ? */
2078 goto trunctlv;
2079 tptr+=mt_len;
2080 tmp-=mt_len;
2081
2082 ext_ip_len = isis_print_extd_ip_reach(tptr, "\n\t ", IPV6);
2083 if (ext_ip_len == 0) /* did something go wrong ? */
2084 goto trunctlv;
2085 tptr+=ext_ip_len;
2086 tmp-=ext_ip_len;
2087 }
2088 break;
2089
2090 case ISIS_TLV_IP6ADDR:
2091 while (tmp>0) {
2092 if (!TTEST2(*tptr, 16))
2093 goto trunctlv;
2094
2095 printf("\n\t IPv6 interface address: %s",
2096 ip6addr_string(tptr));
2097
2098 tptr += 16;
2099 tmp -= 16;
2100 }
2101 break;
2102 #endif
2103 case ISIS_TLV_AUTH:
2104 if (!TTEST2(*tptr, 1))
2105 goto trunctlv;
2106
2107 printf("\n\t %s: ",
2108 tok2str(isis_subtlv_auth_values,
2109 "unknown Authentication type 0x%02x",
2110 *tptr));
2111
2112 switch (*tptr) {
2113 case ISIS_SUBTLV_AUTH_SIMPLE:
2114 for(i=1;i<tlv_len;i++) {
2115 if (!TTEST2(*(tptr+i), 1))
2116 goto trunctlv;
2117 printf("%c",*(tptr+i));
2118 }
2119 break;
2120 case ISIS_SUBTLV_AUTH_MD5:
2121 for(i=1;i<tlv_len;i++) {
2122 if (!TTEST2(*(tptr+i), 1))
2123 goto trunctlv;
2124 printf("%02x",*(tptr+i));
2125 }
2126 if (tlv_len != ISIS_SUBTLV_AUTH_MD5_LEN+1)
2127 printf(", (malformed subTLV) ");
2128 break;
2129 case ISIS_SUBTLV_AUTH_PRIVATE:
2130 default:
2131 if(!print_unknown_data(tptr+1,"\n\t\t ",tlv_len-1))
2132 return(0);
2133 break;
2134 }
2135 break;
2136
2137 case ISIS_TLV_PTP_ADJ:
2138 tlv_ptp_adj = (const struct isis_tlv_ptp_adj *)tptr;
2139 if(tmp>=1) {
2140 if (!TTEST2(*tptr, 1))
2141 goto trunctlv;
2142 printf("\n\t Adjacency State: %s (%u)",
2143 tok2str(isis_ptp_adjancey_values, "unknown", *tptr),
2144 *tptr);
2145 tmp--;
2146 }
2147 if(tmp>sizeof(tlv_ptp_adj->extd_local_circuit_id)) {
2148 if (!TTEST2(tlv_ptp_adj->extd_local_circuit_id,
2149 sizeof(tlv_ptp_adj->extd_local_circuit_id)))
2150 goto trunctlv;
2151 printf("\n\t Extended Local circuit-ID: 0x%08x",
2152 EXTRACT_32BITS(tlv_ptp_adj->extd_local_circuit_id));
2153 tmp-=sizeof(tlv_ptp_adj->extd_local_circuit_id);
2154 }
2155 if(tmp>=SYSTEM_ID_LEN) {
2156 if (!TTEST2(tlv_ptp_adj->neighbor_sysid, SYSTEM_ID_LEN))
2157 goto trunctlv;
2158 printf("\n\t Neighbor System-ID: %s",
2159 isis_print_id(tlv_ptp_adj->neighbor_sysid,SYSTEM_ID_LEN));
2160 tmp-=SYSTEM_ID_LEN;
2161 }
2162 if(tmp>=sizeof(tlv_ptp_adj->neighbor_extd_local_circuit_id)) {
2163 if (!TTEST2(tlv_ptp_adj->neighbor_extd_local_circuit_id,
2164 sizeof(tlv_ptp_adj->neighbor_extd_local_circuit_id)))
2165 goto trunctlv;
2166 printf("\n\t Neighbor Extended Local circuit-ID: 0x%08x",
2167 EXTRACT_32BITS(tlv_ptp_adj->neighbor_extd_local_circuit_id));
2168 }
2169 break;
2170
2171 case ISIS_TLV_PROTOCOLS:
2172 printf("\n\t NLPID(s): ");
2173 while (tmp>0) {
2174 if (!TTEST2(*(tptr), 1))
2175 goto trunctlv;
2176 printf("%s (0x%02x)",
2177 tok2str(nlpid_values,
2178 "unknown",
2179 *tptr),
2180 *tptr);
2181 if (tmp>1) /* further NPLIDs ? - put comma */
2182 printf(", ");
2183 tptr++;
2184 tmp--;
2185 }
2186 break;
2187
2188 case ISIS_TLV_TE_ROUTER_ID:
2189 if (!TTEST2(*pptr, 4))
2190 goto trunctlv;
2191 printf("\n\t Traffic Engineering Router ID: %s", ipaddr_string(pptr));
2192 break;
2193
2194 case ISIS_TLV_IPADDR:
2195 while (tmp>0) {
2196 if (!TTEST2(*tptr, 4))
2197 goto trunctlv;
2198 printf("\n\t IPv4 interface address: %s", ipaddr_string(tptr));
2199 tptr += 4;
2200 tmp -= 4;
2201 }
2202 break;
2203
2204 case ISIS_TLV_HOSTNAME:
2205 printf("\n\t Hostname: ");
2206 while (tmp>0) {
2207 if (!TTEST2(*tptr, 1))
2208 goto trunctlv;
2209 printf("%c",*tptr++);
2210 tmp--;
2211 }
2212 break;
2213
2214 case ISIS_TLV_SHARED_RISK_GROUP:
2215 if (!TTEST2(*tptr, NODE_ID_LEN))
2216 goto trunctlv;
2217 printf("\n\t IS Neighbor: %s", isis_print_id(tptr, NODE_ID_LEN));
2218 tptr+=(NODE_ID_LEN);
2219 tmp-=(NODE_ID_LEN);
2220
2221 if (!TTEST2(*tptr, 1))
2222 goto trunctlv;
2223 printf(", Flags: [%s]", ISIS_MASK_TLV_SHARED_RISK_GROUP(*tptr++) ? "numbered" : "unnumbered");
2224 tmp--;
2225
2226 if (!TTEST2(*tptr,4))
2227 goto trunctlv;
2228 printf("\n\t IPv4 interface address: %s", ipaddr_string(tptr));
2229 tptr+=4;
2230 tmp-=4;
2231
2232 if (!TTEST2(*tptr,4))
2233 goto trunctlv;
2234 printf("\n\t IPv4 neighbor address: %s", ipaddr_string(tptr));
2235 tptr+=4;
2236 tmp-=4;
2237
2238 while (tmp>0) {
2239 if (!TTEST2(*tptr, 4))
2240 goto trunctlv;
2241 printf("\n\t Link-ID: 0x%08x", EXTRACT_32BITS(tptr));
2242 tptr+=4;
2243 tmp-=4;
2244 }
2245 break;
2246
2247 case ISIS_TLV_LSP:
2248 tlv_lsp = (const struct isis_tlv_lsp *)tptr;
2249 while(tmp>0) {
2250 if (!TTEST((tlv_lsp->lsp_id)[LSP_ID_LEN-1]))
2251 goto trunctlv;
2252 printf("\n\t lsp-id: %s",
2253 isis_print_id(tlv_lsp->lsp_id, LSP_ID_LEN));
2254 if (!TTEST2(tlv_lsp->sequence_number, 4))
2255 goto trunctlv;
2256 printf(", seq: 0x%08x",EXTRACT_32BITS(tlv_lsp->sequence_number));
2257 if (!TTEST2(tlv_lsp->remaining_lifetime, 2))
2258 goto trunctlv;
2259 printf(", lifetime: %5ds",EXTRACT_16BITS(tlv_lsp->remaining_lifetime));
2260 if (!TTEST2(tlv_lsp->checksum, 2))
2261 goto trunctlv;
2262 printf(", chksum: 0x%04x",EXTRACT_16BITS(tlv_lsp->checksum));
2263 tmp-=sizeof(struct isis_tlv_lsp);
2264 tlv_lsp++;
2265 }
2266 break;
2267
2268 case ISIS_TLV_CHECKSUM:
2269 if (!TTEST2(*tptr, 2))
2270 goto trunctlv;
2271 printf("\n\t checksum: 0x%04x ", EXTRACT_16BITS(tptr));
2272 /* do not attempt to verify the checksum if it is zero
2273 * most likely a HMAC-MD5 TLV is also present and
2274 * to avoid conflicts the checksum TLV is zeroed.
2275 * see rfc3358 for details
2276 */
2277 if (EXTRACT_16BITS(tptr) == 0)
2278 printf("(unverified)");
2279 else printf("(%s)", osi_cksum(optr, length) ? "incorrect" : "correct");
2280 break;
2281
2282 case ISIS_TLV_MT_SUPPORTED:
2283 while (tmp>1) {
2284 /* length can only be a multiple of 2, otherwise there is
2285 something broken -> so decode down until length is 1 */
2286 if (tmp!=1) {
2287 mt_len = isis_print_mtid(tptr, "\n\t ");
2288 if (mt_len == 0) /* did something go wrong ? */
2289 goto trunctlv;
2290 tptr+=mt_len;
2291 tmp-=mt_len;
2292 } else {
2293 printf("\n\t malformed MT-ID");
2294 break;
2295 }
2296 }
2297 break;
2298
2299 case ISIS_TLV_RESTART_SIGNALING:
2300 if (!TTEST2(*tptr, 3))
2301 goto trunctlv;
2302 printf("\n\t Flags [%s], Remaining holding time %us",
2303 bittok2str(isis_restart_flag_values, "none", *tptr),
2304 EXTRACT_16BITS(tptr+1));
2305 tptr+=3;
2306 break;
2307
2308 case ISIS_TLV_IDRP_INFO:
2309 if (!TTEST2(*tptr, 1))
2310 goto trunctlv;
2311 printf("\n\t Inter-Domain Information Type: %s",
2312 tok2str(isis_subtlv_idrp_values,
2313 "Unknown (0x%02x)",
2314 *tptr));
2315 switch (*tptr++) {
2316 case ISIS_SUBTLV_IDRP_ASN:
2317 if (!TTEST2(*tptr, 2)) /* fetch AS number */
2318 goto trunctlv;
2319 printf("AS Number: %u",EXTRACT_16BITS(tptr));
2320 break;
2321 case ISIS_SUBTLV_IDRP_LOCAL:
2322 case ISIS_SUBTLV_IDRP_RES:
2323 default:
2324 if(!print_unknown_data(tptr,"\n\t ",tlv_len-1))
2325 return(0);
2326 break;
2327 }
2328 break;
2329
2330 case ISIS_TLV_LSP_BUFFERSIZE:
2331 if (!TTEST2(*tptr, 2))
2332 goto trunctlv;
2333 printf("\n\t LSP Buffersize: %u",EXTRACT_16BITS(tptr));
2334 break;
2335
2336 case ISIS_TLV_PART_DIS:
2337 while (tmp >= SYSTEM_ID_LEN) {
2338 if (!TTEST2(*tptr, SYSTEM_ID_LEN))
2339 goto trunctlv;
2340 printf("\n\t %s",isis_print_id(tptr,SYSTEM_ID_LEN));
2341 tptr+=SYSTEM_ID_LEN;
2342 tmp-=SYSTEM_ID_LEN;
2343 }
2344 break;
2345
2346 case ISIS_TLV_PREFIX_NEIGH:
2347 if (!TTEST2(*tptr, sizeof(struct isis_metric_block)))
2348 goto trunctlv;
2349 printf("\n\t Metric Block");
2350 isis_print_metric_block((const struct isis_metric_block *)tptr);
2351 tptr+=sizeof(struct isis_metric_block);
2352 tmp-=sizeof(struct isis_metric_block);
2353
2354 while(tmp>0) {
2355 if (!TTEST2(*tptr, 1))
2356 goto trunctlv;
2357 prefix_len=*tptr++; /* read out prefix length in semioctets*/
2358 if (prefix_len < 2) {
2359 printf("\n\t\tAddress: prefix length %u < 2", prefix_len);
2360 break;
2361 }
2362 tmp--;
2363 if (!TTEST2(*tptr, prefix_len/2))
2364 goto trunctlv;
2365 printf("\n\t\tAddress: %s/%u",
2366 isonsap_string(tptr,prefix_len/2),
2367 prefix_len*4);
2368 tptr+=prefix_len/2;
2369 tmp-=prefix_len/2;
2370 }
2371 break;
2372
2373 case ISIS_TLV_IIH_SEQNR:
2374 if (!TTEST2(*tptr, 4)) /* check if four bytes are on the wire */
2375 goto trunctlv;
2376 printf("\n\t Sequence number: %u", EXTRACT_32BITS(tptr) );
2377 break;
2378
2379 case ISIS_TLV_VENDOR_PRIVATE:
2380 if (!TTEST2(*tptr, 3)) /* check if enough byte for a full oui */
2381 goto trunctlv;
2382 vendor_id = EXTRACT_24BITS(tptr);
2383 printf("\n\t Vendor: %s (%u)",
2384 tok2str(oui_values,"Unknown",vendor_id),
2385 vendor_id);
2386 tptr+=3;
2387 tmp-=3;
2388 if (tmp > 0) /* hexdump the rest */
2389 if(!print_unknown_data(tptr,"\n\t\t",tmp))
2390 return(0);
2391 break;
2392 /*
2393 * FIXME those are the defined TLVs that lack a decoder
2394 * you are welcome to contribute code ;-)
2395 */
2396
2397 case ISIS_TLV_DECNET_PHASE4:
2398 case ISIS_TLV_LUCENT_PRIVATE:
2399 case ISIS_TLV_IPAUTH:
2400 case ISIS_TLV_NORTEL_PRIVATE1:
2401 case ISIS_TLV_NORTEL_PRIVATE2:
2402
2403 default:
2404 if (vflag <= 1) {
2405 if(!print_unknown_data(pptr,"\n\t\t",tlv_len))
2406 return(0);
2407 }
2408 break;
2409 }
2410 /* do we want to see an additionally hexdump ? */
2411 if (vflag> 1) {
2412 if(!print_unknown_data(pptr,"\n\t ",tlv_len))
2413 return(0);
2414 }
2415
2416 pptr += tlv_len;
2417 packet_len -= tlv_len;
2418 }
2419
2420 if (packet_len != 0) {
2421 printf("\n\t %u straggler bytes", packet_len);
2422 }
2423 return (1);
2424
2425 trunc:
2426 fputs("[|isis]", stdout);
2427 return (1);
2428
2429 trunctlv:
2430 printf("\n\t\t packet exceeded snapshot");
2431 return(1);
2432 }
2433
2434 /*
2435 * Verify the checksum. See 8473-1, Appendix C, section C.4.
2436 */
2437
2438 static int
2439 osi_cksum(const u_int8_t *tptr, u_int len)
2440 {
2441 int32_t c0 = 0, c1 = 0;
2442
2443 while ((int)--len >= 0) {
2444 c0 += *tptr++;
2445 c0 %= 255;
2446 c1 += c0;
2447 c1 %= 255;
2448 }
2449 return (c0 | c1);
2450 }
2451
2452
2453 /*
2454 * Local Variables:
2455 * c-style: whitesmith
2456 * c-basic-offset: 8
2457 * End:
2458 */