1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright (c) 2001 by Sun Microsystems, Inc.
24*7c478bd9Sstevel@tonic-gate  * All rights reserved.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #include <stdio.h>
28*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #include <at.h>
31*7c478bd9Sstevel@tonic-gate #include <snoop.h>
32*7c478bd9Sstevel@tonic-gate 
33*7c478bd9Sstevel@tonic-gate static void show_rtmp_tuples(uint8_t *, int);
34*7c478bd9Sstevel@tonic-gate 
35*7c478bd9Sstevel@tonic-gate static char *
rtmp_func_long(uint8_t fun)36*7c478bd9Sstevel@tonic-gate rtmp_func_long(uint8_t fun)
37*7c478bd9Sstevel@tonic-gate {
38*7c478bd9Sstevel@tonic-gate 	switch (fun) {
39*7c478bd9Sstevel@tonic-gate 	case RTMP_REQ:
40*7c478bd9Sstevel@tonic-gate 		return ("Request");
41*7c478bd9Sstevel@tonic-gate 	case RTMP_RDR_SH:
42*7c478bd9Sstevel@tonic-gate 		return ("Route Data Request, split horizon");
43*7c478bd9Sstevel@tonic-gate 	case RTMP_RDR_NSH:
44*7c478bd9Sstevel@tonic-gate 		return ("Route Data Request, no split horizon");
45*7c478bd9Sstevel@tonic-gate 	default:
46*7c478bd9Sstevel@tonic-gate 		return ("unknown");
47*7c478bd9Sstevel@tonic-gate 	}
48*7c478bd9Sstevel@tonic-gate }
49*7c478bd9Sstevel@tonic-gate 
50*7c478bd9Sstevel@tonic-gate static char *
rtmp_func_short(uint8_t fun)51*7c478bd9Sstevel@tonic-gate rtmp_func_short(uint8_t fun)
52*7c478bd9Sstevel@tonic-gate {
53*7c478bd9Sstevel@tonic-gate 	switch (fun) {
54*7c478bd9Sstevel@tonic-gate 	case RTMP_REQ:
55*7c478bd9Sstevel@tonic-gate 		return ("Req");
56*7c478bd9Sstevel@tonic-gate 	case RTMP_RDR_SH:
57*7c478bd9Sstevel@tonic-gate 		return ("RDR, sh");
58*7c478bd9Sstevel@tonic-gate 	case RTMP_RDR_NSH:
59*7c478bd9Sstevel@tonic-gate 		return ("RDR, no sh");
60*7c478bd9Sstevel@tonic-gate 	default:
61*7c478bd9Sstevel@tonic-gate 		return ("unknown");
62*7c478bd9Sstevel@tonic-gate 	}
63*7c478bd9Sstevel@tonic-gate }
64*7c478bd9Sstevel@tonic-gate 
65*7c478bd9Sstevel@tonic-gate void
interpret_rtmp(int flags,struct ddp_hdr * ddp,int len)66*7c478bd9Sstevel@tonic-gate interpret_rtmp(int flags, struct ddp_hdr *ddp, int len)
67*7c478bd9Sstevel@tonic-gate {
68*7c478bd9Sstevel@tonic-gate 	uint8_t *data;
69*7c478bd9Sstevel@tonic-gate 	uint16_t snet;
70*7c478bd9Sstevel@tonic-gate 	uint8_t node;
71*7c478bd9Sstevel@tonic-gate 	int tuples;
72*7c478bd9Sstevel@tonic-gate 	int runt;
73*7c478bd9Sstevel@tonic-gate 	char extended;
74*7c478bd9Sstevel@tonic-gate 
75*7c478bd9Sstevel@tonic-gate 	len -= DDPHDR_SIZE;
76*7c478bd9Sstevel@tonic-gate 	if (len < 0)
77*7c478bd9Sstevel@tonic-gate 		goto out;
78*7c478bd9Sstevel@tonic-gate 
79*7c478bd9Sstevel@tonic-gate 	data = (uint8_t *)ddp + DDPHDR_SIZE;
80*7c478bd9Sstevel@tonic-gate 
81*7c478bd9Sstevel@tonic-gate 	switch (ddp->ddp_type) {
82*7c478bd9Sstevel@tonic-gate 	case DDP_TYPE_RTMPRQ:		/* simple rtmp */
83*7c478bd9Sstevel@tonic-gate 		if (len < 1)
84*7c478bd9Sstevel@tonic-gate 			goto out;
85*7c478bd9Sstevel@tonic-gate 
86*7c478bd9Sstevel@tonic-gate 		if (flags & F_SUM) {
87*7c478bd9Sstevel@tonic-gate 			(void) snprintf(get_sum_line(), MAXLINE,
88*7c478bd9Sstevel@tonic-gate 			    "RTMP F=%s",
89*7c478bd9Sstevel@tonic-gate 			    rtmp_func_short(data[0]));
90*7c478bd9Sstevel@tonic-gate 		}
91*7c478bd9Sstevel@tonic-gate 
92*7c478bd9Sstevel@tonic-gate 		if (flags & F_DTAIL) {
93*7c478bd9Sstevel@tonic-gate 			show_header("RTMP: ", "RTMP Header", len);
94*7c478bd9Sstevel@tonic-gate 			show_space();
95*7c478bd9Sstevel@tonic-gate 
96*7c478bd9Sstevel@tonic-gate 			(void) snprintf(get_line(0, 0), get_line_remain(),
97*7c478bd9Sstevel@tonic-gate 			    "Func = %d (%s)",
98*7c478bd9Sstevel@tonic-gate 			    data[0], rtmp_func_long(data[0]));
99*7c478bd9Sstevel@tonic-gate 		}
100*7c478bd9Sstevel@tonic-gate 		break;
101*7c478bd9Sstevel@tonic-gate 	case DDP_TYPE_RTMPRESP:		/* RTMP data */
102*7c478bd9Sstevel@tonic-gate 		if (len < 3)
103*7c478bd9Sstevel@tonic-gate 			goto out;
104*7c478bd9Sstevel@tonic-gate 
105*7c478bd9Sstevel@tonic-gate 		snet = get_short(data);
106*7c478bd9Sstevel@tonic-gate 		if (data[2] != 8)	/* ID length is always 8 */
107*7c478bd9Sstevel@tonic-gate 			return;
108*7c478bd9Sstevel@tonic-gate 		node = data[3];		/* assume id_len == 8 */
109*7c478bd9Sstevel@tonic-gate 		extended = (data[6] != RTMP_FILLER) &&
110*7c478bd9Sstevel@tonic-gate 		    (get_short(&data[4]) != 0);
111*7c478bd9Sstevel@tonic-gate 
112*7c478bd9Sstevel@tonic-gate 		tuples = (len - 4) / 3;
113*7c478bd9Sstevel@tonic-gate 		runt = (len - 4) % 3; /* integral length? */
114*7c478bd9Sstevel@tonic-gate 
115*7c478bd9Sstevel@tonic-gate 		if (flags & F_SUM) {
116*7c478bd9Sstevel@tonic-gate 			(void) snprintf(get_sum_line(), MAXLINE,
117*7c478bd9Sstevel@tonic-gate 			    "RTMP Data Snet=%d, Snode=%d%s",
118*7c478bd9Sstevel@tonic-gate 			    snet, node, runt != 0 ? " (short)" : "");
119*7c478bd9Sstevel@tonic-gate 		}
120*7c478bd9Sstevel@tonic-gate 
121*7c478bd9Sstevel@tonic-gate 		if (flags & F_DTAIL) {
122*7c478bd9Sstevel@tonic-gate 			show_header("RTMP: ", "RTMP Header", len);
123*7c478bd9Sstevel@tonic-gate 			show_space();
124*7c478bd9Sstevel@tonic-gate 
125*7c478bd9Sstevel@tonic-gate 			(void) snprintf(get_line(0, 0), get_line_remain(),
126*7c478bd9Sstevel@tonic-gate 			    "RTMP Data, Length = %d%s",
127*7c478bd9Sstevel@tonic-gate 			    len, runt != 0 ? " (short packet)" : "");
128*7c478bd9Sstevel@tonic-gate 			(void) snprintf(get_line(0, 0), get_line_remain(),
129*7c478bd9Sstevel@tonic-gate 			    "Senders Net = %d, Sender Node %d",
130*7c478bd9Sstevel@tonic-gate 			    snet, node);
131*7c478bd9Sstevel@tonic-gate 			if (extended)
132*7c478bd9Sstevel@tonic-gate 				show_rtmp_tuples(&data[4], tuples);
133*7c478bd9Sstevel@tonic-gate 			else
134*7c478bd9Sstevel@tonic-gate 				show_rtmp_tuples(&data[7], tuples-1);
135*7c478bd9Sstevel@tonic-gate 		}
136*7c478bd9Sstevel@tonic-gate 
137*7c478bd9Sstevel@tonic-gate 		break;
138*7c478bd9Sstevel@tonic-gate 	}
139*7c478bd9Sstevel@tonic-gate 	return;
140*7c478bd9Sstevel@tonic-gate out:
141*7c478bd9Sstevel@tonic-gate 	if (flags & F_SUM) {
142*7c478bd9Sstevel@tonic-gate 		(void) snprintf(get_sum_line(), MAXLINE,
143*7c478bd9Sstevel@tonic-gate 		    "RTMP (short packet)");
144*7c478bd9Sstevel@tonic-gate 	}
145*7c478bd9Sstevel@tonic-gate 
146*7c478bd9Sstevel@tonic-gate 	if (flags & F_DTAIL) {
147*7c478bd9Sstevel@tonic-gate 		show_header("RTMP: ", "RTMP Header", len);
148*7c478bd9Sstevel@tonic-gate 		show_space();
149*7c478bd9Sstevel@tonic-gate 
150*7c478bd9Sstevel@tonic-gate 		(void) snprintf(get_line(0, 0), get_line_remain(),
151*7c478bd9Sstevel@tonic-gate 		    "(short packet)");
152*7c478bd9Sstevel@tonic-gate 	}
153*7c478bd9Sstevel@tonic-gate }
154*7c478bd9Sstevel@tonic-gate 
155*7c478bd9Sstevel@tonic-gate static void
show_rtmp_tuples(uint8_t * p,int tuples)156*7c478bd9Sstevel@tonic-gate show_rtmp_tuples(uint8_t *p, int tuples)
157*7c478bd9Sstevel@tonic-gate {
158*7c478bd9Sstevel@tonic-gate 	while (tuples > 0) {
159*7c478bd9Sstevel@tonic-gate 
160*7c478bd9Sstevel@tonic-gate 		if (p[2] & RTMP_EXTEND) { /* extended tuple? */
161*7c478bd9Sstevel@tonic-gate 
162*7c478bd9Sstevel@tonic-gate 			(void) snprintf(get_line(0, 0),
163*7c478bd9Sstevel@tonic-gate 			    get_line_remain(),
164*7c478bd9Sstevel@tonic-gate 			    "Network = %d-%d, Distance = %d",
165*7c478bd9Sstevel@tonic-gate 			    get_short(p), get_short(&p[3]),
166*7c478bd9Sstevel@tonic-gate 			    p[2] & RTMP_DIST_MASK);
167*7c478bd9Sstevel@tonic-gate 			p += 6;
168*7c478bd9Sstevel@tonic-gate 			tuples -= 2;
169*7c478bd9Sstevel@tonic-gate 		} else {
170*7c478bd9Sstevel@tonic-gate 
171*7c478bd9Sstevel@tonic-gate 			(void) snprintf(get_line(0, 0),
172*7c478bd9Sstevel@tonic-gate 			    get_line_remain(),
173*7c478bd9Sstevel@tonic-gate 			    "Network = %d, Distance = %d",
174*7c478bd9Sstevel@tonic-gate 			    get_short(p), p[2]);
175*7c478bd9Sstevel@tonic-gate 			p += 3;
176*7c478bd9Sstevel@tonic-gate 			tuples--;
177*7c478bd9Sstevel@tonic-gate 		}
178*7c478bd9Sstevel@tonic-gate 	}
179*7c478bd9Sstevel@tonic-gate }
180