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 this notice is preserved and that due credit is given 7 * to the University of California at Berkeley. The name of the University 8 * may not be used to endorse or promote products derived from this 9 * software without specific prior written permission. This software 10 * is provided ``as is'' without express or implied warranty. 11 * 12 * @(#)tcp_debug.c 7.2 (Berkeley) 12/07/87 13 */ 14 15 #include "param.h" 16 #include "systm.h" 17 #include "mbuf.h" 18 #include "socket.h" 19 #include "socketvar.h" 20 #define PRUREQUESTS 21 #include "protosw.h" 22 #include "errno.h" 23 24 #include "../net/route.h" 25 #include "../net/if.h" 26 27 #include "in.h" 28 #include "in_pcb.h" 29 #include "in_systm.h" 30 #include "ip.h" 31 #include "ip_var.h" 32 #include "tcp.h" 33 #define TCPSTATES 34 #include "tcp_fsm.h" 35 #include "tcp_seq.h" 36 #define TCPTIMERS 37 #include "tcp_timer.h" 38 #include "tcp_var.h" 39 #include "tcpip.h" 40 #define TANAMES 41 #include "tcp_debug.h" 42 43 int tcpconsdebug = 0; 44 /* 45 * Tcp debug routines 46 */ 47 tcp_trace(act, ostate, tp, ti, req) 48 short act, ostate; 49 struct tcpcb *tp; 50 struct tcpiphdr *ti; 51 int req; 52 { 53 tcp_seq seq, ack; 54 int len, flags; 55 struct tcp_debug *td = &tcp_debug[tcp_debx++]; 56 57 if (tcp_debx == TCP_NDEBUG) 58 tcp_debx = 0; 59 td->td_time = iptime(); 60 td->td_act = act; 61 td->td_ostate = ostate; 62 td->td_tcb = (caddr_t)tp; 63 if (tp) 64 td->td_cb = *tp; 65 else 66 bzero((caddr_t)&td->td_cb, sizeof (*tp)); 67 if (ti) 68 td->td_ti = *ti; 69 else 70 bzero((caddr_t)&td->td_ti, sizeof (*ti)); 71 td->td_req = req; 72 if (tcpconsdebug == 0) 73 return; 74 if (tp) 75 printf("%x %s:", tp, tcpstates[ostate]); 76 else 77 printf("???????? "); 78 printf("%s ", tanames[act]); 79 switch (act) { 80 81 case TA_INPUT: 82 case TA_OUTPUT: 83 case TA_DROP: 84 if (ti == 0) 85 break; 86 seq = ti->ti_seq; 87 ack = ti->ti_ack; 88 len = ti->ti_len; 89 if (act == TA_OUTPUT) { 90 seq = ntohl(seq); 91 ack = ntohl(ack); 92 len = ntohs((u_short)len); 93 } 94 if (act == TA_OUTPUT) 95 len -= sizeof (struct tcphdr); 96 if (len) 97 printf("[%x..%x)", seq, seq+len); 98 else 99 printf("%x", seq); 100 printf("@%x, urp=%x", ack, ti->ti_urp); 101 flags = ti->ti_flags; 102 if (flags) { 103 #ifndef lint 104 char *cp = "<"; 105 #define pf(f) { if (ti->ti_flags&TH_/**/f) { printf("%s%s", cp, "f"); cp = ","; } } 106 pf(SYN); pf(ACK); pf(FIN); pf(RST); pf(PUSH); pf(URG); 107 #endif 108 printf(">"); 109 } 110 break; 111 112 case TA_USER: 113 printf("%s", prurequests[req&0xff]); 114 if ((req & 0xff) == PRU_SLOWTIMO) 115 printf("<%s>", tcptimers[req>>8]); 116 break; 117 } 118 if (tp) 119 printf(" -> %s", tcpstates[tp->t_state]); 120 /* print out internal state of tp !?! */ 121 printf("\n"); 122 if (tp == 0) 123 return; 124 printf("\trcv_(nxt,wnd,up) (%x,%x,%x) snd_(una,nxt,max) (%x,%x,%x)\n", 125 tp->rcv_nxt, tp->rcv_wnd, tp->rcv_up, tp->snd_una, tp->snd_nxt, 126 tp->snd_max); 127 printf("\tsnd_(wl1,wl2,wnd) (%x,%x,%x)\n", 128 tp->snd_wl1, tp->snd_wl2, tp->snd_wnd); 129 } 130