]>
git.saurik.com Git - apple/network_cmds.git/blob - trsp.tproj/trsp.c
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.0 (the 'License'). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
25 * Copyright (c) 1985, 1993
26 * The Regents of the University of California. All rights reserved.
28 * Redistribution and use in source and binary forms, with or without
29 * modification, are permitted provided that the following conditions
31 * 1. Redistributions of source code must retain the above copyright
32 * notice, this list of conditions and the following disclaimer.
33 * 2. Redistributions in binary form must reproduce the above copyright
34 * notice, this list of conditions and the following disclaimer in the
35 * documentation and/or other materials provided with the distribution.
36 * 3. All advertising materials mentioning features or use of this software
37 * must display the following acknowledgement:
38 * This product includes software developed by the University of
39 * California, Berkeley and its contributors.
40 * 4. Neither the name of the University nor the names of its contributors
41 * may be used to endorse or promote products derived from this software
42 * without specific prior written permission.
44 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
45 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
47 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
48 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
49 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
50 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
51 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
52 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
53 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 static char copyright
[] =
59 "@(#) Copyright (c) 1985, 1993\n\
60 The Regents of the University of California. All rights reserved.\n";
64 static char sccsid
[] = "@(#)trsp.c 8.1 (Berkeley) 6/6/93";
69 #include <sys/cdefs.h>
70 #include <sys/param.h>
71 #include <sys/socket.h>
72 #include <sys/socketvar.h>
74 #include <sys/protosw.h>
76 #include <net/route.h>
80 #include <netinet/tcp_fsm.h>
82 #include <netinet/tcp_timer.h>
86 #include <netns/idp.h>
87 #include <netns/spidp.h>
88 #include <netns/spp_timer.h>
89 #include <netns/spp_var.h>
90 #include <netns/ns_pcb.h>
91 #include <netns/idp_var.h>
93 #include <netns/spp_debug.h>
107 struct nlist nl
[] = {
112 struct spp_debug spp_debug
[SPP_NDEBUG
];
113 caddr_t spp_pcbs
[SPP_NDEBUG
];
120 int i
, mask
= 0, npcbs
= 0;
128 if (argc
> 0 && !strcmp(*argv
, "-a")) {
129 aflag
++, argc
--, argv
++;
132 if (argc
> 0 && !strcmp(*argv
, "-z")) {
133 zflag
++, argc
--, argv
++;
136 if (argc
> 0 && !strcmp(*argv
, "-s")) {
137 sflag
++, argc
--, argv
++;
140 if (argc
> 0 && !strcmp(*argv
, "-t")) {
141 tflag
++, argc
--, argv
++;
144 if (argc
> 0 && !strcmp(*argv
, "-j")) {
145 jflag
++, argc
--, argv
++;
148 if (argc
> 0 && !strcmp(*argv
, "-p")) {
151 fprintf(stderr
, "-p: missing sppcb address\n");
154 if (npcbs
>= SPP_NDEBUG
) {
155 fprintf(stderr
, "-p: too many pcb's specified\n");
158 sscanf(*argv
, "%x", &spp_pcbs
[npcbs
++]);
167 * Discard setgid privileges if not the running kernel so that
168 * bad guys can't print interesting stuff from kernel memory.
178 (void) nlist(system
, nl
);
179 if (nl
[0].n_value
== 0) {
180 fprintf(stderr
, "trsp: %s: no namelist\n", system
);
184 if (open(core
, 0) < 0) {
185 fprintf(stderr
, "trsp: "); perror(core
);
189 nl
[0].n_value
&= 0x7fffffff;
190 nl
[1].n_value
&= 0x7fffffff;
192 (void) lseek(0, nl
[1].n_value
, 0);
193 if (read(0, &spp_debx
, sizeof (spp_debx
)) != sizeof (spp_debx
)) {
194 fprintf(stderr
, "trsp: "); perror("spp_debx");
197 printf("spp_debx=%d\n", spp_debx
);
198 (void) lseek(0, nl
[0].n_value
, 0);
199 if (read(0, spp_debug
, sizeof (spp_debug
)) != sizeof (spp_debug
)) {
200 fprintf(stderr
, "trsp: "); perror("spp_debug");
204 * Here, we just want to clear out the old trace data and start over.
207 char *cp
= (char *) spp_debug
,
208 *cplim
= cp
+ sizeof(spp_debug
);
210 if (open(core
, 2) < 0) {
211 fprintf(stderr
, "trsp: "); perror(core
);
214 while(cp
< cplim
) *cp
++ = 0;
215 (void) lseek(0, nl
[0].n_value
, 0);
216 if (write(0, spp_debug
, sizeof (spp_debug
)) != sizeof (spp_debug
)) {
217 fprintf(stderr
, "trsp: "); perror("spp_debug");
220 (void) lseek(0, nl
[1].n_value
, 0);
222 if (write(0, &spp_debx
, sizeof (spp_debx
)) != sizeof (spp_debx
)) {
223 fprintf(stderr
, "trsp: "); perror("spp_debx");
229 * If no control blocks have been specified, figure
230 * out how many distinct one we have and summarize
231 * them in spp_pcbs for sorting the trace records
235 for (i
= 0; i
< SPP_NDEBUG
; i
++) {
237 register struct spp_debug
*sd
= &spp_debug
[i
];
241 for (j
= 0; j
< npcbs
; j
++)
242 if (spp_pcbs
[j
] == sd
->sd_cb
)
245 spp_pcbs
[npcbs
++] = sd
->sd_cb
;
248 qsort(spp_pcbs
, npcbs
, sizeof (caddr_t
), numeric
);
252 for (i
= 0; i
< npcbs
; i
++) {
253 printf("%s%x", cp
, spp_pcbs
[i
]);
260 for (i
= 0; i
< npcbs
; i
++) {
261 printf("\n%x:\n", spp_pcbs
[i
]);
262 dotrace(spp_pcbs
[i
]);
268 register caddr_t sppcb
;
271 register struct spp_debug
*sd
;
273 for (i
= spp_debx
% SPP_NDEBUG
; i
< SPP_NDEBUG
; i
++) {
275 if (sppcb
&& sd
->sd_cb
!= sppcb
)
277 ntime
= ntohl(sd
->sd_time
);
278 spp_trace(sd
->sd_act
, sd
->sd_ostate
, sd
->sd_cb
, &sd
->sd_sp
,
279 &sd
->sd_si
, sd
->sd_req
);
281 for (i
= 0; i
< spp_debx
% SPP_NDEBUG
; i
++) {
283 if (sppcb
&& sd
->sd_cb
!= sppcb
)
285 ntime
= ntohl(sd
->sd_time
);
286 spp_trace(sd
->sd_act
, sd
->sd_ostate
, sd
->sd_cb
, &sd
->sd_sp
,
287 &sd
->sd_si
, sd
->sd_req
);
295 printf("%03d ", (ms
/10) % 1000);
305 spp_trace(act
, ostate
, asp
, sp
, si
, req
)
307 struct sppcb
*asp
, *sp
;
311 u_short seq
, ack
, len
, alo
;
315 if(ostate
>= TCP_NSTATES
) ostate
= 0;
316 if(act
> SA_DROP
) act
= SA_DROP
;
319 printf("%s:%s", tcpstates
[ostate
], sanames
[act
]);
337 ns_printhost(&si
->si_sna
);
339 ns_printhost(&si
->si_dna
);
342 #define p1(name, f) { \
343 printf("%s = %x, ", name, f); \
350 printf("flags=%x", flags
);
351 #define pf(name, f) { \
353 printf("%s%s", cp, name); \
366 #define p2(name, f) { \
367 printf("%s = %x, ", name, f); \
369 p2("sid", si
->si_sid
);
370 p2("did", si
->si_did
);
373 ns_printhost(&si
->si_sna
);
375 ns_printhost(&si
->si_dna
);
379 printf("\treq=%s", prurequests
[req
&0xff]);
380 if ((req
& 0xff) == PRU_SLOWTIMO
)
381 printf("<%s>", tcptimers
[req
>>8]);
383 printf(" -> %s", tcpstates
[sp
->s_state
]);
385 /* print out internal state of sp !?! */
389 #define p3(name, f) { \
390 printf("%s = %x, ", name, f); \
394 p3("rack", sp
->s_rack
);
395 p3("ralo", sp
->s_ralo
);
396 p3("smax", sp
->s_smax
);
397 p3("snxt", sp
->s_snxt
);
398 p3("flags", sp
->s_flags
);
400 #define pf(name, f) { \
402 printf("%s%s", cp, name); \
407 if (flags
|| sp
->s_oobflags
) {
409 pf("ACKNOW", SF_ACKNOW
);
410 pf("DELACK", SF_DELACK
);
417 flags
= sp
->s_oobflags
;
423 /* print out timers? */
428 printf("\n\tTIMERS: ");
429 p3("idle", sp
->s_idle
);
430 p3("force", sp
->s_force
);
431 p3("rtseq", sp
->s_rtseq
);
432 for (i
= 0; i
< TCPT_NTIMERS
; i
++) {
433 if (sp
->s_timer
[i
] == 0)
435 printf("%s%s=%d", cp
, tcptimers
[i
], sp
->s_timer
[i
]);
437 printf(" (s_rxtshft=%d)", sp
->s_rxtshift
);
446 register struct ns_addr
*p
;
449 printf("<net:%x%x,host:%4.4x%4.4x%4.4x,port:%x>",