xref: /original-bsd/sys/netinet/tcp_debug.c (revision abd50c55)
1 /*
2  * Copyright (c) 1982, 1986 Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that the above copyright notice and this paragraph are
7  * duplicated in all such forms and that any documentation,
8  * advertising materials, and other materials related to such
9  * distribution and use acknowledge that the software was developed
10  * by the University of California, Berkeley.  The name of the
11  * University may not be used to endorse or promote products derived
12  * from this software without specific prior written permission.
13  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16  *
17  *	@(#)tcp_debug.c	7.4 (Berkeley) 04/03/90
18  */
19 
20 #include "param.h"
21 #include "systm.h"
22 #include "mbuf.h"
23 #include "socket.h"
24 #include "socketvar.h"
25 #define PRUREQUESTS
26 #include "protosw.h"
27 #include "errno.h"
28 
29 #include "../net/route.h"
30 #include "../net/if.h"
31 
32 #include "in.h"
33 #include "in_systm.h"
34 #include "ip.h"
35 #include "in_pcb.h"
36 #include "ip_var.h"
37 #include "tcp.h"
38 #define TCPSTATES
39 #include "tcp_fsm.h"
40 #include "tcp_seq.h"
41 #define	TCPTIMERS
42 #include "tcp_timer.h"
43 #include "tcp_var.h"
44 #include "tcpip.h"
45 #define	TANAMES
46 #include "tcp_debug.h"
47 
48 int	tcpconsdebug = 0;
49 /*
50  * Tcp debug routines
51  */
52 tcp_trace(act, ostate, tp, ti, req)
53 	short act, ostate;
54 	struct tcpcb *tp;
55 	struct tcpiphdr *ti;
56 	int req;
57 {
58 	tcp_seq seq, ack;
59 	int len, flags;
60 	struct tcp_debug *td = &tcp_debug[tcp_debx++];
61 
62 	if (tcp_debx == TCP_NDEBUG)
63 		tcp_debx = 0;
64 	td->td_time = iptime();
65 	td->td_act = act;
66 	td->td_ostate = ostate;
67 	td->td_tcb = (caddr_t)tp;
68 	if (tp)
69 		td->td_cb = *tp;
70 	else
71 		bzero((caddr_t)&td->td_cb, sizeof (*tp));
72 	if (ti)
73 		td->td_ti = *ti;
74 	else
75 		bzero((caddr_t)&td->td_ti, sizeof (*ti));
76 	td->td_req = req;
77 	if (tcpconsdebug == 0)
78 		return;
79 	if (tp)
80 		printf("%x %s:", tp, tcpstates[ostate]);
81 	else
82 		printf("???????? ");
83 	printf("%s ", tanames[act]);
84 	switch (act) {
85 
86 	case TA_INPUT:
87 	case TA_OUTPUT:
88 	case TA_DROP:
89 		if (ti == 0)
90 			break;
91 		seq = ti->ti_seq;
92 		ack = ti->ti_ack;
93 		len = ti->ti_len;
94 		if (act == TA_OUTPUT) {
95 			seq = ntohl(seq);
96 			ack = ntohl(ack);
97 			len = ntohs((u_short)len);
98 		}
99 		if (act == TA_OUTPUT)
100 			len -= sizeof (struct tcphdr);
101 		if (len)
102 			printf("[%x..%x)", seq, seq+len);
103 		else
104 			printf("%x", seq);
105 		printf("@%x, urp=%x", ack, ti->ti_urp);
106 		flags = ti->ti_flags;
107 		if (flags) {
108 #ifndef lint
109 			char *cp = "<";
110 #define pf(f) { if (ti->ti_flags&TH_/**/f) { printf("%s%s", cp, "f"); cp = ","; } }
111 			pf(SYN); pf(ACK); pf(FIN); pf(RST); pf(PUSH); pf(URG);
112 #endif
113 			printf(">");
114 		}
115 		break;
116 
117 	case TA_USER:
118 		printf("%s", prurequests[req&0xff]);
119 		if ((req & 0xff) == PRU_SLOWTIMO)
120 			printf("<%s>", tcptimers[req>>8]);
121 		break;
122 	}
123 	if (tp)
124 		printf(" -> %s", tcpstates[tp->t_state]);
125 	/* print out internal state of tp !?! */
126 	printf("\n");
127 	if (tp == 0)
128 		return;
129 	printf("\trcv_(nxt,wnd,up) (%x,%x,%x) snd_(una,nxt,max) (%x,%x,%x)\n",
130 	    tp->rcv_nxt, tp->rcv_wnd, tp->rcv_up, tp->snd_una, tp->snd_nxt,
131 	    tp->snd_max);
132 	printf("\tsnd_(wl1,wl2,wnd) (%x,%x,%x)\n",
133 	    tp->snd_wl1, tp->snd_wl2, tp->snd_wnd);
134 }
135