xref: /csrg-svn/sys/netinet/tcp_debug.c (revision 34854)
123188Smckusick /*
229148Smckusick  * Copyright (c) 1982, 1986 Regents of the University of California.
332787Sbostic  * All rights reserved.
423188Smckusick  *
532787Sbostic  * Redistribution and use in source and binary forms are permitted
6*34854Sbostic  * provided that the above copyright notice and this paragraph are
7*34854Sbostic  * duplicated in all such forms and that any documentation,
8*34854Sbostic  * advertising materials, and other materials related to such
9*34854Sbostic  * distribution and use acknowledge that the software was developed
10*34854Sbostic  * by the University of California, Berkeley.  The name of the
11*34854Sbostic  * University may not be used to endorse or promote products derived
12*34854Sbostic  * from this software without specific prior written permission.
13*34854Sbostic  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14*34854Sbostic  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15*34854Sbostic  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1632787Sbostic  *
17*34854Sbostic  *	@(#)tcp_debug.c	7.3 (Berkeley) 06/29/88
1823188Smckusick  */
195302Sroot 
2017062Sbloom #include "param.h"
2117062Sbloom #include "systm.h"
2217062Sbloom #include "mbuf.h"
2317062Sbloom #include "socket.h"
2417062Sbloom #include "socketvar.h"
255302Sroot #define PRUREQUESTS
2617062Sbloom #include "protosw.h"
2717062Sbloom #include "errno.h"
2810894Ssam 
2910894Ssam #include "../net/route.h"
3010894Ssam #include "../net/if.h"
3110894Ssam 
3217062Sbloom #include "in.h"
3317062Sbloom #include "in_pcb.h"
3417062Sbloom #include "in_systm.h"
3517062Sbloom #include "ip.h"
3617062Sbloom #include "ip_var.h"
3717062Sbloom #include "tcp.h"
385302Sroot #define TCPSTATES
3917062Sbloom #include "tcp_fsm.h"
4017062Sbloom #include "tcp_seq.h"
415302Sroot #define	TCPTIMERS
4217062Sbloom #include "tcp_timer.h"
4317062Sbloom #include "tcp_var.h"
4417062Sbloom #include "tcpip.h"
455302Sroot #define	TANAMES
4617062Sbloom #include "tcp_debug.h"
475302Sroot 
485302Sroot int	tcpconsdebug = 0;
495302Sroot /*
505302Sroot  * Tcp debug routines
515302Sroot  */
525302Sroot tcp_trace(act, ostate, tp, ti, req)
535302Sroot 	short act, ostate;
545302Sroot 	struct tcpcb *tp;
555302Sroot 	struct tcpiphdr *ti;
565302Sroot 	int req;
575302Sroot {
585302Sroot 	tcp_seq seq, ack;
595302Sroot 	int len, flags;
605302Sroot 	struct tcp_debug *td = &tcp_debug[tcp_debx++];
615302Sroot 
625302Sroot 	if (tcp_debx == TCP_NDEBUG)
635302Sroot 		tcp_debx = 0;
645302Sroot 	td->td_time = iptime();
655302Sroot 	td->td_act = act;
665302Sroot 	td->td_ostate = ostate;
675302Sroot 	td->td_tcb = (caddr_t)tp;
685302Sroot 	if (tp)
695302Sroot 		td->td_cb = *tp;
705302Sroot 	else
715302Sroot 		bzero((caddr_t)&td->td_cb, sizeof (*tp));
725302Sroot 	if (ti)
735302Sroot 		td->td_ti = *ti;
745302Sroot 	else
755302Sroot 		bzero((caddr_t)&td->td_ti, sizeof (*ti));
765302Sroot 	td->td_req = req;
775302Sroot 	if (tcpconsdebug == 0)
785302Sroot 		return;
795302Sroot 	if (tp)
805302Sroot 		printf("%x %s:", tp, tcpstates[ostate]);
815302Sroot 	else
825302Sroot 		printf("???????? ");
835302Sroot 	printf("%s ", tanames[act]);
845302Sroot 	switch (act) {
855302Sroot 
865302Sroot 	case TA_INPUT:
875302Sroot 	case TA_OUTPUT:
8812440Ssam 	case TA_DROP:
8912440Ssam 		if (ti == 0)
9012440Ssam 			break;
915302Sroot 		seq = ti->ti_seq;
925302Sroot 		ack = ti->ti_ack;
935302Sroot 		len = ti->ti_len;
945302Sroot 		if (act == TA_OUTPUT) {
955302Sroot 			seq = ntohl(seq);
965302Sroot 			ack = ntohl(ack);
976161Ssam 			len = ntohs((u_short)len);
985302Sroot 		}
995302Sroot 		if (act == TA_OUTPUT)
1005302Sroot 			len -= sizeof (struct tcphdr);
1015302Sroot 		if (len)
1025302Sroot 			printf("[%x..%x)", seq, seq+len);
1035302Sroot 		else
1045302Sroot 			printf("%x", seq);
10512440Ssam 		printf("@%x, urp=%x", ack, ti->ti_urp);
1065302Sroot 		flags = ti->ti_flags;
1075302Sroot 		if (flags) {
1086161Ssam #ifndef lint
1095302Sroot 			char *cp = "<";
1105302Sroot #define pf(f) { if (ti->ti_flags&TH_/**/f) { printf("%s%s", cp, "f"); cp = ","; } }
11112440Ssam 			pf(SYN); pf(ACK); pf(FIN); pf(RST); pf(PUSH); pf(URG);
1126161Ssam #endif
1135302Sroot 			printf(">");
1145302Sroot 		}
1155302Sroot 		break;
1165302Sroot 
1175302Sroot 	case TA_USER:
1185302Sroot 		printf("%s", prurequests[req&0xff]);
1195302Sroot 		if ((req & 0xff) == PRU_SLOWTIMO)
1205302Sroot 			printf("<%s>", tcptimers[req>>8]);
1215302Sroot 		break;
1225302Sroot 	}
1235302Sroot 	if (tp)
1245302Sroot 		printf(" -> %s", tcpstates[tp->t_state]);
1255302Sroot 	/* print out internal state of tp !?! */
1265302Sroot 	printf("\n");
1275302Sroot 	if (tp == 0)
1285302Sroot 		return;
12912440Ssam 	printf("\trcv_(nxt,wnd,up) (%x,%x,%x) snd_(una,nxt,max) (%x,%x,%x)\n",
13012440Ssam 	    tp->rcv_nxt, tp->rcv_wnd, tp->rcv_up, tp->snd_una, tp->snd_nxt,
13112440Ssam 	    tp->snd_max);
1325302Sroot 	printf("\tsnd_(wl1,wl2,wnd) (%x,%x,%x)\n",
1335302Sroot 	    tp->snd_wl1, tp->snd_wl2, tp->snd_wnd);
1345302Sroot }
135