]> The Tcpdump Group git mirrors - tcpdump/blob - print-isoclns.c
eca58d34a6a2ecb774ba411533b56e45f37568dd
[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.127 2005-03-07 14:36:16 hannes Exp $ (LBL)";
30 #endif
31
32 #ifdef HAVE_CONFIG_H
33 #include "config.h"
34 #endif
35
36 #include <tcpdump-stdinc.h>
37
38 #include <stdio.h>
39 #include <string.h>
40
41 #include "interface.h"
42 #include "addrtoname.h"
43 #include "ethertype.h"
44 #include "ether.h"
45 #include "nlpid.h"
46 #include "extract.h"
47 #include "gmpls.h"
48 #include "oui.h"
49
50 #define IPV4 1 /* AFI value */
51 #define IPV6 2 /* AFI value */
52
53 /*
54 * IS-IS is defined in ISO 10589. Look there for protocol definitions.
55 */
56
57 #define SYSTEM_ID_LEN ETHER_ADDR_LEN
58 #define NODE_ID_LEN SYSTEM_ID_LEN+1
59 #define LSP_ID_LEN SYSTEM_ID_LEN+2
60 #define NSAP_MAX_LENGTH 20
61
62 #define ISIS_VERSION 1
63 #define ESIS_VERSION 1
64 #define CLNP_VERSION 1
65
66 #define ISIS_PDU_TYPE_MASK 0x1F
67 #define ESIS_PDU_TYPE_MASK 0x1F
68 #define CLNP_PDU_TYPE_MASK 0x1F
69 #define CLNP_FLAG_MASK 0xE0
70 #define ISIS_LAN_PRIORITY_MASK 0x7F
71
72 #define ISIS_PDU_L1_LAN_IIH 15
73 #define ISIS_PDU_L2_LAN_IIH 16
74 #define ISIS_PDU_PTP_IIH 17
75 #define ISIS_PDU_L1_LSP 18
76 #define ISIS_PDU_L2_LSP 20
77 #define ISIS_PDU_L1_CSNP 24
78 #define ISIS_PDU_L2_CSNP 25
79 #define ISIS_PDU_L1_PSNP 26
80 #define ISIS_PDU_L2_PSNP 27
81
82 static struct tok isis_pdu_values[] = {
83 { ISIS_PDU_L1_LAN_IIH, "L1 Lan IIH"},
84 { ISIS_PDU_L2_LAN_IIH, "L2 Lan IIH"},
85 { ISIS_PDU_PTP_IIH, "p2p IIH"},
86 { ISIS_PDU_L1_LSP, "L1 LSP"},
87 { ISIS_PDU_L2_LSP, "L2 LSP"},
88 { ISIS_PDU_L1_CSNP, "L1 CSNP"},
89 { ISIS_PDU_L2_CSNP, "L2 CSNP"},
90 { ISIS_PDU_L1_PSNP, "L1 PSNP"},
91 { ISIS_PDU_L2_PSNP, "L2 PSNP"},
92 { 0, NULL}
93 };
94
95 /*
96 * A TLV is a tuple of a type, length and a value and is normally used for
97 * encoding information in all sorts of places. This is an enumeration of
98 * the well known types.
99 *
100 * list taken from rfc3359 plus some memory from veterans ;-)
101 */
102
103 #define ISIS_TLV_AREA_ADDR 1 /* iso10589 */
104 #define ISIS_TLV_IS_REACH 2 /* iso10589 */
105 #define ISIS_TLV_ESNEIGH 3 /* iso10589 */
106 #define ISIS_TLV_PART_DIS 4 /* iso10589 */
107 #define ISIS_TLV_PREFIX_NEIGH 5 /* iso10589 */
108 #define ISIS_TLV_ISNEIGH 6 /* iso10589 */
109 #define ISIS_TLV_ISNEIGH_VARLEN 7 /* iso10589 */
110 #define ISIS_TLV_PADDING 8 /* iso10589 */
111 #define ISIS_TLV_LSP 9 /* iso10589 */
112 #define ISIS_TLV_AUTH 10 /* iso10589, rfc3567 */
113 #define ISIS_TLV_CHECKSUM 12 /* rfc3358 */
114 #define ISIS_TLV_LSP_BUFFERSIZE 14 /* iso10589 rev2 */
115 #define ISIS_TLV_EXT_IS_REACH 22 /* draft-ietf-isis-traffic-05 */
116 #define ISIS_TLV_IS_ALIAS_ID 24 /* draft-ietf-isis-ext-lsp-frags-02 */
117 #define ISIS_TLV_DECNET_PHASE4 42
118 #define ISIS_TLV_LUCENT_PRIVATE 66
119 #define ISIS_TLV_INT_IP_REACH 128 /* rfc1195, rfc2966 */
120 #define ISIS_TLV_PROTOCOLS 129 /* rfc1195 */
121 #define ISIS_TLV_EXT_IP_REACH 130 /* rfc1195, rfc2966 */
122 #define ISIS_TLV_IDRP_INFO 131 /* rfc1195 */
123 #define ISIS_TLV_IPADDR 132 /* rfc1195 */
124 #define ISIS_TLV_IPAUTH 133 /* rfc1195 */
125 #define ISIS_TLV_TE_ROUTER_ID 134 /* draft-ietf-isis-traffic-05 */
126 #define ISIS_TLV_EXTD_IP_REACH 135 /* draft-ietf-isis-traffic-05 */
127 #define ISIS_TLV_HOSTNAME 137 /* rfc2763 */
128 #define ISIS_TLV_SHARED_RISK_GROUP 138 /* draft-ietf-isis-gmpls-extensions */
129 #define ISIS_TLV_NORTEL_PRIVATE1 176
130 #define ISIS_TLV_NORTEL_PRIVATE2 177
131 #define ISIS_TLV_RESTART_SIGNALING 211 /* draft-ietf-isis-restart-01 */
132 #define ISIS_TLV_MT_IS_REACH 222 /* draft-ietf-isis-wg-multi-topology-05 */
133 #define ISIS_TLV_MT_SUPPORTED 229 /* draft-ietf-isis-wg-multi-topology-05 */
134 #define ISIS_TLV_IP6ADDR 232 /* draft-ietf-isis-ipv6-02 */
135 #define ISIS_TLV_MT_IP_REACH 235 /* draft-ietf-isis-wg-multi-topology-05 */
136 #define ISIS_TLV_IP6_REACH 236 /* draft-ietf-isis-ipv6-02 */
137 #define ISIS_TLV_MT_IP6_REACH 237 /* draft-ietf-isis-wg-multi-topology-05 */
138 #define ISIS_TLV_PTP_ADJ 240 /* rfc3373 */
139 #define ISIS_TLV_IIH_SEQNR 241 /* draft-shen-isis-iih-sequence-00 */
140 #define ISIS_TLV_VENDOR_PRIVATE 250 /* draft-ietf-isis-experimental-tlv-01 */
141
142 static struct tok isis_tlv_values[] = {
143 { ISIS_TLV_AREA_ADDR, "Area address(es)"},
144 { ISIS_TLV_IS_REACH, "IS Reachability"},
145 { ISIS_TLV_ESNEIGH, "ES Neighbor(s)"},
146 { ISIS_TLV_PART_DIS, "Partition DIS"},
147 { ISIS_TLV_PREFIX_NEIGH, "Prefix Neighbors"},
148 { ISIS_TLV_ISNEIGH, "IS Neighbor(s)"},
149 { ISIS_TLV_ISNEIGH_VARLEN, "IS Neighbor(s) (variable length)"},
150 { ISIS_TLV_PADDING, "Padding"},
151 { ISIS_TLV_LSP, "LSP entries"},
152 { ISIS_TLV_AUTH, "Authentication"},
153 { ISIS_TLV_CHECKSUM, "Checksum"},
154 { ISIS_TLV_LSP_BUFFERSIZE, "LSP Buffersize"},
155 { ISIS_TLV_EXT_IS_REACH, "Extended IS Reachability"},
156 { ISIS_TLV_IS_ALIAS_ID, "IS Alias ID"},
157 { ISIS_TLV_DECNET_PHASE4, "DECnet Phase IV"},
158 { ISIS_TLV_LUCENT_PRIVATE, "Lucent Proprietary"},
159 { ISIS_TLV_INT_IP_REACH, "IPv4 Internal Reachability"},
160 { ISIS_TLV_PROTOCOLS, "Protocols supported"},
161 { ISIS_TLV_EXT_IP_REACH, "IPv4 External Reachability"},
162 { ISIS_TLV_IDRP_INFO, "Inter-Domain Information Type"},
163 { ISIS_TLV_IPADDR, "IPv4 Interface address(es)"},
164 { ISIS_TLV_IPAUTH, "IPv4 authentication (deprecated)"},
165 { ISIS_TLV_TE_ROUTER_ID, "Traffic Engineering Router ID"},
166 { ISIS_TLV_EXTD_IP_REACH, "Extended IPv4 Reachability"},
167 { ISIS_TLV_SHARED_RISK_GROUP, "Shared Risk Link Group"},
168 { ISIS_TLV_NORTEL_PRIVATE1, "Nortel Proprietary"},
169 { ISIS_TLV_NORTEL_PRIVATE2, "Nortel Proprietary"},
170 { ISIS_TLV_HOSTNAME, "Hostname"},
171 { ISIS_TLV_RESTART_SIGNALING, "Restart Signaling"},
172 { ISIS_TLV_MT_IS_REACH, "Multi Topology IS Reachability"},
173 { ISIS_TLV_MT_SUPPORTED, "Multi Topology"},
174 { ISIS_TLV_IP6ADDR, "IPv6 Interface address(es)"},
175 { ISIS_TLV_MT_IP_REACH, "Multi-Topology IPv4 Reachability"},
176 { ISIS_TLV_IP6_REACH, "IPv6 reachability"},
177 { ISIS_TLV_MT_IP6_REACH, "Multi-Topology IP6 Reachability"},
178 { ISIS_TLV_PTP_ADJ, "Point-to-point Adjacency State"},
179 { ISIS_TLV_IIH_SEQNR, "Hello PDU Sequence Number"},
180 { ISIS_TLV_VENDOR_PRIVATE, "Vendor Private"},
181 { 0, NULL }
182 };
183
184 #define ESIS_OPTION_PROTOCOLS 129
185 #define ESIS_OPTION_QOS_MAINTENANCE 195 /* iso9542 */
186 #define ESIS_OPTION_SECURITY 197 /* iso9542 */
187 #define ESIS_OPTION_ES_CONF_TIME 198 /* iso9542 */
188 #define ESIS_OPTION_PRIORITY 205 /* iso9542 */
189 #define ESIS_OPTION_ADDRESS_MASK 225 /* iso9542 */
190 #define ESIS_OPTION_SNPA_MASK 226 /* iso9542 */
191
192 static struct tok esis_option_values[] = {
193 { ESIS_OPTION_PROTOCOLS, "Protocols supported"},
194 { ESIS_OPTION_QOS_MAINTENANCE, "QoS Maintenance" },
195 { ESIS_OPTION_SECURITY, "Security" },
196 { ESIS_OPTION_ES_CONF_TIME, "ES Configuration Time" },
197 { ESIS_OPTION_PRIORITY, "Priority" },
198 { ESIS_OPTION_ADDRESS_MASK, "Addressk Mask" },
199 { ESIS_OPTION_SNPA_MASK, "SNPA Mask" },
200 { 0, NULL }
201 };
202
203 #define CLNP_OPTION_DISCARD_REASON 193
204 #define CLNP_OPTION_QOS_MAINTENANCE 195 /* iso8473 */
205 #define CLNP_OPTION_PRIORITY 205 /* iso8473 */
206
207 static struct tok clnp_option_values[] = {
208 { CLNP_OPTION_DISCARD_REASON, "Discard Reason"},
209 { CLNP_OPTION_PRIORITY, "Priority"},
210 { CLNP_OPTION_QOS_MAINTENANCE, "QoS Maintenance"},
211 { 0, NULL }
212 };
213
214 #define ISIS_SUBTLV_EXT_IS_REACH_ADMIN_GROUP 3 /* draft-ietf-isis-traffic-05 */
215 #define ISIS_SUBTLV_EXT_IS_REACH_LINK_LOCAL_REMOTE_ID 4 /* draft-ietf-isis-gmpls-extensions */
216 #define ISIS_SUBTLV_EXT_IS_REACH_LINK_REMOTE_ID 5 /* draft-ietf-isis-traffic-05 */
217 #define ISIS_SUBTLV_EXT_IS_REACH_IPV4_INTF_ADDR 6 /* draft-ietf-isis-traffic-05 */
218 #define ISIS_SUBTLV_EXT_IS_REACH_IPV4_NEIGHBOR_ADDR 8 /* draft-ietf-isis-traffic-05 */
219 #define ISIS_SUBTLV_EXT_IS_REACH_MAX_LINK_BW 9 /* draft-ietf-isis-traffic-05 */
220 #define ISIS_SUBTLV_EXT_IS_REACH_RESERVABLE_BW 10 /* draft-ietf-isis-traffic-05 */
221 #define ISIS_SUBTLV_EXT_IS_REACH_UNRESERVED_BW 11 /* draft-ietf-isis-traffic-05 */
222 #define ISIS_SUBTLV_EXT_IS_REACH_DIFFSERV_TE 12 /* draft-ietf-tewg-diff-te-proto-06 */
223 #define ISIS_SUBTLV_EXT_IS_REACH_TE_METRIC 18 /* draft-ietf-isis-traffic-05 */
224 #define ISIS_SUBTLV_EXT_IS_REACH_LINK_PROTECTION_TYPE 20 /* draft-ietf-isis-gmpls-extensions */
225 #define ISIS_SUBTLV_EXT_IS_REACH_INTF_SW_CAP_DESCR 21 /* draft-ietf-isis-gmpls-extensions */
226
227 static struct tok isis_ext_is_reach_subtlv_values[] = {
228 { ISIS_SUBTLV_EXT_IS_REACH_ADMIN_GROUP, "Administrative groups" },
229 { ISIS_SUBTLV_EXT_IS_REACH_LINK_LOCAL_REMOTE_ID, "Link Local/Remote Identifier" },
230 { ISIS_SUBTLV_EXT_IS_REACH_LINK_REMOTE_ID, "Link Remote Identifier" },
231 { ISIS_SUBTLV_EXT_IS_REACH_IPV4_INTF_ADDR, "IPv4 interface address" },
232 { ISIS_SUBTLV_EXT_IS_REACH_IPV4_NEIGHBOR_ADDR, "IPv4 neighbor address" },
233 { ISIS_SUBTLV_EXT_IS_REACH_MAX_LINK_BW, "Maximum link bandwidth" },
234 { ISIS_SUBTLV_EXT_IS_REACH_RESERVABLE_BW, "Reservable link bandwidth" },
235 { ISIS_SUBTLV_EXT_IS_REACH_UNRESERVED_BW, "Unreserved bandwidth" },
236 { ISIS_SUBTLV_EXT_IS_REACH_DIFFSERV_TE, "Diffserv TE" },
237 { ISIS_SUBTLV_EXT_IS_REACH_TE_METRIC, "Traffic Engineering Metric" },
238 { ISIS_SUBTLV_EXT_IS_REACH_LINK_PROTECTION_TYPE, "Link Protection Type" },
239 { ISIS_SUBTLV_EXT_IS_REACH_INTF_SW_CAP_DESCR, "Interface Switching Capability" },
240 { 250, "Reserved for cisco specific extensions" },
241 { 251, "Reserved for cisco specific extensions" },
242 { 252, "Reserved for cisco specific extensions" },
243 { 253, "Reserved for cisco specific extensions" },
244 { 254, "Reserved for cisco specific extensions" },
245 { 255, "Reserved for future expansion" },
246 { 0, NULL }
247 };
248
249 #define ISIS_SUBTLV_EXTD_IP_REACH_ADMIN_TAG32 1 /* draft-ietf-isis-admin-tags-01 */
250 #define ISIS_SUBTLV_EXTD_IP_REACH_ADMIN_TAG64 2 /* draft-ietf-isis-admin-tags-01 */
251 #define ISIS_SUBTLV_EXTD_IP_REACH_MGMT_PREFIX_COLOR 117 /* draft-ietf-isis-wg-multi-topology-05 */
252
253 static struct tok isis_ext_ip_reach_subtlv_values[] = {
254 { ISIS_SUBTLV_EXTD_IP_REACH_ADMIN_TAG32, "32-Bit Administrative tag" },
255 { ISIS_SUBTLV_EXTD_IP_REACH_ADMIN_TAG64, "64-Bit Administrative tag" },
256 { ISIS_SUBTLV_EXTD_IP_REACH_MGMT_PREFIX_COLOR, "Management Prefix Color" },
257 { 0, NULL }
258 };
259
260 #define ISIS_SUBTLV_AUTH_SIMPLE 1
261 #define ISIS_SUBTLV_AUTH_MD5 54
262 #define ISIS_SUBTLV_AUTH_MD5_LEN 16
263 #define ISIS_SUBTLV_AUTH_PRIVATE 255
264
265 static struct tok isis_subtlv_auth_values[] = {
266 { ISIS_SUBTLV_AUTH_SIMPLE, "simple text password"},
267 { ISIS_SUBTLV_AUTH_MD5, "HMAC-MD5 password"},
268 { ISIS_SUBTLV_AUTH_PRIVATE, "Routing Domain private password"},
269 { 0, NULL }
270 };
271
272 #define ISIS_SUBTLV_IDRP_RES 0
273 #define ISIS_SUBTLV_IDRP_LOCAL 1
274 #define ISIS_SUBTLV_IDRP_ASN 2
275
276 static struct tok isis_subtlv_idrp_values[] = {
277 { ISIS_SUBTLV_IDRP_RES, "Reserved"},
278 { ISIS_SUBTLV_IDRP_LOCAL, "Routing-Domain Specific"},
279 { ISIS_SUBTLV_IDRP_ASN, "AS Number Tag"},
280 { 0, NULL}
281 };
282
283 #define CLNP_SEGMENT_PART 0x80
284 #define CLNP_MORE_SEGMENTS 0x40
285 #define CLNP_REQUEST_ER 0x20
286
287 static struct tok clnp_flag_values[] = {
288 { CLNP_SEGMENT_PART, "Segmentation permitted"},
289 { CLNP_MORE_SEGMENTS, "more Segments"},
290 { CLNP_REQUEST_ER, "request Error Report"},
291 { 0, NULL}
292 };
293
294 #define ISIS_MASK_LSP_OL_BIT(x) ((x)&0x4)
295 #define ISIS_MASK_LSP_ISTYPE_BITS(x) ((x)&0x3)
296 #define ISIS_MASK_LSP_PARTITION_BIT(x) ((x)&0x80)
297 #define ISIS_MASK_LSP_ATT_BITS(x) ((x)&0x78)
298 #define ISIS_MASK_LSP_ATT_ERROR_BIT(x) ((x)&0x40)
299 #define ISIS_MASK_LSP_ATT_EXPENSE_BIT(x) ((x)&0x20)
300 #define ISIS_MASK_LSP_ATT_DELAY_BIT(x) ((x)&0x10)
301 #define ISIS_MASK_LSP_ATT_DEFAULT_BIT(x) ((x)&0x8)
302
303 #define ISIS_MASK_MTID(x) ((x)&0x0fff)
304 #define ISIS_MASK_MTFLAGS(x) ((x)&0xf000)
305
306 static struct tok isis_mt_flag_values[] = {
307 { 0x4000, "sub-TLVs present"},
308 { 0x8000, "ATT bit set"},
309 { 0, NULL}
310 };
311
312 #define ISIS_MASK_TLV_EXTD_IP_UPDOWN(x) ((x)&0x80)
313 #define ISIS_MASK_TLV_EXTD_IP_SUBTLV(x) ((x)&0x40)
314
315 #define ISIS_MASK_TLV_EXTD_IP6_IE(x) ((x)&0x40)
316 #define ISIS_MASK_TLV_EXTD_IP6_SUBTLV(x) ((x)&0x20)
317
318 #define ISIS_LSP_TLV_METRIC_SUPPORTED(x) ((x)&0x80)
319 #define ISIS_LSP_TLV_METRIC_IE(x) ((x)&0x40)
320 #define ISIS_LSP_TLV_METRIC_UPDOWN(x) ((x)&0x80)
321 #define ISIS_LSP_TLV_METRIC_VALUE(x) ((x)&0x3f)
322
323 #define ISIS_MASK_TLV_SHARED_RISK_GROUP(x) ((x)&0x1)
324
325 static struct tok isis_mt_values[] = {
326 { 0, "IPv4 unicast"},
327 { 1, "In-Band Management"},
328 { 2, "IPv6 unicast"},
329 { 3, "Multicast"},
330 { 4095, "Development, Experimental or Proprietary"},
331 { 0, NULL }
332 };
333
334 static struct tok isis_iih_circuit_type_values[] = {
335 { 1, "Level 1 only"},
336 { 2, "Level 2 only"},
337 { 3, "Level 1, Level 2"},
338 { 0, NULL}
339 };
340
341 #define ISIS_LSP_TYPE_UNUSED0 0
342 #define ISIS_LSP_TYPE_LEVEL_1 1
343 #define ISIS_LSP_TYPE_UNUSED2 2
344 #define ISIS_LSP_TYPE_LEVEL_2 3
345
346 static struct tok isis_lsp_istype_values[] = {
347 { ISIS_LSP_TYPE_UNUSED0, "Unused 0x0 (invalid)"},
348 { ISIS_LSP_TYPE_LEVEL_1, "L1 IS"},
349 { ISIS_LSP_TYPE_UNUSED2, "Unused 0x2 (invalid)"},
350 { ISIS_LSP_TYPE_LEVEL_2, "L1L2 IS"},
351 { 0, NULL }
352 };
353
354 /*
355 * Katz's point to point adjacency TLV uses codes to tell us the state of
356 * the remote adjacency. Enumerate them.
357 */
358
359 #define ISIS_PTP_ADJ_UP 0
360 #define ISIS_PTP_ADJ_INIT 1
361 #define ISIS_PTP_ADJ_DOWN 2
362
363 static struct tok isis_ptp_adjancey_values[] = {
364 { ISIS_PTP_ADJ_UP, "Up" },
365 { ISIS_PTP_ADJ_INIT, "Initializing" },
366 { ISIS_PTP_ADJ_DOWN, "Down" },
367 { 0, NULL}
368 };
369
370 struct isis_tlv_ptp_adj {
371 u_int8_t adjacency_state;
372 u_int8_t extd_local_circuit_id[4];
373 u_int8_t neighbor_sysid[SYSTEM_ID_LEN];
374 u_int8_t neighbor_extd_local_circuit_id[4];
375 };
376
377 static int osi_cksum(const u_int8_t *, u_int);
378 static int clnp_print(const u_int8_t *, u_int);
379 static void esis_print(const u_int8_t *, u_int);
380 static int isis_print(const u_int8_t *, u_int);
381
382 struct isis_metric_block {
383 u_int8_t metric_default;
384 u_int8_t metric_delay;
385 u_int8_t metric_expense;
386 u_int8_t metric_error;
387 };
388
389 struct isis_tlv_is_reach {
390 struct isis_metric_block isis_metric_block;
391 u_int8_t neighbor_nodeid[NODE_ID_LEN];
392 };
393
394 struct isis_tlv_es_reach {
395 struct isis_metric_block isis_metric_block;
396 u_int8_t neighbor_sysid[SYSTEM_ID_LEN];
397 };
398
399 struct isis_tlv_ip_reach {
400 struct isis_metric_block isis_metric_block;
401 u_int8_t prefix[4];
402 u_int8_t mask[4];
403 };
404
405 static struct tok isis_is_reach_virtual_values[] = {
406 { 0, "IsNotVirtual"},
407 { 1, "IsVirtual"},
408 { 0, NULL }
409 };
410
411 static struct tok isis_restart_flag_values[] = {
412 { 0x1, "Restart Request"},
413 { 0x2, "Restart Acknowledgement"},
414 { 0, NULL }
415 };
416
417 struct isis_common_header {
418 u_int8_t nlpid;
419 u_int8_t fixed_len;
420 u_int8_t version; /* Protocol version */
421 u_int8_t id_length;
422 u_int8_t pdu_type; /* 3 MSbits are reserved */
423 u_int8_t pdu_version; /* Packet format version */
424 u_int8_t reserved;
425 u_int8_t max_area;
426 };
427
428 struct isis_iih_lan_header {
429 u_int8_t circuit_type;
430 u_int8_t source_id[SYSTEM_ID_LEN];
431 u_int8_t holding_time[2];
432 u_int8_t pdu_len[2];
433 u_int8_t priority;
434 u_int8_t lan_id[NODE_ID_LEN];
435 };
436
437 struct isis_iih_ptp_header {
438 u_int8_t circuit_type;
439 u_int8_t source_id[SYSTEM_ID_LEN];
440 u_int8_t holding_time[2];
441 u_int8_t pdu_len[2];
442 u_int8_t circuit_id;
443 };
444
445 struct isis_lsp_header {
446 u_int8_t pdu_len[2];
447 u_int8_t remaining_lifetime[2];
448 u_int8_t lsp_id[LSP_ID_LEN];
449 u_int8_t sequence_number[4];
450 u_int8_t checksum[2];
451 u_int8_t typeblock;
452 };
453
454 struct isis_csnp_header {
455 u_int8_t pdu_len[2];
456 u_int8_t source_id[NODE_ID_LEN];
457 u_int8_t start_lsp_id[LSP_ID_LEN];
458 u_int8_t end_lsp_id[LSP_ID_LEN];
459 };
460
461 struct isis_psnp_header {
462 u_int8_t pdu_len[2];
463 u_int8_t source_id[NODE_ID_LEN];
464 };
465
466 struct isis_tlv_lsp {
467 u_int8_t remaining_lifetime[2];
468 u_int8_t lsp_id[LSP_ID_LEN];
469 u_int8_t sequence_number[4];
470 u_int8_t checksum[2];
471 };
472
473 static char *
474 print_nsap(register const u_int8_t *pptr, register int nsap_length)
475 {
476 int nsap_idx;
477 static char nsap_ascii_output[sizeof("xx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xx")];
478 char *junk_buf = nsap_ascii_output;
479
480 if (nsap_length < 1 || nsap_length > NSAP_MAX_LENGTH) {
481 snprintf(nsap_ascii_output, sizeof(nsap_ascii_output),
482 "illegal length");
483 return (nsap_ascii_output);
484 }
485
486 for (nsap_idx = 0; nsap_idx < nsap_length; nsap_idx++) {
487 if (!TTEST2(*pptr, 1))
488 return (0);
489 snprintf(junk_buf,
490 sizeof(nsap_ascii_output) - (junk_buf - nsap_ascii_output),
491 "%02x", *pptr++);
492 junk_buf += strlen(junk_buf);
493 if (((nsap_idx & 1) == 0) &&
494 (nsap_idx + 1 < nsap_length)) {
495 *junk_buf++ = '.';
496 }
497 }
498 *(junk_buf) = '\0';
499 return (nsap_ascii_output);
500 }
501
502 #define ISIS_COMMON_HEADER_SIZE (sizeof(struct isis_common_header))
503 #define ISIS_IIH_LAN_HEADER_SIZE (sizeof(struct isis_iih_lan_header))
504 #define ISIS_IIH_PTP_HEADER_SIZE (sizeof(struct isis_iih_ptp_header))
505 #define ISIS_LSP_HEADER_SIZE (sizeof(struct isis_lsp_header))
506 #define ISIS_CSNP_HEADER_SIZE (sizeof(struct isis_csnp_header))
507 #define ISIS_PSNP_HEADER_SIZE (sizeof(struct isis_psnp_header))
508
509 void isoclns_print(const u_int8_t *p, u_int length, u_int caplen)
510 {
511 const struct isis_common_header *header;
512
513 header = (const struct isis_common_header *)p;
514
515 if (caplen <= 1) { /* enough bytes on the wire ? */
516 printf("|OSI");
517 return;
518 }
519
520 if (eflag)
521 printf("OSI NLPID %s (0x%02x): ",
522 tok2str(nlpid_values,"Unknown",*p),
523 *p);
524
525 switch (*p) {
526
527 case NLPID_CLNP:
528 if (!clnp_print(p, length))
529 print_unknown_data(p,"\n\t",caplen);
530 break;
531
532 case NLPID_ESIS:
533 esis_print(p, length);
534 return;
535
536 case NLPID_ISIS:
537 if (!isis_print(p, length))
538 print_unknown_data(p,"\n\t",caplen);
539 break;
540
541 case NLPID_NULLNS:
542 (void)printf(", length: %u", length);
543 break;
544
545 case NLPID_Q933:
546 q933_print(p+1, length-1);
547 break;
548
549 case NLPID_IP:
550 ip_print(p+1, length-1);
551 break;
552
553 #ifdef INET6
554 case NLPID_IP6:
555 ip6_print(p+1, length-1);
556 break;
557 #endif
558
559 case NLPID_PPP:
560 ppp_print(p+1, length-1);
561 break;
562
563 default:
564 if (!eflag)
565 printf("OSI NLPID 0x%02x unknown",*p);
566 (void)printf(", length: %u", length);
567 if (caplen > 1)
568 print_unknown_data(p,"\n\t",caplen);
569 break;
570 }
571 }
572
573 #define CLNP_PDU_ER 1
574 #define CLNP_PDU_DT 28
575 #define CLNP_PDU_MD 29
576 #define CLNP_PDU_ERQ 30
577 #define CLNP_PDU_ERP 31
578
579 static struct tok clnp_pdu_values[] = {
580 { CLNP_PDU_ER, "Error Report"},
581 { CLNP_PDU_MD, "MD"},
582 { CLNP_PDU_DT, "Data"},
583 { CLNP_PDU_ERQ, "Echo Request"},
584 { CLNP_PDU_ERP, "Echo Response"},
585 { 0, NULL }
586 };
587
588 struct clnp_header_t {
589 u_int8_t nlpid;
590 u_int8_t length_indicator;
591 u_int8_t version;
592 u_int8_t lifetime; /* units of 500ms */
593 u_int8_t type;
594 u_int8_t segment_length[2];
595 u_int8_t cksum[2];
596 };
597
598 struct clnp_segment_header_t {
599 u_int8_t data_unit_id[2];
600 u_int8_t segment_offset[2];
601 u_int8_t total_length[2];
602 };
603
604 /*
605 * clnp_print
606 * Decode CLNP packets. Return 0 on error.
607 */
608
609 static int clnp_print (const u_int8_t *pptr, u_int length)
610 {
611 const u_int8_t *optr,*source_address,*dest_address;
612 u_int li,source_address_length,dest_address_length, clnp_pdu_type, clnp_flags;
613 const struct clnp_header_t *clnp_header;
614 const struct clnp_segment_header_t *clnp_segment_header;
615
616 clnp_header = (const struct clnp_header_t *) pptr;
617 TCHECK(*clnp_header);
618
619 li = clnp_header->length_indicator;
620 optr = pptr;
621
622 if (!eflag)
623 printf("CLNP");
624
625 /*
626 * Sanity checking of the header.
627 */
628
629 if (clnp_header->version != CLNP_VERSION) {
630 printf("version %d packet not supported", clnp_header->version);
631 return (0);
632 }
633
634 /* FIXME further header sanity checking */
635
636 clnp_pdu_type = clnp_header->type & CLNP_PDU_TYPE_MASK;
637 clnp_flags = clnp_header->type & CLNP_FLAG_MASK;
638
639 pptr += sizeof(struct clnp_header_t);
640 li -= sizeof(struct clnp_header_t);
641 dest_address_length = *pptr;
642 dest_address = pptr + 1;
643
644 pptr += (1 + dest_address_length);
645 li -= (1 + dest_address_length);
646 source_address_length = *pptr;
647 source_address = pptr +1;
648
649 pptr += (1 + source_address_length);
650 li -= (1 + source_address_length);
651
652 if (vflag < 1) {
653 printf("%s%s",
654 eflag ? "" : ", ",
655 print_nsap(source_address, source_address_length));
656 printf("> %s, length %u",
657 print_nsap(dest_address, dest_address_length),
658 length);
659 return (1);
660 }
661 printf("%slength %u",eflag ? "" : ", ",length);
662
663 printf("\n\t%s PDU, hlen: %u, v: %u, lifetime: %u.%us, Segment PDU length: %u, checksum: 0x%04x ",
664 tok2str(clnp_pdu_values,
665 "unknown (%u)",
666 clnp_pdu_type),
667 clnp_header->length_indicator,
668 clnp_header->version,
669 clnp_header->lifetime/2,
670 (clnp_header->lifetime%2)*5,
671 EXTRACT_16BITS(clnp_header->segment_length),
672 EXTRACT_16BITS(clnp_header->cksum));
673
674 /* do not attempt to verify the checksum if it is zero */
675 if (EXTRACT_16BITS(clnp_header->cksum) == 0)
676 printf("(unverified)");
677 else printf("(%s)", osi_cksum(optr, li) ? "incorrect" : "correct");
678
679 printf("\n\tFlags [%s]",
680 bittok2str(clnp_flag_values,"none",clnp_flags));
681
682 printf("\n\tsource address (length %u): %s",
683 source_address_length,
684 print_nsap(source_address, source_address_length));
685 printf("\n\tdest address (length %u): %s",
686 dest_address_length,
687 print_nsap(dest_address, dest_address_length));
688
689 if (clnp_flags & CLNP_SEGMENT_PART) {
690 clnp_segment_header = (const struct clnp_segment_header_t *) pptr;
691 printf("\n\tData Unit ID: 0x%04x, Segment Offset: %u, Total PDU Length: %u",
692 EXTRACT_16BITS(clnp_segment_header->data_unit_id),
693 EXTRACT_16BITS(clnp_segment_header->segment_offset),
694 EXTRACT_16BITS(clnp_segment_header->total_length));
695 pptr+=sizeof(const struct clnp_segment_header_t);
696 li-=sizeof(const struct clnp_segment_header_t);
697 }
698
699 /* now walk the options */
700 while (li >= 2) {
701 u_int op, opli;
702 const u_int8_t *tptr;
703
704 if (snapend - pptr < 2)
705 return (0);
706 if (li < 2) {
707 printf(", bad opts/li");
708 return (0);
709 }
710 op = *pptr++;
711 opli = *pptr++;
712 li -= 2;
713 if (opli > li) {
714 printf(", opt (%d) too long", op);
715 return (0);
716 }
717 li -= opli;
718 tptr = pptr;
719
720 if (snapend < pptr)
721 return(0);
722
723 printf("\n\t %s Option #%u, length %u, value: ",
724 tok2str(clnp_option_values,"Unknown",op),
725 op,
726 opli);
727
728 switch (op) {
729
730 case CLNP_OPTION_PRIORITY:
731 printf("%u", *tptr);
732 break;
733
734 /*
735 * FIXME those are the defined Options that lack a decoder
736 * you are welcome to contribute code ;-)
737 */
738
739 case CLNP_OPTION_DISCARD_REASON:
740
741 default:
742 print_unknown_data(tptr,"\n\t ",opli);
743 break;
744 }
745 if (vflag > 1)
746 print_unknown_data(pptr,"\n\t ",opli);
747 pptr += opli;
748 }
749
750 switch (clnp_pdu_type) {
751
752 case CLNP_PDU_ER:
753 case CLNP_PDU_DT:
754 case CLNP_PDU_MD:
755 case CLNP_PDU_ERQ:
756 case CLNP_PDU_ERP:
757
758 default:
759 /* dump the PDU specific data */
760 printf("\n\t undecoded non-header data");
761 print_unknown_data(optr+clnp_header->length_indicator,"\n\t ",length-clnp_header->length_indicator);
762
763 }
764
765 return (1);
766
767 trunc:
768 fputs("[|clnp]", stdout);
769 return (1);
770
771 }
772
773
774 #define ESIS_PDU_REDIRECT 6
775 #define ESIS_PDU_ESH 2
776 #define ESIS_PDU_ISH 4
777
778 static struct tok esis_pdu_values[] = {
779 { ESIS_PDU_REDIRECT, "redirect"},
780 { ESIS_PDU_ESH, "ESH"},
781 { ESIS_PDU_ISH, "ISH"},
782 { 0, NULL }
783 };
784
785 struct esis_header_t {
786 u_int8_t nlpid;
787 u_int8_t length_indicator;
788 u_int8_t version;
789 u_int8_t reserved;
790 u_int8_t type;
791 u_int8_t holdtime[2];
792 u_int8_t cksum[2];
793 };
794
795 static void
796 esis_print(const u_int8_t *pptr, u_int length)
797 {
798 const u_int8_t *optr;
799 u_int li,esis_pdu_type,source_address_length, source_address_number;
800 const struct esis_header_t *esis_header;
801
802 if (!eflag)
803 printf("ES-IS");
804
805 if (length <= 2) {
806 if (qflag)
807 printf("bad pkt!");
808 else
809 printf("no header at all!");
810 return;
811 }
812
813 esis_header = (const struct esis_header_t *) pptr;
814 li = esis_header->length_indicator;
815 optr = pptr;
816
817 /*
818 * Sanity checking of the header.
819 */
820
821 if (esis_header->nlpid != NLPID_ESIS) {
822 printf(" nlpid 0x%02x packet not supported", esis_header->nlpid);
823 return;
824 }
825
826 if (esis_header->version != ESIS_VERSION) {
827 printf(" version %d packet not supported", esis_header->version);
828 return;
829 }
830
831 if (li > length) {
832 printf(" length indicator(%d) > PDU size (%d)!", li, length);
833 return;
834 }
835
836 if (li < sizeof(struct esis_header_t) + 2) {
837 printf(" length indicator < min PDU size %d:", li);
838 while (--length != 0)
839 printf("%02X", *pptr++);
840 return;
841 }
842
843 esis_pdu_type = esis_header->type & ESIS_PDU_TYPE_MASK;
844
845 if (vflag < 1) {
846 printf("%s%s, length %u",
847 eflag ? "" : ", ",
848 tok2str(esis_pdu_values,"unknown type (%u)",esis_pdu_type),
849 length);
850 return;
851 } else
852 printf("%slength %u\n\t%s (%u)",
853 eflag ? "" : ", ",
854 length,
855 tok2str(esis_pdu_values,"unknown type: %u", esis_pdu_type),
856 esis_pdu_type);
857
858 printf(", v: %u%s", esis_header->version, esis_header->version == ESIS_VERSION ? "" : "unsupported" );
859 printf(", checksum: 0x%04x ", EXTRACT_16BITS(esis_header->cksum));
860 /* do not attempt to verify the checksum if it is zero */
861 if (EXTRACT_16BITS(esis_header->cksum) == 0)
862 printf("(unverified)");
863 else printf("(%s)", osi_cksum(pptr, li) ? "incorrect" : "correct");
864
865 printf(", holding time: %us, length indicator: %u",EXTRACT_16BITS(esis_header->holdtime),li);
866
867 if (vflag > 1)
868 print_unknown_data(optr,"\n\t",sizeof(struct esis_header_t));
869
870 pptr += sizeof(struct esis_header_t);
871 li -= sizeof(struct esis_header_t);
872
873 switch (esis_pdu_type) {
874 case ESIS_PDU_REDIRECT: {
875 const u_int8_t *dst, *snpa, *tptr;
876
877 dst = pptr; pptr += *pptr + 1;
878 if (pptr > snapend)
879 return;
880 printf("\n\t %s", isonsap_string(dst));
881 snpa = pptr; pptr += *pptr + 1;
882 tptr = pptr; pptr += *pptr + 1;
883 if (pptr > snapend)
884 return;
885
886 if (tptr[0] == 0)
887 printf("\n\t %s", etheraddr_string(&snpa[1]));
888 else
889 printf("\n\t %s", isonsap_string(tptr));
890 break;
891 }
892
893 case ESIS_PDU_ESH:
894 source_address_number = *pptr;
895 pptr++;
896 li--;
897
898 printf("\n\t Number of Source Addresses: %u", source_address_number);
899
900 while (source_address_number > 0) {
901 source_address_length = *pptr;
902 printf("\n\t NET (length: %u): %s",
903 source_address_length,
904 print_nsap(pptr+1, source_address_length));
905
906 pptr += source_address_length+1;
907 li -= source_address_length+1;
908 source_address_number--;
909 }
910
911 break;
912
913 case ESIS_PDU_ISH: {
914 source_address_length = *pptr;
915 printf("\n\t NET (length: %u): %s", source_address_length, print_nsap(pptr+1, source_address_length));
916 pptr += source_address_length+1;
917 li -= source_address_length +1;
918 break;
919 }
920
921 default:
922 if (vflag <= 1) {
923 if (pptr < snapend)
924 print_unknown_data(pptr,"\n\t ",snapend-pptr);
925 }
926 return;
927 }
928
929 /* now walk the options */
930 while (li >= 2) {
931 u_int op, opli;
932 const u_int8_t *tptr;
933
934 if (snapend - pptr < 2)
935 return;
936 if (li < 2) {
937 printf(", bad opts/li");
938 return;
939 }
940 op = *pptr++;
941 opli = *pptr++;
942 li -= 2;
943 if (opli > li) {
944 printf(", opt (%d) too long", op);
945 return;
946 }
947 li -= opli;
948 tptr = pptr;
949
950 if (snapend < pptr)
951 return;
952
953 printf("\n\t %s Option #%u, length %u, value: ",
954 tok2str(esis_option_values,"Unknown",op),
955 op,
956 opli);
957
958 switch (op) {
959
960 case ESIS_OPTION_ES_CONF_TIME:
961 printf("%us", EXTRACT_16BITS(tptr));
962 break;
963
964
965 case ESIS_OPTION_PROTOCOLS:
966 while (opli>0) {
967 printf("%s (0x%02x)",
968 tok2str(nlpid_values,
969 "unknown",
970 *tptr),
971 *tptr);
972 if (opli>1) /* further NPLIDs ? - put comma */
973 printf(", ");
974 tptr++;
975 opli--;
976 }
977 break;
978
979 /*
980 * FIXME those are the defined Options that lack a decoder
981 * you are welcome to contribute code ;-)
982 */
983
984 case ESIS_OPTION_QOS_MAINTENANCE:
985 case ESIS_OPTION_SECURITY:
986 case ESIS_OPTION_PRIORITY:
987 case ESIS_OPTION_ADDRESS_MASK:
988 case ESIS_OPTION_SNPA_MASK:
989
990 default:
991 print_unknown_data(tptr,"\n\t ",opli);
992 break;
993 }
994 if (vflag > 1)
995 print_unknown_data(pptr,"\n\t ",opli);
996 pptr += opli;
997 }
998 }
999
1000 /* shared routine for printing system, node and lsp-ids */
1001 static char *
1002 isis_print_id(const u_int8_t *cp, int id_len)
1003 {
1004 int i;
1005 static char id[sizeof("xxxx.xxxx.xxxx.yy-zz")];
1006 char *pos = id;
1007
1008 for (i = 1; i <= SYSTEM_ID_LEN; i++) {
1009 snprintf(pos, sizeof(id) - (pos - id), "%02x", *cp++);
1010 pos += strlen(pos);
1011 if (i == 2 || i == 4)
1012 *pos++ = '.';
1013 }
1014 if (id_len >= NODE_ID_LEN) {
1015 snprintf(pos, sizeof(id) - (pos - id), ".%02x", *cp++);
1016 pos += strlen(pos);
1017 }
1018 if (id_len == LSP_ID_LEN)
1019 snprintf(pos, sizeof(id) - (pos - id), "-%02x", *cp);
1020 return (id);
1021 }
1022
1023 /* print the 4-byte metric block which is common found in the old-style TLVs */
1024 static int
1025 isis_print_metric_block (const struct isis_metric_block *isis_metric_block)
1026 {
1027 printf(", Default Metric: %d, %s",
1028 ISIS_LSP_TLV_METRIC_VALUE(isis_metric_block->metric_default),
1029 ISIS_LSP_TLV_METRIC_IE(isis_metric_block->metric_default) ? "External" : "Internal");
1030 if (!ISIS_LSP_TLV_METRIC_SUPPORTED(isis_metric_block->metric_delay))
1031 printf("\n\t\t Delay Metric: %d, %s",
1032 ISIS_LSP_TLV_METRIC_VALUE(isis_metric_block->metric_delay),
1033 ISIS_LSP_TLV_METRIC_IE(isis_metric_block->metric_delay) ? "External" : "Internal");
1034 if (!ISIS_LSP_TLV_METRIC_SUPPORTED(isis_metric_block->metric_expense))
1035 printf("\n\t\t Expense Metric: %d, %s",
1036 ISIS_LSP_TLV_METRIC_VALUE(isis_metric_block->metric_expense),
1037 ISIS_LSP_TLV_METRIC_IE(isis_metric_block->metric_expense) ? "External" : "Internal");
1038 if (!ISIS_LSP_TLV_METRIC_SUPPORTED(isis_metric_block->metric_error))
1039 printf("\n\t\t Error Metric: %d, %s",
1040 ISIS_LSP_TLV_METRIC_VALUE(isis_metric_block->metric_error),
1041 ISIS_LSP_TLV_METRIC_IE(isis_metric_block->metric_error) ? "External" : "Internal");
1042
1043 return(1); /* everything is ok */
1044 }
1045
1046 static int
1047 isis_print_tlv_ip_reach (const u_int8_t *cp, const char *ident, int length)
1048 {
1049 int prefix_len;
1050 const struct isis_tlv_ip_reach *tlv_ip_reach;
1051
1052 tlv_ip_reach = (const struct isis_tlv_ip_reach *)cp;
1053
1054 while (length > 0) {
1055 if ((size_t)length < sizeof(*tlv_ip_reach)) {
1056 printf("short IPv4 Reachability (%d vs %lu)",
1057 length,
1058 (unsigned long)sizeof(*tlv_ip_reach));
1059 return (0);
1060 }
1061
1062 if (!TTEST(*tlv_ip_reach))
1063 return (0);
1064
1065 prefix_len = mask2plen(EXTRACT_32BITS(tlv_ip_reach->mask));
1066
1067 if (prefix_len == -1)
1068 printf("%sIPv4 prefix: %s mask %s",
1069 ident,
1070 ipaddr_string((tlv_ip_reach->prefix)),
1071 ipaddr_string((tlv_ip_reach->mask)));
1072 else
1073 printf("%sIPv4 prefix: %15s/%u",
1074 ident,
1075 ipaddr_string((tlv_ip_reach->prefix)),
1076 prefix_len);
1077
1078 printf(", Distribution: %s, Metric: %u, %s",
1079 ISIS_LSP_TLV_METRIC_UPDOWN(tlv_ip_reach->isis_metric_block.metric_default) ? "down" : "up",
1080 ISIS_LSP_TLV_METRIC_VALUE(tlv_ip_reach->isis_metric_block.metric_default),
1081 ISIS_LSP_TLV_METRIC_IE(tlv_ip_reach->isis_metric_block.metric_default) ? "External" : "Internal");
1082
1083 if (!ISIS_LSP_TLV_METRIC_SUPPORTED(tlv_ip_reach->isis_metric_block.metric_delay))
1084 printf("%s Delay Metric: %u, %s",
1085 ident,
1086 ISIS_LSP_TLV_METRIC_VALUE(tlv_ip_reach->isis_metric_block.metric_delay),
1087 ISIS_LSP_TLV_METRIC_IE(tlv_ip_reach->isis_metric_block.metric_delay) ? "External" : "Internal");
1088
1089 if (!ISIS_LSP_TLV_METRIC_SUPPORTED(tlv_ip_reach->isis_metric_block.metric_expense))
1090 printf("%s Expense Metric: %u, %s",
1091 ident,
1092 ISIS_LSP_TLV_METRIC_VALUE(tlv_ip_reach->isis_metric_block.metric_expense),
1093 ISIS_LSP_TLV_METRIC_IE(tlv_ip_reach->isis_metric_block.metric_expense) ? "External" : "Internal");
1094
1095 if (!ISIS_LSP_TLV_METRIC_SUPPORTED(tlv_ip_reach->isis_metric_block.metric_error))
1096 printf("%s Error Metric: %u, %s",
1097 ident,
1098 ISIS_LSP_TLV_METRIC_VALUE(tlv_ip_reach->isis_metric_block.metric_error),
1099 ISIS_LSP_TLV_METRIC_IE(tlv_ip_reach->isis_metric_block.metric_error) ? "External" : "Internal");
1100
1101 length -= sizeof(struct isis_tlv_ip_reach);
1102 tlv_ip_reach++;
1103 }
1104 return (1);
1105 }
1106
1107 /*
1108 * this is the common IP-REACH subTLV decoder it is called
1109 * from various EXTD-IP REACH TLVs (135,235,236,237)
1110 */
1111
1112 static int
1113 isis_print_ip_reach_subtlv (const u_int8_t *tptr,int subt,int subl,const char *ident) {
1114
1115 /* first lets see if we know the subTLVs name*/
1116 printf("%s%s subTLV #%u, length: %u",
1117 ident,
1118 tok2str(isis_ext_ip_reach_subtlv_values,
1119 "unknown",
1120 subt),
1121 subt,
1122 subl);
1123
1124 if (!TTEST2(*tptr,subl))
1125 goto trunctlv;
1126
1127 switch(subt) {
1128 case ISIS_SUBTLV_EXTD_IP_REACH_MGMT_PREFIX_COLOR: /* fall through */
1129 case ISIS_SUBTLV_EXTD_IP_REACH_ADMIN_TAG32:
1130 while (subl >= 4) {
1131 printf(", 0x%08x (=%u)",
1132 EXTRACT_32BITS(tptr),
1133 EXTRACT_32BITS(tptr));
1134 tptr+=4;
1135 subl-=4;
1136 }
1137 break;
1138 case ISIS_SUBTLV_EXTD_IP_REACH_ADMIN_TAG64:
1139 while (subl >= 8) {
1140 printf(", 0x%08x%08x",
1141 EXTRACT_32BITS(tptr),
1142 EXTRACT_32BITS(tptr+4));
1143 tptr+=8;
1144 subl-=8;
1145 }
1146 break;
1147 default:
1148 if(!print_unknown_data(tptr,"\n\t\t ",
1149 subl))
1150 return(0);
1151 break;
1152 }
1153 return(1);
1154
1155 trunctlv:
1156 printf("%spacket exceeded snapshot",ident);
1157 return(0);
1158 }
1159
1160 /*
1161 * this is the common IS-REACH subTLV decoder it is called
1162 * from isis_print_ext_is_reach()
1163 */
1164
1165 static int
1166 isis_print_is_reach_subtlv (const u_int8_t *tptr,int subt,int subl,const char *ident) {
1167
1168 int priority_level,bandwidth_constraint;
1169 union { /* int to float conversion buffer for several subTLVs */
1170 float f;
1171 u_int32_t i;
1172 } bw;
1173
1174 /* first lets see if we know the subTLVs name*/
1175 printf("%s%s subTLV #%u, length: %u",
1176 ident,
1177 tok2str(isis_ext_is_reach_subtlv_values,
1178 "unknown",
1179 subt),
1180 subt,
1181 subl);
1182
1183 if (!TTEST2(*tptr,subl))
1184 goto trunctlv;
1185
1186 switch(subt) {
1187 case ISIS_SUBTLV_EXT_IS_REACH_ADMIN_GROUP:
1188 case ISIS_SUBTLV_EXT_IS_REACH_LINK_LOCAL_REMOTE_ID:
1189 case ISIS_SUBTLV_EXT_IS_REACH_LINK_REMOTE_ID:
1190 if (subl >= 4) {
1191 printf(", 0x%08x", EXTRACT_32BITS(tptr));
1192 if (subl == 8) /* draft-ietf-isis-gmpls-extensions */
1193 printf(", 0x%08x", EXTRACT_32BITS(tptr+4));
1194 }
1195 break;
1196 case ISIS_SUBTLV_EXT_IS_REACH_IPV4_INTF_ADDR:
1197 case ISIS_SUBTLV_EXT_IS_REACH_IPV4_NEIGHBOR_ADDR:
1198 if (subl >= 4)
1199 printf(", %s", ipaddr_string(tptr));
1200 break;
1201 case ISIS_SUBTLV_EXT_IS_REACH_MAX_LINK_BW :
1202 case ISIS_SUBTLV_EXT_IS_REACH_RESERVABLE_BW:
1203 if (subl >= 4) {
1204 bw.i = EXTRACT_32BITS(tptr);
1205 printf(", %.3f Mbps", bw.f*8/1000000 );
1206 }
1207 break;
1208 case ISIS_SUBTLV_EXT_IS_REACH_UNRESERVED_BW :
1209 if (subl >= 32) {
1210 for (priority_level = 0; priority_level < 8; priority_level++) {
1211 bw.i = EXTRACT_32BITS(tptr);
1212 printf("%s priority level %d: %.3f Mbps",
1213 ident,
1214 priority_level,
1215 bw.f*8/1000000 );
1216 tptr+=4;
1217 }
1218 }
1219 break;
1220 case ISIS_SUBTLV_EXT_IS_REACH_DIFFSERV_TE:
1221 printf("%sBandwidth Constraints Model ID: %s (%u)",
1222 ident,
1223 tok2str(diffserv_te_bc_values, "unknown", *tptr),
1224 *tptr);
1225 tptr++;
1226 /* decode BCs until the subTLV ends */
1227 for (bandwidth_constraint = 0; bandwidth_constraint < (subl-1)/4; bandwidth_constraint++) {
1228 bw.i = EXTRACT_32BITS(tptr);
1229 printf("%s Bandwidth constraint %d: %.3f Mbps",
1230 ident,
1231 bandwidth_constraint,
1232 bw.f*8/1000000 );
1233 tptr+=4;
1234 }
1235 break;
1236 case ISIS_SUBTLV_EXT_IS_REACH_TE_METRIC:
1237 if (subl >= 3)
1238 printf(", %u", EXTRACT_24BITS(tptr));
1239 break;
1240 case ISIS_SUBTLV_EXT_IS_REACH_LINK_PROTECTION_TYPE:
1241 if (subl >= 2) {
1242 printf(", %s, Priority %u",
1243 bittok2str(gmpls_link_prot_values, "none", *tptr),
1244 *(tptr+1));
1245 }
1246 break;
1247 case ISIS_SUBTLV_EXT_IS_REACH_INTF_SW_CAP_DESCR:
1248 if (subl >= 36) {
1249 printf("%s Interface Switching Capability:%s",
1250 ident,
1251 tok2str(gmpls_switch_cap_values, "Unknown", *(tptr)));
1252 printf(", LSP Encoding: %s",
1253 tok2str(gmpls_encoding_values, "Unknown", *(tptr+1)));
1254 tptr+=4;
1255 printf("%s Max LSP Bandwidth:",ident);
1256 for (priority_level = 0; priority_level < 8; priority_level++) {
1257 bw.i = EXTRACT_32BITS(tptr);
1258 printf("%s priority level %d: %.3f Mbps",
1259 ident,
1260 priority_level,
1261 bw.f*8/1000000 );
1262 tptr+=4;
1263 }
1264 subl-=36;
1265 /* there is some optional stuff left to decode but this is as of yet
1266 not specified so just lets hexdump what is left */
1267 if(subl>0){
1268 if(!print_unknown_data(tptr,"\n\t\t ",
1269 subl-36))
1270 return(0);
1271 }
1272 }
1273 break;
1274 default:
1275 if(!print_unknown_data(tptr,"\n\t\t ",
1276 subl))
1277 return(0);
1278 break;
1279 }
1280 return(1);
1281
1282 trunctlv:
1283 printf("%spacket exceeded snapshot",ident);
1284 return(0);
1285 }
1286
1287
1288 /*
1289 * this is the common IS-REACH decoder it is called
1290 * from various EXTD-IS REACH style TLVs (22,24,222)
1291 */
1292
1293 static int
1294 isis_print_ext_is_reach (const u_int8_t *tptr,const char *ident, int tlv_type) {
1295
1296 char ident_buffer[20];
1297 int subtlv_type,subtlv_len,subtlv_sum_len;
1298 int proc_bytes = 0; /* how many bytes did we process ? */
1299
1300 if (!TTEST2(*tptr, NODE_ID_LEN))
1301 return(0);
1302
1303 printf("%sIS Neighbor: %s", ident, isis_print_id(tptr, NODE_ID_LEN));
1304 tptr+=(NODE_ID_LEN);
1305
1306 if (tlv_type != ISIS_TLV_IS_ALIAS_ID) { /* the Alias TLV Metric field is implicit 0 */
1307 if (!TTEST2(*tptr, 3)) /* and is therefore skipped */
1308 return(0);
1309 printf(", Metric: %d",EXTRACT_24BITS(tptr));
1310 tptr+=3;
1311 }
1312
1313 if (!TTEST2(*tptr, 1))
1314 return(0);
1315 subtlv_sum_len=*(tptr++); /* read out subTLV length */
1316 proc_bytes=NODE_ID_LEN+3+1;
1317 printf(", %ssub-TLVs present",subtlv_sum_len ? "" : "no ");
1318 if (subtlv_sum_len) {
1319 printf(" (%u)",subtlv_sum_len);
1320 while (subtlv_sum_len>0) {
1321 if (!TTEST2(*tptr,2))
1322 return(0);
1323 subtlv_type=*(tptr++);
1324 subtlv_len=*(tptr++);
1325 /* prepend the ident string */
1326 snprintf(ident_buffer, sizeof(ident_buffer), "%s ",ident);
1327 if(!isis_print_is_reach_subtlv(tptr,subtlv_type,subtlv_len,ident_buffer))
1328 return(0);
1329 tptr+=subtlv_len;
1330 subtlv_sum_len-=(subtlv_len+2);
1331 proc_bytes+=(subtlv_len+2);
1332 }
1333 }
1334 return(proc_bytes);
1335 }
1336
1337 /*
1338 * this is the common Multi Topology ID decoder
1339 * it is called from various MT-TLVs (222,229,235,237)
1340 */
1341
1342 static int
1343 isis_print_mtid (const u_int8_t *tptr,const char *ident) {
1344
1345 if (!TTEST2(*tptr, 2))
1346 return(0);
1347
1348 printf("%s%s",
1349 ident,
1350 tok2str(isis_mt_values,
1351 "Reserved for IETF Consensus",
1352 ISIS_MASK_MTID(EXTRACT_16BITS(tptr))));
1353
1354 printf(" Topology (0x%03x), Flags: [%s]",
1355 ISIS_MASK_MTID(EXTRACT_16BITS(tptr)),
1356 bittok2str(isis_mt_flag_values, "none",ISIS_MASK_MTFLAGS(EXTRACT_16BITS(tptr))));
1357
1358 return(2);
1359 }
1360
1361 /*
1362 * this is the common extended IP reach decoder
1363 * it is called from TLVs (135,235,236,237)
1364 * we process the TLV and optional subTLVs and return
1365 * the amount of processed bytes
1366 */
1367
1368 static int
1369 isis_print_extd_ip_reach (const u_int8_t *tptr, const char *ident, u_int16_t afi) {
1370
1371 char ident_buffer[20];
1372 u_int8_t prefix[16]; /* shared copy buffer for IPv4 and IPv6 prefixes */
1373 u_int metric, status_byte, bit_length, byte_length, sublen, processed, subtlvtype, subtlvlen;
1374
1375 if (!TTEST2(*tptr, 4))
1376 return (0);
1377 metric = EXTRACT_32BITS(tptr);
1378 processed=4;
1379 tptr+=4;
1380
1381 if (afi == IPV4) {
1382 if (!TTEST2(*tptr, 1)) /* fetch status byte */
1383 return (0);
1384 status_byte=*(tptr++);
1385 bit_length = status_byte&0x3f;
1386 processed++;
1387 #ifdef INET6
1388 } else if (afi == IPV6) {
1389 if (!TTEST2(*tptr, 1)) /* fetch status & prefix_len byte */
1390 return (0);
1391 status_byte=*(tptr++);
1392 bit_length=*(tptr++);
1393 processed+=2;
1394 #endif
1395 } else
1396 return (0); /* somebody is fooling us */
1397
1398 byte_length = (bit_length + 7) / 8; /* prefix has variable length encoding */
1399
1400 if (!TTEST2(*tptr, byte_length))
1401 return (0);
1402 memset(prefix, 0, 16); /* clear the copy buffer */
1403 memcpy(prefix,tptr,byte_length); /* copy as much as is stored in the TLV */
1404 tptr+=byte_length;
1405 processed+=byte_length;
1406
1407 if (afi == IPV4)
1408 printf("%sIPv4 prefix: %15s/%u",
1409 ident,
1410 ipaddr_string(prefix),
1411 bit_length);
1412 #ifdef INET6
1413 if (afi == IPV6)
1414 printf("%sIPv6 prefix: %s/%u",
1415 ident,
1416 ip6addr_string(prefix),
1417 bit_length);
1418 #endif
1419
1420 printf(", Distribution: %s, Metric: %u",
1421 ISIS_MASK_TLV_EXTD_IP_UPDOWN(status_byte) ? "down" : "up",
1422 metric);
1423
1424 if (afi == IPV4 && ISIS_MASK_TLV_EXTD_IP_SUBTLV(status_byte))
1425 printf(", sub-TLVs present");
1426 #ifdef INET6
1427 if (afi == IPV6)
1428 printf(", %s%s",
1429 ISIS_MASK_TLV_EXTD_IP6_IE(status_byte) ? "External" : "Internal",
1430 ISIS_MASK_TLV_EXTD_IP6_SUBTLV(status_byte) ? ", sub-TLVs present" : "");
1431 #endif
1432
1433 if ((ISIS_MASK_TLV_EXTD_IP_SUBTLV(status_byte) && afi == IPV4) ||
1434 (ISIS_MASK_TLV_EXTD_IP6_SUBTLV(status_byte) && afi == IPV6)) {
1435 /* assume that one prefix can hold more
1436 than one subTLV - therefore the first byte must reflect
1437 the aggregate bytecount of the subTLVs for this prefix
1438 */
1439 if (!TTEST2(*tptr, 1))
1440 return (0);
1441 sublen=*(tptr++);
1442 processed+=sublen+1;
1443 printf(" (%u)",sublen); /* print out subTLV length */
1444
1445 while (sublen>0) {
1446 if (!TTEST2(*tptr,2))
1447 return (0);
1448 subtlvtype=*(tptr++);
1449 subtlvlen=*(tptr++);
1450 /* prepend the ident string */
1451 snprintf(ident_buffer, sizeof(ident_buffer), "%s ",ident);
1452 if(!isis_print_ip_reach_subtlv(tptr,subtlvtype,subtlvlen,ident_buffer))
1453 return(0);
1454 tptr+=subtlvlen;
1455 sublen-=(subtlvlen+2);
1456 }
1457 }
1458 return (processed);
1459 }
1460
1461 /*
1462 * isis_print
1463 * Decode IS-IS packets. Return 0 on error.
1464 */
1465
1466 static int isis_print (const u_int8_t *p, u_int length)
1467 {
1468 const struct isis_common_header *isis_header;
1469
1470 const struct isis_iih_lan_header *header_iih_lan;
1471 const struct isis_iih_ptp_header *header_iih_ptp;
1472 const struct isis_lsp_header *header_lsp;
1473 const struct isis_csnp_header *header_csnp;
1474 const struct isis_psnp_header *header_psnp;
1475
1476 const struct isis_tlv_lsp *tlv_lsp;
1477 const struct isis_tlv_ptp_adj *tlv_ptp_adj;
1478 const struct isis_tlv_is_reach *tlv_is_reach;
1479 const struct isis_tlv_es_reach *tlv_es_reach;
1480
1481 u_int8_t pdu_type, max_area, id_length, tlv_type, tlv_len, tmp, alen, lan_alen, prefix_len;
1482 u_int8_t ext_is_len, ext_ip_len, mt_len;
1483 const u_int8_t *optr, *pptr, *tptr;
1484 u_short packet_len,pdu_len;
1485 u_int i,vendor_id;
1486
1487 packet_len=length;
1488 optr = p; /* initialize the _o_riginal pointer to the packet start -
1489 need it for parsing the checksum TLV */
1490 isis_header = (const struct isis_common_header *)p;
1491 TCHECK(*isis_header);
1492 pptr = p+(ISIS_COMMON_HEADER_SIZE);
1493 header_iih_lan = (const struct isis_iih_lan_header *)pptr;
1494 header_iih_ptp = (const struct isis_iih_ptp_header *)pptr;
1495 header_lsp = (const struct isis_lsp_header *)pptr;
1496 header_csnp = (const struct isis_csnp_header *)pptr;
1497 header_psnp = (const struct isis_psnp_header *)pptr;
1498
1499 if (!eflag)
1500 printf("IS-IS");
1501
1502 /*
1503 * Sanity checking of the header.
1504 */
1505
1506 if (isis_header->version != ISIS_VERSION) {
1507 printf("version %d packet not supported", isis_header->version);
1508 return (0);
1509 }
1510
1511 if ((isis_header->id_length != SYSTEM_ID_LEN) && (isis_header->id_length != 0)) {
1512 printf("system ID length of %d is not supported",
1513 isis_header->id_length);
1514 return (0);
1515 }
1516
1517 if (isis_header->pdu_version != ISIS_VERSION) {
1518 printf("version %d packet not supported", isis_header->pdu_version);
1519 return (0);
1520 }
1521
1522 max_area = isis_header->max_area;
1523 switch(max_area) {
1524 case 0:
1525 max_area = 3; /* silly shit */
1526 break;
1527 case 255:
1528 printf("bad packet -- 255 areas");
1529 return (0);
1530 default:
1531 break;
1532 }
1533
1534 id_length = isis_header->id_length;
1535 switch(id_length) {
1536 case 0:
1537 id_length = 6; /* silly shit again */
1538 break;
1539 case 1: /* 1-8 are valid sys-ID lenghts */
1540 case 2:
1541 case 3:
1542 case 4:
1543 case 5:
1544 case 6:
1545 case 7:
1546 case 8:
1547 break;
1548 case 255:
1549 id_length = 0; /* entirely useless */
1550 break;
1551 default:
1552 break;
1553 }
1554
1555 /* toss any non 6-byte sys-ID len PDUs */
1556 if (id_length != 6 ) {
1557 printf("bad packet -- illegal sys-ID length (%u)", id_length);
1558 return (0);
1559 }
1560
1561 pdu_type=isis_header->pdu_type;
1562
1563 /* in non-verbose mode print the basic PDU Type plus PDU specific brief information*/
1564 if (vflag < 1) {
1565 printf("%s%s",
1566 eflag ? "" : ", ",
1567 tok2str(isis_pdu_values,"unknown PDU-Type %u",pdu_type));
1568
1569 switch (pdu_type) {
1570
1571 case ISIS_PDU_L1_LAN_IIH:
1572 case ISIS_PDU_L2_LAN_IIH:
1573 printf(", src-id %s",
1574 isis_print_id(header_iih_lan->source_id,SYSTEM_ID_LEN));
1575 printf(", lan-id %s, prio %u",
1576 isis_print_id(header_iih_lan->lan_id,NODE_ID_LEN),
1577 header_iih_lan->priority);
1578 break;
1579 case ISIS_PDU_PTP_IIH:
1580 printf(", src-id %s", isis_print_id(header_iih_ptp->source_id,SYSTEM_ID_LEN));
1581 break;
1582 case ISIS_PDU_L1_LSP:
1583 case ISIS_PDU_L2_LSP:
1584 printf(", lsp-id %s, seq 0x%08x, lifetime %5us",
1585 isis_print_id(header_lsp->lsp_id, LSP_ID_LEN),
1586 EXTRACT_32BITS(header_lsp->sequence_number),
1587 EXTRACT_16BITS(header_lsp->remaining_lifetime));
1588 break;
1589 case ISIS_PDU_L1_CSNP:
1590 case ISIS_PDU_L2_CSNP:
1591 printf(", src-id %s", isis_print_id(header_csnp->source_id,NODE_ID_LEN));
1592 break;
1593 case ISIS_PDU_L1_PSNP:
1594 case ISIS_PDU_L2_PSNP:
1595 printf(", src-id %s", isis_print_id(header_psnp->source_id,NODE_ID_LEN));
1596 break;
1597
1598 }
1599 printf(", length %u", length);
1600
1601 return(1);
1602 }
1603
1604 /* ok they seem to want to know everything - lets fully decode it */
1605 printf("%slength %u", eflag ? "" : ", ",length);
1606
1607 printf("\n\t%s, hlen: %u, v: %u, pdu-v: %u, sys-id-len: %u (%u), max-area: %u (%u)",
1608 tok2str(isis_pdu_values,
1609 "unknown, type %u",
1610 pdu_type),
1611 isis_header->fixed_len,
1612 isis_header->version,
1613 isis_header->pdu_version,
1614 id_length,
1615 isis_header->id_length,
1616 max_area,
1617 isis_header->max_area);
1618
1619 if (vflag > 1) {
1620 if(!print_unknown_data(optr,"\n\t",8)) /* provide the _o_riginal pointer */
1621 return(0); /* for optionally debugging the common header */
1622 }
1623
1624 switch (pdu_type) {
1625
1626 case ISIS_PDU_L1_LAN_IIH:
1627 case ISIS_PDU_L2_LAN_IIH:
1628 if (isis_header->fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_LAN_HEADER_SIZE)) {
1629 printf(", bogus fixed header length %u should be %lu",
1630 isis_header->fixed_len, (unsigned long)ISIS_IIH_LAN_HEADER_SIZE);
1631 return (0);
1632 }
1633
1634 pdu_len=EXTRACT_16BITS(header_iih_lan->pdu_len);
1635 if (packet_len>pdu_len) {
1636 packet_len=pdu_len; /* do TLV decoding as long as it makes sense */
1637 length=pdu_len;
1638 }
1639
1640 TCHECK(*header_iih_lan);
1641 printf("\n\t source-id: %s, holding time: %us, Flags: [%s]",
1642 isis_print_id(header_iih_lan->source_id,SYSTEM_ID_LEN),
1643 EXTRACT_16BITS(header_iih_lan->holding_time),
1644 tok2str(isis_iih_circuit_type_values,
1645 "unknown circuit type 0x%02x",
1646 header_iih_lan->circuit_type));
1647
1648 printf("\n\t lan-id: %s, Priority: %u, PDU length: %u",
1649 isis_print_id(header_iih_lan->lan_id, NODE_ID_LEN),
1650 (header_iih_lan->priority) & ISIS_LAN_PRIORITY_MASK,
1651 pdu_len);
1652
1653 if (vflag > 1) {
1654 if(!print_unknown_data(pptr,"\n\t ",ISIS_IIH_LAN_HEADER_SIZE))
1655 return(0);
1656 }
1657
1658 packet_len -= (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_LAN_HEADER_SIZE);
1659 pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_LAN_HEADER_SIZE);
1660 break;
1661
1662 case ISIS_PDU_PTP_IIH:
1663 if (isis_header->fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_PTP_HEADER_SIZE)) {
1664 printf(", bogus fixed header length %u should be %lu",
1665 isis_header->fixed_len, (unsigned long)ISIS_IIH_PTP_HEADER_SIZE);
1666 return (0);
1667 }
1668
1669 pdu_len=EXTRACT_16BITS(header_iih_ptp->pdu_len);
1670 if (packet_len>pdu_len) {
1671 packet_len=pdu_len; /* do TLV decoding as long as it makes sense */
1672 length=pdu_len;
1673 }
1674
1675 TCHECK(*header_iih_ptp);
1676 printf("\n\t source-id: %s, holding time: %us, Flags: [%s]",
1677 isis_print_id(header_iih_ptp->source_id,SYSTEM_ID_LEN),
1678 EXTRACT_16BITS(header_iih_ptp->holding_time),
1679 tok2str(isis_iih_circuit_type_values,
1680 "unknown circuit type 0x%02x",
1681 header_iih_ptp->circuit_type));
1682
1683 printf("\n\t circuit-id: 0x%02x, PDU length: %u",
1684 header_iih_ptp->circuit_id,
1685 pdu_len);
1686
1687 if (vflag > 1) {
1688 if(!print_unknown_data(pptr,"\n\t ",ISIS_IIH_PTP_HEADER_SIZE))
1689 return(0);
1690 }
1691
1692 packet_len -= (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_PTP_HEADER_SIZE);
1693 pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_PTP_HEADER_SIZE);
1694 break;
1695
1696 case ISIS_PDU_L1_LSP:
1697 case ISIS_PDU_L2_LSP:
1698 if (isis_header->fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_LSP_HEADER_SIZE)) {
1699 printf(", bogus fixed header length %u should be %lu",
1700 isis_header->fixed_len, (unsigned long)ISIS_LSP_HEADER_SIZE);
1701 return (0);
1702 }
1703
1704 pdu_len=EXTRACT_16BITS(header_lsp->pdu_len);
1705 if (packet_len>pdu_len) {
1706 packet_len=pdu_len; /* do TLV decoding as long as it makes sense */
1707 length=pdu_len;
1708 }
1709
1710 TCHECK(*header_lsp);
1711 printf("\n\t lsp-id: %s, seq: 0x%08x, lifetime: %5us\n\t chksum: 0x%04x",
1712 isis_print_id(header_lsp->lsp_id, LSP_ID_LEN),
1713 EXTRACT_32BITS(header_lsp->sequence_number),
1714 EXTRACT_16BITS(header_lsp->remaining_lifetime),
1715 EXTRACT_16BITS(header_lsp->checksum));
1716
1717 /* if this is a purge do not attempt to verify the checksum */
1718 if ( EXTRACT_16BITS(header_lsp->remaining_lifetime) == 0 &&
1719 EXTRACT_16BITS(header_lsp->checksum) == 0)
1720 printf(" (purged)");
1721 else
1722 /* verify the checksum -
1723 * checking starts at the lsp-id field at byte position [12]
1724 * hence the length needs to be reduced by 12 bytes */
1725 printf(" (%s)", (osi_cksum((u_int8_t *)header_lsp->lsp_id, length-12)) ? "incorrect" : "correct");
1726
1727 printf(", PDU length: %u, Flags: [ %s",
1728 pdu_len,
1729 ISIS_MASK_LSP_OL_BIT(header_lsp->typeblock) ? "Overload bit set, " : "");
1730
1731 if (ISIS_MASK_LSP_ATT_BITS(header_lsp->typeblock)) {
1732 printf("%s", ISIS_MASK_LSP_ATT_DEFAULT_BIT(header_lsp->typeblock) ? "default " : "");
1733 printf("%s", ISIS_MASK_LSP_ATT_DELAY_BIT(header_lsp->typeblock) ? "delay " : "");
1734 printf("%s", ISIS_MASK_LSP_ATT_EXPENSE_BIT(header_lsp->typeblock) ? "expense " : "");
1735 printf("%s", ISIS_MASK_LSP_ATT_ERROR_BIT(header_lsp->typeblock) ? "error " : "");
1736 printf("ATT bit set, ");
1737 }
1738 printf("%s", ISIS_MASK_LSP_PARTITION_BIT(header_lsp->typeblock) ? "P bit set, " : "");
1739 printf("%s ]", tok2str(isis_lsp_istype_values,"Unknown(0x%x)",ISIS_MASK_LSP_ISTYPE_BITS(header_lsp->typeblock)));
1740
1741 if (vflag > 1) {
1742 if(!print_unknown_data(pptr,"\n\t ",ISIS_LSP_HEADER_SIZE))
1743 return(0);
1744 }
1745
1746 packet_len -= (ISIS_COMMON_HEADER_SIZE+ISIS_LSP_HEADER_SIZE);
1747 pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_LSP_HEADER_SIZE);
1748 break;
1749
1750 case ISIS_PDU_L1_CSNP:
1751 case ISIS_PDU_L2_CSNP:
1752 if (isis_header->fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_CSNP_HEADER_SIZE)) {
1753 printf(", bogus fixed header length %u should be %lu",
1754 isis_header->fixed_len, (unsigned long)ISIS_CSNP_HEADER_SIZE);
1755 return (0);
1756 }
1757
1758 pdu_len=EXTRACT_16BITS(header_csnp->pdu_len);
1759 if (packet_len>pdu_len) {
1760 packet_len=pdu_len; /* do TLV decoding as long as it makes sense */
1761 length=pdu_len;
1762 }
1763
1764 TCHECK(*header_csnp);
1765 printf("\n\t source-id: %s, PDU length: %u",
1766 isis_print_id(header_csnp->source_id, NODE_ID_LEN),
1767 pdu_len);
1768 printf("\n\t start lsp-id: %s",
1769 isis_print_id(header_csnp->start_lsp_id, LSP_ID_LEN));
1770 printf("\n\t end lsp-id: %s",
1771 isis_print_id(header_csnp->end_lsp_id, LSP_ID_LEN));
1772
1773 if (vflag > 1) {
1774 if(!print_unknown_data(pptr,"\n\t ",ISIS_CSNP_HEADER_SIZE))
1775 return(0);
1776 }
1777
1778 packet_len -= (ISIS_COMMON_HEADER_SIZE+ISIS_CSNP_HEADER_SIZE);
1779 pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_CSNP_HEADER_SIZE);
1780 break;
1781
1782 case ISIS_PDU_L1_PSNP:
1783 case ISIS_PDU_L2_PSNP:
1784 if (isis_header->fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_PSNP_HEADER_SIZE)) {
1785 printf("- bogus fixed header length %u should be %lu",
1786 isis_header->fixed_len, (unsigned long)ISIS_PSNP_HEADER_SIZE);
1787 return (0);
1788 }
1789
1790 pdu_len=EXTRACT_16BITS(header_psnp->pdu_len);
1791 if (packet_len>pdu_len) {
1792 packet_len=pdu_len; /* do TLV decoding as long as it makes sense */
1793 length=pdu_len;
1794 }
1795
1796 TCHECK(*header_psnp);
1797 printf("\n\t source-id: %s, PDU length: %u",
1798 isis_print_id(header_psnp->source_id, NODE_ID_LEN),
1799 pdu_len);
1800
1801 if (vflag > 1) {
1802 if(!print_unknown_data(pptr,"\n\t ",ISIS_PSNP_HEADER_SIZE))
1803 return(0);
1804 }
1805
1806 packet_len -= (ISIS_COMMON_HEADER_SIZE+ISIS_PSNP_HEADER_SIZE);
1807 pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_PSNP_HEADER_SIZE);
1808 break;
1809
1810 default:
1811 if(!print_unknown_data(pptr,"\n\t ",length))
1812 return(0);
1813 return (0);
1814 }
1815
1816 /*
1817 * Now print the TLV's.
1818 */
1819
1820 while (packet_len >= 2) {
1821 if (pptr == snapend) {
1822 return (1);
1823 }
1824
1825 if (!TTEST2(*pptr, 2)) {
1826 printf("\n\t\t packet exceeded snapshot (%ld) bytes",
1827 (long)(pptr-snapend));
1828 return (1);
1829 }
1830 tlv_type = *pptr++;
1831 tlv_len = *pptr++;
1832 tmp =tlv_len; /* copy temporary len & pointer to packet data */
1833 tptr = pptr;
1834 packet_len -= 2;
1835 if (tlv_len > packet_len) {
1836 break;
1837 }
1838
1839 /* first lets see if we know the TLVs name*/
1840 printf("\n\t %s TLV #%u, length: %u",
1841 tok2str(isis_tlv_values,
1842 "unknown",
1843 tlv_type),
1844 tlv_type,
1845 tlv_len);
1846
1847 /* now check if we have a decoder otherwise do a hexdump at the end*/
1848 switch (tlv_type) {
1849 case ISIS_TLV_AREA_ADDR:
1850 if (!TTEST2(*tptr, 1))
1851 goto trunctlv;
1852 alen = *tptr++;
1853 while (tmp && alen < tmp) {
1854 printf("\n\t Area address (length: %u): %s",
1855 alen,
1856 print_nsap(tptr, alen));
1857 tptr += alen;
1858 tmp -= alen + 1;
1859 if (tmp==0) /* if this is the last area address do not attemt a boundary check */
1860 break;
1861 if (!TTEST2(*tptr, 1))
1862 goto trunctlv;
1863 alen = *tptr++;
1864 }
1865 break;
1866 case ISIS_TLV_ISNEIGH:
1867 while (tmp >= ETHER_ADDR_LEN) {
1868 if (!TTEST2(*tptr, ETHER_ADDR_LEN))
1869 goto trunctlv;
1870 printf("\n\t SNPA: %s",isis_print_id(tptr,ETHER_ADDR_LEN));
1871 tmp -= ETHER_ADDR_LEN;
1872 tptr += ETHER_ADDR_LEN;
1873 }
1874 break;
1875
1876 case ISIS_TLV_ISNEIGH_VARLEN:
1877 if (!TTEST2(*tptr, 1))
1878 goto trunctlv;
1879 lan_alen = *tptr++; /* LAN adress length */
1880 tmp --;
1881 printf("\n\t LAN address length %u bytes ",lan_alen);
1882 while (tmp >= lan_alen) {
1883 if (!TTEST2(*tptr, lan_alen))
1884 goto trunctlv;
1885 printf("\n\t\tIS Neighbor: %s",isis_print_id(tptr,lan_alen));
1886 tmp -= lan_alen;
1887 tptr +=lan_alen;
1888 }
1889 break;
1890
1891 case ISIS_TLV_PADDING:
1892 break;
1893
1894 case ISIS_TLV_MT_IS_REACH:
1895 while (tmp >= 2+NODE_ID_LEN+3+1) {
1896 mt_len = isis_print_mtid(tptr, "\n\t ");
1897 if (mt_len == 0) /* did something go wrong ? */
1898 goto trunctlv;
1899 tptr+=mt_len;
1900 tmp-=mt_len;
1901
1902 ext_is_len = isis_print_ext_is_reach(tptr,"\n\t ",tlv_type);
1903 if (ext_is_len == 0) /* did something go wrong ? */
1904 goto trunctlv;
1905
1906 tmp-=ext_is_len;
1907 tptr+=ext_is_len;
1908 }
1909 break;
1910
1911 case ISIS_TLV_IS_ALIAS_ID:
1912 while (tmp >= NODE_ID_LEN+1) { /* is it worth attempting a decode ? */
1913 ext_is_len = isis_print_ext_is_reach(tptr,"\n\t ",tlv_type);
1914 if (ext_is_len == 0) /* did something go wrong ? */
1915 goto trunctlv;
1916 tmp-=ext_is_len;
1917 tptr+=ext_is_len;
1918 }
1919 break;
1920
1921 case ISIS_TLV_EXT_IS_REACH:
1922 while (tmp >= NODE_ID_LEN+3+1) { /* is it worth attempting a decode ? */
1923 ext_is_len = isis_print_ext_is_reach(tptr,"\n\t ",tlv_type);
1924 if (ext_is_len == 0) /* did something go wrong ? */
1925 goto trunctlv;
1926 tmp-=ext_is_len;
1927 tptr+=ext_is_len;
1928 }
1929 break;
1930 case ISIS_TLV_IS_REACH:
1931 if (!TTEST2(*tptr,1)) /* check if there is one byte left to read out the virtual flag */
1932 goto trunctlv;
1933 printf("\n\t %s",
1934 tok2str(isis_is_reach_virtual_values,
1935 "bogus virtual flag 0x%02x",
1936 *tptr++));
1937 tlv_is_reach = (const struct isis_tlv_is_reach *)tptr;
1938 while (tmp >= sizeof(struct isis_tlv_is_reach)) {
1939 if (!TTEST(*tlv_is_reach))
1940 goto trunctlv;
1941 printf("\n\t IS Neighbor: %s",
1942 isis_print_id(tlv_is_reach->neighbor_nodeid, NODE_ID_LEN));
1943 isis_print_metric_block(&tlv_is_reach->isis_metric_block);
1944 tmp -= sizeof(struct isis_tlv_is_reach);
1945 tlv_is_reach++;
1946 }
1947 break;
1948
1949 case ISIS_TLV_ESNEIGH:
1950 tlv_es_reach = (const struct isis_tlv_es_reach *)tptr;
1951 while (tmp >= sizeof(struct isis_tlv_es_reach)) {
1952 if (!TTEST(*tlv_es_reach))
1953 goto trunctlv;
1954 printf("\n\t ES Neighbor: %s",
1955 isis_print_id(tlv_es_reach->neighbor_sysid,SYSTEM_ID_LEN));
1956 isis_print_metric_block(&tlv_es_reach->isis_metric_block);
1957 tmp -= sizeof(struct isis_tlv_es_reach);
1958 tlv_es_reach++;
1959 }
1960 break;
1961
1962 /* those two TLVs share the same format */
1963 case ISIS_TLV_INT_IP_REACH:
1964 case ISIS_TLV_EXT_IP_REACH:
1965 if (!isis_print_tlv_ip_reach(pptr, "\n\t ", tlv_len))
1966 return (1);
1967 break;
1968
1969 case ISIS_TLV_EXTD_IP_REACH:
1970 while (tmp>0) {
1971 ext_ip_len = isis_print_extd_ip_reach(tptr, "\n\t ", IPV4);
1972 if (ext_ip_len == 0) /* did something go wrong ? */
1973 goto trunctlv;
1974 tptr+=ext_ip_len;
1975 tmp-=ext_ip_len;
1976 }
1977 break;
1978
1979 case ISIS_TLV_MT_IP_REACH:
1980 while (tmp>0) {
1981 mt_len = isis_print_mtid(tptr, "\n\t ");
1982 if (mt_len == 0) /* did something go wrong ? */
1983 goto trunctlv;
1984 tptr+=mt_len;
1985 tmp-=mt_len;
1986
1987 ext_ip_len = isis_print_extd_ip_reach(tptr, "\n\t ", IPV4);
1988 if (ext_ip_len == 0) /* did something go wrong ? */
1989 goto trunctlv;
1990 tptr+=ext_ip_len;
1991 tmp-=ext_ip_len;
1992 }
1993 break;
1994
1995 #ifdef INET6
1996 case ISIS_TLV_IP6_REACH:
1997 while (tmp>0) {
1998 ext_ip_len = isis_print_extd_ip_reach(tptr, "\n\t ", IPV6);
1999 if (ext_ip_len == 0) /* did something go wrong ? */
2000 goto trunctlv;
2001 tptr+=ext_ip_len;
2002 tmp-=ext_ip_len;
2003 }
2004 break;
2005
2006 case ISIS_TLV_MT_IP6_REACH:
2007 while (tmp>0) {
2008 mt_len = isis_print_mtid(tptr, "\n\t ");
2009 if (mt_len == 0) /* did something go wrong ? */
2010 goto trunctlv;
2011 tptr+=mt_len;
2012 tmp-=mt_len;
2013
2014 ext_ip_len = isis_print_extd_ip_reach(tptr, "\n\t ", IPV6);
2015 if (ext_ip_len == 0) /* did something go wrong ? */
2016 goto trunctlv;
2017 tptr+=ext_ip_len;
2018 tmp-=ext_ip_len;
2019 }
2020 break;
2021
2022 case ISIS_TLV_IP6ADDR:
2023 while (tmp>0) {
2024 if (!TTEST2(*tptr, 16))
2025 goto trunctlv;
2026
2027 printf("\n\t IPv6 interface address: %s",
2028 ip6addr_string(tptr));
2029
2030 tptr += 16;
2031 tmp -= 16;
2032 }
2033 break;
2034 #endif
2035 case ISIS_TLV_AUTH:
2036 if (!TTEST2(*tptr, 1))
2037 goto trunctlv;
2038
2039 printf("\n\t %s: ",
2040 tok2str(isis_subtlv_auth_values,
2041 "unknown Authentication type 0x%02x",
2042 *tptr));
2043
2044 switch (*tptr) {
2045 case ISIS_SUBTLV_AUTH_SIMPLE:
2046 for(i=1;i<tlv_len;i++) {
2047 if (!TTEST2(*(tptr+i), 1))
2048 goto trunctlv;
2049 printf("%c",*(tptr+i));
2050 }
2051 break;
2052 case ISIS_SUBTLV_AUTH_MD5:
2053 for(i=1;i<tlv_len;i++) {
2054 if (!TTEST2(*(tptr+i), 1))
2055 goto trunctlv;
2056 printf("%02x",*(tptr+i));
2057 }
2058 if (tlv_len != ISIS_SUBTLV_AUTH_MD5_LEN+1)
2059 printf(", (malformed subTLV) ");
2060 break;
2061 case ISIS_SUBTLV_AUTH_PRIVATE:
2062 default:
2063 if(!print_unknown_data(tptr+1,"\n\t\t ",tlv_len-1))
2064 return(0);
2065 break;
2066 }
2067 break;
2068
2069 case ISIS_TLV_PTP_ADJ:
2070 tlv_ptp_adj = (const struct isis_tlv_ptp_adj *)tptr;
2071 if(tmp>=1) {
2072 if (!TTEST2(*tptr, 1))
2073 goto trunctlv;
2074 printf("\n\t Adjacency State: %s (%u)",
2075 tok2str(isis_ptp_adjancey_values, "unknown", *tptr),
2076 *tptr);
2077 tmp--;
2078 }
2079 if(tmp>sizeof(tlv_ptp_adj->extd_local_circuit_id)) {
2080 if (!TTEST2(tlv_ptp_adj->extd_local_circuit_id,
2081 sizeof(tlv_ptp_adj->extd_local_circuit_id)))
2082 goto trunctlv;
2083 printf("\n\t Extended Local circuit-ID: 0x%08x",
2084 EXTRACT_32BITS(tlv_ptp_adj->extd_local_circuit_id));
2085 tmp-=sizeof(tlv_ptp_adj->extd_local_circuit_id);
2086 }
2087 if(tmp>=SYSTEM_ID_LEN) {
2088 if (!TTEST2(tlv_ptp_adj->neighbor_sysid, SYSTEM_ID_LEN))
2089 goto trunctlv;
2090 printf("\n\t Neighbor System-ID: %s",
2091 isis_print_id(tlv_ptp_adj->neighbor_sysid,SYSTEM_ID_LEN));
2092 tmp-=SYSTEM_ID_LEN;
2093 }
2094 if(tmp>=sizeof(tlv_ptp_adj->neighbor_extd_local_circuit_id)) {
2095 if (!TTEST2(tlv_ptp_adj->neighbor_extd_local_circuit_id,
2096 sizeof(tlv_ptp_adj->neighbor_extd_local_circuit_id)))
2097 goto trunctlv;
2098 printf("\n\t Neighbor Extended Local circuit-ID: 0x%08x",
2099 EXTRACT_32BITS(tlv_ptp_adj->neighbor_extd_local_circuit_id));
2100 }
2101 break;
2102
2103 case ISIS_TLV_PROTOCOLS:
2104 printf("\n\t NLPID(s): ");
2105 while (tmp>0) {
2106 if (!TTEST2(*(tptr), 1))
2107 goto trunctlv;
2108 printf("%s (0x%02x)",
2109 tok2str(nlpid_values,
2110 "unknown",
2111 *tptr),
2112 *tptr);
2113 if (tmp>1) /* further NPLIDs ? - put comma */
2114 printf(", ");
2115 tptr++;
2116 tmp--;
2117 }
2118 break;
2119
2120 case ISIS_TLV_TE_ROUTER_ID:
2121 if (!TTEST2(*pptr, 4))
2122 goto trunctlv;
2123 printf("\n\t Traffic Engineering Router ID: %s", ipaddr_string(pptr));
2124 break;
2125
2126 case ISIS_TLV_IPADDR:
2127 while (tmp>0) {
2128 if (!TTEST2(*tptr, 4))
2129 goto trunctlv;
2130 printf("\n\t IPv4 interface address: %s", ipaddr_string(tptr));
2131 tptr += 4;
2132 tmp -= 4;
2133 }
2134 break;
2135
2136 case ISIS_TLV_HOSTNAME:
2137 printf("\n\t Hostname: ");
2138 while (tmp>0) {
2139 if (!TTEST2(*tptr, 1))
2140 goto trunctlv;
2141 printf("%c",*tptr++);
2142 tmp--;
2143 }
2144 break;
2145
2146 case ISIS_TLV_SHARED_RISK_GROUP:
2147 if (!TTEST2(*tptr, NODE_ID_LEN))
2148 goto trunctlv;
2149 printf("\n\t IS Neighbor: %s", isis_print_id(tptr, NODE_ID_LEN));
2150 tptr+=(NODE_ID_LEN);
2151 tmp-=(NODE_ID_LEN);
2152
2153 if (!TTEST2(*tptr, 1))
2154 goto trunctlv;
2155 printf(", Flags: [%s]", ISIS_MASK_TLV_SHARED_RISK_GROUP(*tptr++) ? "numbered" : "unnumbered");
2156 tmp--;
2157
2158 if (!TTEST2(*tptr,4))
2159 goto trunctlv;
2160 printf("\n\t IPv4 interface address: %s", ipaddr_string(tptr));
2161 tptr+=4;
2162 tmp-=4;
2163
2164 if (!TTEST2(*tptr,4))
2165 goto trunctlv;
2166 printf("\n\t IPv4 neighbor address: %s", ipaddr_string(tptr));
2167 tptr+=4;
2168 tmp-=4;
2169
2170 while (tmp>0) {
2171 if (!TTEST2(*tptr, 4))
2172 goto trunctlv;
2173 printf("\n\t Link-ID: 0x%08x", EXTRACT_32BITS(tptr));
2174 tptr+=4;
2175 tmp-=4;
2176 }
2177 break;
2178
2179 case ISIS_TLV_LSP:
2180 tlv_lsp = (const struct isis_tlv_lsp *)tptr;
2181 while(tmp>0) {
2182 if (!TTEST((tlv_lsp->lsp_id)[LSP_ID_LEN-1]))
2183 goto trunctlv;
2184 printf("\n\t lsp-id: %s",
2185 isis_print_id(tlv_lsp->lsp_id, LSP_ID_LEN));
2186 if (!TTEST2(tlv_lsp->sequence_number, 4))
2187 goto trunctlv;
2188 printf(", seq: 0x%08x",EXTRACT_32BITS(tlv_lsp->sequence_number));
2189 if (!TTEST2(tlv_lsp->remaining_lifetime, 2))
2190 goto trunctlv;
2191 printf(", lifetime: %5ds",EXTRACT_16BITS(tlv_lsp->remaining_lifetime));
2192 if (!TTEST2(tlv_lsp->checksum, 2))
2193 goto trunctlv;
2194 printf(", chksum: 0x%04x",EXTRACT_16BITS(tlv_lsp->checksum));
2195 tmp-=sizeof(struct isis_tlv_lsp);
2196 tlv_lsp++;
2197 }
2198 break;
2199
2200 case ISIS_TLV_CHECKSUM:
2201 if (!TTEST2(*tptr, 2))
2202 goto trunctlv;
2203 printf("\n\t checksum: 0x%04x ", EXTRACT_16BITS(tptr));
2204 /* do not attempt to verify the checksum if it is zero
2205 * most likely a HMAC-MD5 TLV is also present and
2206 * to avoid conflicts the checksum TLV is zeroed.
2207 * see rfc3358 for details
2208 */
2209 if (EXTRACT_16BITS(tptr) == 0)
2210 printf("(unverified)");
2211 else printf("(%s)", osi_cksum(optr, length) ? "incorrect" : "correct");
2212 break;
2213
2214 case ISIS_TLV_MT_SUPPORTED:
2215 while (tmp>1) {
2216 /* length can only be a multiple of 2, otherwise there is
2217 something broken -> so decode down until length is 1 */
2218 if (tmp!=1) {
2219 mt_len = isis_print_mtid(tptr, "\n\t ");
2220 if (mt_len == 0) /* did something go wrong ? */
2221 goto trunctlv;
2222 tptr+=mt_len;
2223 tmp-=mt_len;
2224 } else {
2225 printf("\n\t malformed MT-ID");
2226 break;
2227 }
2228 }
2229 break;
2230
2231 case ISIS_TLV_RESTART_SIGNALING:
2232 if (!TTEST2(*tptr, 3))
2233 goto trunctlv;
2234 printf("\n\t Flags [%s], Remaining holding time %us",
2235 bittok2str(isis_restart_flag_values, "none", *tptr),
2236 EXTRACT_16BITS(tptr+1));
2237 tptr+=3;
2238 break;
2239
2240 case ISIS_TLV_IDRP_INFO:
2241 if (!TTEST2(*tptr, 1))
2242 goto trunctlv;
2243 printf("\n\t Inter-Domain Information Type: %s",
2244 tok2str(isis_subtlv_idrp_values,
2245 "Unknown (0x%02x)",
2246 *tptr));
2247 switch (*tptr++) {
2248 case ISIS_SUBTLV_IDRP_ASN:
2249 if (!TTEST2(*tptr, 2)) /* fetch AS number */
2250 goto trunctlv;
2251 printf("AS Number: %u",EXTRACT_16BITS(tptr));
2252 break;
2253 case ISIS_SUBTLV_IDRP_LOCAL:
2254 case ISIS_SUBTLV_IDRP_RES:
2255 default:
2256 if(!print_unknown_data(tptr,"\n\t ",tlv_len-1))
2257 return(0);
2258 break;
2259 }
2260 break;
2261
2262 case ISIS_TLV_LSP_BUFFERSIZE:
2263 if (!TTEST2(*tptr, 2))
2264 goto trunctlv;
2265 printf("\n\t LSP Buffersize: %u",EXTRACT_16BITS(tptr));
2266 break;
2267
2268 case ISIS_TLV_PART_DIS:
2269 while (tmp >= SYSTEM_ID_LEN) {
2270 if (!TTEST2(*tptr, SYSTEM_ID_LEN))
2271 goto trunctlv;
2272 printf("\n\t %s",isis_print_id(tptr,SYSTEM_ID_LEN));
2273 tptr+=SYSTEM_ID_LEN;
2274 tmp-=SYSTEM_ID_LEN;
2275 }
2276 break;
2277
2278 case ISIS_TLV_PREFIX_NEIGH:
2279 if (!TTEST2(*tptr, sizeof(struct isis_metric_block)))
2280 goto trunctlv;
2281 printf("\n\t Metric Block");
2282 isis_print_metric_block((const struct isis_metric_block *)tptr);
2283 tptr+=sizeof(struct isis_metric_block);
2284 tmp-=sizeof(struct isis_metric_block);
2285
2286 while(tmp>0) {
2287 if (!TTEST2(*tptr, 1))
2288 goto trunctlv;
2289 prefix_len=*tptr++; /* read out prefix length in semioctets*/
2290 tmp--;
2291 if (!TTEST2(*tptr, prefix_len/2))
2292 goto trunctlv;
2293 printf("\n\t\tAddress: %s/%u",
2294 print_nsap(tptr,prefix_len/2),
2295 prefix_len*4);
2296 tptr+=prefix_len/2;
2297 tmp-=prefix_len/2;
2298 }
2299 break;
2300
2301 case ISIS_TLV_IIH_SEQNR:
2302 if (!TTEST2(*tptr, 4)) /* check if four bytes are on the wire */
2303 goto trunctlv;
2304 printf("\n\t Sequence number: %u", EXTRACT_32BITS(tptr) );
2305 break;
2306
2307 case ISIS_TLV_VENDOR_PRIVATE:
2308 if (!TTEST2(*tptr, 3)) /* check if enough byte for a full oui */
2309 goto trunctlv;
2310 vendor_id = EXTRACT_24BITS(tptr);
2311 printf("\n\t Vendor: %s (%u)",
2312 tok2str(oui_values,"Unknown",vendor_id),
2313 vendor_id);
2314 tptr+=3;
2315 tmp-=3;
2316 if (tmp > 0) /* hexdump the rest */
2317 if(!print_unknown_data(tptr,"\n\t\t",tmp))
2318 return(0);
2319 break;
2320 /*
2321 * FIXME those are the defined TLVs that lack a decoder
2322 * you are welcome to contribute code ;-)
2323 */
2324
2325 case ISIS_TLV_DECNET_PHASE4:
2326 case ISIS_TLV_LUCENT_PRIVATE:
2327 case ISIS_TLV_IPAUTH:
2328 case ISIS_TLV_NORTEL_PRIVATE1:
2329 case ISIS_TLV_NORTEL_PRIVATE2:
2330
2331 default:
2332 if (vflag <= 1) {
2333 if(!print_unknown_data(pptr,"\n\t\t",tlv_len))
2334 return(0);
2335 }
2336 break;
2337 }
2338 /* do we want to see an additionally hexdump ? */
2339 if (vflag> 1) {
2340 if(!print_unknown_data(pptr,"\n\t ",tlv_len))
2341 return(0);
2342 }
2343
2344 pptr += tlv_len;
2345 packet_len -= tlv_len;
2346 }
2347
2348 if (packet_len != 0) {
2349 printf("\n\t %u straggler bytes", packet_len);
2350 }
2351 return (1);
2352
2353 trunc:
2354 fputs("[|isis]", stdout);
2355 return (1);
2356
2357 trunctlv:
2358 printf("\n\t\t packet exceeded snapshot");
2359 return(1);
2360 }
2361
2362 /*
2363 * Verify the checksum. See 8473-1, Appendix C, section C.4.
2364 */
2365
2366 static int
2367 osi_cksum(const u_int8_t *tptr, u_int len)
2368 {
2369 int32_t c0 = 0, c1 = 0;
2370
2371 while ((int)--len >= 0) {
2372 c0 += *tptr++;
2373 c0 %= 255;
2374 c1 += c0;
2375 c1 %= 255;
2376 }
2377 return (c0 | c1);
2378 }