123188Smckusick /* 2*29148Smckusick * Copyright (c) 1982, 1986 Regents of the University of California. 323188Smckusick * All rights reserved. The Berkeley software License Agreement 423188Smckusick * specifies the terms and conditions for redistribution. 523188Smckusick * 6*29148Smckusick * @(#)tcp_debug.c 7.1 (Berkeley) 06/05/86 723188Smckusick */ 85302Sroot 917062Sbloom #include "param.h" 1017062Sbloom #include "systm.h" 1117062Sbloom #include "mbuf.h" 1217062Sbloom #include "socket.h" 1317062Sbloom #include "socketvar.h" 145302Sroot #define PRUREQUESTS 1517062Sbloom #include "protosw.h" 1617062Sbloom #include "errno.h" 1710894Ssam 1810894Ssam #include "../net/route.h" 1910894Ssam #include "../net/if.h" 2010894Ssam 2117062Sbloom #include "in.h" 2217062Sbloom #include "in_pcb.h" 2317062Sbloom #include "in_systm.h" 2417062Sbloom #include "ip.h" 2517062Sbloom #include "ip_var.h" 2617062Sbloom #include "tcp.h" 275302Sroot #define TCPSTATES 2817062Sbloom #include "tcp_fsm.h" 2917062Sbloom #include "tcp_seq.h" 305302Sroot #define TCPTIMERS 3117062Sbloom #include "tcp_timer.h" 3217062Sbloom #include "tcp_var.h" 3317062Sbloom #include "tcpip.h" 345302Sroot #define TANAMES 3517062Sbloom #include "tcp_debug.h" 365302Sroot 375302Sroot int tcpconsdebug = 0; 385302Sroot /* 395302Sroot * Tcp debug routines 405302Sroot */ 415302Sroot tcp_trace(act, ostate, tp, ti, req) 425302Sroot short act, ostate; 435302Sroot struct tcpcb *tp; 445302Sroot struct tcpiphdr *ti; 455302Sroot int req; 465302Sroot { 475302Sroot tcp_seq seq, ack; 485302Sroot int len, flags; 495302Sroot struct tcp_debug *td = &tcp_debug[tcp_debx++]; 505302Sroot 515302Sroot if (tcp_debx == TCP_NDEBUG) 525302Sroot tcp_debx = 0; 535302Sroot td->td_time = iptime(); 545302Sroot td->td_act = act; 555302Sroot td->td_ostate = ostate; 565302Sroot td->td_tcb = (caddr_t)tp; 575302Sroot if (tp) 585302Sroot td->td_cb = *tp; 595302Sroot else 605302Sroot bzero((caddr_t)&td->td_cb, sizeof (*tp)); 615302Sroot if (ti) 625302Sroot td->td_ti = *ti; 635302Sroot else 645302Sroot bzero((caddr_t)&td->td_ti, sizeof (*ti)); 655302Sroot td->td_req = req; 665302Sroot if (tcpconsdebug == 0) 675302Sroot return; 685302Sroot if (tp) 695302Sroot printf("%x %s:", tp, tcpstates[ostate]); 705302Sroot else 715302Sroot printf("???????? "); 725302Sroot printf("%s ", tanames[act]); 735302Sroot switch (act) { 745302Sroot 755302Sroot case TA_INPUT: 765302Sroot case TA_OUTPUT: 7712440Ssam case TA_DROP: 7812440Ssam if (ti == 0) 7912440Ssam break; 805302Sroot seq = ti->ti_seq; 815302Sroot ack = ti->ti_ack; 825302Sroot len = ti->ti_len; 835302Sroot if (act == TA_OUTPUT) { 845302Sroot seq = ntohl(seq); 855302Sroot ack = ntohl(ack); 866161Ssam len = ntohs((u_short)len); 875302Sroot } 885302Sroot if (act == TA_OUTPUT) 895302Sroot len -= sizeof (struct tcphdr); 905302Sroot if (len) 915302Sroot printf("[%x..%x)", seq, seq+len); 925302Sroot else 935302Sroot printf("%x", seq); 9412440Ssam printf("@%x, urp=%x", ack, ti->ti_urp); 955302Sroot flags = ti->ti_flags; 965302Sroot if (flags) { 976161Ssam #ifndef lint 985302Sroot char *cp = "<"; 995302Sroot #define pf(f) { if (ti->ti_flags&TH_/**/f) { printf("%s%s", cp, "f"); cp = ","; } } 10012440Ssam pf(SYN); pf(ACK); pf(FIN); pf(RST); pf(PUSH); pf(URG); 1016161Ssam #endif 1025302Sroot printf(">"); 1035302Sroot } 1045302Sroot break; 1055302Sroot 1065302Sroot case TA_USER: 1075302Sroot printf("%s", prurequests[req&0xff]); 1085302Sroot if ((req & 0xff) == PRU_SLOWTIMO) 1095302Sroot printf("<%s>", tcptimers[req>>8]); 1105302Sroot break; 1115302Sroot } 1125302Sroot if (tp) 1135302Sroot printf(" -> %s", tcpstates[tp->t_state]); 1145302Sroot /* print out internal state of tp !?! */ 1155302Sroot printf("\n"); 1165302Sroot if (tp == 0) 1175302Sroot return; 11812440Ssam printf("\trcv_(nxt,wnd,up) (%x,%x,%x) snd_(una,nxt,max) (%x,%x,%x)\n", 11912440Ssam tp->rcv_nxt, tp->rcv_wnd, tp->rcv_up, tp->snd_una, tp->snd_nxt, 12012440Ssam tp->snd_max); 1215302Sroot printf("\tsnd_(wl1,wl2,wnd) (%x,%x,%x)\n", 1225302Sroot tp->snd_wl1, tp->snd_wl2, tp->snd_wnd); 1235302Sroot } 124