xref: /csrg-svn/sys/netinet/tcp_debug.c (revision 56531)
123188Smckusick /*
229148Smckusick  * Copyright (c) 1982, 1986 Regents of the University of California.
332787Sbostic  * All rights reserved.
423188Smckusick  *
544484Sbostic  * %sccs.include.redist.c%
632787Sbostic  *
7*56531Sbostic  *	@(#)tcp_debug.c	7.7 (Berkeley) 10/11/92
823188Smckusick  */
95302Sroot 
1044374Skarels #ifdef TCPDEBUG
1144374Skarels /* load symbolic names */
1244374Skarels #define PRUREQUESTS
1344374Skarels #define TCPSTATES
1444374Skarels #define	TCPTIMERS
1544374Skarels #define	TANAMES
1644374Skarels #endif
1744374Skarels 
18*56531Sbostic #include <sys/param.h>
19*56531Sbostic #include <sys/systm.h>
20*56531Sbostic #include <sys/mbuf.h>
21*56531Sbostic #include <sys/socket.h>
22*56531Sbostic #include <sys/socketvar.h>
23*56531Sbostic #include <sys/protosw.h>
24*56531Sbostic #include <sys/errno.h>
2510894Ssam 
26*56531Sbostic #include <net/route.h>
27*56531Sbostic #include <net/if.h>
2810894Ssam 
29*56531Sbostic #include <netinet/in.h>
30*56531Sbostic #include <netinet/in_systm.h>
31*56531Sbostic #include <netinet/ip.h>
32*56531Sbostic #include <netinet/in_pcb.h>
33*56531Sbostic #include <netinet/ip_var.h>
34*56531Sbostic #include <netinet/tcp.h>
35*56531Sbostic #include <netinet/tcp_fsm.h>
36*56531Sbostic #include <netinet/tcp_seq.h>
37*56531Sbostic #include <netinet/tcp_timer.h>
38*56531Sbostic #include <netinet/tcp_var.h>
39*56531Sbostic #include <netinet/tcpip.h>
40*56531Sbostic #include <netinet/tcp_debug.h>
415302Sroot 
4244374Skarels #ifdef TCPDEBUG
435302Sroot int	tcpconsdebug = 0;
4444374Skarels #endif
455302Sroot /*
465302Sroot  * Tcp debug routines
475302Sroot  */
485302Sroot tcp_trace(act, ostate, tp, ti, req)
495302Sroot 	short act, ostate;
505302Sroot 	struct tcpcb *tp;
515302Sroot 	struct tcpiphdr *ti;
525302Sroot 	int req;
535302Sroot {
545302Sroot 	tcp_seq seq, ack;
555302Sroot 	int len, flags;
565302Sroot 	struct tcp_debug *td = &tcp_debug[tcp_debx++];
575302Sroot 
585302Sroot 	if (tcp_debx == TCP_NDEBUG)
595302Sroot 		tcp_debx = 0;
605302Sroot 	td->td_time = iptime();
615302Sroot 	td->td_act = act;
625302Sroot 	td->td_ostate = ostate;
635302Sroot 	td->td_tcb = (caddr_t)tp;
645302Sroot 	if (tp)
655302Sroot 		td->td_cb = *tp;
665302Sroot 	else
675302Sroot 		bzero((caddr_t)&td->td_cb, sizeof (*tp));
685302Sroot 	if (ti)
695302Sroot 		td->td_ti = *ti;
705302Sroot 	else
715302Sroot 		bzero((caddr_t)&td->td_ti, sizeof (*ti));
725302Sroot 	td->td_req = req;
7344374Skarels #ifdef TCPDEBUG
745302Sroot 	if (tcpconsdebug == 0)
755302Sroot 		return;
765302Sroot 	if (tp)
775302Sroot 		printf("%x %s:", tp, tcpstates[ostate]);
785302Sroot 	else
795302Sroot 		printf("???????? ");
805302Sroot 	printf("%s ", tanames[act]);
815302Sroot 	switch (act) {
825302Sroot 
835302Sroot 	case TA_INPUT:
845302Sroot 	case TA_OUTPUT:
8512440Ssam 	case TA_DROP:
8612440Ssam 		if (ti == 0)
8712440Ssam 			break;
885302Sroot 		seq = ti->ti_seq;
895302Sroot 		ack = ti->ti_ack;
905302Sroot 		len = ti->ti_len;
915302Sroot 		if (act == TA_OUTPUT) {
925302Sroot 			seq = ntohl(seq);
935302Sroot 			ack = ntohl(ack);
946161Ssam 			len = ntohs((u_short)len);
955302Sroot 		}
965302Sroot 		if (act == TA_OUTPUT)
975302Sroot 			len -= sizeof (struct tcphdr);
985302Sroot 		if (len)
995302Sroot 			printf("[%x..%x)", seq, seq+len);
1005302Sroot 		else
1015302Sroot 			printf("%x", seq);
10212440Ssam 		printf("@%x, urp=%x", ack, ti->ti_urp);
1035302Sroot 		flags = ti->ti_flags;
1045302Sroot 		if (flags) {
1056161Ssam #ifndef lint
1065302Sroot 			char *cp = "<";
1075302Sroot #define pf(f) { if (ti->ti_flags&TH_/**/f) { printf("%s%s", cp, "f"); cp = ","; } }
10812440Ssam 			pf(SYN); pf(ACK); pf(FIN); pf(RST); pf(PUSH); pf(URG);
1096161Ssam #endif
1105302Sroot 			printf(">");
1115302Sroot 		}
1125302Sroot 		break;
1135302Sroot 
1145302Sroot 	case TA_USER:
1155302Sroot 		printf("%s", prurequests[req&0xff]);
1165302Sroot 		if ((req & 0xff) == PRU_SLOWTIMO)
1175302Sroot 			printf("<%s>", tcptimers[req>>8]);
1185302Sroot 		break;
1195302Sroot 	}
1205302Sroot 	if (tp)
1215302Sroot 		printf(" -> %s", tcpstates[tp->t_state]);
1225302Sroot 	/* print out internal state of tp !?! */
1235302Sroot 	printf("\n");
1245302Sroot 	if (tp == 0)
1255302Sroot 		return;
12612440Ssam 	printf("\trcv_(nxt,wnd,up) (%x,%x,%x) snd_(una,nxt,max) (%x,%x,%x)\n",
12712440Ssam 	    tp->rcv_nxt, tp->rcv_wnd, tp->rcv_up, tp->snd_una, tp->snd_nxt,
12812440Ssam 	    tp->snd_max);
1295302Sroot 	printf("\tsnd_(wl1,wl2,wnd) (%x,%x,%x)\n",
1305302Sroot 	    tp->snd_wl1, tp->snd_wl2, tp->snd_wnd);
13144374Skarels #endif /* TCPDEBUG */
1325302Sroot }
133