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