1 /*-
2 * Copyright (c) 1982, 1986, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 4. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * @(#)tcp_debug.c 8.1 (Berkeley) 6/10/93
30 * $FreeBSD$
31 */
32
33 #include "opt_inet.h"
34 #include "opt_inet6.h"
35 #include "opt_tcpdebug.h"
36
37 #ifndef INET
38 #error The option TCPDEBUG requires option INET.
39 #endif
40
41 #ifdef TCPDEBUG
42 /* load symbolic names */
43 #define PRUREQUESTS
44 #define TCPSTATES
45 #define TCPTIMERS
46 #define TANAMES
47 #endif
48
49 #include <sys/param.h>
50 #include <sys/systm.h>
51 #include <sys/mbuf.h>
52 #include <sys/protosw.h>
53 #include <sys/socket.h>
54
55 #include <netinet/in.h>
56 #include <netinet/in_systm.h>
57 #include <netinet/ip.h>
58 #ifdef INET6
59 #include <netinet/ip6.h>
60 #endif
61 #include <netinet/ip_var.h>
62 #include <netinet/tcp.h>
63 #include <netinet/tcp_fsm.h>
64 #include <netinet/tcp_timer.h>
65 #include <netinet/tcp_var.h>
66 #include <netinet/tcpip.h>
67 #include <netinet/tcp_debug.h>
68
69 #ifdef TCPDEBUG
70 static int tcpconsdebug = 0;
71 #endif
72
73 static struct tcp_debug tcp_debug[TCP_NDEBUG];
74 static int tcp_debx;
75
76 /*
77 * Tcp debug routines
78 */
79 void
80 tcp_trace(act, ostate, tp, ipgen, th, req)
81 short act, ostate;
82 struct tcpcb *tp;
83 void *ipgen;
84 struct tcphdr *th;
85 int req;
86 {
87 #ifdef INET6
88 int isipv6;
89 #endif /* INET6 */
90 tcp_seq seq, ack;
91 int len, flags;
92 struct tcp_debug *td = &tcp_debug[tcp_debx++];
93
94 #ifdef INET6
95 isipv6 = (ipgen != NULL && ((struct ip *)ipgen)->ip_v == 6) ? 1 : 0;
96 #endif /* INET6 */
97 td->td_family =
98 #ifdef INET6
99 (isipv6 != 0) ? AF_INET6 :
100 #endif
101 AF_INET;
102 if (tcp_debx == TCP_NDEBUG)
103 tcp_debx = 0;
104 td->td_time = iptime();
105 td->td_act = act;
106 td->td_ostate = ostate;
107 td->td_tcb = (caddr_t)tp;
108 if (tp)
109 td->td_cb = *tp;
110 else
111 bzero((caddr_t)&td->td_cb, sizeof (*tp));
112 if (ipgen) {
113 switch (td->td_family) {
114 case AF_INET:
115 bcopy((caddr_t)ipgen, (caddr_t)&td->td_ti.ti_i,
116 sizeof(td->td_ti.ti_i));
117 bzero((caddr_t)td->td_ip6buf, sizeof(td->td_ip6buf));
118 break;
119 #ifdef INET6
120 case AF_INET6:
121 bcopy((caddr_t)ipgen, (caddr_t)td->td_ip6buf,
122 sizeof(td->td_ip6buf));
123 bzero((caddr_t)&td->td_ti.ti_i,
124 sizeof(td->td_ti.ti_i));
125 break;
126 #endif
127 default:
128 bzero((caddr_t)td->td_ip6buf, sizeof(td->td_ip6buf));
129 bzero((caddr_t)&td->td_ti.ti_i,
130 sizeof(td->td_ti.ti_i));
131 break;
132 }
133 } else {
134 bzero((caddr_t)&td->td_ti.ti_i, sizeof(td->td_ti.ti_i));
135 bzero((caddr_t)td->td_ip6buf, sizeof(td->td_ip6buf));
136 }
137 if (th) {
138 switch (td->td_family) {
139 case AF_INET:
140 td->td_ti.ti_t = *th;
141 bzero((caddr_t)&td->td_ti6.th, sizeof(td->td_ti6.th));
142 break;
143 #ifdef INET6
144 case AF_INET6:
145 td->td_ti6.th = *th;
146 bzero((caddr_t)&td->td_ti.ti_t,
147 sizeof(td->td_ti.ti_t));
148 break;
149 #endif
150 default:
151 bzero((caddr_t)&td->td_ti.ti_t,
152 sizeof(td->td_ti.ti_t));
153 bzero((caddr_t)&td->td_ti6.th, sizeof(td->td_ti6.th));
154 break;
155 }
156 } else {
157 bzero((caddr_t)&td->td_ti.ti_t, sizeof(td->td_ti.ti_t));
158 bzero((caddr_t)&td->td_ti6.th, sizeof(td->td_ti6.th));
159 }
160 td->td_req = req;
161 #ifdef TCPDEBUG
162 if (tcpconsdebug == 0)
163 return;
164 if (tp)
165 printf("%p %s:", tp, tcpstates[ostate]);
166 else
167 printf("???????? ");
168 printf("%s ", tanames[act]);
169 switch (act) {
170
171 case TA_INPUT:
172 case TA_OUTPUT:
173 case TA_DROP:
174 if (ipgen == NULL || th == NULL)
175 break;
176 seq = th->th_seq;
177 ack = th->th_ack;
178 len =
179 #ifdef INET6
180 isipv6 ? ((struct ip6_hdr *)ipgen)->ip6_plen :
181 #endif
182 ((struct ip *)ipgen)->ip_len;
183 if (act == TA_OUTPUT) {
184 seq = ntohl(seq);
185 ack = ntohl(ack);
186 len = ntohs((u_short)len);
187 }
188 if (act == TA_OUTPUT)
189 len -= sizeof (struct tcphdr);
190 if (len)
191 printf("[%x..%x)", seq, seq+len);
192 else
193 printf("%x", seq);
194 printf("@%x, urp=%x", ack, th->th_urp);
195 flags = th->th_flags;
196 if (flags) {
197 char *cp = "<";
198 #define pf(f) { \
199 if (th->th_flags & TH_##f) { \
200 printf("%s%s", cp, #f); \
201 cp = ","; \
202 } \
203 }
204 pf(SYN); pf(ACK); pf(FIN); pf(RST); pf(PUSH); pf(URG);
205 printf(">");
206 }
207 break;
208
209 case TA_USER:
210 printf("%s", prurequests[req&0xff]);
211 if ((req & 0xff) == PRU_SLOWTIMO)
212 printf("<%s>", tcptimers[req>>8]);
213 break;
214 }
215 if (tp)
216 printf(" -> %s", tcpstates[tp->t_state]);
217 /* print out internal state of tp !?! */
218 printf("\n");
219 if (tp == 0)
220 return;
221 printf(
222 "\trcv_(nxt,wnd,up) (%lx,%lx,%lx) snd_(una,nxt,max) (%lx,%lx,%lx)\n",
223 (u_long)tp->rcv_nxt, tp->rcv_wnd, (u_long)tp->rcv_up,
224 (u_long)tp->snd_una, (u_long)tp->snd_nxt, (u_long)tp->snd_max);
225 printf("\tsnd_(wl1,wl2,wnd) (%lx,%lx,%lx)\n",
226 (u_long)tp->snd_wl1, (u_long)tp->snd_wl2, tp->snd_wnd);
227 #endif /* TCPDEBUG */
228 }
Cache object: 9f2ad86aa24fffeb4b1a7dfee4d8ddac
|