xref: /csrg-svn/sys/netinet/tcp_debug.c (revision 6161)
1*6161Ssam /*	tcp_debug.c	4.2	82/03/13	*/
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"
105302Sroot #include "../net/in.h"
115302Sroot #include "../net/in_pcb.h"
125302Sroot #include "../net/in_systm.h"
135302Sroot #include "../net/if.h"
145302Sroot #include "../net/ip.h"
155302Sroot #include "../net/ip_var.h"
165302Sroot #include "../net/tcp.h"
175302Sroot #define TCPSTATES
185302Sroot #include "../net/tcp_fsm.h"
195302Sroot #include "../net/tcp_seq.h"
205302Sroot #define	TCPTIMERS
215302Sroot #include "../net/tcp_timer.h"
225302Sroot #include "../net/tcp_var.h"
235302Sroot #include "../net/tcpip.h"
245302Sroot #define	TANAMES
255302Sroot #include "../net/tcp_debug.h"
265302Sroot #include "../errno.h"
275302Sroot 
285302Sroot int	tcpconsdebug = 0;
295302Sroot /*
305302Sroot  * Tcp debug routines
315302Sroot  */
325302Sroot tcp_trace(act, ostate, tp, ti, req)
335302Sroot 	short act, ostate;
345302Sroot 	struct tcpcb *tp;
355302Sroot 	struct tcpiphdr *ti;
365302Sroot 	int req;
375302Sroot {
385302Sroot 	tcp_seq seq, ack;
395302Sroot 	int len, flags;
405302Sroot 	struct tcp_debug *td = &tcp_debug[tcp_debx++];
415302Sroot 
425302Sroot 	if (tcp_debx == TCP_NDEBUG)
435302Sroot 		tcp_debx = 0;
445302Sroot 	td->td_time = iptime();
455302Sroot 	td->td_act = act;
465302Sroot 	td->td_ostate = ostate;
475302Sroot 	td->td_tcb = (caddr_t)tp;
485302Sroot 	if (tp)
495302Sroot 		td->td_cb = *tp;
505302Sroot 	else
515302Sroot 		bzero((caddr_t)&td->td_cb, sizeof (*tp));
525302Sroot 	if (ti)
535302Sroot 		td->td_ti = *ti;
545302Sroot 	else
555302Sroot 		bzero((caddr_t)&td->td_ti, sizeof (*ti));
565302Sroot 	td->td_req = req;
575302Sroot 	if (tcpconsdebug == 0)
585302Sroot 		return;
595302Sroot 	if (tp)
605302Sroot 		printf("%x %s:", tp, tcpstates[ostate]);
615302Sroot 	else
625302Sroot 		printf("???????? ");
635302Sroot 	printf("%s ", tanames[act]);
645302Sroot 	switch (act) {
655302Sroot 
665302Sroot 	case TA_INPUT:
675302Sroot 	case TA_OUTPUT:
685302Sroot 		seq = ti->ti_seq;
695302Sroot 		ack = ti->ti_ack;
705302Sroot 		len = ti->ti_len;
715302Sroot #if vax
725302Sroot 		if (act == TA_OUTPUT) {
735302Sroot 			seq = ntohl(seq);
745302Sroot 			ack = ntohl(ack);
75*6161Ssam 			len = ntohs((u_short)len);
765302Sroot 		}
775302Sroot #endif
785302Sroot 		if (act == TA_OUTPUT)
795302Sroot 			len -= sizeof (struct tcphdr);
805302Sroot 		if (len)
815302Sroot 			printf("[%x..%x)", seq, seq+len);
825302Sroot 		else
835302Sroot 			printf("%x", seq);
845302Sroot 		printf("@%x", ack);
855302Sroot 		flags = ti->ti_flags;
865302Sroot 		if (flags) {
87*6161Ssam #ifndef lint
885302Sroot 			char *cp = "<";
895302Sroot #define pf(f) { if (ti->ti_flags&TH_/**/f) { printf("%s%s", cp, "f"); cp = ","; } }
905302Sroot 			pf(SYN); pf(ACK); pf(FIN); pf(RST);
91*6161Ssam #endif
925302Sroot 			printf(">");
935302Sroot 		}
945302Sroot 		break;
955302Sroot 
965302Sroot 	case TA_USER:
975302Sroot 		printf("%s", prurequests[req&0xff]);
985302Sroot 		if ((req & 0xff) == PRU_SLOWTIMO)
995302Sroot 			printf("<%s>", tcptimers[req>>8]);
1005302Sroot 		break;
1015302Sroot 	}
1025302Sroot 	if (tp)
1035302Sroot 		printf(" -> %s", tcpstates[tp->t_state]);
1045302Sroot 	/* print out internal state of tp !?! */
1055302Sroot 	printf("\n");
1065302Sroot 	if (tp == 0)
1075302Sroot 		return;
1085302Sroot 	printf("\trcv_(nxt,wnd) (%x,%x) snd_(una,nxt,max) (%x,%x,%x)\n",
1095302Sroot 	    tp->rcv_nxt, tp->rcv_wnd, tp->snd_una, tp->snd_nxt, tp->snd_max);
1105302Sroot 	printf("\tsnd_(wl1,wl2,wnd) (%x,%x,%x)\n",
1115302Sroot 	    tp->snd_wl1, tp->snd_wl2, tp->snd_wnd);
1125302Sroot }
113