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