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