BSD 4_4 release
[unix-history] / usr / src / sys / tests / netiso / tpcb.c
CommitLineData
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
35char 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 41static 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
77struct tpcb_info {
78 char *name;
79 int offset;
80 int size;
81} tpcb_info[];
82
83int tflag = 0;
84int Iflag = 0;
85int Aflag = 0;
8aa4bb3a 86int Sflag = 1;
4a4b11be
KS
87
88char *vmunix = _PATH_UNIX;
89char *kmemf = 0;
90struct nlist nl[] = {
8aa4bb3a 91#define TP_REFINFO 0
4a4b11be
KS
92{"_tp_refinfo"},
930
94};
95struct tp_pcb tp_pcb;
96
97#define kget(p, d) \
98 (kvm_read((void *)(p), &(d), sizeof (d)))
99main(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 128int column;
4a4b11be
KS
129
130#define kdata(t) (data = *(t *)(ti->offset + (char *)&tp_pcb))
131
8aa4bb3a
KS
132doall(refinfo_off)
133off_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
161printone(ti)
162register 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
177parse(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
195struct tpcb_info tpcb_info[] = {
196Entry(next, tp_next),
197Entry(prev, tp_prev),
198Entry(nextlisten, tp_nextlisten),
199Entry(state, tp_state),
200Entry(retrans, tp_retrans),
201Entry(npcb, tp_npcb),
202Entry(nlproto, tp_nlproto),
203Entry(sock, tp_sock),
204Entry(lref, tp_lref),
205Entry(fref, tp_fref),
206Entry(seqmask, tp_seqmask),
207Entry(seqbit, tp_seqbit),
208Entry(seqhalf, tp_seqhalf),
209Entry(ucddata, tp_ucddata),
8aa4bb3a
KS
210Entry(cebit_off, tp_cebit_off),
211Entry(oktonagle, tp_oktonagle),
212Entry(flags, tp_flags),
4a4b11be
KS
213Entry(fcredit, tp_fcredit),
214Entry(maxfcredit, tp_maxfcredit),
215Entry(dupacks, tp_dupacks),
216Entry(cong_win, tp_cong_win),
217Entry(ssthresh, tp_ssthresh),
218Entry(snduna, tp_snduna),
219Entry(sndnew, tp_sndnew),
220Entry(sndnum, tp_sndnum),
221Entry(sndnxt, tp_sndnxt),
222Entry(sndnxt_m, tp_sndnxt_m),
223Entry(Nwindow, tp_Nwindow),
224Entry(rcvnxt, tp_rcvnxt),
225Entry(sent_lcdt, tp_sent_lcdt),
226Entry(sent_uwe, tp_sent_uwe),
227Entry(sent_rcvnxt, tp_sent_rcvnxt),
228Entry(lcredit, tp_lcredit),
229Entry(maxlcredit, tp_maxlcredit),
8aa4bb3a 230Entry(rhiwat, tp_rhiwat),
4a4b11be
KS
231Entry(rsyq, tp_rsyq),
232Entry(rsycnt, tp_rsycnt),
233Entry(win_recv, tp_win_recv),
234Entry(l_tpdusize, tp_l_tpdusize),
235Entry(rtv, tp_rtv),
236Entry(rtt, tp_rtt),
237Entry(rttseq, tp_rttseq),
238Entry(rttemit, tp_rttemit),
239Entry(idle, tp_idle),
240Entry(rxtcur, tp_rxtcur),
241Entry(rxtshift, tp_rxtshift),
242Entry(domain, tp_domain),
243Entry(fsuffixlen, tp_fsuffixlen),
244Entry(fsuffix, tp_fsuffix[0]),
245Entry(lsuffixlen, tp_lsuffixlen),
246Entry(lsuffix, tp_lsuffix[0]),
247{ "fport", Offsetof(tp_fsuffix[0]), sizeof(short), },
248{ "lport", Offsetof(tp_lsuffix[0]), sizeof(short), },
249Entry(vers, tp_vers),
250Entry(peer_acktime, tp_peer_acktime),
251Entry(refstate, tp_refstate),
252Entry(fasttimeo, tp_fasttimeo),
253Entry(inact, tp_timer[TM_inact]),
254Entry(retrans, tp_timer[TM_retrans]),
255Entry(sendack, tp_timer[TM_sendack]),
256Entry(data_retrans, tp_timer[TM_data_retrans]),
257Entry(reference, tp_timer[TM_reference]),
258Entry(Xsnd, tp_Xsnd),
259Entry(Xsndnxt, tp_Xsndnxt),
260Entry(Xuna, tp_Xuna),
261Entry(Xrcvnxt, tp_Xrcvnxt),
262Entry(s_subseq, tp_s_subseq),
263Entry(r_subseq, tp_r_subseq),
264Entry(dt_ticks, tp_dt_ticks),
265Entry(inact_ticks, tp_inact_ticks),
266Entry(keepalive_ticks, tp_keepalive_ticks),
267Entry(cr_ticks, tp_cr_ticks),
268Entry(xpd_ticks, tp_xpd_ticks),
2690};