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 #pragma ident "%Z%%M% %I% %E% SMI"
28*7c478bd9Sstevel@tonic-gate
29*7c478bd9Sstevel@tonic-gate #include <stdio.h>
30*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
31*7c478bd9Sstevel@tonic-gate
32*7c478bd9Sstevel@tonic-gate #include <at.h>
33*7c478bd9Sstevel@tonic-gate #include <snoop.h>
34*7c478bd9Sstevel@tonic-gate
35*7c478bd9Sstevel@tonic-gate static void show_rtmp_tuples(uint8_t *, int);
36*7c478bd9Sstevel@tonic-gate
37*7c478bd9Sstevel@tonic-gate static char *
rtmp_func_long(uint8_t fun)38*7c478bd9Sstevel@tonic-gate rtmp_func_long(uint8_t fun)
39*7c478bd9Sstevel@tonic-gate {
40*7c478bd9Sstevel@tonic-gate switch (fun) {
41*7c478bd9Sstevel@tonic-gate case RTMP_REQ:
42*7c478bd9Sstevel@tonic-gate return ("Request");
43*7c478bd9Sstevel@tonic-gate case RTMP_RDR_SH:
44*7c478bd9Sstevel@tonic-gate return ("Route Data Request, split horizon");
45*7c478bd9Sstevel@tonic-gate case RTMP_RDR_NSH:
46*7c478bd9Sstevel@tonic-gate return ("Route Data Request, no split horizon");
47*7c478bd9Sstevel@tonic-gate default:
48*7c478bd9Sstevel@tonic-gate return ("unknown");
49*7c478bd9Sstevel@tonic-gate }
50*7c478bd9Sstevel@tonic-gate }
51*7c478bd9Sstevel@tonic-gate
52*7c478bd9Sstevel@tonic-gate static char *
rtmp_func_short(uint8_t fun)53*7c478bd9Sstevel@tonic-gate rtmp_func_short(uint8_t fun)
54*7c478bd9Sstevel@tonic-gate {
55*7c478bd9Sstevel@tonic-gate switch (fun) {
56*7c478bd9Sstevel@tonic-gate case RTMP_REQ:
57*7c478bd9Sstevel@tonic-gate return ("Req");
58*7c478bd9Sstevel@tonic-gate case RTMP_RDR_SH:
59*7c478bd9Sstevel@tonic-gate return ("RDR, sh");
60*7c478bd9Sstevel@tonic-gate case RTMP_RDR_NSH:
61*7c478bd9Sstevel@tonic-gate return ("RDR, no sh");
62*7c478bd9Sstevel@tonic-gate default:
63*7c478bd9Sstevel@tonic-gate return ("unknown");
64*7c478bd9Sstevel@tonic-gate }
65*7c478bd9Sstevel@tonic-gate }
66*7c478bd9Sstevel@tonic-gate
67*7c478bd9Sstevel@tonic-gate void
interpret_rtmp(int flags,struct ddp_hdr * ddp,int len)68*7c478bd9Sstevel@tonic-gate interpret_rtmp(int flags, struct ddp_hdr *ddp, int len)
69*7c478bd9Sstevel@tonic-gate {
70*7c478bd9Sstevel@tonic-gate uint8_t *data;
71*7c478bd9Sstevel@tonic-gate uint16_t snet;
72*7c478bd9Sstevel@tonic-gate uint8_t node;
73*7c478bd9Sstevel@tonic-gate int tuples;
74*7c478bd9Sstevel@tonic-gate int runt;
75*7c478bd9Sstevel@tonic-gate char extended;
76*7c478bd9Sstevel@tonic-gate
77*7c478bd9Sstevel@tonic-gate len -= DDPHDR_SIZE;
78*7c478bd9Sstevel@tonic-gate if (len < 0)
79*7c478bd9Sstevel@tonic-gate goto out;
80*7c478bd9Sstevel@tonic-gate
81*7c478bd9Sstevel@tonic-gate data = (uint8_t *)ddp + DDPHDR_SIZE;
82*7c478bd9Sstevel@tonic-gate
83*7c478bd9Sstevel@tonic-gate switch (ddp->ddp_type) {
84*7c478bd9Sstevel@tonic-gate case DDP_TYPE_RTMPRQ: /* simple rtmp */
85*7c478bd9Sstevel@tonic-gate if (len < 1)
86*7c478bd9Sstevel@tonic-gate goto out;
87*7c478bd9Sstevel@tonic-gate
88*7c478bd9Sstevel@tonic-gate if (flags & F_SUM) {
89*7c478bd9Sstevel@tonic-gate (void) snprintf(get_sum_line(), MAXLINE,
90*7c478bd9Sstevel@tonic-gate "RTMP F=%s",
91*7c478bd9Sstevel@tonic-gate rtmp_func_short(data[0]));
92*7c478bd9Sstevel@tonic-gate }
93*7c478bd9Sstevel@tonic-gate
94*7c478bd9Sstevel@tonic-gate if (flags & F_DTAIL) {
95*7c478bd9Sstevel@tonic-gate show_header("RTMP: ", "RTMP Header", len);
96*7c478bd9Sstevel@tonic-gate show_space();
97*7c478bd9Sstevel@tonic-gate
98*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(),
99*7c478bd9Sstevel@tonic-gate "Func = %d (%s)",
100*7c478bd9Sstevel@tonic-gate data[0], rtmp_func_long(data[0]));
101*7c478bd9Sstevel@tonic-gate }
102*7c478bd9Sstevel@tonic-gate break;
103*7c478bd9Sstevel@tonic-gate case DDP_TYPE_RTMPRESP: /* RTMP data */
104*7c478bd9Sstevel@tonic-gate if (len < 3)
105*7c478bd9Sstevel@tonic-gate goto out;
106*7c478bd9Sstevel@tonic-gate
107*7c478bd9Sstevel@tonic-gate snet = get_short(data);
108*7c478bd9Sstevel@tonic-gate if (data[2] != 8) /* ID length is always 8 */
109*7c478bd9Sstevel@tonic-gate return;
110*7c478bd9Sstevel@tonic-gate node = data[3]; /* assume id_len == 8 */
111*7c478bd9Sstevel@tonic-gate extended = (data[6] != RTMP_FILLER) &&
112*7c478bd9Sstevel@tonic-gate (get_short(&data[4]) != 0);
113*7c478bd9Sstevel@tonic-gate
114*7c478bd9Sstevel@tonic-gate tuples = (len - 4) / 3;
115*7c478bd9Sstevel@tonic-gate runt = (len - 4) % 3; /* integral length? */
116*7c478bd9Sstevel@tonic-gate
117*7c478bd9Sstevel@tonic-gate if (flags & F_SUM) {
118*7c478bd9Sstevel@tonic-gate (void) snprintf(get_sum_line(), MAXLINE,
119*7c478bd9Sstevel@tonic-gate "RTMP Data Snet=%d, Snode=%d%s",
120*7c478bd9Sstevel@tonic-gate snet, node, runt != 0 ? " (short)" : "");
121*7c478bd9Sstevel@tonic-gate }
122*7c478bd9Sstevel@tonic-gate
123*7c478bd9Sstevel@tonic-gate if (flags & F_DTAIL) {
124*7c478bd9Sstevel@tonic-gate show_header("RTMP: ", "RTMP Header", len);
125*7c478bd9Sstevel@tonic-gate show_space();
126*7c478bd9Sstevel@tonic-gate
127*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(),
128*7c478bd9Sstevel@tonic-gate "RTMP Data, Length = %d%s",
129*7c478bd9Sstevel@tonic-gate len, runt != 0 ? " (short packet)" : "");
130*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(),
131*7c478bd9Sstevel@tonic-gate "Senders Net = %d, Sender Node %d",
132*7c478bd9Sstevel@tonic-gate snet, node);
133*7c478bd9Sstevel@tonic-gate if (extended)
134*7c478bd9Sstevel@tonic-gate show_rtmp_tuples(&data[4], tuples);
135*7c478bd9Sstevel@tonic-gate else
136*7c478bd9Sstevel@tonic-gate show_rtmp_tuples(&data[7], tuples-1);
137*7c478bd9Sstevel@tonic-gate }
138*7c478bd9Sstevel@tonic-gate
139*7c478bd9Sstevel@tonic-gate break;
140*7c478bd9Sstevel@tonic-gate }
141*7c478bd9Sstevel@tonic-gate return;
142*7c478bd9Sstevel@tonic-gate out:
143*7c478bd9Sstevel@tonic-gate if (flags & F_SUM) {
144*7c478bd9Sstevel@tonic-gate (void) snprintf(get_sum_line(), MAXLINE,
145*7c478bd9Sstevel@tonic-gate "RTMP (short packet)");
146*7c478bd9Sstevel@tonic-gate }
147*7c478bd9Sstevel@tonic-gate
148*7c478bd9Sstevel@tonic-gate if (flags & F_DTAIL) {
149*7c478bd9Sstevel@tonic-gate show_header("RTMP: ", "RTMP Header", len);
150*7c478bd9Sstevel@tonic-gate show_space();
151*7c478bd9Sstevel@tonic-gate
152*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(),
153*7c478bd9Sstevel@tonic-gate "(short packet)");
154*7c478bd9Sstevel@tonic-gate }
155*7c478bd9Sstevel@tonic-gate }
156*7c478bd9Sstevel@tonic-gate
157*7c478bd9Sstevel@tonic-gate static void
show_rtmp_tuples(uint8_t * p,int tuples)158*7c478bd9Sstevel@tonic-gate show_rtmp_tuples(uint8_t *p, int tuples)
159*7c478bd9Sstevel@tonic-gate {
160*7c478bd9Sstevel@tonic-gate while (tuples > 0) {
161*7c478bd9Sstevel@tonic-gate
162*7c478bd9Sstevel@tonic-gate if (p[2] & RTMP_EXTEND) { /* extended tuple? */
163*7c478bd9Sstevel@tonic-gate
164*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0),
165*7c478bd9Sstevel@tonic-gate get_line_remain(),
166*7c478bd9Sstevel@tonic-gate "Network = %d-%d, Distance = %d",
167*7c478bd9Sstevel@tonic-gate get_short(p), get_short(&p[3]),
168*7c478bd9Sstevel@tonic-gate p[2] & RTMP_DIST_MASK);
169*7c478bd9Sstevel@tonic-gate p += 6;
170*7c478bd9Sstevel@tonic-gate tuples -= 2;
171*7c478bd9Sstevel@tonic-gate } else {
172*7c478bd9Sstevel@tonic-gate
173*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0),
174*7c478bd9Sstevel@tonic-gate get_line_remain(),
175*7c478bd9Sstevel@tonic-gate "Network = %d, Distance = %d",
176*7c478bd9Sstevel@tonic-gate get_short(p), p[2]);
177*7c478bd9Sstevel@tonic-gate p += 3;
178*7c478bd9Sstevel@tonic-gate tuples--;
179*7c478bd9Sstevel@tonic-gate }
180*7c478bd9Sstevel@tonic-gate }
181*7c478bd9Sstevel@tonic-gate }
182