2014-11-12 06:34:59 +03:00
|
|
|
/* $NetBSD: main.c,v 1.95 2014/11/12 03:34:59 christos Exp $ */
|
1995-10-04 00:42:34 +03:00
|
|
|
|
1993-03-21 21:04:42 +03:00
|
|
|
/*
|
1994-05-13 12:08:09 +04:00
|
|
|
* Copyright (c) 1983, 1988, 1993
|
|
|
|
* Regents of the University of California. All rights reserved.
|
1993-03-21 21:04:42 +03: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:13:06 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1993-03-21 21:04:42 +03: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-10-19 09:49:56 +04:00
|
|
|
#include <sys/cdefs.h>
|
1993-03-21 21:04:42 +03:00
|
|
|
#ifndef lint
|
2008-07-21 18:19:20 +04:00
|
|
|
__COPYRIGHT("@(#) Copyright (c) 1983, 1988, 1993\
|
|
|
|
Regents of the University of California. All rights reserved.");
|
1993-03-21 21:04:42 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#ifndef lint
|
1995-10-04 00:42:34 +03:00
|
|
|
#if 0
|
|
|
|
static char sccsid[] = "from: @(#)main.c 8.4 (Berkeley) 3/1/94";
|
|
|
|
#else
|
2014-11-12 06:34:59 +03:00
|
|
|
__RCSID("$NetBSD: main.c,v 1.95 2014/11/12 03:34:59 christos Exp $");
|
1995-10-04 00:42:34 +03:00
|
|
|
#endif
|
1993-03-21 21:04:42 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/file.h>
|
1994-05-13 12:08:09 +04:00
|
|
|
#include <sys/protosw.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
2002-07-03 05:42:59 +04:00
|
|
|
#include <net/if.h>
|
1994-05-13 12:08:09 +04:00
|
|
|
#include <netinet/in.h>
|
|
|
|
|
|
|
|
#include <ctype.h>
|
1998-07-06 11:50:18 +04:00
|
|
|
#include <err.h>
|
1993-03-21 21:04:42 +03:00
|
|
|
#include <errno.h>
|
1994-05-13 12:08:09 +04:00
|
|
|
#include <kvm.h>
|
|
|
|
#include <limits.h>
|
1993-03-21 21:04:42 +03:00
|
|
|
#include <netdb.h>
|
|
|
|
#include <nlist.h>
|
1994-05-13 12:08:09 +04:00
|
|
|
#include <paths.h>
|
1993-03-21 21:04:42 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
1994-05-13 12:08:09 +04:00
|
|
|
#include <unistd.h>
|
|
|
|
#include "netstat.h"
|
2014-11-07 00:30:09 +03:00
|
|
|
#include "rtutil.h"
|
2010-12-14 00:15:30 +03:00
|
|
|
#include "prog_ops.h"
|
1993-03-21 21:04:42 +03:00
|
|
|
|
|
|
|
struct nlist nl[] = {
|
|
|
|
#define N_MBSTAT 0
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_mbstat", 0, 0, 0, 0 },
|
1993-03-21 21:04:42 +03:00
|
|
|
#define N_IPSTAT 1
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_ipstat", 0, 0, 0, 0 }, /* not available via kvm */
|
1995-06-12 07:03:07 +04:00
|
|
|
#define N_TCBTABLE 2
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_tcbtable", 0, 0, 0, 0 },
|
1993-03-21 21:04:42 +03:00
|
|
|
#define N_TCPSTAT 3
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_tcpstat", 0, 0, 0, 0 }, /* not available via kvm */
|
1995-06-12 07:03:07 +04:00
|
|
|
#define N_UDBTABLE 4
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_udbtable", 0, 0, 0, 0 },
|
1993-03-21 21:04:42 +03:00
|
|
|
#define N_UDPSTAT 5
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_udpstat", 0, 0, 0, 0 }, /* not available via kvm */
|
2014-05-30 05:44:21 +04:00
|
|
|
#define N_IFNET_LIST 6
|
|
|
|
{ "_ifnet_list", 0, 0, 0, 0 },
|
2013-03-01 22:25:13 +04:00
|
|
|
#define N_ICMPSTAT 7
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_icmpstat", 0, 0, 0, 0 }, /* not available via kvm */
|
2013-03-01 22:25:13 +04:00
|
|
|
#define N_RTSTAT 8
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_rtstat", 0, 0, 0, 0 },
|
2013-03-01 22:25:13 +04:00
|
|
|
#define N_UNIXSW 9
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_unixsw", 0, 0, 0, 0 },
|
2013-03-01 22:25:13 +04:00
|
|
|
#define N_RTREE 10
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_rt_tables", 0, 0, 0, 0 },
|
2013-03-01 22:25:13 +04:00
|
|
|
#define N_NFILE 11
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_nfile", 0, 0, 0, 0 },
|
2013-03-01 22:25:13 +04:00
|
|
|
#define N_IGMPSTAT 12
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_igmpstat", 0, 0, 0, 0 }, /* not available via kvm */
|
2013-03-01 22:25:13 +04:00
|
|
|
#define N_MRTPROTO 13
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_ip_mrtproto", 0, 0, 0, 0 },
|
2013-03-01 22:25:13 +04:00
|
|
|
#define N_MRTSTAT 14
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_mrtstat", 0, 0, 0, 0 },
|
2013-03-01 22:25:13 +04:00
|
|
|
#define N_MFCHASHTBL 15
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_mfchashtbl", 0, 0, 0, 0 },
|
2013-03-01 22:25:13 +04:00
|
|
|
#define N_MFCHASH 16
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_mfchash", 0, 0, 0, 0 },
|
2013-03-01 22:25:13 +04:00
|
|
|
#define N_VIFTABLE 17
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_viftable", 0, 0, 0, 0 },
|
2013-03-01 22:25:13 +04:00
|
|
|
#define N_MSIZE 18
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_msize", 0, 0, 0, 0 },
|
2013-03-01 22:25:13 +04:00
|
|
|
#define N_MCLBYTES 19
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_mclbytes", 0, 0, 0, 0 },
|
2013-03-01 22:25:13 +04:00
|
|
|
#define N_DDPSTAT 20
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_ddpstat", 0, 0, 0, 0 }, /* not available via kvm */
|
2013-03-01 22:25:13 +04:00
|
|
|
#define N_DDPCB 21
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_ddpcb", 0, 0, 0, 0 },
|
2013-03-01 22:25:13 +04:00
|
|
|
#define N_MBPOOL 22
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_mbpool", 0, 0, 0, 0 },
|
2013-03-01 22:25:13 +04:00
|
|
|
#define N_MCLPOOL 23
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_mclpool", 0, 0, 0, 0 },
|
2013-03-01 22:25:13 +04:00
|
|
|
#define N_IP6STAT 24
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_ip6stat", 0, 0, 0, 0 }, /* not available via kvm */
|
2013-03-01 22:25:13 +04:00
|
|
|
#define N_TCP6STAT 25
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_tcp6stat", 0, 0, 0, 0 }, /* not available via kvm */
|
2013-03-01 22:25:13 +04:00
|
|
|
#define N_UDP6STAT 26
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_udp6stat", 0, 0, 0, 0 }, /* not available via kvm */
|
2013-03-01 22:25:13 +04:00
|
|
|
#define N_ICMP6STAT 27
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_icmp6stat", 0, 0, 0, 0 }, /* not available via kvm */
|
2013-03-01 22:25:13 +04:00
|
|
|
#define N_IPSECSTAT 28
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_ipsecstat", 0, 0, 0, 0 }, /* not available via kvm */
|
2013-03-01 22:25:13 +04:00
|
|
|
#define N_IPSEC6STAT 29
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_ipsec6stat", 0, 0, 0, 0 }, /* not available via kvm */
|
2013-03-01 22:25:13 +04:00
|
|
|
#define N_PIM6STAT 30
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_pim6stat", 0, 0, 0, 0 }, /* not available via kvm */
|
2013-03-01 22:25:13 +04:00
|
|
|
#define N_MRT6PROTO 31
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_ip6_mrtproto", 0, 0, 0, 0 },
|
2013-03-01 22:25:13 +04:00
|
|
|
#define N_MRT6STAT 32
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_mrt6stat", 0, 0, 0, 0 },
|
2013-03-01 22:25:13 +04:00
|
|
|
#define N_MF6CTABLE 33
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_mf6ctable", 0, 0, 0, 0 },
|
2013-03-01 22:25:13 +04:00
|
|
|
#define N_MIF6TABLE 34
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_mif6table", 0, 0, 0, 0 },
|
2013-03-01 22:25:13 +04:00
|
|
|
#define N_PFKEYSTAT 35
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_pfkeystat", 0, 0, 0, 0 }, /* not available via kvm */
|
2013-03-01 22:25:13 +04:00
|
|
|
#define N_ARPSTAT 36
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_arpstat", 0, 0, 0, 0 }, /* not available via kvm */
|
2013-03-01 22:25:13 +04:00
|
|
|
#define N_RIP6STAT 37
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_rip6stat", 0, 0, 0, 0 }, /* not available via kvm */
|
2013-03-01 22:25:13 +04:00
|
|
|
#define N_ARPINTRQ 38
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_arpintrq", 0, 0, 0, 0 },
|
2013-03-01 22:25:13 +04:00
|
|
|
#define N_IPINTRQ 39
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_ipintrq", 0, 0, 0, 0 },
|
2013-03-01 22:25:13 +04:00
|
|
|
#define N_IP6INTRQ 40
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_ip6intrq", 0, 0, 0, 0 },
|
2013-03-01 22:25:13 +04:00
|
|
|
#define N_ATINTRQ1 41
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_atintrq1", 0, 0, 0, 0 },
|
2013-03-01 22:25:13 +04:00
|
|
|
#define N_ATINTRQ2 42
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_atintrq2", 0, 0, 0, 0 },
|
2013-03-01 22:25:13 +04:00
|
|
|
#define N_NSINTRQ 43
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_nsintrq", 0, 0, 0, 0 },
|
2013-03-01 22:25:13 +04:00
|
|
|
#define N_LLCINTRQ 44
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_llcintrq", 0, 0, 0, 0 },
|
2013-03-01 22:25:13 +04:00
|
|
|
#define N_HDINTRQ 45
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_hdintrq", 0, 0, 0, 0 },
|
2013-03-01 22:25:13 +04:00
|
|
|
#define N_NATMINTRQ 46
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_natmintrq", 0, 0, 0, 0 },
|
2013-03-01 22:25:13 +04:00
|
|
|
#define N_PPPOEDISCINQ 47
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_ppoediscinq", 0, 0, 0, 0 },
|
2013-03-01 22:25:13 +04:00
|
|
|
#define N_PPPOEINQ 48
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_ppoeinq", 0, 0, 0, 0 },
|
2013-03-01 22:25:13 +04:00
|
|
|
#define N_PKINTRQ 49
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_pkintrq", 0, 0, 0, 0 },
|
2013-03-01 22:25:13 +04:00
|
|
|
#define N_HARDCLOCK_TICKS 50
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_hardclock_ticks", 0, 0, 0, 0 },
|
2013-03-01 22:25:13 +04:00
|
|
|
#define N_PIMSTAT 51
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_pimstat", 0, 0, 0, 0 },
|
2013-03-01 22:25:13 +04:00
|
|
|
#define N_CARPSTAT 52
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "_carpstats", 0, 0, 0, 0 }, /* not available via kvm */
|
2013-03-01 22:25:13 +04:00
|
|
|
#define N_PFSYNCSTAT 53
|
2009-09-14 14:36:48 +04:00
|
|
|
{ "_pfsyncstats", 0, 0, 0, 0}, /* not available via kvm */
|
2009-04-12 20:08:37 +04:00
|
|
|
{ "", 0, 0, 0, 0 },
|
1993-03-21 21:04:42 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct protox {
|
|
|
|
u_char pr_index; /* index into nlist of cb head */
|
|
|
|
u_char pr_sindex; /* index into nlist of stat block */
|
|
|
|
u_char pr_wanted; /* 1 if wanted, 0 otherwise */
|
1997-04-03 08:46:44 +04:00
|
|
|
void (*pr_cblocks) /* control blocks printing routine */
|
2009-04-12 20:08:37 +04:00
|
|
|
__P((u_long, const char *));
|
1997-04-03 08:46:44 +04:00
|
|
|
void (*pr_stats) /* statistics printing routine */
|
2009-04-12 20:08:37 +04:00
|
|
|
__P((u_long, const char *));
|
1999-12-13 18:22:55 +03:00
|
|
|
void (*pr_istats)
|
2009-04-12 20:08:37 +04:00
|
|
|
__P((const char *)); /* per/if statistics printing routine */
|
1998-06-03 06:41:10 +04:00
|
|
|
void (*pr_dump) /* PCB state dump routine */
|
2013-06-20 01:12:03 +04:00
|
|
|
__P((u_long, const char *, u_long));
|
2009-04-12 20:08:37 +04:00
|
|
|
const char *pr_name; /* well-known name */
|
1993-03-21 21:04:42 +03:00
|
|
|
} protox[] = {
|
1995-06-12 07:03:07 +04:00
|
|
|
{ N_TCBTABLE, N_TCPSTAT, 1, protopr,
|
1999-12-13 18:22:55 +03:00
|
|
|
tcp_stats, NULL, tcp_dump, "tcp" },
|
1995-06-12 07:03:07 +04:00
|
|
|
{ N_UDBTABLE, N_UDPSTAT, 1, protopr,
|
1999-12-13 18:22:55 +03:00
|
|
|
udp_stats, NULL, 0, "udp" },
|
1993-03-21 21:04:42 +03:00
|
|
|
{ -1, N_IPSTAT, 1, 0,
|
1999-12-13 18:22:55 +03:00
|
|
|
ip_stats, NULL, 0, "ip" },
|
1993-03-21 21:04:42 +03:00
|
|
|
{ -1, N_ICMPSTAT, 1, 0,
|
1999-12-13 18:22:55 +03:00
|
|
|
icmp_stats, NULL, 0, "icmp" },
|
1994-01-11 22:42:48 +03:00
|
|
|
{ -1, N_IGMPSTAT, 1, 0,
|
1999-12-13 18:22:55 +03:00
|
|
|
igmp_stats, NULL, 0, "igmp" },
|
2006-05-18 13:05:49 +04:00
|
|
|
{ -1, N_CARPSTAT, 1, 0,
|
|
|
|
carp_stats, NULL, 0, "carp" },
|
1999-07-01 22:40:35 +04:00
|
|
|
#ifdef IPSEC
|
|
|
|
{ -1, N_IPSECSTAT, 1, 0,
|
2012-03-23 00:34:37 +04:00
|
|
|
fast_ipsec_stats, NULL, 0, "ipsec" },
|
1999-07-01 22:40:35 +04:00
|
|
|
#endif
|
2004-09-05 03:35:43 +04:00
|
|
|
{ -1, N_PIMSTAT, 1, 0,
|
|
|
|
pim_stats, NULL, 0, "pim" },
|
2009-09-14 14:36:48 +04:00
|
|
|
{ -1, N_PFSYNCSTAT, 1, 0,
|
|
|
|
pfsync_stats, NULL, 0, "pfsync" },
|
1999-07-01 22:40:35 +04:00
|
|
|
{ -1, -1, 0, 0,
|
1999-12-13 18:22:55 +03:00
|
|
|
0, NULL, 0, 0 }
|
1999-07-01 22:40:35 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef INET6
|
|
|
|
struct protox ip6protox[] = {
|
|
|
|
{ -1, N_IP6STAT, 1, 0,
|
1999-12-13 18:22:55 +03:00
|
|
|
ip6_stats, ip6_ifstats, 0, "ip6" },
|
1999-07-01 22:40:35 +04:00
|
|
|
{ -1, N_ICMP6STAT, 1, 0,
|
1999-12-13 18:22:55 +03:00
|
|
|
icmp6_stats, icmp6_ifstats, 0, "icmp6" },
|
1999-07-01 22:40:35 +04:00
|
|
|
#ifdef TCP6
|
2003-09-04 13:23:35 +04:00
|
|
|
{ N_TCBTABLE, N_TCP6STAT, 1, ip6protopr,
|
1999-12-13 18:22:55 +03:00
|
|
|
tcp6_stats, NULL, tcp6_dump, "tcp6" },
|
1999-07-01 22:40:35 +04:00
|
|
|
#else
|
2003-09-04 13:23:35 +04:00
|
|
|
{ N_TCBTABLE, N_TCP6STAT, 1, ip6protopr,
|
2013-11-24 02:01:12 +04:00
|
|
|
tcp_stats, NULL, tcp6_dump, "tcp6" },
|
1999-07-01 22:40:35 +04:00
|
|
|
#endif
|
2003-09-04 13:23:35 +04:00
|
|
|
{ N_UDBTABLE, N_UDP6STAT, 1, ip6protopr,
|
1999-12-13 18:22:55 +03:00
|
|
|
udp6_stats, NULL, 0, "udp6" },
|
1999-07-01 22:40:35 +04:00
|
|
|
#ifdef IPSEC
|
|
|
|
{ -1, N_IPSEC6STAT, 1, 0,
|
2012-03-23 00:34:37 +04:00
|
|
|
fast_ipsec_stats, NULL, 0, "ipsec6" },
|
1999-07-01 22:40:35 +04:00
|
|
|
#endif
|
|
|
|
{ -1, N_PIM6STAT, 1, 0,
|
1999-12-13 18:22:55 +03:00
|
|
|
pim6_stats, NULL, 0, "pim6" },
|
2001-10-18 13:26:16 +04:00
|
|
|
{ -1, N_RIP6STAT, 1, 0,
|
|
|
|
rip6_stats, NULL, 0, "rip6" },
|
1993-03-21 21:04:42 +03:00
|
|
|
{ -1, -1, 0, 0,
|
1999-12-13 18:22:55 +03:00
|
|
|
0, NULL, 0, 0 }
|
1993-03-21 21:04:42 +03:00
|
|
|
};
|
1999-07-01 22:40:35 +04:00
|
|
|
#endif
|
1993-03-21 21:04:42 +03:00
|
|
|
|
2000-08-16 00:24:57 +04:00
|
|
|
struct protox arpprotox[] = {
|
|
|
|
{ -1, N_ARPSTAT, 1, 0,
|
|
|
|
arp_stats, NULL, 0, "arp" },
|
2000-10-28 07:53:33 +04:00
|
|
|
{ -1, -1, 0, 0,
|
|
|
|
0, NULL, 0, 0 }
|
2000-08-16 00:24:57 +04:00
|
|
|
};
|
|
|
|
|
2000-02-26 12:55:24 +03:00
|
|
|
#ifdef IPSEC
|
|
|
|
struct protox pfkeyprotox[] = {
|
|
|
|
{ -1, N_PFKEYSTAT, 1, 0,
|
|
|
|
pfkey_stats, NULL, 0, "pfkey" },
|
|
|
|
{ -1, -1, 0, 0,
|
|
|
|
0, NULL, 0, 0 }
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
1999-01-11 15:31:53 +03:00
|
|
|
#ifndef SMALL
|
1997-04-03 08:46:44 +04:00
|
|
|
struct protox atalkprotox[] = {
|
|
|
|
{ N_DDPCB, N_DDPSTAT, 1, atalkprotopr,
|
1999-12-13 18:22:55 +03:00
|
|
|
ddp_stats, NULL, 0, "ddp" },
|
1997-04-03 08:46:44 +04:00
|
|
|
{ -1, -1, 0, 0,
|
2009-04-12 20:08:37 +04:00
|
|
|
0, NULL, 0, NULL }
|
1997-04-03 08:46:44 +04:00
|
|
|
};
|
1999-01-11 15:31:53 +03:00
|
|
|
#endif
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1999-01-11 15:31:53 +03:00
|
|
|
struct protox *protoprotox[] = { protox,
|
1999-07-01 22:40:35 +04:00
|
|
|
#ifdef INET6
|
|
|
|
ip6protox,
|
|
|
|
#endif
|
2000-08-16 00:24:57 +04:00
|
|
|
arpprotox,
|
2000-02-26 12:55:24 +03:00
|
|
|
#ifdef IPSEC
|
|
|
|
pfkeyprotox,
|
|
|
|
#endif
|
1999-01-11 15:31:53 +03:00
|
|
|
#ifndef SMALL
|
2006-08-26 19:33:20 +04:00
|
|
|
atalkprotox,
|
1999-01-11 15:31:53 +03:00
|
|
|
#endif
|
|
|
|
NULL };
|
1993-03-21 21:04:42 +03:00
|
|
|
|
2002-07-03 05:42:59 +04:00
|
|
|
const struct softintrq {
|
|
|
|
const char *siq_name;
|
|
|
|
int siq_index;
|
|
|
|
} softintrq[] = {
|
|
|
|
{ "arpintrq", N_ARPINTRQ },
|
|
|
|
{ "ipintrq", N_IPINTRQ },
|
|
|
|
{ "ip6intrq", N_IP6INTRQ },
|
|
|
|
{ "atintrq1", N_ATINTRQ1 },
|
|
|
|
{ "atintrq2", N_ATINTRQ2 },
|
|
|
|
{ "llcintrq", N_LLCINTRQ },
|
|
|
|
{ "hdintrq", N_HDINTRQ },
|
|
|
|
{ "natmintrq", N_NATMINTRQ },
|
2002-07-24 03:34:39 +04:00
|
|
|
{ "ppoediscinq", N_PPPOEDISCINQ },
|
|
|
|
{ "ppoeinq", N_PPPOEINQ },
|
|
|
|
{ "pkintrq", N_PKINTRQ },
|
2002-07-03 05:42:59 +04:00
|
|
|
{ NULL, -1 },
|
|
|
|
};
|
|
|
|
|
1997-04-03 08:46:44 +04:00
|
|
|
int main __P((int, char *[]));
|
2009-04-12 20:08:37 +04:00
|
|
|
static void printproto __P((struct protox *, const char *));
|
2002-07-03 05:42:59 +04:00
|
|
|
static void print_softintrq __P((void));
|
2011-09-16 19:39:25 +04:00
|
|
|
__dead static void usage(void);
|
2009-04-12 20:08:37 +04:00
|
|
|
static struct protox *name2protox __P((const char *));
|
|
|
|
static struct protox *knownname __P((const char *));
|
Reduces the resources demanded by TCP sessions in TIME_WAIT-state using
methods called Vestigial Time-Wait (VTW) and Maximum Segment Lifetime
Truncation (MSLT).
MSLT and VTW were contributed by Coyote Point Systems, Inc.
Even after a TCP session enters the TIME_WAIT state, its corresponding
socket and protocol control blocks (PCBs) stick around until the TCP
Maximum Segment Lifetime (MSL) expires. On a host whose workload
necessarily creates and closes down many TCP sockets, the sockets & PCBs
for TCP sessions in TIME_WAIT state amount to many megabytes of dead
weight in RAM.
Maximum Segment Lifetimes Truncation (MSLT) assigns each TCP session to
a class based on the nearness of the peer. Corresponding to each class
is an MSL, and a session uses the MSL of its class. The classes are
loopback (local host equals remote host), local (local host and remote
host are on the same link/subnet), and remote (local host and remote
host communicate via one or more gateways). Classes corresponding to
nearer peers have lower MSLs by default: 2 seconds for loopback, 10
seconds for local, 60 seconds for remote. Loopback and local sessions
expire more quickly when MSLT is used.
Vestigial Time-Wait (VTW) replaces a TIME_WAIT session's PCB/socket
dead weight with a compact representation of the session, called a
"vestigial PCB". VTW data structures are designed to be very fast and
memory-efficient: for fast insertion and lookup of vestigial PCBs,
the PCBs are stored in a hash table that is designed to minimize the
number of cacheline visits per lookup/insertion. The memory both
for vestigial PCBs and for elements of the PCB hashtable come from
fixed-size pools, and linked data structures exploit this to conserve
memory by representing references with a narrow index/offset from the
start of a pool instead of a pointer. When space for new vestigial PCBs
runs out, VTW makes room by discarding old vestigial PCBs, oldest first.
VTW cooperates with MSLT.
It may help to think of VTW as a "FIN cache" by analogy to the SYN
cache.
A 2.8-GHz Pentium 4 running a test workload that creates TIME_WAIT
sessions as fast as it can is approximately 17% idle when VTW is active
versus 0% idle when VTW is inactive. It has 103 megabytes more free RAM
when VTW is active (approximately 64k vestigial PCBs are created) than
when it is inactive.
2011-05-03 22:28:44 +04:00
|
|
|
static void prepare(const char *, const char *, struct protox *tp);
|
2011-05-04 05:13:35 +04:00
|
|
|
static kvm_t *prepare_kvmd(const char *, const char *, char *);
|
1993-03-21 21:04:42 +03:00
|
|
|
|
2011-05-04 05:13:35 +04:00
|
|
|
static kvm_t *kvmd = NULL;
|
2006-10-13 20:33:57 +04:00
|
|
|
gid_t egid;
|
2009-04-12 20:08:37 +04:00
|
|
|
int interval; /* repeat interval for i/f stats */
|
Reduces the resources demanded by TCP sessions in TIME_WAIT-state using
methods called Vestigial Time-Wait (VTW) and Maximum Segment Lifetime
Truncation (MSLT).
MSLT and VTW were contributed by Coyote Point Systems, Inc.
Even after a TCP session enters the TIME_WAIT state, its corresponding
socket and protocol control blocks (PCBs) stick around until the TCP
Maximum Segment Lifetime (MSL) expires. On a host whose workload
necessarily creates and closes down many TCP sockets, the sockets & PCBs
for TCP sessions in TIME_WAIT state amount to many megabytes of dead
weight in RAM.
Maximum Segment Lifetimes Truncation (MSLT) assigns each TCP session to
a class based on the nearness of the peer. Corresponding to each class
is an MSL, and a session uses the MSL of its class. The classes are
loopback (local host equals remote host), local (local host and remote
host are on the same link/subnet), and remote (local host and remote
host communicate via one or more gateways). Classes corresponding to
nearer peers have lower MSLs by default: 2 seconds for loopback, 10
seconds for local, 60 seconds for remote. Loopback and local sessions
expire more quickly when MSLT is used.
Vestigial Time-Wait (VTW) replaces a TIME_WAIT session's PCB/socket
dead weight with a compact representation of the session, called a
"vestigial PCB". VTW data structures are designed to be very fast and
memory-efficient: for fast insertion and lookup of vestigial PCBs,
the PCBs are stored in a hash table that is designed to minimize the
number of cacheline visits per lookup/insertion. The memory both
for vestigial PCBs and for elements of the PCB hashtable come from
fixed-size pools, and linked data structures exploit this to conserve
memory by representing references with a narrow index/offset from the
start of a pool instead of a pointer. When space for new vestigial PCBs
runs out, VTW makes room by discarding old vestigial PCBs, oldest first.
VTW cooperates with MSLT.
It may help to think of VTW as a "FIN cache" by analogy to the SYN
cache.
A 2.8-GHz Pentium 4 running a test workload that creates TIME_WAIT
sessions as fast as it can is approximately 17% idle when VTW is active
versus 0% idle when VTW is inactive. It has 103 megabytes more free RAM
when VTW is active (approximately 64k vestigial PCBs are created) than
when it is inactive.
2011-05-03 22:28:44 +04:00
|
|
|
static const char *nlistf = NULL, *memf = NULL;
|
2006-10-13 20:33:57 +04:00
|
|
|
|
Reduces the resources demanded by TCP sessions in TIME_WAIT-state using
methods called Vestigial Time-Wait (VTW) and Maximum Segment Lifetime
Truncation (MSLT).
MSLT and VTW were contributed by Coyote Point Systems, Inc.
Even after a TCP session enters the TIME_WAIT state, its corresponding
socket and protocol control blocks (PCBs) stick around until the TCP
Maximum Segment Lifetime (MSL) expires. On a host whose workload
necessarily creates and closes down many TCP sockets, the sockets & PCBs
for TCP sessions in TIME_WAIT state amount to many megabytes of dead
weight in RAM.
Maximum Segment Lifetimes Truncation (MSLT) assigns each TCP session to
a class based on the nearness of the peer. Corresponding to each class
is an MSL, and a session uses the MSL of its class. The classes are
loopback (local host equals remote host), local (local host and remote
host are on the same link/subnet), and remote (local host and remote
host communicate via one or more gateways). Classes corresponding to
nearer peers have lower MSLs by default: 2 seconds for loopback, 10
seconds for local, 60 seconds for remote. Loopback and local sessions
expire more quickly when MSLT is used.
Vestigial Time-Wait (VTW) replaces a TIME_WAIT session's PCB/socket
dead weight with a compact representation of the session, called a
"vestigial PCB". VTW data structures are designed to be very fast and
memory-efficient: for fast insertion and lookup of vestigial PCBs,
the PCBs are stored in a hash table that is designed to minimize the
number of cacheline visits per lookup/insertion. The memory both
for vestigial PCBs and for elements of the PCB hashtable come from
fixed-size pools, and linked data structures exploit this to conserve
memory by representing references with a narrow index/offset from the
start of a pool instead of a pointer. When space for new vestigial PCBs
runs out, VTW makes room by discarding old vestigial PCBs, oldest first.
VTW cooperates with MSLT.
It may help to think of VTW as a "FIN cache" by analogy to the SYN
cache.
A 2.8-GHz Pentium 4 running a test workload that creates TIME_WAIT
sessions as fast as it can is approximately 17% idle when VTW is active
versus 0% idle when VTW is inactive. It has 103 megabytes more free RAM
when VTW is active (approximately 64k vestigial PCBs are created) than
when it is inactive.
2011-05-03 22:28:44 +04:00
|
|
|
kvm_t *
|
|
|
|
get_kvmd(void)
|
|
|
|
{
|
2011-05-04 05:13:35 +04:00
|
|
|
char buf[_POSIX2_LINE_MAX];
|
|
|
|
|
|
|
|
if (kvmd != NULL)
|
|
|
|
return kvmd;
|
|
|
|
if ((kvmd = prepare_kvmd(nlistf, memf, buf)) == NULL)
|
2011-07-17 14:22:07 +04:00
|
|
|
errx(1, "kvm error: %s", buf);
|
2011-05-04 05:13:35 +04:00
|
|
|
return kvmd;
|
Reduces the resources demanded by TCP sessions in TIME_WAIT-state using
methods called Vestigial Time-Wait (VTW) and Maximum Segment Lifetime
Truncation (MSLT).
MSLT and VTW were contributed by Coyote Point Systems, Inc.
Even after a TCP session enters the TIME_WAIT state, its corresponding
socket and protocol control blocks (PCBs) stick around until the TCP
Maximum Segment Lifetime (MSL) expires. On a host whose workload
necessarily creates and closes down many TCP sockets, the sockets & PCBs
for TCP sessions in TIME_WAIT state amount to many megabytes of dead
weight in RAM.
Maximum Segment Lifetimes Truncation (MSLT) assigns each TCP session to
a class based on the nearness of the peer. Corresponding to each class
is an MSL, and a session uses the MSL of its class. The classes are
loopback (local host equals remote host), local (local host and remote
host are on the same link/subnet), and remote (local host and remote
host communicate via one or more gateways). Classes corresponding to
nearer peers have lower MSLs by default: 2 seconds for loopback, 10
seconds for local, 60 seconds for remote. Loopback and local sessions
expire more quickly when MSLT is used.
Vestigial Time-Wait (VTW) replaces a TIME_WAIT session's PCB/socket
dead weight with a compact representation of the session, called a
"vestigial PCB". VTW data structures are designed to be very fast and
memory-efficient: for fast insertion and lookup of vestigial PCBs,
the PCBs are stored in a hash table that is designed to minimize the
number of cacheline visits per lookup/insertion. The memory both
for vestigial PCBs and for elements of the PCB hashtable come from
fixed-size pools, and linked data structures exploit this to conserve
memory by representing references with a narrow index/offset from the
start of a pool instead of a pointer. When space for new vestigial PCBs
runs out, VTW makes room by discarding old vestigial PCBs, oldest first.
VTW cooperates with MSLT.
It may help to think of VTW as a "FIN cache" by analogy to the SYN
cache.
A 2.8-GHz Pentium 4 running a test workload that creates TIME_WAIT
sessions as fast as it can is approximately 17% idle when VTW is active
versus 0% idle when VTW is inactive. It has 103 megabytes more free RAM
when VTW is active (approximately 64k vestigial PCBs are created) than
when it is inactive.
2011-05-03 22:28:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static kvm_t *
|
2011-05-04 05:13:35 +04:00
|
|
|
prepare_kvmd(const char *nf, const char *mf, char *errbuf)
|
2006-10-13 20:33:57 +04:00
|
|
|
{
|
2011-05-04 05:13:35 +04:00
|
|
|
kvm_t *k;
|
2006-10-13 20:33:57 +04:00
|
|
|
|
Reduces the resources demanded by TCP sessions in TIME_WAIT-state using
methods called Vestigial Time-Wait (VTW) and Maximum Segment Lifetime
Truncation (MSLT).
MSLT and VTW were contributed by Coyote Point Systems, Inc.
Even after a TCP session enters the TIME_WAIT state, its corresponding
socket and protocol control blocks (PCBs) stick around until the TCP
Maximum Segment Lifetime (MSL) expires. On a host whose workload
necessarily creates and closes down many TCP sockets, the sockets & PCBs
for TCP sessions in TIME_WAIT state amount to many megabytes of dead
weight in RAM.
Maximum Segment Lifetimes Truncation (MSLT) assigns each TCP session to
a class based on the nearness of the peer. Corresponding to each class
is an MSL, and a session uses the MSL of its class. The classes are
loopback (local host equals remote host), local (local host and remote
host are on the same link/subnet), and remote (local host and remote
host communicate via one or more gateways). Classes corresponding to
nearer peers have lower MSLs by default: 2 seconds for loopback, 10
seconds for local, 60 seconds for remote. Loopback and local sessions
expire more quickly when MSLT is used.
Vestigial Time-Wait (VTW) replaces a TIME_WAIT session's PCB/socket
dead weight with a compact representation of the session, called a
"vestigial PCB". VTW data structures are designed to be very fast and
memory-efficient: for fast insertion and lookup of vestigial PCBs,
the PCBs are stored in a hash table that is designed to minimize the
number of cacheline visits per lookup/insertion. The memory both
for vestigial PCBs and for elements of the PCB hashtable come from
fixed-size pools, and linked data structures exploit this to conserve
memory by representing references with a narrow index/offset from the
start of a pool instead of a pointer. When space for new vestigial PCBs
runs out, VTW makes room by discarding old vestigial PCBs, oldest first.
VTW cooperates with MSLT.
It may help to think of VTW as a "FIN cache" by analogy to the SYN
cache.
A 2.8-GHz Pentium 4 running a test workload that creates TIME_WAIT
sessions as fast as it can is approximately 17% idle when VTW is active
versus 0% idle when VTW is inactive. It has 103 megabytes more free RAM
when VTW is active (approximately 64k vestigial PCBs are created) than
when it is inactive.
2011-05-03 22:28:44 +04:00
|
|
|
(void)setegid(egid);
|
2011-05-04 05:13:35 +04:00
|
|
|
k = kvm_openfiles(nf, mf, NULL, O_RDONLY, errbuf);
|
Reduces the resources demanded by TCP sessions in TIME_WAIT-state using
methods called Vestigial Time-Wait (VTW) and Maximum Segment Lifetime
Truncation (MSLT).
MSLT and VTW were contributed by Coyote Point Systems, Inc.
Even after a TCP session enters the TIME_WAIT state, its corresponding
socket and protocol control blocks (PCBs) stick around until the TCP
Maximum Segment Lifetime (MSL) expires. On a host whose workload
necessarily creates and closes down many TCP sockets, the sockets & PCBs
for TCP sessions in TIME_WAIT state amount to many megabytes of dead
weight in RAM.
Maximum Segment Lifetimes Truncation (MSLT) assigns each TCP session to
a class based on the nearness of the peer. Corresponding to each class
is an MSL, and a session uses the MSL of its class. The classes are
loopback (local host equals remote host), local (local host and remote
host are on the same link/subnet), and remote (local host and remote
host communicate via one or more gateways). Classes corresponding to
nearer peers have lower MSLs by default: 2 seconds for loopback, 10
seconds for local, 60 seconds for remote. Loopback and local sessions
expire more quickly when MSLT is used.
Vestigial Time-Wait (VTW) replaces a TIME_WAIT session's PCB/socket
dead weight with a compact representation of the session, called a
"vestigial PCB". VTW data structures are designed to be very fast and
memory-efficient: for fast insertion and lookup of vestigial PCBs,
the PCBs are stored in a hash table that is designed to minimize the
number of cacheline visits per lookup/insertion. The memory both
for vestigial PCBs and for elements of the PCB hashtable come from
fixed-size pools, and linked data structures exploit this to conserve
memory by representing references with a narrow index/offset from the
start of a pool instead of a pointer. When space for new vestigial PCBs
runs out, VTW makes room by discarding old vestigial PCBs, oldest first.
VTW cooperates with MSLT.
It may help to think of VTW as a "FIN cache" by analogy to the SYN
cache.
A 2.8-GHz Pentium 4 running a test workload that creates TIME_WAIT
sessions as fast as it can is approximately 17% idle when VTW is active
versus 0% idle when VTW is inactive. It has 103 megabytes more free RAM
when VTW is active (approximately 64k vestigial PCBs are created) than
when it is inactive.
2011-05-03 22:28:44 +04:00
|
|
|
(void)setgid(getgid());
|
2011-05-04 05:13:35 +04:00
|
|
|
return k;
|
Reduces the resources demanded by TCP sessions in TIME_WAIT-state using
methods called Vestigial Time-Wait (VTW) and Maximum Segment Lifetime
Truncation (MSLT).
MSLT and VTW were contributed by Coyote Point Systems, Inc.
Even after a TCP session enters the TIME_WAIT state, its corresponding
socket and protocol control blocks (PCBs) stick around until the TCP
Maximum Segment Lifetime (MSL) expires. On a host whose workload
necessarily creates and closes down many TCP sockets, the sockets & PCBs
for TCP sessions in TIME_WAIT state amount to many megabytes of dead
weight in RAM.
Maximum Segment Lifetimes Truncation (MSLT) assigns each TCP session to
a class based on the nearness of the peer. Corresponding to each class
is an MSL, and a session uses the MSL of its class. The classes are
loopback (local host equals remote host), local (local host and remote
host are on the same link/subnet), and remote (local host and remote
host communicate via one or more gateways). Classes corresponding to
nearer peers have lower MSLs by default: 2 seconds for loopback, 10
seconds for local, 60 seconds for remote. Loopback and local sessions
expire more quickly when MSLT is used.
Vestigial Time-Wait (VTW) replaces a TIME_WAIT session's PCB/socket
dead weight with a compact representation of the session, called a
"vestigial PCB". VTW data structures are designed to be very fast and
memory-efficient: for fast insertion and lookup of vestigial PCBs,
the PCBs are stored in a hash table that is designed to minimize the
number of cacheline visits per lookup/insertion. The memory both
for vestigial PCBs and for elements of the PCB hashtable come from
fixed-size pools, and linked data structures exploit this to conserve
memory by representing references with a narrow index/offset from the
start of a pool instead of a pointer. When space for new vestigial PCBs
runs out, VTW makes room by discarding old vestigial PCBs, oldest first.
VTW cooperates with MSLT.
It may help to think of VTW as a "FIN cache" by analogy to the SYN
cache.
A 2.8-GHz Pentium 4 running a test workload that creates TIME_WAIT
sessions as fast as it can is approximately 17% idle when VTW is active
versus 0% idle when VTW is inactive. It has 103 megabytes more free RAM
when VTW is active (approximately 64k vestigial PCBs are created) than
when it is inactive.
2011-05-03 22:28:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
prepare(const char *nf, const char *mf, struct protox *tp)
|
|
|
|
{
|
2011-05-04 05:13:35 +04:00
|
|
|
char buf[_POSIX2_LINE_MAX];
|
2006-10-13 20:33:57 +04:00
|
|
|
/*
|
|
|
|
* Try to figure out if we can use sysctl or not.
|
|
|
|
*/
|
2014-10-10 03:45:47 +04:00
|
|
|
if (nf != NULL || mf != NULL) {
|
2009-09-13 06:53:17 +04:00
|
|
|
/* Of course, we can't use sysctl with dumps. */
|
|
|
|
if (force_sysctl)
|
|
|
|
errx(EXIT_FAILURE, "can't use sysctl with dumps");
|
|
|
|
|
2014-10-10 03:45:47 +04:00
|
|
|
/*
|
|
|
|
* If we have -M or -N, we're not dealing with live memory
|
|
|
|
* or want to use kvm interface explicitly. It is sometimes
|
|
|
|
* useful to dig inside of kernel without extending
|
|
|
|
* sysctl interface (i.e., without rebuilding kernel).
|
|
|
|
*/
|
2006-10-13 20:33:57 +04:00
|
|
|
use_sysctl = 0;
|
2011-05-04 05:13:35 +04:00
|
|
|
} else if (qflag ||
|
2006-10-13 20:33:57 +04:00
|
|
|
iflag ||
|
2006-11-15 14:55:00 +03:00
|
|
|
#ifndef SMALL
|
2006-10-13 20:33:57 +04:00
|
|
|
gflag ||
|
2007-04-27 22:37:53 +04:00
|
|
|
#endif
|
|
|
|
(pflag && tp->pr_sindex == N_PIMSTAT) ||
|
2006-10-13 20:33:57 +04:00
|
|
|
Pflag) {
|
|
|
|
/* These flags are not yet supported via sysctl(3). */
|
|
|
|
use_sysctl = 0;
|
|
|
|
} else {
|
|
|
|
/* We can use sysctl(3). */
|
|
|
|
use_sysctl = 1;
|
|
|
|
}
|
|
|
|
|
2009-09-13 06:53:17 +04:00
|
|
|
if (force_sysctl && !use_sysctl) {
|
|
|
|
/* Let the user know what's about to happen. */
|
|
|
|
warnx("forcing sysctl usage even though it might not be "\
|
|
|
|
"supported");
|
|
|
|
use_sysctl = 1;
|
|
|
|
}
|
|
|
|
|
2011-05-04 05:13:35 +04:00
|
|
|
kvmd = prepare_kvmd(nf, mf, buf);
|
|
|
|
|
2006-10-13 20:33:57 +04:00
|
|
|
if (!use_sysctl) {
|
Reduces the resources demanded by TCP sessions in TIME_WAIT-state using
methods called Vestigial Time-Wait (VTW) and Maximum Segment Lifetime
Truncation (MSLT).
MSLT and VTW were contributed by Coyote Point Systems, Inc.
Even after a TCP session enters the TIME_WAIT state, its corresponding
socket and protocol control blocks (PCBs) stick around until the TCP
Maximum Segment Lifetime (MSL) expires. On a host whose workload
necessarily creates and closes down many TCP sockets, the sockets & PCBs
for TCP sessions in TIME_WAIT state amount to many megabytes of dead
weight in RAM.
Maximum Segment Lifetimes Truncation (MSLT) assigns each TCP session to
a class based on the nearness of the peer. Corresponding to each class
is an MSL, and a session uses the MSL of its class. The classes are
loopback (local host equals remote host), local (local host and remote
host are on the same link/subnet), and remote (local host and remote
host communicate via one or more gateways). Classes corresponding to
nearer peers have lower MSLs by default: 2 seconds for loopback, 10
seconds for local, 60 seconds for remote. Loopback and local sessions
expire more quickly when MSLT is used.
Vestigial Time-Wait (VTW) replaces a TIME_WAIT session's PCB/socket
dead weight with a compact representation of the session, called a
"vestigial PCB". VTW data structures are designed to be very fast and
memory-efficient: for fast insertion and lookup of vestigial PCBs,
the PCBs are stored in a hash table that is designed to minimize the
number of cacheline visits per lookup/insertion. The memory both
for vestigial PCBs and for elements of the PCB hashtable come from
fixed-size pools, and linked data structures exploit this to conserve
memory by representing references with a narrow index/offset from the
start of a pool instead of a pointer. When space for new vestigial PCBs
runs out, VTW makes room by discarding old vestigial PCBs, oldest first.
VTW cooperates with MSLT.
It may help to think of VTW as a "FIN cache" by analogy to the SYN
cache.
A 2.8-GHz Pentium 4 running a test workload that creates TIME_WAIT
sessions as fast as it can is approximately 17% idle when VTW is active
versus 0% idle when VTW is inactive. It has 103 megabytes more free RAM
when VTW is active (approximately 64k vestigial PCBs are created) than
when it is inactive.
2011-05-03 22:28:44 +04:00
|
|
|
|
2011-05-04 05:13:35 +04:00
|
|
|
if (kvmd == NULL)
|
2011-07-17 14:22:07 +04:00
|
|
|
errx(1, "kvm error: %s", buf);
|
2006-10-13 20:33:57 +04:00
|
|
|
if (kvm_nlist(kvmd, nl) < 0 || nl[0].n_type == 0) {
|
Reduces the resources demanded by TCP sessions in TIME_WAIT-state using
methods called Vestigial Time-Wait (VTW) and Maximum Segment Lifetime
Truncation (MSLT).
MSLT and VTW were contributed by Coyote Point Systems, Inc.
Even after a TCP session enters the TIME_WAIT state, its corresponding
socket and protocol control blocks (PCBs) stick around until the TCP
Maximum Segment Lifetime (MSL) expires. On a host whose workload
necessarily creates and closes down many TCP sockets, the sockets & PCBs
for TCP sessions in TIME_WAIT state amount to many megabytes of dead
weight in RAM.
Maximum Segment Lifetimes Truncation (MSLT) assigns each TCP session to
a class based on the nearness of the peer. Corresponding to each class
is an MSL, and a session uses the MSL of its class. The classes are
loopback (local host equals remote host), local (local host and remote
host are on the same link/subnet), and remote (local host and remote
host communicate via one or more gateways). Classes corresponding to
nearer peers have lower MSLs by default: 2 seconds for loopback, 10
seconds for local, 60 seconds for remote. Loopback and local sessions
expire more quickly when MSLT is used.
Vestigial Time-Wait (VTW) replaces a TIME_WAIT session's PCB/socket
dead weight with a compact representation of the session, called a
"vestigial PCB". VTW data structures are designed to be very fast and
memory-efficient: for fast insertion and lookup of vestigial PCBs,
the PCBs are stored in a hash table that is designed to minimize the
number of cacheline visits per lookup/insertion. The memory both
for vestigial PCBs and for elements of the PCB hashtable come from
fixed-size pools, and linked data structures exploit this to conserve
memory by representing references with a narrow index/offset from the
start of a pool instead of a pointer. When space for new vestigial PCBs
runs out, VTW makes room by discarding old vestigial PCBs, oldest first.
VTW cooperates with MSLT.
It may help to think of VTW as a "FIN cache" by analogy to the SYN
cache.
A 2.8-GHz Pentium 4 running a test workload that creates TIME_WAIT
sessions as fast as it can is approximately 17% idle when VTW is active
versus 0% idle when VTW is inactive. It has 103 megabytes more free RAM
when VTW is active (approximately 64k vestigial PCBs are created) than
when it is inactive.
2011-05-03 22:28:44 +04:00
|
|
|
if (nf)
|
|
|
|
errx(1, "%s: no namelist", nf);
|
2006-10-13 20:33:57 +04:00
|
|
|
else
|
|
|
|
errx(1, "no namelist");
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
(void)setgid(getgid());
|
|
|
|
}
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-05-13 12:08:09 +04:00
|
|
|
int
|
2012-03-21 00:34:57 +04:00
|
|
|
main(int argc, char *argv[])
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1997-10-19 09:49:56 +04:00
|
|
|
struct protoent *p;
|
|
|
|
struct protox *tp; /* for printing cblocks & stats */
|
1993-03-21 21:04:42 +03:00
|
|
|
int ch;
|
2006-10-13 20:33:57 +04:00
|
|
|
char *cp;
|
2013-10-19 02:18:14 +04:00
|
|
|
char *afname, *afnames;
|
1998-06-03 06:41:10 +04:00
|
|
|
u_long pcbaddr;
|
1994-05-13 12:08:09 +04:00
|
|
|
|
2010-12-14 00:15:30 +03:00
|
|
|
if (prog_init) {
|
|
|
|
if (prog_init() == -1)
|
|
|
|
err(1, "init failed");
|
|
|
|
force_sysctl = 1; /* cheap trick */
|
|
|
|
}
|
|
|
|
|
2006-10-13 20:33:57 +04:00
|
|
|
egid = getegid();
|
1998-07-06 11:50:18 +04:00
|
|
|
(void)setegid(getgid());
|
1997-10-19 09:49:56 +04:00
|
|
|
tp = NULL;
|
1994-05-13 12:08:09 +04:00
|
|
|
af = AF_UNSPEC;
|
2013-10-19 02:18:14 +04:00
|
|
|
afnames = NULL;
|
1998-06-03 06:41:10 +04:00
|
|
|
pcbaddr = 0;
|
1993-03-21 21:04:42 +03:00
|
|
|
|
2002-07-03 05:42:59 +04:00
|
|
|
while ((ch = getopt(argc, argv,
|
Reduces the resources demanded by TCP sessions in TIME_WAIT-state using
methods called Vestigial Time-Wait (VTW) and Maximum Segment Lifetime
Truncation (MSLT).
MSLT and VTW were contributed by Coyote Point Systems, Inc.
Even after a TCP session enters the TIME_WAIT state, its corresponding
socket and protocol control blocks (PCBs) stick around until the TCP
Maximum Segment Lifetime (MSL) expires. On a host whose workload
necessarily creates and closes down many TCP sockets, the sockets & PCBs
for TCP sessions in TIME_WAIT state amount to many megabytes of dead
weight in RAM.
Maximum Segment Lifetimes Truncation (MSLT) assigns each TCP session to
a class based on the nearness of the peer. Corresponding to each class
is an MSL, and a session uses the MSL of its class. The classes are
loopback (local host equals remote host), local (local host and remote
host are on the same link/subnet), and remote (local host and remote
host communicate via one or more gateways). Classes corresponding to
nearer peers have lower MSLs by default: 2 seconds for loopback, 10
seconds for local, 60 seconds for remote. Loopback and local sessions
expire more quickly when MSLT is used.
Vestigial Time-Wait (VTW) replaces a TIME_WAIT session's PCB/socket
dead weight with a compact representation of the session, called a
"vestigial PCB". VTW data structures are designed to be very fast and
memory-efficient: for fast insertion and lookup of vestigial PCBs,
the PCBs are stored in a hash table that is designed to minimize the
number of cacheline visits per lookup/insertion. The memory both
for vestigial PCBs and for elements of the PCB hashtable come from
fixed-size pools, and linked data structures exploit this to conserve
memory by representing references with a narrow index/offset from the
start of a pool instead of a pointer. When space for new vestigial PCBs
runs out, VTW makes room by discarding old vestigial PCBs, oldest first.
VTW cooperates with MSLT.
It may help to think of VTW as a "FIN cache" by analogy to the SYN
cache.
A 2.8-GHz Pentium 4 running a test workload that creates TIME_WAIT
sessions as fast as it can is approximately 17% idle when VTW is active
versus 0% idle when VTW is inactive. It has 103 megabytes more free RAM
when VTW is active (approximately 64k vestigial PCBs are created) than
when it is inactive.
2011-05-03 22:28:44 +04:00
|
|
|
"AabBdf:ghI:LliM:mN:nP:p:qrsStTuVvw:X")) != -1)
|
2002-07-03 05:42:59 +04:00
|
|
|
switch (ch) {
|
1993-03-21 21:04:42 +03:00
|
|
|
case 'A':
|
2014-11-07 15:42:27 +03:00
|
|
|
Aflag = RT_AFLAG;
|
1993-03-21 21:04:42 +03:00
|
|
|
break;
|
|
|
|
case 'a':
|
|
|
|
aflag = 1;
|
|
|
|
break;
|
1998-03-19 05:42:57 +03:00
|
|
|
case 'b':
|
|
|
|
bflag = 1;
|
|
|
|
break;
|
2005-08-04 23:39:40 +04:00
|
|
|
case 'B':
|
|
|
|
Bflag = 1;
|
|
|
|
break;
|
1993-03-21 21:04:42 +03:00
|
|
|
case 'd':
|
|
|
|
dflag = 1;
|
|
|
|
break;
|
|
|
|
case 'f':
|
2013-10-19 02:18:14 +04:00
|
|
|
afnames = optarg;
|
1993-03-21 21:04:42 +03:00
|
|
|
break;
|
1999-01-11 15:31:53 +03:00
|
|
|
#ifndef SMALL
|
1994-05-13 12:08:09 +04:00
|
|
|
case 'g':
|
|
|
|
gflag = 1;
|
1993-03-21 21:04:42 +03:00
|
|
|
break;
|
1999-01-11 15:31:53 +03:00
|
|
|
#endif
|
2010-02-24 14:00:27 +03:00
|
|
|
case 'h':
|
|
|
|
hflag = 1;
|
|
|
|
break;
|
1996-05-07 06:55:00 +04:00
|
|
|
case 'I':
|
1993-03-21 21:04:42 +03:00
|
|
|
iflag = 1;
|
1996-05-07 06:55:00 +04:00
|
|
|
interface = optarg;
|
1993-03-21 21:04:42 +03:00
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
iflag = 1;
|
|
|
|
break;
|
1999-09-16 00:12:18 +04:00
|
|
|
case 'L':
|
2014-11-12 06:34:59 +03:00
|
|
|
Lflag = RT_LFLAG;
|
1999-09-16 00:12:18 +04:00
|
|
|
break;
|
1999-07-01 22:40:35 +04:00
|
|
|
case 'l':
|
|
|
|
lflag = 1;
|
|
|
|
break;
|
1993-03-21 21:04:42 +03:00
|
|
|
case 'M':
|
1994-05-13 12:08:09 +04:00
|
|
|
memf = optarg;
|
1993-03-21 21:04:42 +03:00
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
mflag = 1;
|
|
|
|
break;
|
|
|
|
case 'N':
|
1994-05-13 12:08:09 +04:00
|
|
|
nlistf = optarg;
|
1993-03-21 21:04:42 +03:00
|
|
|
break;
|
|
|
|
case 'n':
|
2014-11-07 00:30:09 +03:00
|
|
|
numeric_addr = numeric_port = nflag = RT_NFLAG;
|
1993-03-21 21:04:42 +03:00
|
|
|
break;
|
1998-06-03 06:41:10 +04:00
|
|
|
case 'P':
|
2003-04-18 07:21:00 +04:00
|
|
|
errno = 0;
|
1998-06-03 06:41:10 +04:00
|
|
|
pcbaddr = strtoul(optarg, &cp, 16);
|
1998-07-12 07:20:13 +04:00
|
|
|
if (*cp != '\0' || errno == ERANGE)
|
|
|
|
errx(1, "invalid PCB address %s",
|
|
|
|
optarg);
|
1998-06-03 06:41:10 +04:00
|
|
|
Pflag = 1;
|
|
|
|
break;
|
1993-03-21 21:04:42 +03:00
|
|
|
case 'p':
|
1998-07-12 07:20:13 +04:00
|
|
|
if ((tp = name2protox(optarg)) == NULL)
|
|
|
|
errx(1, "%s: unknown or uninstrumented protocol",
|
|
|
|
optarg);
|
1993-03-21 21:04:42 +03:00
|
|
|
pflag = 1;
|
|
|
|
break;
|
2002-07-03 05:42:59 +04:00
|
|
|
case 'q':
|
|
|
|
qflag = 1;
|
|
|
|
break;
|
1993-03-21 21:04:42 +03:00
|
|
|
case 'r':
|
|
|
|
rflag = 1;
|
|
|
|
break;
|
|
|
|
case 's':
|
1994-05-13 12:08:09 +04:00
|
|
|
++sflag;
|
1993-03-21 21:04:42 +03:00
|
|
|
break;
|
2001-05-28 08:22:55 +04:00
|
|
|
case 'S':
|
|
|
|
numeric_addr = 1;
|
|
|
|
break;
|
1993-03-21 21:04:42 +03:00
|
|
|
case 't':
|
|
|
|
tflag = 1;
|
|
|
|
break;
|
2010-06-27 10:52:37 +04:00
|
|
|
case 'T':
|
2014-11-07 15:42:27 +03:00
|
|
|
tagflag = RT_TFLAG;
|
2010-06-27 10:52:37 +04:00
|
|
|
break;
|
1993-03-21 21:04:42 +03:00
|
|
|
case 'u':
|
1998-07-18 09:04:10 +04:00
|
|
|
af = AF_LOCAL;
|
1993-03-21 21:04:42 +03:00
|
|
|
break;
|
Reduces the resources demanded by TCP sessions in TIME_WAIT-state using
methods called Vestigial Time-Wait (VTW) and Maximum Segment Lifetime
Truncation (MSLT).
MSLT and VTW were contributed by Coyote Point Systems, Inc.
Even after a TCP session enters the TIME_WAIT state, its corresponding
socket and protocol control blocks (PCBs) stick around until the TCP
Maximum Segment Lifetime (MSL) expires. On a host whose workload
necessarily creates and closes down many TCP sockets, the sockets & PCBs
for TCP sessions in TIME_WAIT state amount to many megabytes of dead
weight in RAM.
Maximum Segment Lifetimes Truncation (MSLT) assigns each TCP session to
a class based on the nearness of the peer. Corresponding to each class
is an MSL, and a session uses the MSL of its class. The classes are
loopback (local host equals remote host), local (local host and remote
host are on the same link/subnet), and remote (local host and remote
host communicate via one or more gateways). Classes corresponding to
nearer peers have lower MSLs by default: 2 seconds for loopback, 10
seconds for local, 60 seconds for remote. Loopback and local sessions
expire more quickly when MSLT is used.
Vestigial Time-Wait (VTW) replaces a TIME_WAIT session's PCB/socket
dead weight with a compact representation of the session, called a
"vestigial PCB". VTW data structures are designed to be very fast and
memory-efficient: for fast insertion and lookup of vestigial PCBs,
the PCBs are stored in a hash table that is designed to minimize the
number of cacheline visits per lookup/insertion. The memory both
for vestigial PCBs and for elements of the PCB hashtable come from
fixed-size pools, and linked data structures exploit this to conserve
memory by representing references with a narrow index/offset from the
start of a pool instead of a pointer. When space for new vestigial PCBs
runs out, VTW makes room by discarding old vestigial PCBs, oldest first.
VTW cooperates with MSLT.
It may help to think of VTW as a "FIN cache" by analogy to the SYN
cache.
A 2.8-GHz Pentium 4 running a test workload that creates TIME_WAIT
sessions as fast as it can is approximately 17% idle when VTW is active
versus 0% idle when VTW is inactive. It has 103 megabytes more free RAM
when VTW is active (approximately 64k vestigial PCBs are created) than
when it is inactive.
2011-05-03 22:28:44 +04:00
|
|
|
case 'V':
|
|
|
|
Vflag++;
|
|
|
|
break;
|
1999-01-15 22:06:25 +03:00
|
|
|
case 'v':
|
2014-11-07 15:42:27 +03:00
|
|
|
vflag = RT_VFLAG;
|
1999-01-15 22:06:25 +03:00
|
|
|
break;
|
1993-03-21 21:04:42 +03:00
|
|
|
case 'w':
|
|
|
|
interval = atoi(optarg);
|
1994-05-13 12:08:09 +04:00
|
|
|
iflag = 1;
|
1993-03-21 21:04:42 +03:00
|
|
|
break;
|
2009-09-13 06:53:17 +04:00
|
|
|
case 'X':
|
|
|
|
force_sysctl = 1;
|
|
|
|
break;
|
1993-03-21 21:04:42 +03:00
|
|
|
case '?':
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
argv += optind;
|
|
|
|
argc -= optind;
|
|
|
|
|
|
|
|
#define BACKWARD_COMPATIBILITY
|
|
|
|
#ifdef BACKWARD_COMPATIBILITY
|
|
|
|
if (*argv) {
|
2004-10-31 00:56:20 +04:00
|
|
|
if (isdigit((unsigned char)**argv)) {
|
1993-03-21 21:04:42 +03:00
|
|
|
interval = atoi(*argv);
|
|
|
|
if (interval <= 0)
|
|
|
|
usage();
|
|
|
|
++argv;
|
|
|
|
iflag = 1;
|
|
|
|
}
|
|
|
|
if (*argv) {
|
1994-05-13 12:08:09 +04:00
|
|
|
nlistf = *argv;
|
|
|
|
if (*++argv)
|
|
|
|
memf = *argv;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
1994-05-13 12:08:09 +04:00
|
|
|
|
2007-04-27 22:37:53 +04:00
|
|
|
prepare(nlistf, memf, tp);
|
1998-07-06 11:50:18 +04:00
|
|
|
|
2005-09-14 19:35:26 +04:00
|
|
|
#ifndef SMALL
|
2005-08-04 23:39:40 +04:00
|
|
|
if (Bflag) {
|
|
|
|
if (sflag)
|
|
|
|
bpf_stats();
|
|
|
|
else
|
2005-09-03 02:23:13 +04:00
|
|
|
bpf_dump(interface);
|
2005-08-04 23:39:40 +04:00
|
|
|
exit(0);
|
|
|
|
}
|
2005-09-14 19:35:26 +04:00
|
|
|
#endif
|
2005-08-04 23:39:40 +04:00
|
|
|
|
1993-03-21 21:04:42 +03:00
|
|
|
if (mflag) {
|
1997-02-28 03:14:19 +03:00
|
|
|
mbpr(nl[N_MBSTAT].n_value, nl[N_MSIZE].n_value,
|
1999-02-27 20:37:24 +03:00
|
|
|
nl[N_MCLBYTES].n_value, nl[N_MBPOOL].n_value,
|
|
|
|
nl[N_MCLPOOL].n_value);
|
1993-03-21 21:04:42 +03:00
|
|
|
exit(0);
|
|
|
|
}
|
1998-06-03 06:41:10 +04:00
|
|
|
if (Pflag) {
|
|
|
|
if (tp == NULL) {
|
|
|
|
/* Default to TCP. */
|
|
|
|
tp = name2protox("tcp");
|
|
|
|
}
|
|
|
|
if (tp->pr_dump)
|
2013-06-20 01:12:03 +04:00
|
|
|
(*tp->pr_dump)(nl[tp->pr_index].n_value, tp->pr_name,
|
|
|
|
pcbaddr);
|
1998-06-03 06:41:10 +04:00
|
|
|
else
|
|
|
|
printf("%s: no PCB dump routine\n", tp->pr_name);
|
|
|
|
exit(0);
|
|
|
|
}
|
1993-03-21 21:04:42 +03:00
|
|
|
if (pflag) {
|
1999-12-13 18:22:55 +03:00
|
|
|
if (iflag && tp->pr_istats)
|
2014-05-30 05:44:21 +04:00
|
|
|
intpr(interval, nl[N_IFNET_LIST].n_value, tp->pr_istats);
|
1999-12-13 18:22:55 +03:00
|
|
|
else if (tp->pr_stats)
|
1993-03-21 21:04:42 +03:00
|
|
|
(*tp->pr_stats)(nl[tp->pr_sindex].n_value,
|
|
|
|
tp->pr_name);
|
|
|
|
else
|
|
|
|
printf("%s: no stats routine\n", tp->pr_name);
|
|
|
|
exit(0);
|
|
|
|
}
|
2002-07-03 05:42:59 +04:00
|
|
|
if (qflag) {
|
|
|
|
print_softintrq();
|
|
|
|
exit(0);
|
|
|
|
}
|
1993-03-21 21:04:42 +03:00
|
|
|
/*
|
|
|
|
* Keep file descriptors open to avoid overhead
|
|
|
|
* of open/close on each call to get* routines.
|
|
|
|
*/
|
|
|
|
sethostent(1);
|
|
|
|
setnetent(1);
|
2013-10-19 02:18:14 +04:00
|
|
|
/*
|
|
|
|
* If -f was used afnames != NULL, loop over the address families.
|
|
|
|
* Otherwise do this at least once (with af == AF_UNSPEC).
|
|
|
|
*/
|
|
|
|
afname = NULL;
|
|
|
|
do {
|
|
|
|
if (afnames != NULL) {
|
|
|
|
afname = strsep(&afnames, ",");
|
|
|
|
if (afname == NULL)
|
|
|
|
break; /* Exit early */
|
|
|
|
if (strcmp(afname, "inet") == 0)
|
|
|
|
af = AF_INET;
|
|
|
|
else if (strcmp(afname, "inet6") == 0)
|
|
|
|
af = AF_INET6;
|
|
|
|
else if (strcmp(afname, "arp") == 0)
|
|
|
|
af = AF_ARP;
|
|
|
|
else if (strcmp(afname, "pfkey") == 0)
|
|
|
|
af = PF_KEY;
|
|
|
|
else if (strcmp(afname, "unix") == 0
|
|
|
|
|| strcmp(afname, "local") == 0)
|
|
|
|
af = AF_LOCAL;
|
|
|
|
else if (strcmp(afname, "atalk") == 0)
|
|
|
|
af = AF_APPLETALK;
|
|
|
|
else if (strcmp(afname, "mpls") == 0)
|
|
|
|
af = AF_MPLS;
|
|
|
|
else {
|
|
|
|
warnx("%s: unknown address family",
|
|
|
|
afname);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
1999-12-13 18:22:55 +03:00
|
|
|
|
2013-10-19 02:18:14 +04:00
|
|
|
if (iflag) {
|
|
|
|
if (af != AF_UNSPEC)
|
|
|
|
goto protostat;
|
|
|
|
|
2014-05-30 05:44:21 +04:00
|
|
|
intpr(interval, nl[N_IFNET_LIST].n_value, NULL);
|
2013-10-19 02:18:14 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (rflag) {
|
|
|
|
if (sflag)
|
|
|
|
rt_stats(use_sysctl ? 0 : nl[N_RTSTAT].n_value);
|
|
|
|
else {
|
2014-04-24 18:56:29 +04:00
|
|
|
if (use_sysctl)
|
2014-11-07 15:42:27 +03:00
|
|
|
p_rttables(af,
|
2014-11-12 06:34:59 +03:00
|
|
|
nflag|tagflag|vflag|Lflag, 0, ~0);
|
2014-04-24 18:56:29 +04:00
|
|
|
else
|
|
|
|
routepr(nl[N_RTREE].n_value);
|
2013-10-19 02:18:14 +04:00
|
|
|
}
|
|
|
|
break;
|
2006-05-28 20:51:40 +04:00
|
|
|
}
|
1999-01-11 15:31:53 +03:00
|
|
|
#ifndef SMALL
|
2013-10-19 02:18:14 +04:00
|
|
|
if (gflag) {
|
|
|
|
if (sflag) {
|
|
|
|
if (af == AF_INET || af == AF_UNSPEC)
|
|
|
|
mrt_stats(nl[N_MRTPROTO].n_value,
|
|
|
|
nl[N_MRTSTAT].n_value);
|
1999-07-01 22:40:35 +04:00
|
|
|
#ifdef INET6
|
2013-10-19 02:18:14 +04:00
|
|
|
if (af == AF_INET6 || af == AF_UNSPEC)
|
|
|
|
mrt6_stats(nl[N_MRT6PROTO].n_value,
|
|
|
|
nl[N_MRT6STAT].n_value);
|
1999-07-01 22:40:35 +04:00
|
|
|
#endif
|
2013-10-19 02:18:14 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (af == AF_INET || af == AF_UNSPEC)
|
|
|
|
mroutepr(nl[N_MRTPROTO].n_value,
|
|
|
|
nl[N_MFCHASHTBL].n_value,
|
|
|
|
nl[N_MFCHASH].n_value,
|
|
|
|
nl[N_VIFTABLE].n_value);
|
1999-07-01 22:40:35 +04:00
|
|
|
#ifdef INET6
|
2013-10-19 02:18:14 +04:00
|
|
|
if (af == AF_INET6 || af == AF_UNSPEC)
|
|
|
|
mroute6pr(nl[N_MRT6PROTO].n_value,
|
|
|
|
nl[N_MF6CTABLE].n_value,
|
|
|
|
nl[N_MIF6TABLE].n_value);
|
1999-07-01 22:40:35 +04:00
|
|
|
#endif
|
2013-10-19 02:18:14 +04:00
|
|
|
}
|
|
|
|
break;
|
1999-07-01 22:40:35 +04:00
|
|
|
}
|
1999-01-11 15:31:53 +03:00
|
|
|
#endif
|
2013-10-19 02:18:14 +04:00
|
|
|
protostat:
|
|
|
|
if (af == AF_INET || af == AF_UNSPEC) {
|
|
|
|
setprotoent(1);
|
|
|
|
setservent(1);
|
|
|
|
/* ugh, this is O(MN) ... why do we do this? */
|
|
|
|
while ((p = getprotoent()) != NULL) {
|
|
|
|
for (tp = protox; tp->pr_name; tp++)
|
|
|
|
if (strcmp(tp->pr_name, p->p_name) == 0)
|
|
|
|
break;
|
|
|
|
if (tp->pr_name == 0 || tp->pr_wanted == 0)
|
|
|
|
continue;
|
|
|
|
printproto(tp, p->p_name);
|
|
|
|
tp->pr_wanted = 0;
|
|
|
|
}
|
|
|
|
endprotoent();
|
1994-05-13 12:08:09 +04:00
|
|
|
for (tp = protox; tp->pr_name; tp++)
|
2013-10-19 02:18:14 +04:00
|
|
|
if (tp->pr_wanted)
|
|
|
|
printproto(tp, tp->pr_name);
|
1994-05-13 12:08:09 +04:00
|
|
|
}
|
1999-07-01 22:40:35 +04:00
|
|
|
#ifdef INET6
|
2013-10-19 02:18:14 +04:00
|
|
|
if (af == AF_INET6 || af == AF_UNSPEC)
|
|
|
|
for (tp = ip6protox; tp->pr_name; tp++)
|
|
|
|
printproto(tp, tp->pr_name);
|
1999-07-01 22:40:35 +04:00
|
|
|
#endif
|
2013-10-19 02:18:14 +04:00
|
|
|
if (af == AF_ARP || af == AF_UNSPEC)
|
|
|
|
for (tp = arpprotox; tp->pr_name; tp++)
|
|
|
|
printproto(tp, tp->pr_name);
|
2000-02-26 12:55:24 +03:00
|
|
|
#ifdef IPSEC
|
2013-10-19 02:18:14 +04:00
|
|
|
if (af == PF_KEY || af == AF_UNSPEC)
|
|
|
|
for (tp = pfkeyprotox; tp->pr_name; tp++)
|
|
|
|
printproto(tp, tp->pr_name);
|
2000-02-26 12:55:24 +03:00
|
|
|
#endif
|
1999-01-11 15:31:53 +03:00
|
|
|
#ifndef SMALL
|
2013-10-19 02:18:14 +04:00
|
|
|
if (af == AF_APPLETALK || af == AF_UNSPEC)
|
|
|
|
for (tp = atalkprotox; tp->pr_name; tp++)
|
|
|
|
printproto(tp, tp->pr_name);
|
|
|
|
if ((af == AF_LOCAL || af == AF_UNSPEC) && !sflag)
|
|
|
|
unixpr(nl[N_UNIXSW].n_value);
|
1999-01-11 15:31:53 +03:00
|
|
|
#endif
|
2013-10-19 02:18:14 +04:00
|
|
|
} while (afnames != NULL && afname != NULL);
|
1994-05-13 12:08:09 +04:00
|
|
|
exit(0);
|
|
|
|
}
|
1994-01-11 22:42:48 +03:00
|
|
|
|
1994-05-13 12:08:09 +04:00
|
|
|
/*
|
|
|
|
* Print out protocol statistics or control blocks (per sflag).
|
|
|
|
* If the interface was not specifically requested, and the symbol
|
|
|
|
* is not in the namelist, ignore this one.
|
|
|
|
*/
|
|
|
|
static void
|
2012-03-21 00:34:57 +04:00
|
|
|
printproto(struct protox *tp, const char *name)
|
1994-05-13 12:08:09 +04:00
|
|
|
{
|
2009-04-12 20:08:37 +04:00
|
|
|
void (*pr) __P((u_long, const char *));
|
1994-05-13 12:08:09 +04:00
|
|
|
u_long off;
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-05-13 12:08:09 +04:00
|
|
|
if (sflag) {
|
1999-12-13 18:22:55 +03:00
|
|
|
if (iflag) {
|
|
|
|
if (tp->pr_istats)
|
2014-05-30 05:44:21 +04:00
|
|
|
intpr(interval, nl[N_IFNET_LIST].n_value,
|
1999-12-13 18:22:55 +03:00
|
|
|
tp->pr_istats);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pr = tp->pr_stats;
|
|
|
|
off = nl[tp->pr_sindex].n_value;
|
|
|
|
}
|
1994-05-13 12:08:09 +04:00
|
|
|
} else {
|
|
|
|
pr = tp->pr_cblocks;
|
|
|
|
off = nl[tp->pr_index].n_value;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
2006-05-28 20:51:40 +04:00
|
|
|
if (pr != NULL && ((off || af != AF_UNSPEC) || use_sysctl)) {
|
1994-05-13 12:08:09 +04:00
|
|
|
(*pr)(off, name);
|
2006-05-28 20:51:40 +04:00
|
|
|
}
|
1994-05-13 12:08:09 +04:00
|
|
|
}
|
|
|
|
|
2002-07-03 05:42:59 +04:00
|
|
|
/*
|
|
|
|
* Print softintrq status.
|
|
|
|
*/
|
|
|
|
void
|
2012-03-21 00:34:57 +04:00
|
|
|
print_softintrq(void)
|
2002-07-03 05:42:59 +04:00
|
|
|
{
|
|
|
|
struct ifqueue intrq, *ifq = &intrq;
|
|
|
|
const struct softintrq *siq;
|
|
|
|
u_long off;
|
|
|
|
|
|
|
|
for (siq = softintrq; siq->siq_name != NULL; siq++) {
|
|
|
|
off = nl[siq->siq_index].n_value;
|
|
|
|
if (off == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
kread(off, (char *)ifq, sizeof(*ifq));
|
|
|
|
printf("%s:\n", siq->siq_name);
|
|
|
|
printf("\tqueue length: %d\n", ifq->ifq_len);
|
|
|
|
printf("\tmaximum queue length: %d\n", ifq->ifq_maxlen);
|
|
|
|
printf("\tpackets dropped: %d\n", ifq->ifq_drops);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1994-05-13 12:08:09 +04:00
|
|
|
/*
|
|
|
|
* Read kernel memory, return 0 on success.
|
|
|
|
*/
|
|
|
|
int
|
2012-03-21 00:34:57 +04:00
|
|
|
kread(u_long addr, char *buf, int size)
|
1994-05-13 12:08:09 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
if (kvm_read(kvmd, addr, buf, size) != size) {
|
2002-06-11 10:06:18 +04:00
|
|
|
warnx("%s", kvm_geterr(kvmd));
|
1994-05-13 12:08:09 +04:00
|
|
|
return (-1);
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
1994-05-13 12:08:09 +04:00
|
|
|
return (0);
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
|
2009-04-12 20:08:37 +04:00
|
|
|
const char *
|
2012-03-21 00:34:57 +04:00
|
|
|
plural(int n)
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1998-07-12 07:20:13 +04:00
|
|
|
|
1993-03-21 21:04:42 +03:00
|
|
|
return (n != 1 ? "s" : "");
|
|
|
|
}
|
|
|
|
|
2009-04-12 20:08:37 +04:00
|
|
|
const char *
|
2012-03-21 00:34:57 +04:00
|
|
|
plurales(int n)
|
1994-05-13 12:08:09 +04:00
|
|
|
{
|
1998-07-12 07:20:13 +04:00
|
|
|
|
1994-05-13 12:08:09 +04:00
|
|
|
return (n != 1 ? "es" : "");
|
|
|
|
}
|
|
|
|
|
2003-02-04 04:22:08 +03:00
|
|
|
int
|
|
|
|
get_hardticks(void)
|
|
|
|
{
|
|
|
|
int hardticks;
|
|
|
|
|
|
|
|
kread(nl[N_HARDCLOCK_TICKS].n_value, (char *)&hardticks,
|
|
|
|
sizeof(hardticks));
|
|
|
|
return (hardticks);
|
|
|
|
}
|
|
|
|
|
1993-03-21 21:04:42 +03:00
|
|
|
/*
|
|
|
|
* Find the protox for the given "well-known" name.
|
|
|
|
*/
|
1994-05-13 12:08:09 +04:00
|
|
|
static struct protox *
|
2012-03-21 00:34:57 +04:00
|
|
|
knownname(const char *name)
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
|
|
|
struct protox **tpp, *tp;
|
|
|
|
|
|
|
|
for (tpp = protoprotox; *tpp; tpp++)
|
1994-05-13 12:08:09 +04:00
|
|
|
for (tp = *tpp; tp->pr_name; tp++)
|
|
|
|
if (strcmp(tp->pr_name, name) == 0)
|
|
|
|
return (tp);
|
|
|
|
return (NULL);
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the protox corresponding to name.
|
|
|
|
*/
|
1994-05-13 12:08:09 +04:00
|
|
|
static struct protox *
|
2012-03-21 00:34:57 +04:00
|
|
|
name2protox(const char *name)
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
|
|
|
struct protox *tp;
|
|
|
|
char **alias; /* alias from p->aliases */
|
|
|
|
struct protoent *p;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try to find the name in the list of "well-known" names. If that
|
|
|
|
* fails, check if name is an alias for an Internet protocol.
|
|
|
|
*/
|
1997-04-03 08:46:44 +04:00
|
|
|
if ((tp = knownname(name)) != NULL)
|
1994-05-13 12:08:09 +04:00
|
|
|
return (tp);
|
1993-03-21 21:04:42 +03:00
|
|
|
|
|
|
|
setprotoent(1); /* make protocol lookup cheaper */
|
1997-04-03 08:46:44 +04:00
|
|
|
while ((p = getprotoent()) != NULL) {
|
1993-03-21 21:04:42 +03:00
|
|
|
/* assert: name not same as p->name */
|
|
|
|
for (alias = p->p_aliases; *alias; alias++)
|
|
|
|
if (strcmp(name, *alias) == 0) {
|
|
|
|
endprotoent();
|
1994-05-13 12:08:09 +04:00
|
|
|
return (knownname(p->p_name));
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
endprotoent();
|
1994-05-13 12:08:09 +04:00
|
|
|
return (NULL);
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
|
1994-05-13 12:08:09 +04:00
|
|
|
static void
|
2012-03-21 00:34:57 +04:00
|
|
|
usage(void)
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
2001-02-20 02:03:42 +03:00
|
|
|
const char *progname = getprogname();
|
|
|
|
|
1993-03-21 21:04:42 +03:00
|
|
|
(void)fprintf(stderr,
|
2013-10-19 02:18:14 +04:00
|
|
|
"usage: %s [-Aan] [-f address_family[,family ...]] [-M core] [-N system]\n", progname);
|
1993-03-21 21:04:42 +03:00
|
|
|
(void)fprintf(stderr,
|
2013-10-19 02:18:14 +04:00
|
|
|
" %s [-bdgiLmnqrsSv] [-f address_family[,family ...]] [-M core] [-N system]\n",
|
2001-02-20 02:03:42 +03:00
|
|
|
progname);
|
1993-03-21 21:04:42 +03:00
|
|
|
(void)fprintf(stderr,
|
2002-07-03 01:34:18 +04:00
|
|
|
" %s [-dn] [-I interface] [-M core] [-N system] [-w wait]\n", progname);
|
1993-03-21 21:04:42 +03:00
|
|
|
(void)fprintf(stderr,
|
2002-07-03 01:34:18 +04:00
|
|
|
" %s [-p protocol] [-M core] [-N system]\n", progname);
|
1998-06-03 06:41:10 +04:00
|
|
|
(void)fprintf(stderr,
|
2002-07-03 01:34:18 +04:00
|
|
|
" %s [-p protocol] [-M core] [-N system] -P pcbaddr\n", progname);
|
|
|
|
(void)fprintf(stderr,
|
|
|
|
" %s [-p protocol] [-i] [-I Interface] \n", progname);
|
|
|
|
(void)fprintf(stderr,
|
2013-10-19 02:18:14 +04:00
|
|
|
" %s [-s] [-f address_family[,family ...]] [-i] [-I Interface]\n", progname);
|
2005-08-04 23:39:40 +04:00
|
|
|
(void)fprintf(stderr,
|
|
|
|
" %s [-s] [-B] [-I interface]\n", progname);
|
1993-03-21 21:04:42 +03:00
|
|
|
exit(1);
|
|
|
|
}
|