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