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