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