Commit | Line | Data |
---|---|---|
4a4b11be KS |
1 | /*- |
2 | * Copyright (c) 1988, 1990 The Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
ad787160 C |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions | |
7 | * are met: | |
8 | * 1. Redistributions of source code must retain the above copyright | |
9 | * notice, this list of conditions and the following disclaimer. | |
10 | * 2. Redistributions in binary form must reproduce the above copyright | |
11 | * notice, this list of conditions and the following disclaimer in the | |
12 | * documentation and/or other materials provided with the distribution. | |
13 | * 3. All advertising materials mentioning features or use of this software | |
14 | * must display the following acknowledgement: | |
15 | * This product includes software developed by the University of | |
16 | * California, Berkeley and its contributors. | |
17 | * 4. Neither the name of the University nor the names of its contributors | |
18 | * may be used to endorse or promote products derived from this software | |
19 | * without specific prior written permission. | |
20 | * | |
21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
31 | * SUCH DAMAGE. | |
4a4b11be KS |
32 | */ |
33 | ||
34 | #ifndef lint | |
35 | char copyright[] = | |
36 | "@(#) Copyright (c) 1988, 1990 The Regents of the University of California.\n\ | |
37 | All rights reserved.\n"; | |
38 | #endif /* not lint */ | |
39 | ||
40 | #ifndef lint | |
ad787160 | 41 | static char sccsid[] = "@(#)tpcb.c 7.2 (Berkeley) 7/23/92"; |
4a4b11be KS |
42 | #endif /* not lint */ |
43 | ||
44 | #include <sys/param.h> | |
45 | #include <sys/mbuf.h> | |
46 | #include <sys/socket.h> | |
47 | #include <sys/socketvar.h> | |
48 | #include <sys/ioctl.h> | |
49 | #include <net/route.h> | |
50 | #include <net/if.h> | |
51 | #define TCPT_NTIMERS 4 | |
52 | #include <netiso/iso.h> | |
53 | #include <netiso/tp_param.h> | |
54 | #include <netiso/tp_user.h> | |
55 | #include <netiso/tp_pcb.h> | |
56 | #include <netiso/tp_events.h> | |
8aa4bb3a | 57 | #include <netiso/tp_states.h> |
4a4b11be KS |
58 | |
59 | #include <errno.h> | |
60 | #include <netdb.h> | |
61 | #include <nlist.h> | |
62 | #include <kvm.h> | |
63 | #include <paths.h> | |
64 | #include <stdio.h> | |
65 | /* | |
66 | * This is a kernel debugging aid. | |
67 | * dumps out a tp_pcb. | |
68 | */ | |
69 | #define mem(e) (((struct tp_pcb *)0)->e) | |
70 | #define Offsetof(e) ((int)&mem(e)) | |
71 | #define Sizeof(e) sizeof mem(e) | |
72 | #if defined(__STDC__) || defined(__cplusplus) | |
73 | #define Entry(n, e) { #n , Offsetof(e), Sizeof(e), } | |
74 | #else | |
75 | #define Entry(n, e) { "n" , Offsetof(e), Sizeof(e), } | |
76 | #endif | |
77 | struct tpcb_info { | |
78 | char *name; | |
79 | int offset; | |
80 | int size; | |
81 | } tpcb_info[]; | |
82 | ||
83 | int tflag = 0; | |
84 | int Iflag = 0; | |
85 | int Aflag = 0; | |
8aa4bb3a | 86 | int Sflag = 1; |
4a4b11be KS |
87 | |
88 | char *vmunix = _PATH_UNIX; | |
89 | char *kmemf = 0; | |
90 | struct nlist nl[] = { | |
8aa4bb3a | 91 | #define TP_REFINFO 0 |
4a4b11be KS |
92 | {"_tp_refinfo"}, |
93 | 0 | |
94 | }; | |
95 | struct tp_pcb tp_pcb; | |
96 | ||
97 | #define kget(p, d) \ | |
98 | (kvm_read((void *)(p), &(d), sizeof (d))) | |
99 | main(argc, argv) | |
100 | int argc; | |
101 | char **argv; | |
102 | { | |
103 | int loc, n; | |
104 | char *end; | |
105 | argc--; argv++; | |
8aa4bb3a | 106 | if ((argc > 0) && strcmp("-k", argv[0]) == 0) { |
4a4b11be KS |
107 | vmunix = argv[1]; |
108 | kmemf = argv[2]; | |
109 | argc -= 3; | |
110 | argv += 3; | |
111 | } | |
112 | if (kvm_openfiles(vmunix, kmemf, NULL) == -1) { | |
113 | fprintf(stderr, "tpcb: kvm_openfiles: %s\n", kvm_geterr()); | |
114 | exit(1); | |
115 | } | |
116 | if (kvm_nlist(nl) < 0 || nl[0].n_type == 0) { | |
117 | fprintf(stderr, "%s: no namelist\n", vmunix); | |
118 | exit(1); | |
119 | } | |
120 | if (argc < 1) { | |
8aa4bb3a KS |
121 | doall(nl[TP_REFINFO].n_value); |
122 | exit(0); | |
4a4b11be KS |
123 | } |
124 | sscanf(argv[0], "%x", &loc); | |
125 | n = kget(loc, tp_pcb); | |
126 | parse(--argc, ++argv); | |
127 | } | |
8aa4bb3a | 128 | int column; |
4a4b11be KS |
129 | |
130 | #define kdata(t) (data = *(t *)(ti->offset + (char *)&tp_pcb)) | |
131 | ||
8aa4bb3a KS |
132 | doall(refinfo_off) |
133 | off_t refinfo_off; | |
134 | { | |
135 | struct tp_refinfo tp_refinfo; | |
136 | register struct tp_pcb **tpp, **tpplim; | |
137 | char *tpr_base, *malloc(); | |
138 | int n; | |
139 | ||
140 | kget(refinfo_off, tp_refinfo); | |
141 | n = tp_refinfo.tpr_size * sizeof(struct tp_pcb *); | |
142 | if (tp_refinfo.tpr_base && (tpr_base = malloc(n))) { | |
143 | tpp = (struct tp_pcb **)tpr_base; | |
144 | tpplim = tpp + tp_refinfo.tpr_maxopen; | |
145 | bzero(tpr_base, n); | |
146 | kvm_read(tp_refinfo.tpr_base, tpr_base, n); | |
147 | for (n = 0; tpp <= tpplim; tpp++) | |
148 | if (*tpp) { | |
149 | n++; | |
150 | kget(*tpp, tp_pcb); | |
151 | if (Sflag == 0 || tp_pcb.tp_state == TP_OPEN) { | |
152 | printf("\n\npcb at 0x%x:\n", *tpp); | |
153 | parse(0, (char **)""); | |
154 | } | |
155 | } | |
156 | if (n != tp_refinfo.tpr_numopen) | |
157 | printf("\nFound %d of %d expected tpcb's\n", | |
158 | n, tp_refinfo.tpr_numopen); | |
159 | } | |
160 | } | |
4a4b11be KS |
161 | printone(ti) |
162 | register struct tpcb_info *ti; | |
163 | { | |
8aa4bb3a | 164 | int data = -1; |
4a4b11be KS |
165 | switch (ti->size) { |
166 | case 1: kdata(u_char); break; | |
167 | case 2: kdata(u_short); break; | |
168 | case 4: kdata(u_long); break; | |
169 | } | |
170 | column += printf("%s 0x%x, ", ti->name, data); | |
8aa4bb3a | 171 | if (column > 65 || Sflag) { |
4a4b11be KS |
172 | column = 0; |
173 | putchar('\n'); | |
174 | } | |
175 | } | |
176 | ||
177 | parse(argc, argv) | |
178 | register int argc; | |
179 | register char **argv; | |
180 | { | |
181 | register struct tpcb_info *ti; | |
8aa4bb3a | 182 | column = 0; |
4a4b11be KS |
183 | if (argc > 0) { |
184 | for (; argc-- > 0; argv++) | |
185 | for (ti = tpcb_info; ti->name; ti++) | |
186 | if (strcmp(ti->name, *argv) == 0) { | |
187 | printone(ti); | |
188 | break; | |
189 | } | |
190 | } else | |
191 | for (ti = tpcb_info; ti->name; ti++) | |
192 | printone(ti); | |
193 | } | |
194 | ||
195 | struct tpcb_info tpcb_info[] = { | |
196 | Entry(next, tp_next), | |
197 | Entry(prev, tp_prev), | |
198 | Entry(nextlisten, tp_nextlisten), | |
199 | Entry(state, tp_state), | |
200 | Entry(retrans, tp_retrans), | |
201 | Entry(npcb, tp_npcb), | |
202 | Entry(nlproto, tp_nlproto), | |
203 | Entry(sock, tp_sock), | |
204 | Entry(lref, tp_lref), | |
205 | Entry(fref, tp_fref), | |
206 | Entry(seqmask, tp_seqmask), | |
207 | Entry(seqbit, tp_seqbit), | |
208 | Entry(seqhalf, tp_seqhalf), | |
209 | Entry(ucddata, tp_ucddata), | |
8aa4bb3a KS |
210 | Entry(cebit_off, tp_cebit_off), |
211 | Entry(oktonagle, tp_oktonagle), | |
212 | Entry(flags, tp_flags), | |
4a4b11be KS |
213 | Entry(fcredit, tp_fcredit), |
214 | Entry(maxfcredit, tp_maxfcredit), | |
215 | Entry(dupacks, tp_dupacks), | |
216 | Entry(cong_win, tp_cong_win), | |
217 | Entry(ssthresh, tp_ssthresh), | |
218 | Entry(snduna, tp_snduna), | |
219 | Entry(sndnew, tp_sndnew), | |
220 | Entry(sndnum, tp_sndnum), | |
221 | Entry(sndnxt, tp_sndnxt), | |
222 | Entry(sndnxt_m, tp_sndnxt_m), | |
223 | Entry(Nwindow, tp_Nwindow), | |
224 | Entry(rcvnxt, tp_rcvnxt), | |
225 | Entry(sent_lcdt, tp_sent_lcdt), | |
226 | Entry(sent_uwe, tp_sent_uwe), | |
227 | Entry(sent_rcvnxt, tp_sent_rcvnxt), | |
228 | Entry(lcredit, tp_lcredit), | |
229 | Entry(maxlcredit, tp_maxlcredit), | |
8aa4bb3a | 230 | Entry(rhiwat, tp_rhiwat), |
4a4b11be KS |
231 | Entry(rsyq, tp_rsyq), |
232 | Entry(rsycnt, tp_rsycnt), | |
233 | Entry(win_recv, tp_win_recv), | |
234 | Entry(l_tpdusize, tp_l_tpdusize), | |
235 | Entry(rtv, tp_rtv), | |
236 | Entry(rtt, tp_rtt), | |
237 | Entry(rttseq, tp_rttseq), | |
238 | Entry(rttemit, tp_rttemit), | |
239 | Entry(idle, tp_idle), | |
240 | Entry(rxtcur, tp_rxtcur), | |
241 | Entry(rxtshift, tp_rxtshift), | |
242 | Entry(domain, tp_domain), | |
243 | Entry(fsuffixlen, tp_fsuffixlen), | |
244 | Entry(fsuffix, tp_fsuffix[0]), | |
245 | Entry(lsuffixlen, tp_lsuffixlen), | |
246 | Entry(lsuffix, tp_lsuffix[0]), | |
247 | { "fport", Offsetof(tp_fsuffix[0]), sizeof(short), }, | |
248 | { "lport", Offsetof(tp_lsuffix[0]), sizeof(short), }, | |
249 | Entry(vers, tp_vers), | |
250 | Entry(peer_acktime, tp_peer_acktime), | |
251 | Entry(refstate, tp_refstate), | |
252 | Entry(fasttimeo, tp_fasttimeo), | |
253 | Entry(inact, tp_timer[TM_inact]), | |
254 | Entry(retrans, tp_timer[TM_retrans]), | |
255 | Entry(sendack, tp_timer[TM_sendack]), | |
256 | Entry(data_retrans, tp_timer[TM_data_retrans]), | |
257 | Entry(reference, tp_timer[TM_reference]), | |
258 | Entry(Xsnd, tp_Xsnd), | |
259 | Entry(Xsndnxt, tp_Xsndnxt), | |
260 | Entry(Xuna, tp_Xuna), | |
261 | Entry(Xrcvnxt, tp_Xrcvnxt), | |
262 | Entry(s_subseq, tp_s_subseq), | |
263 | Entry(r_subseq, tp_r_subseq), | |
264 | Entry(dt_ticks, tp_dt_ticks), | |
265 | Entry(inact_ticks, tp_inact_ticks), | |
266 | Entry(keepalive_ticks, tp_keepalive_ticks), | |
267 | Entry(cr_ticks, tp_cr_ticks), | |
268 | Entry(xpd_ticks, tp_xpd_ticks), | |
269 | 0}; |