xref: /original-bsd/sys/netinet/tcp_debug.c (revision 9c59a687)
1 /*	tcp_debug.c	4.3	82/03/29	*/
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"
10 #include "../net/in.h"
11 #include "../net/route.h"
12 #include "../net/in_pcb.h"
13 #include "../net/in_systm.h"
14 #include "../net/if.h"
15 #include "../net/ip.h"
16 #include "../net/ip_var.h"
17 #include "../net/tcp.h"
18 #define TCPSTATES
19 #include "../net/tcp_fsm.h"
20 #include "../net/tcp_seq.h"
21 #define	TCPTIMERS
22 #include "../net/tcp_timer.h"
23 #include "../net/tcp_var.h"
24 #include "../net/tcpip.h"
25 #define	TANAMES
26 #include "../net/tcp_debug.h"
27 #include "../errno.h"
28 
29 int	tcpconsdebug = 0;
30 /*
31  * Tcp debug routines
32  */
33 tcp_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;
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;
72 #if vax
73 		if (act == TA_OUTPUT) {
74 			seq = ntohl(seq);
75 			ack = ntohl(ack);
76 			len = ntohs((u_short)len);
77 		}
78 #endif
79 		if (act == TA_OUTPUT)
80 			len -= sizeof (struct tcphdr);
81 		if (len)
82 			printf("[%x..%x)", seq, seq+len);
83 		else
84 			printf("%x", seq);
85 		printf("@%x", ack);
86 		flags = ti->ti_flags;
87 		if (flags) {
88 #ifndef lint
89 			char *cp = "<";
90 #define pf(f) { if (ti->ti_flags&TH_/**/f) { printf("%s%s", cp, "f"); cp = ","; } }
91 			pf(SYN); pf(ACK); pf(FIN); pf(RST);
92 #endif
93 			printf(">");
94 		}
95 		break;
96 
97 	case TA_USER:
98 		printf("%s", prurequests[req&0xff]);
99 		if ((req & 0xff) == PRU_SLOWTIMO)
100 			printf("<%s>", tcptimers[req>>8]);
101 		break;
102 	}
103 	if (tp)
104 		printf(" -> %s", tcpstates[tp->t_state]);
105 	/* print out internal state of tp !?! */
106 	printf("\n");
107 	if (tp == 0)
108 		return;
109 	printf("\trcv_(nxt,wnd) (%x,%x) snd_(una,nxt,max) (%x,%x,%x)\n",
110 	    tp->rcv_nxt, tp->rcv_wnd, tp->snd_una, tp->snd_nxt, tp->snd_max);
111 	printf("\tsnd_(wl1,wl2,wnd) (%x,%x,%x)\n",
112 	    tp->snd_wl1, tp->snd_wl2, tp->snd_wnd);
113 }
114