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