]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/dtrace/tcpdebug
MFH r289384-r293170
[FreeBSD/FreeBSD.git] / share / dtrace / tcpdebug
1 #!/usr/sbin/dtrace -s
2 /*
3  * Copyright (c) 2015 George V. Neville-Neil
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  *
27  * $FreeBSD$
28  *
29  * The tcpdebug D script uses the tcp:kernel::debug tracepoints
30  * to replicate the action of turning on TCPDEBUG in a kernel configuration.
31  *
32  * A TCP debug statement shows a connection's
33  *
34  * direction:   input, output, user, drop
35  * state:       CLOSED, LISTEN, SYN_SENT, SYN_RCVD, ESTABLISHED,
36  *              CLOSE_WAIT, FIN_WAIT_1, CLOSING, LAST_ACK, FIN_WAIT_2,TIME_WAIT
37  * sequence:    sequence space
38  *
39  * congestion:  rcv_nxt, rcv_wnd, rcv_up, snd_una, snd_nxt, snx_max,
40  *              snd_wl1, snd_wl2, snd_wnd
41  *
42  * NOTE: Only sockets with SO_DEBUG set will be shown.
43  * 
44  * Usage: tcpdebug
45  */
46
47 #pragma D option quiet
48 tcp:kernel::debug-input
49 /args[0]->tcps_debug/
50 {
51         seq = args[1]->tcp_seq;
52         ack = args[1]->tcp_ack;
53         len = args[2]->ip_plength - sizeof(struct tcphdr);
54         flags = args[1]->tcp_flags;
55         
56         printf("%p %s: input [%xu..%xu]", arg0,
57                tcp_state_string[args[0]->tcps_state], seq, seq + len);
58
59         printf("@%x, urp=%x", ack, args[1]->tcp_urgent);
60
61         printf("%s", flags != 0 ? "<" : "");
62         printf("%s", flags & TH_SYN ? "SYN," :"");
63         printf("%s", flags & TH_ACK ? "ACK," :"");
64         printf("%s", flags & TH_FIN ? "FIN," :"");
65         printf("%s", flags & TH_RST ? "RST," :"");
66         printf("%s", flags & TH_PUSH ? "PUSH," :"");
67         printf("%s", flags & TH_URG ? "URG," :"");
68         printf("%s", flags & TH_ECE ? "ECE," :"");
69         printf("%s", flags & TH_CWR ? "CWR" :"");
70         printf("%s", flags != 0 ? ">" : "");
71
72         printf("\n");
73         printf("\trcv_(nxt,wnd,up) (%x,%x,%x) snd_(una,nxt,max) (%x,%x,%x)\n",
74                args[0]->tcps_rnxt, args[0]->tcps_rwnd, args[0]->tcps_rup,
75                args[0]->tcps_suna, args[0]->tcps_snxt, args[0]->tcps_smax);
76         printf("\tsnd_(wl1,wl2,wnd) (%x,%x,%x)\n",
77                args[0]->tcps_swl1, args[0]->tcps_swl2, args[0]->tcps_swnd);
78
79 }
80
81 tcp:kernel::debug-output
82 /args[0]->tcps_debug/
83 {
84         seq = args[1]->tcp_seq;
85         ack = args[1]->tcp_ack;
86         len = args[2]->ip_plength - 20;
87
88         printf("%p %s: output [%x..%x]", arg0,
89                tcp_state_string[args[0]->tcps_state], seq, seq + len);
90
91         printf("@%x, urp=%x", ack, args[1]->tcp_urgent);
92
93         printf("%s", flags != 0 ? "<" : "");
94         printf("%s", flags & TH_SYN ? "SYN," :"");
95         printf("%s", flags & TH_ACK ? "ACK," :"");
96         printf("%s", flags & TH_FIN ? "FIN," :"");
97         printf("%s", flags & TH_RST ? "RST," :"");
98         printf("%s", flags & TH_PUSH ? "PUSH," :"");
99         printf("%s", flags & TH_URG ? "URG," :"");
100         printf("%s", flags & TH_ECE ? "ECE," :"");
101         printf("%s", flags & TH_CWR ? "CWR" :"");
102         printf("%s", flags != 0 ? ">" : "");
103
104         printf("\n");
105         printf("\trcv_(nxt,wnd,up) (%u,%x,%x) snd_(una,nxt,max) (%x,%x,%x)\n",
106                args[0]->tcps_rnxt, args[0]->tcps_rwnd, args[0]->tcps_rup,
107                args[0]->tcps_suna, args[0]->tcps_snxt, args[0]->tcps_smax);
108         printf("\tsnd_(wl1,wl2,wnd) (%x,%x,%x)\n",
109                args[0]->tcps_swl1, args[0]->tcps_swl2, args[0]->tcps_swnd);
110
111 }
112
113 tcp:kernel::debug-drop
114 /args[0]->tcps_debug/
115 {
116         printf("%p %s: output [x..x] @%x, urp=%x\n", arg0,
117                tcp_state_string[args[0]->tcps_state],
118                args[1]->tcp_ack,
119                args[1]->tcp_urgent);
120
121         seq = args[1]->tcp_seq;
122         ack = args[1]->tcp_ack;
123         len = args[2]->ip_plength;
124
125         printf("%p %s: drop [%x..%x]", arg0,
126                tcp_state_string[args[0]->tcps_state], seq, seq + len);
127
128         printf("@%x, urp=%x", ack, args[1]->tcp_urgent);
129
130         printf("%s", flags != 0 ? "<" : "");
131         printf("%s", flags & TH_SYN ? "SYN," :"");
132         printf("%s", flags & TH_ACK ? "ACK," :"");
133         printf("%s", flags & TH_FIN ? "FIN," :"");
134         printf("%s", flags & TH_RST ? "RST," :"");
135         printf("%s", flags & TH_PUSH ? "PUSH," :"");
136         printf("%s", flags & TH_URG ? "URG," :"");
137         printf("%s", flags & TH_ECE ? "ECE," :"");
138         printf("%s", flags & TH_CWR ? "CWR" :"");
139         printf("%s", flags != 0 ? ">" : "");
140
141         printf("\n");
142         printf("\trcv_(nxt,wnd,up) (%x,%x,%x) snd_(una,nxt,max) (%x,%x,%x)\n",
143                args[0]->tcps_rnxt, args[0]->tcps_rwnd, args[0]->tcps_rup,
144                args[0]->tcps_suna, args[0]->tcps_snxt, args[0]->tcps_smax);
145         printf("\tsnd_(wl1,wl2,wnd) (%x,%x,%x)\n",
146                args[0]->tcps_swl1, args[0]->tcps_swl2, args[0]->tcps_swnd);
147
148 }
149
150 tcp:kernel::debug-user
151 /args[0]->tcps_debug/
152 {
153         printf("%p %s: user ", arg0,
154                tcp_state_string[args[0]->tcps_state]);
155
156         printf("%s", prureq_string[arg1]);
157         printf("\n");
158         printf("\trcv_(nxt,wnd,up) (%x,%x,%x) snd_(una,nxt,max) (%x,%x,%x)\n",
159                args[0]->tcps_rnxt, args[0]->tcps_rwnd, args[0]->tcps_rup,
160                args[0]->tcps_suna, args[0]->tcps_snxt, args[0]->tcps_smax);
161         printf("\tsnd_(wl1,wl2,wnd) (%x,%x,%x)\n",
162                args[0]->tcps_swl1, args[0]->tcps_swl2, args[0]->tcps_swnd);
163
164 }
165