xref: /titanic_41/usr/src/cmd/dtrace/demo/ip/tcprst.d (revision fab254e2b865295c3dd79c791650a3161d99e196)
1*fab254e2SAruna Ramakrishna #!/usr/sbin/dtrace -Cqs
2*fab254e2SAruna Ramakrishna /*
3*fab254e2SAruna Ramakrishna  * CDDL HEADER START
4*fab254e2SAruna Ramakrishna  *
5*fab254e2SAruna Ramakrishna  * The contents of this file are subject to the terms of the
6*fab254e2SAruna Ramakrishna  * Common Development and Distribution License (the "License").
7*fab254e2SAruna Ramakrishna  * You may not use this file except in compliance with the License.
8*fab254e2SAruna Ramakrishna  *
9*fab254e2SAruna Ramakrishna  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*fab254e2SAruna Ramakrishna  * or http://www.opensolaris.org/os/licensing.
11*fab254e2SAruna Ramakrishna  * See the License for the specific language governing permissions
12*fab254e2SAruna Ramakrishna  * and limitations under the License.
13*fab254e2SAruna Ramakrishna  *
14*fab254e2SAruna Ramakrishna  * When distributing Covered Code, include this CDDL HEADER in each
15*fab254e2SAruna Ramakrishna  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*fab254e2SAruna Ramakrishna  * If applicable, add the following below this CDDL HEADER, with the
17*fab254e2SAruna Ramakrishna  * fields enclosed by brackets "[]" replaced with your own identifying
18*fab254e2SAruna Ramakrishna  * information: Portions Copyright [yyyy] [name of copyright owner]
19*fab254e2SAruna Ramakrishna  *
20*fab254e2SAruna Ramakrishna  * CDDL HEADER END
21*fab254e2SAruna Ramakrishna  */
22*fab254e2SAruna Ramakrishna /*
23*fab254e2SAruna Ramakrishna  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24*fab254e2SAruna Ramakrishna  * Use is subject to license terms.
25*fab254e2SAruna Ramakrishna  */
26*fab254e2SAruna Ramakrishna 
27*fab254e2SAruna Ramakrishna #pragma D option dynvarsize=64m
28*fab254e2SAruna Ramakrishna 
29*fab254e2SAruna Ramakrishna #define TH_RST		0x04
30*fab254e2SAruna Ramakrishna #define MAX_RECORDS	10
31*fab254e2SAruna Ramakrishna #define M_CTL		0x0d
32*fab254e2SAruna Ramakrishna 
33*fab254e2SAruna Ramakrishna #define PRINT_MAIN_HEADER()						\
34*fab254e2SAruna Ramakrishna 	(printf("\n%-25s %-6s %-25s %-6s %-10s %-10s %8s %8s\n",	\
35*fab254e2SAruna Ramakrishna 	    "LADDR", "LPORT", "RADDR", "RPORT", "ISS", "IRS",		\
36*fab254e2SAruna Ramakrishna 	    "SND_CNT", "RCV_CNT"))
37*fab254e2SAruna Ramakrishna 
38*fab254e2SAruna Ramakrishna #define PRINT_RECORD_HEADER()						\
39*fab254e2SAruna Ramakrishna 	(printf("%-20s %-20s %-3s %15s %15s %8s %8s %5s\n",		\
40*fab254e2SAruna Ramakrishna 	    "PROBENAME", "TIME", "S/R", "SEQ", "ACK", "DATALEN",	\
41*fab254e2SAruna Ramakrishna 	    "WND", "FLAGS"))
42*fab254e2SAruna Ramakrishna 
43*fab254e2SAruna Ramakrishna #define PRINT_MAIN_HEADER_VALUES()					\
44*fab254e2SAruna Ramakrishna 	(printf("%-25s %-6d %-25s %-6d %-10d %-10d %8d %8d\n",		\
45*fab254e2SAruna Ramakrishna 	    laddr[self->conn_id], lport[self->conn_id],			\
46*fab254e2SAruna Ramakrishna 	    faddr[self->conn_id], fport[self->conn_id],			\
47*fab254e2SAruna Ramakrishna 	    iss[self->conn_id], irs[self->conn_id],			\
48*fab254e2SAruna Ramakrishna 	    send_count[self->conn_id], recv_count[self->conn_id]))
49*fab254e2SAruna Ramakrishna 
50*fab254e2SAruna Ramakrishna #define PRINT_HEADER()							\
51*fab254e2SAruna Ramakrishna 	PRINT_MAIN_HEADER(); PRINT_MAIN_HEADER_VALUES();		\
52*fab254e2SAruna Ramakrishna 	    PRINT_RECORD_HEADER()
53*fab254e2SAruna Ramakrishna 
54*fab254e2SAruna Ramakrishna #define PRINT_RECORD(i)							\
55*fab254e2SAruna Ramakrishna 	(printf("%-20s %-20Y %-3s %15d %15d %8d %8d %2x\n",		\
56*fab254e2SAruna Ramakrishna 	    probe_name[self->conn_id, i],				\
57*fab254e2SAruna Ramakrishna 	    conn_time[self->conn_id, i],				\
58*fab254e2SAruna Ramakrishna 	    send_recv[self->conn_id, i],				\
59*fab254e2SAruna Ramakrishna 	    seqno[self->conn_id, i],					\
60*fab254e2SAruna Ramakrishna 	    ack[self->conn_id, i],					\
61*fab254e2SAruna Ramakrishna 	    datalen[self->conn_id, i],					\
62*fab254e2SAruna Ramakrishna 	    wnd[self->conn_id, i],					\
63*fab254e2SAruna Ramakrishna 	    flags[self->conn_id, i]))
64*fab254e2SAruna Ramakrishna 
65*fab254e2SAruna Ramakrishna tcp-trace-*
66*fab254e2SAruna Ramakrishna {
67*fab254e2SAruna Ramakrishna 	/* extract connection details */
68*fab254e2SAruna Ramakrishna 
69*fab254e2SAruna Ramakrishna 	this->mp = (mblk_t *)arg0;
70*fab254e2SAruna Ramakrishna 	this->mp = (this->mp->b_datap->db_type == M_CTL?
71*fab254e2SAruna Ramakrishna 	    this->mp->b_cont : this->mp);
72*fab254e2SAruna Ramakrishna 	self->tcpp = (tcp_t *)arg1;
73*fab254e2SAruna Ramakrishna 	this->connp = (conn_t *)self->tcpp->tcp_connp;
74*fab254e2SAruna Ramakrishna 
75*fab254e2SAruna Ramakrishna 	self->iph = (ipha_t *)this->mp->b_rptr;
76*fab254e2SAruna Ramakrishna 	this->iph_length =
77*fab254e2SAruna Ramakrishna 	    (int)(((ipha_t *)self->iph)->ipha_version_and_hdr_length
78*fab254e2SAruna Ramakrishna 	    & 0xF) << 2;
79*fab254e2SAruna Ramakrishna 	self->tcph = (tcpha_t *)((char *)self->iph + this->iph_length);
80*fab254e2SAruna Ramakrishna 	this->tcph_length =
81*fab254e2SAruna Ramakrishna 	    (((tcph_t *)self->tcph)->th_offset_and_rsrvd[0] >>2) &(0xF << 2);
82*fab254e2SAruna Ramakrishna 
83*fab254e2SAruna Ramakrishna 	/* ports */
84*fab254e2SAruna Ramakrishna 	self->i_lport = ntohs(this->connp->u_port.tcpu_ports.tcpu_lport);
85*fab254e2SAruna Ramakrishna 	self->i_fport = ntohs(this->connp->u_port.tcpu_ports.tcpu_fport);
86*fab254e2SAruna Ramakrishna 
87*fab254e2SAruna Ramakrishna 	/* IP addresses */
88*fab254e2SAruna Ramakrishna 	this->i_fad = (in6_addr_t *)&this->connp->connua_v6addr.connua_faddr;
89*fab254e2SAruna Ramakrishna 	this->i_lad = (in6_addr_t *)&this->connp->connua_v6addr.connua_laddr;
90*fab254e2SAruna Ramakrishna 
91*fab254e2SAruna Ramakrishna 	/* the address would either be IPv6 or IPv4-mapped-IPv6  */
92*fab254e2SAruna Ramakrishna 	self->i_faddr = inet_ntop(AF_INET6, (void *)this->i_fad);
93*fab254e2SAruna Ramakrishna 	self->i_laddr = inet_ntop(AF_INET6, (void *)this->i_lad);
94*fab254e2SAruna Ramakrishna 
95*fab254e2SAruna Ramakrishna 	/* create connection identifier, so we can track packets by conn */
96*fab254e2SAruna Ramakrishna 	self->conn_id = (uint64_t)self->tcpp->tcp_connp;
97*fab254e2SAruna Ramakrishna }
98*fab254e2SAruna Ramakrishna 
99*fab254e2SAruna Ramakrishna tcp-trace-*
100*fab254e2SAruna Ramakrishna /first[self->conn_id] == 0/
101*fab254e2SAruna Ramakrishna {
102*fab254e2SAruna Ramakrishna 	/* initialize counters - this is the first packet for this connection */
103*fab254e2SAruna Ramakrishna 	pcount[self->conn_id] = -1;
104*fab254e2SAruna Ramakrishna 	rollover[self->conn_id] = 0;
105*fab254e2SAruna Ramakrishna 	end_ptr[self->conn_id] = 0;
106*fab254e2SAruna Ramakrishna 	num[self->conn_id] = 0;
107*fab254e2SAruna Ramakrishna 
108*fab254e2SAruna Ramakrishna 	first[self->conn_id] = 1;
109*fab254e2SAruna Ramakrishna 
110*fab254e2SAruna Ramakrishna 	/* connection info */
111*fab254e2SAruna Ramakrishna 	laddr[self->conn_id] = self->i_laddr;
112*fab254e2SAruna Ramakrishna 	faddr[self->conn_id] = self->i_faddr;
113*fab254e2SAruna Ramakrishna 	lport[self->conn_id] = self->i_lport;
114*fab254e2SAruna Ramakrishna 	fport[self->conn_id] = self->i_fport;
115*fab254e2SAruna Ramakrishna 	iss[self->conn_id] = self->tcpp->tcp_iss;
116*fab254e2SAruna Ramakrishna 	irs[self->conn_id] = self->tcpp->tcp_irs;
117*fab254e2SAruna Ramakrishna 
118*fab254e2SAruna Ramakrishna }
119*fab254e2SAruna Ramakrishna 
120*fab254e2SAruna Ramakrishna tcp-trace-*
121*fab254e2SAruna Ramakrishna {
122*fab254e2SAruna Ramakrishna 	/* counters, to keep track of how much info to dump */
123*fab254e2SAruna Ramakrishna 	pcount[self->conn_id]++;
124*fab254e2SAruna Ramakrishna 	rollover[self->conn_id] |= pcount[self->conn_id]/MAX_RECORDS;
125*fab254e2SAruna Ramakrishna 	pcount[self->conn_id] = pcount[self->conn_id]%MAX_RECORDS;
126*fab254e2SAruna Ramakrishna 	self->pcount = pcount[self->conn_id];
127*fab254e2SAruna Ramakrishna 	end_ptr[self->conn_id] = self->pcount;
128*fab254e2SAruna Ramakrishna 	num[self->conn_id] = (rollover[self->conn_id]?
129*fab254e2SAruna Ramakrishna 	    MAX_RECORDS : pcount[self->conn_id] + 1);
130*fab254e2SAruna Ramakrishna 	conn_time[self->conn_id, self->pcount] = walltimestamp;
131*fab254e2SAruna Ramakrishna 
132*fab254e2SAruna Ramakrishna 	/* tcp state info */
133*fab254e2SAruna Ramakrishna 	seqno[self->conn_id, self->pcount] = ntohl(self->tcph->tha_seq);
134*fab254e2SAruna Ramakrishna 	ack[self->conn_id, self->pcount] = ntohl(self->tcph->tha_ack);
135*fab254e2SAruna Ramakrishna 	datalen[self->conn_id, self->pcount] =  ntohs(self->iph->ipha_length);
136*fab254e2SAruna Ramakrishna 	wnd[self->conn_id, self->pcount] =  ntohs(self->tcph->tha_win);
137*fab254e2SAruna Ramakrishna 	probe_name[self->conn_id, self->pcount] = probename;
138*fab254e2SAruna Ramakrishna 
139*fab254e2SAruna Ramakrishna 	/* flag 0x04 indicates a RST packet */
140*fab254e2SAruna Ramakrishna 	flags[self->conn_id, self->pcount] = self->tcph->tha_flags;
141*fab254e2SAruna Ramakrishna 	self->flags = self->tcph->tha_flags;
142*fab254e2SAruna Ramakrishna }
143*fab254e2SAruna Ramakrishna 
144*fab254e2SAruna Ramakrishna tcp-trace-send
145*fab254e2SAruna Ramakrishna {
146*fab254e2SAruna Ramakrishna 	send_count[self->conn_id]++;
147*fab254e2SAruna Ramakrishna 	send_recv[self->conn_id, self->pcount] = "S";
148*fab254e2SAruna Ramakrishna }
149*fab254e2SAruna Ramakrishna 
150*fab254e2SAruna Ramakrishna tcp-trace-recv
151*fab254e2SAruna Ramakrishna {
152*fab254e2SAruna Ramakrishna 	recv_count[self->conn_id]++;
153*fab254e2SAruna Ramakrishna 	send_recv[self->conn_id, self->pcount] = "R";
154*fab254e2SAruna Ramakrishna }
155*fab254e2SAruna Ramakrishna 
156*fab254e2SAruna Ramakrishna tcp-trace-*
157*fab254e2SAruna Ramakrishna /(self->flags & TH_RST)/
158*fab254e2SAruna Ramakrishna {
159*fab254e2SAruna Ramakrishna 	PRINT_HEADER();
160*fab254e2SAruna Ramakrishna 
161*fab254e2SAruna Ramakrishna 	self->i = (end_ptr[self->conn_id] + MAX_RECORDS - num[self->conn_id]
162*fab254e2SAruna Ramakrishna 	    + 1)%MAX_RECORDS;
163*fab254e2SAruna Ramakrishna }
164*fab254e2SAruna Ramakrishna 
165*fab254e2SAruna Ramakrishna tcp-trace-*
166*fab254e2SAruna Ramakrishna /(self->flags & TH_RST) && (num[self->conn_id] >= 10)/
167*fab254e2SAruna Ramakrishna {
168*fab254e2SAruna Ramakrishna 	PRINT_RECORD(self->i);
169*fab254e2SAruna Ramakrishna 	self->i = (self->i + 1)%MAX_RECORDS;
170*fab254e2SAruna Ramakrishna 
171*fab254e2SAruna Ramakrishna 	num[self->conn_id]--;
172*fab254e2SAruna Ramakrishna }
173*fab254e2SAruna Ramakrishna 
174*fab254e2SAruna Ramakrishna tcp-trace-*
175*fab254e2SAruna Ramakrishna /(self->flags & TH_RST) && (num[self->conn_id] >= 9)/
176*fab254e2SAruna Ramakrishna {
177*fab254e2SAruna Ramakrishna 	PRINT_RECORD(self->i);
178*fab254e2SAruna Ramakrishna 	self->i = (self->i + 1)%MAX_RECORDS;
179*fab254e2SAruna Ramakrishna 
180*fab254e2SAruna Ramakrishna 	num[self->conn_id]--;
181*fab254e2SAruna Ramakrishna }
182*fab254e2SAruna Ramakrishna 
183*fab254e2SAruna Ramakrishna tcp-trace-*
184*fab254e2SAruna Ramakrishna /(self->flags & TH_RST) && (num[self->conn_id] >= 8)/
185*fab254e2SAruna Ramakrishna {
186*fab254e2SAruna Ramakrishna 	PRINT_RECORD(self->i);
187*fab254e2SAruna Ramakrishna 	self->i = (self->i + 1)%MAX_RECORDS;
188*fab254e2SAruna Ramakrishna 
189*fab254e2SAruna Ramakrishna 	num[self->conn_id]--;
190*fab254e2SAruna Ramakrishna }
191*fab254e2SAruna Ramakrishna 
192*fab254e2SAruna Ramakrishna tcp-trace-*
193*fab254e2SAruna Ramakrishna /(self->flags & TH_RST) && (num[self->conn_id] >= 7)/
194*fab254e2SAruna Ramakrishna {
195*fab254e2SAruna Ramakrishna 	PRINT_RECORD(self->i);
196*fab254e2SAruna Ramakrishna 	self->i = (self->i + 1)%MAX_RECORDS;
197*fab254e2SAruna Ramakrishna 
198*fab254e2SAruna Ramakrishna 	num[self->conn_id]--;
199*fab254e2SAruna Ramakrishna }
200*fab254e2SAruna Ramakrishna 
201*fab254e2SAruna Ramakrishna tcp-trace-*
202*fab254e2SAruna Ramakrishna /(self->flags & TH_RST) && (num[self->conn_id] >= 6)/
203*fab254e2SAruna Ramakrishna {
204*fab254e2SAruna Ramakrishna 	PRINT_RECORD(self->i);
205*fab254e2SAruna Ramakrishna 	self->i = (self->i + 1)%MAX_RECORDS;
206*fab254e2SAruna Ramakrishna 
207*fab254e2SAruna Ramakrishna 	num[self->conn_id]--;
208*fab254e2SAruna Ramakrishna }
209*fab254e2SAruna Ramakrishna 
210*fab254e2SAruna Ramakrishna tcp-trace-*
211*fab254e2SAruna Ramakrishna /(self->flags & TH_RST) && (num[self->conn_id] >= 5)/
212*fab254e2SAruna Ramakrishna {
213*fab254e2SAruna Ramakrishna 	PRINT_RECORD(self->i);
214*fab254e2SAruna Ramakrishna 	self->i = (self->i + 1)%MAX_RECORDS;
215*fab254e2SAruna Ramakrishna 
216*fab254e2SAruna Ramakrishna 	num[self->conn_id]--;
217*fab254e2SAruna Ramakrishna }
218*fab254e2SAruna Ramakrishna 
219*fab254e2SAruna Ramakrishna tcp-trace-*
220*fab254e2SAruna Ramakrishna /(self->flags & TH_RST) && (num[self->conn_id] >= 4)/
221*fab254e2SAruna Ramakrishna {
222*fab254e2SAruna Ramakrishna 	PRINT_RECORD(self->i);
223*fab254e2SAruna Ramakrishna 	self->i = (self->i + 1)%MAX_RECORDS;
224*fab254e2SAruna Ramakrishna 
225*fab254e2SAruna Ramakrishna 	num[self->conn_id]--;
226*fab254e2SAruna Ramakrishna }
227*fab254e2SAruna Ramakrishna 
228*fab254e2SAruna Ramakrishna tcp-trace-*
229*fab254e2SAruna Ramakrishna /(self->flags & TH_RST) && (num[self->conn_id] >= 3)/
230*fab254e2SAruna Ramakrishna {
231*fab254e2SAruna Ramakrishna 	PRINT_RECORD(self->i);
232*fab254e2SAruna Ramakrishna 	self->i = (self->i + 1)%MAX_RECORDS;
233*fab254e2SAruna Ramakrishna 
234*fab254e2SAruna Ramakrishna 	num[self->conn_id]--;
235*fab254e2SAruna Ramakrishna }
236*fab254e2SAruna Ramakrishna 
237*fab254e2SAruna Ramakrishna tcp-trace-*
238*fab254e2SAruna Ramakrishna /(self->flags & TH_RST) && (num[self->conn_id] >= 2)/
239*fab254e2SAruna Ramakrishna {
240*fab254e2SAruna Ramakrishna 	PRINT_RECORD(self->i);
241*fab254e2SAruna Ramakrishna 	self->i = (self->i + 1)%MAX_RECORDS;
242*fab254e2SAruna Ramakrishna 
243*fab254e2SAruna Ramakrishna 	num[self->conn_id]--;
244*fab254e2SAruna Ramakrishna }
245*fab254e2SAruna Ramakrishna 
246*fab254e2SAruna Ramakrishna tcp-trace-*
247*fab254e2SAruna Ramakrishna /(self->flags & TH_RST) && (num[self->conn_id] >= 1)/
248*fab254e2SAruna Ramakrishna {
249*fab254e2SAruna Ramakrishna 	PRINT_RECORD(self->i);
250*fab254e2SAruna Ramakrishna 	self->i = (self->i + 1)%MAX_RECORDS;
251*fab254e2SAruna Ramakrishna 
252*fab254e2SAruna Ramakrishna 	num[self->conn_id]--;
253*fab254e2SAruna Ramakrishna 	self->reset = self->conn_id;
254*fab254e2SAruna Ramakrishna }
255*fab254e2SAruna Ramakrishna 
256*fab254e2SAruna Ramakrishna tcp-trace-*
257*fab254e2SAruna Ramakrishna /self->reset/
258*fab254e2SAruna Ramakrishna {
259*fab254e2SAruna Ramakrishna 	pcount[self->reset] = -1;
260*fab254e2SAruna Ramakrishna 	rollover[self->reset] = 0;
261*fab254e2SAruna Ramakrishna 	end_ptr[self->reset] = 0;
262*fab254e2SAruna Ramakrishna 	num[self->reset] = 0;
263*fab254e2SAruna Ramakrishna 
264*fab254e2SAruna Ramakrishna 	self->reset = 0;
265*fab254e2SAruna Ramakrishna }
266*fab254e2SAruna Ramakrishna 
267*fab254e2SAruna Ramakrishna conn-destroy
268*fab254e2SAruna Ramakrishna {
269*fab254e2SAruna Ramakrishna 	/* clear old connection state */
270*fab254e2SAruna Ramakrishna 	this->conn_id = (uint64_t)arg0;
271*fab254e2SAruna Ramakrishna 
272*fab254e2SAruna Ramakrishna 	pcount[this->conn_id] = -1;
273*fab254e2SAruna Ramakrishna 	rollover[this->conn_id] = 0;
274*fab254e2SAruna Ramakrishna 	end_ptr[this->conn_id] = 0;
275*fab254e2SAruna Ramakrishna 	num[this->conn_id] = 0;
276*fab254e2SAruna Ramakrishna 	first[this->conn_id] = 0;
277*fab254e2SAruna Ramakrishna 
278*fab254e2SAruna Ramakrishna 	laddr[this->conn_id] = 0;
279*fab254e2SAruna Ramakrishna 	faddr[this->conn_id] = 0;
280*fab254e2SAruna Ramakrishna 	lport[this->conn_id] = 0;
281*fab254e2SAruna Ramakrishna 	fport[this->conn_id] = 0;
282*fab254e2SAruna Ramakrishna 	iss[this->conn_id] = 0;
283*fab254e2SAruna Ramakrishna 	irs[this->conn_id] = 0;
284*fab254e2SAruna Ramakrishna }
285