xref: /titanic_50/usr/src/cmd/cmd-inet/usr.sbin/snoop/snoop_bpdu.c (revision 8f588c8376a0fa02470fc4554ec83442b305020f)
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 
32 #include <snoop.h>
33 
34 struct conf_bpdu {
35 	uchar_t cb_protid[2];		/* Protocol Identifier */
36 	uchar_t cb_protvers;		/* Protocol Version Identifier */
37 	uchar_t cb_type;		/* BPDU Type */
38 	uchar_t cb_flags;		/* BPDU Flags */
39 	uchar_t cb_rootid[8];		/* Root Identifier */
40 	uchar_t cb_rootcost[4];		/* Root Path Cost */
41 	uchar_t cb_bridgeid[8];		/* Bridge Identifier */
42 	uchar_t cb_portid[2];		/* Port Identifier */
43 	uchar_t cb_messageage[2];	/* Message Age */
44 	uchar_t cb_maxage[2];		/* Max Age */
45 	uchar_t cb_hello[2];		/* Hello Time */
46 	uchar_t cb_fwddelay[2];		/* Forward Delay */
47 };
48 
49 #define	BPDU_TYPE_CONF		0
50 #define	BPDU_TYPE_RCONF		2
51 #define	BPDU_TYPE_TCNOTIF	0x80
52 
53 int
54 interpret_bpdu(int flags, char *data, int dlen)
55 {
56 	struct conf_bpdu *cb;
57 	const char *pdutype;
58 
59 	if (dlen < 4) {
60 		(void) snprintf(get_sum_line(), MAXLINE,
61 		    "BPDU (short packet)");
62 		return (0);
63 	}
64 
65 	cb = (struct conf_bpdu *)data;
66 
67 	if (flags & F_SUM) {
68 		(void) snprintf(get_sum_line(), MAXLINE,
69 		    "Bridge PDU T:%d L:%d", cb->cb_type, dlen);
70 	}
71 
72 	if (flags & F_DTAIL) {
73 		show_header("Bridge-PDU: ",
74 		    "Bridge PDU Frame", dlen);
75 		show_space();
76 		switch (cb->cb_type) {
77 		case BPDU_TYPE_CONF:
78 			pdutype = "Configuration";
79 			break;
80 		case BPDU_TYPE_RCONF:
81 			pdutype = "Rapid Configuration";
82 			break;
83 		case BPDU_TYPE_TCNOTIF:
84 			pdutype = "TC Notification";
85 			break;
86 		default:
87 			pdutype = "?";
88 			break;
89 		}
90 		(void) snprintf(get_line(0, 0), get_line_remain(),
91 		    "PDU type = %d (%s)", cb->cb_type, pdutype);
92 		show_trailer();
93 	}
94 	return (0);
95 }
96