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