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