date and time created 83/01/21 11:13:43 by dlw
[unix-history] / usr / src / sys / netinet / tcp_debug.c
CommitLineData
2c48b3f8 1/* tcp_debug.c 4.8 82/10/30 */
24342857
BJ
2
3#include "../h/param.h"
4#include "../h/systm.h"
5#include "../h/mbuf.h"
6#include "../h/socket.h"
7#include "../h/socketvar.h"
8#define PRUREQUESTS
9#include "../h/protosw.h"
fcfe450e 10#include "../netinet/in.h"
c124e997 11#include "../net/route.h"
fcfe450e
BJ
12#include "../netinet/in_pcb.h"
13#include "../netinet/in_systm.h"
24342857 14#include "../net/if.h"
fcfe450e
BJ
15#include "../netinet/ip.h"
16#include "../netinet/ip_var.h"
17#include "../netinet/tcp.h"
24342857 18#define TCPSTATES
fcfe450e
BJ
19#include "../netinet/tcp_fsm.h"
20#include "../netinet/tcp_seq.h"
24342857 21#define TCPTIMERS
fcfe450e
BJ
22#include "../netinet/tcp_timer.h"
23#include "../netinet/tcp_var.h"
24#include "../netinet/tcpip.h"
24342857 25#define TANAMES
fcfe450e 26#include "../netinet/tcp_debug.h"
c47a5909 27#include <errno.h>
24342857
BJ
28
29int tcpconsdebug = 0;
30/*
31 * Tcp debug routines
32 */
33tcp_trace(act, ostate, tp, ti, req)
34 short act, ostate;
35 struct tcpcb *tp;
36 struct tcpiphdr *ti;
37 int req;
38{
39 tcp_seq seq, ack;
40 int len, flags;
24342857
BJ
41 struct tcp_debug *td = &tcp_debug[tcp_debx++];
42
43 if (tcp_debx == TCP_NDEBUG)
44 tcp_debx = 0;
45 td->td_time = iptime();
46 td->td_act = act;
47 td->td_ostate = ostate;
48 td->td_tcb = (caddr_t)tp;
49 if (tp)
50 td->td_cb = *tp;
51 else
52 bzero((caddr_t)&td->td_cb, sizeof (*tp));
53 if (ti)
54 td->td_ti = *ti;
55 else
56 bzero((caddr_t)&td->td_ti, sizeof (*ti));
57 td->td_req = req;
58 if (tcpconsdebug == 0)
59 return;
60 if (tp)
61 printf("%x %s:", tp, tcpstates[ostate]);
62 else
63 printf("???????? ");
64 printf("%s ", tanames[act]);
65 switch (act) {
66
67 case TA_INPUT:
68 case TA_OUTPUT:
69 seq = ti->ti_seq;
70 ack = ti->ti_ack;
71 len = ti->ti_len;
24342857
BJ
72 if (act == TA_OUTPUT) {
73 seq = ntohl(seq);
74 ack = ntohl(ack);
668cc26d 75 len = ntohs((u_short)len);
24342857 76 }
24342857
BJ
77 if (act == TA_OUTPUT)
78 len -= sizeof (struct tcphdr);
79 if (len)
80 printf("[%x..%x)", seq, seq+len);
81 else
82 printf("%x", seq);
83 printf("@%x", ack);
84 flags = ti->ti_flags;
85 if (flags) {
668cc26d 86#ifndef lint
24342857
BJ
87 char *cp = "<";
88#define pf(f) { if (ti->ti_flags&TH_/**/f) { printf("%s%s", cp, "f"); cp = ","; } }
89 pf(SYN); pf(ACK); pf(FIN); pf(RST);
668cc26d 90#endif
24342857
BJ
91 printf(">");
92 }
93 break;
94
95 case TA_USER:
96 printf("%s", prurequests[req&0xff]);
97 if ((req & 0xff) == PRU_SLOWTIMO)
98 printf("<%s>", tcptimers[req>>8]);
99 break;
100 }
101 if (tp)
102 printf(" -> %s", tcpstates[tp->t_state]);
103 /* print out internal state of tp !?! */
104 printf("\n");
105 if (tp == 0)
106 return;
107 printf("\trcv_(nxt,wnd) (%x,%x) snd_(una,nxt,max) (%x,%x,%x)\n",
108 tp->rcv_nxt, tp->rcv_wnd, tp->snd_una, tp->snd_nxt, tp->snd_max);
109 printf("\tsnd_(wl1,wl2,wnd) (%x,%x,%x)\n",
110 tp->snd_wl1, tp->snd_wl2, tp->snd_wnd);
111}