xref: /csrg-svn/sys/netinet/tcp_debug.c (revision 61335)
123188Smckusick /*
229148Smckusick  * Copyright (c) 1982, 1986 Regents of the University of California.
332787Sbostic  * All rights reserved.
423188Smckusick  *
544484Sbostic  * %sccs.include.redist.c%
632787Sbostic  *
7*61335Sbostic  *	@(#)tcp_debug.c	7.8 (Berkeley) 06/04/93
823188Smckusick  */
95302Sroot 
1044374Skarels #ifdef TCPDEBUG
1144374Skarels /* load symbolic names */
1244374Skarels #define PRUREQUESTS
1344374Skarels #define TCPSTATES
1444374Skarels #define	TCPTIMERS
1544374Skarels #define	TANAMES
1644374Skarels #endif
1744374Skarels 
1856531Sbostic #include <sys/param.h>
1956531Sbostic #include <sys/systm.h>
2056531Sbostic #include <sys/mbuf.h>
2156531Sbostic #include <sys/socket.h>
2256531Sbostic #include <sys/socketvar.h>
2356531Sbostic #include <sys/protosw.h>
2456531Sbostic #include <sys/errno.h>
2510894Ssam 
2656531Sbostic #include <net/route.h>
2756531Sbostic #include <net/if.h>
2810894Ssam 
2956531Sbostic #include <netinet/in.h>
3056531Sbostic #include <netinet/in_systm.h>
3156531Sbostic #include <netinet/ip.h>
3256531Sbostic #include <netinet/in_pcb.h>
3356531Sbostic #include <netinet/ip_var.h>
3456531Sbostic #include <netinet/tcp.h>
3556531Sbostic #include <netinet/tcp_fsm.h>
3656531Sbostic #include <netinet/tcp_seq.h>
3756531Sbostic #include <netinet/tcp_timer.h>
3856531Sbostic #include <netinet/tcp_var.h>
3956531Sbostic #include <netinet/tcpip.h>
4056531Sbostic #include <netinet/tcp_debug.h>
415302Sroot 
4244374Skarels #ifdef TCPDEBUG
435302Sroot int	tcpconsdebug = 0;
4444374Skarels #endif
455302Sroot /*
465302Sroot  * Tcp debug routines
475302Sroot  */
48*61335Sbostic void
495302Sroot tcp_trace(act, ostate, tp, ti, req)
505302Sroot 	short act, ostate;
515302Sroot 	struct tcpcb *tp;
525302Sroot 	struct tcpiphdr *ti;
535302Sroot 	int req;
545302Sroot {
555302Sroot 	tcp_seq seq, ack;
565302Sroot 	int len, flags;
575302Sroot 	struct tcp_debug *td = &tcp_debug[tcp_debx++];
585302Sroot 
595302Sroot 	if (tcp_debx == TCP_NDEBUG)
605302Sroot 		tcp_debx = 0;
615302Sroot 	td->td_time = iptime();
625302Sroot 	td->td_act = act;
635302Sroot 	td->td_ostate = ostate;
645302Sroot 	td->td_tcb = (caddr_t)tp;
655302Sroot 	if (tp)
665302Sroot 		td->td_cb = *tp;
675302Sroot 	else
685302Sroot 		bzero((caddr_t)&td->td_cb, sizeof (*tp));
695302Sroot 	if (ti)
705302Sroot 		td->td_ti = *ti;
715302Sroot 	else
725302Sroot 		bzero((caddr_t)&td->td_ti, sizeof (*ti));
735302Sroot 	td->td_req = req;
7444374Skarels #ifdef TCPDEBUG
755302Sroot 	if (tcpconsdebug == 0)
765302Sroot 		return;
775302Sroot 	if (tp)
785302Sroot 		printf("%x %s:", tp, tcpstates[ostate]);
795302Sroot 	else
805302Sroot 		printf("???????? ");
815302Sroot 	printf("%s ", tanames[act]);
825302Sroot 	switch (act) {
835302Sroot 
845302Sroot 	case TA_INPUT:
855302Sroot 	case TA_OUTPUT:
8612440Ssam 	case TA_DROP:
8712440Ssam 		if (ti == 0)
8812440Ssam 			break;
895302Sroot 		seq = ti->ti_seq;
905302Sroot 		ack = ti->ti_ack;
915302Sroot 		len = ti->ti_len;
925302Sroot 		if (act == TA_OUTPUT) {
935302Sroot 			seq = ntohl(seq);
945302Sroot 			ack = ntohl(ack);
956161Ssam 			len = ntohs((u_short)len);
965302Sroot 		}
975302Sroot 		if (act == TA_OUTPUT)
985302Sroot 			len -= sizeof (struct tcphdr);
995302Sroot 		if (len)
1005302Sroot 			printf("[%x..%x)", seq, seq+len);
1015302Sroot 		else
1025302Sroot 			printf("%x", seq);
10312440Ssam 		printf("@%x, urp=%x", ack, ti->ti_urp);
1045302Sroot 		flags = ti->ti_flags;
1055302Sroot 		if (flags) {
1066161Ssam #ifndef lint
1075302Sroot 			char *cp = "<";
1085302Sroot #define pf(f) { if (ti->ti_flags&TH_/**/f) { printf("%s%s", cp, "f"); cp = ","; } }
10912440Ssam 			pf(SYN); pf(ACK); pf(FIN); pf(RST); pf(PUSH); pf(URG);
1106161Ssam #endif
1115302Sroot 			printf(">");
1125302Sroot 		}
1135302Sroot 		break;
1145302Sroot 
1155302Sroot 	case TA_USER:
1165302Sroot 		printf("%s", prurequests[req&0xff]);
1175302Sroot 		if ((req & 0xff) == PRU_SLOWTIMO)
1185302Sroot 			printf("<%s>", tcptimers[req>>8]);
1195302Sroot 		break;
1205302Sroot 	}
1215302Sroot 	if (tp)
1225302Sroot 		printf(" -> %s", tcpstates[tp->t_state]);
1235302Sroot 	/* print out internal state of tp !?! */
1245302Sroot 	printf("\n");
1255302Sroot 	if (tp == 0)
1265302Sroot 		return;
12712440Ssam 	printf("\trcv_(nxt,wnd,up) (%x,%x,%x) snd_(una,nxt,max) (%x,%x,%x)\n",
12812440Ssam 	    tp->rcv_nxt, tp->rcv_wnd, tp->rcv_up, tp->snd_una, tp->snd_nxt,
12912440Ssam 	    tp->snd_max);
1305302Sroot 	printf("\tsnd_(wl1,wl2,wnd) (%x,%x,%x)\n",
1315302Sroot 	    tp->snd_wl1, tp->snd_wl2, tp->snd_wnd);
13244374Skarels #endif /* TCPDEBUG */
1335302Sroot }
134