Home | History | Annotate | Line # | Download | only in netinet
tcp_debug.c revision 1.13.26.1
      1  1.13.26.1    itojun /*	$NetBSD: tcp_debug.c,v 1.13.26.1 1999/06/28 06:37:01 itojun Exp $	*/
      2        1.8       cgd 
      3        1.1       cgd /*
      4        1.7   mycroft  * Copyright (c) 1982, 1986, 1993
      5        1.7   mycroft  *	The Regents of the University of California.  All rights reserved.
      6        1.1       cgd  *
      7        1.1       cgd  * Redistribution and use in source and binary forms, with or without
      8        1.1       cgd  * modification, are permitted provided that the following conditions
      9        1.1       cgd  * are met:
     10        1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     11        1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     12        1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     13        1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     14        1.1       cgd  *    documentation and/or other materials provided with the distribution.
     15        1.1       cgd  * 3. All advertising materials mentioning features or use of this software
     16        1.1       cgd  *    must display the following acknowledgement:
     17        1.1       cgd  *	This product includes software developed by the University of
     18        1.1       cgd  *	California, Berkeley and its contributors.
     19        1.1       cgd  * 4. Neither the name of the University nor the names of its contributors
     20        1.1       cgd  *    may be used to endorse or promote products derived from this software
     21        1.1       cgd  *    without specific prior written permission.
     22        1.1       cgd  *
     23        1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24        1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25        1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26        1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27        1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28        1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29        1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30        1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31        1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32        1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33        1.1       cgd  * SUCH DAMAGE.
     34        1.1       cgd  *
     35        1.8       cgd  *	@(#)tcp_debug.c	8.1 (Berkeley) 6/10/93
     36        1.1       cgd  */
     37        1.1       cgd 
     38  1.13.26.1    itojun #include "opt_inet.h"
     39  1.13.26.1    itojun 
     40        1.1       cgd #ifdef TCPDEBUG
     41        1.1       cgd /* load symbolic names */
     42        1.5   mycroft #define	PRUREQUESTS
     43        1.5   mycroft #define	TCPSTATES
     44        1.1       cgd #define	TCPTIMERS
     45        1.1       cgd #define	TANAMES
     46        1.1       cgd #endif
     47        1.1       cgd 
     48        1.4   mycroft #include <sys/param.h>
     49        1.4   mycroft #include <sys/systm.h>
     50        1.4   mycroft #include <sys/mbuf.h>
     51        1.4   mycroft #include <sys/socket.h>
     52        1.4   mycroft #include <sys/socketvar.h>
     53        1.4   mycroft #include <sys/protosw.h>
     54        1.4   mycroft #include <sys/errno.h>
     55        1.1       cgd 
     56        1.4   mycroft #include <net/route.h>
     57        1.4   mycroft #include <net/if.h>
     58        1.1       cgd 
     59        1.4   mycroft #include <netinet/in.h>
     60        1.4   mycroft #include <netinet/in_systm.h>
     61        1.4   mycroft #include <netinet/ip.h>
     62        1.4   mycroft #include <netinet/in_pcb.h>
     63        1.4   mycroft #include <netinet/ip_var.h>
     64  1.13.26.1    itojun 
     65  1.13.26.1    itojun #ifdef INET6
     66  1.13.26.1    itojun #ifndef INET
     67  1.13.26.1    itojun #include <netinet/in.h>
     68  1.13.26.1    itojun #endif
     69  1.13.26.1    itojun #include <netinet/ip6.h>
     70  1.13.26.1    itojun #endif
     71  1.13.26.1    itojun 
     72        1.4   mycroft #include <netinet/tcp.h>
     73        1.4   mycroft #include <netinet/tcp_fsm.h>
     74        1.4   mycroft #include <netinet/tcp_seq.h>
     75        1.4   mycroft #include <netinet/tcp_timer.h>
     76        1.4   mycroft #include <netinet/tcp_var.h>
     77        1.4   mycroft #include <netinet/tcpip.h>
     78        1.4   mycroft #include <netinet/tcp_debug.h>
     79        1.1       cgd 
     80        1.1       cgd #ifdef TCPDEBUG
     81        1.1       cgd int	tcpconsdebug = 0;
     82        1.1       cgd #endif
     83        1.1       cgd /*
     84        1.1       cgd  * Tcp debug routines
     85        1.1       cgd  */
     86        1.6   mycroft void
     87  1.13.26.1    itojun tcp_trace(act, ostate, tp, m, req)
     88        1.1       cgd 	short act, ostate;
     89        1.1       cgd 	struct tcpcb *tp;
     90  1.13.26.1    itojun 	struct mbuf *m;
     91        1.1       cgd 	int req;
     92        1.1       cgd {
     93       1.10  christos #ifdef TCPDEBUG
     94        1.1       cgd 	tcp_seq seq, ack;
     95        1.1       cgd 	int len, flags;
     96  1.13.26.1    itojun 	struct tcphdr *th;
     97       1.10  christos #endif
     98        1.1       cgd 	struct tcp_debug *td = &tcp_debug[tcp_debx++];
     99        1.1       cgd 
    100        1.1       cgd 	if (tcp_debx == TCP_NDEBUG)
    101        1.1       cgd 		tcp_debx = 0;
    102        1.1       cgd 	td->td_time = iptime();
    103        1.1       cgd 	td->td_act = act;
    104        1.1       cgd 	td->td_ostate = ostate;
    105        1.1       cgd 	td->td_tcb = (caddr_t)tp;
    106        1.1       cgd 	if (tp)
    107        1.1       cgd 		td->td_cb = *tp;
    108        1.1       cgd 	else
    109        1.1       cgd 		bzero((caddr_t)&td->td_cb, sizeof (*tp));
    110  1.13.26.1    itojun 	td->td_family = tp->t_family;
    111  1.13.26.1    itojun 	bzero((caddr_t)&td->td_ti, sizeof (td->td_ti));
    112  1.13.26.1    itojun #ifdef INET6
    113  1.13.26.1    itojun 	bzero((caddr_t)&td->td_ti6, sizeof (td->td_ti6));
    114  1.13.26.1    itojun #endif
    115  1.13.26.1    itojun #ifdef TCPDEBUG
    116  1.13.26.1    itojun 	th = NULL;
    117  1.13.26.1    itojun #endif
    118  1.13.26.1    itojun 	if (m) {
    119  1.13.26.1    itojun 		struct ip *ip;
    120  1.13.26.1    itojun 		ip = mtod(m, struct ip *);
    121  1.13.26.1    itojun 		switch (ip->ip_v) {
    122  1.13.26.1    itojun 		case 4:
    123  1.13.26.1    itojun 			if (m->m_len < sizeof(td->td_ti))
    124  1.13.26.1    itojun 				break;
    125  1.13.26.1    itojun 			bcopy(mtod(m, caddr_t), &td->td_ti, sizeof(td->td_ti));
    126  1.13.26.1    itojun #ifdef TCPDEBUG
    127  1.13.26.1    itojun 			th = (struct tcphdr *)((caddr_t)td->td_ti + sizeof(struct ip));
    128  1.13.26.1    itojun #endif
    129  1.13.26.1    itojun 			break;
    130  1.13.26.1    itojun #ifdef INET6
    131  1.13.26.1    itojun 		case 6:
    132  1.13.26.1    itojun 			if (m->m_len < sizeof(td->td_ti6))
    133  1.13.26.1    itojun 				break;
    134  1.13.26.1    itojun 			bcopy(mtod(m, caddr_t), &td->td_ti6,
    135  1.13.26.1    itojun 				sizeof(td->td_ti6));
    136  1.13.26.1    itojun #ifdef TCPDEBUG
    137  1.13.26.1    itojun 			th = (struct tcphdr *)((caddr_t)td->td_ti6 + sizeof(struct ip6_hdr));
    138  1.13.26.1    itojun #endif
    139  1.13.26.1    itojun 			break;
    140  1.13.26.1    itojun #endif
    141  1.13.26.1    itojun 		}
    142  1.13.26.1    itojun 	}
    143        1.1       cgd 	td->td_req = req;
    144        1.1       cgd #ifdef TCPDEBUG
    145        1.1       cgd 	if (tcpconsdebug == 0)
    146        1.1       cgd 		return;
    147        1.1       cgd 	if (tp)
    148       1.12  christos 		printf("%x %s:", tp, tcpstates[ostate]);
    149        1.1       cgd 	else
    150       1.12  christos 		printf("???????? ");
    151       1.12  christos 	printf("%s ", tanames[act]);
    152        1.1       cgd 	switch (act) {
    153        1.1       cgd 
    154        1.1       cgd 	case TA_INPUT:
    155        1.1       cgd 	case TA_OUTPUT:
    156        1.1       cgd 	case TA_DROP:
    157  1.13.26.1    itojun 		if (th == 0)
    158        1.1       cgd 			break;
    159  1.13.26.1    itojun 		seq = th->th_seq;
    160  1.13.26.1    itojun 		ack = th->th_ack;
    161  1.13.26.1    itojun 		len = th->th_len;
    162        1.1       cgd 		if (act == TA_OUTPUT) {
    163        1.1       cgd 			seq = ntohl(seq);
    164        1.1       cgd 			ack = ntohl(ack);
    165        1.9       cgd 			len = ntohs((u_int16_t)len);
    166        1.1       cgd 		}
    167        1.1       cgd 		if (act == TA_OUTPUT)
    168        1.1       cgd 			len -= sizeof (struct tcphdr);
    169        1.1       cgd 		if (len)
    170       1.12  christos 			printf("[%x..%x)", seq, seq+len);
    171        1.1       cgd 		else
    172       1.12  christos 			printf("%x", seq);
    173  1.13.26.1    itojun 		printf("@%x, urp=%x", ack, th->th_urp);
    174  1.13.26.1    itojun 		flags = th->th_flags;
    175        1.1       cgd 		if (flags) {
    176        1.1       cgd #ifndef lint
    177        1.1       cgd 			char *cp = "<";
    178  1.13.26.1    itojun #define pf(f) { if (th->th_flags&TH_/**/f) { printf("%s%s", cp, "f"); cp = ","; } }
    179        1.1       cgd 			pf(SYN); pf(ACK); pf(FIN); pf(RST); pf(PUSH); pf(URG);
    180        1.1       cgd #endif
    181       1.13  christos 			printf(">");
    182        1.1       cgd 		}
    183        1.1       cgd 		break;
    184        1.1       cgd 
    185        1.1       cgd 	case TA_USER:
    186       1.12  christos 		printf("%s", prurequests[req&0xff]);
    187        1.1       cgd 		if ((req & 0xff) == PRU_SLOWTIMO)
    188       1.12  christos 			printf("<%s>", tcptimers[req>>8]);
    189        1.1       cgd 		break;
    190        1.1       cgd 	}
    191        1.1       cgd 	if (tp)
    192       1.12  christos 		printf(" -> %s", tcpstates[tp->t_state]);
    193        1.1       cgd 	/* print out internal state of tp !?! */
    194       1.12  christos 	printf("\n");
    195        1.1       cgd 	if (tp == 0)
    196        1.1       cgd 		return;
    197       1.12  christos 	printf("\trcv_(nxt,wnd,up) (%x,%x,%x) snd_(una,nxt,max) (%x,%x,%x)\n",
    198        1.1       cgd 	    tp->rcv_nxt, tp->rcv_wnd, tp->rcv_up, tp->snd_una, tp->snd_nxt,
    199        1.1       cgd 	    tp->snd_max);
    200       1.12  christos 	printf("\tsnd_(wl1,wl2,wnd) (%x,%x,%x)\n",
    201        1.1       cgd 	    tp->snd_wl1, tp->snd_wl2, tp->snd_wnd);
    202        1.1       cgd #endif /* TCPDEBUG */
    203        1.1       cgd }
    204