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