]> The Tcpdump Group git mirrors - tcpdump/blob - print-isoclns.c
Make the "dlci" variable a u_int, as all the code that refers to it
[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 support.
25 */
26
27 #ifndef lint
28 static const char rcsid[] _U_ =
29 "@(#) $Header: /tcpdump/master/tcpdump/print-isoclns.c,v 1.106.2.2 2003-11-16 08:51:29 guy Exp $ (LBL)";
30 #endif
31
32 #ifdef HAVE_CONFIG_H
33 #include "config.h"
34 #endif
35
36 #include <tcpdump-stdinc.h>
37
38 #include <stdio.h>
39 #include <string.h>
40
41 #include "interface.h"
42 #include "addrtoname.h"
43 #include "ethertype.h"
44 #include "ether.h"
45 #include "extract.h"
46 #include "gmpls.h"
47
48 #define NLPID_CLNS 129 /* 0x81 */
49 #define NLPID_ESIS 130 /* 0x82 */
50 #define NLPID_ISIS 131 /* 0x83 */
51 #define NLPID_IP6 0x8e
52 #define NLPID_IP 0xcc
53 #define NLPID_NULLNS 0
54
55 #define IPV4 1 /* AFI value */
56 #define IPV6 2 /* AFI value */
57
58 /*
59 * IS-IS is defined in ISO 10589. Look there for protocol definitions.
60 */
61
62 #define SYSTEM_ID_LEN ETHER_ADDR_LEN
63 #define NODE_ID_LEN SYSTEM_ID_LEN+1
64 #define LSP_ID_LEN SYSTEM_ID_LEN+2
65
66 #define ISIS_VERSION 1
67 #define PDU_TYPE_MASK 0x1F
68 #define PRIORITY_MASK 0x7F
69
70 #define L1_LAN_IIH 15
71 #define L2_LAN_IIH 16
72 #define PTP_IIH 17
73 #define L1_LSP 18
74 #define L2_LSP 20
75 #define L1_CSNP 24
76 #define L2_CSNP 25
77 #define L1_PSNP 26
78 #define L2_PSNP 27
79
80 static struct tok isis_pdu_values[] = {
81 { L1_LAN_IIH, "L1 Lan IIH"},
82 { L2_LAN_IIH, "L2 Lan IIH"},
83 { PTP_IIH, "p2p IIH"},
84 { L1_LSP, "L1 LSP"},
85 { L2_LSP, "L2 LSP"},
86 { L1_CSNP, "L1 CSNP"},
87 { L2_CSNP, "L2 CSNP"},
88 { L1_PSNP, "L1 PSNP"},
89 { L2_PSNP, "L2 PSNP"},
90 { 0, NULL}
91 };
92
93 /*
94 * A TLV is a tuple of a type, length and a value and is normally used for
95 * encoding information in all sorts of places. This is an enumeration of
96 * the well known types.
97 *
98 * list taken from rfc3359 plus some memory from veterans ;-)
99 */
100
101 #define TLV_AREA_ADDR 1 /* iso10589 */
102 #define TLV_IS_REACH 2 /* iso10589 */
103 #define TLV_ESNEIGH 3 /* iso10589 */
104 #define TLV_PART_DIS 4 /* iso10589 */
105 #define TLV_PREFIX_NEIGH 5 /* iso10589 */
106 #define TLV_ISNEIGH 6 /* iso10589 */
107 #define TLV_ISNEIGH_VARLEN 7 /* iso10589 */
108 #define TLV_PADDING 8 /* iso10589 */
109 #define TLV_LSP 9 /* iso10589 */
110 #define TLV_AUTH 10 /* iso10589, rfc3567 */
111 #define TLV_CHECKSUM 12 /* rfc3358 */
112 #define TLV_LSP_BUFFERSIZE 14 /* iso10589 rev2 */
113 #define TLV_EXT_IS_REACH 22 /* draft-ietf-isis-traffic-05 */
114 #define TLV_IS_ALIAS_ID 24 /* draft-ietf-isis-ext-lsp-frags-02 */
115 #define TLV_DECNET_PHASE4 42
116 #define TLV_LUCENT_PRIVATE 66
117 #define TLV_INT_IP_REACH 128 /* rfc1195, rfc2966 */
118 #define TLV_PROTOCOLS 129 /* rfc1195 */
119 #define TLV_EXT_IP_REACH 130 /* rfc1195, rfc2966 */
120 #define TLV_IDRP_INFO 131 /* rfc1195 */
121 #define TLV_IPADDR 132 /* rfc1195 */
122 #define TLV_IPAUTH 133 /* rfc1195 */
123 #define TLV_TE_ROUTER_ID 134 /* draft-ietf-isis-traffic-05 */
124 #define TLV_EXTD_IP_REACH 135 /* draft-ietf-isis-traffic-05 */
125 #define TLV_HOSTNAME 137 /* rfc2763 */
126 #define TLV_SHARED_RISK_GROUP 138 /* draft-ietf-isis-gmpls-extensions */
127 #define TLV_NORTEL_PRIVATE1 176
128 #define TLV_NORTEL_PRIVATE2 177
129 #define TLV_HOLDTIME 198 /* ES-IS */
130 #define TLV_RESTART_SIGNALING 211 /* draft-ietf-isis-restart-01 */
131 #define TLV_MT_IS_REACH 222 /* draft-ietf-isis-wg-multi-topology-05 */
132 #define TLV_MT_SUPPORTED 229 /* draft-ietf-isis-wg-multi-topology-05 */
133 #define TLV_IP6ADDR 232 /* draft-ietf-isis-ipv6-02 */
134 #define TLV_MT_IP_REACH 235 /* draft-ietf-isis-wg-multi-topology-05 */
135 #define TLV_IP6_REACH 236 /* draft-ietf-isis-ipv6-02 */
136 #define TLV_MT_IP6_REACH 237 /* draft-ietf-isis-wg-multi-topology-05 */
137 #define TLV_PTP_ADJ 240 /* rfc3373 */
138 #define TLV_IIH_SEQNR 241 /* draft-shen-isis-iih-sequence-00 */
139 #define TLV_VENDOR_PRIVATE 250 /* draft-ietf-isis-proprietary-tlv-00 */
140
141 static struct tok isis_tlv_values[] = {
142 { TLV_AREA_ADDR, "Area address(es)"},
143 { TLV_IS_REACH, "IS Reachability"},
144 { TLV_ESNEIGH, "ES Neighbor(s)"},
145 { TLV_PART_DIS, "Partition DIS"},
146 { TLV_PREFIX_NEIGH, "Prefix Neighbors"},
147 { TLV_ISNEIGH, "IS Neighbor(s)"},
148 { TLV_ISNEIGH_VARLEN, "IS Neighbor(s) (variable length)"},
149 { TLV_PADDING, "Padding"},
150 { TLV_LSP, "LSP entries"},
151 { TLV_AUTH, "Authentication"},
152 { TLV_CHECKSUM, "Checksum"},
153 { TLV_LSP_BUFFERSIZE, "LSP Buffersize"},
154 { TLV_EXT_IS_REACH, "Extended IS Reachability"},
155 { TLV_IS_ALIAS_ID, "IS Alias ID"},
156 { TLV_DECNET_PHASE4, "DECnet Phase IV"},
157 { TLV_LUCENT_PRIVATE, "Lucent Proprietary"},
158 { TLV_INT_IP_REACH, "IPv4 Internal Reachability"},
159 { TLV_PROTOCOLS, "Protocols supported"},
160 { TLV_EXT_IP_REACH, "IPv4 External Reachability"},
161 { TLV_IDRP_INFO, "Inter-Domain Information Type"},
162 { TLV_IPADDR, "IPv4 Interface address(es)"},
163 { TLV_IPAUTH, "IPv4 authentication (deprecated)"},
164 { TLV_TE_ROUTER_ID, "Traffic Engineering Router ID"},
165 { TLV_EXTD_IP_REACH, "Extended IPv4 Reachability"},
166 { TLV_HOSTNAME, "Hostname"},
167 { TLV_SHARED_RISK_GROUP, "Shared Risk Link Group"},
168 { TLV_NORTEL_PRIVATE1, "Nortel Proprietary"},
169 { TLV_NORTEL_PRIVATE2, "Nortel Proprietary"},
170 { TLV_HOLDTIME, "Holdtime"},
171 { TLV_RESTART_SIGNALING, "Restart Signaling"},
172 { TLV_MT_IS_REACH, "Multi Topology IS Reachability"},
173 { TLV_MT_SUPPORTED, "Multi Topology"},
174 { TLV_IP6ADDR, "IPv6 Interface address(es)"},
175 { TLV_MT_IP_REACH, "Multi-Topology IPv4 Reachability"},
176 { TLV_IP6_REACH, "IPv6 reachability"},
177 { TLV_MT_IP6_REACH, "Multi-Topology IP6 Reachability"},
178 { TLV_PTP_ADJ, "Point-to-point Adjacency State"},
179 { TLV_IIH_SEQNR, "Hello PDU Sequence Number"},
180 { TLV_VENDOR_PRIVATE, "Vendor Private"},
181 { 0, NULL }
182 };
183
184 #define SUBTLV_EXT_IS_REACH_ADMIN_GROUP 3 /* draft-ietf-isis-traffic-05 */
185 #define SUBTLV_EXT_IS_REACH_LINK_LOCAL_REMOTE_ID 4 /* draft-ietf-isis-gmpls-extensions */
186 #define SUBTLV_EXT_IS_REACH_LINK_REMOTE_ID 5 /* draft-ietf-isis-traffic-05 */
187 #define SUBTLV_EXT_IS_REACH_IPV4_INTF_ADDR 6 /* draft-ietf-isis-traffic-05 */
188 #define SUBTLV_EXT_IS_REACH_IPV4_NEIGHBOR_ADDR 8 /* draft-ietf-isis-traffic-05 */
189 #define SUBTLV_EXT_IS_REACH_MAX_LINK_BW 9 /* draft-ietf-isis-traffic-05 */
190 #define SUBTLV_EXT_IS_REACH_RESERVABLE_BW 10 /* draft-ietf-isis-traffic-05 */
191 #define SUBTLV_EXT_IS_REACH_UNRESERVED_BW 11 /* draft-ietf-isis-traffic-05 */
192 #define SUBTLV_EXT_IS_REACH_TE_METRIC 18 /* draft-ietf-isis-traffic-05 */
193 #define SUBTLV_EXT_IS_REACH_LINK_PROTECTION_TYPE 20 /* draft-ietf-isis-gmpls-extensions */
194 #define SUBTLV_EXT_IS_REACH_INTF_SW_CAP_DESCR 21 /* draft-ietf-isis-gmpls-extensions */
195
196 static struct tok isis_ext_is_reach_subtlv_values[] = {
197 { SUBTLV_EXT_IS_REACH_ADMIN_GROUP, "Administrative groups" },
198 { SUBTLV_EXT_IS_REACH_LINK_LOCAL_REMOTE_ID, "Link Local/Remote Identifier" },
199 { SUBTLV_EXT_IS_REACH_LINK_REMOTE_ID, "Link Remote Identifier" },
200 { SUBTLV_EXT_IS_REACH_IPV4_INTF_ADDR, "IPv4 interface address" },
201 { SUBTLV_EXT_IS_REACH_IPV4_NEIGHBOR_ADDR, "IPv4 neighbor address" },
202 { SUBTLV_EXT_IS_REACH_MAX_LINK_BW, "Maximum link bandwidth" },
203 { SUBTLV_EXT_IS_REACH_RESERVABLE_BW, "Reservable link bandwidth" },
204 { SUBTLV_EXT_IS_REACH_UNRESERVED_BW, "Unreserved bandwidth" },
205 { SUBTLV_EXT_IS_REACH_TE_METRIC, "Traffic Engineering Metric" },
206 { SUBTLV_EXT_IS_REACH_LINK_PROTECTION_TYPE, "Link Protection Type" },
207 { SUBTLV_EXT_IS_REACH_INTF_SW_CAP_DESCR, "Interface Switching Capability" },
208 { 250, "Reserved for cisco specific extensions" },
209 { 251, "Reserved for cisco specific extensions" },
210 { 252, "Reserved for cisco specific extensions" },
211 { 253, "Reserved for cisco specific extensions" },
212 { 254, "Reserved for cisco specific extensions" },
213 { 255, "Reserved for future expansion" },
214 { 0, NULL }
215 };
216
217 #define SUBTLV_EXTD_IP_REACH_ADMIN_TAG32 1
218 #define SUBTLV_EXTD_IP_REACH_ADMIN_TAG64 2
219
220 static struct tok isis_ext_ip_reach_subtlv_values[] = {
221 { SUBTLV_EXTD_IP_REACH_ADMIN_TAG32, "32-Bit Administrative tag" },
222 { SUBTLV_EXTD_IP_REACH_ADMIN_TAG64, "64-Bit Administrative tag" },
223 { 0, NULL }
224 };
225
226 #define SUBTLV_AUTH_SIMPLE 1
227 #define SUBTLV_AUTH_MD5 54
228 #define SUBTLV_AUTH_MD5_LEN 16
229 #define SUBTLV_AUTH_PRIVATE 255
230
231 static struct tok isis_subtlv_auth_values[] = {
232 { SUBTLV_AUTH_SIMPLE, "simple text password"},
233 { SUBTLV_AUTH_MD5, "HMAC-MD5 password"},
234 { SUBTLV_AUTH_PRIVATE, "Routing Domain private password"},
235 { 0, NULL }
236 };
237
238 #define SUBTLV_IDRP_RES 0
239 #define SUBTLV_IDRP_LOCAL 1
240 #define SUBTLV_IDRP_ASN 2
241
242 static struct tok isis_subtlv_idrp_values[] = {
243 { SUBTLV_IDRP_RES, "Reserved"},
244 { SUBTLV_IDRP_LOCAL, "Routing-Domain Specific"},
245 { SUBTLV_IDRP_ASN, "AS Number Tag"},
246 { 0, NULL}
247 };
248
249 #define ISIS_8BIT_MASK(x) ((x)&0xff)
250
251 #define ISIS_MASK_LSP_OL_BIT(x) ((x)&0x4)
252 #define ISIS_MASK_LSP_ISTYPE_BITS(x) ((x)&0x3)
253 #define ISIS_MASK_LSP_PARTITION_BIT(x) ((x)&0x80)
254 #define ISIS_MASK_LSP_ATT_BITS(x) ((x)&0x78)
255 #define ISIS_MASK_LSP_ATT_ERROR_BIT(x) ((x)&0x40)
256 #define ISIS_MASK_LSP_ATT_EXPENSE_BIT(x) ((x)&0x20)
257 #define ISIS_MASK_LSP_ATT_DELAY_BIT(x) ((x)&0x10)
258 #define ISIS_MASK_LSP_ATT_DEFAULT_BIT(x) ((x)&0x8)
259
260 #define ISIS_MASK_MTID(x) ((x)&0x0fff)
261 #define ISIS_MASK_MTFLAGS(x) ((x)&0xf000)
262
263 static struct tok isis_mt_flag_values[] = {
264 { 0x4000, "sub-TLVs present"},
265 { 0x8000, "ATT bit set"},
266 { 0, NULL}
267 };
268
269 #define ISIS_MASK_TLV_EXTD_IP_UPDOWN(x) ((x)&0x80)
270 #define ISIS_MASK_TLV_EXTD_IP_SUBTLV(x) ((x)&0x40)
271
272 #define ISIS_MASK_TLV_EXTD_IP6_IE(x) ((x)&0x40)
273 #define ISIS_MASK_TLV_EXTD_IP6_SUBTLV(x) ((x)&0x20)
274
275 #define ISIS_LSP_TLV_METRIC_SUPPORTED(x) ((x)&0x80)
276 #define ISIS_LSP_TLV_METRIC_IE(x) ((x)&0x40)
277 #define ISIS_LSP_TLV_METRIC_UPDOWN(x) ((x)&0x80)
278 #define ISIS_LSP_TLV_METRIC_VALUE(x) ((x)&0x3f)
279
280 #define ISIS_MASK_TLV_SHARED_RISK_GROUP(x) ((x)&0x1)
281
282 static struct tok isis_mt_values[] = {
283 { 0, "IPv4 unicast"},
284 { 1, "In-Band Management"},
285 { 2, "IPv6 unicast"},
286 { 3, "Multicast"},
287 { 4095, "Development, Experimental or Proprietary"},
288 { 0, NULL }
289 };
290
291 static struct tok isis_iih_circuit_type_values[] = {
292 { 1, "Level 1 only"},
293 { 2, "Level 2 only"},
294 { 3, "Level 1, Level 2"},
295 { 0, NULL}
296 };
297
298 #define ISIS_LSP_TYPE_UNUSED0 0
299 #define ISIS_LSP_TYPE_LEVEL_1 1
300 #define ISIS_LSP_TYPE_UNUSED2 2
301 #define ISIS_LSP_TYPE_LEVEL_2 3
302
303 static struct tok isis_lsp_istype_values[] = {
304 { ISIS_LSP_TYPE_UNUSED0, "Unused 0x0 (invalid)"},
305 { ISIS_LSP_TYPE_LEVEL_1, "L1 IS"},
306 { ISIS_LSP_TYPE_UNUSED2, "Unused 0x2 (invalid)"},
307 { ISIS_LSP_TYPE_LEVEL_2, "L1L2 IS"},
308 { 0, NULL }
309 };
310
311 static struct tok osi_nlpid_values[] = {
312 { NLPID_CLNS, "CLNS"},
313 { NLPID_IP, "IPv4"},
314 { NLPID_IP6, "IPv6"},
315 { 0, NULL }
316 };
317
318 /*
319 * Katz's point to point adjacency TLV uses codes to tell us the state of
320 * the remote adjacency. Enumerate them.
321 */
322
323 #define ISIS_PTP_ADJ_UP 0
324 #define ISIS_PTP_ADJ_INIT 1
325 #define ISIS_PTP_ADJ_DOWN 2
326
327
328 static struct tok isis_ptp_adjancey_values[] = {
329 { ISIS_PTP_ADJ_UP, "Up" },
330 { ISIS_PTP_ADJ_INIT, "Initializing" },
331 { ISIS_PTP_ADJ_DOWN, "Down" },
332 { 0, NULL}
333 };
334
335 struct isis_tlv_ptp_adj {
336 u_int8_t adjacency_state;
337 u_int8_t extd_local_circuit_id[4];
338 u_int8_t neighbor_sysid[SYSTEM_ID_LEN];
339 u_int8_t neighbor_extd_local_circuit_id[4];
340 };
341
342 static int osi_cksum(const u_int8_t *, u_int);
343 static void esis_print(const u_int8_t *, u_int);
344 static int isis_print(const u_int8_t *, u_int);
345
346 struct isis_metric_block {
347 u_int8_t metric_default;
348 u_int8_t metric_delay;
349 u_int8_t metric_expense;
350 u_int8_t metric_error;
351 };
352
353 struct isis_tlv_is_reach {
354 struct isis_metric_block isis_metric_block;
355 u_int8_t neighbor_nodeid[NODE_ID_LEN];
356 };
357
358 struct isis_tlv_es_reach {
359 struct isis_metric_block isis_metric_block;
360 u_int8_t neighbor_sysid[SYSTEM_ID_LEN];
361 };
362
363 struct isis_tlv_ip_reach {
364 struct isis_metric_block isis_metric_block;
365 u_int8_t prefix[4];
366 u_int8_t mask[4];
367 };
368
369 static struct tok isis_is_reach_virtual_values[] = {
370 { 0, "IsNotVirtual"},
371 { 1, "IsVirtual"},
372 { 0, NULL }
373 };
374
375 static struct tok isis_restart_flag_values[] = {
376 { 0x1, "Restart Request"},
377 { 0x2, "Restart Acknowledgement"},
378 { 0, NULL }
379 };
380
381 struct isis_common_header {
382 u_int8_t nlpid;
383 u_int8_t fixed_len;
384 u_int8_t version; /* Protocol version */
385 u_int8_t id_length;
386 u_int8_t pdu_type; /* 3 MSbits are reserved */
387 u_int8_t pdu_version; /* Packet format version */
388 u_int8_t reserved;
389 u_int8_t max_area;
390 };
391
392 struct isis_iih_lan_header {
393 u_int8_t circuit_type;
394 u_int8_t source_id[SYSTEM_ID_LEN];
395 u_int8_t holding_time[2];
396 u_int8_t pdu_len[2];
397 u_int8_t priority;
398 u_int8_t lan_id[NODE_ID_LEN];
399 };
400
401 struct isis_iih_ptp_header {
402 u_int8_t circuit_type;
403 u_int8_t source_id[SYSTEM_ID_LEN];
404 u_int8_t holding_time[2];
405 u_int8_t pdu_len[2];
406 u_int8_t circuit_id;
407 };
408
409 struct isis_lsp_header {
410 u_int8_t pdu_len[2];
411 u_int8_t remaining_lifetime[2];
412 u_int8_t lsp_id[LSP_ID_LEN];
413 u_int8_t sequence_number[4];
414 u_int8_t checksum[2];
415 u_int8_t typeblock;
416 };
417
418 struct isis_csnp_header {
419 u_int8_t pdu_len[2];
420 u_int8_t source_id[NODE_ID_LEN];
421 u_int8_t start_lsp_id[LSP_ID_LEN];
422 u_int8_t end_lsp_id[LSP_ID_LEN];
423 };
424
425 struct isis_psnp_header {
426 u_int8_t pdu_len[2];
427 u_int8_t source_id[NODE_ID_LEN];
428 };
429
430 struct isis_tlv_lsp {
431 u_int8_t remaining_lifetime[2];
432 u_int8_t lsp_id[LSP_ID_LEN];
433 u_int8_t sequence_number[4];
434 u_int8_t checksum[2];
435 };
436
437 static char *
438 print_nsap(register const u_int8_t *pptr, register int nsap_length)
439 {
440 int nsap_idx;
441 static char nsap_ascii_output[sizeof("xx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xx")];
442 char *junk_buf = nsap_ascii_output;
443
444 if (nsap_length < 1 || nsap_length > 20) {
445 snprintf(nsap_ascii_output, sizeof(nsap_ascii_output),
446 "illegal length");
447 return (nsap_ascii_output);
448 }
449
450 for (nsap_idx = 0; nsap_idx < nsap_length; nsap_idx++) {
451 if (!TTEST2(*pptr, 1))
452 return (0);
453 snprintf(junk_buf,
454 sizeof(nsap_ascii_output) - (junk_buf - nsap_ascii_output),
455 "%02x", *pptr++);
456 junk_buf += strlen(junk_buf);
457 if (((nsap_idx & 1) == 0) &&
458 (nsap_idx + 1 < nsap_length)) {
459 *junk_buf++ = '.';
460 }
461 }
462 *(junk_buf) = '\0';
463 return (nsap_ascii_output);
464 }
465
466 #define ISIS_COMMON_HEADER_SIZE (sizeof(struct isis_common_header))
467 #define ISIS_IIH_LAN_HEADER_SIZE (sizeof(struct isis_iih_lan_header))
468 #define ISIS_IIH_PTP_HEADER_SIZE (sizeof(struct isis_iih_ptp_header))
469 #define ISIS_LSP_HEADER_SIZE (sizeof(struct isis_lsp_header))
470 #define ISIS_CSNP_HEADER_SIZE (sizeof(struct isis_csnp_header))
471 #define ISIS_PSNP_HEADER_SIZE (sizeof(struct isis_psnp_header))
472
473 void isoclns_print(const u_int8_t *p, u_int length, u_int caplen)
474 {
475 u_int8_t pdu_type;
476 const struct isis_common_header *header;
477
478 header = (const struct isis_common_header *)p;
479 pdu_type = header->pdu_type & PDU_TYPE_MASK;
480
481 printf("%sOSI", caplen < 1 ? "|" : "");
482
483 if (caplen < 1) /* enough bytes on the wire ? */
484 return;
485
486 switch (*p) {
487
488 case NLPID_CLNS:
489 (void)printf(", CLNS, length %u", length);
490 break;
491
492 case NLPID_ESIS:
493 esis_print(p, length);
494 return;
495
496 case NLPID_ISIS:
497 if (!isis_print(p, length))
498 print_unknown_data(p,"\n\t",caplen);
499 break;
500
501 case NLPID_NULLNS:
502 (void)printf(", ISO NULLNS, length: %u", length);
503 break;
504
505 default:
506 (void)printf(", Unknown NLPID 0x%02x, length: %u", p[0], length);
507 if (caplen > 1)
508 print_unknown_data(p,"\n\t",caplen);
509 break;
510 }
511 }
512
513 #define ESIS_REDIRECT 6
514 #define ESIS_ESH 2
515 #define ESIS_ISH 4
516
517 static struct tok esis_values[] = {
518 { ESIS_REDIRECT, "redirect"},
519 { ESIS_ESH, "ESH"},
520 { ESIS_ISH, "ISH"},
521 { 0, NULL }
522 };
523
524 struct esis_hdr {
525 u_int8_t version;
526 u_int8_t reserved;
527 u_int8_t type;
528 u_int8_t tmo[2];
529 u_int8_t cksum[2];
530 };
531
532 static void
533 esis_print(const u_int8_t *p, u_int length)
534 {
535 const u_int8_t *ep;
536 u_int li;
537 const struct esis_hdr *eh;
538
539 if (length <= 2) {
540 if (qflag)
541 printf(" bad pkt!");
542 else
543 printf(" no header at all!");
544 return;
545 }
546 li = p[1];
547 eh = (const struct esis_hdr *) &p[2];
548 ep = p + li;
549 if (li > length) {
550 if (qflag)
551 printf(" bad pkt!");
552 else
553 printf(" LI(%d) > PDU size (%d)!", li, length);
554 return;
555 }
556 if (li < sizeof(struct esis_hdr) + 2) {
557 if (qflag)
558 printf(" bad pkt!");
559 else {
560 printf(" too short for esis header %d:", li);
561 while (--length != 0)
562 printf("%02X", *p++);
563 }
564 return;
565 }
566
567 printf(", ES-IS, %s, length %u",
568 tok2str(esis_values,"unknown type: %u",eh->type & 0x1f),
569 length);
570
571 if(vflag < 1)
572 return;
573
574 if (vflag && osi_cksum(p, li)) {
575 printf(" bad cksum (got 0x%02x%02x)",
576 eh->cksum[1], eh->cksum[0]);
577 default_print(p, length);
578 return;
579 }
580 if (eh->version != 1) {
581 printf(" unsupported version %d", eh->version);
582 return;
583 }
584 p += sizeof(*eh) + 2;
585 li -= sizeof(*eh) + 2; /* protoid * li */
586
587 switch (eh->type & 0x1f) {
588 case ESIS_REDIRECT: {
589 const u_int8_t *dst, *snpa, *is;
590
591 dst = p; p += *p + 1;
592 if (p > snapend)
593 return;
594 printf("\n\t\t %s", isonsap_string(dst));
595 snpa = p; p += *p + 1;
596 is = p; p += *p + 1;
597 if (p > snapend)
598 return;
599 if (p > ep) {
600 printf(" [bad li]");
601 return;
602 }
603 if (is[0] == 0)
604 printf(" > %s", etheraddr_string(&snpa[1]));
605 else
606 printf(" > %s", isonsap_string(is));
607 li = ep - p;
608 break;
609 }
610
611 case ESIS_ESH:
612 break;
613
614 case ESIS_ISH: {
615 const u_int8_t *is;
616
617 is = p; p += *p + 1;
618 if (p > ep) {
619 printf(" [bad li]");
620 return;
621 }
622 if (p > snapend)
623 return;
624 if (!qflag)
625 printf("\n\tNET: %s", print_nsap(is+1,*is));
626 li = ep - p;
627 break;
628 }
629
630 default:
631 if (vflag <= 1) {
632 if (p < snapend)
633 print_unknown_data(p,"\n\t ",snapend-p);
634 }
635 return;
636 }
637
638 /* hexdump - FIXME ? */
639 if (vflag > 1) {
640 if (p < snapend)
641 print_unknown_data(p,"\n\t ",snapend-p);
642 }
643 if (vflag)
644 while (p < ep && li) {
645 u_int op, opli;
646 const u_int8_t *q;
647
648 if (snapend - p < 2)
649 return;
650 if (li < 2) {
651 printf(", bad opts/li");
652 return;
653 }
654 op = *p++;
655 opli = *p++;
656 li -= 2;
657 if (opli > li) {
658 printf(", opt (%d) too long", op);
659 return;
660 }
661 li -= opli;
662 q = p;
663 p += opli;
664
665 if (snapend < p)
666 return;
667
668 if (op == TLV_HOLDTIME && opli == 2) {
669 printf("\n\tholdtime: %us", EXTRACT_16BITS(q));
670 continue;
671 }
672
673 if (op == TLV_PROTOCOLS && opli >= 1) {
674 printf("\n\t%s (length: %u): %s",
675 tok2str(isis_tlv_values, "unknown", op),
676 opli,
677 tok2str(osi_nlpid_values,"Unknown 0x%02x",*q));
678 continue;
679 }
680
681 print_unknown_data(q,"\n\t ",opli);
682 }
683 }
684
685 /* shared routine for printing system, node and lsp-ids */
686 static char *
687 isis_print_id(const u_int8_t *cp, int id_len)
688 {
689 int i;
690 static char id[sizeof("xxxx.xxxx.xxxx.yy-zz")];
691 char *pos = id;
692
693 for (i = 1; i <= SYSTEM_ID_LEN; i++) {
694 snprintf(pos, sizeof(id) - (pos - id), "%02x", *cp++);
695 pos += strlen(pos);
696 if (i == 2 || i == 4)
697 *pos++ = '.';
698 }
699 if (id_len >= NODE_ID_LEN) {
700 snprintf(pos, sizeof(id) - (pos - id), ".%02x", *cp++);
701 pos += strlen(pos);
702 }
703 if (id_len == LSP_ID_LEN)
704 snprintf(pos, sizeof(id) - (pos - id), "-%02x", *cp);
705 return (id);
706 }
707
708 /* print the 4-byte metric block which is common found in the old-style TLVs */
709 static int
710 isis_print_metric_block (const struct isis_metric_block *isis_metric_block)
711 {
712 printf(", Default Metric: %d, %s",
713 ISIS_LSP_TLV_METRIC_VALUE(isis_metric_block->metric_default),
714 ISIS_LSP_TLV_METRIC_IE(isis_metric_block->metric_default) ? "External" : "Internal");
715 if (!ISIS_LSP_TLV_METRIC_SUPPORTED(isis_metric_block->metric_delay))
716 printf("\n\t\t Delay Metric: %d, %s",
717 ISIS_LSP_TLV_METRIC_VALUE(isis_metric_block->metric_delay),
718 ISIS_LSP_TLV_METRIC_IE(isis_metric_block->metric_delay) ? "External" : "Internal");
719 if (!ISIS_LSP_TLV_METRIC_SUPPORTED(isis_metric_block->metric_expense))
720 printf("\n\t\t Expense Metric: %d, %s",
721 ISIS_LSP_TLV_METRIC_VALUE(isis_metric_block->metric_expense),
722 ISIS_LSP_TLV_METRIC_IE(isis_metric_block->metric_expense) ? "External" : "Internal");
723 if (!ISIS_LSP_TLV_METRIC_SUPPORTED(isis_metric_block->metric_error))
724 printf("\n\t\t Error Metric: %d, %s",
725 ISIS_LSP_TLV_METRIC_VALUE(isis_metric_block->metric_error),
726 ISIS_LSP_TLV_METRIC_IE(isis_metric_block->metric_error) ? "External" : "Internal");
727
728 return(1); /* everything is ok */
729 }
730
731 static int
732 isis_print_tlv_ip_reach (const u_int8_t *cp, const char *ident, int length)
733 {
734 int prefix_len;
735 const struct isis_tlv_ip_reach *tlv_ip_reach;
736
737 tlv_ip_reach = (const struct isis_tlv_ip_reach *)cp;
738
739 while (length > 0) {
740 if ((size_t)length < sizeof(*tlv_ip_reach)) {
741 printf("short IPv4 Reachability (%d vs %lu)",
742 length,
743 (unsigned long)sizeof(*tlv_ip_reach));
744 return (0);
745 }
746
747 if (!TTEST(*tlv_ip_reach))
748 return (0);
749
750 prefix_len = mask2plen(EXTRACT_32BITS(tlv_ip_reach->mask));
751
752 if (prefix_len == -1)
753 printf("%sIPv4 prefix: %s mask %s",
754 ident,
755 ipaddr_string((tlv_ip_reach->prefix)),
756 ipaddr_string((tlv_ip_reach->mask)));
757 else
758 printf("%sIPv4 prefix: %15s/%u",
759 ident,
760 ipaddr_string((tlv_ip_reach->prefix)),
761 prefix_len);
762
763 printf(", Distribution: %s, Metric: %u, %s",
764 ISIS_LSP_TLV_METRIC_UPDOWN(tlv_ip_reach->isis_metric_block.metric_default) ? "down" : "up",
765 ISIS_LSP_TLV_METRIC_VALUE(tlv_ip_reach->isis_metric_block.metric_default),
766 ISIS_LSP_TLV_METRIC_IE(tlv_ip_reach->isis_metric_block.metric_default) ? "External" : "Internal");
767
768 if (!ISIS_LSP_TLV_METRIC_SUPPORTED(tlv_ip_reach->isis_metric_block.metric_delay))
769 printf("%s Delay Metric: %u, %s",
770 ident,
771 ISIS_LSP_TLV_METRIC_VALUE(tlv_ip_reach->isis_metric_block.metric_delay),
772 ISIS_LSP_TLV_METRIC_IE(tlv_ip_reach->isis_metric_block.metric_delay) ? "External" : "Internal");
773
774 if (!ISIS_LSP_TLV_METRIC_SUPPORTED(tlv_ip_reach->isis_metric_block.metric_expense))
775 printf("%s Expense Metric: %u, %s",
776 ident,
777 ISIS_LSP_TLV_METRIC_VALUE(tlv_ip_reach->isis_metric_block.metric_expense),
778 ISIS_LSP_TLV_METRIC_IE(tlv_ip_reach->isis_metric_block.metric_expense) ? "External" : "Internal");
779
780 if (!ISIS_LSP_TLV_METRIC_SUPPORTED(tlv_ip_reach->isis_metric_block.metric_error))
781 printf("%s Error Metric: %u, %s",
782 ident,
783 ISIS_LSP_TLV_METRIC_VALUE(tlv_ip_reach->isis_metric_block.metric_error),
784 ISIS_LSP_TLV_METRIC_IE(tlv_ip_reach->isis_metric_block.metric_error) ? "External" : "Internal");
785
786 length -= sizeof(struct isis_tlv_ip_reach);
787 tlv_ip_reach++;
788 }
789 return (1);
790 }
791
792 /*
793 * this is the common IP-REACH subTLV decoder it is called
794 * from various EXTD-IP REACH TLVs (135,235,236,237)
795 */
796
797 static int
798 isis_print_ip_reach_subtlv (const u_int8_t *tptr,int subt,int subl,const char *ident) {
799
800 /* first lets see if we know the subTLVs name*/
801 printf("%s%s subTLV #%u, length: %u",
802 ident,
803 tok2str(isis_ext_ip_reach_subtlv_values,
804 "unknown",
805 subt),
806 subt,
807 subl);
808
809 if (!TTEST2(*tptr,subl))
810 goto trunctlv;
811
812 switch(subt) {
813 case SUBTLV_EXTD_IP_REACH_ADMIN_TAG32:
814 while (subl >= 4) {
815 printf(", 0x%08x (=%u)",
816 EXTRACT_32BITS(tptr),
817 EXTRACT_32BITS(tptr));
818 tptr+=4;
819 subl-=4;
820 }
821 break;
822 case SUBTLV_EXTD_IP_REACH_ADMIN_TAG64:
823 while (subl >= 8) {
824 printf(", 0x%08x%08x",
825 EXTRACT_32BITS(tptr),
826 EXTRACT_32BITS(tptr+4));
827 tptr+=8;
828 subl-=8;
829 }
830 break;
831 default:
832 if(!print_unknown_data(tptr,"\n\t\t ",
833 subl))
834 return(0);
835 break;
836 }
837 return(1);
838
839 trunctlv:
840 printf("%spacket exceeded snapshot",ident);
841 return(0);
842 }
843
844 /*
845 * this is the common IS-REACH subTLV decoder it is called
846 * from isis_print_ext_is_reach()
847 */
848
849 static int
850 isis_print_is_reach_subtlv (const u_int8_t *tptr,int subt,int subl,const char *ident) {
851
852 int priority_level;
853 union { /* int to float conversion buffer for several subTLVs */
854 float f;
855 u_int32_t i;
856 } bw;
857
858 /* first lets see if we know the subTLVs name*/
859 printf("%s%s subTLV #%u, length: %u",
860 ident,
861 tok2str(isis_ext_is_reach_subtlv_values,
862 "unknown",
863 subt),
864 subt,
865 subl);
866
867 if (!TTEST2(*tptr,subl))
868 goto trunctlv;
869
870 switch(subt) {
871 case SUBTLV_EXT_IS_REACH_ADMIN_GROUP:
872 case SUBTLV_EXT_IS_REACH_LINK_LOCAL_REMOTE_ID:
873 case SUBTLV_EXT_IS_REACH_LINK_REMOTE_ID:
874 printf(", 0x%08x", EXTRACT_32BITS(tptr));
875 if (subl == 8) /* draft-ietf-isis-gmpls-extensions */
876 printf(", 0x%08x", EXTRACT_32BITS(tptr+4));
877 break;
878 case SUBTLV_EXT_IS_REACH_IPV4_INTF_ADDR:
879 case SUBTLV_EXT_IS_REACH_IPV4_NEIGHBOR_ADDR:
880 printf(", %s", ipaddr_string(tptr));
881 break;
882 case SUBTLV_EXT_IS_REACH_MAX_LINK_BW :
883 case SUBTLV_EXT_IS_REACH_RESERVABLE_BW:
884 bw.i = EXTRACT_32BITS(tptr);
885 printf(", %.3f Mbps", bw.f*8/1000000 );
886 break;
887 case SUBTLV_EXT_IS_REACH_UNRESERVED_BW :
888 for (priority_level = 0; priority_level < 8; priority_level++) {
889 bw.i = EXTRACT_32BITS(tptr);
890 printf("%s priority level %d: %.3f Mbps",
891 ident,
892 priority_level,
893 bw.f*8/1000000 );
894 tptr+=4;
895 }
896 break;
897 case SUBTLV_EXT_IS_REACH_TE_METRIC:
898 printf(", %u", EXTRACT_24BITS(tptr));
899 break;
900 case SUBTLV_EXT_IS_REACH_LINK_PROTECTION_TYPE:
901 printf(", %s, Priority %u",
902 bittok2str(gmpls_link_prot_values, "none", *tptr),
903 *(tptr+1));
904 break;
905 case SUBTLV_EXT_IS_REACH_INTF_SW_CAP_DESCR:
906 printf("%s Interface Switching Capability:%s",
907 ident,
908 tok2str(gmpls_switch_cap_values, "Unknown", *(tptr)));
909 printf(", LSP Encoding: %s",
910 tok2str(gmpls_encoding_values, "Unknown", *(tptr+1)));
911 tptr+=4;
912 printf("%s Max LSP Bandwidth:",ident);
913 for (priority_level = 0; priority_level < 8; priority_level++) {
914 bw.i = EXTRACT_32BITS(tptr);
915 printf("%s priority level %d: %.3f Mbps",
916 ident,
917 priority_level,
918 bw.f*8/1000000 );
919 tptr+=4;
920 }
921 subl-=36;
922 /* there is some optional stuff left to decode but this is as of yet
923 not specified so just lets hexdump what is left */
924 if(subl>0){
925 if(!print_unknown_data(tptr,"\n\t\t ",
926 subl-36))
927 return(0);
928 }
929 break;
930 default:
931 if(!print_unknown_data(tptr,"\n\t\t ",
932 subl))
933 return(0);
934 break;
935 }
936 return(1);
937
938 trunctlv:
939 printf("%spacket exceeded snapshot",ident);
940 return(0);
941 }
942
943
944 /*
945 * this is the common IS-REACH decoder it is called
946 * from various EXTD-IS REACH style TLVs (22,24,222)
947 */
948
949 static int
950 isis_print_ext_is_reach (const u_int8_t *tptr,const char *ident, int tlv_type) {
951
952 char ident_buffer[20];
953 int subtlv_type,subtlv_len,subtlv_sum_len;
954 int proc_bytes = 0; /* how many bytes did we process ? */
955
956 if (!TTEST2(*tptr, NODE_ID_LEN))
957 return(0);
958
959 printf("%sIS Neighbor: %s", ident, isis_print_id(tptr, NODE_ID_LEN));
960 tptr+=(NODE_ID_LEN);
961
962 if (tlv_type != TLV_IS_ALIAS_ID) { /* the Alias TLV Metric field is implicit 0 */
963 if (!TTEST2(*tptr, 3)) /* and is therefore skipped */
964 return(0);
965 printf(", Metric: %d",EXTRACT_24BITS(tptr));
966 tptr+=3;
967 }
968
969 if (!TTEST2(*tptr, 1))
970 return(0);
971 subtlv_sum_len=*(tptr++); /* read out subTLV length */
972 proc_bytes=NODE_ID_LEN+3+1;
973 printf(", %ssub-TLVs present",subtlv_sum_len ? "" : "no ");
974 if (subtlv_sum_len) {
975 printf(" (%u)",subtlv_sum_len);
976 while (subtlv_sum_len>0) {
977 if (!TTEST2(*tptr,2))
978 return(0);
979 subtlv_type=*(tptr++);
980 subtlv_len=*(tptr++);
981 /* prepend the ident string */
982 snprintf(ident_buffer, sizeof(ident_buffer), "%s ",ident);
983 if(!isis_print_is_reach_subtlv(tptr,subtlv_type,subtlv_len,ident_buffer))
984 return(0);
985 tptr+=subtlv_len;
986 subtlv_sum_len-=(subtlv_len+2);
987 proc_bytes+=(subtlv_len+2);
988 }
989 }
990 return(proc_bytes);
991 }
992
993 /*
994 * this is the common Multi Topology ID decoder
995 * it is called from various MT-TLVs (222,229,235,237)
996 */
997
998 static int
999 isis_print_mtid (const u_int8_t *tptr,const char *ident) {
1000
1001 if (!TTEST2(*tptr, 2))
1002 return(0);
1003
1004 printf("%s%s",
1005 ident,
1006 tok2str(isis_mt_values,
1007 "Reserved for IETF Consensus",
1008 ISIS_MASK_MTID(EXTRACT_16BITS(tptr))));
1009
1010 printf(" Topology (0x%03x), Flags: [%s]",
1011 ISIS_MASK_MTID(EXTRACT_16BITS(tptr)),
1012 bittok2str(isis_mt_flag_values, "none",ISIS_MASK_MTFLAGS(EXTRACT_16BITS(tptr))));
1013
1014 return(2);
1015 }
1016
1017 /*
1018 * this is the common extended IP reach decoder
1019 * it is called from TLVs (135,235,236,237)
1020 * we process the TLV and optional subTLVs and return
1021 * the amount of processed bytes
1022 */
1023
1024 static int
1025 isis_print_extd_ip_reach (const u_int8_t *tptr, const char *ident, u_int16_t afi) {
1026
1027 char ident_buffer[20];
1028 u_int8_t prefix[16]; /* shared copy buffer for IPv4 and IPv6 prefixes */
1029 u_int metric, status_byte, bit_length, byte_length, sublen, processed, subtlvtype, subtlvlen;
1030
1031 if (!TTEST2(*tptr, 4))
1032 return (0);
1033 metric = EXTRACT_32BITS(tptr);
1034 processed=4;
1035 tptr+=4;
1036
1037 if (afi == IPV4) {
1038 if (!TTEST2(*tptr, 1)) /* fetch status byte */
1039 return (0);
1040 status_byte=*(tptr++);
1041 bit_length = status_byte&0x3f;
1042 processed++;
1043 #ifdef INET6
1044 } else if (afi == IPV6) {
1045 if (!TTEST2(*tptr, 1)) /* fetch status & prefix_len byte */
1046 return (0);
1047 status_byte=*(tptr++);
1048 bit_length=*(tptr++);
1049 processed+=2;
1050 #endif
1051 } else
1052 return (0); /* somebody is fooling us */
1053
1054 byte_length = (bit_length + 7) / 8; /* prefix has variable length encoding */
1055
1056 if (!TTEST2(*tptr, byte_length))
1057 return (0);
1058 memset(prefix, 0, 16); /* clear the copy buffer */
1059 memcpy(prefix,tptr,byte_length); /* copy as much as is stored in the TLV */
1060 tptr+=byte_length;
1061 processed+=byte_length;
1062
1063 if (afi == IPV4)
1064 printf("%sIPv4 prefix: %15s/%u",
1065 ident,
1066 ipaddr_string(prefix),
1067 bit_length);
1068 #ifdef INET6
1069 if (afi == IPV6)
1070 printf("%sIPv6 prefix: %s/%u",
1071 ident,
1072 ip6addr_string(prefix),
1073 bit_length);
1074 #endif
1075
1076 printf(", Distribution: %s, Metric: %u",
1077 ISIS_MASK_TLV_EXTD_IP_UPDOWN(status_byte) ? "down" : "up",
1078 metric);
1079
1080 if (afi == IPV4 && ISIS_MASK_TLV_EXTD_IP_SUBTLV(status_byte))
1081 printf(", sub-TLVs present");
1082 #ifdef INET6
1083 if (afi == IPV6)
1084 printf(", %s%s",
1085 ISIS_MASK_TLV_EXTD_IP6_IE(status_byte) ? "External" : "Internal",
1086 ISIS_MASK_TLV_EXTD_IP6_SUBTLV(status_byte) ? ", sub-TLVs present" : "");
1087 #endif
1088
1089 if ((ISIS_MASK_TLV_EXTD_IP_SUBTLV(status_byte) && afi == IPV4) ||
1090 (ISIS_MASK_TLV_EXTD_IP6_SUBTLV(status_byte) && afi == IPV6)) {
1091 /* assume that one prefix can hold more
1092 than one subTLV - therefore the first byte must reflect
1093 the aggregate bytecount of the subTLVs for this prefix
1094 */
1095 if (!TTEST2(*tptr, 1))
1096 return (0);
1097 sublen=*(tptr++);
1098 processed+=sublen+1;
1099 printf(" (%u)",sublen); /* print out subTLV length */
1100
1101 while (sublen>0) {
1102 if (!TTEST2(*tptr,2))
1103 return (0);
1104 subtlvtype=*(tptr++);
1105 subtlvlen=*(tptr++);
1106 /* prepend the ident string */
1107 snprintf(ident_buffer, sizeof(ident_buffer), "%s ",ident);
1108 if(!isis_print_ip_reach_subtlv(tptr,subtlvtype,subtlvlen,ident_buffer))
1109 return(0);
1110 tptr+=subtlvlen;
1111 sublen-=(subtlvlen+2);
1112 }
1113 }
1114 return (processed);
1115 }
1116
1117 /*
1118 * isis_print
1119 * Decode IS-IS packets. Return 0 on error.
1120 */
1121
1122 static int isis_print (const u_int8_t *p, u_int length)
1123 {
1124 const struct isis_common_header *header;
1125
1126 const struct isis_iih_lan_header *header_iih_lan;
1127 const struct isis_iih_ptp_header *header_iih_ptp;
1128 const struct isis_lsp_header *header_lsp;
1129 const struct isis_csnp_header *header_csnp;
1130 const struct isis_psnp_header *header_psnp;
1131
1132 const struct isis_tlv_lsp *tlv_lsp;
1133 const struct isis_tlv_ptp_adj *tlv_ptp_adj;
1134 const struct isis_tlv_is_reach *tlv_is_reach;
1135 const struct isis_tlv_es_reach *tlv_es_reach;
1136
1137 u_int8_t pdu_type, max_area, id_length, tlv_type, tlv_len, tmp, alen, lan_alen, prefix_len;
1138 u_int8_t ext_is_len, ext_ip_len, mt_len;
1139 const u_int8_t *optr, *pptr, *tptr;
1140 u_short packet_len,pdu_len;
1141 u_int i;
1142
1143 packet_len=length;
1144 optr = p; /* initialize the _o_riginal pointer to the packet start -
1145 need it for parsing the checksum TLV */
1146 header = (const struct isis_common_header *)p;
1147 TCHECK(*header);
1148 pptr = p+(ISIS_COMMON_HEADER_SIZE);
1149 header_iih_lan = (const struct isis_iih_lan_header *)pptr;
1150 header_iih_ptp = (const struct isis_iih_ptp_header *)pptr;
1151 header_lsp = (const struct isis_lsp_header *)pptr;
1152 header_csnp = (const struct isis_csnp_header *)pptr;
1153 header_psnp = (const struct isis_psnp_header *)pptr;
1154
1155 /*
1156 * Sanity checking of the header.
1157 */
1158
1159 if (header->version != ISIS_VERSION) {
1160 printf(", version %d packet not supported", header->version);
1161 return (0);
1162 }
1163
1164 if ((header->id_length != SYSTEM_ID_LEN) && (header->id_length != 0)) {
1165 printf(", system ID length of %d is not supported",
1166 header->id_length);
1167 return (0);
1168 }
1169
1170 if (header->pdu_version != ISIS_VERSION) {
1171 printf(", version %d packet not supported", header->pdu_version);
1172 return (0);
1173 }
1174
1175 max_area = header->max_area;
1176 switch(max_area) {
1177 case 0:
1178 max_area = 3; /* silly shit */
1179 break;
1180 case 255:
1181 printf(", bad packet -- 255 areas");
1182 return (0);
1183 default:
1184 break;
1185 }
1186
1187 id_length = header->id_length;
1188 switch(id_length) {
1189 case 0:
1190 id_length = 6; /* silly shit again */
1191 break;
1192 case 1: /* 1-8 are valid sys-ID lenghts */
1193 case 2:
1194 case 3:
1195 case 4:
1196 case 5:
1197 case 6:
1198 case 7:
1199 case 8:
1200 break;
1201 case 255:
1202 id_length = 0; /* entirely useless */
1203 break;
1204 default:
1205 break;
1206 }
1207
1208 /* toss any non 6-byte sys-ID len PDUs */
1209 if (id_length != 6 ) {
1210 printf(", bad packet -- illegal sys-ID length (%u)", id_length);
1211 return (0);
1212 }
1213
1214 pdu_type=header->pdu_type;
1215
1216 /* in non-verbose mode print the basic PDU Type plus PDU specific brief information*/
1217 if (vflag < 1) {
1218 printf(", IS-IS, %s",
1219 tok2str(isis_pdu_values,"unknown PDU-Type %u",pdu_type));
1220
1221 switch (pdu_type) {
1222
1223 case L1_LAN_IIH:
1224 case L2_LAN_IIH:
1225 printf(", src-id %s",
1226 isis_print_id(header_iih_lan->source_id,SYSTEM_ID_LEN));
1227 printf(", lan-id %s, prio %u",
1228 isis_print_id(header_iih_lan->lan_id,NODE_ID_LEN),
1229 header_iih_lan->priority);
1230 break;
1231 case PTP_IIH:
1232 printf(", src-id %s", isis_print_id(header_iih_ptp->source_id,SYSTEM_ID_LEN));
1233 break;
1234 case L1_LSP:
1235 case L2_LSP:
1236 printf(", lsp-id %s, seq 0x%08x, lifetime %5us",
1237 isis_print_id(header_lsp->lsp_id, LSP_ID_LEN),
1238 EXTRACT_32BITS(header_lsp->sequence_number),
1239 EXTRACT_16BITS(header_lsp->remaining_lifetime));
1240 break;
1241 case L1_CSNP:
1242 case L2_CSNP:
1243 printf(", src-id %s", isis_print_id(header_csnp->source_id,SYSTEM_ID_LEN));
1244 break;
1245 case L1_PSNP:
1246 case L2_PSNP:
1247 printf(", src-id %s", isis_print_id(header_psnp->source_id,SYSTEM_ID_LEN));
1248 break;
1249
1250 }
1251 printf(", length %u", length);
1252
1253 return(1);
1254 }
1255
1256 /* ok they seem to want to know everything - lets fully decode it */
1257 printf(", IS-IS, length: %u",length);
1258
1259 printf("\n\t%s, hlen: %u, v: %u, pdu-v: %u, sys-id-len: %u (%u), max-area: %u (%u)",
1260 tok2str(isis_pdu_values,
1261 "unknown, type %u",
1262 pdu_type),
1263 header->fixed_len,
1264 header->version,
1265 header->pdu_version,
1266 id_length,
1267 header->id_length,
1268 max_area,
1269 header->max_area);
1270
1271 if (vflag > 1) {
1272 if(!print_unknown_data(optr,"\n\t",8)) /* provide the _o_riginal pointer */
1273 return(0); /* for optionally debugging the common header */
1274 }
1275
1276 switch (pdu_type) {
1277
1278 case L1_LAN_IIH:
1279 case L2_LAN_IIH:
1280 if (header->fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_LAN_HEADER_SIZE)) {
1281 printf(", bogus fixed header length %u should be %lu",
1282 header->fixed_len, (unsigned long)ISIS_IIH_LAN_HEADER_SIZE);
1283 return (0);
1284 }
1285
1286 pdu_len=EXTRACT_16BITS(header_iih_lan->pdu_len);
1287 if (packet_len>pdu_len) {
1288 packet_len=pdu_len; /* do TLV decoding as long as it makes sense */
1289 length=pdu_len;
1290 }
1291
1292 TCHECK(*header_iih_lan);
1293 printf("\n\t source-id: %s, holding time: %us, Flags: [%s]",
1294 isis_print_id(header_iih_lan->source_id,SYSTEM_ID_LEN),
1295 EXTRACT_16BITS(header_iih_lan->holding_time),
1296 tok2str(isis_iih_circuit_type_values,
1297 "unknown circuit type 0x%02x",
1298 header_iih_lan->circuit_type));
1299
1300 printf("\n\t lan-id: %s, Priority: %u, PDU length: %u",
1301 isis_print_id(header_iih_lan->lan_id, NODE_ID_LEN),
1302 (header_iih_lan->priority) & PRIORITY_MASK,
1303 pdu_len);
1304
1305 if (vflag > 1) {
1306 if(!print_unknown_data(pptr,"\n\t ",ISIS_IIH_LAN_HEADER_SIZE))
1307 return(0);
1308 }
1309
1310 packet_len -= (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_LAN_HEADER_SIZE);
1311 pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_LAN_HEADER_SIZE);
1312 break;
1313
1314 case PTP_IIH:
1315 if (header->fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_PTP_HEADER_SIZE)) {
1316 printf(", bogus fixed header length %u should be %lu",
1317 header->fixed_len, (unsigned long)ISIS_IIH_PTP_HEADER_SIZE);
1318 return (0);
1319 }
1320
1321 pdu_len=EXTRACT_16BITS(header_iih_ptp->pdu_len);
1322 if (packet_len>pdu_len) {
1323 packet_len=pdu_len; /* do TLV decoding as long as it makes sense */
1324 length=pdu_len;
1325 }
1326
1327 TCHECK(*header_iih_ptp);
1328 printf("\n\t source-id: %s, holding time: %us, Flags: [%s]",
1329 isis_print_id(header_iih_ptp->source_id,SYSTEM_ID_LEN),
1330 EXTRACT_16BITS(header_iih_ptp->holding_time),
1331 tok2str(isis_iih_circuit_type_values,
1332 "unknown circuit type 0x%02x",
1333 header_iih_ptp->circuit_type));
1334
1335 printf("\n\t circuit-id: 0x%02x, PDU length: %u",
1336 header_iih_ptp->circuit_id,
1337 pdu_len);
1338
1339 if (vflag > 1) {
1340 if(!print_unknown_data(pptr,"\n\t ",ISIS_IIH_PTP_HEADER_SIZE))
1341 return(0);
1342 }
1343
1344 packet_len -= (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_PTP_HEADER_SIZE);
1345 pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_PTP_HEADER_SIZE);
1346 break;
1347
1348 case L1_LSP:
1349 case L2_LSP:
1350 if (header->fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_LSP_HEADER_SIZE)) {
1351 printf(", bogus fixed header length %u should be %lu",
1352 header->fixed_len, (unsigned long)ISIS_LSP_HEADER_SIZE);
1353 return (0);
1354 }
1355
1356 pdu_len=EXTRACT_16BITS(header_lsp->pdu_len);
1357 if (packet_len>pdu_len) {
1358 packet_len=pdu_len; /* do TLV decoding as long as it makes sense */
1359 length=pdu_len;
1360 }
1361
1362 TCHECK(*header_lsp);
1363 printf("\n\t lsp-id: %s, seq: 0x%08x, lifetime: %5us\n\t chksum: 0x%04x",
1364 isis_print_id(header_lsp->lsp_id, LSP_ID_LEN),
1365 EXTRACT_32BITS(header_lsp->sequence_number),
1366 EXTRACT_16BITS(header_lsp->remaining_lifetime),
1367 EXTRACT_16BITS(header_lsp->checksum));
1368
1369 /* if this is a purge do not attempt to verify the checksum */
1370 if ( EXTRACT_16BITS(header_lsp->remaining_lifetime) == 0 &&
1371 EXTRACT_16BITS(header_lsp->checksum) == 0)
1372 printf(" (purged)");
1373 else
1374 /* verify the checksum -
1375 * checking starts at the lsp-id field at byte position [12]
1376 * hence the length needs to be reduced by 12 bytes */
1377 printf(" (%s)", (osi_cksum((u_int8_t *)header_lsp->lsp_id, length-12)) ? "incorrect" : "correct");
1378
1379 printf(", PDU length: %u, Flags: [ %s",
1380 pdu_len,
1381 ISIS_MASK_LSP_OL_BIT(header_lsp->typeblock) ? "Overload bit set, " : "");
1382
1383 if (ISIS_MASK_LSP_ATT_BITS(header_lsp->typeblock)) {
1384 printf("%s", ISIS_MASK_LSP_ATT_DEFAULT_BIT(header_lsp->typeblock) ? "default " : "");
1385 printf("%s", ISIS_MASK_LSP_ATT_DELAY_BIT(header_lsp->typeblock) ? "delay " : "");
1386 printf("%s", ISIS_MASK_LSP_ATT_EXPENSE_BIT(header_lsp->typeblock) ? "expense " : "");
1387 printf("%s", ISIS_MASK_LSP_ATT_ERROR_BIT(header_lsp->typeblock) ? "error " : "");
1388 printf("ATT bit set, ");
1389 }
1390 printf("%s", ISIS_MASK_LSP_PARTITION_BIT(header_lsp->typeblock) ? "P bit set, " : "");
1391 printf("%s ]", tok2str(isis_lsp_istype_values,"Unknown(0x%x)",ISIS_MASK_LSP_ISTYPE_BITS(header_lsp->typeblock)));
1392
1393 if (vflag > 1) {
1394 if(!print_unknown_data(pptr,"\n\t ",ISIS_LSP_HEADER_SIZE))
1395 return(0);
1396 }
1397
1398 packet_len -= (ISIS_COMMON_HEADER_SIZE+ISIS_LSP_HEADER_SIZE);
1399 pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_LSP_HEADER_SIZE);
1400 break;
1401
1402 case L1_CSNP:
1403 case L2_CSNP:
1404 if (header->fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_CSNP_HEADER_SIZE)) {
1405 printf(", bogus fixed header length %u should be %lu",
1406 header->fixed_len, (unsigned long)ISIS_CSNP_HEADER_SIZE);
1407 return (0);
1408 }
1409
1410 pdu_len=EXTRACT_16BITS(header_csnp->pdu_len);
1411 if (packet_len>pdu_len) {
1412 packet_len=pdu_len; /* do TLV decoding as long as it makes sense */
1413 length=pdu_len;
1414 }
1415
1416 TCHECK(*header_csnp);
1417 printf("\n\t source-id: %s, PDU length: %u",
1418 isis_print_id(header_csnp->source_id, NODE_ID_LEN),
1419 pdu_len);
1420 printf("\n\t start lsp-id: %s",
1421 isis_print_id(header_csnp->start_lsp_id, LSP_ID_LEN));
1422 printf("\n\t end lsp-id: %s",
1423 isis_print_id(header_csnp->end_lsp_id, LSP_ID_LEN));
1424
1425 if (vflag > 1) {
1426 if(!print_unknown_data(pptr,"\n\t ",ISIS_CSNP_HEADER_SIZE))
1427 return(0);
1428 }
1429
1430 packet_len -= (ISIS_COMMON_HEADER_SIZE+ISIS_CSNP_HEADER_SIZE);
1431 pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_CSNP_HEADER_SIZE);
1432 break;
1433
1434 case L1_PSNP:
1435 case L2_PSNP:
1436 if (header->fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_PSNP_HEADER_SIZE)) {
1437 printf("- bogus fixed header length %u should be %lu",
1438 header->fixed_len, (unsigned long)ISIS_PSNP_HEADER_SIZE);
1439 return (0);
1440 }
1441
1442 pdu_len=EXTRACT_16BITS(header_psnp->pdu_len);
1443 if (packet_len>pdu_len) {
1444 packet_len=pdu_len; /* do TLV decoding as long as it makes sense */
1445 length=pdu_len;
1446 }
1447
1448 TCHECK(*header_psnp);
1449 printf("\n\t source-id: %s, PDU length: %u",
1450 isis_print_id(header_psnp->source_id, NODE_ID_LEN),
1451 pdu_len);
1452
1453 if (vflag > 1) {
1454 if(!print_unknown_data(pptr,"\n\t ",ISIS_PSNP_HEADER_SIZE))
1455 return(0);
1456 }
1457
1458 packet_len -= (ISIS_COMMON_HEADER_SIZE+ISIS_PSNP_HEADER_SIZE);
1459 pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_PSNP_HEADER_SIZE);
1460 break;
1461
1462 default:
1463 if(!print_unknown_data(pptr,"\n\t ",length))
1464 return(0);
1465 return (0);
1466 }
1467
1468 /*
1469 * Now print the TLV's.
1470 */
1471
1472 while (packet_len >= 2) {
1473 if (pptr == snapend) {
1474 return (1);
1475 }
1476
1477 if (!TTEST2(*pptr, 2)) {
1478 printf("\n\t\t packet exceeded snapshot (%ld) bytes",
1479 (long)(pptr-snapend));
1480 return (1);
1481 }
1482 tlv_type = *pptr++;
1483 tlv_len = *pptr++;
1484 tmp =tlv_len; /* copy temporary len & pointer to packet data */
1485 tptr = pptr;
1486 packet_len -= 2;
1487 if (tlv_len > packet_len) {
1488 break;
1489 }
1490
1491 /* first lets see if we know the TLVs name*/
1492 printf("\n\t %s TLV #%u, length: %u",
1493 tok2str(isis_tlv_values,
1494 "unknown",
1495 tlv_type),
1496 tlv_type,
1497 tlv_len);
1498
1499 /* now check if we have a decoder otherwise do a hexdump at the end*/
1500 switch (tlv_type) {
1501 case TLV_AREA_ADDR:
1502 if (!TTEST2(*tptr, 1))
1503 goto trunctlv;
1504 alen = *tptr++;
1505 while (tmp && alen < tmp) {
1506 printf("\n\t Area address (length: %u): %s",
1507 alen,
1508 print_nsap(tptr, alen));
1509 tptr += alen;
1510 tmp -= alen + 1;
1511 if (tmp==0) /* if this is the last area address do not attemt a boundary check */
1512 break;
1513 if (!TTEST2(*tptr, 1))
1514 goto trunctlv;
1515 alen = *tptr++;
1516 }
1517 break;
1518 case TLV_ISNEIGH:
1519 while (tmp >= ETHER_ADDR_LEN) {
1520 if (!TTEST2(*tptr, ETHER_ADDR_LEN))
1521 goto trunctlv;
1522 printf("\n\t SNPA: %s",isis_print_id(tptr,ETHER_ADDR_LEN));
1523 tmp -= ETHER_ADDR_LEN;
1524 tptr += ETHER_ADDR_LEN;
1525 }
1526 break;
1527
1528 case TLV_ISNEIGH_VARLEN:
1529 if (!TTEST2(*tptr, 1))
1530 goto trunctlv;
1531 lan_alen = *tptr++; /* LAN adress length */
1532 tmp --;
1533 printf("\n\t LAN address length %u bytes ",lan_alen);
1534 while (tmp >= lan_alen) {
1535 if (!TTEST2(*tptr, lan_alen))
1536 goto trunctlv;
1537 printf("\n\t\tIS Neighbor: %s",isis_print_id(tptr,lan_alen));
1538 tmp -= lan_alen;
1539 tptr +=lan_alen;
1540 }
1541 break;
1542
1543 case TLV_PADDING:
1544 break;
1545
1546 case TLV_MT_IS_REACH:
1547 while (tmp >= 2+NODE_ID_LEN+3+1) {
1548 mt_len = isis_print_mtid(tptr, "\n\t ");
1549 if (mt_len == 0) /* did something go wrong ? */
1550 goto trunctlv;
1551 tptr+=mt_len;
1552 tmp-=mt_len;
1553
1554 ext_is_len = isis_print_ext_is_reach(tptr,"\n\t ",tlv_type);
1555 if (ext_is_len == 0) /* did something go wrong ? */
1556 goto trunctlv;
1557
1558 tmp-=ext_is_len;
1559 tptr+=ext_is_len;
1560 }
1561 break;
1562
1563 case TLV_IS_ALIAS_ID:
1564 while (tmp >= NODE_ID_LEN+1) { /* is it worth attempting a decode ? */
1565 ext_is_len = isis_print_ext_is_reach(tptr,"\n\t ",tlv_type);
1566 if (ext_is_len == 0) /* did something go wrong ? */
1567 goto trunctlv;
1568 tmp-=ext_is_len;
1569 tptr+=ext_is_len;
1570 }
1571 break;
1572
1573 case TLV_EXT_IS_REACH:
1574 while (tmp >= NODE_ID_LEN+3+1) { /* is it worth attempting a decode ? */
1575 ext_is_len = isis_print_ext_is_reach(tptr,"\n\t ",tlv_type);
1576 if (ext_is_len == 0) /* did something go wrong ? */
1577 goto trunctlv;
1578 tmp-=ext_is_len;
1579 tptr+=ext_is_len;
1580 }
1581 break;
1582 case TLV_IS_REACH:
1583 if (!TTEST2(*tptr,1)) /* check if there is one byte left to read out the virtual flag */
1584 goto trunctlv;
1585 printf("\n\t %s",
1586 tok2str(isis_is_reach_virtual_values,
1587 "bogus virtual flag 0x%02x",
1588 *tptr++));
1589 tlv_is_reach = (const struct isis_tlv_is_reach *)tptr;
1590 while (tmp >= sizeof(struct isis_tlv_is_reach)) {
1591 if (!TTEST(*tlv_is_reach))
1592 goto trunctlv;
1593 printf("\n\t IS Neighbor: %s",
1594 isis_print_id(tlv_is_reach->neighbor_nodeid, NODE_ID_LEN));
1595 isis_print_metric_block(&tlv_is_reach->isis_metric_block);
1596 tmp -= sizeof(struct isis_tlv_is_reach);
1597 tlv_is_reach++;
1598 }
1599 break;
1600
1601 case TLV_ESNEIGH:
1602 tlv_es_reach = (const struct isis_tlv_es_reach *)tptr;
1603 while (tmp >= sizeof(struct isis_tlv_es_reach)) {
1604 if (!TTEST(*tlv_es_reach))
1605 goto trunctlv;
1606 printf("\n\t ES Neighbor: %s",
1607 isis_print_id(tlv_es_reach->neighbor_sysid,SYSTEM_ID_LEN));
1608 isis_print_metric_block(&tlv_es_reach->isis_metric_block);
1609 tmp -= sizeof(struct isis_tlv_es_reach);
1610 tlv_es_reach++;
1611 }
1612 break;
1613
1614 /* those two TLVs share the same format */
1615 case TLV_INT_IP_REACH:
1616 case TLV_EXT_IP_REACH:
1617 if (!isis_print_tlv_ip_reach(pptr, "\n\t ", tlv_len))
1618 return (1);
1619 break;
1620
1621 case TLV_EXTD_IP_REACH:
1622 while (tmp>0) {
1623 ext_ip_len = isis_print_extd_ip_reach(tptr, "\n\t ", IPV4);
1624 if (ext_ip_len == 0) /* did something go wrong ? */
1625 goto trunctlv;
1626 tptr+=ext_ip_len;
1627 tmp-=ext_ip_len;
1628 }
1629 break;
1630
1631 case TLV_MT_IP_REACH:
1632 while (tmp>0) {
1633 mt_len = isis_print_mtid(tptr, "\n\t ");
1634 if (mt_len == 0) /* did something go wrong ? */
1635 goto trunctlv;
1636 tptr+=mt_len;
1637 tmp-=mt_len;
1638
1639 ext_ip_len = isis_print_extd_ip_reach(tptr, "\n\t ", IPV4);
1640 if (ext_ip_len == 0) /* did something go wrong ? */
1641 goto trunctlv;
1642 tptr+=ext_ip_len;
1643 tmp-=ext_ip_len;
1644 }
1645 break;
1646
1647 #ifdef INET6
1648 case TLV_IP6_REACH:
1649 while (tmp>0) {
1650 ext_ip_len = isis_print_extd_ip_reach(tptr, "\n\t ", IPV6);
1651 if (ext_ip_len == 0) /* did something go wrong ? */
1652 goto trunctlv;
1653 tptr+=ext_ip_len;
1654 tmp-=ext_ip_len;
1655 }
1656 break;
1657
1658 case TLV_MT_IP6_REACH:
1659 while (tmp>0) {
1660 mt_len = isis_print_mtid(tptr, "\n\t ");
1661 if (mt_len == 0) /* did something go wrong ? */
1662 goto trunctlv;
1663 tptr+=mt_len;
1664 tmp-=mt_len;
1665
1666 ext_ip_len = isis_print_extd_ip_reach(tptr, "\n\t ", IPV6);
1667 if (ext_ip_len == 0) /* did something go wrong ? */
1668 goto trunctlv;
1669 tptr+=ext_ip_len;
1670 tmp-=ext_ip_len;
1671 }
1672 break;
1673
1674 case TLV_IP6ADDR:
1675 while (tmp>0) {
1676 if (!TTEST2(*tptr, 16))
1677 goto trunctlv;
1678
1679 printf("\n\t IPv6 interface address: %s",
1680 ip6addr_string(tptr));
1681
1682 tptr += 16;
1683 tmp -= 16;
1684 }
1685 break;
1686 #endif
1687 case TLV_AUTH:
1688 if (!TTEST2(*tptr, 1))
1689 goto trunctlv;
1690
1691 printf("\n\t %s: ",
1692 tok2str(isis_subtlv_auth_values,
1693 "unknown Authentication type 0x%02x",
1694 *tptr));
1695
1696 switch (*tptr) {
1697 case SUBTLV_AUTH_SIMPLE:
1698 for(i=1;i<tlv_len;i++) {
1699 if (!TTEST2(*(tptr+i), 1))
1700 goto trunctlv;
1701 printf("%c",*(tptr+i));
1702 }
1703 break;
1704 case SUBTLV_AUTH_MD5:
1705 for(i=1;i<tlv_len;i++) {
1706 if (!TTEST2(*(tptr+i), 1))
1707 goto trunctlv;
1708 printf("%02x",*(tptr+i));
1709 }
1710 if (tlv_len != SUBTLV_AUTH_MD5_LEN+1)
1711 printf(", (malformed subTLV) ");
1712 break;
1713 case SUBTLV_AUTH_PRIVATE:
1714 default:
1715 if(!print_unknown_data(tptr+1,"\n\t\t ",tlv_len-1))
1716 return(0);
1717 break;
1718 }
1719 break;
1720
1721 case TLV_PTP_ADJ:
1722 tlv_ptp_adj = (const struct isis_tlv_ptp_adj *)tptr;
1723 if(tmp>=1) {
1724 if (!TTEST2(*tptr, 1))
1725 goto trunctlv;
1726 printf("\n\t Adjacency State: %s (%u)",
1727 tok2str(isis_ptp_adjancey_values, "unknown", *tptr),
1728 *tptr);
1729 tmp--;
1730 }
1731 if(tmp>sizeof(tlv_ptp_adj->extd_local_circuit_id)) {
1732 if (!TTEST2(tlv_ptp_adj->extd_local_circuit_id,
1733 sizeof(tlv_ptp_adj->extd_local_circuit_id)))
1734 goto trunctlv;
1735 printf("\n\t Extended Local circuit-ID: 0x%08x",
1736 EXTRACT_32BITS(tlv_ptp_adj->extd_local_circuit_id));
1737 tmp-=sizeof(tlv_ptp_adj->extd_local_circuit_id);
1738 }
1739 if(tmp>=SYSTEM_ID_LEN) {
1740 if (!TTEST2(tlv_ptp_adj->neighbor_sysid, SYSTEM_ID_LEN))
1741 goto trunctlv;
1742 printf("\n\t Neighbor System-ID: %s",
1743 isis_print_id(tlv_ptp_adj->neighbor_sysid,SYSTEM_ID_LEN));
1744 tmp-=SYSTEM_ID_LEN;
1745 }
1746 if(tmp>=sizeof(tlv_ptp_adj->neighbor_extd_local_circuit_id)) {
1747 if (!TTEST2(tlv_ptp_adj->neighbor_extd_local_circuit_id,
1748 sizeof(tlv_ptp_adj->neighbor_extd_local_circuit_id)))
1749 goto trunctlv;
1750 printf("\n\t Neighbor Extended Local circuit-ID: 0x%08x",
1751 EXTRACT_32BITS(tlv_ptp_adj->neighbor_extd_local_circuit_id));
1752 }
1753 break;
1754
1755 case TLV_PROTOCOLS:
1756 printf("\n\t NLPID(s): ");
1757 while (tmp>0) {
1758 if (!TTEST2(*(tptr), 1))
1759 goto trunctlv;
1760 printf("%s (0x%02x)",
1761 tok2str(osi_nlpid_values,
1762 "unknown",
1763 *tptr),
1764 *tptr);
1765 if (tmp>1) /* further NPLIDs ? - put comma */
1766 printf(", ");
1767 tptr++;
1768 tmp--;
1769 }
1770 break;
1771
1772 case TLV_TE_ROUTER_ID:
1773 if (!TTEST2(*pptr, 4))
1774 goto trunctlv;
1775 printf("\n\t Traffic Engineering Router ID: %s", ipaddr_string(pptr));
1776 break;
1777
1778 case TLV_IPADDR:
1779 while (tmp>0) {
1780 if (!TTEST2(*tptr, 4))
1781 goto trunctlv;
1782 printf("\n\t IPv4 interface address: %s", ipaddr_string(tptr));
1783 tptr += 4;
1784 tmp -= 4;
1785 }
1786 break;
1787
1788 case TLV_HOSTNAME:
1789 printf("\n\t Hostname: ");
1790 while (tmp>0) {
1791 if (!TTEST2(*tptr, 1))
1792 goto trunctlv;
1793 printf("%c",*tptr++);
1794 tmp--;
1795 }
1796 break;
1797
1798 case TLV_SHARED_RISK_GROUP:
1799 if (!TTEST2(*tptr, NODE_ID_LEN))
1800 goto trunctlv;
1801 printf("\n\t IS Neighbor: %s", isis_print_id(tptr, NODE_ID_LEN));
1802 tptr+=(NODE_ID_LEN);
1803 tmp-=(NODE_ID_LEN);
1804
1805 if (!TTEST2(*tptr, 1))
1806 goto trunctlv;
1807 printf(", Flags: [%s]", ISIS_MASK_TLV_SHARED_RISK_GROUP(*tptr++) ? "numbered" : "unnumbered");
1808 tmp--;
1809
1810 if (!TTEST2(*tptr,4))
1811 goto trunctlv;
1812 printf("\n\t IPv4 interface address: %s", ipaddr_string(tptr));
1813 tptr+=4;
1814 tmp-=4;
1815
1816 if (!TTEST2(*tptr,4))
1817 goto trunctlv;
1818 printf("\n\t IPv4 neighbor address: %s", ipaddr_string(tptr));
1819 tptr+=4;
1820 tmp-=4;
1821
1822 while (tmp>0) {
1823 if (!TTEST2(*tptr, 4))
1824 goto trunctlv;
1825 printf("\n\t Link-ID: 0x%08x", EXTRACT_32BITS(tptr));
1826 tptr+=4;
1827 tmp-=4;
1828 }
1829 break;
1830
1831 case TLV_LSP:
1832 tlv_lsp = (const struct isis_tlv_lsp *)tptr;
1833 while(tmp>0) {
1834 if (!TTEST((tlv_lsp->lsp_id)[LSP_ID_LEN]))
1835 goto trunctlv;
1836 printf("\n\t lsp-id: %s",
1837 isis_print_id(tlv_lsp->lsp_id, LSP_ID_LEN));
1838 if (!TTEST2(tlv_lsp->sequence_number, 4))
1839 goto trunctlv;
1840 printf(", seq: 0x%08x",EXTRACT_32BITS(tlv_lsp->sequence_number));
1841 if (!TTEST2(tlv_lsp->remaining_lifetime, 2))
1842 goto trunctlv;
1843 printf(", lifetime: %5ds",EXTRACT_16BITS(tlv_lsp->remaining_lifetime));
1844 if (!TTEST2(tlv_lsp->checksum, 2))
1845 goto trunctlv;
1846 printf(", chksum: 0x%04x",EXTRACT_16BITS(tlv_lsp->checksum));
1847 tmp-=sizeof(struct isis_tlv_lsp);
1848 tlv_lsp++;
1849 }
1850 break;
1851
1852 case TLV_CHECKSUM:
1853 if (!TTEST2(*tptr, 2))
1854 goto trunctlv;
1855 printf("\n\t checksum: 0x%04x ", EXTRACT_16BITS(tptr));
1856 /* do not attempt to verify the checksum if it is zero
1857 * most likely a HMAC-MD5 TLV is also present and
1858 * to avoid conflicts the checksum TLV is zeroed.
1859 * see rfc3358 for details
1860 */
1861 if (EXTRACT_16BITS(tptr) == 0)
1862 printf("(unverified)");
1863 else printf("(%s)", osi_cksum(optr, length) ? "incorrect" : "correct");
1864 break;
1865
1866 case TLV_MT_SUPPORTED:
1867 while (tmp>1) {
1868 /* length can only be a multiple of 2, otherwise there is
1869 something broken -> so decode down until length is 1 */
1870 if (tmp!=1) {
1871 mt_len = isis_print_mtid(tptr, "\n\t ");
1872 if (mt_len == 0) /* did something go wrong ? */
1873 goto trunctlv;
1874 tptr+=mt_len;
1875 tmp-=mt_len;
1876 } else {
1877 printf("\n\t malformed MT-ID");
1878 break;
1879 }
1880 }
1881 break;
1882
1883 case TLV_RESTART_SIGNALING:
1884 if (!TTEST2(*tptr, 3))
1885 goto trunctlv;
1886 printf("\n\t Flags [%s], Remaining holding time %us",
1887 bittok2str(isis_restart_flag_values, "none", *tptr),
1888 EXTRACT_16BITS(tptr+1));
1889 tptr+=3;
1890 break;
1891
1892 case TLV_IDRP_INFO:
1893 if (!TTEST2(*tptr, 1))
1894 goto trunctlv;
1895 printf("\n\t Inter-Domain Information Type: %s",
1896 tok2str(isis_subtlv_idrp_values,
1897 "Unknown (0x%02x)",
1898 *tptr));
1899 switch (*tptr++) {
1900 case SUBTLV_IDRP_ASN:
1901 if (!TTEST2(*tptr, 2)) /* fetch AS number */
1902 goto trunctlv;
1903 printf("AS Number: %u",EXTRACT_16BITS(tptr));
1904 break;
1905 case SUBTLV_IDRP_LOCAL:
1906 case SUBTLV_IDRP_RES:
1907 default:
1908 if(!print_unknown_data(tptr,"\n\t ",tlv_len-1))
1909 return(0);
1910 break;
1911 }
1912 break;
1913
1914 case TLV_LSP_BUFFERSIZE:
1915 if (!TTEST2(*tptr, 2))
1916 goto trunctlv;
1917 printf("\n\t LSP Buffersize: %u",EXTRACT_16BITS(tptr));
1918 break;
1919
1920 case TLV_PART_DIS:
1921 while (tmp >= SYSTEM_ID_LEN) {
1922 if (!TTEST2(*tptr, SYSTEM_ID_LEN))
1923 goto trunctlv;
1924 printf("\n\t %s",isis_print_id(tptr,SYSTEM_ID_LEN));
1925 tptr+=SYSTEM_ID_LEN;
1926 tmp-=SYSTEM_ID_LEN;
1927 }
1928 break;
1929
1930 case TLV_PREFIX_NEIGH:
1931 if (!TTEST2(*tptr, sizeof(struct isis_metric_block)))
1932 goto trunctlv;
1933 printf("\n\t Metric Block");
1934 isis_print_metric_block((const struct isis_metric_block *)tptr);
1935 tptr+=sizeof(struct isis_metric_block);
1936 tmp-=sizeof(struct isis_metric_block);
1937
1938 while(tmp>0) {
1939 if (!TTEST2(*tptr, 1))
1940 goto trunctlv;
1941 prefix_len=*tptr++; /* read out prefix length in semioctets*/
1942 tmp--;
1943 if (!TTEST2(*tptr, prefix_len/2))
1944 goto trunctlv;
1945 printf("\n\t\tAddress: %s/%u",
1946 print_nsap(tptr,prefix_len/2),
1947 prefix_len*4);
1948 tptr+=prefix_len/2;
1949 tmp-=prefix_len/2;
1950 }
1951 break;
1952
1953 case TLV_IIH_SEQNR:
1954 if (!TTEST2(*tptr, 4)) /* check if four bytes are on the wire */
1955 goto trunctlv;
1956 printf("\n\t Sequence number: %u", EXTRACT_32BITS(tptr) );
1957 break;
1958
1959 case TLV_VENDOR_PRIVATE:
1960 if (!TTEST2(*tptr, 3)) /* check if enough byte for a full oui */
1961 goto trunctlv;
1962 printf("\n\t Vendor OUI Code: 0x%06x", EXTRACT_24BITS(tptr) );
1963 tptr+=3;
1964 tmp-=3;
1965 if (tmp > 0) /* hexdump the rest */
1966 if(!print_unknown_data(tptr,"\n\t\t",tmp))
1967 return(0);
1968 break;
1969 /*
1970 * FIXME those are the defined TLVs that lack a decoder
1971 * you are welcome to contribute code ;-)
1972 */
1973
1974 case TLV_DECNET_PHASE4:
1975 case TLV_LUCENT_PRIVATE:
1976 case TLV_IPAUTH:
1977 case TLV_NORTEL_PRIVATE1:
1978 case TLV_NORTEL_PRIVATE2:
1979
1980 default:
1981 if (vflag <= 1) {
1982 if(!print_unknown_data(pptr,"\n\t\t",tlv_len))
1983 return(0);
1984 }
1985 break;
1986 }
1987 /* do we want to see an additionally hexdump ? */
1988 if (vflag> 1) {
1989 if(!print_unknown_data(pptr,"\n\t ",tlv_len))
1990 return(0);
1991 }
1992
1993 pptr += tlv_len;
1994 packet_len -= tlv_len;
1995 }
1996
1997 if (packet_len != 0) {
1998 printf("\n\t %u straggler bytes", packet_len);
1999 }
2000 return (1);
2001
2002 trunc:
2003 fputs("[|isis]", stdout);
2004 return (1);
2005
2006 trunctlv:
2007 printf("\n\t\t packet exceeded snapshot");
2008 return(1);
2009 }
2010
2011 /*
2012 * Verify the checksum. See 8473-1, Appendix C, section C.4.
2013 */
2014
2015 static int
2016 osi_cksum(const u_int8_t *tptr, u_int len)
2017 {
2018 int32_t c0 = 0, c1 = 0;
2019
2020 while ((int)--len >= 0) {
2021 c0 += *tptr++;
2022 c0 %= 255;
2023 c1 += c0;
2024 c1 %= 255;
2025 }
2026 return (c0 | c1);
2027 }