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