xref: /onnv-gate/usr/src/cmd/cmd-inet/usr.sbin/snoop/snoop_bpdu.c (revision 10491:8893b747ecdf)
1*10491SRishi.Srivatsavai@Sun.COM /*
2*10491SRishi.Srivatsavai@Sun.COM  * CDDL HEADER START
3*10491SRishi.Srivatsavai@Sun.COM  *
4*10491SRishi.Srivatsavai@Sun.COM  * The contents of this file are subject to the terms of the
5*10491SRishi.Srivatsavai@Sun.COM  * Common Development and Distribution License (the "License").
6*10491SRishi.Srivatsavai@Sun.COM  * You may not use this file except in compliance with the License.
7*10491SRishi.Srivatsavai@Sun.COM  *
8*10491SRishi.Srivatsavai@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*10491SRishi.Srivatsavai@Sun.COM  * or http://www.opensolaris.org/os/licensing.
10*10491SRishi.Srivatsavai@Sun.COM  * See the License for the specific language governing permissions
11*10491SRishi.Srivatsavai@Sun.COM  * and limitations under the License.
12*10491SRishi.Srivatsavai@Sun.COM  *
13*10491SRishi.Srivatsavai@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
14*10491SRishi.Srivatsavai@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*10491SRishi.Srivatsavai@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
16*10491SRishi.Srivatsavai@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
17*10491SRishi.Srivatsavai@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
18*10491SRishi.Srivatsavai@Sun.COM  *
19*10491SRishi.Srivatsavai@Sun.COM  * CDDL HEADER END
20*10491SRishi.Srivatsavai@Sun.COM  */
21*10491SRishi.Srivatsavai@Sun.COM 
22*10491SRishi.Srivatsavai@Sun.COM /*
23*10491SRishi.Srivatsavai@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24*10491SRishi.Srivatsavai@Sun.COM  * Use is subject to license terms.
25*10491SRishi.Srivatsavai@Sun.COM  */
26*10491SRishi.Srivatsavai@Sun.COM 
27*10491SRishi.Srivatsavai@Sun.COM #include <stdio.h>
28*10491SRishi.Srivatsavai@Sun.COM #include <sys/types.h>
29*10491SRishi.Srivatsavai@Sun.COM #include <sys/socket.h>
30*10491SRishi.Srivatsavai@Sun.COM #include <sys/ethernet.h>
31*10491SRishi.Srivatsavai@Sun.COM 
32*10491SRishi.Srivatsavai@Sun.COM #include <snoop.h>
33*10491SRishi.Srivatsavai@Sun.COM 
34*10491SRishi.Srivatsavai@Sun.COM struct conf_bpdu {
35*10491SRishi.Srivatsavai@Sun.COM 	uchar_t cb_protid[2];		/* Protocol Identifier */
36*10491SRishi.Srivatsavai@Sun.COM 	uchar_t cb_protvers;		/* Protocol Version Identifier */
37*10491SRishi.Srivatsavai@Sun.COM 	uchar_t cb_type;		/* BPDU Type */
38*10491SRishi.Srivatsavai@Sun.COM 	uchar_t cb_flags;		/* BPDU Flags */
39*10491SRishi.Srivatsavai@Sun.COM 	uchar_t cb_rootid[8];		/* Root Identifier */
40*10491SRishi.Srivatsavai@Sun.COM 	uchar_t cb_rootcost[4];		/* Root Path Cost */
41*10491SRishi.Srivatsavai@Sun.COM 	uchar_t cb_bridgeid[8];		/* Bridge Identifier */
42*10491SRishi.Srivatsavai@Sun.COM 	uchar_t cb_portid[2];		/* Port Identifier */
43*10491SRishi.Srivatsavai@Sun.COM 	uchar_t cb_messageage[2];	/* Message Age */
44*10491SRishi.Srivatsavai@Sun.COM 	uchar_t cb_maxage[2];		/* Max Age */
45*10491SRishi.Srivatsavai@Sun.COM 	uchar_t cb_hello[2];		/* Hello Time */
46*10491SRishi.Srivatsavai@Sun.COM 	uchar_t cb_fwddelay[2];		/* Forward Delay */
47*10491SRishi.Srivatsavai@Sun.COM };
48*10491SRishi.Srivatsavai@Sun.COM 
49*10491SRishi.Srivatsavai@Sun.COM #define	BPDU_TYPE_CONF		0
50*10491SRishi.Srivatsavai@Sun.COM #define	BPDU_TYPE_RCONF		2
51*10491SRishi.Srivatsavai@Sun.COM #define	BPDU_TYPE_TCNOTIF	0x80
52*10491SRishi.Srivatsavai@Sun.COM 
53*10491SRishi.Srivatsavai@Sun.COM int
interpret_bpdu(int flags,char * data,int dlen)54*10491SRishi.Srivatsavai@Sun.COM interpret_bpdu(int flags, char *data, int dlen)
55*10491SRishi.Srivatsavai@Sun.COM {
56*10491SRishi.Srivatsavai@Sun.COM 	struct conf_bpdu *cb;
57*10491SRishi.Srivatsavai@Sun.COM 	const char *pdutype;
58*10491SRishi.Srivatsavai@Sun.COM 
59*10491SRishi.Srivatsavai@Sun.COM 	if (dlen < 4) {
60*10491SRishi.Srivatsavai@Sun.COM 		(void) snprintf(get_sum_line(), MAXLINE,
61*10491SRishi.Srivatsavai@Sun.COM 		    "BPDU (short packet)");
62*10491SRishi.Srivatsavai@Sun.COM 		return (0);
63*10491SRishi.Srivatsavai@Sun.COM 	}
64*10491SRishi.Srivatsavai@Sun.COM 
65*10491SRishi.Srivatsavai@Sun.COM 	cb = (struct conf_bpdu *)data;
66*10491SRishi.Srivatsavai@Sun.COM 
67*10491SRishi.Srivatsavai@Sun.COM 	if (flags & F_SUM) {
68*10491SRishi.Srivatsavai@Sun.COM 		(void) snprintf(get_sum_line(), MAXLINE,
69*10491SRishi.Srivatsavai@Sun.COM 		    "Bridge PDU T:%d L:%d", cb->cb_type, dlen);
70*10491SRishi.Srivatsavai@Sun.COM 	}
71*10491SRishi.Srivatsavai@Sun.COM 
72*10491SRishi.Srivatsavai@Sun.COM 	if (flags & F_DTAIL) {
73*10491SRishi.Srivatsavai@Sun.COM 		show_header("Bridge-PDU: ",
74*10491SRishi.Srivatsavai@Sun.COM 		    "Bridge PDU Frame", dlen);
75*10491SRishi.Srivatsavai@Sun.COM 		show_space();
76*10491SRishi.Srivatsavai@Sun.COM 		switch (cb->cb_type) {
77*10491SRishi.Srivatsavai@Sun.COM 		case BPDU_TYPE_CONF:
78*10491SRishi.Srivatsavai@Sun.COM 			pdutype = "Configuration";
79*10491SRishi.Srivatsavai@Sun.COM 			break;
80*10491SRishi.Srivatsavai@Sun.COM 		case BPDU_TYPE_RCONF:
81*10491SRishi.Srivatsavai@Sun.COM 			pdutype = "Rapid Configuration";
82*10491SRishi.Srivatsavai@Sun.COM 			break;
83*10491SRishi.Srivatsavai@Sun.COM 		case BPDU_TYPE_TCNOTIF:
84*10491SRishi.Srivatsavai@Sun.COM 			pdutype = "TC Notification";
85*10491SRishi.Srivatsavai@Sun.COM 			break;
86*10491SRishi.Srivatsavai@Sun.COM 		default:
87*10491SRishi.Srivatsavai@Sun.COM 			pdutype = "?";
88*10491SRishi.Srivatsavai@Sun.COM 			break;
89*10491SRishi.Srivatsavai@Sun.COM 		}
90*10491SRishi.Srivatsavai@Sun.COM 		(void) snprintf(get_line(0, 0), get_line_remain(),
91*10491SRishi.Srivatsavai@Sun.COM 		    "PDU type = %d (%s)", cb->cb_type, pdutype);
92*10491SRishi.Srivatsavai@Sun.COM 		show_trailer();
93*10491SRishi.Srivatsavai@Sun.COM 	}
94*10491SRishi.Srivatsavai@Sun.COM 	return (0);
95*10491SRishi.Srivatsavai@Sun.COM }
96