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