2 * Copyright (c) 1992, 1993, 1994, 1995, 1996
3 * The Regents of the University of California. All rights reserved.
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
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.
21 * Original code by Matt Thomas, Digital Equipment Corporation
25 static const char rcsid[] =
26 "@(#) $Header: print-isoclns.c,v 1.15 96/12/31 21:27:41 leres Exp $ (LBL)";
29 #include <sys/types.h>
31 #include <sys/socket.h>
39 #include <netinet/in.h>
40 #include <net/ethernet.h>
44 #include "interface.h"
45 #include "addrtoname.h"
46 #include "ethertype.h"
49 #define NLPID_CLNS 129 /* 0x81 */
50 #define NLPID_ESIS 130 /* 0x82 */
51 #define NLPID_ISIS 131 /* 0x83 */
52 #define NLPID_NULLNS 0
56 * IS-IS is defined in ISO 10589. Look there for protocol definitions.
59 #define SYSTEM_ID_LEN sizeof(struct ether_addr)
60 #define ISIS_VERSION 1
61 #define PDU_TYPE_MASK 0x1F
62 #define PRIORITY_MASK 0x7F
69 #define L1_COMPLETE_SEQ_PDU 24
70 #define L2_COMPLETE_SEQ_PDU 25
73 * A TLV is a tuple of a type, length and a value and is normally used for
74 * encoding information in all sorts of places. This is an enumeration of
75 * the well known types.
78 #define TLV_AREA_ADDR 1
79 #define TLV_IS_REACH 2
80 #define TLV_ES_REACH 3
85 #define TLV_AUTHENT 10
86 #define TLV_IP_REACH 128
87 #define TLV_PROTOCOLS 129
88 #define TLV_IP_EXTERN 130
89 #define TLV_IDRP_INFO 131
90 #define TLV_IPADDR 132
91 #define TLV_IPAUTH 133
92 #define TLV_PTP_ADJ 240
95 * Katz's point to point adjacency TLV uses codes to tell us the state of
96 * the remote adjacency. Enumerate them.
99 #define ISIS_PTP_ADJ_UP 0
100 #define ISIS_PTP_ADJ_INIT 1
101 #define ISIS_PTP_ADJ_DOWN 2
103 static int osi_cksum(const u_char *, int, u_char *);
104 static void esis_print(const u_char *, u_int);
105 static int isis_print(const u_char *, u_int);
108 struct isis_ptp_adjancey_values {
113 static struct isis_ptp_adjancey_values isis_ptp_adjancey_values[] = {
114 ISIS_PTP_ADJ_UP, "UP",
115 ISIS_PTP_ADJ_INIT, "INIT",
116 ISIS_PTP_ADJ_DOWN, "DOWN"
119 struct isis_common_header {
122 u_char version; /* Protocol version? */
124 u_char enc_pdu_type; /* 3 MSbs are reserved */
125 u_char pkt_version; /* Packet format version? */
133 u_char version; /* Protocol version? */
135 u_char enc_pdu_type; /* 3 MSbs are reserved */
136 u_char pkt_version; /* Packet format version? */
140 u_char enc_source_id[SYSTEM_ID_LEN];
141 u_char enc_holding_time[2];
142 u_char enc_packet_len[2];
144 u_char enc_lan_id[SYSTEM_ID_LEN+1];
146 struct isis_lan_header {
148 u_char enc_source_id[SYSTEM_ID_LEN];
149 u_char enc_holding_time[2];
150 u_char enc_packet_len[2];
152 u_char enc_lan_id[SYSTEM_ID_LEN+1];
155 struct isis_ptp_header {
157 u_char enc_source_id[SYSTEM_ID_LEN];
158 u_char enc_holding_time[2];
159 u_char enc_packet_len[2];
160 u_char loc_circuit_id;
163 #define ISIS_COMMON_HEADER_SIZE (sizeof(struct isis_common_header))
164 #define ISIS_HEADER_SIZE (15+(SYSTEM_ID_LEN<<1))
165 #define ISIS_PTP_HEADER_SIZE (14+SYSTEM_ID_LEN)
166 #define L1_LS_PDU_HEADER_SIZE (21+SYSTEM_ID_LEN)
167 #define L2_LS_PDU_HEADER_SIZE L1_LS_PDU_HEADER_SIZE
168 #define L1_COMPLETE_SEQ_PDU_HEADER_SIZE 33
169 #define L2_COMPLETE_SEQ_PDU_HEADER_SIZE L1_COMPLETE_SEQ_PDU_HEADER_SIZE
174 isoclns_print(const u_char *p, u_int length, u_int caplen,
175 const u_char *esrc, const u_char *edst)
178 struct isis_header *header;
180 header = (struct isis_header *)p;
181 pdu_type = header->enc_pdu_type & PDU_TYPE_MASK;
184 printf("[|iso-clns] ");
187 etheraddr_string(esrc),
188 etheraddr_string(edst));
197 (void)printf(" %s > %s",
198 etheraddr_string(esrc),
199 etheraddr_string(edst));
205 (void)printf(" %s > %s",
206 etheraddr_string(esrc),
207 etheraddr_string(edst));
208 esis_print(p, length);
214 if(pdu_type != PTP_IIH)
215 (void)printf(" %s > %s",
216 etheraddr_string(esrc),
217 etheraddr_string(edst));
219 (void)printf(" len=%d ", length);
220 if (!isis_print(p, length))
221 default_print_unaligned(p, caplen);
225 printf("iso nullns");
227 (void)printf(" %s > %s",
228 etheraddr_string(esrc),
229 etheraddr_string(edst));
233 printf("iso clns %02x", p[0]);
235 (void)printf(" %s > %s",
236 etheraddr_string(esrc),
237 etheraddr_string(edst));
238 (void)printf(" len=%d ", length);
240 default_print_unaligned(p, caplen);
245 #define ESIS_REDIRECT 6
258 esis_print(const u_char *p, u_int length)
262 const struct esis_hdr *eh = (const struct esis_hdr *) &p[2];
270 printf(" no header at all!");
278 printf(" LI(%d) > PDU size (%d)!", li, length);
281 if (li < sizeof(struct esis_hdr) + 2) {
285 printf(" too short for esis header %d:", li);
286 while (--length != 0)
287 printf("%02X", *p++);
291 switch (eh->type & 0x1f) {
306 printf(" type %d", eh->type & 0x1f);
309 off[0] = eh->cksum[0];
310 off[1] = eh->cksum[1];
311 if (vflag && osi_cksum(p, li, off)) {
312 printf(" bad cksum (got %02x%02x)",
313 eh->cksum[1], eh->cksum[0]);
314 default_print(p, length);
317 if (eh->version != 1) {
318 printf(" unsupported version %d", eh->version);
321 p += sizeof(*eh) + 2;
322 li -= sizeof(*eh) + 2; /* protoid * li */
324 switch (eh->type & 0x1f) {
325 case ESIS_REDIRECT: {
326 const u_char *dst, *snpa, *is;
328 dst = p; p += *p + 1;
331 printf("\n\t\t\t %s", isonsap_string(dst));
332 snpa = p; p += *p + 1;
341 printf(" > %s", etheraddr_string(&snpa[1]));
343 printf(" > %s", isonsap_string(is));
363 printf("\n\t\t\t %s", isonsap_string(is));
369 (void)printf(" len=%d", length);
370 if (length && p < snapend) {
371 length = snapend - p;
372 default_print(p, length);
377 while (p < ep && li) {
384 printf(" bad opts/li");
391 printf(" opt (%d) too long", op);
399 if (op == 198 && opli == 2) {
400 printf(" tmo=%d", q[0] * 256 + q[1]);
403 printf (" %d:<", op);
405 printf("%02x", *q++);
416 print_nsap (register const u_char *cp, register int length)
420 for (i = 0; i < length; i++) {
421 printf("%02x", *cp++);
422 if (((i & 1) == 0) && (i + 1 < length)) {
431 * Decode IS-IS packets. Return 0 on error.
433 * So far, this is only smart enough to print IIH's. Someday...
437 isis_print (const u_char *p, u_int length)
439 struct isis_header *header;
440 struct isis_ptp_header *header_ptp;
441 u_char pdu_type, max_area, priority, *pptr, type, len, *tptr, tmp, alen;
442 u_short packet_len, holding_time;
445 header_ptp = (struct isis_ptp_header *)header = (struct isis_header *)p;
449 * Sanity checking of the header.
451 if (header->nlpid != NLPID_ISIS) {
452 printf(" coding error!");
456 if (header->version != ISIS_VERSION) {
457 printf(" version %d packet not supported", header->version);
461 if ((header->id_length != SYSTEM_ID_LEN) && (header->id_length != 0)) {
462 printf(" system ID length of %d is not supported",
467 if ((header->fixed_len != ISIS_HEADER_SIZE) &&
468 (header->fixed_len != ISIS_PTP_HEADER_SIZE) &&
469 (header->fixed_len != L1_LS_PDU_HEADER_SIZE) &&
470 (header-> fixed_len != L1_COMPLETE_SEQ_PDU_HEADER_SIZE) ) {
471 printf(" bogus fixed header length",
476 pdu_type = header->enc_pdu_type & PDU_TYPE_MASK;
477 if ((pdu_type != L1_LAN_IIH) && (pdu_type != L2_LAN_IIH) &&
478 (pdu_type != PTP_IIH) &&
479 (pdu_type != L1_COMPLETE_SEQ_PDU) &&
480 (pdu_type != L2_COMPLETE_SEQ_PDU) ) {
481 printf(" PDU type (%d) not supported", pdu_type);
485 if (header->pkt_version != ISIS_VERSION) {
486 printf(" version %d packet not supported", header->pkt_version);
490 max_area = header->enc_max_area;
493 max_area = 3; /* silly shit */
496 printf(" bad packet -- 255 areas");
502 switch (header->circuit) {
504 printf(" PDU with circuit type 0");
507 if (pdu_type == L2_LAN_IIH) {
508 printf(" L2 IIH on an L1 only circuit");
513 if (pdu_type == L1_LAN_IIH) {
514 printf(" L1 IIH on an L2 only circuit");
521 printf(" unknown circuit type");
525 holding_time = EXTRACT_16BITS(header->enc_holding_time);
527 packet_len = EXTRACT_16BITS(header->enc_packet_len);
528 if ((packet_len < ISIS_HEADER_SIZE) ||
529 (packet_len > length)) {
530 printf(" bogus packet length %d, real length %d", packet_len,
535 if(pdu_type != PTP_IIH)
536 priority = header->enc_priority & PRIORITY_MASK;
539 * Now print the fixed header.
543 printf(" L1 lan iih, ");
546 printf(" L2 lan iih, ");
549 printf(" PTP iih, ");
554 switch (header->circuit) {
566 printf ("holding time %d ", holding_time);
567 printf ("\n\t\t\t source %s, length %d",
568 etheraddr_string(header->enc_source_id), packet_len);
569 if((pdu_type==L1_LAN_IIH)||(pdu_type==L2_LAN_IIH))
570 printf ("\n\t\t\t lan id %s(%d)", etheraddr_string(header->enc_lan_id),
571 header->enc_lan_id[SYSTEM_ID_LEN]);
574 * Now print the TLV's.
576 if(pdu_type==PTP_IIH) {
577 packet_len -= ISIS_PTP_HEADER_SIZE;
578 pptr = (char *)p + ISIS_PTP_HEADER_SIZE;
580 packet_len -= ISIS_HEADER_SIZE;
581 pptr = (char *)p + ISIS_HEADER_SIZE;
583 while (packet_len >= 2) {
584 if (pptr >= snapend) {
585 printf("\n\t\t\t packet exceeded snapshot");
591 if (len > packet_len) {
597 printf("\n\t\t\t area addresses");
601 while (tmp && alen < tmp) {
603 print_nsap(tptr, alen);
604 printf(" (%d)", alen);
611 printf("\n\t\t\t neighbor addresses");
614 while (tmp >= sizeof(struct ether_addr)) {
615 printf("\n\t\t\t %s", etheraddr_string(tptr));
616 tmp -= sizeof(struct ether_addr);
617 tptr += sizeof(struct ether_addr);
621 printf("\n\t\t\t padding for %d bytes", len);
624 printf("\n\t\t\t authentication data");
625 default_print(pptr, len);
628 printf("\n\t\t\t PTP adjacency status %s",
629 isis_ptp_adjancey_values[*pptr].name);
632 printf("\n\t\t\t Supports protocols %s", (len>1)? "are":"is");
634 printf(" %02X", (u_char)*(pptr+i));
637 printf("\n\t\t\t IP address: %s", ipaddr_string(pptr));
640 printf("\n\t\t\t unknown TLV, type %d, length %d", type, len);
648 if (packet_len != 0) {
649 printf("\n\t\t\t %d straggler bytes", packet_len);
655 * Verify the checksum. See 8473-1, Appendix C, section C.4.
659 osi_cksum(register const u_char *p, register int len, u_char *off)
661 int32_t c0 = 0, c1 = 0;
663 if ((off[0] == 0) && (off[1] == 0))
667 while ((int)--len >= 0) {