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