xref: /onnv-gate/usr/src/cmd/cmd-inet/usr.sbin/snoop/snoop_trill.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 #include <sys/vlan.h>
32*10491SRishi.Srivatsavai@Sun.COM #include <net/trill.h>
33*10491SRishi.Srivatsavai@Sun.COM 
34*10491SRishi.Srivatsavai@Sun.COM #include <snoop.h>
35*10491SRishi.Srivatsavai@Sun.COM 
36*10491SRishi.Srivatsavai@Sun.COM int
interpret_trill(int flags,struct ether_header ** e,char * data,int * alen)37*10491SRishi.Srivatsavai@Sun.COM interpret_trill(int flags, struct ether_header **e, char *data, int *alen)
38*10491SRishi.Srivatsavai@Sun.COM {
39*10491SRishi.Srivatsavai@Sun.COM 	trill_header_t *trillhdr;
40*10491SRishi.Srivatsavai@Sun.COM 	struct ether_header *inner_ethhdr;
41*10491SRishi.Srivatsavai@Sun.COM 	struct ether_vlan_header *inner_ethvlanhdr;
42*10491SRishi.Srivatsavai@Sun.COM 	uint16_t ethertype;
43*10491SRishi.Srivatsavai@Sun.COM 	int dlen = *alen;
44*10491SRishi.Srivatsavai@Sun.COM 	size_t optslen;
45*10491SRishi.Srivatsavai@Sun.COM 	size_t trillhdrlen;
46*10491SRishi.Srivatsavai@Sun.COM 
47*10491SRishi.Srivatsavai@Sun.COM 	if (dlen < sizeof (trill_header_t)) {
48*10491SRishi.Srivatsavai@Sun.COM 		(void) snprintf(get_sum_line(), MAXLINE,
49*10491SRishi.Srivatsavai@Sun.COM 		    "TRILL (short packet)");
50*10491SRishi.Srivatsavai@Sun.COM 		return (0);
51*10491SRishi.Srivatsavai@Sun.COM 	}
52*10491SRishi.Srivatsavai@Sun.COM 
53*10491SRishi.Srivatsavai@Sun.COM 	trillhdr = (trill_header_t *)data;
54*10491SRishi.Srivatsavai@Sun.COM 	optslen = GET_TRILL_OPTS_LEN(trillhdr) * sizeof (uint32_t);
55*10491SRishi.Srivatsavai@Sun.COM 
56*10491SRishi.Srivatsavai@Sun.COM 	if (flags & F_DTAIL) {
57*10491SRishi.Srivatsavai@Sun.COM 		show_header("TRILL: ", "TRILL Data Frame", dlen);
58*10491SRishi.Srivatsavai@Sun.COM 		show_space();
59*10491SRishi.Srivatsavai@Sun.COM 
60*10491SRishi.Srivatsavai@Sun.COM 		(void) snprintf(get_line(0, 0), get_line_remain(),
61*10491SRishi.Srivatsavai@Sun.COM 		    "Egress nickname = %d",
62*10491SRishi.Srivatsavai@Sun.COM 		    ntohs(trillhdr->th_egressnick));
63*10491SRishi.Srivatsavai@Sun.COM 		(void) snprintf(get_line(0, 0), get_line_remain(),
64*10491SRishi.Srivatsavai@Sun.COM 		    "Ingress nickname = %d",
65*10491SRishi.Srivatsavai@Sun.COM 		    ntohs(trillhdr->th_ingressnick));
66*10491SRishi.Srivatsavai@Sun.COM 		(void) snprintf(get_line(0, 0), get_line_remain(),
67*10491SRishi.Srivatsavai@Sun.COM 		    "Hop count = %d", trillhdr->th_hopcount);
68*10491SRishi.Srivatsavai@Sun.COM 		(void) snprintf(get_line(0, 0), get_line_remain(),
69*10491SRishi.Srivatsavai@Sun.COM 		    "Multi-destination = %d", trillhdr->th_multidest);
70*10491SRishi.Srivatsavai@Sun.COM 		(void) snprintf(get_line(0, 0), get_line_remain(),
71*10491SRishi.Srivatsavai@Sun.COM 		    "Options Len = %d bytes", optslen);
72*10491SRishi.Srivatsavai@Sun.COM 		show_trailer();
73*10491SRishi.Srivatsavai@Sun.COM 	}
74*10491SRishi.Srivatsavai@Sun.COM 
75*10491SRishi.Srivatsavai@Sun.COM 	trillhdrlen = sizeof (trill_header_t) + optslen;
76*10491SRishi.Srivatsavai@Sun.COM 
77*10491SRishi.Srivatsavai@Sun.COM 	if (dlen < trillhdrlen) {
78*10491SRishi.Srivatsavai@Sun.COM 		(void) snprintf(get_sum_line(), MAXLINE,
79*10491SRishi.Srivatsavai@Sun.COM 		    "TRILL (options truncated)");
80*10491SRishi.Srivatsavai@Sun.COM 		return (0);
81*10491SRishi.Srivatsavai@Sun.COM 	}
82*10491SRishi.Srivatsavai@Sun.COM 
83*10491SRishi.Srivatsavai@Sun.COM 	dlen -= trillhdrlen;
84*10491SRishi.Srivatsavai@Sun.COM 
85*10491SRishi.Srivatsavai@Sun.COM 	if (dlen < sizeof (struct ether_header)) {
86*10491SRishi.Srivatsavai@Sun.COM 		(void) snprintf(get_sum_line(), MAXLINE,
87*10491SRishi.Srivatsavai@Sun.COM 		    "TRILL (missing required inner MAC)");
88*10491SRishi.Srivatsavai@Sun.COM 		return (0);
89*10491SRishi.Srivatsavai@Sun.COM 	}
90*10491SRishi.Srivatsavai@Sun.COM 
91*10491SRishi.Srivatsavai@Sun.COM 	inner_ethhdr = (struct ether_header *)(data + trillhdrlen);
92*10491SRishi.Srivatsavai@Sun.COM 	if (inner_ethhdr->ether_type != htons(ETHERTYPE_VLAN)) {
93*10491SRishi.Srivatsavai@Sun.COM 		(void) snprintf(get_sum_line(), MAXLINE,
94*10491SRishi.Srivatsavai@Sun.COM 		    "TRILL (inner VLAN missing; ethertype %X)",
95*10491SRishi.Srivatsavai@Sun.COM 		    ntohs(inner_ethhdr->ether_type));
96*10491SRishi.Srivatsavai@Sun.COM 		return (0);
97*10491SRishi.Srivatsavai@Sun.COM 	}
98*10491SRishi.Srivatsavai@Sun.COM 
99*10491SRishi.Srivatsavai@Sun.COM 	inner_ethvlanhdr = (struct ether_vlan_header *)inner_ethhdr;
100*10491SRishi.Srivatsavai@Sun.COM 	ethertype = ntohs(inner_ethvlanhdr->ether_type);
101*10491SRishi.Srivatsavai@Sun.COM 
102*10491SRishi.Srivatsavai@Sun.COM 	if (flags & F_SUM) {
103*10491SRishi.Srivatsavai@Sun.COM 		(void) snprintf(get_sum_line(), MAXLINE,
104*10491SRishi.Srivatsavai@Sun.COM 		    "TRILL D:%d S:%d HC:%d M:%d O:%d L:%d VLAN:%d %s",
105*10491SRishi.Srivatsavai@Sun.COM 		    ntohs(trillhdr->th_egressnick),
106*10491SRishi.Srivatsavai@Sun.COM 		    ntohs(trillhdr->th_ingressnick),
107*10491SRishi.Srivatsavai@Sun.COM 		    trillhdr->th_hopcount,
108*10491SRishi.Srivatsavai@Sun.COM 		    trillhdr->th_multidest,
109*10491SRishi.Srivatsavai@Sun.COM 		    optslen,
110*10491SRishi.Srivatsavai@Sun.COM 		    dlen, VLAN_ID(inner_ethvlanhdr->ether_tci),
111*10491SRishi.Srivatsavai@Sun.COM 		    print_ethertype(ethertype));
112*10491SRishi.Srivatsavai@Sun.COM 	}
113*10491SRishi.Srivatsavai@Sun.COM 
114*10491SRishi.Srivatsavai@Sun.COM 	*alen = dlen;
115*10491SRishi.Srivatsavai@Sun.COM 	*e = inner_ethhdr;
116*10491SRishi.Srivatsavai@Sun.COM 	return (ethertype);
117*10491SRishi.Srivatsavai@Sun.COM }
118