]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netinet/tcp_debug.c
61f1ad53a3b9db6f38bc054116fbaff31af0ac29
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 * Copyright (c) 1982, 1986, 1993
25 * The Regents of the University of California. All rights reserved.
27 * Redistribution and use in source and binary forms, with or without
28 * modification, are permitted provided that the following conditions
30 * 1. Redistributions of source code must retain the above copyright
31 * notice, this list of conditions and the following disclaimer.
32 * 2. Redistributions in binary form must reproduce the above copyright
33 * notice, this list of conditions and the following disclaimer in the
34 * documentation and/or other materials provided with the distribution.
35 * 3. All advertising materials mentioning features or use of this software
36 * must display the following acknowledgement:
37 * This product includes software developed by the University of
38 * California, Berkeley and its contributors.
39 * 4. Neither the name of the University nor the names of its contributors
40 * may be used to endorse or promote products derived from this software
41 * without specific prior written permission.
43 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
44 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
47 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
49 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
55 * @(#)tcp_debug.c 8.1 (Berkeley) 6/10/93
56 * $FreeBSD: src/sys/netinet/tcp_debug.c,v 1.16.2.1 2000/07/15 07:14:31 kris Exp $
61 #error The option TCPDEBUG requires option INET.
65 /* load symbolic names */
72 #include <sys/param.h>
73 #include <sys/systm.h>
74 #include <sys/protosw.h>
75 #include <sys/sysctl.h>
76 #include <sys/socket.h>
78 #include <netinet/in.h>
79 #include <netinet/in_systm.h>
80 #include <netinet/ip.h>
82 #include <netinet/ip6.h>
84 #include <netinet/ip_var.h>
85 #include <netinet/tcp.h>
86 #include <netinet/tcp_fsm.h>
87 #include <netinet/tcp_timer.h>
88 #include <netinet/tcp_var.h>
89 #include <netinet/tcpip.h>
90 #include <netinet/tcp_debug.h>
93 __private_extern__
int tcpconsdebug
= 0;
94 SYSCTL_INT(_net_inet_tcp
, OID_AUTO
, tcpconsdebug
, CTLFLAG_RW
,
95 &tcpconsdebug
, 0, "Turn tcp debugging on or off");
98 static struct tcp_debug tcp_debug
[TCP_NDEBUG
];
105 tcp_trace(act
, ostate
, tp
, ipgen
, th
, req
)
117 struct tcp_debug
*td
= &tcp_debug
[tcp_debx
++];
120 isipv6
= (ipgen
!= NULL
&& ((struct ip
*)ipgen
)->ip_v
== 6) ? 1 : 0;
124 (isipv6
!= 0) ? AF_INET6
:
127 if (tcp_debx
== TCP_NDEBUG
)
129 td
->td_time
= iptime();
131 td
->td_ostate
= ostate
;
132 td
->td_tcb
= (caddr_t
)tp
;
136 bzero((caddr_t
)&td
->td_cb
, sizeof (*tp
));
138 switch (td
->td_family
) {
140 bcopy((caddr_t
)ipgen
, (caddr_t
)&td
->td_ti
.ti_i
,
141 sizeof(td
->td_ti
.ti_i
));
142 bzero((caddr_t
)td
->td_ip6buf
, sizeof(td
->td_ip6buf
));
146 bcopy((caddr_t
)ipgen
, (caddr_t
)td
->td_ip6buf
,
147 sizeof(td
->td_ip6buf
));
148 bzero((caddr_t
)&td
->td_ti
.ti_i
,
149 sizeof(td
->td_ti
.ti_i
));
153 bzero((caddr_t
)td
->td_ip6buf
, sizeof(td
->td_ip6buf
));
154 bzero((caddr_t
)&td
->td_ti
.ti_i
,
155 sizeof(td
->td_ti
.ti_i
));
159 bzero((caddr_t
)&td
->td_ti
.ti_i
, sizeof(td
->td_ti
.ti_i
));
160 bzero((caddr_t
)td
->td_ip6buf
, sizeof(td
->td_ip6buf
));
163 switch (td
->td_family
) {
165 td
->td_ti
.ti_t
= *th
;
166 bzero((caddr_t
)&td
->td_ti6
.th
, sizeof(td
->td_ti6
.th
));
171 bzero((caddr_t
)&td
->td_ti
.ti_t
,
172 sizeof(td
->td_ti
.ti_t
));
176 bzero((caddr_t
)&td
->td_ti
.ti_t
,
177 sizeof(td
->td_ti
.ti_t
));
178 bzero((caddr_t
)&td
->td_ti6
.th
, sizeof(td
->td_ti6
.th
));
182 bzero((caddr_t
)&td
->td_ti
.ti_t
, sizeof(td
->td_ti
.ti_t
));
183 bzero((caddr_t
)&td
->td_ti6
.th
, sizeof(td
->td_ti6
.th
));
187 if (tcpconsdebug
== 0)
190 printf("%x %s:", tp
, tcpstates
[ostate
]);
193 printf("%s ", tanames
[act
]);
199 if (ipgen
== NULL
|| th
== NULL
)
205 isipv6
? ((struct ip6_hdr
*)ipgen
)->ip6_plen
:
207 ((struct ip
*)ipgen
)->ip_len
;
208 if (act
== TA_OUTPUT
) {
211 len
= ntohs((u_short
)len
);
213 if (act
== TA_OUTPUT
)
214 len
-= sizeof (struct tcphdr
);
216 printf("[%x..%x)", seq
, seq
+len
);
219 printf("@%x, urp=%x", ack
, th
->th_urp
);
220 flags
= th
->th_flags
;
224 if (th->th_flags & TH_##f) { \
225 printf("%s%s", cp, #f); \
229 pf(SYN
); pf(ACK
); pf(FIN
); pf(RST
); pf(PUSH
); pf(URG
);
235 printf("%s", prurequests
[req
&0xff]);
236 if ((req
& 0xff) == PRU_SLOWTIMO
)
237 printf("<%s>", tcptimers
[req
>>8]);
241 printf(" -> %s", tcpstates
[tp
->t_state
]);
242 /* print out internal state of tp !?! */
247 "\trcv_(nxt,wnd,up) (%lx,%lx,%lx) snd_(una,nxt,max) (%lx,%lx,%lx)\n",
248 (u_long
)tp
->rcv_nxt
, tp
->rcv_wnd
, (u_long
)tp
->rcv_up
,
249 (u_long
)tp
->snd_una
, (u_long
)tp
->snd_nxt
, (u_long
)tp
->snd_max
);
250 printf("\tsnd_(wl1,wl2,wnd) (%lx,%lx,%lx)\n",
251 (u_long
)tp
->snd_wl1
, (u_long
)tp
->snd_wl2
, tp
->snd_wnd
);
252 #endif /* TCPDEBUG */