3 * Copyright (c) 2015 George V. Neville-Neil
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
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
27 * The tcpdebug D script uses the tcp:kernel::debug tracepoints
28 * to replicate the action of turning on TCPDEBUG in a kernel configuration.
30 * A TCP debug statement shows a connection's
32 * direction: input, output, user, drop
33 * state: CLOSED, LISTEN, SYN_SENT, SYN_RCVD, ESTABLISHED,
34 * CLOSE_WAIT, FIN_WAIT_1, CLOSING, LAST_ACK, FIN_WAIT_2,TIME_WAIT
35 * sequence: sequence space
37 * congestion: rcv_nxt, rcv_wnd, rcv_up, snd_una, snd_nxt, snx_max,
38 * snd_wl1, snd_wl2, snd_wnd
40 * NOTE: Only sockets with SO_DEBUG set will be shown.
45 #pragma D option quiet
46 tcp:kernel::debug-input
49 seq = args[1]->tcp_seq;
50 ack = args[1]->tcp_ack;
51 len = args[2]->ip_plength - sizeof(struct tcphdr);
52 flags = args[1]->tcp_flags;
54 printf("%p %s: input [%xu..%xu]", arg0,
55 tcp_state_string[args[0]->tcps_state], seq, seq + len);
57 printf("@%x, urp=%x", ack, args[1]->tcp_urgent);
59 printf("%s", flags != 0 ? "<" : "");
60 printf("%s", flags & TH_SYN ? "SYN," :"");
61 printf("%s", flags & TH_ACK ? "ACK," :"");
62 printf("%s", flags & TH_FIN ? "FIN," :"");
63 printf("%s", flags & TH_RST ? "RST," :"");
64 printf("%s", flags & TH_PUSH ? "PUSH," :"");
65 printf("%s", flags & TH_URG ? "URG," :"");
66 printf("%s", flags & TH_ECE ? "ECE," :"");
67 printf("%s", flags & TH_CWR ? "CWR" :"");
68 printf("%s", flags != 0 ? ">" : "");
71 printf("\trcv_(nxt,wnd,up) (%x,%x,%x) snd_(una,nxt,max) (%x,%x,%x)\n",
72 args[0]->tcps_rnxt, args[0]->tcps_rwnd, args[0]->tcps_rup,
73 args[0]->tcps_suna, args[0]->tcps_snxt, args[0]->tcps_smax);
74 printf("\tsnd_(wl1,wl2,wnd) (%x,%x,%x)\n",
75 args[0]->tcps_swl1, args[0]->tcps_swl2, args[0]->tcps_swnd);
79 tcp:kernel::debug-output
82 seq = args[1]->tcp_seq;
83 ack = args[1]->tcp_ack;
84 len = args[2]->ip_plength - sizeof(struct tcphdr);
85 flags = args[1]->tcp_flags;
87 printf("%p %s: output [%x..%x]", arg0,
88 tcp_state_string[args[0]->tcps_state], seq, seq + len);
90 printf("@%x, urp=%x", ack, args[1]->tcp_urgent);
92 printf("%s", flags != 0 ? "<" : "");
93 printf("%s", flags & TH_SYN ? "SYN," :"");
94 printf("%s", flags & TH_ACK ? "ACK," :"");
95 printf("%s", flags & TH_FIN ? "FIN," :"");
96 printf("%s", flags & TH_RST ? "RST," :"");
97 printf("%s", flags & TH_PUSH ? "PUSH," :"");
98 printf("%s", flags & TH_URG ? "URG," :"");
99 printf("%s", flags & TH_ECE ? "ECE," :"");
100 printf("%s", flags & TH_CWR ? "CWR" :"");
101 printf("%s", flags != 0 ? ">" : "");
104 printf("\trcv_(nxt,wnd,up) (%u,%x,%x) snd_(una,nxt,max) (%x,%x,%x)\n",
105 args[0]->tcps_rnxt, args[0]->tcps_rwnd, args[0]->tcps_rup,
106 args[0]->tcps_suna, args[0]->tcps_snxt, args[0]->tcps_smax);
107 printf("\tsnd_(wl1,wl2,wnd) (%x,%x,%x)\n",
108 args[0]->tcps_swl1, args[0]->tcps_swl2, args[0]->tcps_swnd);
112 tcp:kernel::debug-drop
113 /args[0]->tcps_debug/
115 printf("%p %s: output [x..x] @%x, urp=%x\n", arg0,
116 tcp_state_string[args[0]->tcps_state],
118 args[1]->tcp_urgent);
120 seq = args[1]->tcp_seq;
121 ack = args[1]->tcp_ack;
122 len = args[2]->ip_plength - sizeof(struct tcphdr);
123 flags = args[1]->tcp_flags;
125 printf("%p %s: drop [%x..%x]", arg0,
126 tcp_state_string[args[0]->tcps_state], seq, seq + len);
128 printf("@%x, urp=%x", ack, args[1]->tcp_urgent);
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 ? ">" : "");
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);
150 tcp:kernel::debug-user
151 /args[0]->tcps_debug/
153 printf("%p %s: user ", arg0,
154 tcp_state_string[args[0]->tcps_state]);
156 printf("%s", prureq_string[arg1]);
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);