xref: /csrg-svn/sys/netinet/tcp_debug.c (revision 8401)
1*8401Swnj /*	tcp_debug.c	4.5	82/10/09	*/
25302Sroot 
35302Sroot #include "../h/param.h"
45302Sroot #include "../h/systm.h"
55302Sroot #include "../h/mbuf.h"
65302Sroot #include "../h/socket.h"
75302Sroot #include "../h/socketvar.h"
85302Sroot #define PRUREQUESTS
95302Sroot #include "../h/protosw.h"
10*8401Swnj #include "../netinet/in.h"
116351Ssam #include "../net/route.h"
12*8401Swnj #include "../netinet/in_pcb.h"
13*8401Swnj #include "../netinet/in_systm.h"
145302Sroot #include "../net/if.h"
15*8401Swnj #include "../netinet/ip.h"
16*8401Swnj #include "../netinet/ip_var.h"
17*8401Swnj #include "../netinet/tcp.h"
185302Sroot #define TCPSTATES
19*8401Swnj #include "../netinet/tcp_fsm.h"
20*8401Swnj #include "../netinet/tcp_seq.h"
215302Sroot #define	TCPTIMERS
22*8401Swnj #include "../netinet/tcp_timer.h"
23*8401Swnj #include "../netinet/tcp_var.h"
24*8401Swnj #include "../netinet/tcpip.h"
255302Sroot #define	TANAMES
26*8401Swnj #include "../netinet/tcp_debug.h"
277300Ssam #include <errno.h>
285302Sroot 
295302Sroot int	tcpconsdebug = 0;
305302Sroot /*
315302Sroot  * Tcp debug routines
325302Sroot  */
335302Sroot tcp_trace(act, ostate, tp, ti, req)
345302Sroot 	short act, ostate;
355302Sroot 	struct tcpcb *tp;
365302Sroot 	struct tcpiphdr *ti;
375302Sroot 	int req;
385302Sroot {
395302Sroot 	tcp_seq seq, ack;
405302Sroot 	int len, flags;
415302Sroot 	struct tcp_debug *td = &tcp_debug[tcp_debx++];
425302Sroot 
435302Sroot 	if (tcp_debx == TCP_NDEBUG)
445302Sroot 		tcp_debx = 0;
455302Sroot 	td->td_time = iptime();
465302Sroot 	td->td_act = act;
475302Sroot 	td->td_ostate = ostate;
485302Sroot 	td->td_tcb = (caddr_t)tp;
495302Sroot 	if (tp)
505302Sroot 		td->td_cb = *tp;
515302Sroot 	else
525302Sroot 		bzero((caddr_t)&td->td_cb, sizeof (*tp));
535302Sroot 	if (ti)
545302Sroot 		td->td_ti = *ti;
555302Sroot 	else
565302Sroot 		bzero((caddr_t)&td->td_ti, sizeof (*ti));
575302Sroot 	td->td_req = req;
585302Sroot 	if (tcpconsdebug == 0)
595302Sroot 		return;
605302Sroot 	if (tp)
615302Sroot 		printf("%x %s:", tp, tcpstates[ostate]);
625302Sroot 	else
635302Sroot 		printf("???????? ");
645302Sroot 	printf("%s ", tanames[act]);
655302Sroot 	switch (act) {
665302Sroot 
675302Sroot 	case TA_INPUT:
685302Sroot 	case TA_OUTPUT:
695302Sroot 		seq = ti->ti_seq;
705302Sroot 		ack = ti->ti_ack;
715302Sroot 		len = ti->ti_len;
725302Sroot #if vax
735302Sroot 		if (act == TA_OUTPUT) {
745302Sroot 			seq = ntohl(seq);
755302Sroot 			ack = ntohl(ack);
766161Ssam 			len = ntohs((u_short)len);
775302Sroot 		}
785302Sroot #endif
795302Sroot 		if (act == TA_OUTPUT)
805302Sroot 			len -= sizeof (struct tcphdr);
815302Sroot 		if (len)
825302Sroot 			printf("[%x..%x)", seq, seq+len);
835302Sroot 		else
845302Sroot 			printf("%x", seq);
855302Sroot 		printf("@%x", ack);
865302Sroot 		flags = ti->ti_flags;
875302Sroot 		if (flags) {
886161Ssam #ifndef lint
895302Sroot 			char *cp = "<";
905302Sroot #define pf(f) { if (ti->ti_flags&TH_/**/f) { printf("%s%s", cp, "f"); cp = ","; } }
915302Sroot 			pf(SYN); pf(ACK); pf(FIN); pf(RST);
926161Ssam #endif
935302Sroot 			printf(">");
945302Sroot 		}
955302Sroot 		break;
965302Sroot 
975302Sroot 	case TA_USER:
985302Sroot 		printf("%s", prurequests[req&0xff]);
995302Sroot 		if ((req & 0xff) == PRU_SLOWTIMO)
1005302Sroot 			printf("<%s>", tcptimers[req>>8]);
1015302Sroot 		break;
1025302Sroot 	}
1035302Sroot 	if (tp)
1045302Sroot 		printf(" -> %s", tcpstates[tp->t_state]);
1055302Sroot 	/* print out internal state of tp !?! */
1065302Sroot 	printf("\n");
1075302Sroot 	if (tp == 0)
1085302Sroot 		return;
1095302Sroot 	printf("\trcv_(nxt,wnd) (%x,%x) snd_(una,nxt,max) (%x,%x,%x)\n",
1105302Sroot 	    tp->rcv_nxt, tp->rcv_wnd, tp->snd_una, tp->snd_nxt, tp->snd_max);
1115302Sroot 	printf("\tsnd_(wl1,wl2,wnd) (%x,%x,%x)\n",
1125302Sroot 	    tp->snd_wl1, tp->snd_wl2, tp->snd_wnd);
1135302Sroot }
114