1 /* 2 * Copyright (c) 1982, 1986 Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are permitted 6 * provided that the above copyright notice and this paragraph are 7 * duplicated in all such forms and that any documentation, 8 * advertising materials, and other materials related to such 9 * distribution and use acknowledge that the software was developed 10 * by the University of California, Berkeley. The name of the 11 * University may not be used to endorse or promote products derived 12 * from this software without specific prior written permission. 13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 16 * 17 * @(#)tcp_debug.c 7.5 (Berkeley) 06/28/90 18 */ 19 20 #ifdef TCPDEBUG 21 /* load symbolic names */ 22 #define PRUREQUESTS 23 #define TCPSTATES 24 #define TCPTIMERS 25 #define TANAMES 26 #endif 27 28 #include "param.h" 29 #include "systm.h" 30 #include "mbuf.h" 31 #include "socket.h" 32 #include "socketvar.h" 33 #include "protosw.h" 34 #include "errno.h" 35 36 #include "../net/route.h" 37 #include "../net/if.h" 38 39 #include "in.h" 40 #include "in_systm.h" 41 #include "ip.h" 42 #include "in_pcb.h" 43 #include "ip_var.h" 44 #include "tcp.h" 45 #include "tcp_fsm.h" 46 #include "tcp_seq.h" 47 #include "tcp_timer.h" 48 #include "tcp_var.h" 49 #include "tcpip.h" 50 #include "tcp_debug.h" 51 52 #ifdef TCPDEBUG 53 int tcpconsdebug = 0; 54 #endif 55 /* 56 * Tcp debug routines 57 */ 58 tcp_trace(act, ostate, tp, ti, req) 59 short act, ostate; 60 struct tcpcb *tp; 61 struct tcpiphdr *ti; 62 int req; 63 { 64 tcp_seq seq, ack; 65 int len, flags; 66 struct tcp_debug *td = &tcp_debug[tcp_debx++]; 67 68 if (tcp_debx == TCP_NDEBUG) 69 tcp_debx = 0; 70 td->td_time = iptime(); 71 td->td_act = act; 72 td->td_ostate = ostate; 73 td->td_tcb = (caddr_t)tp; 74 if (tp) 75 td->td_cb = *tp; 76 else 77 bzero((caddr_t)&td->td_cb, sizeof (*tp)); 78 if (ti) 79 td->td_ti = *ti; 80 else 81 bzero((caddr_t)&td->td_ti, sizeof (*ti)); 82 td->td_req = req; 83 #ifdef TCPDEBUG 84 if (tcpconsdebug == 0) 85 return; 86 if (tp) 87 printf("%x %s:", tp, tcpstates[ostate]); 88 else 89 printf("???????? "); 90 printf("%s ", tanames[act]); 91 switch (act) { 92 93 case TA_INPUT: 94 case TA_OUTPUT: 95 case TA_DROP: 96 if (ti == 0) 97 break; 98 seq = ti->ti_seq; 99 ack = ti->ti_ack; 100 len = ti->ti_len; 101 if (act == TA_OUTPUT) { 102 seq = ntohl(seq); 103 ack = ntohl(ack); 104 len = ntohs((u_short)len); 105 } 106 if (act == TA_OUTPUT) 107 len -= sizeof (struct tcphdr); 108 if (len) 109 printf("[%x..%x)", seq, seq+len); 110 else 111 printf("%x", seq); 112 printf("@%x, urp=%x", ack, ti->ti_urp); 113 flags = ti->ti_flags; 114 if (flags) { 115 #ifndef lint 116 char *cp = "<"; 117 #define pf(f) { if (ti->ti_flags&TH_/**/f) { printf("%s%s", cp, "f"); cp = ","; } } 118 pf(SYN); pf(ACK); pf(FIN); pf(RST); pf(PUSH); pf(URG); 119 #endif 120 printf(">"); 121 } 122 break; 123 124 case TA_USER: 125 printf("%s", prurequests[req&0xff]); 126 if ((req & 0xff) == PRU_SLOWTIMO) 127 printf("<%s>", tcptimers[req>>8]); 128 break; 129 } 130 if (tp) 131 printf(" -> %s", tcpstates[tp->t_state]); 132 /* print out internal state of tp !?! */ 133 printf("\n"); 134 if (tp == 0) 135 return; 136 printf("\trcv_(nxt,wnd,up) (%x,%x,%x) snd_(una,nxt,max) (%x,%x,%x)\n", 137 tp->rcv_nxt, tp->rcv_wnd, tp->rcv_up, tp->snd_una, tp->snd_nxt, 138 tp->snd_max); 139 printf("\tsnd_(wl1,wl2,wnd) (%x,%x,%x)\n", 140 tp->snd_wl1, tp->snd_wl2, tp->snd_wnd); 141 #endif /* TCPDEBUG */ 142 } 143