xref: /original-bsd/sys/netinet/tcp_debug.c (revision 05cf3734)
1 /*
2  * Copyright (c) 1982, 1986 Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)tcp_debug.c	7.6 (Berkeley) 06/28/90
8  */
9 
10 #ifdef TCPDEBUG
11 /* load symbolic names */
12 #define PRUREQUESTS
13 #define TCPSTATES
14 #define	TCPTIMERS
15 #define	TANAMES
16 #endif
17 
18 #include "param.h"
19 #include "systm.h"
20 #include "mbuf.h"
21 #include "socket.h"
22 #include "socketvar.h"
23 #include "protosw.h"
24 #include "errno.h"
25 
26 #include "../net/route.h"
27 #include "../net/if.h"
28 
29 #include "in.h"
30 #include "in_systm.h"
31 #include "ip.h"
32 #include "in_pcb.h"
33 #include "ip_var.h"
34 #include "tcp.h"
35 #include "tcp_fsm.h"
36 #include "tcp_seq.h"
37 #include "tcp_timer.h"
38 #include "tcp_var.h"
39 #include "tcpip.h"
40 #include "tcp_debug.h"
41 
42 #ifdef TCPDEBUG
43 int	tcpconsdebug = 0;
44 #endif
45 /*
46  * Tcp debug routines
47  */
48 tcp_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;
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;
73 #ifdef TCPDEBUG
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:
85 	case TA_DROP:
86 		if (ti == 0)
87 			break;
88 		seq = ti->ti_seq;
89 		ack = ti->ti_ack;
90 		len = ti->ti_len;
91 		if (act == TA_OUTPUT) {
92 			seq = ntohl(seq);
93 			ack = ntohl(ack);
94 			len = ntohs((u_short)len);
95 		}
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);
102 		printf("@%x, urp=%x", ack, ti->ti_urp);
103 		flags = ti->ti_flags;
104 		if (flags) {
105 #ifndef lint
106 			char *cp = "<";
107 #define pf(f) { if (ti->ti_flags&TH_/**/f) { printf("%s%s", cp, "f"); cp = ","; } }
108 			pf(SYN); pf(ACK); pf(FIN); pf(RST); pf(PUSH); pf(URG);
109 #endif
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;
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);
129 	printf("\tsnd_(wl1,wl2,wnd) (%x,%x,%x)\n",
130 	    tp->snd_wl1, tp->snd_wl2, tp->snd_wnd);
131 #endif /* TCPDEBUG */
132 }
133