xref: /original-bsd/sys/netinet/tcp_debug.c (revision 57124d5e)
1 /*
2  * Copyright (c) 1982, 1986 Regents of the University of California.
3  * All rights reserved.  The Berkeley software License Agreement
4  * specifies the terms and conditions for redistribution.
5  *
6  *	@(#)tcp_debug.c	7.1 (Berkeley) 06/05/86
7  */
8 
9 #include "param.h"
10 #include "systm.h"
11 #include "mbuf.h"
12 #include "socket.h"
13 #include "socketvar.h"
14 #define PRUREQUESTS
15 #include "protosw.h"
16 #include "errno.h"
17 
18 #include "../net/route.h"
19 #include "../net/if.h"
20 
21 #include "in.h"
22 #include "in_pcb.h"
23 #include "in_systm.h"
24 #include "ip.h"
25 #include "ip_var.h"
26 #include "tcp.h"
27 #define TCPSTATES
28 #include "tcp_fsm.h"
29 #include "tcp_seq.h"
30 #define	TCPTIMERS
31 #include "tcp_timer.h"
32 #include "tcp_var.h"
33 #include "tcpip.h"
34 #define	TANAMES
35 #include "tcp_debug.h"
36 
37 int	tcpconsdebug = 0;
38 /*
39  * Tcp debug routines
40  */
41 tcp_trace(act, ostate, tp, ti, req)
42 	short act, ostate;
43 	struct tcpcb *tp;
44 	struct tcpiphdr *ti;
45 	int req;
46 {
47 	tcp_seq seq, ack;
48 	int len, flags;
49 	struct tcp_debug *td = &tcp_debug[tcp_debx++];
50 
51 	if (tcp_debx == TCP_NDEBUG)
52 		tcp_debx = 0;
53 	td->td_time = iptime();
54 	td->td_act = act;
55 	td->td_ostate = ostate;
56 	td->td_tcb = (caddr_t)tp;
57 	if (tp)
58 		td->td_cb = *tp;
59 	else
60 		bzero((caddr_t)&td->td_cb, sizeof (*tp));
61 	if (ti)
62 		td->td_ti = *ti;
63 	else
64 		bzero((caddr_t)&td->td_ti, sizeof (*ti));
65 	td->td_req = req;
66 	if (tcpconsdebug == 0)
67 		return;
68 	if (tp)
69 		printf("%x %s:", tp, tcpstates[ostate]);
70 	else
71 		printf("???????? ");
72 	printf("%s ", tanames[act]);
73 	switch (act) {
74 
75 	case TA_INPUT:
76 	case TA_OUTPUT:
77 	case TA_DROP:
78 		if (ti == 0)
79 			break;
80 		seq = ti->ti_seq;
81 		ack = ti->ti_ack;
82 		len = ti->ti_len;
83 		if (act == TA_OUTPUT) {
84 			seq = ntohl(seq);
85 			ack = ntohl(ack);
86 			len = ntohs((u_short)len);
87 		}
88 		if (act == TA_OUTPUT)
89 			len -= sizeof (struct tcphdr);
90 		if (len)
91 			printf("[%x..%x)", seq, seq+len);
92 		else
93 			printf("%x", seq);
94 		printf("@%x, urp=%x", ack, ti->ti_urp);
95 		flags = ti->ti_flags;
96 		if (flags) {
97 #ifndef lint
98 			char *cp = "<";
99 #define pf(f) { if (ti->ti_flags&TH_/**/f) { printf("%s%s", cp, "f"); cp = ","; } }
100 			pf(SYN); pf(ACK); pf(FIN); pf(RST); pf(PUSH); pf(URG);
101 #endif
102 			printf(">");
103 		}
104 		break;
105 
106 	case TA_USER:
107 		printf("%s", prurequests[req&0xff]);
108 		if ((req & 0xff) == PRU_SLOWTIMO)
109 			printf("<%s>", tcptimers[req>>8]);
110 		break;
111 	}
112 	if (tp)
113 		printf(" -> %s", tcpstates[tp->t_state]);
114 	/* print out internal state of tp !?! */
115 	printf("\n");
116 	if (tp == 0)
117 		return;
118 	printf("\trcv_(nxt,wnd,up) (%x,%x,%x) snd_(una,nxt,max) (%x,%x,%x)\n",
119 	    tp->rcv_nxt, tp->rcv_wnd, tp->rcv_up, tp->snd_una, tp->snd_nxt,
120 	    tp->snd_max);
121 	printf("\tsnd_(wl1,wl2,wnd) (%x,%x,%x)\n",
122 	    tp->snd_wl1, tp->snd_wl2, tp->snd_wnd);
123 }
124