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