2006-03-31 14:20:21 +04:00
|
|
|
/* $NetBSD: trpt.c,v 1.22 2006/03/31 10:20:21 rpaulo Exp $ */
|
1997-07-23 12:19:59 +04:00
|
|
|
|
|
|
|
/*-
|
2006-03-31 14:20:21 +04:00
|
|
|
* Copyright (c) 1997, 2005, 2006 The NetBSD Foundation, Inc.
|
1997-07-23 12:19:59 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
|
|
|
|
* NASA Ames Research Center.
|
|
|
|
*
|
|
|
|
* 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 NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
|
|
|
|
*/
|
1997-07-23 10:31:43 +04:00
|
|
|
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
/*
|
1997-07-23 10:31:43 +04:00
|
|
|
* Copyright (c) 1983, 1988, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
*
|
|
|
|
* 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.
|
2003-08-07 15:25:11 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
1997-07-23 12:19:59 +04:00
|
|
|
#include <sys/cdefs.h>
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
#ifndef lint
|
1997-07-23 12:19:59 +04:00
|
|
|
__COPYRIGHT(
|
1997-07-23 10:31:43 +04:00
|
|
|
"@(#) Copyright (c) 1983, 1988, 1993\n\
|
1997-07-23 12:19:59 +04:00
|
|
|
The Regents of the University of California. All rights reserved.\n");
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#ifndef lint
|
1997-07-23 10:31:43 +04:00
|
|
|
#if 0
|
|
|
|
static char sccsid[] = "@(#)trpt.c 8.1 (Berkeley) 6/6/93";
|
|
|
|
#else
|
2006-03-31 14:20:21 +04:00
|
|
|
__RCSID("$NetBSD: trpt.c,v 1.22 2006/03/31 10:20:21 rpaulo Exp $");
|
1997-07-23 10:31:43 +04:00
|
|
|
#endif
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
1994-12-23 19:35:50 +03:00
|
|
|
#include <sys/queue.h>
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/socketvar.h>
|
2005-09-06 07:04:15 +04:00
|
|
|
#include <sys/sysctl.h>
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
#define PRUREQUESTS
|
|
|
|
#include <sys/protosw.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
|
|
|
|
#include <net/route.h>
|
|
|
|
#include <net/if.h>
|
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
#include <netinet/in_pcb.h>
|
|
|
|
#include <netinet/ip_var.h>
|
1999-07-01 23:15:03 +04:00
|
|
|
|
|
|
|
#ifdef INET6
|
|
|
|
#ifndef INET
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#endif
|
|
|
|
#include <netinet/ip6.h>
|
|
|
|
#endif
|
|
|
|
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
#include <netinet/tcp.h>
|
|
|
|
#define TCPSTATES
|
|
|
|
#include <netinet/tcp_fsm.h>
|
|
|
|
#include <netinet/tcp_seq.h>
|
|
|
|
#define TCPTIMERS
|
|
|
|
#include <netinet/tcp_timer.h>
|
|
|
|
#include <netinet/tcp_var.h>
|
|
|
|
#include <netinet/tcpip.h>
|
|
|
|
#define TANAMES
|
|
|
|
#include <netinet/tcp_debug.h>
|
|
|
|
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
1997-07-23 12:19:59 +04:00
|
|
|
#include <err.h>
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
1997-07-23 12:19:59 +04:00
|
|
|
#include <kvm.h>
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
#include <nlist.h>
|
|
|
|
#include <paths.h>
|
1997-07-23 12:19:59 +04:00
|
|
|
#include <limits.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
|
|
|
|
struct nlist nl[] = {
|
2003-02-04 04:22:08 +03:00
|
|
|
#define N_HARDCLOCK_TICKS 0
|
|
|
|
{ "_hardclock_ticks" },
|
|
|
|
#define N_TCP_DEBUG 1
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
{ "_tcp_debug" },
|
2003-02-04 04:22:08 +03:00
|
|
|
#define N_TCP_DEBX 2
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
{ "_tcp_debx" },
|
1997-07-23 12:19:59 +04:00
|
|
|
{ NULL },
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static caddr_t tcp_pcbs[TCP_NDEBUG];
|
|
|
|
static n_time ntime;
|
1997-07-23 12:19:59 +04:00
|
|
|
static int aflag, follow, sflag, tflag;
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
|
2001-07-09 11:54:59 +04:00
|
|
|
/* see sys/netinet/tcp_debug.c */
|
|
|
|
struct tcp_debug tcp_debug[TCP_NDEBUG];
|
|
|
|
int tcp_debx;
|
|
|
|
|
2005-02-06 08:00:46 +03:00
|
|
|
int main(int, char *[]);
|
|
|
|
void dotrace(caddr_t);
|
|
|
|
void tcp_trace(short, short, struct tcpcb *, struct tcpcb *,
|
|
|
|
int, void *, int);
|
|
|
|
int numeric(const void *, const void *);
|
|
|
|
void usage(void);
|
1997-07-23 12:19:59 +04:00
|
|
|
|
|
|
|
kvm_t *kd;
|
2005-09-06 07:04:15 +04:00
|
|
|
int use_sysctl;
|
1997-07-23 12:19:59 +04:00
|
|
|
|
|
|
|
int
|
2005-02-06 08:00:46 +03:00
|
|
|
main(int argc, char *argv[])
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
{
|
1997-07-23 12:19:59 +04:00
|
|
|
int ch, i, jflag, npcbs;
|
|
|
|
char *system, *core, *cp, errbuf[_POSIX2_LINE_MAX];
|
2002-11-16 07:20:42 +03:00
|
|
|
unsigned long l;
|
1997-07-23 12:19:59 +04:00
|
|
|
|
2005-09-06 07:04:15 +04:00
|
|
|
jflag = npcbs = 0;
|
1997-07-23 12:19:59 +04:00
|
|
|
system = core = NULL;
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
|
2002-10-12 12:57:16 +04:00
|
|
|
while ((ch = getopt(argc, argv, "afjp:stN:M:")) != -1) {
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
switch (ch) {
|
|
|
|
case 'a':
|
|
|
|
++aflag;
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
++follow;
|
|
|
|
setlinebuf(stdout);
|
|
|
|
break;
|
|
|
|
case 'j':
|
|
|
|
++jflag;
|
|
|
|
break;
|
|
|
|
case 'p':
|
1997-07-23 12:19:59 +04:00
|
|
|
if (npcbs >= TCP_NDEBUG)
|
|
|
|
errx(1, "too many pcbs specified");
|
|
|
|
errno = 0;
|
2002-11-16 07:20:42 +03:00
|
|
|
cp = NULL;
|
|
|
|
l = strtoul(optarg, &cp, 16);
|
|
|
|
tcp_pcbs[npcbs] = (caddr_t)l;
|
|
|
|
if (*optarg == '\0' || *cp != '\0' || errno ||
|
|
|
|
(unsigned long)tcp_pcbs[npcbs] != l)
|
1997-07-23 12:19:59 +04:00
|
|
|
errx(1, "invalid address: %s", optarg);
|
2002-11-16 07:20:42 +03:00
|
|
|
npcbs++;
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
++sflag;
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
++tflag;
|
|
|
|
break;
|
1997-07-23 12:19:59 +04:00
|
|
|
case 'N':
|
|
|
|
system = optarg;
|
|
|
|
break;
|
|
|
|
case 'M':
|
|
|
|
core = optarg;
|
|
|
|
break;
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
default:
|
1997-07-23 12:19:59 +04:00
|
|
|
usage();
|
|
|
|
/* NOTREACHED */
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
}
|
1997-07-23 12:19:59 +04:00
|
|
|
}
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
1997-07-23 12:19:59 +04:00
|
|
|
if (argc)
|
|
|
|
usage();
|
|
|
|
|
2005-09-06 07:04:15 +04:00
|
|
|
use_sysctl = (system == NULL && core == NULL);
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
|
2005-09-06 07:04:15 +04:00
|
|
|
if (use_sysctl) {
|
|
|
|
size_t lenx = sizeof(tcp_debx);
|
|
|
|
size_t lend = sizeof(tcp_debug);
|
1997-07-23 12:19:59 +04:00
|
|
|
|
2005-09-06 07:04:15 +04:00
|
|
|
if (sysctlbyname("net.inet.tcp.debx", &tcp_debx, &lenx,
|
|
|
|
NULL, 0) == -1)
|
|
|
|
err(1, "net.inet.tcp.debx");
|
|
|
|
if (sysctlbyname("net.inet.tcp.debug", &tcp_debug, &lend,
|
|
|
|
NULL, 0) == -1)
|
|
|
|
err(1, "net.inet.tcp.debug");
|
|
|
|
} else {
|
|
|
|
kd = kvm_openfiles(system, core, NULL, O_RDONLY, errbuf);
|
|
|
|
if (kd == NULL)
|
|
|
|
errx(1, "can't open kmem: %s", errbuf);
|
1998-07-06 11:50:18 +04:00
|
|
|
|
2005-09-06 07:04:15 +04:00
|
|
|
if (kvm_nlist(kd, nl))
|
|
|
|
errx(2, "%s: no namelist", system);
|
1997-07-23 12:19:59 +04:00
|
|
|
|
2005-09-06 07:04:15 +04:00
|
|
|
if (kvm_read(kd, nl[N_TCP_DEBX].n_value, (char *)&tcp_debx,
|
|
|
|
sizeof(tcp_debx)) != sizeof(tcp_debx))
|
|
|
|
errx(3, "tcp_debx: %s", kvm_geterr(kd));
|
1997-07-23 12:19:59 +04:00
|
|
|
|
2005-09-06 07:04:15 +04:00
|
|
|
if (kvm_read(kd, nl[N_TCP_DEBUG].n_value, (char *)tcp_debug,
|
|
|
|
sizeof(tcp_debug)) != sizeof(tcp_debug))
|
|
|
|
errx(3, "tcp_debug: %s", kvm_geterr(kd));
|
|
|
|
}
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If no control blocks have been specified, figure
|
|
|
|
* out how many distinct one we have and summarize
|
|
|
|
* them in tcp_pcbs for sorting the trace records
|
|
|
|
* below.
|
|
|
|
*/
|
1997-07-23 12:19:59 +04:00
|
|
|
if (npcbs == 0) {
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
for (i = 0; i < TCP_NDEBUG; i++) {
|
1997-07-23 12:19:59 +04:00
|
|
|
struct tcp_debug *td = &tcp_debug[i];
|
|
|
|
int j;
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
|
|
|
|
if (td->td_tcb == 0)
|
|
|
|
continue;
|
|
|
|
for (j = 0; j < npcbs; j++)
|
|
|
|
if (tcp_pcbs[j] == td->td_tcb)
|
|
|
|
break;
|
|
|
|
if (j >= npcbs)
|
|
|
|
tcp_pcbs[npcbs++] = td->td_tcb;
|
|
|
|
}
|
1997-07-23 12:19:59 +04:00
|
|
|
if (npcbs == 0)
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
qsort(tcp_pcbs, npcbs, sizeof(caddr_t), numeric);
|
|
|
|
if (jflag) {
|
|
|
|
for (i = 0;;) {
|
1994-12-23 19:35:50 +03:00
|
|
|
printf("%lx", (long)tcp_pcbs[i]);
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
if (++i == npcbs)
|
|
|
|
break;
|
|
|
|
fputs(", ", stdout);
|
|
|
|
}
|
|
|
|
putchar('\n');
|
1997-07-23 12:19:59 +04:00
|
|
|
} else {
|
|
|
|
for (i = 0; i < npcbs; i++) {
|
|
|
|
printf("\n%lx:\n", (long)tcp_pcbs[i]);
|
|
|
|
dotrace(tcp_pcbs[i]);
|
|
|
|
}
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
}
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
1997-07-23 12:19:59 +04:00
|
|
|
void
|
2005-02-06 08:00:46 +03:00
|
|
|
dotrace(caddr_t tcpcb)
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
{
|
1997-07-23 12:19:59 +04:00
|
|
|
struct tcp_debug *td;
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
int prev_debx = tcp_debx;
|
1997-07-23 12:19:59 +04:00
|
|
|
int i;
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
|
1997-07-23 12:19:59 +04:00
|
|
|
again:
|
|
|
|
if (--tcp_debx < 0)
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
tcp_debx = TCP_NDEBUG - 1;
|
|
|
|
for (i = prev_debx % TCP_NDEBUG; i < TCP_NDEBUG; i++) {
|
|
|
|
td = &tcp_debug[i];
|
|
|
|
if (tcpcb && td->td_tcb != tcpcb)
|
|
|
|
continue;
|
|
|
|
ntime = ntohl(td->td_time);
|
1999-07-01 23:15:03 +04:00
|
|
|
switch (td->td_family) {
|
|
|
|
case AF_INET:
|
|
|
|
tcp_trace(td->td_act, td->td_ostate,
|
|
|
|
(struct tcpcb *)td->td_tcb, &td->td_cb,
|
|
|
|
td->td_family, &td->td_ti, td->td_req);
|
|
|
|
break;
|
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
|
|
|
tcp_trace(td->td_act, td->td_ostate,
|
|
|
|
(struct tcpcb *)td->td_tcb, &td->td_cb,
|
|
|
|
td->td_family, &td->td_ti6, td->td_req);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
tcp_trace(td->td_act, td->td_ostate,
|
|
|
|
(struct tcpcb *)td->td_tcb, &td->td_cb,
|
|
|
|
td->td_family, NULL, td->td_req);
|
|
|
|
break;
|
|
|
|
}
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
if (i == tcp_debx)
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
for (i = 0; i <= tcp_debx % TCP_NDEBUG; i++) {
|
|
|
|
td = &tcp_debug[i];
|
|
|
|
if (tcpcb && td->td_tcb != tcpcb)
|
|
|
|
continue;
|
|
|
|
ntime = ntohl(td->td_time);
|
1999-07-01 23:15:03 +04:00
|
|
|
switch (td->td_family) {
|
|
|
|
case AF_INET:
|
|
|
|
tcp_trace(td->td_act, td->td_ostate,
|
|
|
|
(struct tcpcb *)td->td_tcb, &td->td_cb,
|
|
|
|
td->td_family, &td->td_ti, td->td_req);
|
|
|
|
break;
|
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
|
|
|
tcp_trace(td->td_act, td->td_ostate,
|
|
|
|
(struct tcpcb *)td->td_tcb, &td->td_cb,
|
|
|
|
td->td_family, &td->td_ti6, td->td_req);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
tcp_trace(td->td_act, td->td_ostate,
|
|
|
|
(struct tcpcb *)td->td_tcb, &td->td_cb,
|
|
|
|
td->td_family, NULL, td->td_req);
|
|
|
|
break;
|
|
|
|
}
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
}
|
1997-07-23 12:19:59 +04:00
|
|
|
done:
|
|
|
|
if (follow) {
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
prev_debx = tcp_debx + 1;
|
|
|
|
if (prev_debx >= TCP_NDEBUG)
|
|
|
|
prev_debx = 0;
|
|
|
|
do {
|
|
|
|
sleep(1);
|
2005-09-06 07:04:15 +04:00
|
|
|
if (use_sysctl) {
|
|
|
|
size_t len = sizeof(tcp_debx);
|
|
|
|
|
|
|
|
if (sysctlbyname("net.inet.tcp.debx",
|
|
|
|
&tcp_debx, &len, NULL, 0) == -1)
|
|
|
|
err(1, "net.inet.tcp.debx");
|
|
|
|
} else
|
|
|
|
if (kvm_read(kd, nl[N_TCP_DEBX].n_value,
|
|
|
|
(char *)&tcp_debx, sizeof(tcp_debx)) !=
|
|
|
|
sizeof(tcp_debx))
|
|
|
|
errx(3, "tcp_debx: %s",
|
|
|
|
kvm_geterr(kd));
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
} while (tcp_debx == prev_debx);
|
1997-07-23 12:19:59 +04:00
|
|
|
|
2005-09-06 07:04:15 +04:00
|
|
|
if (use_sysctl) {
|
|
|
|
size_t len = sizeof(tcp_debug);
|
|
|
|
|
|
|
|
if (sysctlbyname("net.inet.tcp.debug", &tcp_debug,
|
|
|
|
&len, NULL, 0) == -1)
|
|
|
|
err(1, "net.inet.tcp.debug");
|
|
|
|
} else
|
|
|
|
if (kvm_read(kd, nl[N_TCP_DEBUG].n_value,
|
|
|
|
(char *)tcp_debug,
|
|
|
|
sizeof(tcp_debug)) != sizeof(tcp_debug))
|
|
|
|
errx(3, "tcp_debug: %s", kvm_geterr(kd));
|
1997-07-23 12:19:59 +04:00
|
|
|
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Tcp debug routines
|
|
|
|
*/
|
|
|
|
/*ARGSUSED*/
|
1997-07-23 12:19:59 +04:00
|
|
|
void
|
2005-02-06 08:00:46 +03:00
|
|
|
tcp_trace(short act, short ostate, struct tcpcb *atp, struct tcpcb *tp,
|
|
|
|
int family, void *packet, int req)
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
{
|
|
|
|
tcp_seq seq, ack;
|
|
|
|
int flags, len, win, timer;
|
1999-07-01 23:15:03 +04:00
|
|
|
struct tcphdr *th = NULL;
|
|
|
|
struct ip *ip = NULL;
|
|
|
|
#ifdef INET6
|
|
|
|
struct ip6_hdr *ip6 = NULL;
|
|
|
|
#endif
|
|
|
|
char hbuf[MAXHOSTNAMELEN];
|
|
|
|
|
2005-06-02 13:42:57 +04:00
|
|
|
len = 0; /* XXXGCC -Wuninitialized */
|
|
|
|
|
1999-07-01 23:15:03 +04:00
|
|
|
switch (family) {
|
|
|
|
case AF_INET:
|
|
|
|
if (packet) {
|
|
|
|
ip = (struct ip *)packet;
|
|
|
|
th = (struct tcphdr *)(ip + 1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
|
|
|
if (packet) {
|
|
|
|
ip6 = (struct ip6_hdr *)packet;
|
|
|
|
th = (struct tcphdr *)(ip6 + 1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
|
1997-07-23 12:19:59 +04:00
|
|
|
printf("%03d %s:%s ", (ntime/10) % 1000, tcpstates[ostate],
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
tanames[act]);
|
1999-07-01 23:15:03 +04:00
|
|
|
|
|
|
|
#ifndef INET6
|
|
|
|
if (!ip)
|
|
|
|
#else
|
|
|
|
if (!(ip || ip6))
|
|
|
|
#endif
|
|
|
|
goto skipact;
|
|
|
|
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
switch (act) {
|
|
|
|
case TA_INPUT:
|
|
|
|
case TA_OUTPUT:
|
|
|
|
case TA_DROP:
|
|
|
|
if (aflag) {
|
1999-07-01 23:15:03 +04:00
|
|
|
inet_ntop(family,
|
|
|
|
#ifndef INET6
|
|
|
|
(void *)&ip->ip_src,
|
|
|
|
#else
|
|
|
|
family == AF_INET ? (void *)&ip->ip_src
|
|
|
|
: (void *)&ip6->ip6_src,
|
|
|
|
#endif
|
|
|
|
hbuf, sizeof(hbuf));
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
printf("(src=%s,%u, ",
|
1999-07-01 23:15:03 +04:00
|
|
|
hbuf, ntohs(th->th_sport));
|
|
|
|
inet_ntop(family,
|
|
|
|
#ifndef INET6
|
|
|
|
(void *)&ip->ip_dst,
|
|
|
|
#else
|
|
|
|
family == AF_INET ? (void *)&ip->ip_dst
|
|
|
|
: (void *)&ip6->ip6_dst,
|
|
|
|
#endif
|
|
|
|
hbuf, sizeof(hbuf));
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
printf("dst=%s,%u)",
|
1999-07-01 23:15:03 +04:00
|
|
|
hbuf, ntohs(th->th_dport));
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
}
|
1999-07-01 23:15:03 +04:00
|
|
|
seq = th->th_seq;
|
|
|
|
ack = th->th_ack;
|
|
|
|
if (ip)
|
|
|
|
len = ip->ip_len;
|
|
|
|
#ifdef INET6
|
|
|
|
else if (ip6)
|
|
|
|
len = ip6->ip6_plen;
|
|
|
|
#endif
|
|
|
|
win = th->th_win;
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
if (act == TA_OUTPUT) {
|
1997-07-23 12:19:59 +04:00
|
|
|
NTOHL(seq);
|
|
|
|
NTOHL(ack);
|
|
|
|
NTOHS(len);
|
|
|
|
NTOHS(win);
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
}
|
|
|
|
if (act == TA_OUTPUT)
|
|
|
|
len -= sizeof(struct tcphdr);
|
|
|
|
if (len)
|
1997-07-23 12:19:59 +04:00
|
|
|
printf("[%x..%x)", seq, seq + len);
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
else
|
1997-07-23 12:19:59 +04:00
|
|
|
printf("%x", seq);
|
|
|
|
printf("@%x", ack);
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
if (win)
|
|
|
|
printf("(win=%x)", win);
|
1999-07-01 23:15:03 +04:00
|
|
|
flags = th->th_flags;
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
if (flags) {
|
2005-02-06 08:00:46 +03:00
|
|
|
char *cp = "<";
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
#define pf(flag, string) { \
|
1999-07-01 23:15:03 +04:00
|
|
|
if (th->th_flags&flag) { \
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
(void)printf("%s%s", cp, string); \
|
|
|
|
cp = ","; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
pf(TH_SYN, "SYN");
|
|
|
|
pf(TH_ACK, "ACK");
|
|
|
|
pf(TH_FIN, "FIN");
|
|
|
|
pf(TH_RST, "RST");
|
|
|
|
pf(TH_PUSH, "PUSH");
|
|
|
|
pf(TH_URG, "URG");
|
2006-03-31 14:20:21 +04:00
|
|
|
pf(TH_CWR, "CWR");
|
|
|
|
pf(TH_ECE, "ECE");
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
printf(">");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TA_USER:
|
|
|
|
timer = req >> 8;
|
|
|
|
req &= 0xff;
|
|
|
|
printf("%s", prurequests[req]);
|
|
|
|
if (req == PRU_SLOWTIMO || req == PRU_FASTTIMO)
|
|
|
|
printf("<%s>", tcptimers[timer]);
|
|
|
|
break;
|
|
|
|
}
|
1999-07-01 23:15:03 +04:00
|
|
|
|
|
|
|
skipact:
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
printf(" -> %s", tcpstates[tp->t_state]);
|
|
|
|
/* print out internal state of tp !?! */
|
|
|
|
printf("\n");
|
|
|
|
if (sflag) {
|
1997-07-23 12:19:59 +04:00
|
|
|
printf("\trcv_nxt %x rcv_wnd %lx snd_una %x snd_nxt %x snd_max %x\n",
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
tp->rcv_nxt, tp->rcv_wnd, tp->snd_una, tp->snd_nxt,
|
|
|
|
tp->snd_max);
|
1997-07-23 12:19:59 +04:00
|
|
|
printf("\tsnd_wl1 %x snd_wl2 %x snd_wnd %lx\n", tp->snd_wl1,
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
tp->snd_wl2, tp->snd_wnd);
|
|
|
|
}
|
|
|
|
/* print out timers? */
|
|
|
|
if (tflag) {
|
2005-02-06 08:00:46 +03:00
|
|
|
char *cp = "\t";
|
|
|
|
int i;
|
2003-02-04 04:22:08 +03:00
|
|
|
int hardticks;
|
|
|
|
|
2005-09-06 07:04:15 +04:00
|
|
|
if (use_sysctl) {
|
|
|
|
size_t len = sizeof(hardticks);
|
|
|
|
|
|
|
|
if (sysctlbyname("kern.hardclock_ticks", &hardticks,
|
|
|
|
&len, NULL, 0) == -1)
|
|
|
|
err(1, "kern.hardclock_ticks");
|
|
|
|
} else {
|
|
|
|
if (kvm_read(kd, nl[N_HARDCLOCK_TICKS].n_value,
|
|
|
|
(char *)&hardticks,
|
|
|
|
sizeof(hardticks)) != sizeof(hardticks))
|
|
|
|
errx(3, "hardclock_ticks: %s", kvm_geterr(kd));
|
|
|
|
|
|
|
|
for (i = 0; i < TCPT_NTIMERS; i++) {
|
|
|
|
if ((tp->t_timer[i].c_flags
|
|
|
|
& CALLOUT_PENDING) == 0)
|
|
|
|
continue;
|
|
|
|
printf("%s%s=%d", cp, tcptimers[i],
|
|
|
|
tp->t_timer[i].c_time - hardticks);
|
|
|
|
if (i == TCPT_REXMT)
|
|
|
|
printf(" (t_rxtshft=%d)",
|
|
|
|
tp->t_rxtshift);
|
|
|
|
cp = ", ";
|
|
|
|
}
|
|
|
|
if (*cp != '\t')
|
|
|
|
putchar('\n');
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-07-23 12:19:59 +04:00
|
|
|
int
|
2005-02-06 08:00:46 +03:00
|
|
|
numeric(const void *v1, const void *v2)
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
{
|
1997-07-23 20:27:50 +04:00
|
|
|
const caddr_t *c1 = v1;
|
|
|
|
const caddr_t *c2 = v2;
|
1997-07-23 20:41:43 +04:00
|
|
|
int rv;
|
1997-07-23 12:19:59 +04:00
|
|
|
|
1997-07-23 20:41:43 +04:00
|
|
|
if (*c1 < *c2)
|
|
|
|
rv = -1;
|
|
|
|
else if (*c1 > *c2)
|
|
|
|
rv = 1;
|
|
|
|
else
|
|
|
|
rv = 0;
|
|
|
|
|
|
|
|
return (rv);
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
}
|
|
|
|
|
1997-07-23 12:19:59 +04:00
|
|
|
void
|
2005-02-06 08:00:46 +03:00
|
|
|
usage(void)
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
{
|
|
|
|
|
1997-07-23 12:19:59 +04:00
|
|
|
(void) fprintf(stderr, "usage: %s [-afjst] [-p hex-address]"
|
2001-02-20 02:22:40 +03:00
|
|
|
" [-N system] [-M core]\n", getprogname());
|
1997-07-23 12:19:59 +04:00
|
|
|
exit(1);
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
}
|