1*10894Ssam /* tcp_debug.c 4.9 83/02/10 */ 25302Sroot 35302Sroot #include "../h/param.h" 45302Sroot #include "../h/systm.h" 55302Sroot #include "../h/mbuf.h" 65302Sroot #include "../h/socket.h" 75302Sroot #include "../h/socketvar.h" 85302Sroot #define PRUREQUESTS 95302Sroot #include "../h/protosw.h" 10*10894Ssam #include "../h/errno.h" 11*10894Ssam 12*10894Ssam #include "../net/route.h" 13*10894Ssam #include "../net/if.h" 14*10894Ssam 158401Swnj #include "../netinet/in.h" 168401Swnj #include "../netinet/in_pcb.h" 178401Swnj #include "../netinet/in_systm.h" 188401Swnj #include "../netinet/ip.h" 198401Swnj #include "../netinet/ip_var.h" 208401Swnj #include "../netinet/tcp.h" 215302Sroot #define TCPSTATES 228401Swnj #include "../netinet/tcp_fsm.h" 238401Swnj #include "../netinet/tcp_seq.h" 245302Sroot #define TCPTIMERS 258401Swnj #include "../netinet/tcp_timer.h" 268401Swnj #include "../netinet/tcp_var.h" 278401Swnj #include "../netinet/tcpip.h" 285302Sroot #define TANAMES 298401Swnj #include "../netinet/tcp_debug.h" 305302Sroot 315302Sroot int tcpconsdebug = 0; 325302Sroot /* 335302Sroot * Tcp debug routines 345302Sroot */ 355302Sroot tcp_trace(act, ostate, tp, ti, req) 365302Sroot short act, ostate; 375302Sroot struct tcpcb *tp; 385302Sroot struct tcpiphdr *ti; 395302Sroot int req; 405302Sroot { 415302Sroot tcp_seq seq, ack; 425302Sroot int len, flags; 435302Sroot struct tcp_debug *td = &tcp_debug[tcp_debx++]; 445302Sroot 455302Sroot if (tcp_debx == TCP_NDEBUG) 465302Sroot tcp_debx = 0; 475302Sroot td->td_time = iptime(); 485302Sroot td->td_act = act; 495302Sroot td->td_ostate = ostate; 505302Sroot td->td_tcb = (caddr_t)tp; 515302Sroot if (tp) 525302Sroot td->td_cb = *tp; 535302Sroot else 545302Sroot bzero((caddr_t)&td->td_cb, sizeof (*tp)); 555302Sroot if (ti) 565302Sroot td->td_ti = *ti; 575302Sroot else 585302Sroot bzero((caddr_t)&td->td_ti, sizeof (*ti)); 595302Sroot td->td_req = req; 605302Sroot if (tcpconsdebug == 0) 615302Sroot return; 625302Sroot if (tp) 635302Sroot printf("%x %s:", tp, tcpstates[ostate]); 645302Sroot else 655302Sroot printf("???????? "); 665302Sroot printf("%s ", tanames[act]); 675302Sroot switch (act) { 685302Sroot 695302Sroot case TA_INPUT: 705302Sroot case TA_OUTPUT: 715302Sroot seq = ti->ti_seq; 725302Sroot ack = ti->ti_ack; 735302Sroot len = ti->ti_len; 745302Sroot if (act == TA_OUTPUT) { 755302Sroot seq = ntohl(seq); 765302Sroot ack = ntohl(ack); 776161Ssam len = ntohs((u_short)len); 785302Sroot } 795302Sroot if (act == TA_OUTPUT) 805302Sroot len -= sizeof (struct tcphdr); 815302Sroot if (len) 825302Sroot printf("[%x..%x)", seq, seq+len); 835302Sroot else 845302Sroot printf("%x", seq); 855302Sroot printf("@%x", ack); 865302Sroot flags = ti->ti_flags; 875302Sroot if (flags) { 886161Ssam #ifndef lint 895302Sroot char *cp = "<"; 905302Sroot #define pf(f) { if (ti->ti_flags&TH_/**/f) { printf("%s%s", cp, "f"); cp = ","; } } 915302Sroot pf(SYN); pf(ACK); pf(FIN); pf(RST); 926161Ssam #endif 935302Sroot printf(">"); 945302Sroot } 955302Sroot break; 965302Sroot 975302Sroot case TA_USER: 985302Sroot printf("%s", prurequests[req&0xff]); 995302Sroot if ((req & 0xff) == PRU_SLOWTIMO) 1005302Sroot printf("<%s>", tcptimers[req>>8]); 1015302Sroot break; 1025302Sroot } 1035302Sroot if (tp) 1045302Sroot printf(" -> %s", tcpstates[tp->t_state]); 1055302Sroot /* print out internal state of tp !?! */ 1065302Sroot printf("\n"); 1075302Sroot if (tp == 0) 1085302Sroot return; 1095302Sroot printf("\trcv_(nxt,wnd) (%x,%x) snd_(una,nxt,max) (%x,%x,%x)\n", 1105302Sroot tp->rcv_nxt, tp->rcv_wnd, tp->snd_una, tp->snd_nxt, tp->snd_max); 1115302Sroot printf("\tsnd_(wl1,wl2,wnd) (%x,%x,%x)\n", 1125302Sroot tp->snd_wl1, tp->snd_wl2, tp->snd_wnd); 1135302Sroot } 114