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