fix bug that can cause recursive .forward files to fail
[unix-history] / usr / src / sys / netinet / tcp_debug.c
CommitLineData
8ae0e4b4 1/*
e7a3707f
KB
2 * Copyright (c) 1982, 1986, 1993
3 * The Regents of the University of California. All rights reserved.
8ae0e4b4 4 *
dbf0c423 5 * %sccs.include.redist.c%
2b6b6284 6 *
e7a3707f 7 * @(#)tcp_debug.c 8.1 (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
5548a02f
KB
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>
f4d55810 25
5548a02f
KB
26#include <net/route.h>
27#include <net/if.h>
f4d55810 28
5548a02f
KB
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>
24342857 41
5adb2ee7 42#ifdef TCPDEBUG
24342857 43int tcpconsdebug = 0;
5adb2ee7 44#endif
24342857
BJ
45/*
46 * Tcp debug routines
47 */
c46785cb 48void
24342857
BJ
49tcp_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;
24342857
BJ
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;
5adb2ee7 74#ifdef TCPDEBUG
24342857
BJ
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:
b78c1941
SL
86 case TA_DROP:
87 if (ti == 0)
88 break;
24342857
BJ
89 seq = ti->ti_seq;
90 ack = ti->ti_ack;
91 len = ti->ti_len;
24342857
BJ
92 if (act == TA_OUTPUT) {
93 seq = ntohl(seq);
94 ack = ntohl(ack);
668cc26d 95 len = ntohs((u_short)len);
24342857 96 }
24342857
BJ
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);
b78c1941 103 printf("@%x, urp=%x", ack, ti->ti_urp);
24342857
BJ
104 flags = ti->ti_flags;
105 if (flags) {
668cc26d 106#ifndef lint
24342857
BJ
107 char *cp = "<";
108#define pf(f) { if (ti->ti_flags&TH_/**/f) { printf("%s%s", cp, "f"); cp = ","; } }
b78c1941 109 pf(SYN); pf(ACK); pf(FIN); pf(RST); pf(PUSH); pf(URG);
668cc26d 110#endif
24342857
BJ
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;
b78c1941
SL
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);
24342857
BJ
130 printf("\tsnd_(wl1,wl2,wnd) (%x,%x,%x)\n",
131 tp->snd_wl1, tp->snd_wl2, tp->snd_wnd);
5adb2ee7 132#endif /* TCPDEBUG */
24342857 133}