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