xref: /csrg-svn/sys/netinet/tcp_debug.c (revision 32787)
123188Smckusick /*
229148Smckusick  * Copyright (c) 1982, 1986 Regents of the University of California.
3*32787Sbostic  * All rights reserved.
423188Smckusick  *
5*32787Sbostic  * Redistribution and use in source and binary forms are permitted
6*32787Sbostic  * provided that this notice is preserved and that due credit is given
7*32787Sbostic  * to the University of California at Berkeley. The name of the University
8*32787Sbostic  * may not be used to endorse or promote products derived from this
9*32787Sbostic  * software without specific prior written permission. This software
10*32787Sbostic  * is provided ``as is'' without express or implied warranty.
11*32787Sbostic  *
12*32787Sbostic  *	@(#)tcp_debug.c	7.2 (Berkeley) 12/07/87
1323188Smckusick  */
145302Sroot 
1517062Sbloom #include "param.h"
1617062Sbloom #include "systm.h"
1717062Sbloom #include "mbuf.h"
1817062Sbloom #include "socket.h"
1917062Sbloom #include "socketvar.h"
205302Sroot #define PRUREQUESTS
2117062Sbloom #include "protosw.h"
2217062Sbloom #include "errno.h"
2310894Ssam 
2410894Ssam #include "../net/route.h"
2510894Ssam #include "../net/if.h"
2610894Ssam 
2717062Sbloom #include "in.h"
2817062Sbloom #include "in_pcb.h"
2917062Sbloom #include "in_systm.h"
3017062Sbloom #include "ip.h"
3117062Sbloom #include "ip_var.h"
3217062Sbloom #include "tcp.h"
335302Sroot #define TCPSTATES
3417062Sbloom #include "tcp_fsm.h"
3517062Sbloom #include "tcp_seq.h"
365302Sroot #define	TCPTIMERS
3717062Sbloom #include "tcp_timer.h"
3817062Sbloom #include "tcp_var.h"
3917062Sbloom #include "tcpip.h"
405302Sroot #define	TANAMES
4117062Sbloom #include "tcp_debug.h"
425302Sroot 
435302Sroot int	tcpconsdebug = 0;
445302Sroot /*
455302Sroot  * Tcp debug routines
465302Sroot  */
475302Sroot tcp_trace(act, ostate, tp, ti, req)
485302Sroot 	short act, ostate;
495302Sroot 	struct tcpcb *tp;
505302Sroot 	struct tcpiphdr *ti;
515302Sroot 	int req;
525302Sroot {
535302Sroot 	tcp_seq seq, ack;
545302Sroot 	int len, flags;
555302Sroot 	struct tcp_debug *td = &tcp_debug[tcp_debx++];
565302Sroot 
575302Sroot 	if (tcp_debx == TCP_NDEBUG)
585302Sroot 		tcp_debx = 0;
595302Sroot 	td->td_time = iptime();
605302Sroot 	td->td_act = act;
615302Sroot 	td->td_ostate = ostate;
625302Sroot 	td->td_tcb = (caddr_t)tp;
635302Sroot 	if (tp)
645302Sroot 		td->td_cb = *tp;
655302Sroot 	else
665302Sroot 		bzero((caddr_t)&td->td_cb, sizeof (*tp));
675302Sroot 	if (ti)
685302Sroot 		td->td_ti = *ti;
695302Sroot 	else
705302Sroot 		bzero((caddr_t)&td->td_ti, sizeof (*ti));
715302Sroot 	td->td_req = req;
725302Sroot 	if (tcpconsdebug == 0)
735302Sroot 		return;
745302Sroot 	if (tp)
755302Sroot 		printf("%x %s:", tp, tcpstates[ostate]);
765302Sroot 	else
775302Sroot 		printf("???????? ");
785302Sroot 	printf("%s ", tanames[act]);
795302Sroot 	switch (act) {
805302Sroot 
815302Sroot 	case TA_INPUT:
825302Sroot 	case TA_OUTPUT:
8312440Ssam 	case TA_DROP:
8412440Ssam 		if (ti == 0)
8512440Ssam 			break;
865302Sroot 		seq = ti->ti_seq;
875302Sroot 		ack = ti->ti_ack;
885302Sroot 		len = ti->ti_len;
895302Sroot 		if (act == TA_OUTPUT) {
905302Sroot 			seq = ntohl(seq);
915302Sroot 			ack = ntohl(ack);
926161Ssam 			len = ntohs((u_short)len);
935302Sroot 		}
945302Sroot 		if (act == TA_OUTPUT)
955302Sroot 			len -= sizeof (struct tcphdr);
965302Sroot 		if (len)
975302Sroot 			printf("[%x..%x)", seq, seq+len);
985302Sroot 		else
995302Sroot 			printf("%x", seq);
10012440Ssam 		printf("@%x, urp=%x", ack, ti->ti_urp);
1015302Sroot 		flags = ti->ti_flags;
1025302Sroot 		if (flags) {
1036161Ssam #ifndef lint
1045302Sroot 			char *cp = "<";
1055302Sroot #define pf(f) { if (ti->ti_flags&TH_/**/f) { printf("%s%s", cp, "f"); cp = ","; } }
10612440Ssam 			pf(SYN); pf(ACK); pf(FIN); pf(RST); pf(PUSH); pf(URG);
1076161Ssam #endif
1085302Sroot 			printf(">");
1095302Sroot 		}
1105302Sroot 		break;
1115302Sroot 
1125302Sroot 	case TA_USER:
1135302Sroot 		printf("%s", prurequests[req&0xff]);
1145302Sroot 		if ((req & 0xff) == PRU_SLOWTIMO)
1155302Sroot 			printf("<%s>", tcptimers[req>>8]);
1165302Sroot 		break;
1175302Sroot 	}
1185302Sroot 	if (tp)
1195302Sroot 		printf(" -> %s", tcpstates[tp->t_state]);
1205302Sroot 	/* print out internal state of tp !?! */
1215302Sroot 	printf("\n");
1225302Sroot 	if (tp == 0)
1235302Sroot 		return;
12412440Ssam 	printf("\trcv_(nxt,wnd,up) (%x,%x,%x) snd_(una,nxt,max) (%x,%x,%x)\n",
12512440Ssam 	    tp->rcv_nxt, tp->rcv_wnd, tp->rcv_up, tp->snd_una, tp->snd_nxt,
12612440Ssam 	    tp->snd_max);
1275302Sroot 	printf("\tsnd_(wl1,wl2,wnd) (%x,%x,%x)\n",
1285302Sroot 	    tp->snd_wl1, tp->snd_wl2, tp->snd_wnd);
1295302Sroot }
130