1*5302Sroot /* tcp_debug.c 4.1 81/12/22 */ 2*5302Sroot 3*5302Sroot #include "../h/param.h" 4*5302Sroot #include "../h/systm.h" 5*5302Sroot #include "../h/mbuf.h" 6*5302Sroot #include "../h/socket.h" 7*5302Sroot #include "../h/socketvar.h" 8*5302Sroot #define PRUREQUESTS 9*5302Sroot #include "../h/protosw.h" 10*5302Sroot #include "../net/in.h" 11*5302Sroot #include "../net/in_pcb.h" 12*5302Sroot #include "../net/in_systm.h" 13*5302Sroot #include "../net/if.h" 14*5302Sroot #include "../net/ip.h" 15*5302Sroot #include "../net/ip_var.h" 16*5302Sroot #include "../net/tcp.h" 17*5302Sroot #define TCPSTATES 18*5302Sroot #include "../net/tcp_fsm.h" 19*5302Sroot #include "../net/tcp_seq.h" 20*5302Sroot #define TCPTIMERS 21*5302Sroot #include "../net/tcp_timer.h" 22*5302Sroot #include "../net/tcp_var.h" 23*5302Sroot #include "../net/tcpip.h" 24*5302Sroot #define TANAMES 25*5302Sroot #include "../net/tcp_debug.h" 26*5302Sroot #include "../errno.h" 27*5302Sroot 28*5302Sroot int tcpconsdebug = 0; 29*5302Sroot /* 30*5302Sroot * Tcp debug routines 31*5302Sroot */ 32*5302Sroot tcp_trace(act, ostate, tp, ti, req) 33*5302Sroot short act, ostate; 34*5302Sroot struct tcpcb *tp; 35*5302Sroot struct tcpiphdr *ti; 36*5302Sroot int req; 37*5302Sroot { 38*5302Sroot tcp_seq seq, ack; 39*5302Sroot int len, flags; 40*5302Sroot char *cp; 41*5302Sroot struct tcp_debug *td = &tcp_debug[tcp_debx++]; 42*5302Sroot 43*5302Sroot if (tcp_debx == TCP_NDEBUG) 44*5302Sroot tcp_debx = 0; 45*5302Sroot td->td_time = iptime(); 46*5302Sroot td->td_act = act; 47*5302Sroot td->td_ostate = ostate; 48*5302Sroot td->td_tcb = (caddr_t)tp; 49*5302Sroot if (tp) 50*5302Sroot td->td_cb = *tp; 51*5302Sroot else 52*5302Sroot bzero((caddr_t)&td->td_cb, sizeof (*tp)); 53*5302Sroot if (ti) 54*5302Sroot td->td_ti = *ti; 55*5302Sroot else 56*5302Sroot bzero((caddr_t)&td->td_ti, sizeof (*ti)); 57*5302Sroot td->td_req = req; 58*5302Sroot if (tcpconsdebug == 0) 59*5302Sroot return; 60*5302Sroot if (tp) 61*5302Sroot printf("%x %s:", tp, tcpstates[ostate]); 62*5302Sroot else 63*5302Sroot printf("???????? "); 64*5302Sroot printf("%s ", tanames[act]); 65*5302Sroot switch (act) { 66*5302Sroot 67*5302Sroot case TA_INPUT: 68*5302Sroot case TA_OUTPUT: 69*5302Sroot seq = ti->ti_seq; 70*5302Sroot ack = ti->ti_ack; 71*5302Sroot len = ti->ti_len; 72*5302Sroot #if vax 73*5302Sroot if (act == TA_OUTPUT) { 74*5302Sroot seq = ntohl(seq); 75*5302Sroot ack = ntohl(ack); 76*5302Sroot len = ntohs(len); 77*5302Sroot } 78*5302Sroot #endif 79*5302Sroot if (act == TA_OUTPUT) 80*5302Sroot len -= sizeof (struct tcphdr); 81*5302Sroot if (len) 82*5302Sroot printf("[%x..%x)", seq, seq+len); 83*5302Sroot else 84*5302Sroot printf("%x", seq); 85*5302Sroot printf("@%x", ack); 86*5302Sroot flags = ti->ti_flags; 87*5302Sroot if (flags) { 88*5302Sroot char *cp = "<"; 89*5302Sroot #define pf(f) { if (ti->ti_flags&TH_/**/f) { printf("%s%s", cp, "f"); cp = ","; } } 90*5302Sroot pf(SYN); pf(ACK); pf(FIN); pf(RST); 91*5302Sroot printf(">"); 92*5302Sroot } 93*5302Sroot break; 94*5302Sroot 95*5302Sroot case TA_USER: 96*5302Sroot printf("%s", prurequests[req&0xff]); 97*5302Sroot if ((req & 0xff) == PRU_SLOWTIMO) 98*5302Sroot printf("<%s>", tcptimers[req>>8]); 99*5302Sroot break; 100*5302Sroot } 101*5302Sroot if (tp) 102*5302Sroot printf(" -> %s", tcpstates[tp->t_state]); 103*5302Sroot /* print out internal state of tp !?! */ 104*5302Sroot printf("\n"); 105*5302Sroot if (tp == 0) 106*5302Sroot return; 107*5302Sroot printf("\trcv_(nxt,wnd) (%x,%x) snd_(una,nxt,max) (%x,%x,%x)\n", 108*5302Sroot tp->rcv_nxt, tp->rcv_wnd, tp->snd_una, tp->snd_nxt, tp->snd_max); 109*5302Sroot printf("\tsnd_(wl1,wl2,wnd) (%x,%x,%x)\n", 110*5302Sroot tp->snd_wl1, tp->snd_wl2, tp->snd_wnd); 111*5302Sroot } 112