1 |
1254 |
phoenix |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// sys/netinet/tcp_debug.c
|
4 |
|
|
//
|
5 |
|
|
//
|
6 |
|
|
//
|
7 |
|
|
//==========================================================================
|
8 |
|
|
//####BSDCOPYRIGHTBEGIN####
|
9 |
|
|
//
|
10 |
|
|
// -------------------------------------------
|
11 |
|
|
//
|
12 |
|
|
// Portions of this software may have been derived from OpenBSD or other sources,
|
13 |
|
|
// and are covered by the appropriate copyright disclaimers included herein.
|
14 |
|
|
//
|
15 |
|
|
// -------------------------------------------
|
16 |
|
|
//
|
17 |
|
|
//####BSDCOPYRIGHTEND####
|
18 |
|
|
//==========================================================================
|
19 |
|
|
//#####DESCRIPTIONBEGIN####
|
20 |
|
|
//
|
21 |
|
|
// Author(s): gthomas
|
22 |
|
|
// Contributors: gthomas
|
23 |
|
|
// Date: 2000-01-10
|
24 |
|
|
// Purpose:
|
25 |
|
|
// Description:
|
26 |
|
|
//
|
27 |
|
|
//
|
28 |
|
|
//####DESCRIPTIONEND####
|
29 |
|
|
//
|
30 |
|
|
//==========================================================================
|
31 |
|
|
|
32 |
|
|
|
33 |
|
|
/* $OpenBSD: tcp_debug.c,v 1.6 1999/12/08 06:50:20 itojun Exp $ */
|
34 |
|
|
/* $NetBSD: tcp_debug.c,v 1.10 1996/02/13 23:43:36 christos Exp $ */
|
35 |
|
|
|
36 |
|
|
/*
|
37 |
|
|
* Copyright (c) 1982, 1986, 1993
|
38 |
|
|
* The Regents of the University of California. All rights reserved.
|
39 |
|
|
*
|
40 |
|
|
* Redistribution and use in source and binary forms, with or without
|
41 |
|
|
* modification, are permitted provided that the following conditions
|
42 |
|
|
* are met:
|
43 |
|
|
* 1. Redistributions of source code must retain the above copyright
|
44 |
|
|
* notice, this list of conditions and the following disclaimer.
|
45 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
46 |
|
|
* notice, this list of conditions and the following disclaimer in the
|
47 |
|
|
* documentation and/or other materials provided with the distribution.
|
48 |
|
|
* 3. All advertising materials mentioning features or use of this software
|
49 |
|
|
* must display the following acknowledgement:
|
50 |
|
|
* This product includes software developed by the University of
|
51 |
|
|
* California, Berkeley and its contributors.
|
52 |
|
|
* 4. Neither the name of the University nor the names of its contributors
|
53 |
|
|
* may be used to endorse or promote products derived from this software
|
54 |
|
|
* without specific prior written permission.
|
55 |
|
|
*
|
56 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
57 |
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
58 |
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
59 |
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
60 |
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
61 |
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
62 |
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
63 |
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
64 |
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
65 |
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
66 |
|
|
* SUCH DAMAGE.
|
67 |
|
|
*
|
68 |
|
|
* @(#)tcp_debug.c 8.1 (Berkeley) 6/10/93
|
69 |
|
|
*/
|
70 |
|
|
|
71 |
|
|
/*
|
72 |
|
|
%%% portions-copyright-nrl-95
|
73 |
|
|
Portions of this software are Copyright 1995-1998 by Randall Atkinson,
|
74 |
|
|
Ronald Lee, Daniel McDonald, Bao Phan, and Chris Winters. All Rights
|
75 |
|
|
Reserved. All rights under this copyright have been assigned to the US
|
76 |
|
|
Naval Research Laboratory (NRL). The NRL Copyright Notice and License
|
77 |
|
|
Agreement Version 1.1 (January 17, 1995) applies to these portions of the
|
78 |
|
|
software.
|
79 |
|
|
You should have received a copy of the license with this software. If you
|
80 |
|
|
didn't get a copy, you may request one from <license@ipv6.nrl.navy.mil>.
|
81 |
|
|
*/
|
82 |
|
|
|
83 |
|
|
#ifdef TCPDEBUG
|
84 |
|
|
/* load symbolic names */
|
85 |
|
|
#define PRUREQUESTS
|
86 |
|
|
#define TCPSTATES
|
87 |
|
|
#define TCPTIMERS
|
88 |
|
|
#define TANAMES
|
89 |
|
|
|
90 |
|
|
#include <sys/param.h>
|
91 |
|
|
#ifndef __ECOS
|
92 |
|
|
#include <sys/systm.h>
|
93 |
|
|
#endif
|
94 |
|
|
#include <sys/mbuf.h>
|
95 |
|
|
#include <sys/socket.h>
|
96 |
|
|
#include <sys/socketvar.h>
|
97 |
|
|
#include <sys/protosw.h>
|
98 |
|
|
#include <sys/errno.h>
|
99 |
|
|
|
100 |
|
|
#include <net/route.h>
|
101 |
|
|
#include <net/if.h>
|
102 |
|
|
|
103 |
|
|
#include <netinet/in.h>
|
104 |
|
|
#include <netinet/in_systm.h>
|
105 |
|
|
#include <netinet/ip.h>
|
106 |
|
|
#include <netinet/in_pcb.h>
|
107 |
|
|
#include <netinet/ip_var.h>
|
108 |
|
|
#include <netinet/tcp.h>
|
109 |
|
|
#include <netinet/tcp_fsm.h>
|
110 |
|
|
#include <netinet/tcp_seq.h>
|
111 |
|
|
#include <netinet/tcp_timer.h>
|
112 |
|
|
#include <netinet/tcp_var.h>
|
113 |
|
|
#include <netinet/tcpip.h>
|
114 |
|
|
#include <netinet/tcp_debug.h>
|
115 |
|
|
|
116 |
|
|
#ifdef INET6
|
117 |
|
|
#ifndef INET
|
118 |
|
|
#include <netinet/in.h>
|
119 |
|
|
#endif
|
120 |
|
|
#include <netinet6/ip6.h>
|
121 |
|
|
#endif /* INET6 */
|
122 |
|
|
|
123 |
|
|
#ifdef TCPDEBUG
|
124 |
|
|
int tcpconsdebug = 1;
|
125 |
|
|
#endif
|
126 |
|
|
/*
|
127 |
|
|
* Tcp debug routines
|
128 |
|
|
*/
|
129 |
|
|
void
|
130 |
|
|
tcp_trace(act, ostate, tp, headers, req, len)
|
131 |
|
|
short act, ostate;
|
132 |
|
|
struct tcpcb *tp;
|
133 |
|
|
caddr_t headers;
|
134 |
|
|
int req;
|
135 |
|
|
int len;
|
136 |
|
|
{
|
137 |
|
|
#ifdef TCPDEBUG
|
138 |
|
|
tcp_seq seq, ack;
|
139 |
|
|
int flags;
|
140 |
|
|
#endif
|
141 |
|
|
struct tcp_debug *td = &tcp_debug[tcp_debx++];
|
142 |
|
|
struct tcpiphdr *ti = (struct tcpiphdr *)headers;
|
143 |
|
|
#ifdef INET6
|
144 |
|
|
struct tcphdr *th;
|
145 |
|
|
struct tcpipv6hdr *ti6 = (struct tcpipv6hdr *)ti;
|
146 |
|
|
#endif
|
147 |
|
|
|
148 |
|
|
if (tcp_debx == TCP_NDEBUG)
|
149 |
|
|
tcp_debx = 0;
|
150 |
|
|
td->td_time = iptime();
|
151 |
|
|
td->td_act = act;
|
152 |
|
|
td->td_ostate = ostate;
|
153 |
|
|
td->td_tcb = (caddr_t)tp;
|
154 |
|
|
if (tp)
|
155 |
|
|
td->td_cb = *tp;
|
156 |
|
|
else
|
157 |
|
|
bzero((caddr_t)&td->td_cb, sizeof (*tp));
|
158 |
|
|
#ifdef INET6
|
159 |
|
|
if (tp->pf == PF_INET6) {
|
160 |
|
|
if (ti) {
|
161 |
|
|
th = &ti6->ti6_t;
|
162 |
|
|
td->td_ti6 = *ti6;
|
163 |
|
|
} else {
|
164 |
|
|
bzero(&td->td_ti6, sizeof(struct tcpipv6hdr));
|
165 |
|
|
}
|
166 |
|
|
} else {
|
167 |
|
|
if (ti) {
|
168 |
|
|
th = &ti->ti_t;
|
169 |
|
|
td->td_ti = *ti;
|
170 |
|
|
} else {
|
171 |
|
|
bzero(&td->td_ti, sizeof(struct tcpiphdr));
|
172 |
|
|
}
|
173 |
|
|
}
|
174 |
|
|
#else /* INET6 */
|
175 |
|
|
if (ti)
|
176 |
|
|
td->td_ti = *ti;
|
177 |
|
|
else
|
178 |
|
|
bzero((caddr_t)&td->td_ti, sizeof (*ti));
|
179 |
|
|
#endif /* INET6 */
|
180 |
|
|
|
181 |
|
|
td->td_req = req;
|
182 |
|
|
#ifdef TCPDEBUG
|
183 |
|
|
if (tcpconsdebug == 0)
|
184 |
|
|
return;
|
185 |
|
|
if (tp)
|
186 |
|
|
printf("%x %s:", tp, tcpstates[ostate]);
|
187 |
|
|
else
|
188 |
|
|
printf("???????? ");
|
189 |
|
|
printf("%s ", tanames[act]);
|
190 |
|
|
switch (act) {
|
191 |
|
|
|
192 |
|
|
case TA_INPUT:
|
193 |
|
|
case TA_OUTPUT:
|
194 |
|
|
case TA_DROP:
|
195 |
|
|
if (ti == 0)
|
196 |
|
|
break;
|
197 |
|
|
seq = th->th_seq;
|
198 |
|
|
ack = th->th_ack;
|
199 |
|
|
if (act == TA_OUTPUT) {
|
200 |
|
|
seq = ntohl(seq);
|
201 |
|
|
ack = ntohl(ack);
|
202 |
|
|
}
|
203 |
|
|
if (len)
|
204 |
|
|
printf("[%x..%x)", seq, seq+len);
|
205 |
|
|
else
|
206 |
|
|
printf("%x", seq);
|
207 |
|
|
printf("@%x, urp=%x", ack, th->th_urp);
|
208 |
|
|
flags = th->th_flags;
|
209 |
|
|
if (flags) {
|
210 |
|
|
#ifndef lint
|
211 |
|
|
char *cp = "<";
|
212 |
|
|
#define pf(f) { if (th->th_flags&TH_/**/f) { printf("%s%s", cp, "f"); cp = ","; } }
|
213 |
|
|
pf(SYN); pf(ACK); pf(FIN); pf(RST); pf(PUSH); pf(URG);
|
214 |
|
|
#endif
|
215 |
|
|
printf(">");
|
216 |
|
|
}
|
217 |
|
|
break;
|
218 |
|
|
|
219 |
|
|
case TA_USER:
|
220 |
|
|
printf("%s", prurequests[req&0xff]);
|
221 |
|
|
if ((req & 0xff) == PRU_SLOWTIMO)
|
222 |
|
|
printf("<%s>", tcptimers[req>>8]);
|
223 |
|
|
break;
|
224 |
|
|
}
|
225 |
|
|
if (tp)
|
226 |
|
|
printf(" -> %s", tcpstates[tp->t_state]);
|
227 |
|
|
/* print out internal state of tp !?! */
|
228 |
|
|
printf("\n");
|
229 |
|
|
if (tp == 0)
|
230 |
|
|
return;
|
231 |
|
|
printf("\trcv_(nxt,wnd,up) (%x,%x,%x) snd_(una,nxt,max) (%x,%x,%x)\n",
|
232 |
|
|
tp->rcv_nxt, tp->rcv_wnd, tp->rcv_up, tp->snd_una, tp->snd_nxt,
|
233 |
|
|
tp->snd_max);
|
234 |
|
|
printf("\tsnd_(wl1,wl2,wnd) (%x,%x,%x)\n",
|
235 |
|
|
tp->snd_wl1, tp->snd_wl2, tp->snd_wnd);
|
236 |
|
|
#endif /* TCPDEBUG */
|
237 |
|
|
}
|
238 |
|
|
#endif
|