xref: /csrg-svn/sys/netinet/tcp_debug.c (revision 17062)
1*17062Sbloom /*	tcp_debug.c	6.2	84/08/29	*/
25302Sroot 
3*17062Sbloom #include "param.h"
4*17062Sbloom #include "systm.h"
5*17062Sbloom #include "mbuf.h"
6*17062Sbloom #include "socket.h"
7*17062Sbloom #include "socketvar.h"
85302Sroot #define PRUREQUESTS
9*17062Sbloom #include "protosw.h"
10*17062Sbloom #include "errno.h"
1110894Ssam 
1210894Ssam #include "../net/route.h"
1310894Ssam #include "../net/if.h"
1410894Ssam 
15*17062Sbloom #include "in.h"
16*17062Sbloom #include "in_pcb.h"
17*17062Sbloom #include "in_systm.h"
18*17062Sbloom #include "ip.h"
19*17062Sbloom #include "ip_var.h"
20*17062Sbloom #include "tcp.h"
215302Sroot #define TCPSTATES
22*17062Sbloom #include "tcp_fsm.h"
23*17062Sbloom #include "tcp_seq.h"
245302Sroot #define	TCPTIMERS
25*17062Sbloom #include "tcp_timer.h"
26*17062Sbloom #include "tcp_var.h"
27*17062Sbloom #include "tcpip.h"
285302Sroot #define	TANAMES
29*17062Sbloom #include "tcp_debug.h"
305302Sroot 
315302Sroot int	tcpconsdebug = 0;
325302Sroot /*
335302Sroot  * Tcp debug routines
345302Sroot  */
355302Sroot tcp_trace(act, ostate, tp, ti, req)
365302Sroot 	short act, ostate;
375302Sroot 	struct tcpcb *tp;
385302Sroot 	struct tcpiphdr *ti;
395302Sroot 	int req;
405302Sroot {
415302Sroot 	tcp_seq seq, ack;
425302Sroot 	int len, flags;
435302Sroot 	struct tcp_debug *td = &tcp_debug[tcp_debx++];
445302Sroot 
455302Sroot 	if (tcp_debx == TCP_NDEBUG)
465302Sroot 		tcp_debx = 0;
475302Sroot 	td->td_time = iptime();
485302Sroot 	td->td_act = act;
495302Sroot 	td->td_ostate = ostate;
505302Sroot 	td->td_tcb = (caddr_t)tp;
515302Sroot 	if (tp)
525302Sroot 		td->td_cb = *tp;
535302Sroot 	else
545302Sroot 		bzero((caddr_t)&td->td_cb, sizeof (*tp));
555302Sroot 	if (ti)
565302Sroot 		td->td_ti = *ti;
575302Sroot 	else
585302Sroot 		bzero((caddr_t)&td->td_ti, sizeof (*ti));
595302Sroot 	td->td_req = req;
605302Sroot 	if (tcpconsdebug == 0)
615302Sroot 		return;
625302Sroot 	if (tp)
635302Sroot 		printf("%x %s:", tp, tcpstates[ostate]);
645302Sroot 	else
655302Sroot 		printf("???????? ");
665302Sroot 	printf("%s ", tanames[act]);
675302Sroot 	switch (act) {
685302Sroot 
695302Sroot 	case TA_INPUT:
705302Sroot 	case TA_OUTPUT:
7112440Ssam 	case TA_DROP:
7212440Ssam 		if (ti == 0)
7312440Ssam 			break;
745302Sroot 		seq = ti->ti_seq;
755302Sroot 		ack = ti->ti_ack;
765302Sroot 		len = ti->ti_len;
775302Sroot 		if (act == TA_OUTPUT) {
785302Sroot 			seq = ntohl(seq);
795302Sroot 			ack = ntohl(ack);
806161Ssam 			len = ntohs((u_short)len);
815302Sroot 		}
825302Sroot 		if (act == TA_OUTPUT)
835302Sroot 			len -= sizeof (struct tcphdr);
845302Sroot 		if (len)
855302Sroot 			printf("[%x..%x)", seq, seq+len);
865302Sroot 		else
875302Sroot 			printf("%x", seq);
8812440Ssam 		printf("@%x, urp=%x", ack, ti->ti_urp);
895302Sroot 		flags = ti->ti_flags;
905302Sroot 		if (flags) {
916161Ssam #ifndef lint
925302Sroot 			char *cp = "<";
935302Sroot #define pf(f) { if (ti->ti_flags&TH_/**/f) { printf("%s%s", cp, "f"); cp = ","; } }
9412440Ssam 			pf(SYN); pf(ACK); pf(FIN); pf(RST); pf(PUSH); pf(URG);
956161Ssam #endif
965302Sroot 			printf(">");
975302Sroot 		}
985302Sroot 		break;
995302Sroot 
1005302Sroot 	case TA_USER:
1015302Sroot 		printf("%s", prurequests[req&0xff]);
1025302Sroot 		if ((req & 0xff) == PRU_SLOWTIMO)
1035302Sroot 			printf("<%s>", tcptimers[req>>8]);
1045302Sroot 		break;
1055302Sroot 	}
1065302Sroot 	if (tp)
1075302Sroot 		printf(" -> %s", tcpstates[tp->t_state]);
1085302Sroot 	/* print out internal state of tp !?! */
1095302Sroot 	printf("\n");
1105302Sroot 	if (tp == 0)
1115302Sroot 		return;
11212440Ssam 	printf("\trcv_(nxt,wnd,up) (%x,%x,%x) snd_(una,nxt,max) (%x,%x,%x)\n",
11312440Ssam 	    tp->rcv_nxt, tp->rcv_wnd, tp->rcv_up, tp->snd_una, tp->snd_nxt,
11412440Ssam 	    tp->snd_max);
1155302Sroot 	printf("\tsnd_(wl1,wl2,wnd) (%x,%x,%x)\n",
1165302Sroot 	    tp->snd_wl1, tp->snd_wl2, tp->snd_wnd);
1175302Sroot }
118