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