]> The Tcpdump Group git mirrors - tcpdump/blob - print-isoclns.c
provide multiline output for PIM Joins/Grafts/Graft-Acks
[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.118 2004-03-18 10:58:17 hannes Exp $ (LBL)";
30 #endif
31
32 #ifdef HAVE_CONFIG_H
33 #include "config.h"
34 #endif
35
36 #include <tcpdump-stdinc.h>
37
38 #include <stdio.h>
39 #include <string.h>
40
41 #include "interface.h"
42 #include "addrtoname.h"
43 #include "ethertype.h"
44 #include "ether.h"
45 #include "extract.h"
46 #include "gmpls.h"
47 #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 printf(", 0x%08x", EXTRACT_32BITS(tptr));
1064 if (subl == 8) /* draft-ietf-isis-gmpls-extensions */
1065 printf(", 0x%08x", EXTRACT_32BITS(tptr+4));
1066 break;
1067 case ISIS_SUBTLV_EXT_IS_REACH_IPV4_INTF_ADDR:
1068 case ISIS_SUBTLV_EXT_IS_REACH_IPV4_NEIGHBOR_ADDR:
1069 printf(", %s", ipaddr_string(tptr));
1070 break;
1071 case ISIS_SUBTLV_EXT_IS_REACH_MAX_LINK_BW :
1072 case ISIS_SUBTLV_EXT_IS_REACH_RESERVABLE_BW:
1073 bw.i = EXTRACT_32BITS(tptr);
1074 printf(", %.3f Mbps", bw.f*8/1000000 );
1075 break;
1076 case ISIS_SUBTLV_EXT_IS_REACH_UNRESERVED_BW :
1077 for (priority_level = 0; priority_level < 8; priority_level++) {
1078 bw.i = EXTRACT_32BITS(tptr);
1079 printf("%s priority level %d: %.3f Mbps",
1080 ident,
1081 priority_level,
1082 bw.f*8/1000000 );
1083 tptr+=4;
1084 }
1085 break;
1086 case ISIS_SUBTLV_EXT_IS_REACH_DIFFSERV_TE:
1087 printf("%sBandwidth Constraints Model ID: (%u)",ident, *tptr);
1088 tptr+=4;
1089 /* for now lets just print the first 8 BCs -
1090 * FIXME is this dep. on the BC model ?
1091 */
1092 for (bandwidth_constraint = 0; bandwidth_constraint < 8; bandwidth_constraint++) {
1093 bw.i = EXTRACT_32BITS(tptr);
1094 printf("%s Bandwidth constraint %d: %.3f Mbps",
1095 ident,
1096 bandwidth_constraint,
1097 bw.f*8/1000000 );
1098 tptr+=4;
1099 }
1100 break;
1101 case ISIS_SUBTLV_EXT_IS_REACH_TE_METRIC:
1102 printf(", %u", EXTRACT_24BITS(tptr));
1103 break;
1104 case ISIS_SUBTLV_EXT_IS_REACH_LINK_PROTECTION_TYPE:
1105 printf(", %s, Priority %u",
1106 bittok2str(gmpls_link_prot_values, "none", *tptr),
1107 *(tptr+1));
1108 break;
1109 case ISIS_SUBTLV_EXT_IS_REACH_INTF_SW_CAP_DESCR:
1110 printf("%s Interface Switching Capability:%s",
1111 ident,
1112 tok2str(gmpls_switch_cap_values, "Unknown", *(tptr)));
1113 printf(", LSP Encoding: %s",
1114 tok2str(gmpls_encoding_values, "Unknown", *(tptr+1)));
1115 tptr+=4;
1116 printf("%s Max LSP Bandwidth:",ident);
1117 for (priority_level = 0; priority_level < 8; priority_level++) {
1118 bw.i = EXTRACT_32BITS(tptr);
1119 printf("%s priority level %d: %.3f Mbps",
1120 ident,
1121 priority_level,
1122 bw.f*8/1000000 );
1123 tptr+=4;
1124 }
1125 subl-=36;
1126 /* there is some optional stuff left to decode but this is as of yet
1127 not specified so just lets hexdump what is left */
1128 if(subl>0){
1129 if(!print_unknown_data(tptr,"\n\t\t ",
1130 subl-36))
1131 return(0);
1132 }
1133 break;
1134 default:
1135 if(!print_unknown_data(tptr,"\n\t\t ",
1136 subl))
1137 return(0);
1138 break;
1139 }
1140 return(1);
1141
1142 trunctlv:
1143 printf("%spacket exceeded snapshot",ident);
1144 return(0);
1145 }
1146
1147
1148 /*
1149 * this is the common IS-REACH decoder it is called
1150 * from various EXTD-IS REACH style TLVs (22,24,222)
1151 */
1152
1153 static int
1154 isis_print_ext_is_reach (const u_int8_t *tptr,const char *ident, int tlv_type) {
1155
1156 char ident_buffer[20];
1157 int subtlv_type,subtlv_len,subtlv_sum_len;
1158 int proc_bytes = 0; /* how many bytes did we process ? */
1159
1160 if (!TTEST2(*tptr, NODE_ID_LEN))
1161 return(0);
1162
1163 printf("%sIS Neighbor: %s", ident, isis_print_id(tptr, NODE_ID_LEN));
1164 tptr+=(NODE_ID_LEN);
1165
1166 if (tlv_type != ISIS_TLV_IS_ALIAS_ID) { /* the Alias TLV Metric field is implicit 0 */
1167 if (!TTEST2(*tptr, 3)) /* and is therefore skipped */
1168 return(0);
1169 printf(", Metric: %d",EXTRACT_24BITS(tptr));
1170 tptr+=3;
1171 }
1172
1173 if (!TTEST2(*tptr, 1))
1174 return(0);
1175 subtlv_sum_len=*(tptr++); /* read out subTLV length */
1176 proc_bytes=NODE_ID_LEN+3+1;
1177 printf(", %ssub-TLVs present",subtlv_sum_len ? "" : "no ");
1178 if (subtlv_sum_len) {
1179 printf(" (%u)",subtlv_sum_len);
1180 while (subtlv_sum_len>0) {
1181 if (!TTEST2(*tptr,2))
1182 return(0);
1183 subtlv_type=*(tptr++);
1184 subtlv_len=*(tptr++);
1185 /* prepend the ident string */
1186 snprintf(ident_buffer, sizeof(ident_buffer), "%s ",ident);
1187 if(!isis_print_is_reach_subtlv(tptr,subtlv_type,subtlv_len,ident_buffer))
1188 return(0);
1189 tptr+=subtlv_len;
1190 subtlv_sum_len-=(subtlv_len+2);
1191 proc_bytes+=(subtlv_len+2);
1192 }
1193 }
1194 return(proc_bytes);
1195 }
1196
1197 /*
1198 * this is the common Multi Topology ID decoder
1199 * it is called from various MT-TLVs (222,229,235,237)
1200 */
1201
1202 static int
1203 isis_print_mtid (const u_int8_t *tptr,const char *ident) {
1204
1205 if (!TTEST2(*tptr, 2))
1206 return(0);
1207
1208 printf("%s%s",
1209 ident,
1210 tok2str(isis_mt_values,
1211 "Reserved for IETF Consensus",
1212 ISIS_MASK_MTID(EXTRACT_16BITS(tptr))));
1213
1214 printf(" Topology (0x%03x), Flags: [%s]",
1215 ISIS_MASK_MTID(EXTRACT_16BITS(tptr)),
1216 bittok2str(isis_mt_flag_values, "none",ISIS_MASK_MTFLAGS(EXTRACT_16BITS(tptr))));
1217
1218 return(2);
1219 }
1220
1221 /*
1222 * this is the common extended IP reach decoder
1223 * it is called from TLVs (135,235,236,237)
1224 * we process the TLV and optional subTLVs and return
1225 * the amount of processed bytes
1226 */
1227
1228 static int
1229 isis_print_extd_ip_reach (const u_int8_t *tptr, const char *ident, u_int16_t afi) {
1230
1231 char ident_buffer[20];
1232 u_int8_t prefix[16]; /* shared copy buffer for IPv4 and IPv6 prefixes */
1233 u_int metric, status_byte, bit_length, byte_length, sublen, processed, subtlvtype, subtlvlen;
1234
1235 if (!TTEST2(*tptr, 4))
1236 return (0);
1237 metric = EXTRACT_32BITS(tptr);
1238 processed=4;
1239 tptr+=4;
1240
1241 if (afi == IPV4) {
1242 if (!TTEST2(*tptr, 1)) /* fetch status byte */
1243 return (0);
1244 status_byte=*(tptr++);
1245 bit_length = status_byte&0x3f;
1246 processed++;
1247 #ifdef INET6
1248 } else if (afi == IPV6) {
1249 if (!TTEST2(*tptr, 1)) /* fetch status & prefix_len byte */
1250 return (0);
1251 status_byte=*(tptr++);
1252 bit_length=*(tptr++);
1253 processed+=2;
1254 #endif
1255 } else
1256 return (0); /* somebody is fooling us */
1257
1258 byte_length = (bit_length + 7) / 8; /* prefix has variable length encoding */
1259
1260 if (!TTEST2(*tptr, byte_length))
1261 return (0);
1262 memset(prefix, 0, 16); /* clear the copy buffer */
1263 memcpy(prefix,tptr,byte_length); /* copy as much as is stored in the TLV */
1264 tptr+=byte_length;
1265 processed+=byte_length;
1266
1267 if (afi == IPV4)
1268 printf("%sIPv4 prefix: %15s/%u",
1269 ident,
1270 ipaddr_string(prefix),
1271 bit_length);
1272 #ifdef INET6
1273 if (afi == IPV6)
1274 printf("%sIPv6 prefix: %s/%u",
1275 ident,
1276 ip6addr_string(prefix),
1277 bit_length);
1278 #endif
1279
1280 printf(", Distribution: %s, Metric: %u",
1281 ISIS_MASK_TLV_EXTD_IP_UPDOWN(status_byte) ? "down" : "up",
1282 metric);
1283
1284 if (afi == IPV4 && ISIS_MASK_TLV_EXTD_IP_SUBTLV(status_byte))
1285 printf(", sub-TLVs present");
1286 #ifdef INET6
1287 if (afi == IPV6)
1288 printf(", %s%s",
1289 ISIS_MASK_TLV_EXTD_IP6_IE(status_byte) ? "External" : "Internal",
1290 ISIS_MASK_TLV_EXTD_IP6_SUBTLV(status_byte) ? ", sub-TLVs present" : "");
1291 #endif
1292
1293 if ((ISIS_MASK_TLV_EXTD_IP_SUBTLV(status_byte) && afi == IPV4) ||
1294 (ISIS_MASK_TLV_EXTD_IP6_SUBTLV(status_byte) && afi == IPV6)) {
1295 /* assume that one prefix can hold more
1296 than one subTLV - therefore the first byte must reflect
1297 the aggregate bytecount of the subTLVs for this prefix
1298 */
1299 if (!TTEST2(*tptr, 1))
1300 return (0);
1301 sublen=*(tptr++);
1302 processed+=sublen+1;
1303 printf(" (%u)",sublen); /* print out subTLV length */
1304
1305 while (sublen>0) {
1306 if (!TTEST2(*tptr,2))
1307 return (0);
1308 subtlvtype=*(tptr++);
1309 subtlvlen=*(tptr++);
1310 /* prepend the ident string */
1311 snprintf(ident_buffer, sizeof(ident_buffer), "%s ",ident);
1312 if(!isis_print_ip_reach_subtlv(tptr,subtlvtype,subtlvlen,ident_buffer))
1313 return(0);
1314 tptr+=subtlvlen;
1315 sublen-=(subtlvlen+2);
1316 }
1317 }
1318 return (processed);
1319 }
1320
1321 /*
1322 * isis_print
1323 * Decode IS-IS packets. Return 0 on error.
1324 */
1325
1326 static int isis_print (const u_int8_t *p, u_int length)
1327 {
1328 const struct isis_common_header *isis_header;
1329
1330 const struct isis_iih_lan_header *header_iih_lan;
1331 const struct isis_iih_ptp_header *header_iih_ptp;
1332 const struct isis_lsp_header *header_lsp;
1333 const struct isis_csnp_header *header_csnp;
1334 const struct isis_psnp_header *header_psnp;
1335
1336 const struct isis_tlv_lsp *tlv_lsp;
1337 const struct isis_tlv_ptp_adj *tlv_ptp_adj;
1338 const struct isis_tlv_is_reach *tlv_is_reach;
1339 const struct isis_tlv_es_reach *tlv_es_reach;
1340
1341 u_int8_t pdu_type, max_area, id_length, tlv_type, tlv_len, tmp, alen, lan_alen, prefix_len;
1342 u_int8_t ext_is_len, ext_ip_len, mt_len;
1343 const u_int8_t *optr, *pptr, *tptr;
1344 u_short packet_len,pdu_len;
1345 u_int i,vendor_id;
1346
1347 packet_len=length;
1348 optr = p; /* initialize the _o_riginal pointer to the packet start -
1349 need it for parsing the checksum TLV */
1350 isis_header = (const struct isis_common_header *)p;
1351 TCHECK(*isis_header);
1352 pptr = p+(ISIS_COMMON_HEADER_SIZE);
1353 header_iih_lan = (const struct isis_iih_lan_header *)pptr;
1354 header_iih_ptp = (const struct isis_iih_ptp_header *)pptr;
1355 header_lsp = (const struct isis_lsp_header *)pptr;
1356 header_csnp = (const struct isis_csnp_header *)pptr;
1357 header_psnp = (const struct isis_psnp_header *)pptr;
1358
1359 /*
1360 * Sanity checking of the header.
1361 */
1362
1363 if (isis_header->version != ISIS_VERSION) {
1364 printf(", version %d packet not supported", isis_header->version);
1365 return (0);
1366 }
1367
1368 if ((isis_header->id_length != SYSTEM_ID_LEN) && (isis_header->id_length != 0)) {
1369 printf(", system ID length of %d is not supported",
1370 isis_header->id_length);
1371 return (0);
1372 }
1373
1374 if (isis_header->pdu_version != ISIS_VERSION) {
1375 printf(", version %d packet not supported", isis_header->pdu_version);
1376 return (0);
1377 }
1378
1379 max_area = isis_header->max_area;
1380 switch(max_area) {
1381 case 0:
1382 max_area = 3; /* silly shit */
1383 break;
1384 case 255:
1385 printf(", bad packet -- 255 areas");
1386 return (0);
1387 default:
1388 break;
1389 }
1390
1391 id_length = isis_header->id_length;
1392 switch(id_length) {
1393 case 0:
1394 id_length = 6; /* silly shit again */
1395 break;
1396 case 1: /* 1-8 are valid sys-ID lenghts */
1397 case 2:
1398 case 3:
1399 case 4:
1400 case 5:
1401 case 6:
1402 case 7:
1403 case 8:
1404 break;
1405 case 255:
1406 id_length = 0; /* entirely useless */
1407 break;
1408 default:
1409 break;
1410 }
1411
1412 /* toss any non 6-byte sys-ID len PDUs */
1413 if (id_length != 6 ) {
1414 printf(", bad packet -- illegal sys-ID length (%u)", id_length);
1415 return (0);
1416 }
1417
1418 pdu_type=isis_header->pdu_type;
1419
1420 /* in non-verbose mode print the basic PDU Type plus PDU specific brief information*/
1421 if (vflag < 1) {
1422 printf(", %s", tok2str(isis_pdu_values,"unknown PDU-Type %u",pdu_type));
1423
1424 switch (pdu_type) {
1425
1426 case ISIS_PDU_L1_LAN_IIH:
1427 case ISIS_PDU_L2_LAN_IIH:
1428 printf(", src-id %s",
1429 isis_print_id(header_iih_lan->source_id,SYSTEM_ID_LEN));
1430 printf(", lan-id %s, prio %u",
1431 isis_print_id(header_iih_lan->lan_id,NODE_ID_LEN),
1432 header_iih_lan->priority);
1433 break;
1434 case ISIS_PDU_PTP_IIH:
1435 printf(", src-id %s", isis_print_id(header_iih_ptp->source_id,SYSTEM_ID_LEN));
1436 break;
1437 case ISIS_PDU_L1_LSP:
1438 case ISIS_PDU_L2_LSP:
1439 printf(", lsp-id %s, seq 0x%08x, lifetime %5us",
1440 isis_print_id(header_lsp->lsp_id, LSP_ID_LEN),
1441 EXTRACT_32BITS(header_lsp->sequence_number),
1442 EXTRACT_16BITS(header_lsp->remaining_lifetime));
1443 break;
1444 case ISIS_PDU_L1_CSNP:
1445 case ISIS_PDU_L2_CSNP:
1446 printf(", src-id %s", isis_print_id(header_csnp->source_id,SYSTEM_ID_LEN));
1447 break;
1448 case ISIS_PDU_L1_PSNP:
1449 case ISIS_PDU_L2_PSNP:
1450 printf(", src-id %s", isis_print_id(header_psnp->source_id,SYSTEM_ID_LEN));
1451 break;
1452
1453 }
1454 printf(", length %u", length);
1455
1456 return(1);
1457 }
1458
1459 /* ok they seem to want to know everything - lets fully decode it */
1460 printf(", length: %u",length);
1461
1462 printf("\n\t%s, hlen: %u, v: %u, pdu-v: %u, sys-id-len: %u (%u), max-area: %u (%u)",
1463 tok2str(isis_pdu_values,
1464 "unknown, type %u",
1465 pdu_type),
1466 isis_header->fixed_len,
1467 isis_header->version,
1468 isis_header->pdu_version,
1469 id_length,
1470 isis_header->id_length,
1471 max_area,
1472 isis_header->max_area);
1473
1474 if (vflag > 1) {
1475 if(!print_unknown_data(optr,"\n\t",8)) /* provide the _o_riginal pointer */
1476 return(0); /* for optionally debugging the common header */
1477 }
1478
1479 switch (pdu_type) {
1480
1481 case ISIS_PDU_L1_LAN_IIH:
1482 case ISIS_PDU_L2_LAN_IIH:
1483 if (isis_header->fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_LAN_HEADER_SIZE)) {
1484 printf(", bogus fixed header length %u should be %lu",
1485 isis_header->fixed_len, (unsigned long)ISIS_IIH_LAN_HEADER_SIZE);
1486 return (0);
1487 }
1488
1489 pdu_len=EXTRACT_16BITS(header_iih_lan->pdu_len);
1490 if (packet_len>pdu_len) {
1491 packet_len=pdu_len; /* do TLV decoding as long as it makes sense */
1492 length=pdu_len;
1493 }
1494
1495 TCHECK(*header_iih_lan);
1496 printf("\n\t source-id: %s, holding time: %us, Flags: [%s]",
1497 isis_print_id(header_iih_lan->source_id,SYSTEM_ID_LEN),
1498 EXTRACT_16BITS(header_iih_lan->holding_time),
1499 tok2str(isis_iih_circuit_type_values,
1500 "unknown circuit type 0x%02x",
1501 header_iih_lan->circuit_type));
1502
1503 printf("\n\t lan-id: %s, Priority: %u, PDU length: %u",
1504 isis_print_id(header_iih_lan->lan_id, NODE_ID_LEN),
1505 (header_iih_lan->priority) & ISIS_LAN_PRIORITY_MASK,
1506 pdu_len);
1507
1508 if (vflag > 1) {
1509 if(!print_unknown_data(pptr,"\n\t ",ISIS_IIH_LAN_HEADER_SIZE))
1510 return(0);
1511 }
1512
1513 packet_len -= (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_LAN_HEADER_SIZE);
1514 pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_LAN_HEADER_SIZE);
1515 break;
1516
1517 case ISIS_PDU_PTP_IIH:
1518 if (isis_header->fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_PTP_HEADER_SIZE)) {
1519 printf(", bogus fixed header length %u should be %lu",
1520 isis_header->fixed_len, (unsigned long)ISIS_IIH_PTP_HEADER_SIZE);
1521 return (0);
1522 }
1523
1524 pdu_len=EXTRACT_16BITS(header_iih_ptp->pdu_len);
1525 if (packet_len>pdu_len) {
1526 packet_len=pdu_len; /* do TLV decoding as long as it makes sense */
1527 length=pdu_len;
1528 }
1529
1530 TCHECK(*header_iih_ptp);
1531 printf("\n\t source-id: %s, holding time: %us, Flags: [%s]",
1532 isis_print_id(header_iih_ptp->source_id,SYSTEM_ID_LEN),
1533 EXTRACT_16BITS(header_iih_ptp->holding_time),
1534 tok2str(isis_iih_circuit_type_values,
1535 "unknown circuit type 0x%02x",
1536 header_iih_ptp->circuit_type));
1537
1538 printf("\n\t circuit-id: 0x%02x, PDU length: %u",
1539 header_iih_ptp->circuit_id,
1540 pdu_len);
1541
1542 if (vflag > 1) {
1543 if(!print_unknown_data(pptr,"\n\t ",ISIS_IIH_PTP_HEADER_SIZE))
1544 return(0);
1545 }
1546
1547 packet_len -= (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_PTP_HEADER_SIZE);
1548 pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_PTP_HEADER_SIZE);
1549 break;
1550
1551 case ISIS_PDU_L1_LSP:
1552 case ISIS_PDU_L2_LSP:
1553 if (isis_header->fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_LSP_HEADER_SIZE)) {
1554 printf(", bogus fixed header length %u should be %lu",
1555 isis_header->fixed_len, (unsigned long)ISIS_LSP_HEADER_SIZE);
1556 return (0);
1557 }
1558
1559 pdu_len=EXTRACT_16BITS(header_lsp->pdu_len);
1560 if (packet_len>pdu_len) {
1561 packet_len=pdu_len; /* do TLV decoding as long as it makes sense */
1562 length=pdu_len;
1563 }
1564
1565 TCHECK(*header_lsp);
1566 printf("\n\t lsp-id: %s, seq: 0x%08x, lifetime: %5us\n\t chksum: 0x%04x",
1567 isis_print_id(header_lsp->lsp_id, LSP_ID_LEN),
1568 EXTRACT_32BITS(header_lsp->sequence_number),
1569 EXTRACT_16BITS(header_lsp->remaining_lifetime),
1570 EXTRACT_16BITS(header_lsp->checksum));
1571
1572 /* if this is a purge do not attempt to verify the checksum */
1573 if ( EXTRACT_16BITS(header_lsp->remaining_lifetime) == 0 &&
1574 EXTRACT_16BITS(header_lsp->checksum) == 0)
1575 printf(" (purged)");
1576 else
1577 /* verify the checksum -
1578 * checking starts at the lsp-id field at byte position [12]
1579 * hence the length needs to be reduced by 12 bytes */
1580 printf(" (%s)", (osi_cksum((u_int8_t *)header_lsp->lsp_id, length-12)) ? "incorrect" : "correct");
1581
1582 printf(", PDU length: %u, Flags: [ %s",
1583 pdu_len,
1584 ISIS_MASK_LSP_OL_BIT(header_lsp->typeblock) ? "Overload bit set, " : "");
1585
1586 if (ISIS_MASK_LSP_ATT_BITS(header_lsp->typeblock)) {
1587 printf("%s", ISIS_MASK_LSP_ATT_DEFAULT_BIT(header_lsp->typeblock) ? "default " : "");
1588 printf("%s", ISIS_MASK_LSP_ATT_DELAY_BIT(header_lsp->typeblock) ? "delay " : "");
1589 printf("%s", ISIS_MASK_LSP_ATT_EXPENSE_BIT(header_lsp->typeblock) ? "expense " : "");
1590 printf("%s", ISIS_MASK_LSP_ATT_ERROR_BIT(header_lsp->typeblock) ? "error " : "");
1591 printf("ATT bit set, ");
1592 }
1593 printf("%s", ISIS_MASK_LSP_PARTITION_BIT(header_lsp->typeblock) ? "P bit set, " : "");
1594 printf("%s ]", tok2str(isis_lsp_istype_values,"Unknown(0x%x)",ISIS_MASK_LSP_ISTYPE_BITS(header_lsp->typeblock)));
1595
1596 if (vflag > 1) {
1597 if(!print_unknown_data(pptr,"\n\t ",ISIS_LSP_HEADER_SIZE))
1598 return(0);
1599 }
1600
1601 packet_len -= (ISIS_COMMON_HEADER_SIZE+ISIS_LSP_HEADER_SIZE);
1602 pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_LSP_HEADER_SIZE);
1603 break;
1604
1605 case ISIS_PDU_L1_CSNP:
1606 case ISIS_PDU_L2_CSNP:
1607 if (isis_header->fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_CSNP_HEADER_SIZE)) {
1608 printf(", bogus fixed header length %u should be %lu",
1609 isis_header->fixed_len, (unsigned long)ISIS_CSNP_HEADER_SIZE);
1610 return (0);
1611 }
1612
1613 pdu_len=EXTRACT_16BITS(header_csnp->pdu_len);
1614 if (packet_len>pdu_len) {
1615 packet_len=pdu_len; /* do TLV decoding as long as it makes sense */
1616 length=pdu_len;
1617 }
1618
1619 TCHECK(*header_csnp);
1620 printf("\n\t source-id: %s, PDU length: %u",
1621 isis_print_id(header_csnp->source_id, NODE_ID_LEN),
1622 pdu_len);
1623 printf("\n\t start lsp-id: %s",
1624 isis_print_id(header_csnp->start_lsp_id, LSP_ID_LEN));
1625 printf("\n\t end lsp-id: %s",
1626 isis_print_id(header_csnp->end_lsp_id, LSP_ID_LEN));
1627
1628 if (vflag > 1) {
1629 if(!print_unknown_data(pptr,"\n\t ",ISIS_CSNP_HEADER_SIZE))
1630 return(0);
1631 }
1632
1633 packet_len -= (ISIS_COMMON_HEADER_SIZE+ISIS_CSNP_HEADER_SIZE);
1634 pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_CSNP_HEADER_SIZE);
1635 break;
1636
1637 case ISIS_PDU_L1_PSNP:
1638 case ISIS_PDU_L2_PSNP:
1639 if (isis_header->fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_PSNP_HEADER_SIZE)) {
1640 printf("- bogus fixed header length %u should be %lu",
1641 isis_header->fixed_len, (unsigned long)ISIS_PSNP_HEADER_SIZE);
1642 return (0);
1643 }
1644
1645 pdu_len=EXTRACT_16BITS(header_psnp->pdu_len);
1646 if (packet_len>pdu_len) {
1647 packet_len=pdu_len; /* do TLV decoding as long as it makes sense */
1648 length=pdu_len;
1649 }
1650
1651 TCHECK(*header_psnp);
1652 printf("\n\t source-id: %s, PDU length: %u",
1653 isis_print_id(header_psnp->source_id, NODE_ID_LEN),
1654 pdu_len);
1655
1656 if (vflag > 1) {
1657 if(!print_unknown_data(pptr,"\n\t ",ISIS_PSNP_HEADER_SIZE))
1658 return(0);
1659 }
1660
1661 packet_len -= (ISIS_COMMON_HEADER_SIZE+ISIS_PSNP_HEADER_SIZE);
1662 pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_PSNP_HEADER_SIZE);
1663 break;
1664
1665 default:
1666 if(!print_unknown_data(pptr,"\n\t ",length))
1667 return(0);
1668 return (0);
1669 }
1670
1671 /*
1672 * Now print the TLV's.
1673 */
1674
1675 while (packet_len >= 2) {
1676 if (pptr == snapend) {
1677 return (1);
1678 }
1679
1680 if (!TTEST2(*pptr, 2)) {
1681 printf("\n\t\t packet exceeded snapshot (%ld) bytes",
1682 (long)(pptr-snapend));
1683 return (1);
1684 }
1685 tlv_type = *pptr++;
1686 tlv_len = *pptr++;
1687 tmp =tlv_len; /* copy temporary len & pointer to packet data */
1688 tptr = pptr;
1689 packet_len -= 2;
1690 if (tlv_len > packet_len) {
1691 break;
1692 }
1693
1694 /* first lets see if we know the TLVs name*/
1695 printf("\n\t %s TLV #%u, length: %u",
1696 tok2str(isis_tlv_values,
1697 "unknown",
1698 tlv_type),
1699 tlv_type,
1700 tlv_len);
1701
1702 /* now check if we have a decoder otherwise do a hexdump at the end*/
1703 switch (tlv_type) {
1704 case ISIS_TLV_AREA_ADDR:
1705 if (!TTEST2(*tptr, 1))
1706 goto trunctlv;
1707 alen = *tptr++;
1708 while (tmp && alen < tmp) {
1709 printf("\n\t Area address (length: %u): %s",
1710 alen,
1711 print_nsap(tptr, alen));
1712 tptr += alen;
1713 tmp -= alen + 1;
1714 if (tmp==0) /* if this is the last area address do not attemt a boundary check */
1715 break;
1716 if (!TTEST2(*tptr, 1))
1717 goto trunctlv;
1718 alen = *tptr++;
1719 }
1720 break;
1721 case ISIS_TLV_ISNEIGH:
1722 while (tmp >= ETHER_ADDR_LEN) {
1723 if (!TTEST2(*tptr, ETHER_ADDR_LEN))
1724 goto trunctlv;
1725 printf("\n\t SNPA: %s",isis_print_id(tptr,ETHER_ADDR_LEN));
1726 tmp -= ETHER_ADDR_LEN;
1727 tptr += ETHER_ADDR_LEN;
1728 }
1729 break;
1730
1731 case ISIS_TLV_ISNEIGH_VARLEN:
1732 if (!TTEST2(*tptr, 1))
1733 goto trunctlv;
1734 lan_alen = *tptr++; /* LAN adress length */
1735 tmp --;
1736 printf("\n\t LAN address length %u bytes ",lan_alen);
1737 while (tmp >= lan_alen) {
1738 if (!TTEST2(*tptr, lan_alen))
1739 goto trunctlv;
1740 printf("\n\t\tIS Neighbor: %s",isis_print_id(tptr,lan_alen));
1741 tmp -= lan_alen;
1742 tptr +=lan_alen;
1743 }
1744 break;
1745
1746 case ISIS_TLV_PADDING:
1747 break;
1748
1749 case ISIS_TLV_MT_IS_REACH:
1750 while (tmp >= 2+NODE_ID_LEN+3+1) {
1751 mt_len = isis_print_mtid(tptr, "\n\t ");
1752 if (mt_len == 0) /* did something go wrong ? */
1753 goto trunctlv;
1754 tptr+=mt_len;
1755 tmp-=mt_len;
1756
1757 ext_is_len = isis_print_ext_is_reach(tptr,"\n\t ",tlv_type);
1758 if (ext_is_len == 0) /* did something go wrong ? */
1759 goto trunctlv;
1760
1761 tmp-=ext_is_len;
1762 tptr+=ext_is_len;
1763 }
1764 break;
1765
1766 case ISIS_TLV_IS_ALIAS_ID:
1767 while (tmp >= NODE_ID_LEN+1) { /* is it worth attempting a decode ? */
1768 ext_is_len = isis_print_ext_is_reach(tptr,"\n\t ",tlv_type);
1769 if (ext_is_len == 0) /* did something go wrong ? */
1770 goto trunctlv;
1771 tmp-=ext_is_len;
1772 tptr+=ext_is_len;
1773 }
1774 break;
1775
1776 case ISIS_TLV_EXT_IS_REACH:
1777 while (tmp >= NODE_ID_LEN+3+1) { /* is it worth attempting a decode ? */
1778 ext_is_len = isis_print_ext_is_reach(tptr,"\n\t ",tlv_type);
1779 if (ext_is_len == 0) /* did something go wrong ? */
1780 goto trunctlv;
1781 tmp-=ext_is_len;
1782 tptr+=ext_is_len;
1783 }
1784 break;
1785 case ISIS_TLV_IS_REACH:
1786 if (!TTEST2(*tptr,1)) /* check if there is one byte left to read out the virtual flag */
1787 goto trunctlv;
1788 printf("\n\t %s",
1789 tok2str(isis_is_reach_virtual_values,
1790 "bogus virtual flag 0x%02x",
1791 *tptr++));
1792 tlv_is_reach = (const struct isis_tlv_is_reach *)tptr;
1793 while (tmp >= sizeof(struct isis_tlv_is_reach)) {
1794 if (!TTEST(*tlv_is_reach))
1795 goto trunctlv;
1796 printf("\n\t IS Neighbor: %s",
1797 isis_print_id(tlv_is_reach->neighbor_nodeid, NODE_ID_LEN));
1798 isis_print_metric_block(&tlv_is_reach->isis_metric_block);
1799 tmp -= sizeof(struct isis_tlv_is_reach);
1800 tlv_is_reach++;
1801 }
1802 break;
1803
1804 case ISIS_TLV_ESNEIGH:
1805 tlv_es_reach = (const struct isis_tlv_es_reach *)tptr;
1806 while (tmp >= sizeof(struct isis_tlv_es_reach)) {
1807 if (!TTEST(*tlv_es_reach))
1808 goto trunctlv;
1809 printf("\n\t ES Neighbor: %s",
1810 isis_print_id(tlv_es_reach->neighbor_sysid,SYSTEM_ID_LEN));
1811 isis_print_metric_block(&tlv_es_reach->isis_metric_block);
1812 tmp -= sizeof(struct isis_tlv_es_reach);
1813 tlv_es_reach++;
1814 }
1815 break;
1816
1817 /* those two TLVs share the same format */
1818 case ISIS_TLV_INT_IP_REACH:
1819 case ISIS_TLV_EXT_IP_REACH:
1820 if (!isis_print_tlv_ip_reach(pptr, "\n\t ", tlv_len))
1821 return (1);
1822 break;
1823
1824 case ISIS_TLV_EXTD_IP_REACH:
1825 while (tmp>0) {
1826 ext_ip_len = isis_print_extd_ip_reach(tptr, "\n\t ", IPV4);
1827 if (ext_ip_len == 0) /* did something go wrong ? */
1828 goto trunctlv;
1829 tptr+=ext_ip_len;
1830 tmp-=ext_ip_len;
1831 }
1832 break;
1833
1834 case ISIS_TLV_MT_IP_REACH:
1835 while (tmp>0) {
1836 mt_len = isis_print_mtid(tptr, "\n\t ");
1837 if (mt_len == 0) /* did something go wrong ? */
1838 goto trunctlv;
1839 tptr+=mt_len;
1840 tmp-=mt_len;
1841
1842 ext_ip_len = isis_print_extd_ip_reach(tptr, "\n\t ", IPV4);
1843 if (ext_ip_len == 0) /* did something go wrong ? */
1844 goto trunctlv;
1845 tptr+=ext_ip_len;
1846 tmp-=ext_ip_len;
1847 }
1848 break;
1849
1850 #ifdef INET6
1851 case ISIS_TLV_IP6_REACH:
1852 while (tmp>0) {
1853 ext_ip_len = isis_print_extd_ip_reach(tptr, "\n\t ", IPV6);
1854 if (ext_ip_len == 0) /* did something go wrong ? */
1855 goto trunctlv;
1856 tptr+=ext_ip_len;
1857 tmp-=ext_ip_len;
1858 }
1859 break;
1860
1861 case ISIS_TLV_MT_IP6_REACH:
1862 while (tmp>0) {
1863 mt_len = isis_print_mtid(tptr, "\n\t ");
1864 if (mt_len == 0) /* did something go wrong ? */
1865 goto trunctlv;
1866 tptr+=mt_len;
1867 tmp-=mt_len;
1868
1869 ext_ip_len = isis_print_extd_ip_reach(tptr, "\n\t ", IPV6);
1870 if (ext_ip_len == 0) /* did something go wrong ? */
1871 goto trunctlv;
1872 tptr+=ext_ip_len;
1873 tmp-=ext_ip_len;
1874 }
1875 break;
1876
1877 case ISIS_TLV_IP6ADDR:
1878 while (tmp>0) {
1879 if (!TTEST2(*tptr, 16))
1880 goto trunctlv;
1881
1882 printf("\n\t IPv6 interface address: %s",
1883 ip6addr_string(tptr));
1884
1885 tptr += 16;
1886 tmp -= 16;
1887 }
1888 break;
1889 #endif
1890 case ISIS_TLV_AUTH:
1891 if (!TTEST2(*tptr, 1))
1892 goto trunctlv;
1893
1894 printf("\n\t %s: ",
1895 tok2str(isis_subtlv_auth_values,
1896 "unknown Authentication type 0x%02x",
1897 *tptr));
1898
1899 switch (*tptr) {
1900 case ISIS_SUBTLV_AUTH_SIMPLE:
1901 for(i=1;i<tlv_len;i++) {
1902 if (!TTEST2(*(tptr+i), 1))
1903 goto trunctlv;
1904 printf("%c",*(tptr+i));
1905 }
1906 break;
1907 case ISIS_SUBTLV_AUTH_MD5:
1908 for(i=1;i<tlv_len;i++) {
1909 if (!TTEST2(*(tptr+i), 1))
1910 goto trunctlv;
1911 printf("%02x",*(tptr+i));
1912 }
1913 if (tlv_len != ISIS_SUBTLV_AUTH_MD5_LEN+1)
1914 printf(", (malformed subTLV) ");
1915 break;
1916 case ISIS_SUBTLV_AUTH_PRIVATE:
1917 default:
1918 if(!print_unknown_data(tptr+1,"\n\t\t ",tlv_len-1))
1919 return(0);
1920 break;
1921 }
1922 break;
1923
1924 case ISIS_TLV_PTP_ADJ:
1925 tlv_ptp_adj = (const struct isis_tlv_ptp_adj *)tptr;
1926 if(tmp>=1) {
1927 if (!TTEST2(*tptr, 1))
1928 goto trunctlv;
1929 printf("\n\t Adjacency State: %s (%u)",
1930 tok2str(isis_ptp_adjancey_values, "unknown", *tptr),
1931 *tptr);
1932 tmp--;
1933 }
1934 if(tmp>sizeof(tlv_ptp_adj->extd_local_circuit_id)) {
1935 if (!TTEST2(tlv_ptp_adj->extd_local_circuit_id,
1936 sizeof(tlv_ptp_adj->extd_local_circuit_id)))
1937 goto trunctlv;
1938 printf("\n\t Extended Local circuit-ID: 0x%08x",
1939 EXTRACT_32BITS(tlv_ptp_adj->extd_local_circuit_id));
1940 tmp-=sizeof(tlv_ptp_adj->extd_local_circuit_id);
1941 }
1942 if(tmp>=SYSTEM_ID_LEN) {
1943 if (!TTEST2(tlv_ptp_adj->neighbor_sysid, SYSTEM_ID_LEN))
1944 goto trunctlv;
1945 printf("\n\t Neighbor System-ID: %s",
1946 isis_print_id(tlv_ptp_adj->neighbor_sysid,SYSTEM_ID_LEN));
1947 tmp-=SYSTEM_ID_LEN;
1948 }
1949 if(tmp>=sizeof(tlv_ptp_adj->neighbor_extd_local_circuit_id)) {
1950 if (!TTEST2(tlv_ptp_adj->neighbor_extd_local_circuit_id,
1951 sizeof(tlv_ptp_adj->neighbor_extd_local_circuit_id)))
1952 goto trunctlv;
1953 printf("\n\t Neighbor Extended Local circuit-ID: 0x%08x",
1954 EXTRACT_32BITS(tlv_ptp_adj->neighbor_extd_local_circuit_id));
1955 }
1956 break;
1957
1958 case ISIS_TLV_PROTOCOLS:
1959 printf("\n\t NLPID(s): ");
1960 while (tmp>0) {
1961 if (!TTEST2(*(tptr), 1))
1962 goto trunctlv;
1963 printf("%s (0x%02x)",
1964 tok2str(osi_nlpid_values,
1965 "unknown",
1966 *tptr),
1967 *tptr);
1968 if (tmp>1) /* further NPLIDs ? - put comma */
1969 printf(", ");
1970 tptr++;
1971 tmp--;
1972 }
1973 break;
1974
1975 case ISIS_TLV_TE_ROUTER_ID:
1976 if (!TTEST2(*pptr, 4))
1977 goto trunctlv;
1978 printf("\n\t Traffic Engineering Router ID: %s", ipaddr_string(pptr));
1979 break;
1980
1981 case ISIS_TLV_IPADDR:
1982 while (tmp>0) {
1983 if (!TTEST2(*tptr, 4))
1984 goto trunctlv;
1985 printf("\n\t IPv4 interface address: %s", ipaddr_string(tptr));
1986 tptr += 4;
1987 tmp -= 4;
1988 }
1989 break;
1990
1991 case ISIS_TLV_HOSTNAME:
1992 printf("\n\t Hostname: ");
1993 while (tmp>0) {
1994 if (!TTEST2(*tptr, 1))
1995 goto trunctlv;
1996 printf("%c",*tptr++);
1997 tmp--;
1998 }
1999 break;
2000
2001 case ISIS_TLV_SHARED_RISK_GROUP:
2002 if (!TTEST2(*tptr, NODE_ID_LEN))
2003 goto trunctlv;
2004 printf("\n\t IS Neighbor: %s", isis_print_id(tptr, NODE_ID_LEN));
2005 tptr+=(NODE_ID_LEN);
2006 tmp-=(NODE_ID_LEN);
2007
2008 if (!TTEST2(*tptr, 1))
2009 goto trunctlv;
2010 printf(", Flags: [%s]", ISIS_MASK_TLV_SHARED_RISK_GROUP(*tptr++) ? "numbered" : "unnumbered");
2011 tmp--;
2012
2013 if (!TTEST2(*tptr,4))
2014 goto trunctlv;
2015 printf("\n\t IPv4 interface address: %s", ipaddr_string(tptr));
2016 tptr+=4;
2017 tmp-=4;
2018
2019 if (!TTEST2(*tptr,4))
2020 goto trunctlv;
2021 printf("\n\t IPv4 neighbor address: %s", ipaddr_string(tptr));
2022 tptr+=4;
2023 tmp-=4;
2024
2025 while (tmp>0) {
2026 if (!TTEST2(*tptr, 4))
2027 goto trunctlv;
2028 printf("\n\t Link-ID: 0x%08x", EXTRACT_32BITS(tptr));
2029 tptr+=4;
2030 tmp-=4;
2031 }
2032 break;
2033
2034 case ISIS_TLV_LSP:
2035 tlv_lsp = (const struct isis_tlv_lsp *)tptr;
2036 while(tmp>0) {
2037 if (!TTEST((tlv_lsp->lsp_id)[LSP_ID_LEN-1]))
2038 goto trunctlv;
2039 printf("\n\t lsp-id: %s",
2040 isis_print_id(tlv_lsp->lsp_id, LSP_ID_LEN));
2041 if (!TTEST2(tlv_lsp->sequence_number, 4))
2042 goto trunctlv;
2043 printf(", seq: 0x%08x",EXTRACT_32BITS(tlv_lsp->sequence_number));
2044 if (!TTEST2(tlv_lsp->remaining_lifetime, 2))
2045 goto trunctlv;
2046 printf(", lifetime: %5ds",EXTRACT_16BITS(tlv_lsp->remaining_lifetime));
2047 if (!TTEST2(tlv_lsp->checksum, 2))
2048 goto trunctlv;
2049 printf(", chksum: 0x%04x",EXTRACT_16BITS(tlv_lsp->checksum));
2050 tmp-=sizeof(struct isis_tlv_lsp);
2051 tlv_lsp++;
2052 }
2053 break;
2054
2055 case ISIS_TLV_CHECKSUM:
2056 if (!TTEST2(*tptr, 2))
2057 goto trunctlv;
2058 printf("\n\t checksum: 0x%04x ", EXTRACT_16BITS(tptr));
2059 /* do not attempt to verify the checksum if it is zero
2060 * most likely a HMAC-MD5 TLV is also present and
2061 * to avoid conflicts the checksum TLV is zeroed.
2062 * see rfc3358 for details
2063 */
2064 if (EXTRACT_16BITS(tptr) == 0)
2065 printf("(unverified)");
2066 else printf("(%s)", osi_cksum(optr, length) ? "incorrect" : "correct");
2067 break;
2068
2069 case ISIS_TLV_MT_SUPPORTED:
2070 while (tmp>1) {
2071 /* length can only be a multiple of 2, otherwise there is
2072 something broken -> so decode down until length is 1 */
2073 if (tmp!=1) {
2074 mt_len = isis_print_mtid(tptr, "\n\t ");
2075 if (mt_len == 0) /* did something go wrong ? */
2076 goto trunctlv;
2077 tptr+=mt_len;
2078 tmp-=mt_len;
2079 } else {
2080 printf("\n\t malformed MT-ID");
2081 break;
2082 }
2083 }
2084 break;
2085
2086 case ISIS_TLV_RESTART_SIGNALING:
2087 if (!TTEST2(*tptr, 3))
2088 goto trunctlv;
2089 printf("\n\t Flags [%s], Remaining holding time %us",
2090 bittok2str(isis_restart_flag_values, "none", *tptr),
2091 EXTRACT_16BITS(tptr+1));
2092 tptr+=3;
2093 break;
2094
2095 case ISIS_TLV_IDRP_INFO:
2096 if (!TTEST2(*tptr, 1))
2097 goto trunctlv;
2098 printf("\n\t Inter-Domain Information Type: %s",
2099 tok2str(isis_subtlv_idrp_values,
2100 "Unknown (0x%02x)",
2101 *tptr));
2102 switch (*tptr++) {
2103 case ISIS_SUBTLV_IDRP_ASN:
2104 if (!TTEST2(*tptr, 2)) /* fetch AS number */
2105 goto trunctlv;
2106 printf("AS Number: %u",EXTRACT_16BITS(tptr));
2107 break;
2108 case ISIS_SUBTLV_IDRP_LOCAL:
2109 case ISIS_SUBTLV_IDRP_RES:
2110 default:
2111 if(!print_unknown_data(tptr,"\n\t ",tlv_len-1))
2112 return(0);
2113 break;
2114 }
2115 break;
2116
2117 case ISIS_TLV_LSP_BUFFERSIZE:
2118 if (!TTEST2(*tptr, 2))
2119 goto trunctlv;
2120 printf("\n\t LSP Buffersize: %u",EXTRACT_16BITS(tptr));
2121 break;
2122
2123 case ISIS_TLV_PART_DIS:
2124 while (tmp >= SYSTEM_ID_LEN) {
2125 if (!TTEST2(*tptr, SYSTEM_ID_LEN))
2126 goto trunctlv;
2127 printf("\n\t %s",isis_print_id(tptr,SYSTEM_ID_LEN));
2128 tptr+=SYSTEM_ID_LEN;
2129 tmp-=SYSTEM_ID_LEN;
2130 }
2131 break;
2132
2133 case ISIS_TLV_PREFIX_NEIGH:
2134 if (!TTEST2(*tptr, sizeof(struct isis_metric_block)))
2135 goto trunctlv;
2136 printf("\n\t Metric Block");
2137 isis_print_metric_block((const struct isis_metric_block *)tptr);
2138 tptr+=sizeof(struct isis_metric_block);
2139 tmp-=sizeof(struct isis_metric_block);
2140
2141 while(tmp>0) {
2142 if (!TTEST2(*tptr, 1))
2143 goto trunctlv;
2144 prefix_len=*tptr++; /* read out prefix length in semioctets*/
2145 tmp--;
2146 if (!TTEST2(*tptr, prefix_len/2))
2147 goto trunctlv;
2148 printf("\n\t\tAddress: %s/%u",
2149 print_nsap(tptr,prefix_len/2),
2150 prefix_len*4);
2151 tptr+=prefix_len/2;
2152 tmp-=prefix_len/2;
2153 }
2154 break;
2155
2156 case ISIS_TLV_IIH_SEQNR:
2157 if (!TTEST2(*tptr, 4)) /* check if four bytes are on the wire */
2158 goto trunctlv;
2159 printf("\n\t Sequence number: %u", EXTRACT_32BITS(tptr) );
2160 break;
2161
2162 case ISIS_TLV_VENDOR_PRIVATE:
2163 if (!TTEST2(*tptr, 3)) /* check if enough byte for a full oui */
2164 goto trunctlv;
2165 vendor_id = EXTRACT_24BITS(tptr);
2166 printf("\n\t Vendor: %s (%u)",
2167 tok2str(oui_values,"Unknown",vendor_id),
2168 vendor_id);
2169 tptr+=3;
2170 tmp-=3;
2171 if (tmp > 0) /* hexdump the rest */
2172 if(!print_unknown_data(tptr,"\n\t\t",tmp))
2173 return(0);
2174 break;
2175 /*
2176 * FIXME those are the defined TLVs that lack a decoder
2177 * you are welcome to contribute code ;-)
2178 */
2179
2180 case ISIS_TLV_DECNET_PHASE4:
2181 case ISIS_TLV_LUCENT_PRIVATE:
2182 case ISIS_TLV_IPAUTH:
2183 case ISIS_TLV_NORTEL_PRIVATE1:
2184 case ISIS_TLV_NORTEL_PRIVATE2:
2185
2186 default:
2187 if (vflag <= 1) {
2188 if(!print_unknown_data(pptr,"\n\t\t",tlv_len))
2189 return(0);
2190 }
2191 break;
2192 }
2193 /* do we want to see an additionally hexdump ? */
2194 if (vflag> 1) {
2195 if(!print_unknown_data(pptr,"\n\t ",tlv_len))
2196 return(0);
2197 }
2198
2199 pptr += tlv_len;
2200 packet_len -= tlv_len;
2201 }
2202
2203 if (packet_len != 0) {
2204 printf("\n\t %u straggler bytes", packet_len);
2205 }
2206 return (1);
2207
2208 trunc:
2209 fputs("[|isis]", stdout);
2210 return (1);
2211
2212 trunctlv:
2213 printf("\n\t\t packet exceeded snapshot");
2214 return(1);
2215 }
2216
2217 /*
2218 * Verify the checksum. See 8473-1, Appendix C, section C.4.
2219 */
2220
2221 static int
2222 osi_cksum(const u_int8_t *tptr, u_int len)
2223 {
2224 int32_t c0 = 0, c1 = 0;
2225
2226 while ((int)--len >= 0) {
2227 c0 += *tptr++;
2228 c0 %= 255;
2229 c1 += c0;
2230 c1 %= 255;
2231 }
2232 return (c0 | c1);
2233 }