1 /*- 2 * Copyright (c) 1988, 1990 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 char copyright[] = 10 "@(#) Copyright (c) 1988, 1990 The Regents of the University of California.\n\ 11 All rights reserved.\n"; 12 #endif /* not lint */ 13 14 #ifndef lint 15 static char sccsid[] = "@(#)tpcb.c 7.2 (Berkeley) 07/23/92"; 16 #endif /* not lint */ 17 18 #include <sys/param.h> 19 #include <sys/mbuf.h> 20 #include <sys/socket.h> 21 #include <sys/socketvar.h> 22 #include <sys/ioctl.h> 23 #include <net/route.h> 24 #include <net/if.h> 25 #define TCPT_NTIMERS 4 26 #include <netiso/iso.h> 27 #include <netiso/tp_param.h> 28 #include <netiso/tp_user.h> 29 #include <netiso/tp_pcb.h> 30 #include <netiso/tp_events.h> 31 #include <netiso/tp_states.h> 32 33 #include <errno.h> 34 #include <netdb.h> 35 #include <nlist.h> 36 #include <kvm.h> 37 #include <paths.h> 38 #include <stdio.h> 39 /* 40 * This is a kernel debugging aid. 41 * dumps out a tp_pcb. 42 */ 43 #define mem(e) (((struct tp_pcb *)0)->e) 44 #define Offsetof(e) ((int)&mem(e)) 45 #define Sizeof(e) sizeof mem(e) 46 #if defined(__STDC__) || defined(__cplusplus) 47 #define Entry(n, e) { #n , Offsetof(e), Sizeof(e), } 48 #else 49 #define Entry(n, e) { "n" , Offsetof(e), Sizeof(e), } 50 #endif 51 struct tpcb_info { 52 char *name; 53 int offset; 54 int size; 55 } tpcb_info[]; 56 57 int tflag = 0; 58 int Iflag = 0; 59 int Aflag = 0; 60 int Sflag = 1; 61 62 char *vmunix = _PATH_UNIX; 63 char *kmemf = 0; 64 struct nlist nl[] = { 65 #define TP_REFINFO 0 66 {"_tp_refinfo"}, 67 0 68 }; 69 struct tp_pcb tp_pcb; 70 71 #define kget(p, d) \ 72 (kvm_read((void *)(p), &(d), sizeof (d))) 73 main(argc, argv) 74 int argc; 75 char **argv; 76 { 77 int loc, n; 78 char *end; 79 argc--; argv++; 80 if ((argc > 0) && strcmp("-k", argv[0]) == 0) { 81 vmunix = argv[1]; 82 kmemf = argv[2]; 83 argc -= 3; 84 argv += 3; 85 } 86 if (kvm_openfiles(vmunix, kmemf, NULL) == -1) { 87 fprintf(stderr, "tpcb: kvm_openfiles: %s\n", kvm_geterr()); 88 exit(1); 89 } 90 if (kvm_nlist(nl) < 0 || nl[0].n_type == 0) { 91 fprintf(stderr, "%s: no namelist\n", vmunix); 92 exit(1); 93 } 94 if (argc < 1) { 95 doall(nl[TP_REFINFO].n_value); 96 exit(0); 97 } 98 sscanf(argv[0], "%x", &loc); 99 n = kget(loc, tp_pcb); 100 parse(--argc, ++argv); 101 } 102 int column; 103 104 #define kdata(t) (data = *(t *)(ti->offset + (char *)&tp_pcb)) 105 106 doall(refinfo_off) 107 off_t refinfo_off; 108 { 109 struct tp_refinfo tp_refinfo; 110 register struct tp_pcb **tpp, **tpplim; 111 char *tpr_base, *malloc(); 112 int n; 113 114 kget(refinfo_off, tp_refinfo); 115 n = tp_refinfo.tpr_size * sizeof(struct tp_pcb *); 116 if (tp_refinfo.tpr_base && (tpr_base = malloc(n))) { 117 tpp = (struct tp_pcb **)tpr_base; 118 tpplim = tpp + tp_refinfo.tpr_maxopen; 119 bzero(tpr_base, n); 120 kvm_read(tp_refinfo.tpr_base, tpr_base, n); 121 for (n = 0; tpp <= tpplim; tpp++) 122 if (*tpp) { 123 n++; 124 kget(*tpp, tp_pcb); 125 if (Sflag == 0 || tp_pcb.tp_state == TP_OPEN) { 126 printf("\n\npcb at 0x%x:\n", *tpp); 127 parse(0, (char **)""); 128 } 129 } 130 if (n != tp_refinfo.tpr_numopen) 131 printf("\nFound %d of %d expected tpcb's\n", 132 n, tp_refinfo.tpr_numopen); 133 } 134 } 135 printone(ti) 136 register struct tpcb_info *ti; 137 { 138 int data = -1; 139 switch (ti->size) { 140 case 1: kdata(u_char); break; 141 case 2: kdata(u_short); break; 142 case 4: kdata(u_long); break; 143 } 144 column += printf("%s 0x%x, ", ti->name, data); 145 if (column > 65 || Sflag) { 146 column = 0; 147 putchar('\n'); 148 } 149 } 150 151 parse(argc, argv) 152 register int argc; 153 register char **argv; 154 { 155 register struct tpcb_info *ti; 156 column = 0; 157 if (argc > 0) { 158 for (; argc-- > 0; argv++) 159 for (ti = tpcb_info; ti->name; ti++) 160 if (strcmp(ti->name, *argv) == 0) { 161 printone(ti); 162 break; 163 } 164 } else 165 for (ti = tpcb_info; ti->name; ti++) 166 printone(ti); 167 } 168 169 struct tpcb_info tpcb_info[] = { 170 Entry(next, tp_next), 171 Entry(prev, tp_prev), 172 Entry(nextlisten, tp_nextlisten), 173 Entry(state, tp_state), 174 Entry(retrans, tp_retrans), 175 Entry(npcb, tp_npcb), 176 Entry(nlproto, tp_nlproto), 177 Entry(sock, tp_sock), 178 Entry(lref, tp_lref), 179 Entry(fref, tp_fref), 180 Entry(seqmask, tp_seqmask), 181 Entry(seqbit, tp_seqbit), 182 Entry(seqhalf, tp_seqhalf), 183 Entry(ucddata, tp_ucddata), 184 Entry(cebit_off, tp_cebit_off), 185 Entry(oktonagle, tp_oktonagle), 186 Entry(flags, tp_flags), 187 Entry(fcredit, tp_fcredit), 188 Entry(maxfcredit, tp_maxfcredit), 189 Entry(dupacks, tp_dupacks), 190 Entry(cong_win, tp_cong_win), 191 Entry(ssthresh, tp_ssthresh), 192 Entry(snduna, tp_snduna), 193 Entry(sndnew, tp_sndnew), 194 Entry(sndnum, tp_sndnum), 195 Entry(sndnxt, tp_sndnxt), 196 Entry(sndnxt_m, tp_sndnxt_m), 197 Entry(Nwindow, tp_Nwindow), 198 Entry(rcvnxt, tp_rcvnxt), 199 Entry(sent_lcdt, tp_sent_lcdt), 200 Entry(sent_uwe, tp_sent_uwe), 201 Entry(sent_rcvnxt, tp_sent_rcvnxt), 202 Entry(lcredit, tp_lcredit), 203 Entry(maxlcredit, tp_maxlcredit), 204 Entry(rhiwat, tp_rhiwat), 205 Entry(rsyq, tp_rsyq), 206 Entry(rsycnt, tp_rsycnt), 207 Entry(win_recv, tp_win_recv), 208 Entry(l_tpdusize, tp_l_tpdusize), 209 Entry(rtv, tp_rtv), 210 Entry(rtt, tp_rtt), 211 Entry(rttseq, tp_rttseq), 212 Entry(rttemit, tp_rttemit), 213 Entry(idle, tp_idle), 214 Entry(rxtcur, tp_rxtcur), 215 Entry(rxtshift, tp_rxtshift), 216 Entry(domain, tp_domain), 217 Entry(fsuffixlen, tp_fsuffixlen), 218 Entry(fsuffix, tp_fsuffix[0]), 219 Entry(lsuffixlen, tp_lsuffixlen), 220 Entry(lsuffix, tp_lsuffix[0]), 221 { "fport", Offsetof(tp_fsuffix[0]), sizeof(short), }, 222 { "lport", Offsetof(tp_lsuffix[0]), sizeof(short), }, 223 Entry(vers, tp_vers), 224 Entry(peer_acktime, tp_peer_acktime), 225 Entry(refstate, tp_refstate), 226 Entry(fasttimeo, tp_fasttimeo), 227 Entry(inact, tp_timer[TM_inact]), 228 Entry(retrans, tp_timer[TM_retrans]), 229 Entry(sendack, tp_timer[TM_sendack]), 230 Entry(data_retrans, tp_timer[TM_data_retrans]), 231 Entry(reference, tp_timer[TM_reference]), 232 Entry(Xsnd, tp_Xsnd), 233 Entry(Xsndnxt, tp_Xsndnxt), 234 Entry(Xuna, tp_Xuna), 235 Entry(Xrcvnxt, tp_Xrcvnxt), 236 Entry(s_subseq, tp_s_subseq), 237 Entry(r_subseq, tp_r_subseq), 238 Entry(dt_ticks, tp_dt_ticks), 239 Entry(inact_ticks, tp_inact_ticks), 240 Entry(keepalive_ticks, tp_keepalive_ticks), 241 Entry(cr_ticks, tp_cr_ticks), 242 Entry(xpd_ticks, tp_xpd_ticks), 243 0}; 244