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