|
|
1.1 root 1: /*
2: * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
6: * The contents of this file constitute Original Code as defined in and
7: * are subject to the Apple Public Source License Version 1.1 (the
8: * "License"). You may not use this file except in compliance with the
9: * License. Please obtain a copy of the License at
10: * http://www.apple.com/publicsource and read it before using this file.
11: *
12: * This Original Code and all software distributed under the License are
13: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17: * License for the specific language governing rights and limitations
18: * under the License.
19: *
20: * @APPLE_LICENSE_HEADER_END@
21: */
22: /*
23: * Copyright (c) 1982, 1986, 1993
24: * The Regents of the University of California. All rights reserved.
25: *
26: * Redistribution and use in source and binary forms, with or without
27: * modification, are permitted provided that the following conditions
28: * are met:
29: * 1. Redistributions of source code must retain the above copyright
30: * notice, this list of conditions and the following disclaimer.
31: * 2. Redistributions in binary form must reproduce the above copyright
32: * notice, this list of conditions and the following disclaimer in the
33: * documentation and/or other materials provided with the distribution.
34: * 3. All advertising materials mentioning features or use of this software
35: * must display the following acknowledgement:
36: * This product includes software developed by the University of
37: * California, Berkeley and its contributors.
38: * 4. Neither the name of the University nor the names of its contributors
39: * may be used to endorse or promote products derived from this software
40: * without specific prior written permission.
41: *
42: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
43: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
46: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
47: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
48: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
50: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
51: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
52: * SUCH DAMAGE.
53: *
54: * @(#)tcp_debug.c 8.1 (Berkeley) 6/10/93
55: */
56:
57: #if ISFB31
58: #include "opt_inet.h"
59: #include "opt_tcpdebug.h"
60: #endif
61:
62: #ifndef INET
63: #error The option TCPDEBUG requires option INET.
64: #endif
65:
66: #if TCPDEBUG
67: /* load symbolic names */
68: #define PRUREQUESTS
69: #define TCPSTATES
70: #define TCPTIMERS
71: #define TANAMES
72: #endif
73:
74: #include <sys/param.h>
75: #include <sys/systm.h>
76: #include <sys/protosw.h>
77:
78: #include <netinet/in.h>
79: #include <netinet/in_systm.h>
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: #if TCPDEBUG
89: static int tcpconsdebug = 0;
90: #endif
91:
92: static struct tcp_debug tcp_debug[TCP_NDEBUG];
93: static int tcp_debx;
94:
95: /*
96: * Tcp debug routines
97: */
98: void
99: tcp_trace(act, ostate, tp, ti, req)
100: short act, ostate;
101: struct tcpcb *tp;
102: struct tcpiphdr *ti;
103: int req;
104: {
105: tcp_seq seq, ack;
106: int len, flags;
107: struct tcp_debug *td = &tcp_debug[tcp_debx++];
108:
109: if (tcp_debx == TCP_NDEBUG)
110: tcp_debx = 0;
111: td->td_time = iptime();
112: td->td_act = act;
113: td->td_ostate = ostate;
114: td->td_tcb = (caddr_t)tp;
115: if (tp)
116: td->td_cb = *tp;
117: else
118: bzero((caddr_t)&td->td_cb, sizeof (*tp));
119: if (ti)
120: td->td_ti = *ti;
121: else
122: bzero((caddr_t)&td->td_ti, sizeof (*ti));
123: td->td_req = req;
124: #if TCPDEBUG
125: if (tcpconsdebug == 0)
126: return;
127: if (tp)
128: printf("%p %s:", tp, tcpstates[ostate]);
129: else
130: printf("???????? ");
131: printf("%s ", tanames[act]);
132: switch (act) {
133:
134: case TA_INPUT:
135: case TA_OUTPUT:
136: case TA_DROP:
137: if (ti == 0)
138: break;
139: seq = ti->ti_seq;
140: ack = ti->ti_ack;
141: len = ti->ti_len;
142: if (act == TA_OUTPUT) {
143: seq = ntohl(seq);
144: ack = ntohl(ack);
145: len = ntohs((u_short)len);
146: }
147: if (act == TA_OUTPUT)
148: len -= sizeof (struct tcphdr);
149: if (len)
150: printf("[%x..%x)", seq, seq+len);
151: else
152: printf("%x", seq);
153: printf("@%x, urp=%x", ack, ti->ti_urp);
154: flags = ti->ti_flags;
155: if (flags) {
156: char *cp = "<";
157: #define pf(f) { \
158: if (ti->ti_flags & TH_##f) { \
159: printf("%s%s", cp, #f); \
160: cp = ","; \
161: } \
162: }
163: pf(SYN); pf(ACK); pf(FIN); pf(RST); pf(PUSH); pf(URG);
164: printf(">");
165: }
166: break;
167:
168: case TA_USER:
169: printf("%s", prurequests[req&0xff]);
170: if ((req & 0xff) == PRU_SLOWTIMO)
171: printf("<%s>", tcptimers[req>>8]);
172: break;
173: }
174: if (tp)
175: printf(" -> %s", tcpstates[tp->t_state]);
176: /* print out internal state of tp !?! */
177: printf("\n");
178: if (tp == 0)
179: return;
180: printf(
181: "\trcv_(nxt,wnd,up) (%lx,%lx,%lx) snd_(una,nxt,max) (%lx,%lx,%lx)\n",
182: (u_long)tp->rcv_nxt, tp->rcv_wnd, (u_long)tp->rcv_up,
183: (u_long)tp->snd_una, (u_long)tp->snd_nxt, (u_long)tp->snd_max);
184: printf("\tsnd_(wl1,wl2,wnd) (%lx,%lx,%lx)\n",
185: (u_long)tp->snd_wl1, (u_long)tp->snd_wl2, tp->snd_wnd);
186: #endif /* TCPDEBUG */
187: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.