xref: /illumos-gate/usr/src/cmd/cmd-inet/usr.sbin/snoop/snoop_isis.c (revision 45d3dd981abb9025d8ac994cf4cc8ce8cb1a9480)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #include <stdio.h>
28 #include <sys/types.h>
29 #include <sys/socket.h>
30 #include <sys/ethernet.h>
31 #include <sys/vlan.h>
32 #include <net/trill.h>
33 
34 #include <snoop.h>
35 
36 #define	PDUTYPE_OFFSET 4
37 #define	PDUTYPE_HELLO1 15
38 #define	PDUTYPE_HELLO2 16
39 #define	PDUTYPE_HELLOP2P 17
40 #define	PDUTYPE_LSP1 18
41 #define	PDUTYPE_LSP2 20
42 #define	PDUTYPE_CSN1 24
43 #define	PDUTYPE_CSN2 25
44 #define	PDUTYPE_PSN1 26
45 #define	PDUTYPE_PSN2 27
46 
47 int
48 interpret_isis(int flags, char *data, int dlen, boolean_t istrill)
49 {
50 	uint8_t pdutypenum;
51 	char *pdutype;
52 
53 	pdutypenum = *(data+ PDUTYPE_OFFSET);
54 	switch (pdutypenum) {
55 	case PDUTYPE_HELLO1:
56 	case PDUTYPE_HELLO2:
57 		pdutype = "Hello";
58 		break;
59 	case PDUTYPE_HELLOP2P:
60 		pdutype = "P2P Hello";
61 		break;
62 	case PDUTYPE_LSP1:
63 	case PDUTYPE_LSP2:
64 		pdutype = "Link State";
65 		break;
66 	case PDUTYPE_CSN1:
67 	case PDUTYPE_CSN2:
68 		pdutype = "CSN";
69 		break;
70 	case PDUTYPE_PSN1:
71 	case PDUTYPE_PSN2:
72 		pdutype = "PSN";
73 		break;
74 	default:
75 		pdutype = "Unknown";
76 		break;
77 	}
78 
79 	if (flags & F_SUM) {
80 		(void) snprintf(get_sum_line(), MAXLINE,
81 		    "%s %s L:%d", istrill ? "Core TRILL IS-IS" : "IS-IS",
82 		    pdutype, dlen);
83 	}
84 
85 	if (flags & F_DTAIL) {
86 		if (istrill) {
87 			show_header("TRILL-IS-IS: ",
88 			    "Core TRILL IS-IS Frame", dlen);
89 		} else {
90 			show_header("IS-IS: ",
91 			    "IS-IS Frame", dlen);
92 		}
93 		show_space();
94 		(void) snprintf(get_line(0, 0), get_line_remain(),
95 		    "Frame type = %02X (%s)", pdutypenum, pdutype);
96 		show_trailer();
97 	}
98 	return (0);
99 }
100