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