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