| 1 | #ifndef lint |
| 2 | static char sccsid[] = "@(#)trpt.c 4.5 83/01/18"; |
| 3 | #endif |
| 4 | |
| 5 | #include <sys/param.h> |
| 6 | #include <sys/socket.h> |
| 7 | #include <sys/socketvar.h> |
| 8 | #define PRUREQUESTS |
| 9 | #include <sys/protosw.h> |
| 10 | |
| 11 | #include <net/route.h> |
| 12 | #include <net/if.h> |
| 13 | |
| 14 | #include <netinet/in.h> |
| 15 | #include <netinet/in_pcb.h> |
| 16 | #include <netinet/in_systm.h> |
| 17 | #include <netinet/ip.h> |
| 18 | #include <netinet/ip_var.h> |
| 19 | #include <netinet/tcp.h> |
| 20 | #define TCPSTATES |
| 21 | #include <netinet/tcp_fsm.h> |
| 22 | #include <netinet/tcp_seq.h> |
| 23 | #define TCPTIMERS |
| 24 | #include <netinet/tcp_timer.h> |
| 25 | #include <netinet/tcp_var.h> |
| 26 | #include <netinet/tcpip.h> |
| 27 | #define TANAMES |
| 28 | #include <netinet/tcp_debug.h> |
| 29 | |
| 30 | #include <stdio.h> |
| 31 | #include <errno.h> |
| 32 | #include <nlist.h> |
| 33 | |
| 34 | n_time ntime; |
| 35 | int sflag; |
| 36 | struct nlist nl[] = { |
| 37 | { "_tcp_debug" }, |
| 38 | { "_tcp_debx" }, |
| 39 | 0 |
| 40 | }; |
| 41 | struct tcp_debug tcp_debug[TCP_NDEBUG]; |
| 42 | int tcp_debx; |
| 43 | |
| 44 | main(argc, argv) |
| 45 | int argc; |
| 46 | char **argv; |
| 47 | { |
| 48 | int i, mask = 0; |
| 49 | caddr_t tcpcb = 0; |
| 50 | char *system = "/vmunix", *core = "/dev/kmem"; |
| 51 | |
| 52 | argc--, argv++; |
| 53 | again: |
| 54 | if (argc > 0 && !strcmp(*argv, "-s")) { |
| 55 | sflag++, argc--, argv++; |
| 56 | goto again; |
| 57 | } |
| 58 | if (argc > 0 && !strcmp(*argv, "-p")) { |
| 59 | if (argc < 1) { |
| 60 | fprintf(stderr, "-p: missing tcpcb address\n"); |
| 61 | exit(1); |
| 62 | } |
| 63 | argc--, argv++; |
| 64 | sscanf(*argv, "%x", &tcpcb); |
| 65 | argc--, argv++; |
| 66 | goto again; |
| 67 | } |
| 68 | if (argc > 0) { |
| 69 | system = *argv; |
| 70 | argc--, argv++; |
| 71 | mask++; |
| 72 | } |
| 73 | if (argc > 0) { |
| 74 | core = *argv; |
| 75 | argc--, argv++; |
| 76 | mask++; |
| 77 | } |
| 78 | (void) nlist(system, nl); |
| 79 | if (nl[0].n_value == 0) { |
| 80 | fprintf(stderr, "trpt: %s: no namelist\n", system); |
| 81 | exit(1); |
| 82 | } |
| 83 | (void) close(0); |
| 84 | if (open(core, 0) < 0) { |
| 85 | fprintf(stderr, "trpt: "); perror(core); |
| 86 | exit(2); |
| 87 | } |
| 88 | if (mask) { |
| 89 | nl[0].n_value &= 0x7fffffff; |
| 90 | nl[1].n_value &= 0x7fffffff; |
| 91 | } |
| 92 | (void) lseek(0, nl[1].n_value, 0); |
| 93 | if (read(0, &tcp_debx, sizeof (tcp_debx)) != sizeof (tcp_debx)) { |
| 94 | fprintf(stderr, "trpt: "); perror("tcp_debx"); |
| 95 | exit(3); |
| 96 | } |
| 97 | printf("tcp_debx=%d\n", tcp_debx); |
| 98 | (void) lseek(0, nl[0].n_value, 0); |
| 99 | if (read(0, tcp_debug, sizeof (tcp_debug)) != sizeof (tcp_debug)) { |
| 100 | fprintf(stderr, "trpt: "); perror("tcp_debug"); |
| 101 | exit(3); |
| 102 | } |
| 103 | for (i = tcp_debx % TCP_NDEBUG; i < TCP_NDEBUG; i++) { |
| 104 | struct tcp_debug *td = &tcp_debug[i]; |
| 105 | |
| 106 | if (tcpcb && td->td_tcb != tcpcb) |
| 107 | continue; |
| 108 | ntime = ntohl(td->td_time); |
| 109 | tcp_trace(td->td_act, td->td_ostate, td->td_tcb, &td->td_cb, |
| 110 | &td->td_ti, td->td_req); |
| 111 | } |
| 112 | for (i = 0; i < tcp_debx % TCP_NDEBUG; i++) { |
| 113 | struct tcp_debug *td = &tcp_debug[i]; |
| 114 | |
| 115 | if (tcpcb && td->td_tcb != tcpcb) |
| 116 | continue; |
| 117 | ntime = ntohl(td->td_time); |
| 118 | tcp_trace(td->td_act, td->td_ostate, td->td_tcb, &td->td_cb, |
| 119 | &td->td_ti, td->td_req); |
| 120 | } |
| 121 | exit(0); |
| 122 | } |
| 123 | |
| 124 | /* |
| 125 | * Tcp debug routines |
| 126 | */ |
| 127 | tcp_trace(act, ostate, atp, tp, ti, req) |
| 128 | short act, ostate; |
| 129 | struct tcpcb *atp, *tp; |
| 130 | struct tcpiphdr *ti; |
| 131 | int req; |
| 132 | { |
| 133 | tcp_seq seq, ack; |
| 134 | int len, flags, win, timer; |
| 135 | char *cp; |
| 136 | |
| 137 | ptime(ntime); |
| 138 | printf("%x %s:%s ", ((int)atp)&0xfffff, |
| 139 | tcpstates[ostate], tanames[act]); |
| 140 | switch (act) { |
| 141 | |
| 142 | case TA_INPUT: |
| 143 | case TA_OUTPUT: |
| 144 | seq = ti->ti_seq; |
| 145 | ack = ti->ti_ack; |
| 146 | len = ti->ti_len; |
| 147 | win = ti->ti_win; |
| 148 | if (act == TA_OUTPUT) { |
| 149 | seq = ntohl(seq); |
| 150 | ack = ntohl(ack); |
| 151 | len = ntohs(len); |
| 152 | win = ntohs(win); |
| 153 | } |
| 154 | if (act == TA_OUTPUT) |
| 155 | len -= sizeof (struct tcphdr); |
| 156 | if (len) |
| 157 | printf("[%x..%x)", seq, seq+len); |
| 158 | else |
| 159 | printf("%x", seq); |
| 160 | printf("@%x", ack); |
| 161 | if (win) |
| 162 | printf("(win=%d)", win); |
| 163 | flags = ti->ti_flags; |
| 164 | if (flags) { |
| 165 | char *cp = "<"; |
| 166 | #define pf(f) { if (ti->ti_flags&TH_/**/f) { printf("%s%s", cp, "f"); cp = ","; } } |
| 167 | pf(SYN); pf(ACK); pf(FIN); pf(RST); pf(PUSH); pf(URG); |
| 168 | printf(">"); |
| 169 | } |
| 170 | break; |
| 171 | |
| 172 | case TA_USER: |
| 173 | timer = req >> 8; |
| 174 | req &= 0xff; |
| 175 | printf("%s", prurequests[req]); |
| 176 | if (req == PRU_SLOWTIMO || req == PRU_FASTTIMO) |
| 177 | printf("<%s>", tcptimers[timer]); |
| 178 | break; |
| 179 | } |
| 180 | printf(" -> %s", tcpstates[tp->t_state]); |
| 181 | /* print out internal state of tp !?! */ |
| 182 | printf("\n"); |
| 183 | if (sflag) { |
| 184 | printf("\trcv_nxt %x rcv_wnd %d snd_una %x snd_nxt %x snd_max %x\n", |
| 185 | tp->rcv_nxt, tp->rcv_wnd, tp->snd_una, tp->snd_nxt, |
| 186 | tp->snd_max); |
| 187 | printf("\tsnd_wl1 %x snd_wl2 %x snd_wnd %x\n", tp->snd_wl1, |
| 188 | tp->snd_wl2, tp->snd_wnd); |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | ptime(ms) |
| 193 | int ms; |
| 194 | { |
| 195 | |
| 196 | printf("%03d ", (ms/10) % 1000); |
| 197 | } |