tcp_debug.c revision 1.4 1 1.1 cgd /*
2 1.1 cgd * Copyright (c) 1982, 1986 Regents of the University of California.
3 1.1 cgd * All rights reserved.
4 1.1 cgd *
5 1.1 cgd * Redistribution and use in source and binary forms, with or without
6 1.1 cgd * modification, are permitted provided that the following conditions
7 1.1 cgd * are met:
8 1.1 cgd * 1. Redistributions of source code must retain the above copyright
9 1.1 cgd * notice, this list of conditions and the following disclaimer.
10 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
11 1.1 cgd * notice, this list of conditions and the following disclaimer in the
12 1.1 cgd * documentation and/or other materials provided with the distribution.
13 1.1 cgd * 3. All advertising materials mentioning features or use of this software
14 1.1 cgd * must display the following acknowledgement:
15 1.1 cgd * This product includes software developed by the University of
16 1.1 cgd * California, Berkeley and its contributors.
17 1.1 cgd * 4. Neither the name of the University nor the names of its contributors
18 1.1 cgd * may be used to endorse or promote products derived from this software
19 1.1 cgd * without specific prior written permission.
20 1.1 cgd *
21 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 1.1 cgd * SUCH DAMAGE.
32 1.1 cgd *
33 1.2 cgd * from: @(#)tcp_debug.c 7.6 (Berkeley) 6/28/90
34 1.4 mycroft * $Id: tcp_debug.c,v 1.4 1993/12/18 00:42:01 mycroft Exp $
35 1.1 cgd */
36 1.1 cgd
37 1.1 cgd #ifdef TCPDEBUG
38 1.1 cgd /* load symbolic names */
39 1.1 cgd #define PRUREQUESTS
40 1.1 cgd #define TCPSTATES
41 1.1 cgd #define TCPTIMERS
42 1.1 cgd #define TANAMES
43 1.1 cgd #endif
44 1.1 cgd
45 1.4 mycroft #include <sys/param.h>
46 1.4 mycroft #include <sys/systm.h>
47 1.4 mycroft #include <sys/mbuf.h>
48 1.4 mycroft #include <sys/socket.h>
49 1.4 mycroft #include <sys/socketvar.h>
50 1.4 mycroft #include <sys/protosw.h>
51 1.4 mycroft #include <sys/errno.h>
52 1.1 cgd
53 1.4 mycroft #include <net/route.h>
54 1.4 mycroft #include <net/if.h>
55 1.1 cgd
56 1.4 mycroft #include <netinet/in.h>
57 1.4 mycroft #include <netinet/in_systm.h>
58 1.4 mycroft #include <netinet/ip.h>
59 1.4 mycroft #include <netinet/in_pcb.h>
60 1.4 mycroft #include <netinet/ip_var.h>
61 1.4 mycroft #include <netinet/tcp.h>
62 1.4 mycroft #include <netinet/tcp_fsm.h>
63 1.4 mycroft #include <netinet/tcp_seq.h>
64 1.4 mycroft #include <netinet/tcp_timer.h>
65 1.4 mycroft #include <netinet/tcp_var.h>
66 1.4 mycroft #include <netinet/tcpip.h>
67 1.4 mycroft #include <netinet/tcp_debug.h>
68 1.1 cgd
69 1.1 cgd #ifdef TCPDEBUG
70 1.1 cgd int tcpconsdebug = 0;
71 1.1 cgd #endif
72 1.1 cgd /*
73 1.1 cgd * Tcp debug routines
74 1.1 cgd */
75 1.1 cgd tcp_trace(act, ostate, tp, ti, req)
76 1.1 cgd short act, ostate;
77 1.1 cgd struct tcpcb *tp;
78 1.1 cgd struct tcpiphdr *ti;
79 1.1 cgd int req;
80 1.1 cgd {
81 1.1 cgd tcp_seq seq, ack;
82 1.1 cgd int len, flags;
83 1.1 cgd struct tcp_debug *td = &tcp_debug[tcp_debx++];
84 1.1 cgd
85 1.1 cgd if (tcp_debx == TCP_NDEBUG)
86 1.1 cgd tcp_debx = 0;
87 1.1 cgd td->td_time = iptime();
88 1.1 cgd td->td_act = act;
89 1.1 cgd td->td_ostate = ostate;
90 1.1 cgd td->td_tcb = (caddr_t)tp;
91 1.1 cgd if (tp)
92 1.1 cgd td->td_cb = *tp;
93 1.1 cgd else
94 1.1 cgd bzero((caddr_t)&td->td_cb, sizeof (*tp));
95 1.1 cgd if (ti)
96 1.1 cgd td->td_ti = *ti;
97 1.1 cgd else
98 1.1 cgd bzero((caddr_t)&td->td_ti, sizeof (*ti));
99 1.1 cgd td->td_req = req;
100 1.1 cgd #ifdef TCPDEBUG
101 1.1 cgd if (tcpconsdebug == 0)
102 1.1 cgd return;
103 1.1 cgd if (tp)
104 1.1 cgd printf("%x %s:", tp, tcpstates[ostate]);
105 1.1 cgd else
106 1.1 cgd printf("???????? ");
107 1.1 cgd printf("%s ", tanames[act]);
108 1.1 cgd switch (act) {
109 1.1 cgd
110 1.1 cgd case TA_INPUT:
111 1.1 cgd case TA_OUTPUT:
112 1.1 cgd case TA_DROP:
113 1.1 cgd if (ti == 0)
114 1.1 cgd break;
115 1.1 cgd seq = ti->ti_seq;
116 1.1 cgd ack = ti->ti_ack;
117 1.1 cgd len = ti->ti_len;
118 1.1 cgd if (act == TA_OUTPUT) {
119 1.1 cgd seq = ntohl(seq);
120 1.1 cgd ack = ntohl(ack);
121 1.1 cgd len = ntohs((u_short)len);
122 1.1 cgd }
123 1.1 cgd if (act == TA_OUTPUT)
124 1.1 cgd len -= sizeof (struct tcphdr);
125 1.1 cgd if (len)
126 1.1 cgd printf("[%x..%x)", seq, seq+len);
127 1.1 cgd else
128 1.1 cgd printf("%x", seq);
129 1.1 cgd printf("@%x, urp=%x", ack, ti->ti_urp);
130 1.1 cgd flags = ti->ti_flags;
131 1.1 cgd if (flags) {
132 1.1 cgd #ifndef lint
133 1.1 cgd char *cp = "<";
134 1.1 cgd #define pf(f) { if (ti->ti_flags&TH_/**/f) { printf("%s%s", cp, "f"); cp = ","; } }
135 1.1 cgd pf(SYN); pf(ACK); pf(FIN); pf(RST); pf(PUSH); pf(URG);
136 1.1 cgd #endif
137 1.1 cgd printf(">");
138 1.1 cgd }
139 1.1 cgd break;
140 1.1 cgd
141 1.1 cgd case TA_USER:
142 1.1 cgd printf("%s", prurequests[req&0xff]);
143 1.1 cgd if ((req & 0xff) == PRU_SLOWTIMO)
144 1.1 cgd printf("<%s>", tcptimers[req>>8]);
145 1.1 cgd break;
146 1.1 cgd }
147 1.1 cgd if (tp)
148 1.1 cgd printf(" -> %s", tcpstates[tp->t_state]);
149 1.1 cgd /* print out internal state of tp !?! */
150 1.1 cgd printf("\n");
151 1.1 cgd if (tp == 0)
152 1.1 cgd return;
153 1.1 cgd printf("\trcv_(nxt,wnd,up) (%x,%x,%x) snd_(una,nxt,max) (%x,%x,%x)\n",
154 1.1 cgd tp->rcv_nxt, tp->rcv_wnd, tp->rcv_up, tp->snd_una, tp->snd_nxt,
155 1.1 cgd tp->snd_max);
156 1.1 cgd printf("\tsnd_(wl1,wl2,wnd) (%x,%x,%x)\n",
157 1.1 cgd tp->snd_wl1, tp->snd_wl2, tp->snd_wnd);
158 1.1 cgd #endif /* TCPDEBUG */
159 1.1 cgd }
160