123188Smckusick /* 229148Smckusick * Copyright (c) 1982, 1986 Regents of the University of California. 332787Sbostic * All rights reserved. 423188Smckusick * 532787Sbostic * Redistribution and use in source and binary forms are permitted 634854Sbostic * provided that the above copyright notice and this paragraph are 734854Sbostic * duplicated in all such forms and that any documentation, 834854Sbostic * advertising materials, and other materials related to such 934854Sbostic * distribution and use acknowledge that the software was developed 1034854Sbostic * by the University of California, Berkeley. The name of the 1134854Sbostic * University may not be used to endorse or promote products derived 1234854Sbostic * from this software without specific prior written permission. 1334854Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 1434854Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 1534854Sbostic * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1632787Sbostic * 17*44374Skarels * @(#)tcp_debug.c 7.5 (Berkeley) 06/28/90 1823188Smckusick */ 195302Sroot 20*44374Skarels #ifdef TCPDEBUG 21*44374Skarels /* load symbolic names */ 22*44374Skarels #define PRUREQUESTS 23*44374Skarels #define TCPSTATES 24*44374Skarels #define TCPTIMERS 25*44374Skarels #define TANAMES 26*44374Skarels #endif 27*44374Skarels 2817062Sbloom #include "param.h" 2917062Sbloom #include "systm.h" 3017062Sbloom #include "mbuf.h" 3117062Sbloom #include "socket.h" 3217062Sbloom #include "socketvar.h" 3317062Sbloom #include "protosw.h" 3417062Sbloom #include "errno.h" 3510894Ssam 3610894Ssam #include "../net/route.h" 3710894Ssam #include "../net/if.h" 3810894Ssam 3917062Sbloom #include "in.h" 4017062Sbloom #include "in_systm.h" 4117062Sbloom #include "ip.h" 4240690Skarels #include "in_pcb.h" 4317062Sbloom #include "ip_var.h" 4417062Sbloom #include "tcp.h" 4517062Sbloom #include "tcp_fsm.h" 4617062Sbloom #include "tcp_seq.h" 4717062Sbloom #include "tcp_timer.h" 4817062Sbloom #include "tcp_var.h" 4917062Sbloom #include "tcpip.h" 5017062Sbloom #include "tcp_debug.h" 515302Sroot 52*44374Skarels #ifdef TCPDEBUG 535302Sroot int tcpconsdebug = 0; 54*44374Skarels #endif 555302Sroot /* 565302Sroot * Tcp debug routines 575302Sroot */ 585302Sroot tcp_trace(act, ostate, tp, ti, req) 595302Sroot short act, ostate; 605302Sroot struct tcpcb *tp; 615302Sroot struct tcpiphdr *ti; 625302Sroot int req; 635302Sroot { 645302Sroot tcp_seq seq, ack; 655302Sroot int len, flags; 665302Sroot struct tcp_debug *td = &tcp_debug[tcp_debx++]; 675302Sroot 685302Sroot if (tcp_debx == TCP_NDEBUG) 695302Sroot tcp_debx = 0; 705302Sroot td->td_time = iptime(); 715302Sroot td->td_act = act; 725302Sroot td->td_ostate = ostate; 735302Sroot td->td_tcb = (caddr_t)tp; 745302Sroot if (tp) 755302Sroot td->td_cb = *tp; 765302Sroot else 775302Sroot bzero((caddr_t)&td->td_cb, sizeof (*tp)); 785302Sroot if (ti) 795302Sroot td->td_ti = *ti; 805302Sroot else 815302Sroot bzero((caddr_t)&td->td_ti, sizeof (*ti)); 825302Sroot td->td_req = req; 83*44374Skarels #ifdef TCPDEBUG 845302Sroot if (tcpconsdebug == 0) 855302Sroot return; 865302Sroot if (tp) 875302Sroot printf("%x %s:", tp, tcpstates[ostate]); 885302Sroot else 895302Sroot printf("???????? "); 905302Sroot printf("%s ", tanames[act]); 915302Sroot switch (act) { 925302Sroot 935302Sroot case TA_INPUT: 945302Sroot case TA_OUTPUT: 9512440Ssam case TA_DROP: 9612440Ssam if (ti == 0) 9712440Ssam break; 985302Sroot seq = ti->ti_seq; 995302Sroot ack = ti->ti_ack; 1005302Sroot len = ti->ti_len; 1015302Sroot if (act == TA_OUTPUT) { 1025302Sroot seq = ntohl(seq); 1035302Sroot ack = ntohl(ack); 1046161Ssam len = ntohs((u_short)len); 1055302Sroot } 1065302Sroot if (act == TA_OUTPUT) 1075302Sroot len -= sizeof (struct tcphdr); 1085302Sroot if (len) 1095302Sroot printf("[%x..%x)", seq, seq+len); 1105302Sroot else 1115302Sroot printf("%x", seq); 11212440Ssam printf("@%x, urp=%x", ack, ti->ti_urp); 1135302Sroot flags = ti->ti_flags; 1145302Sroot if (flags) { 1156161Ssam #ifndef lint 1165302Sroot char *cp = "<"; 1175302Sroot #define pf(f) { if (ti->ti_flags&TH_/**/f) { printf("%s%s", cp, "f"); cp = ","; } } 11812440Ssam pf(SYN); pf(ACK); pf(FIN); pf(RST); pf(PUSH); pf(URG); 1196161Ssam #endif 1205302Sroot printf(">"); 1215302Sroot } 1225302Sroot break; 1235302Sroot 1245302Sroot case TA_USER: 1255302Sroot printf("%s", prurequests[req&0xff]); 1265302Sroot if ((req & 0xff) == PRU_SLOWTIMO) 1275302Sroot printf("<%s>", tcptimers[req>>8]); 1285302Sroot break; 1295302Sroot } 1305302Sroot if (tp) 1315302Sroot printf(" -> %s", tcpstates[tp->t_state]); 1325302Sroot /* print out internal state of tp !?! */ 1335302Sroot printf("\n"); 1345302Sroot if (tp == 0) 1355302Sroot return; 13612440Ssam printf("\trcv_(nxt,wnd,up) (%x,%x,%x) snd_(una,nxt,max) (%x,%x,%x)\n", 13712440Ssam tp->rcv_nxt, tp->rcv_wnd, tp->rcv_up, tp->snd_una, tp->snd_nxt, 13812440Ssam tp->snd_max); 1395302Sroot printf("\tsnd_(wl1,wl2,wnd) (%x,%x,%x)\n", 1405302Sroot tp->snd_wl1, tp->snd_wl2, tp->snd_wnd); 141*44374Skarels #endif /* TCPDEBUG */ 1425302Sroot } 143