1 /*
2 * Copyright (c) 1982, 1986, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * %sccs.include.redist.c%
6 *
7 * @(#)tcp_debug.c 8.1 (Berkeley) 06/10/93
8 */
9
10 #ifdef TCPDEBUG
11 /* load symbolic names */
12 #define PRUREQUESTS
13 #define TCPSTATES
14 #define TCPTIMERS
15 #define TANAMES
16 #endif
17
18 #include <sys/param.h>
19 #include <sys/systm.h>
20 #include <sys/mbuf.h>
21 #include <sys/socket.h>
22 #include <sys/socketvar.h>
23 #include <sys/protosw.h>
24 #include <sys/errno.h>
25
26 #include <net/route.h>
27 #include <net/if.h>
28
29 #include <netinet/in.h>
30 #include <netinet/in_systm.h>
31 #include <netinet/ip.h>
32 #include <netinet/in_pcb.h>
33 #include <netinet/ip_var.h>
34 #include <netinet/tcp.h>
35 #include <netinet/tcp_fsm.h>
36 #include <netinet/tcp_seq.h>
37 #include <netinet/tcp_timer.h>
38 #include <netinet/tcp_var.h>
39 #include <netinet/tcpip.h>
40 #include <netinet/tcp_debug.h>
41
42 #ifdef TCPDEBUG
43 int tcpconsdebug = 0;
44 #endif
45 /*
46 * Tcp debug routines
47 */
48 void
tcp_trace(act,ostate,tp,ti,req)49 tcp_trace(act, ostate, tp, ti, req)
50 short act, ostate;
51 struct tcpcb *tp;
52 struct tcpiphdr *ti;
53 int req;
54 {
55 tcp_seq seq, ack;
56 int len, flags;
57 struct tcp_debug *td = &tcp_debug[tcp_debx++];
58
59 if (tcp_debx == TCP_NDEBUG)
60 tcp_debx = 0;
61 td->td_time = iptime();
62 td->td_act = act;
63 td->td_ostate = ostate;
64 td->td_tcb = (caddr_t)tp;
65 if (tp)
66 td->td_cb = *tp;
67 else
68 bzero((caddr_t)&td->td_cb, sizeof (*tp));
69 if (ti)
70 td->td_ti = *ti;
71 else
72 bzero((caddr_t)&td->td_ti, sizeof (*ti));
73 td->td_req = req;
74 #ifdef TCPDEBUG
75 if (tcpconsdebug == 0)
76 return;
77 if (tp)
78 printf("%x %s:", tp, tcpstates[ostate]);
79 else
80 printf("???????? ");
81 printf("%s ", tanames[act]);
82 switch (act) {
83
84 case TA_INPUT:
85 case TA_OUTPUT:
86 case TA_DROP:
87 if (ti == 0)
88 break;
89 seq = ti->ti_seq;
90 ack = ti->ti_ack;
91 len = ti->ti_len;
92 if (act == TA_OUTPUT) {
93 seq = ntohl(seq);
94 ack = ntohl(ack);
95 len = ntohs((u_short)len);
96 }
97 if (act == TA_OUTPUT)
98 len -= sizeof (struct tcphdr);
99 if (len)
100 printf("[%x..%x)", seq, seq+len);
101 else
102 printf("%x", seq);
103 printf("@%x, urp=%x", ack, ti->ti_urp);
104 flags = ti->ti_flags;
105 if (flags) {
106 #ifndef lint
107 char *cp = "<";
108 #define pf(f) { if (ti->ti_flags&TH_/**/f) { printf("%s%s", cp, "f"); cp = ","; } }
109 pf(SYN); pf(ACK); pf(FIN); pf(RST); pf(PUSH); pf(URG);
110 #endif
111 printf(">");
112 }
113 break;
114
115 case TA_USER:
116 printf("%s", prurequests[req&0xff]);
117 if ((req & 0xff) == PRU_SLOWTIMO)
118 printf("<%s>", tcptimers[req>>8]);
119 break;
120 }
121 if (tp)
122 printf(" -> %s", tcpstates[tp->t_state]);
123 /* print out internal state of tp !?! */
124 printf("\n");
125 if (tp == 0)
126 return;
127 printf("\trcv_(nxt,wnd,up) (%x,%x,%x) snd_(una,nxt,max) (%x,%x,%x)\n",
128 tp->rcv_nxt, tp->rcv_wnd, tp->rcv_up, tp->snd_una, tp->snd_nxt,
129 tp->snd_max);
130 printf("\tsnd_(wl1,wl2,wnd) (%x,%x,%x)\n",
131 tp->snd_wl1, tp->snd_wl2, tp->snd_wnd);
132 #endif /* TCPDEBUG */
133 }
134