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