summaryrefslogtreecommitdiff
path: root/usr.sbin/trsp
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>1995-10-18 08:53:40 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>1995-10-18 08:53:40 +0000
commitd6583bb2a13f329cf0332ef2570eb8bb8fc0e39c (patch)
treeece253b876159b39c620e62b6c9b1174642e070e /usr.sbin/trsp
initial import of NetBSD tree
Diffstat (limited to 'usr.sbin/trsp')
-rw-r--r--usr.sbin/trsp/Makefile10
-rw-r--r--usr.sbin/trsp/trsp.8144
-rw-r--r--usr.sbin/trsp/trsp.c428
3 files changed, 582 insertions, 0 deletions
diff --git a/usr.sbin/trsp/Makefile b/usr.sbin/trsp/Makefile
new file mode 100644
index 00000000000..0298a246738
--- /dev/null
+++ b/usr.sbin/trsp/Makefile
@@ -0,0 +1,10 @@
+# from: @(#)Makefile 5.3 (Berkeley) 5/11/90
+# $Id: Makefile,v 1.1 1995/10/18 08:48:30 deraadt Exp $
+
+PROG= trsp
+MAN= trsp.8
+BINGRP= kmem
+BINMODE=2555
+
+.include <bsd.prog.mk>
+
diff --git a/usr.sbin/trsp/trsp.8 b/usr.sbin/trsp/trsp.8
new file mode 100644
index 00000000000..115c3a4a13b
--- /dev/null
+++ b/usr.sbin/trsp/trsp.8
@@ -0,0 +1,144 @@
+.\" Copyright (c) 1985, 1991 The Regents of the University of California.
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" from: @(#)trsp.8 6.4 (Berkeley) 3/16/91
+.\" $Id: trsp.8,v 1.1 1995/10/18 08:48:30 deraadt Exp $
+.\"
+.Dd March 16, 1991
+.Dt TRSP 8
+.Os BSD 4.2
+.Sh NAME
+.Nm trsp
+.Nd transliterate sequenced packet protocol trace
+.Sh SYNOPSIS
+.Nm trsp
+.Op Fl a
+.Op Fl s
+.Op Fl t
+.Op Fl j
+.Op Fl p Ar hex-address
+.Oo
+.Ar system Op Ar core
+.Oc
+.Sh DESCRIPTION
+.Xr Trpt
+interrogates the buffer of
+.Tn SPP
+trace records created
+when a socket is marked for
+.Dq debugging
+(see
+.Xr setsockopt 2 ) ,
+and prints a readable description of these records.
+When no options are supplied,
+.Nm trsp
+prints all the trace records found in the system
+grouped according to
+.Tn SPP
+connection protocol control
+block
+.Pq Tn PCB .
+The following options may be used to
+alter this behavior.
+.Bl -tag -width Ds
+.It Fl a
+In addition to the normal output,
+print the values of the source and destination
+addresses for each packet recorded.
+.It Fl j
+Just give a list of the protocol control block
+addresses for which there are trace records.
+.It Fl p
+Show only trace records associated with the protocol
+control block at the given address,
+.Ar hex-address .
+.It Fl s
+in addition to the normal output,
+print a detailed description of the packet
+sequencing information.
+.It Fl t
+in addition to the normal output,
+print the values for all timers at each
+point in the trace,
+.El
+.Pp
+The recommended use of
+.Nm trsp
+is as follows.
+Isolate the problem and enable debugging on the
+socket(s) involved in the connection.
+Find the address of the protocol control blocks
+associated with the sockets using the
+.Fl A
+option to
+.Xr netstat 1 .
+Then run
+.Nm trsp
+with the
+.Fl p
+option, supplying the associated
+protocol control block addresses. If there are
+many sockets using the debugging option, the
+.Fl j
+option may be useful in checking to see if
+any trace records are present for the socket in
+question.
+.Pp
+If debugging is being performed on a system or
+core file other than the default, the last two
+arguments may be used to supplant the defaults.
+.Sh FILES
+.Bl -tag -width /dev/kmem -compact
+.It Pa /dev/kmem
+default kernel memory
+.It Pa /netbsd
+default system namelist
+.El
+.Sh SEE ALSO
+.Xr netstat 1 ,
+.Xr setsockopt 2
+.Sh DIAGNOSTICS
+.Bl -tag -width Ds
+.It Sy no namelist
+When the system image doesn't
+contain the proper symbols to find the trace buffer;
+others which should be self explanatory.
+.Sh BUGS
+Should also print the data for each input or output,
+but this is not saved in the race record.
+.Pp
+The output format is inscrutable and should be described
+here.
+.Sh HISTORY
+The
+.Nm
+command appeared in
+.Bx 4.3 .
diff --git a/usr.sbin/trsp/trsp.c b/usr.sbin/trsp/trsp.c
new file mode 100644
index 00000000000..62e1a61c689
--- /dev/null
+++ b/usr.sbin/trsp/trsp.c
@@ -0,0 +1,428 @@
+/*
+ * Copyright (c) 1985 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+char copyright[] =
+"@(#) Copyright (c) 1985 Regents of the University of California.\n\
+ All rights reserved.\n";
+#endif /* not lint */
+
+#ifndef lint
+/*static char sccsid[] = "from: @(#)trsp.c 6.8 (Berkeley) 3/2/91";*/
+static char rcsid[] = "$Id: trsp.c,v 1.1 1995/10/18 08:48:30 deraadt Exp $";
+#endif /* not lint */
+
+#include <sys/cdefs.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <sys/socketvar.h>
+#define PRUREQUESTS
+#include <sys/protosw.h>
+
+#include <net/route.h>
+#include <net/if.h>
+
+#define TCPSTATES
+#include <netinet/tcp_fsm.h>
+#define TCPTIMERS
+#include <netinet/tcp_timer.h>
+
+#include <netns/ns.h>
+#include <netns/sp.h>
+#include <netns/idp.h>
+#include <netns/spidp.h>
+#include <netns/spp_timer.h>
+#include <netns/spp_var.h>
+#include <netns/ns_pcb.h>
+#include <netns/idp_var.h>
+#define SANAMES
+#include <netns/spp_debug.h>
+
+#include <stdio.h>
+#include <errno.h>
+#include <nlist.h>
+#include <paths.h>
+
+unsigned long ntime;
+int sflag;
+int tflag;
+int jflag;
+int aflag;
+int zflag;
+int numeric();
+struct nlist nl[] = {
+ { "_spp_debug" },
+ { "_spp_debx" },
+ 0
+};
+struct spp_debug spp_debug[SPP_NDEBUG];
+caddr_t spp_pcbs[SPP_NDEBUG];
+int spp_debx;
+
+main(argc, argv)
+ int argc;
+ char **argv;
+{
+ int i, mask = 0, npcbs = 0;
+ char *system, *core;
+
+ system = _PATH_UNIX;
+ core = _PATH_KMEM;
+
+ argc--, argv++;
+again:
+ if (argc > 0 && !strcmp(*argv, "-a")) {
+ aflag++, argc--, argv++;
+ goto again;
+ }
+ if (argc > 0 && !strcmp(*argv, "-z")) {
+ zflag++, argc--, argv++;
+ goto again;
+ }
+ if (argc > 0 && !strcmp(*argv, "-s")) {
+ sflag++, argc--, argv++;
+ goto again;
+ }
+ if (argc > 0 && !strcmp(*argv, "-t")) {
+ tflag++, argc--, argv++;
+ goto again;
+ }
+ if (argc > 0 && !strcmp(*argv, "-j")) {
+ jflag++, argc--, argv++;
+ goto again;
+ }
+ if (argc > 0 && !strcmp(*argv, "-p")) {
+ argc--, argv++;
+ if (argc < 1) {
+ fprintf(stderr, "-p: missing sppcb address\n");
+ exit(1);
+ }
+ if (npcbs >= SPP_NDEBUG) {
+ fprintf(stderr, "-p: too many pcb's specified\n");
+ exit(1);
+ }
+ sscanf(*argv, "%x", &spp_pcbs[npcbs++]);
+ argc--, argv++;
+ goto again;
+ }
+ if (argc > 0) {
+ system = *argv;
+ argc--, argv++;
+ mask++;
+ }
+ if (argc > 0) {
+ core = *argv;
+ argc--, argv++;
+ mask++;
+ }
+ (void) nlist(system, nl);
+ if (nl[0].n_value == 0) {
+ fprintf(stderr, "trsp: %s: no namelist\n", system);
+ exit(1);
+ }
+ (void) close(0);
+ if (open(core, 0) < 0) {
+ fprintf(stderr, "trsp: "); perror(core);
+ exit(2);
+ }
+ if (mask) {
+ nl[0].n_value &= 0x7fffffff;
+ nl[1].n_value &= 0x7fffffff;
+ }
+ (void) lseek(0, nl[1].n_value, 0);
+ if (read(0, &spp_debx, sizeof (spp_debx)) != sizeof (spp_debx)) {
+ fprintf(stderr, "trsp: "); perror("spp_debx");
+ exit(3);
+ }
+ printf("spp_debx=%d\n", spp_debx);
+ (void) lseek(0, nl[0].n_value, 0);
+ if (read(0, spp_debug, sizeof (spp_debug)) != sizeof (spp_debug)) {
+ fprintf(stderr, "trsp: "); perror("spp_debug");
+ exit(3);
+ }
+ /*
+ * Here, we just want to clear out the old trace data and start over.
+ */
+ if (zflag) {
+ char *cp = (char *) spp_debug,
+ *cplim = cp + sizeof(spp_debug);
+ (void) close(0);
+ if (open(core, 2) < 0) {
+ fprintf(stderr, "trsp: "); perror(core);
+ exit(2);
+ }
+ while(cp < cplim) *cp++ = 0;
+ (void) lseek(0, nl[0].n_value, 0);
+ if (write(0, spp_debug, sizeof (spp_debug)) != sizeof (spp_debug)) {
+ fprintf(stderr, "trsp: "); perror("spp_debug");
+ exit(3);
+ }
+ (void) lseek(0, nl[1].n_value, 0);
+ spp_debx = 0;
+ if (write(0, &spp_debx, sizeof (spp_debx)) != sizeof (spp_debx)) {
+ fprintf(stderr, "trsp: "); perror("spp_debx");
+ exit(3);
+ }
+ exit(0);
+ }
+ /*
+ * If no control blocks have been specified, figure
+ * out how many distinct one we have and summarize
+ * them in spp_pcbs for sorting the trace records
+ * below.
+ */
+ if (npcbs == 0) {
+ for (i = 0; i < SPP_NDEBUG; i++) {
+ register int j;
+ register struct spp_debug *sd = &spp_debug[i];
+
+ if (sd->sd_cb == 0)
+ continue;
+ for (j = 0; j < npcbs; j++)
+ if (spp_pcbs[j] == sd->sd_cb)
+ break;
+ if (j >= npcbs)
+ spp_pcbs[npcbs++] = sd->sd_cb;
+ }
+ }
+ qsort(spp_pcbs, npcbs, sizeof (caddr_t), numeric);
+ if (jflag) {
+ char *cp = "";
+
+ for (i = 0; i < npcbs; i++) {
+ printf("%s%x", cp, spp_pcbs[i]);
+ cp = ", ";
+ }
+ if (*cp)
+ putchar('\n');
+ exit(0);
+ }
+ for (i = 0; i < npcbs; i++) {
+ printf("\n%x:\n", spp_pcbs[i]);
+ dotrace(spp_pcbs[i]);
+ }
+ exit(0);
+}
+
+dotrace(sppcb)
+ register caddr_t sppcb;
+{
+ register int i;
+ register struct spp_debug *sd;
+
+ for (i = spp_debx % SPP_NDEBUG; i < SPP_NDEBUG; i++) {
+ sd = &spp_debug[i];
+ if (sppcb && sd->sd_cb != sppcb)
+ continue;
+ ntime = ntohl(sd->sd_time);
+ spp_trace(sd->sd_act, sd->sd_ostate, sd->sd_cb, &sd->sd_sp,
+ &sd->sd_si, sd->sd_req);
+ }
+ for (i = 0; i < spp_debx % SPP_NDEBUG; i++) {
+ sd = &spp_debug[i];
+ if (sppcb && sd->sd_cb != sppcb)
+ continue;
+ ntime = ntohl(sd->sd_time);
+ spp_trace(sd->sd_act, sd->sd_ostate, sd->sd_cb, &sd->sd_sp,
+ &sd->sd_si, sd->sd_req);
+ }
+}
+
+ptime(ms)
+ int ms;
+{
+
+ printf("%03d ", (ms/10) % 1000);
+}
+
+numeric(c1, c2)
+ caddr_t *c1, *c2;
+{
+
+ return (*c1 - *c2);
+}
+
+spp_trace(act, ostate, asp, sp, si, req)
+ short act, ostate;
+ struct sppcb *asp, *sp;
+ struct spidp *si;
+ int req;
+{
+ u_short seq, ack, len, alo;
+ int flags, timer;
+ char *cp;
+
+ if(ostate >= TCP_NSTATES) ostate = 0;
+ if(act > SA_DROP) act = SA_DROP;
+ printf("\n");
+ ptime(ntime);
+ printf("%s:%s", tcpstates[ostate], sanames[act]);
+
+ if (si != 0) {
+ seq = si->si_seq;
+ ack = si->si_ack;
+ alo = si->si_alo;
+ len = si->si_len;
+ switch (act) {
+ case SA_RESPOND:
+ case SA_OUTPUT:
+ seq = ntohs(seq);
+ ack = ntohs(ack);
+ alo = ntohs(alo);
+ len = ntohs(len);
+ case SA_INPUT:
+ case SA_DROP:
+ if (aflag) {
+ printf("\n\tsna=");
+ ns_printhost(&si->si_sna);
+ printf("\tdna=");
+ ns_printhost(&si->si_dna);
+ }
+ printf("\n\t");
+#define p1(name, f) { \
+ printf("%s = %x, ", name, f); \
+ }
+ p1("seq", seq);
+ p1("ack", ack);
+ p1("alo", alo);
+ p1("len", len);
+ flags = si->si_cc;
+ printf("flags=%x", flags);
+#define pf(name, f) { \
+ if (flags & f) { \
+ printf("%s%s", cp, name); \
+ cp = ","; \
+ } \
+}
+ if (flags) {
+ char *cp = "<";
+ pf("SP_SP", SP_SP);
+ pf("SP_SA", SP_SA);
+ pf("SP_OB", SP_OB);
+ pf("SP_EM", SP_EM);
+ printf(">");
+ }
+ printf(", ");
+#define p2(name, f) { \
+ printf("%s = %x, ", name, f); \
+}
+ p2("sid", si->si_sid);
+ p2("did", si->si_did);
+ p2("dt", si->si_dt);
+ printf("\n\tsna=");
+ ns_printhost(&si->si_sna);
+ printf("\tdna=");
+ ns_printhost(&si->si_dna);
+ }
+ }
+ if(act == SA_USER) {
+ printf("\treq=%s", prurequests[req&0xff]);
+ if ((req & 0xff) == PRU_SLOWTIMO)
+ printf("<%s>", tcptimers[req>>8]);
+ }
+ printf(" -> %s", tcpstates[sp->s_state]);
+
+ /* print out internal state of sp !?! */
+ printf("\n");
+ if (sp == 0)
+ return;
+#define p3(name, f) { \
+ printf("%s = %x, ", name, f); \
+}
+ if (sflag) {
+ printf("\t");
+ p3("rack", sp->s_rack);
+ p3("ralo", sp->s_ralo);
+ p3("smax", sp->s_smax);
+ p3("snxt", sp->s_snxt);
+ p3("flags", sp->s_flags);
+#undef pf
+#define pf(name, f) { \
+ if (flags & f) { \
+ printf("%s%s", cp, name); \
+ cp = ","; \
+ } \
+}
+ flags = sp->s_flags;
+ if (flags || sp->s_oobflags) {
+ char *cp = "<";
+ pf("ACKNOW", SF_ACKNOW);
+ pf("DELACK", SF_DELACK);
+ pf("HI", SF_HI);
+ pf("HO", SF_HO);
+ pf("PI", SF_PI);
+ pf("WIN", SF_WIN);
+ pf("RXT", SF_RXT);
+ pf("RVD", SF_RVD);
+ flags = sp->s_oobflags;
+ pf("SOOB", SF_SOOB);
+ pf("IOOB", SF_IOOB);
+ printf(">");
+ }
+ }
+ /* print out timers? */
+ if (tflag) {
+ char *cp = "\t";
+ register int i;
+
+ printf("\n\tTIMERS: ");
+ p3("idle", sp->s_idle);
+ p3("force", sp->s_force);
+ p3("rtseq", sp->s_rtseq);
+ for (i = 0; i < TCPT_NTIMERS; i++) {
+ if (sp->s_timer[i] == 0)
+ continue;
+ printf("%s%s=%d", cp, tcptimers[i], sp->s_timer[i]);
+ if (i == TCPT_REXMT)
+ printf(" (s_rxtshft=%d)", sp->s_rxtshift);
+ cp = ", ";
+ }
+ if (*cp != '\t')
+ putchar('\n');
+ }
+}
+
+ns_printhost(p)
+register struct ns_addr *p;
+{
+
+ printf("<net:%x%x,host:%4.4x%4.4x%4.4x,port:%x>",
+ p->x_net.s_net[0],
+ p->x_net.s_net[1],
+ p->x_host.s_host[0],
+ p->x_host.s_host[1],
+ p->x_host.s_host[2],
+ p->x_port);
+
+}
+