Module Name: src
Committed By: martin
Date: Mon Sep 12 14:29:20 UTC 2022
Modified Files:
src/usr.bin/netstat [netbsd-8]: atalk.c bpf.c fast_ipsec.c if.c inet.c
inet6.c main.c mbuf.c mroute.c mroute6.c netstat.1 netstat.h
pfkey.c pfsync.c route.c unix.c vtw.c
Log Message:
Pull up the following, requested by msaitoh in ticket #1762:
usr.bin/netstat/atalk.c 1.18,1.20-1.21
usr.bin/netstat/bpf.c 1.16 via patch
usr.bin/netstat/fast_ipsec.c 1.24 via patch
usr.bin/netstat/if.c 1.97-1.99,1.101-1.104 via patch
usr.bin/netstat/inet.c 1.111,1.115-1.116 via patch
usr.bin/netstat/inet6.c 1.70,1.74-1.75,1.80-1.81 via patch
usr.bin/netstat/main.c 1.100,1.102-1.103
usr.bin/netstat/mbuf.c 1.34-1.35
usr.bin/netstat/mroute.c 1.26-1.27
usr.bin/netstat/mroute6.c 1.16
usr.bin/netstat/netstat.h 1.52-1.53
usr.bin/netstat/pfkey.c 1.4-1.5 via patch
usr.bin/netstat/pfsync.c 1.4-1.5 via patch
usr.bin/netstat/route.c 1.87-1.88
usr.bin/netstat/unix.c 1.36-1.37
usr.bin/netstat/vtw.c 1.11,1.13
- Add names of a few more ICMPv6 messages.
Also make the array be explicitly 256 entries long.
- sprintf() -> snprintf(), and adjust a buffer size to avoid any
potential for overflow.
- Add missing {IP,IP6}_STAT_NOIPSEC to netstat.
- Don't show any of the completely and utterly undocumented VTW info
if the feature isn't enabled.
- Print oqdrops correctly.
- netstat.1: Add various xrefs present in the body to "See Also".
- Limit maximum owner name to appease gcc.
- KNF. Style fixes.
To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.16.8.1 src/usr.bin/netstat/atalk.c
cvs rdiff -u -r1.11 -r1.11.22.1 src/usr.bin/netstat/bpf.c
cvs rdiff -u -r1.21.4.1 -r1.21.4.2 src/usr.bin/netstat/fast_ipsec.c
cvs rdiff -u -r1.94.4.1 -r1.94.4.2 src/usr.bin/netstat/if.c
cvs rdiff -u -r1.107 -r1.107.6.1 src/usr.bin/netstat/inet.c
cvs rdiff -u -r1.69 -r1.69.6.1 src/usr.bin/netstat/inet6.c
cvs rdiff -u -r1.99 -r1.99.8.1 src/usr.bin/netstat/main.c
cvs rdiff -u -r1.33 -r1.33.8.1 src/usr.bin/netstat/mbuf.c
cvs rdiff -u -r1.25 -r1.25.8.1 src/usr.bin/netstat/mroute.c
cvs rdiff -u -r1.15 -r1.15.8.1 src/usr.bin/netstat/mroute6.c
cvs rdiff -u -r1.73 -r1.73.8.1 src/usr.bin/netstat/netstat.1
cvs rdiff -u -r1.51 -r1.51.8.1 src/usr.bin/netstat/netstat.h
cvs rdiff -u -r1.1 -r1.1.34.1 src/usr.bin/netstat/pfkey.c
cvs rdiff -u -r1.1 -r1.1.38.1 src/usr.bin/netstat/pfsync.c
cvs rdiff -u -r1.85 -r1.85.8.1 src/usr.bin/netstat/route.c
cvs rdiff -u -r1.35 -r1.35.6.1 src/usr.bin/netstat/unix.c
cvs rdiff -u -r1.9 -r1.9.8.1 src/usr.bin/netstat/vtw.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/netstat/atalk.c
diff -u src/usr.bin/netstat/atalk.c:1.16 src/usr.bin/netstat/atalk.c:1.16.8.1
--- src/usr.bin/netstat/atalk.c:1.16 Sat Jun 6 13:08:31 2015
+++ src/usr.bin/netstat/atalk.c Mon Sep 12 14:29:19 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: atalk.c,v 1.16 2015/06/06 13:08:31 joerg Exp $ */
+/* $NetBSD: atalk.c,v 1.16.8.1 2022/09/12 14:29:19 martin Exp $ */
/*
* Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "from @(#)atalk.c 1.1 (Whistle) 6/6/96";
#else
-__RCSID("$NetBSD: atalk.c,v 1.16 2015/06/06 13:08:31 joerg Exp $");
+__RCSID("$NetBSD: atalk.c,v 1.16.8.1 2022/09/12 14:29:19 martin Exp $");
#endif
#endif /* not lint */
@@ -62,9 +62,6 @@ __RCSID("$NetBSD: atalk.c,v 1.16 2015/06
#include <string.h>
#include "netstat.h"
-struct ddpcb ddpcb;
-struct socket sockb;
-
static int first = 1;
/*
@@ -84,11 +81,12 @@ at_pr_net(const struct sockaddr_at *sat,
case 0xffff:
return "????";
case ATADDR_ANYNET:
- return ("*");
+ return "*";
}
}
- (void)snprintf(mybuf, sizeof(mybuf), "%hu", ntohs(sat->sat_addr.s_net));
- return (mybuf);
+ (void)snprintf(mybuf, sizeof(mybuf), "%hu",
+ ntohs(sat->sat_addr.s_net));
+ return mybuf;
}
static const char *
@@ -101,12 +99,12 @@ at_pr_host(const struct sockaddr_at *sat
case ATADDR_BCAST:
return "bcast";
case ATADDR_ANYNODE:
- return ("*");
+ return "*";
}
}
- (void)snprintf(mybuf, sizeof(mybuf), "%d",
+ (void)snprintf(mybuf, sizeof(mybuf), "%d",
(unsigned int)sat->sat_addr.s_node);
- return (mybuf);
+ return mybuf;
}
static const char *
@@ -116,13 +114,13 @@ at_pr_port(const struct sockaddr_at *sat
switch (sat->sat_port) {
case ATADDR_ANYPORT:
- return ("*");
+ return "*";
case 0xff:
return "????";
default:
(void)snprintf(mybuf, sizeof(mybuf), "%d",
(unsigned int)sat->sat_port);
- return (mybuf);
+ return mybuf;
}
}
@@ -140,7 +138,7 @@ at_pr_range(const struct sockaddr_at *sa
(void)snprintf(mybuf, sizeof(mybuf), "%d",
ntohs(sat->sat_range.r_netrange.nr_firstnet));
}
- return (mybuf);
+ return mybuf;
}
@@ -182,7 +180,7 @@ atalk_print(const struct sockaddr *sa, i
(void)snprintf(mybuf + strlen(mybuf),
sizeof(mybuf) - strlen(mybuf), ".%s", at_pr_port(sat));
}
- return (mybuf);
+ return mybuf;
}
const char *
@@ -223,12 +221,14 @@ atalk_print2(const struct sockaddr *sa,
if (l > 0)
n += l;
}
- return (buf);
+ return buf;
}
void
atalkprotopr(u_long off, const char *name)
{
+ struct ddpcb ddpcb;
+ struct socket sockb;
struct ddpcb *next;
struct ddpcb *initial;
int width = 22;
@@ -243,9 +243,8 @@ atalkprotopr(u_long off, const char *nam
return;
next = ddpcb.ddp_next;
#if 0
- if (!aflag && atalk_nullhost(ddpcb.ddp_lsat)) {
+ if (!aflag && atalk_nullhost(ddpcb.ddp_lsat))
continue;
- }
#endif
if (kread((u_long)ddpcb.ddp_socket,
(char *)&sockb, sizeof(sockb)) < 0)
@@ -261,7 +260,7 @@ atalkprotopr(u_long off, const char *nam
}
printf("%-5.5s %-6.6s %-6.6s %*.*s %*.*s %s\n",
"Proto", "Recv-Q", "Send-Q",
- -width, width, "Local Address",
+ -width, width, "Local Address",
-width, width, "Foreign Address", "(state)");
first = 0;
}
@@ -276,8 +275,9 @@ atalkprotopr(u_long off, const char *nam
putchar('\n');
}
}
-#define ANY(x,y,z) \
- ((sflag==1 || (x)) ? printf("\t%llu %s%s%s\n",(unsigned long long)x,y,plural(x),z) : 0)
+#define ANY(x,y,z) \
+ ((sflag==1 || (x)) ? \
+ printf("\t%llu %s%s%s\n",(unsigned long long)x,y,plural(x),z) : 0)
/*
* Dump DDP statistics structure.
@@ -308,7 +308,9 @@ ddp_stats(u_long off, const char *name)
ANY(ddpstat[DDP_STAT_TOOSMALL], "packet", " with not enough data ");
ANY(ddpstat[DDP_STAT_FORWARD], "packet", " forwarded ");
ANY(ddpstat[DDP_STAT_ENCAP], "packet", " encapsulated ");
- ANY(ddpstat[DDP_STAT_CANTFORWARD], "packet", " rcvd for unreachable dest ");
- ANY(ddpstat[DDP_STAT_NOSOCKSPACE], "packet", " dropped due to no socket space ");
+ ANY(ddpstat[DDP_STAT_CANTFORWARD], "packet",
+ " rcvd for unreachable dest ");
+ ANY(ddpstat[DDP_STAT_NOSOCKSPACE], "packet",
+ " dropped due to no socket space ");
}
#undef ANY
Index: src/usr.bin/netstat/bpf.c
diff -u src/usr.bin/netstat/bpf.c:1.11 src/usr.bin/netstat/bpf.c:1.11.22.1
--- src/usr.bin/netstat/bpf.c:1.11 Fri Dec 14 08:15:44 2012
+++ src/usr.bin/netstat/bpf.c Mon Sep 12 14:29:19 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: bpf.c,v 1.11 2012/12/14 08:15:44 msaitoh Exp $ */
+/* $NetBSD: bpf.c,v 1.11.22.1 2022/09/12 14:29:19 martin Exp $ */
/*
* Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -55,17 +55,16 @@ bpf_stats(void)
if (use_sysctl) {
if (sysctlbyname("net.bpf.stats", &bpf_s, &len, NULL, 0) == -1)
err(1, "net.bpf.stats");
-
+
printf("bpf:\n");
- printf("\t%" PRIu64 " total packets received\n",
+ printf("\t%" PRIu64 " total packets received\n",
bpf_s.bs_recv);
- printf("\t%" PRIu64 " total packets captured\n",
+ printf("\t%" PRIu64 " total packets captured\n",
bpf_s.bs_capt);
- printf("\t%" PRIu64 " total packets dropped\n",
+ printf("\t%" PRIu64 " total packets dropped\n",
bpf_s.bs_drop);
- } else {
+ } else
warnx("BPF stats not available via KVM.");
- }
}
void
@@ -79,7 +78,7 @@ bpf_dump(const char *bpfif)
u_int namelen;
void *v;
struct kinfo_proc2 p;
-
+
/* adapted from sockstat.c by Andrew Brown */
sz = CTL_MAXNAME;
@@ -89,7 +88,7 @@ bpf_dump(const char *bpfif)
name[namelen++] = sizeof(*dpe);
name[namelen++] = INT_MAX;
-
+
v = NULL;
sz = 0;
do {
@@ -117,19 +116,19 @@ bpf_dump(const char *bpfif)
#define BPFEXT(entry) dpe->entry
for (i = 0; i < (sz / sizeof(*dpe)); i++, dpe++) {
- if (bpfif &&
+ if (bpfif &&
strncmp(BPFEXT(bde_ifname), bpfif, IFNAMSIZ))
continue;
-
+
printf("%-7d ", BPFEXT(bde_pid));
printf("%-7s ",
- (BPFEXT(bde_ifname)[0] == '\0') ? "-" :
+ (BPFEXT(bde_ifname)[0] == '\0') ? "-" :
BPFEXT(bde_ifname));
- printf("%-8" PRIu64 " %-8" PRIu64 " %-8" PRIu64 " ",
- BPFEXT(bde_rcount), BPFEXT(bde_dcount),
+ printf("%-8" PRIu64 " %-8" PRIu64 " %-8" PRIu64 " ",
+ BPFEXT(bde_rcount), BPFEXT(bde_dcount),
BPFEXT(bde_ccount));
-
+
switch (BPFEXT(bde_state)) {
case BPF_IDLE:
printf("I");
@@ -144,7 +143,7 @@ bpf_dump(const char *bpfif)
printf("-");
break;
}
-
+
printf("%c", BPFEXT(bde_promisc) ? 'P' : '-');
printf("%c", BPFEXT(bde_immediate) ? 'R' : '-');
printf("%c", BPFEXT(bde_seesent) ? 'S' : '-');
@@ -160,7 +159,7 @@ bpf_dump(const char *bpfif)
name[namelen++] = szproc;
name[namelen++] = 1;
- if (prog_sysctl(&name[0], namelen, &p, &szproc,
+ if (prog_sysctl(&name[0], namelen, &p, &szproc,
NULL, 0) == -1)
printf("-\n");
else
@@ -169,7 +168,7 @@ bpf_dump(const char *bpfif)
}
free(v);
} else {
- /* XXX */
- errx(1, "bpf_dump not implemented using kvm");
- }
+ /* XXX */
+ errx(1, "bpf_dump not implemented using kvm");
+ }
}
Index: src/usr.bin/netstat/fast_ipsec.c
diff -u src/usr.bin/netstat/fast_ipsec.c:1.21.4.1 src/usr.bin/netstat/fast_ipsec.c:1.21.4.2
--- src/usr.bin/netstat/fast_ipsec.c:1.21.4.1 Sat Oct 21 19:43:56 2017
+++ src/usr.bin/netstat/fast_ipsec.c Mon Sep 12 14:29:19 2022
@@ -1,5 +1,5 @@
-/* $NetBSD: fast_ipsec.c,v 1.21.4.1 2017/10/21 19:43:56 snj Exp $ */
-/* $FreeBSD: src/tools/tools/crypto/ipsecstats.c,v 1.1.4.1 2003/06/03 00:13:13 sam Exp $ */
+/* $NetBSD: fast_ipsec.c,v 1.21.4.2 2022/09/12 14:29:19 martin Exp $ */
+/* $FreeBSD: src/tools/tools/crypto/ipsecstats.c,v 1.1.4.1 2003/06/03 00:13:13 sam Exp $ */
/*-
* Copyright (c) 2003, 2004 Jonathan Stone
@@ -33,7 +33,7 @@
#include <sys/cdefs.h>
#ifndef lint
#ifdef __NetBSD__
-__RCSID("$NetBSD: fast_ipsec.c,v 1.21.4.1 2017/10/21 19:43:56 snj Exp $");
+__RCSID("$NetBSD: fast_ipsec.c,v 1.21.4.2 2022/09/12 14:29:19 martin Exp $");
#endif
#endif /* not lint*/
@@ -88,7 +88,7 @@ algname(size_t a, const char *algs[], si
/*
* Print the fast_ipsec statistics.
- * Since NetBSD's netstat(1) seems not to find us for "netstat -s",
+ * Since NetBSD's netstat(1) seems not to find us for "netstat -s",
* but does(?) find KAME, be prepared to be called explicitly from
* netstat's main program for "netstat -s"; but silently do nothing
* if that happens when we are running on KAME IPsec.
@@ -147,125 +147,139 @@ fast_ipsec_stats(u_long off, const char
printf("%s:\n", name);
-#define STAT(x,fmt) if ((x) || sflag <= 1) printf("\t%"PRIu64" " fmt "\n", x)
+#define STAT(x, fmt) \
+ if (ipsecstats[x] || sflag <= 1) \
+ printf("\t%"PRIu64" " fmt "\n", ipsecstats[x])
+
if (ipsecstats[IPSEC_STAT_IN_POLVIO]+ipsecstats[IPSEC_STAT_OUT_POLVIO])
- printf("\t%"PRIu64" policy violations: %"PRIu64" input %"PRIu64" output\n",
- ipsecstats[IPSEC_STAT_IN_POLVIO] + ipsecstats[IPSEC_STAT_OUT_POLVIO],
- ipsecstats[IPSEC_STAT_IN_POLVIO], ipsecstats[IPSEC_STAT_OUT_POLVIO]);
- STAT(ipsecstats[IPSEC_STAT_OUT_NOSA], "no SA found (output)");
- STAT(ipsecstats[IPSEC_STAT_OUT_NOMEM], "no memory available (output)");
- STAT(ipsecstats[IPSEC_STAT_OUT_NOROUTE], "no route available (output)");
- STAT(ipsecstats[IPSEC_STAT_OUT_INVAL], "generic errors (output)");
- STAT(ipsecstats[IPSEC_STAT_OUT_BUNDLESA], "bundled SA processed (output)");
- STAT(ipsecstats[IPSEC_STAT_SPDCACHELOOKUP], "SPD cache lookups");
- STAT(ipsecstats[IPSEC_STAT_SPDCACHEMISS], "SPD cache misses");
+ printf("\t%"PRIu64" policy violations: %"PRIu64" input %"
+ PRIu64" output\n",
+ ipsecstats[IPSEC_STAT_IN_POLVIO] + ipsecstats[IPSEC_STAT_OUT_POLVIO],
+ ipsecstats[IPSEC_STAT_IN_POLVIO], ipsecstats[IPSEC_STAT_OUT_POLVIO]);
+ STAT(IPSEC_STAT_OUT_NOSA, "no SA found (output)");
+ STAT(IPSEC_STAT_OUT_NOMEM, "no memory available (output)");
+ STAT(IPSEC_STAT_OUT_NOROUTE, "no route available (output)");
+ STAT(IPSEC_STAT_OUT_INVAL, "generic errors (output)");
+ STAT(IPSEC_STAT_OUT_BUNDLESA, "bundled SA processed (output)");
+ STAT(IPSEC_STAT_SPDCACHELOOKUP, "SPD cache lookups");
+ STAT(IPSEC_STAT_SPDCACHEMISS, "SPD cache misses");
#undef STAT
-
+
printf("\tah:\n");
-#define AHSTAT(x,fmt) if ((x) || sflag <= 1) printf("\t\t%"PRIu64" ah " fmt "\n", x)
- AHSTAT(ahstats[AH_STAT_INPUT], "input packets processed");
- AHSTAT(ahstats[AH_STAT_OUTPUT], "output packets processed");
- AHSTAT(ahstats[AH_STAT_HDROPS], "headers too short");
- AHSTAT(ahstats[AH_STAT_NOPF], "headers for unsupported address family");
- AHSTAT(ahstats[AH_STAT_NOTDB], "packets with no SA");
- AHSTAT(ahstats[AH_STAT_BADKCR], "packets dropped by crypto returning NULL mbuf");
- AHSTAT(ahstats[AH_STAT_BADAUTH], "packets with bad authentication");
- AHSTAT(ahstats[AH_STAT_NOXFORM], "packets with no xform");
- AHSTAT(ahstats[AH_STAT_QFULL], "packets dropped due to queue full");
- AHSTAT(ahstats[AH_STAT_WRAP], "packets dropped for replay counter wrap");
- AHSTAT(ahstats[AH_STAT_REPLAY], "packets dropped for possible replay");
- AHSTAT(ahstats[AH_STAT_BADAUTHL],"packets dropped for bad authenticator length");
- AHSTAT(ahstats[AH_STAT_INVALID], "packets with an invalid SA");
- AHSTAT(ahstats[AH_STAT_TOOBIG], "packets too big");
- AHSTAT(ahstats[AH_STAT_PDROPS], "packets blocked due to policy");
- AHSTAT(ahstats[AH_STAT_CRYPTO], "failed crypto requests");
- AHSTAT(ahstats[AH_STAT_TUNNEL], "tunnel sanity check failures");
+#define AHSTAT(x, fmt) \
+ if (ahstats[x] || sflag <= 1) \
+ printf("\t\t%"PRIu64" ah " fmt "\n", ahstats[x])
+
+ AHSTAT(AH_STAT_INPUT, "input packets processed");
+ AHSTAT(AH_STAT_OUTPUT, "output packets processed");
+ AHSTAT(AH_STAT_HDROPS, "headers too short");
+ AHSTAT(AH_STAT_NOPF, "headers for unsupported address family");
+ AHSTAT(AH_STAT_NOTDB, "packets with no SA");
+ AHSTAT(AH_STAT_BADKCR,
+ "packets dropped by crypto returning NULL mbuf");
+ AHSTAT(AH_STAT_BADAUTH, "packets with bad authentication");
+ AHSTAT(AH_STAT_NOXFORM, "packets with no xform");
+ AHSTAT(AH_STAT_QFULL, "packets dropped due to queue full");
+ AHSTAT(AH_STAT_WRAP, "packets dropped for replay counter wrap");
+ AHSTAT(AH_STAT_REPLAY, "packets dropped for possible replay");
+ AHSTAT(AH_STAT_BADAUTHL,
+ "packets dropped for bad authenticator length");
+ AHSTAT(AH_STAT_INVALID, "packets with an invalid SA");
+ AHSTAT(AH_STAT_TOOBIG, "packets too big");
+ AHSTAT(AH_STAT_PDROPS, "packets blocked due to policy");
+ AHSTAT(AH_STAT_CRYPTO, "failed crypto requests");
+ AHSTAT(AH_STAT_TUNNEL, "tunnel sanity check failures");
printf("\tah histogram:\n");
for (i = 0; i < AH_ALG_MAX; i++)
if (ahstats[AH_STAT_HIST + i])
- printf("\t\tah packets with %s: %"PRIu64"\n"
- , algname(i, ahalgs, __arraycount(ahalgs))
- , ahstats[AH_STAT_HIST + i]
- );
- AHSTAT(ahstats[AH_STAT_IBYTES], "bytes received");
- AHSTAT(ahstats[AH_STAT_OBYTES], "bytes transmitted");
+ printf("\t\tah packets with %s: %"PRIu64"\n",
+ algname(i, ahalgs, __arraycount(ahalgs)),
+ ahstats[AH_STAT_HIST + i]);
+ AHSTAT(AH_STAT_IBYTES, "bytes received");
+ AHSTAT(AH_STAT_OBYTES, "bytes transmitted");
#undef AHSTAT
printf("\tesp:\n");
-#define ESPSTAT(x,fmt) if ((x) || sflag <= 1) printf("\t\t%"PRIu64" esp " fmt "\n", x)
- ESPSTAT(espstats[ESP_STAT_INPUT],"input packets processed");
- ESPSTAT(espstats[ESP_STAT_OUTPUT],"output packets processed");
- ESPSTAT(espstats[ESP_STAT_HDROPS],"headers too short");
- ESPSTAT(espstats[ESP_STAT_NOPF], "headers for unsupported address family");
- ESPSTAT(espstats[ESP_STAT_NOTDB],"packets with no SA");
- ESPSTAT(espstats[ESP_STAT_BADKCR],"packets dropped by crypto returning NULL mbuf");
- ESPSTAT(espstats[ESP_STAT_QFULL],"packets dropped due to queue full");
- ESPSTAT(espstats[ESP_STAT_NOXFORM],"packets with no xform");
- ESPSTAT(espstats[ESP_STAT_BADILEN],"packets with bad ilen");
- ESPSTAT(espstats[ESP_STAT_BADENC],"packets with bad encryption");
- ESPSTAT(espstats[ESP_STAT_BADAUTH],"packets with bad authentication");
- ESPSTAT(espstats[ESP_STAT_WRAP], "packets dropped for replay counter wrap");
- ESPSTAT(espstats[ESP_STAT_REPLAY],"packets dropped for possible replay");
- ESPSTAT(espstats[ESP_STAT_INVALID],"packets with an invalid SA");
- ESPSTAT(espstats[ESP_STAT_TOOBIG],"packets too big");
- ESPSTAT(espstats[ESP_STAT_PDROPS],"packets blocked due to policy");
- ESPSTAT(espstats[ESP_STAT_CRYPTO],"failed crypto requests");
- ESPSTAT(espstats[ESP_STAT_TUNNEL],"tunnel sanity check failures");
+#define ESPSTAT(x, fmt) \
+ if (espstats[x] || sflag <= 1) \
+ printf("\t\t%"PRIu64" esp " fmt "\n", espstats[x])
+
+ ESPSTAT(ESP_STAT_INPUT, "input packets processed");
+ ESPSTAT(ESP_STAT_OUTPUT, "output packets processed");
+ ESPSTAT(ESP_STAT_HDROPS, "headers too short");
+ ESPSTAT(ESP_STAT_NOPF, "headers for unsupported address family");
+ ESPSTAT(ESP_STAT_NOTDB, "packets with no SA");
+ ESPSTAT(ESP_STAT_BADKCR,
+ "packets dropped by crypto returning NULL mbuf");
+ ESPSTAT(ESP_STAT_QFULL, "packets dropped due to queue full");
+ ESPSTAT(ESP_STAT_NOXFORM, "packets with no xform");
+ ESPSTAT(ESP_STAT_BADILEN, "packets with bad ilen");
+ ESPSTAT(ESP_STAT_BADENC, "packets with bad encryption");
+ ESPSTAT(ESP_STAT_BADAUTH, "packets with bad authentication");
+ ESPSTAT(ESP_STAT_WRAP, "packets dropped for replay counter wrap");
+ ESPSTAT(ESP_STAT_REPLAY, "packets dropped for possible replay");
+ ESPSTAT(ESP_STAT_INVALID, "packets with an invalid SA");
+ ESPSTAT(ESP_STAT_TOOBIG, "packets too big");
+ ESPSTAT(ESP_STAT_PDROPS, "packets blocked due to policy");
+ ESPSTAT(ESP_STAT_CRYPTO, "failed crypto requests");
+ ESPSTAT(ESP_STAT_TUNNEL, "tunnel sanity check failures");
printf("\tesp histogram:\n");
for (i = 0; i < ESP_ALG_MAX; i++)
if (espstats[ESP_STAT_HIST + i])
- printf("\t\tesp packets with %s: %"PRIu64"\n"
- , algname(i, espalgs, __arraycount(espalgs))
- , espstats[ESP_STAT_HIST + i]
- );
- ESPSTAT(espstats[ESP_STAT_IBYTES], "bytes received");
- ESPSTAT(espstats[ESP_STAT_OBYTES], "bytes transmitted");
+ printf("\t\tesp packets with %s: %"PRIu64"\n",
+ algname(i, espalgs, __arraycount(espalgs)),
+ espstats[ESP_STAT_HIST + i]);
+ ESPSTAT(ESP_STAT_IBYTES, "bytes received");
+ ESPSTAT(ESP_STAT_OBYTES, "bytes transmitted");
#undef ESPSTAT
printf("\tipip:\n");
-#define IPIPSTAT(x,fmt) \
- if ((x) || sflag <= 1) printf("\t\t%"PRIu64" ipip " fmt "\n", x)
- IPIPSTAT(ipips[IPIP_STAT_IPACKETS],"total input packets");
- IPIPSTAT(ipips[IPIP_STAT_OPACKETS],"total output packets");
- IPIPSTAT(ipips[IPIP_STAT_HDROPS],"packets too short for header length");
- IPIPSTAT(ipips[IPIP_STAT_QFULL],"packets dropped due to queue full");
- IPIPSTAT(ipips[IPIP_STAT_PDROPS],"packets blocked due to policy");
- IPIPSTAT(ipips[IPIP_STAT_SPOOF],"IP spoofing attempts");
- IPIPSTAT(ipips[IPIP_STAT_FAMILY],"protocol family mismatched");
- IPIPSTAT(ipips[IPIP_STAT_UNSPEC],"missing tunnel-endpoint address");
- IPIPSTAT(ipips[IPIP_STAT_IBYTES],"input bytes received");
- IPIPSTAT(ipips[IPIP_STAT_OBYTES],"output bytes processed");
+#define IPIPSTAT(x, fmt) \
+ if (ipips[x] || sflag <= 1) \
+ printf("\t\t%"PRIu64" ipip " fmt "\n", ipips[x])
+
+ IPIPSTAT(IPIP_STAT_IPACKETS, "total input packets");
+ IPIPSTAT(IPIP_STAT_OPACKETS, "total output packets");
+ IPIPSTAT(IPIP_STAT_HDROPS, "packets too short for header length");
+ IPIPSTAT(IPIP_STAT_QFULL, "packets dropped due to queue full");
+ IPIPSTAT(IPIP_STAT_PDROPS, "packets blocked due to policy");
+ IPIPSTAT(IPIP_STAT_SPOOF, "IP spoofing attempts");
+ IPIPSTAT(IPIP_STAT_FAMILY, "protocol family mismatched");
+ IPIPSTAT(IPIP_STAT_UNSPEC, "missing tunnel-endpoint address");
+ IPIPSTAT(IPIP_STAT_IBYTES, "input bytes received");
+ IPIPSTAT(IPIP_STAT_OBYTES, "output bytes processed");
#undef IPIPSTAT
printf("\tipcomp:\n");
-#define IPCOMP(x,fmt) \
- if ((x) || sflag <= 1) printf("\t\t%"PRIu64" ipcomp " fmt "\n", x)
-
- IPCOMP(ipcs[IPCOMP_STAT_HDROPS],"packets too short for header length");
- IPCOMP(ipcs[IPCOMP_STAT_NOPF], "protocol family not supported");
- IPCOMP(ipcs[IPCOMP_STAT_NOTDB], "packets with no SA");
- IPCOMP(ipcs[IPCOMP_STAT_BADKCR],"packets dropped by crypto returning NULL mbuf");
- IPCOMP(ipcs[IPCOMP_STAT_QFULL], "queue full");
- IPCOMP(ipcs[IPCOMP_STAT_NOXFORM],"no support for transform");
- IPCOMP(ipcs[IPCOMP_STAT_WRAP], "packets dropped for replay counter wrap");
- IPCOMP(ipcs[IPCOMP_STAT_INPUT], "input IPcomp packets");
- IPCOMP(ipcs[IPCOMP_STAT_OUTPUT],"output IPcomp packets");
- IPCOMP(ipcs[IPCOMP_STAT_INVALID],"packets with an invalid SA");
- IPCOMP(ipcs[IPCOMP_STAT_TOOBIG],"packets decompressed as too big");
- IPCOMP(ipcs[IPCOMP_STAT_MINLEN], "packets too short to be compressed");
- IPCOMP(ipcs[IPCOMP_STAT_USELESS],"packet for which compression was useless");
- IPCOMP(ipcs[IPCOMP_STAT_PDROPS],"packets blocked due to policy");
- IPCOMP(ipcs[IPCOMP_STAT_CRYPTO],"failed crypto requests");
+#define IPCOMP(x, fmt) \
+ if (ipcs[x] || sflag <= 1) \
+ printf("\t\t%"PRIu64" ipcomp " fmt "\n", ipcs[x])
+
+ IPCOMP(IPCOMP_STAT_HDROPS, "packets too short for header length");
+ IPCOMP(IPCOMP_STAT_NOPF, "protocol family not supported");
+ IPCOMP(IPCOMP_STAT_NOTDB, "packets with no SA");
+ IPCOMP(IPCOMP_STAT_BADKCR,
+ "packets dropped by crypto returning NULL mbuf");
+ IPCOMP(IPCOMP_STAT_QFULL, "queue full");
+ IPCOMP(IPCOMP_STAT_NOXFORM, "no support for transform");
+ IPCOMP(IPCOMP_STAT_WRAP, "packets dropped for replay counter wrap");
+ IPCOMP(IPCOMP_STAT_INPUT, "input IPcomp packets");
+ IPCOMP(IPCOMP_STAT_OUTPUT, "output IPcomp packets");
+ IPCOMP(IPCOMP_STAT_INVALID, "packets with an invalid SA");
+ IPCOMP(IPCOMP_STAT_TOOBIG, "packets decompressed as too big");
+ IPCOMP(IPCOMP_STAT_MINLEN, "packets too short to be compressed");
+ IPCOMP(IPCOMP_STAT_USELESS,"packet for which compression was useless");
+ IPCOMP(IPCOMP_STAT_PDROPS, "packets blocked due to policy");
+ IPCOMP(IPCOMP_STAT_CRYPTO, "failed crypto requests");
printf("\tipcomp histogram:\n");
for (i = 0; i < IPCOMP_ALG_MAX; i++)
if (ipcs[IPCOMP_STAT_HIST + i])
- printf("\t\tIPcomp packets with %s: %"PRIu64"\n"
- , algname(i, ipcompalgs, __arraycount(ipcompalgs))
- , ipcs[IPCOMP_STAT_HIST + i]
- );
- IPCOMP(ipcs[IPCOMP_STAT_IBYTES],"input bytes");
- IPCOMP(ipcs[IPCOMP_STAT_OBYTES],"output bytes");
+ printf("\t\tIPcomp packets with %s: %"PRIu64"\n",
+ algname(i, ipcompalgs, __arraycount(ipcompalgs)),
+ ipcs[IPCOMP_STAT_HIST + i]);
+ IPCOMP(IPCOMP_STAT_IBYTES, "input bytes");
+ IPCOMP(IPCOMP_STAT_OBYTES, "output bytes");
#undef IPCOMP
}
Index: src/usr.bin/netstat/if.c
diff -u src/usr.bin/netstat/if.c:1.94.4.1 src/usr.bin/netstat/if.c:1.94.4.2
--- src/usr.bin/netstat/if.c:1.94.4.1 Thu Jul 26 23:43:31 2018
+++ src/usr.bin/netstat/if.c Mon Sep 12 14:29:19 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: if.c,v 1.94.4.1 2018/07/26 23:43:31 snj Exp $ */
+/* $NetBSD: if.c,v 1.94.4.2 2022/09/12 14:29:19 martin Exp $ */
/*
* Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "from: @(#)if.c 8.2 (Berkeley) 2/21/94";
#else
-__RCSID("$NetBSD: if.c,v 1.94.4.1 2018/07/26 23:43:31 snj Exp $");
+__RCSID("$NetBSD: if.c,v 1.94.4.2 2022/09/12 14:29:19 martin Exp $");
#endif
#endif /* not lint */
@@ -76,16 +76,21 @@ struct iftot {
u_quad_t ift_ip; /* input packets */
u_quad_t ift_ib; /* input bytes */
u_quad_t ift_ie; /* input errors */
+ u_quad_t ift_iq; /* input drops */
u_quad_t ift_op; /* output packets */
u_quad_t ift_ob; /* output bytes */
u_quad_t ift_oe; /* output errors */
+ u_quad_t ift_oq; /* output drops */
u_quad_t ift_co; /* collisions */
- u_quad_t ift_dr; /* drops */
+};
+
+struct if_data_ext {
+ uint64_t ifi_oqdrops;
};
static void set_lines(void);
static void print_addr(const int, struct sockaddr *, struct sockaddr **,
- struct if_data *, struct ifnet *);
+ struct if_data *, struct ifnet *, struct if_data_ext *);
static void sidewaysintpr(u_int, u_long);
static void iftot_banner(struct iftot *);
@@ -96,6 +101,7 @@ static void catchalarm(int);
static void get_rtaddrs(int, struct sockaddr *, struct sockaddr **);
static void fetchifs(void);
+static int if_data_ext_get(const char *, struct if_data_ext *);
static void intpr_sysctl(void);
static void intpr_kvm(u_long, void (*)(const char *));
@@ -132,12 +138,10 @@ intpr(int interval, u_long ifnetaddr, vo
return;
}
- if (use_sysctl) {
+ if (use_sysctl)
intpr_sysctl();
- } else {
+ else
intpr_kvm(ifnetaddr, pfunc);
- }
-
}
static void
@@ -147,9 +151,9 @@ intpr_header(void)
if (!sflag && !pflag) {
if (bflag) {
printf("%-5.5s %-5.5s %-13.13s %-17.17s "
- "%10.10s %10.10s",
- "Name", "Mtu", "Network", "Address",
- "Ibytes", "Obytes");
+ "%10.10s %10.10s",
+ "Name", "Mtu", "Network", "Address",
+ "Ibytes", "Obytes");
} else {
printf("%-5.5s %-5.5s %-13.13s %-17.17s "
"%8.8s %5.5s",
@@ -167,6 +171,28 @@ intpr_header(void)
}
}
+int
+if_data_ext_get(const char *ifname, struct if_data_ext *dext)
+{
+ char namebuf[1024];
+ size_t len;
+ int drops;
+
+ /* For sysctl */
+ snprintf(namebuf, sizeof(namebuf),
+ "net.interfaces.%s.sndq.drops", ifname);
+ len = sizeof(drops);
+ if (sysctlbyname(namebuf, &drops, &len, NULL, 0)
+ == -1) {
+ warnx("'%s' not found", namebuf);
+ dext->ifi_oqdrops = 0;
+ return -1;
+ } else
+ dext->ifi_oqdrops = drops;
+
+ return 0;
+}
+
static void
intpr_sysctl(void)
{
@@ -184,6 +210,7 @@ intpr_sysctl(void)
size_t len;
int did = 1, rtax = 0, n;
char name[IFNAMSIZ + 1]; /* + 1 for `*' */
+ char origname[IFNAMSIZ]; /* without `*' */
int ifindex = 0;
if (prog_sysctl(mib, 6, NULL, &len, NULL, 0) == -1)
@@ -201,6 +228,8 @@ intpr_sysctl(void)
lim = buf + len;
for (next = buf; next < lim; next += rtm->rtm_msglen) {
+ struct if_data_ext dext;
+
rtm = (struct rt_msghdr *)next;
if (rtm->rtm_version != RTM_VERSION)
continue;
@@ -214,25 +243,29 @@ intpr_sysctl(void)
get_rtaddrs(ifm->ifm_addrs, sa, rti_info);
sdl = (struct sockaddr_dl *)rti_info[RTAX_IFP];
- if (sdl == NULL || sdl->sdl_family != AF_LINK) {
+ if (sdl == NULL || sdl->sdl_family != AF_LINK)
continue;
- }
+
bzero(name, sizeof(name));
if (sdl->sdl_nlen >= IFNAMSIZ)
memcpy(name, sdl->sdl_data, IFNAMSIZ - 1);
- else if (sdl->sdl_nlen > 0)
+ else if (sdl->sdl_nlen > 0)
memcpy(name, sdl->sdl_data, sdl->sdl_nlen);
- if (interface != 0 && strcmp(name, interface) != 0)
+ if (interface != NULL && strcmp(name, interface) != 0)
continue;
ifindex = sdl->sdl_index;
- /* mark inactive interfaces with a '*' */
+ /* Keep the original name */
+ strcpy(origname, name);
+
+ /* Mark inactive interfaces with a '*' */
cp = strchr(name, '\0');
- if ((ifm->ifm_flags & IFF_UP) == 0)
+ if ((ifm->ifm_flags & IFF_UP) == 0) {
*cp++ = '*';
- *cp = '\0';
+ *cp = '\0';
+ }
if (qflag) {
total = ifd->ifi_ibytes + ifd->ifi_obytes +
@@ -254,7 +287,7 @@ intpr_sysctl(void)
case RTM_NEWADDR:
if (qflag && total == 0)
continue;
- if (interface != 0 && strcmp(name, interface) != 0)
+ if (interface != NULL && strcmp(name, interface) != 0)
continue;
ifam = (struct ifa_msghdr *)next;
if ((ifam->ifam_addrs & (RTA_NETMASK | RTA_IFA |
@@ -276,7 +309,11 @@ intpr_sysctl(void)
n = 5;
printf("%-*.*s %-5" PRIu64 " ", n, n, name, ifd->ifi_mtu);
- print_addr(ifindex, rti_info[rtax], rti_info, ifd, NULL);
+ if (dflag)
+ if_data_ext_get(origname, &dext);
+
+ print_addr(ifindex, rti_info[rtax], rti_info, ifd,
+ NULL, dflag ? &dext : NULL);
}
}
@@ -324,7 +361,7 @@ intpr_kvm(u_long ifnetaddr, void (*pfunc
memmove(name, ifnet.if_xname, IFNAMSIZ);
name[IFNAMSIZ - 1] = '\0'; /* sanity */
ifnetaddr = (u_long)ifnet.if_list.tqe_next;
- if (interface != 0 && strcmp(name, interface) != 0)
+ if (interface != NULL && strcmp(name, interface) != 0)
continue;
cp = strchr(name, '\0');
@@ -350,7 +387,8 @@ intpr_kvm(u_long ifnetaddr, void (*pfunc
} else {
struct sockaddr *sa;
- if (kread(ifaddraddr, (char *)&ifaddr, sizeof ifaddr)) {
+ if (kread(ifaddraddr, (char *)&ifaddr, sizeof ifaddr))
+ {
ifaddraddr = 0;
continue;
}
@@ -359,7 +397,7 @@ intpr_kvm(u_long ifnetaddr, void (*pfunc
CP(&ifaddr);
sa = (struct sockaddr *)cp;
print_addr(ifnet.if_index, sa, (void *)&ifaddr,
- &ifnet.if_data, &ifnet);
+ &ifnet.if_data, &ifnet, NULL);
}
ifaddraddr = (u_long)ifaddr.ifa.ifa_list.tqe_next;
}
@@ -456,8 +494,8 @@ mc4_print(const int ifindex)
}
static void
-print_addr(const int ifindex, struct sockaddr *sa,
- struct sockaddr **rtinfo, struct if_data *ifd, struct ifnet *ifnet)
+print_addr(const int ifindex, struct sockaddr *sa, struct sockaddr **rtinfo,
+ struct if_data *ifd, struct ifnet *ifnet, struct if_data_ext *dext)
{
char hexsep = '.'; /* for hexprint */
static const char hexfmt[] = "%02x%c"; /* for hexprint */
@@ -479,7 +517,8 @@ print_addr(const int ifindex, struct soc
case AF_INET:
sin = (struct sockaddr_in *)sa;
if (use_sysctl) {
- netmask = *((struct sockaddr_in *)rtinfo[RTAX_NETMASK]);
+ netmask =
+ *((struct sockaddr_in *)rtinfo[RTAX_NETMASK]);
} else {
struct in_ifaddr *ifaddr_in = (void *)rtinfo;
netmask.sin_addr.s_addr = ifaddr_in->ia_subnetmask;
@@ -510,9 +549,8 @@ print_addr(const int ifindex, struct soc
ia4_print(&inm.inm_addr);
multiaddr = (u_long)inm.inm_list.le_next;
}
- } else {
+ } else
mc4_print(ifindex);
- }
break;
#ifdef INET6
case AF_INET6:
@@ -523,9 +561,9 @@ print_addr(const int ifindex, struct soc
sin6->sin6_scope_id = 0;
#endif
- if (use_sysctl) {
+ if (use_sysctl)
netmask6 = (struct sockaddr_in6 *)rtinfo[RTAX_NETMASK];
- } else {
+ else {
struct in6_ifaddr *ifaddr_in6 = (void *)rtinfo;
netmask6 = &ifaddr_in6->ia_prefixmask;
}
@@ -549,29 +587,27 @@ print_addr(const int ifindex, struct soc
n = 17;
printf("%-*.*s ", n, n, cp);
- if (!aflag)
+ if (!aflag)
break;
if (ifnet) {
u_long multiaddr;
struct in6_multi inm;
union ifaddr_u *ifaddr = (union ifaddr_u *)rtinfo;
-
+
multiaddr = (u_long)ifaddr->in6._ia6_multiaddrs.lh_first;
while (multiaddr != 0) {
kread(multiaddr, (char *)&inm, sizeof inm);
ia6_print(&inm.in6m_addr);
multiaddr = (u_long)inm.in6m_entry.le_next;
}
- } else {
+ } else
mc6_print(ifindex);
- }
break;
#endif /*INET6*/
#ifndef SMALL
case AF_APPLETALK:
- printf("atalk:%-7.7s ",
- atalk_print(sa,0x10));
- printf("%-17.17s ", atalk_print(sa,0x0b));
+ printf("atalk:%-7.7s ", atalk_print(sa, 0x10));
+ printf("%-17.17s ", atalk_print(sa, 0x0b));
break;
#endif
case AF_LINK:
@@ -632,7 +668,8 @@ print_addr(const int ifindex, struct soc
}
if (dflag)
printf(" %6lld", ifnet ?
- (unsigned long long)ifnet->if_snd.ifq_drops : 0);
+ (unsigned long long)ifnet->if_snd.ifq_drops :
+ dext->ifi_oqdrops);
if (tflag)
printf(" %4d", ifnet ? ifnet->if_timer : 0);
putchar('\n');
@@ -697,7 +734,7 @@ iftot_print(struct iftot *cur, struct if
cur->ift_oe - old->ift_oe,
cur->ift_co - old->ift_co);
if (dflag)
- printf(" %5" PRIu64, cur->ift_dr - old->ift_dr);
+ printf(" %5" PRIu64, cur->ift_oq - old->ift_oq);
}
static void
@@ -716,7 +753,7 @@ iftot_print_sum(struct iftot *cur, struc
cur->ift_co - old->ift_co);
if (dflag)
- printf(" %5" PRIu64, cur->ift_dr - old->ift_dr);
+ printf(" %5" PRIu64, cur->ift_oq - old->ift_oq);
}
__dead static void
@@ -770,9 +807,9 @@ loop:
putchar('\n');
fflush(stdout);
line++;
- if (signalled == 0) {
+ if (signalled == 0)
sigsuspend(&emptyset);
- }
+
signalled = 0;
if (line == redraw_lines)
goto banner;
@@ -864,11 +901,12 @@ banner:
ip->ift_ip = 0;
ip->ift_ib = 0;
ip->ift_ie = 0;
+ ip->ift_iq = 0;
ip->ift_op = 0;
ip->ift_ob = 0;
ip->ift_oe = 0;
+ ip->ift_oq = 0;
ip->ift_co = 0;
- ip->ift_dr = 0;
}
putchar('\n');
if (bflag)
@@ -896,11 +934,12 @@ loop:
sum->ift_ip = 0;
sum->ift_ib = 0;
sum->ift_ie = 0;
+ sum->ift_iq = 0;
sum->ift_op = 0;
sum->ift_ob = 0;
sum->ift_oe = 0;
+ sum->ift_oq = 0;
sum->ift_co = 0;
- sum->ift_dr = 0;
for (off = firstifnet, ip = iftot; off && ip < lastif; ip++) {
if (kread(off, (char *)&ifnet, sizeof ifnet)) {
off = 0;
@@ -916,7 +955,7 @@ loop:
HN_AUTOSCALE, HN_NOSPACE | HN_B) > 0)
printf("%10s %8.8s ", humbuf, " ");
else
- printf("%10llu %8.8s ",
+ printf("%10llu %8.8s ",
(unsigned long long)
(ifnet.if_ibytes-ip->ift_ib), " ");
@@ -926,7 +965,7 @@ loop:
HN_AUTOSCALE, HN_NOSPACE | HN_B) > 0)
printf("%10s %5.5s", humbuf, " ");
else
- printf("%10llu %5.5s",
+ printf("%10llu %5.5s",
(unsigned long long)
(ifnet.if_obytes-ip->ift_ob), " ");
} else {
@@ -944,7 +983,7 @@ loop:
}
if (dflag)
printf(" %5" PRIu64,
- ifnet.if_snd.ifq_drops - ip->ift_dr);
+ ifnet.if_snd.ifq_drops - ip->ift_oq);
}
ip->ift_ip = ifnet.if_ipackets;
ip->ift_ib = ifnet.if_ibytes;
@@ -953,7 +992,7 @@ loop:
ip->ift_ob = ifnet.if_obytes;
ip->ift_oe = ifnet.if_oerrors;
ip->ift_co = ifnet.if_collisions;
- ip->ift_dr = ifnet.if_snd.ifq_drops;
+ ip->ift_oq = ifnet.if_snd.ifq_drops;
sum->ift_ip += ip->ift_ip;
sum->ift_ib += ip->ift_ib;
sum->ift_ie += ip->ift_ie;
@@ -961,7 +1000,7 @@ loop:
sum->ift_ob += ip->ift_ob;
sum->ift_oe += ip->ift_oe;
sum->ift_co += ip->ift_co;
- sum->ift_dr += ip->ift_dr;
+ sum->ift_oq += ip->ift_oq;
off = (u_long)ifnet.if_list.tqe_next;
}
if (lastif - iftot > 0) {
@@ -973,7 +1012,7 @@ loop:
HN_AUTOSCALE, HN_NOSPACE | HN_B) > 0)
printf(" %10s %8.8s ", humbuf, " ");
else
- printf(" %10llu %8.8s ",
+ printf(" %10llu %8.8s ",
(unsigned long long)
(sum->ift_ib - total->ift_ib), " ");
@@ -982,7 +1021,7 @@ loop:
HN_AUTOSCALE, HN_NOSPACE | HN_B) > 0)
printf("%10s %5.5s", humbuf, " ");
else
- printf("%10llu %5.5s",
+ printf("%10llu %5.5s",
(unsigned long long)
(sum->ift_ob - total->ift_ob), " ");
} else {
@@ -1000,15 +1039,15 @@ loop:
}
if (dflag)
printf(" %5llu",
- (unsigned long long)(sum->ift_dr - total->ift_dr));
+ (unsigned long long)(sum->ift_oq - total->ift_oq));
}
*total = *sum;
putchar('\n');
fflush(stdout);
line++;
- if (signalled == 0) {
+ if (signalled == 0)
sigsuspend(&emptyset);
- }
+
signalled = 0;
if (line == redraw_lines)
goto banner;
@@ -1026,11 +1065,10 @@ static void
sidewaysintpr(unsigned int interval, u_long off)
{
- if (use_sysctl) {
+ if (use_sysctl)
sidewaysintpr_sysctl(interval);
- } else {
+ else
sidewaysintpr_kvm(interval, off);
- }
}
/*
@@ -1046,7 +1084,7 @@ catchalarm(int signo)
static void
get_rtaddrs(int addrs, struct sockaddr *sa, struct sockaddr **rti_info)
-{
+{
int i;
for (i = 0; i < RTAX_MAX; i++) {
@@ -1054,7 +1092,7 @@ get_rtaddrs(int addrs, struct sockaddr *
rti_info[i] = sa;
sa = (struct sockaddr *)((char *)(sa) +
RT_ROUNDUP(sa->sa_len));
- } else
+ } else
rti_info[i] = NULL;
}
}
@@ -1070,6 +1108,7 @@ fetchifs(void)
struct sockaddr_dl *sdl;
static char *buf = NULL;
static size_t olen;
+ struct if_data_ext dext;
char *next, *lim;
char name[IFNAMSIZ];
size_t len;
@@ -1085,6 +1124,7 @@ fetchifs(void)
if (prog_sysctl(mib, 6, buf, &len, NULL, 0) == -1)
err(1, "sysctl");
+ memset(&dext, 0, sizeof(dext));
lim = buf + len;
for (next = buf; next < lim; next += rtm->rtm_msglen) {
rtm = (struct rt_msghdr *)next;
@@ -1104,10 +1144,12 @@ fetchifs(void)
bzero(name, sizeof(name));
if (sdl->sdl_nlen >= IFNAMSIZ)
memcpy(name, sdl->sdl_data, IFNAMSIZ - 1);
- else if (sdl->sdl_nlen > 0)
+ else if (sdl->sdl_nlen > 0)
memcpy(name, sdl->sdl_data, sdl->sdl_nlen);
- if (interface != 0 && !strcmp(name, interface)) {
+ if_data_ext_get(name, &dext);
+
+ if (interface != NULL && !strcmp(name, interface)) {
strlcpy(ip_cur.ift_name, name,
sizeof(ip_cur.ift_name));
ip_cur.ift_ip = ifd->ifi_ipackets;
@@ -1117,7 +1159,8 @@ fetchifs(void)
ip_cur.ift_ob = ifd->ifi_obytes;
ip_cur.ift_oe = ifd->ifi_oerrors;
ip_cur.ift_co = ifd->ifi_collisions;
- ip_cur.ift_dr = ifd->ifi_iqdrops;
+ ip_cur.ift_iq = ifd->ifi_iqdrops;
+ ip_cur.ift_oq = dext.ifi_oqdrops;
}
sum_cur.ift_ip += ifd->ifi_ipackets;
@@ -1127,7 +1170,8 @@ fetchifs(void)
sum_cur.ift_ob += ifd->ifi_obytes;
sum_cur.ift_oe += ifd->ifi_oerrors;
sum_cur.ift_co += ifd->ifi_collisions;
- sum_cur.ift_dr += ifd->ifi_iqdrops;
+ sum_cur.ift_iq += ifd->ifi_iqdrops;
+ sum_cur.ift_oq += dext.ifi_oqdrops;
break;
}
}
@@ -1141,6 +1185,7 @@ fetchifs(void)
ip_cur.ift_ob = ifd->ifi_obytes;
ip_cur.ift_oe = ifd->ifi_oerrors;
ip_cur.ift_co = ifd->ifi_collisions;
- ip_cur.ift_dr = ifd->ifi_iqdrops;
+ ip_cur.ift_iq = ifd->ifi_iqdrops;
+ ip_cur.ift_oq = dext.ifi_oqdrops;
}
}
Index: src/usr.bin/netstat/inet.c
diff -u src/usr.bin/netstat/inet.c:1.107 src/usr.bin/netstat/inet.c:1.107.6.1
--- src/usr.bin/netstat/inet.c:1.107 Fri Dec 23 06:22:00 2016
+++ src/usr.bin/netstat/inet.c Mon Sep 12 14:29:19 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: inet.c,v 1.107 2016/12/23 06:22:00 mrg Exp $ */
+/* $NetBSD: inet.c,v 1.107.6.1 2022/09/12 14:29:19 martin Exp $ */
/*
* Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "from: @(#)inet.c 8.4 (Berkeley) 4/20/94";
#else
-__RCSID("$NetBSD: inet.c,v 1.107 2016/12/23 06:22:00 mrg Exp $");
+__RCSID("$NetBSD: inet.c,v 1.107.6.1 2022/09/12 14:29:19 martin Exp $");
#endif
#endif /* not lint */
@@ -95,7 +95,7 @@ __RCSID("$NetBSD: inet.c,v 1.107 2016/12
#include "prog_ops.h"
char *inetname(struct in_addr *);
-void inetprint(struct in_addr *, u_int16_t, const char *, int);
+void inetprint(struct in_addr *, uint16_t, const char *, int);
void print_vtw_v4(const vtw_t *);
@@ -122,7 +122,7 @@ protoprhdr(void)
printf("%-8.8s ", "PCB");
printf(
Vflag ? "%-5.5s %-6.6s %-6.6s %s%-*.*s %-*.*s %-13.13s Expires\n"
- : "%-5.5s %-6.6s %-6.6s %s%-*.*s %-*.*s %s\n",
+ : "%-5.5s %-6.6s %-6.6s %s%-*.*s %-*.*s %s\n",
"Proto", "Recv-Q", "Send-Q", compact ? "" : " ",
width, width, "Local Address",
width, width, "Foreign Address",
@@ -131,25 +131,25 @@ protoprhdr(void)
static void
protopr0(intptr_t ppcb, u_long rcv_sb_cc, u_long snd_sb_cc,
- struct in_addr *laddr, u_int16_t lport,
- struct in_addr *faddr, u_int16_t fport,
+ struct in_addr *laddr, uint16_t lport,
+ struct in_addr *faddr, uint16_t fport,
short t_state, const char *name, int inp_flags,
const struct timeval *expires)
{
static const char *shorttcpstates[] = {
"CLOSED", "LISTEN", "SYNSEN", "SYSRCV",
"ESTABL", "CLWAIT", "FWAIT1", "CLOSNG",
- "LASTAK", "FWAIT2", "TMWAIT",
+ "LASTAK", "FWAIT2", "TMWAIT"
};
int istcp;
istcp = strcmp(name, "tcp") == 0;
- if (Aflag) {
+ if (Aflag)
printf("%8" PRIxPTR " ", ppcb);
- }
+
printf("%-5.5s %6ld %6ld%s", name, rcv_sb_cc, snd_sb_cc,
- compact ? "" : " ");
+ compact ? "" : " ");
if (numeric_port) {
inetprint(laddr, lport, name, 1);
inetprint(faddr, fport, name, 1);
@@ -165,7 +165,7 @@ protopr0(intptr_t ppcb, u_long rcv_sb_cc
printf(" %d", t_state);
else
printf(" %s", compact ? shorttcpstates[t_state] :
- tcpstates[t_state]);
+ tcpstates[t_state]);
}
if (Vflag && expires != NULL) {
if (expires->tv_sec == 0 && expires->tv_usec == -1)
@@ -187,7 +187,7 @@ dbg_printf(const char *fmt, ...)
return;
}
-void
+void
print_vtw_v4(const vtw_t *vtw)
{
const vtw_v4_t *v4 = (const vtw_v4_t *)vtw;
@@ -205,23 +205,23 @@ print_vtw_v4(const vtw_t *vtw)
timersub(&vtw->expire, &now, &delta);
if (vtw->expire.tv_sec == 0 && vtw->expire.tv_usec == -1) {
- dbg_printf("%15.15s:%d %15.15s:%d reclaimed\n"
- ,buf[0], ntohs(v4->lport)
- ,buf[1], ntohs(v4->fport));
+ dbg_printf("%15.15s:%d %15.15s:%d reclaimed\n",
+ buf[0], ntohs(v4->lport),
+ buf[1], ntohs(v4->fport));
if (!(Vflag && vflag))
return;
} else if (vtw->expire.tv_sec == 0)
return;
else if (timercmp(&delta, &zero, <) && !(Vflag && vflag)) {
- dbg_printf("%15.15s:%d %15.15s:%d expired\n"
- ,buf[0], ntohs(v4->lport)
- ,buf[1], ntohs(v4->fport));
+ dbg_printf("%15.15s:%d %15.15s:%d expired\n",
+ buf[0], ntohs(v4->lport),
+ buf[1], ntohs(v4->fport));
return;
} else {
- dbg_printf("%15.15s:%d %15.15s:%d expires in %.3fms\n"
- ,buf[0], ntohs(v4->lport)
- ,buf[1], ntohs(v4->fport)
- ,delta.tv_sec * 1000.0 + delta.tv_usec / 1000.0);
+ dbg_printf("%15.15s:%d %15.15s:%d expires in %.3fms\n",
+ buf[0], ntohs(v4->lport),
+ buf[1], ntohs(v4->fport),
+ delta.tv_sec * 1000.0 + delta.tv_usec / 1000.0);
}
protopr0(0, 0, 0,
&la, v4->lport,
@@ -230,7 +230,8 @@ print_vtw_v4(const vtw_t *vtw)
}
struct kinfo_pcb *
-getpcblist_sysctl(const char *name, size_t *len) {
+getpcblist_sysctl(const char *name, size_t *len)
+{
int mib[8];
size_t namelen = 0, size = 0;
char *mibname = NULL;
@@ -247,7 +248,7 @@ getpcblist_sysctl(const char *name, size
*len = 0;
return NULL;
}
-
+
err(1, "sysctlnametomib: %s", mibname);
}
@@ -272,7 +273,8 @@ getpcblist_sysctl(const char *name, size
}
static struct kinfo_pcb *
-getpcblist_kmem(u_long off, const char *name, size_t *len) {
+getpcblist_kmem(u_long off, const char *name, size_t *len)
+{
struct inpcbtable table;
struct inpcb_hdr *next, *prev;
struct inpcb inpcb;
@@ -281,7 +283,7 @@ getpcblist_kmem(u_long off, const char *
int istcp = strcmp(name, "tcp") == 0;
struct kinfo_pcb *pcblist;
size_t size = 100, i;
- struct sockaddr_in sin;
+ struct sockaddr_in sin;
struct inpcbqueue *head;
if (off == 0) {
@@ -358,7 +360,7 @@ protopr(u_long off, const char *name)
if (use_sysctl)
pcblist = getpcblist_sysctl(name, &len);
else
- pcblist = getpcblist_kmem(off, name, &len);
+ pcblist = getpcblist_kmem(off, name, &len);
for (i = 0; i < len; i++) {
struct sockaddr_in src, dst;
@@ -366,8 +368,7 @@ protopr(u_long off, const char *name)
memcpy(&src, &pcblist[i].ki_s, sizeof(src));
memcpy(&dst, &pcblist[i].ki_d, sizeof(dst));
- if (!aflag &&
- inet_lnaof(dst.sin_addr) == INADDR_ANY)
+ if (!aflag && (inet_lnaof(dst.sin_addr) == INADDR_ANY))
continue;
if (first) {
@@ -414,18 +415,18 @@ tcp_stats(u_long off, const char *name)
printf ("%s:\n", name);
-#define ps(f, m) if (tcpstat[f] || sflag <= 1) \
- printf(m, tcpstat[f])
-#define p(f, m) if (tcpstat[f] || sflag <= 1) \
- printf(m, tcpstat[f], plural(tcpstat[f]))
-#define p2(f1, f2, m) if (tcpstat[f1] || tcpstat[f2] || sflag <= 1) \
- printf(m, tcpstat[f1], plural(tcpstat[f1]), \
- tcpstat[f2], plural(tcpstat[f2]))
-#define p2s(f1, f2, m) if (tcpstat[f1] || tcpstat[f2] || sflag <= 1) \
- printf(m, tcpstat[f1], plural(tcpstat[f1]), \
- tcpstat[f2])
-#define p3(f, m) if (tcpstat[f] || sflag <= 1) \
- printf(m, tcpstat[f], plurales(tcpstat[f]))
+#define ps(f, m) if (tcpstat[f] || sflag <= 1) \
+ printf(m, tcpstat[f])
+#define p(f, m) if (tcpstat[f] || sflag <= 1) \
+ printf(m, tcpstat[f], plural(tcpstat[f]))
+#define p2(f1, f2, m) if (tcpstat[f1] || tcpstat[f2] || sflag <= 1) \
+ printf(m, tcpstat[f1], plural(tcpstat[f1]), \
+ tcpstat[f2], plural(tcpstat[f2]))
+#define p2s(f1, f2, m) if (tcpstat[f1] || tcpstat[f2] || sflag <= 1) \
+ printf(m, tcpstat[f1], plural(tcpstat[f1]), \
+ tcpstat[f2])
+#define p3(f, m) if (tcpstat[f] || sflag <= 1) \
+ printf(m, tcpstat[f], plurales(tcpstat[f]))
p(TCP_STAT_SNDTOTAL, "\t%" PRIu64 " packet%s sent\n");
p2(TCP_STAT_SNDPACK,TCP_STAT_SNDBYTE,
@@ -442,69 +443,84 @@ tcp_stats(u_long off, const char *name)
"\t\t%" PRIu64 " send attempt%s resulted in self-quench\n");
p(TCP_STAT_RCVTOTAL, "\t%" PRIu64 " packet%s received\n");
p2(TCP_STAT_RCVACKPACK, TCP_STAT_RCVACKBYTE,
- "\t\t%" PRIu64 " ack%s (for %" PRIu64 " byte%s)\n");
+ "\t\t%" PRIu64 " ack%s (for %" PRIu64 " byte%s)\n");
p(TCP_STAT_RCVDUPACK, "\t\t%" PRIu64 " duplicate ack%s\n");
p(TCP_STAT_RCVACKTOOMUCH, "\t\t%" PRIu64 " ack%s for unsent data\n");
p2(TCP_STAT_RCVPACK, TCP_STAT_RCVBYTE,
- "\t\t%" PRIu64 " packet%s (%" PRIu64 " byte%s) received in-sequence\n");
+ "\t\t%" PRIu64 " packet%s (%" PRIu64 " byte%s) received in-sequence\n");
p2(TCP_STAT_RCVDUPPACK, TCP_STAT_RCVDUPBYTE,
- "\t\t%" PRIu64 " completely duplicate packet%s (%" PRIu64 " byte%s)\n");
+ "\t\t%" PRIu64 " completely duplicate packet%s (%" PRIu64 " byte%s)\n");
p(TCP_STAT_PAWSDROP, "\t\t%" PRIu64 " old duplicate packet%s\n");
p2(TCP_STAT_RCVPARTDUPPACK, TCP_STAT_RCVPARTDUPBYTE,
- "\t\t%" PRIu64 " packet%s with some dup. data (%" PRIu64 " byte%s duped)\n");
+ "\t\t%" PRIu64 " packet%s with some dup. data (%" PRIu64 " byte%s duped)\n");
p2(TCP_STAT_RCVOOPACK, TCP_STAT_RCVOOBYTE,
- "\t\t%" PRIu64 " out-of-order packet%s (%" PRIu64 " byte%s)\n");
+ "\t\t%" PRIu64 " out-of-order packet%s (%" PRIu64 " byte%s)\n");
p2(TCP_STAT_RCVPACKAFTERWIN, TCP_STAT_RCVBYTEAFTERWIN,
- "\t\t%" PRIu64 " packet%s (%" PRIu64 " byte%s) of data after window\n");
+ "\t\t%" PRIu64 " packet%s (%" PRIu64 " byte%s) of data after window\n");
p(TCP_STAT_RCVWINPROBE, "\t\t%" PRIu64 " window probe%s\n");
p(TCP_STAT_RCVWINUPD, "\t\t%" PRIu64 " window update packet%s\n");
- p(TCP_STAT_RCVAFTERCLOSE, "\t\t%" PRIu64 " packet%s received after close\n");
- p(TCP_STAT_RCVBADSUM, "\t\t%" PRIu64 " discarded for bad checksum%s\n");
- p(TCP_STAT_RCVBADOFF, "\t\t%" PRIu64 " discarded for bad header offset field%s\n");
- ps(TCP_STAT_RCVSHORT, "\t\t%" PRIu64 " discarded because packet too short\n");
+ p(TCP_STAT_RCVAFTERCLOSE,
+ "\t\t%" PRIu64 " packet%s received after close\n");
+ p(TCP_STAT_RCVBADSUM,
+ "\t\t%" PRIu64 " discarded for bad checksum%s\n");
+ p(TCP_STAT_RCVBADOFF,
+ "\t\t%" PRIu64 " discarded for bad header offset field%s\n");
+ ps(TCP_STAT_RCVSHORT,
+ "\t\t%" PRIu64 " discarded because packet too short\n");
p(TCP_STAT_CONNATTEMPT, "\t%" PRIu64 " connection request%s\n");
p(TCP_STAT_ACCEPTS, "\t%" PRIu64 " connection accept%s\n");
p(TCP_STAT_CONNECTS,
- "\t%" PRIu64 " connection%s established (including accepts)\n");
+ "\t%" PRIu64 " connection%s established (including accepts)\n");
p2(TCP_STAT_CLOSED, TCP_STAT_DROPS,
- "\t%" PRIu64 " connection%s closed (including %" PRIu64 " drop%s)\n");
- p(TCP_STAT_CONNDROPS, "\t%" PRIu64 " embryonic connection%s dropped\n");
+ "\t%" PRIu64 " connection%s closed (including %" PRIu64 " drop%s)\n");
+ p(TCP_STAT_CONNDROPS,
+ "\t%" PRIu64 " embryonic connection%s dropped\n");
p(TCP_STAT_DELAYED_FREE, "\t%" PRIu64 " delayed free%s of tcpcb\n");
p2(TCP_STAT_RTTUPDATED, TCP_STAT_SEGSTIMED,
- "\t%" PRIu64 " segment%s updated rtt (of %" PRIu64 " attempt%s)\n");
+ "\t%" PRIu64 " segment%s updated rtt (of %" PRIu64 " attempt%s)\n");
p(TCP_STAT_REXMTTIMEO, "\t%" PRIu64 " retransmit timeout%s\n");
p(TCP_STAT_TIMEOUTDROP,
- "\t\t%" PRIu64 " connection%s dropped by rexmit timeout\n");
+ "\t\t%" PRIu64 " connection%s dropped by rexmit timeout\n");
p2(TCP_STAT_PERSISTTIMEO, TCP_STAT_PERSISTDROPS,
"\t%" PRIu64 " persist timeout%s (resulting in %" PRIu64 " dropped "
"connection%s)\n");
p(TCP_STAT_KEEPTIMEO, "\t%" PRIu64 " keepalive timeout%s\n");
p(TCP_STAT_KEEPPROBE, "\t\t%" PRIu64 " keepalive probe%s sent\n");
- p(TCP_STAT_KEEPDROPS, "\t\t%" PRIu64 " connection%s dropped by keepalive\n");
+ p(TCP_STAT_KEEPDROPS,
+ "\t\t%" PRIu64 " connection%s dropped by keepalive\n");
p(TCP_STAT_PREDACK, "\t%" PRIu64 " correct ACK header prediction%s\n");
- p(TCP_STAT_PREDDAT, "\t%" PRIu64 " correct data packet header prediction%s\n");
+ p(TCP_STAT_PREDDAT,
+ "\t%" PRIu64 " correct data packet header prediction%s\n");
p3(TCP_STAT_PCBHASHMISS, "\t%" PRIu64 " PCB hash miss%s\n");
ps(TCP_STAT_NOPORT, "\t%" PRIu64 " dropped due to no socket\n");
- p(TCP_STAT_CONNSDRAINED, "\t%" PRIu64 " connection%s drained due to memory "
- "shortage\n");
- p(TCP_STAT_PMTUBLACKHOLE, "\t%" PRIu64 " PMTUD blackhole%s detected\n");
+ p(TCP_STAT_CONNSDRAINED,
+ "\t%" PRIu64 " connection%s drained due to memory shortage\n");
+ p(TCP_STAT_PMTUBLACKHOLE,
+ "\t%" PRIu64 " PMTUD blackhole%s detected\n");
p(TCP_STAT_BADSYN, "\t%" PRIu64 " bad connection attempt%s\n");
ps(TCP_STAT_SC_ADDED, "\t%" PRIu64 " SYN cache entries added\n");
p(TCP_STAT_SC_COLLISIONS, "\t\t%" PRIu64 " hash collision%s\n");
ps(TCP_STAT_SC_COMPLETED, "\t\t%" PRIu64 " completed\n");
- ps(TCP_STAT_SC_ABORTED, "\t\t%" PRIu64 " aborted (no space to build PCB)\n");
+ ps(TCP_STAT_SC_ABORTED,
+ "\t\t%" PRIu64 " aborted (no space to build PCB)\n");
ps(TCP_STAT_SC_TIMED_OUT, "\t\t%" PRIu64 " timed out\n");
- ps(TCP_STAT_SC_OVERFLOWED, "\t\t%" PRIu64 " dropped due to overflow\n");
- ps(TCP_STAT_SC_BUCKETOVERFLOW, "\t\t%" PRIu64 " dropped due to bucket overflow\n");
+ ps(TCP_STAT_SC_OVERFLOWED,
+ "\t\t%" PRIu64 " dropped due to overflow\n");
+ ps(TCP_STAT_SC_BUCKETOVERFLOW,
+ "\t\t%" PRIu64 " dropped due to bucket overflow\n");
ps(TCP_STAT_SC_RESET, "\t\t%" PRIu64 " dropped due to RST\n");
- ps(TCP_STAT_SC_UNREACH, "\t\t%" PRIu64 " dropped due to ICMP unreachable\n");
- ps(TCP_STAT_SC_DELAYED_FREE, "\t\t%" PRIu64 " delayed free of SYN cache "
- "entries\n");
- p(TCP_STAT_SC_RETRANSMITTED, "\t%" PRIu64 " SYN,ACK%s retransmitted\n");
- p(TCP_STAT_SC_DUPESYN, "\t%" PRIu64 " duplicate SYN%s received for entries "
+ ps(TCP_STAT_SC_UNREACH,
+ "\t\t%" PRIu64 " dropped due to ICMP unreachable\n");
+ ps(TCP_STAT_SC_DELAYED_FREE,
+ "\t\t%" PRIu64 " delayed free of SYN cache entries\n");
+ p(TCP_STAT_SC_RETRANSMITTED,
+ "\t%" PRIu64 " SYN,ACK%s retransmitted\n");
+ p(TCP_STAT_SC_DUPESYN,
+ "\t%" PRIu64 " duplicate SYN%s received for entries "
"already in the cache\n");
- p(TCP_STAT_SC_DROPPED, "\t%" PRIu64 " SYN%s dropped (no route or no space)\n");
+ p(TCP_STAT_SC_DROPPED,
+ "\t%" PRIu64 " SYN%s dropped (no route or no space)\n");
p(TCP_STAT_BADSIG, "\t%" PRIu64 " packet%s with bad signature\n");
p(TCP_STAT_GOODSIG, "\t%" PRIu64 " packet%s with good signature\n");
@@ -541,21 +557,22 @@ udp_stats(u_long off, const char *name)
printf ("%s:\n", name);
-#define ps(f, m) if (udpstat[f] || sflag <= 1) \
- printf(m, udpstat[f])
-#define p(f, m) if (udpstat[f] || sflag <= 1) \
- printf(m, udpstat[f], plural(udpstat[f]))
-#define p3(f, m) if (udpstat[f] || sflag <= 1) \
- printf(m, udpstat[f], plurales(udpstat[f]))
+#define ps(f, m) if (udpstat[f] || sflag <= 1) \
+ printf(m, udpstat[f])
+#define p(f, m) if (udpstat[f] || sflag <= 1) \
+ printf(m, udpstat[f], plural(udpstat[f]))
+#define p3(f, m) if (udpstat[f] || sflag <= 1) \
+ printf(m, udpstat[f], plurales(udpstat[f]))
p(UDP_STAT_IPACKETS, "\t%" PRIu64 " datagram%s received\n");
ps(UDP_STAT_HDROPS, "\t%" PRIu64 " with incomplete header\n");
ps(UDP_STAT_BADLEN, "\t%" PRIu64 " with bad data length field\n");
ps(UDP_STAT_BADSUM, "\t%" PRIu64 " with bad checksum\n");
ps(UDP_STAT_NOPORT, "\t%" PRIu64 " dropped due to no socket\n");
- p(UDP_STAT_NOPORTBCAST,
- "\t%" PRIu64 " broadcast/multicast datagram%s dropped due to no socket\n");
- ps(UDP_STAT_FULLSOCK, "\t%" PRIu64 " dropped due to full socket buffers\n");
+ p(UDP_STAT_NOPORTBCAST, "\t%" PRIu64
+ " broadcast/multicast datagram%s dropped due to no socket\n");
+ ps(UDP_STAT_FULLSOCK, "\t%" PRIu64
+ " dropped due to full socket buffers\n");
delivered = udpstat[UDP_STAT_IPACKETS] -
udpstat[UDP_STAT_HDROPS] -
udpstat[UDP_STAT_BADLEN] -
@@ -585,7 +602,7 @@ ip_stats(u_long off, const char *name)
size_t size = sizeof(ipstat);
if (sysctlbyname("net.inet.ip.stats", ipstat, &size,
- NULL, 0) == -1)
+ NULL, 0) == -1)
return;
} else {
warnx("%s stats not available via KVM.", name);
@@ -594,28 +611,33 @@ ip_stats(u_long off, const char *name)
printf("%s:\n", name);
-#define ps(f, m) if (ipstat[f] || sflag <= 1) \
- printf(m, ipstat[f])
-#define p(f, m) if (ipstat[f] || sflag <= 1) \
- printf(m, ipstat[f], plural(ipstat[f]))
+#define ps(f, m) if (ipstat[f] || sflag <= 1) \
+ printf(m, ipstat[f])
+#define p(f, m) if (ipstat[f] || sflag <= 1) \
+ printf(m, ipstat[f], plural(ipstat[f]))
p(IP_STAT_TOTAL, "\t%" PRIu64 " total packet%s received\n");
p(IP_STAT_BADSUM, "\t%" PRIu64 " bad header checksum%s\n");
ps(IP_STAT_TOOSMALL, "\t%" PRIu64 " with size smaller than minimum\n");
ps(IP_STAT_TOOSHORT, "\t%" PRIu64 " with data size < data length\n");
- ps(IP_STAT_TOOLONG, "\t%" PRIu64 " with length > max ip packet size\n");
+ ps(IP_STAT_TOOLONG,
+ "\t%" PRIu64 " with length > max ip packet size\n");
ps(IP_STAT_BADHLEN, "\t%" PRIu64 " with header length < data size\n");
ps(IP_STAT_BADLEN, "\t%" PRIu64 " with data length < header length\n");
ps(IP_STAT_BADOPTIONS, "\t%" PRIu64 " with bad options\n");
ps(IP_STAT_BADVERS, "\t%" PRIu64 " with incorrect version number\n");
p(IP_STAT_FRAGMENTS, "\t%" PRIu64 " fragment%s received\n");
- p(IP_STAT_FRAGDROPPED, "\t%" PRIu64 " fragment%s dropped (dup or out of space)\n");
- p(IP_STAT_RCVMEMDROP, "\t%" PRIu64 " fragment%s dropped (out of ipqent)\n");
+ p(IP_STAT_FRAGDROPPED,
+ "\t%" PRIu64 " fragment%s dropped (dup or out of space)\n");
+ p(IP_STAT_RCVMEMDROP,
+ "\t%" PRIu64 " fragment%s dropped (out of ipqent)\n");
p(IP_STAT_BADFRAGS, "\t%" PRIu64 " malformed fragment%s dropped\n");
- p(IP_STAT_FRAGTIMEOUT, "\t%" PRIu64 " fragment%s dropped after timeout\n");
+ p(IP_STAT_FRAGTIMEOUT,
+ "\t%" PRIu64 " fragment%s dropped after timeout\n");
p(IP_STAT_REASSEMBLED, "\t%" PRIu64 " packet%s reassembled ok\n");
p(IP_STAT_DELIVERED, "\t%" PRIu64 " packet%s for this host\n");
- p(IP_STAT_NOPROTO, "\t%" PRIu64 " packet%s for unknown/unsupported protocol\n");
+ p(IP_STAT_NOPROTO,
+ "\t%" PRIu64 " packet%s for unknown/unsupported protocol\n");
p(IP_STAT_FORWARD, "\t%" PRIu64 " packet%s forwarded");
p(IP_STAT_FASTFORWARD, " (%" PRIu64 " packet%s fast forwarded)");
if (ipstat[IP_STAT_FORWARD] || sflag <= 1)
@@ -623,14 +645,21 @@ ip_stats(u_long off, const char *name)
p(IP_STAT_CANTFORWARD, "\t%" PRIu64 " packet%s not forwardable\n");
p(IP_STAT_REDIRECTSENT, "\t%" PRIu64 " redirect%s sent\n");
p(IP_STAT_NOGIF, "\t%" PRIu64 " packet%s no matching gif found\n");
+ p(IP_STAT_NOIPSEC,
+ "\t%" PRIu64 " packet%s no matching ipsecif found\n");
p(IP_STAT_LOCALOUT, "\t%" PRIu64 " packet%s sent from this host\n");
- p(IP_STAT_RAWOUT, "\t%" PRIu64 " packet%s sent with fabricated ip header\n");
- p(IP_STAT_ODROPPED, "\t%" PRIu64 " output packet%s dropped due to no bufs, etc.\n");
- p(IP_STAT_NOROUTE, "\t%" PRIu64 " output packet%s discarded due to no route\n");
+ p(IP_STAT_RAWOUT,
+ "\t%" PRIu64 " packet%s sent with fabricated ip header\n");
+ p(IP_STAT_ODROPPED,
+ "\t%" PRIu64 " output packet%s dropped due to no bufs, etc.\n");
+ p(IP_STAT_NOROUTE,
+ "\t%" PRIu64 " output packet%s discarded due to no route\n");
p(IP_STAT_FRAGMENTED, "\t%" PRIu64 " output datagram%s fragmented\n");
p(IP_STAT_OFRAGMENTS, "\t%" PRIu64 " fragment%s created\n");
- p(IP_STAT_CANTFRAG, "\t%" PRIu64 " datagram%s that can't be fragmented\n");
- p(IP_STAT_BADADDR, "\t%" PRIu64 " datagram%s with bad address in header\n");
+ p(IP_STAT_CANTFRAG,
+ "\t%" PRIu64 " datagram%s that can't be fragmented\n");
+ p(IP_STAT_BADADDR,
+ "\t%" PRIu64 " datagram%s with bad address in header\n");
#undef ps
#undef p
}
@@ -661,8 +690,8 @@ icmp_stats(u_long off, const char *name)
printf(m, icmpstat[f], plural(icmpstat[f]))
p(ICMP_STAT_ERROR, "\t%" PRIu64 " call%s to icmp_error\n");
- p(ICMP_STAT_OLDICMP,
- "\t%" PRIu64 " error%s not generated because old message was icmp\n");
+ p(ICMP_STAT_OLDICMP, "\t%" PRIu64
+ " error%s not generated because old message was icmp\n");
for (first = 1, i = 0; i < ICMP_MAXTYPE + 1; i++)
if (icmpstat[ICMP_STAT_OUTHIST + i] != 0) {
if (first) {
@@ -676,8 +705,10 @@ icmp_stats(u_long off, const char *name)
p(ICMP_STAT_TOOSHORT, "\t%" PRIu64 " message%s < minimum length\n");
p(ICMP_STAT_CHECKSUM, "\t%" PRIu64 " bad checksum%s\n");
p(ICMP_STAT_BADLEN, "\t%" PRIu64 " message%s with bad length\n");
- p(ICMP_STAT_BMCASTECHO, "\t%" PRIu64 " multicast echo request%s ignored\n");
- p(ICMP_STAT_BMCASTTSTAMP, "\t%" PRIu64 " multicast timestamp request%s ignored\n");
+ p(ICMP_STAT_BMCASTECHO,
+ "\t%" PRIu64 " multicast echo request%s ignored\n");
+ p(ICMP_STAT_BMCASTTSTAMP,
+ "\t%" PRIu64 " multicast timestamp request%s ignored\n");
for (first = 1, i = 0; i < ICMP_MAXTYPE + 1; i++)
if (icmpstat[ICMP_STAT_INHIST + i] != 0) {
if (first) {
@@ -704,7 +735,7 @@ igmp_stats(u_long off, const char *name)
size_t size = sizeof(igmpstat);
if (sysctlbyname("net.inet.igmp.stats", igmpstat, &size,
- NULL, 0) == -1)
+ NULL, 0) == -1)
return;
} else {
warnx("%s stats not available via KVM.", name);
@@ -713,19 +744,28 @@ igmp_stats(u_long off, const char *name)
printf("%s:\n", name);
-#define p(f, m) if (igmpstat[f] || sflag <= 1) \
- printf(m, igmpstat[f], plural(igmpstat[f]))
-#define py(f, m) if (igmpstat[f] || sflag <= 1) \
- printf(m, igmpstat[f], igmpstat[f] != 1 ? "ies" : "y")
+#define p(f, m) if (igmpstat[f] || sflag <= 1) \
+ printf(m, igmpstat[f], plural(igmpstat[f]))
+#define py(f, m) if (igmpstat[f] || sflag <= 1) \
+ printf(m, igmpstat[f], igmpstat[f] != 1 ? "ies" : "y")
+
p(IGMP_STAT_RCV_TOTAL, "\t%" PRIu64 " message%s received\n");
- p(IGMP_STAT_RCV_TOOSHORT, "\t%" PRIu64 " message%s received with too few bytes\n");
- p(IGMP_STAT_RCV_BADSUM, "\t%" PRIu64 " message%s received with bad checksum\n");
- py(IGMP_STAT_RCV_QUERIES, "\t%" PRIu64 " membership quer%s received\n");
- py(IGMP_STAT_RCV_BADQUERIES, "\t%" PRIu64 " membership quer%s received with invalid field(s)\n");
- p(IGMP_STAT_RCV_REPORTS, "\t%" PRIu64 " membership report%s received\n");
- p(IGMP_STAT_RCV_BADREPORTS, "\t%" PRIu64 " membership report%s received with invalid field(s)\n");
- p(IGMP_STAT_RCV_OURREPORTS, "\t%" PRIu64 " membership report%s received for groups to which we belong\n");
- p(IGMP_STAT_SND_REPORTS, "\t%" PRIu64 " membership report%s sent\n");
+ p(IGMP_STAT_RCV_TOOSHORT,
+ "\t%" PRIu64 " message%s received with too few bytes\n");
+ p(IGMP_STAT_RCV_BADSUM,
+ "\t%" PRIu64 " message%s received with bad checksum\n");
+ py(IGMP_STAT_RCV_QUERIES,
+ "\t%" PRIu64 " membership quer%s received\n");
+ py(IGMP_STAT_RCV_BADQUERIES,
+ "\t%" PRIu64 " membership quer%s received with invalid field(s)\n");
+ p(IGMP_STAT_RCV_REPORTS,
+ "\t%" PRIu64 " membership report%s received\n");
+ p(IGMP_STAT_RCV_BADREPORTS, "\t%" PRIu64
+ " membership report%s received with invalid field(s)\n");
+ p(IGMP_STAT_RCV_OURREPORTS, "\t%" PRIu64
+ " membership report%s received for groups to which we belong\n");
+ p(IGMP_STAT_SND_REPORTS,
+ "\t%" PRIu64 " membership report%s sent\n");
#undef p
#undef py
}
@@ -763,17 +803,18 @@ carp_stats(u_long off, const char *name)
p(CARP_STAT_BADTTL,
"\t\t%" PRIu64 " packet%s discarded for wrong TTL\n");
p(CARP_STAT_HDROPS, "\t\t%" PRIu64 " packet%s shorter than header\n");
- p(CARP_STAT_BADSUM, "\t\t%" PRIu64
- " packet%s discarded for bad checksum\n");
+ p(CARP_STAT_BADSUM,
+ "\t\t%" PRIu64 " packet%s discarded for bad checksum\n");
p(CARP_STAT_BADVER,
"\t\t%" PRIu64 " packet%s discarded with a bad version\n");
p2(CARP_STAT_BADLEN,
"\t\t%" PRIu64 " discarded because packet was too short\n");
p(CARP_STAT_BADAUTH,
"\t\t%" PRIu64 " packet%s discarded for bad authentication\n");
- p(CARP_STAT_BADVHID, "\t\t%" PRIu64 " packet%s discarded for bad vhid\n");
+ p(CARP_STAT_BADVHID,
+ "\t\t%" PRIu64 " packet%s discarded for bad vhid\n");
p(CARP_STAT_BADADDRS, "\t\t%" PRIu64
- " packet%s discarded because of a bad address list\n");
+ " packet%s discarded because of a bad address list\n");
p(CARP_STAT_OPACKETS, "\t%" PRIu64 " packet%s sent (IPv4)\n");
p(CARP_STAT_OPACKETS6, "\t%" PRIu64 " packet%s sent (IPv6)\n");
p2(CARP_STAT_ONOMEM,
@@ -804,15 +845,24 @@ pim_stats(u_long off, const char *name)
p(pims_rcv_total_msgs, "\t%" PRIu64 " message%s received\n");
p(pims_rcv_total_bytes, "\t%" PRIu64 " byte%s received\n");
- p(pims_rcv_tooshort, "\t%" PRIu64 " message%s received with too few bytes\n");
- p(pims_rcv_badsum, "\t%" PRIu64 " message%s received with bad checksum\n");
- p(pims_rcv_badversion, "\t%" PRIu64 " message%s received with bad version\n");
- p(pims_rcv_registers_msgs, "\t%" PRIu64 " data register message%s received\n");
- p(pims_rcv_registers_bytes, "\t%" PRIu64 " data register byte%s received\n");
- p(pims_rcv_registers_wrongiif, "\t%" PRIu64 " data register message%s received on wrong iif\n");
- p(pims_rcv_badregisters, "\t%" PRIu64 " bad register%s received\n");
- p(pims_snd_registers_msgs, "\t%" PRIu64 " data register message%s sent\n");
- p(pims_snd_registers_bytes, "\t%" PRIu64 " data register byte%s sent\n");
+ p(pims_rcv_tooshort,
+ "\t%" PRIu64 " message%s received with too few bytes\n");
+ p(pims_rcv_badsum,
+ "\t%" PRIu64 " message%s received with bad checksum\n");
+ p(pims_rcv_badversion,
+ "\t%" PRIu64 " message%s received with bad version\n");
+ p(pims_rcv_registers_msgs,
+ "\t%" PRIu64 " data register message%s received\n");
+ p(pims_rcv_registers_bytes,
+ "\t%" PRIu64 " data register byte%s received\n");
+ p(pims_rcv_registers_wrongiif,
+ "\t%" PRIu64 " data register message%s received on wrong iif\n");
+ p(pims_rcv_badregisters,
+ "\t%" PRIu64 " bad register%s received\n");
+ p(pims_snd_registers_msgs,
+ "\t%" PRIu64 " data register message%s sent\n");
+ p(pims_snd_registers_bytes,
+ "\t%" PRIu64 " data register byte%s sent\n");
#undef p
}
@@ -850,22 +900,33 @@ arp_stats(u_long off, const char *name)
p(ARP_STAT_RCVREPLY, "\t\t%" PRIu64 " reply packet%s\n");
p(ARP_STAT_RCVREQUEST, "\t\t%" PRIu64 " valid request packet%s\n");
p(ARP_STAT_RCVMCAST, "\t\t%" PRIu64 " broadcast/multicast packet%s\n");
- p(ARP_STAT_RCVBADPROTO, "\t\t%" PRIu64 " packet%s with unknown protocol type\n");
- p(ARP_STAT_RCVBADLEN, "\t\t%" PRIu64 " packet%s with bad (short) length\n");
- p(ARP_STAT_RCVZEROTPA, "\t\t%" PRIu64 " packet%s with null target IP address\n");
- p(ARP_STAT_RCVZEROSPA, "\t\t%" PRIu64 " packet%s with null source IP address\n");
- ps(ARP_STAT_RCVNOINT, "\t\t%" PRIu64 " could not be mapped to an interface\n");
- p(ARP_STAT_RCVLOCALSHA, "\t\t%" PRIu64 " packet%s sourced from a local hardware "
+ p(ARP_STAT_RCVBADPROTO,
+ "\t\t%" PRIu64 " packet%s with unknown protocol type\n");
+ p(ARP_STAT_RCVBADLEN,
+ "\t\t%" PRIu64 " packet%s with bad (short) length\n");
+ p(ARP_STAT_RCVZEROTPA,
+ "\t\t%" PRIu64 " packet%s with null target IP address\n");
+ p(ARP_STAT_RCVZEROSPA,
+ "\t\t%" PRIu64 " packet%s with null source IP address\n");
+ ps(ARP_STAT_RCVNOINT,
+ "\t\t%" PRIu64 " could not be mapped to an interface\n");
+ p(ARP_STAT_RCVLOCALSHA,
+ "\t\t%" PRIu64 " packet%s sourced from a local hardware "
"address\n");
p(ARP_STAT_RCVBCASTSHA, "\t\t%" PRIu64 " packet%s with a broadcast "
"source hardware address\n");
- p(ARP_STAT_RCVLOCALSPA, "\t\t%" PRIu64 " duplicate%s for a local IP address\n");
- p(ARP_STAT_RCVOVERPERM, "\t\t%" PRIu64 " attempt%s to overwrite a static entry\n");
- p(ARP_STAT_RCVOVERINT, "\t\t%" PRIu64 " packet%s received on wrong interface\n");
+ p(ARP_STAT_RCVLOCALSPA,
+ "\t\t%" PRIu64 " duplicate%s for a local IP address\n");
+ p(ARP_STAT_RCVOVERPERM,
+ "\t\t%" PRIu64 " attempt%s to overwrite a static entry\n");
+ p(ARP_STAT_RCVOVERINT,
+ "\t\t%" PRIu64 " packet%s received on wrong interface\n");
p(ARP_STAT_RCVOVER, "\t\t%" PRIu64 " entry%s overwritten\n");
- p(ARP_STAT_RCVLENCHG, "\t\t%" PRIu64 " change%s in hardware address length\n");
+ p(ARP_STAT_RCVLENCHG,
+ "\t\t%" PRIu64 " change%s in hardware address length\n");
- p(ARP_STAT_DFRTOTAL, "\t%" PRIu64 " packet%s deferred pending ARP resolution\n");
+ p(ARP_STAT_DFRTOTAL,
+ "\t%" PRIu64 " packet%s deferred pending ARP resolution\n");
ps(ARP_STAT_DFRSENT, "\t\t%" PRIu64 " sent\n");
ps(ARP_STAT_DFRDROPPED, "\t\t%" PRIu64 " dropped\n");
@@ -958,7 +1019,7 @@ inetname(struct in_addr *inp)
C(inp->s_addr >> 8), C(inp->s_addr));
#undef C
}
- return (line);
+ return line;
}
/*
@@ -974,9 +1035,9 @@ tcp_dump(u_long off, const char *name, u
size_t j, len;
if (use_sysctl)
- pcblist = getpcblist_sysctl(name, &len);
+ pcblist = getpcblist_sysctl(name, &len);
else
- pcblist = getpcblist_kmem(off, name, &len);
+ pcblist = getpcblist_kmem(off, name, &len);
for (j = 0; j < len; j++)
if (pcblist[j].ki_ppcbaddr == pcbaddr)
@@ -1013,7 +1074,7 @@ tcp_dump(u_long off, const char *name, u
printf("rxtshift %d, rxtcur %d, dupacks %d\n", tcpcb.t_rxtshift,
tcpcb.t_rxtcur, tcpcb.t_dupacks);
- printf("peermss %u, ourmss %u, segsz %u, segqlen %u\n\n",
+ printf("peermss %u, ourmss %u, segsz %u, segqlen %u\n\n",
tcpcb.t_peermss, tcpcb.t_ourmss, tcpcb.t_segsz, tcpcb.t_segqlen);
printf("snd_una %u, snd_nxt %u, snd_up %u\n",
Index: src/usr.bin/netstat/inet6.c
diff -u src/usr.bin/netstat/inet6.c:1.69 src/usr.bin/netstat/inet6.c:1.69.6.1
--- src/usr.bin/netstat/inet6.c:1.69 Sat Dec 17 09:12:22 2016
+++ src/usr.bin/netstat/inet6.c Mon Sep 12 14:29:19 2022
@@ -1,10 +1,10 @@
-/* $NetBSD: inet6.c,v 1.69 2016/12/17 09:12:22 mlelstv Exp $ */
+/* $NetBSD: inet6.c,v 1.69.6.1 2022/09/12 14:29:19 martin Exp $ */
/* BSDI inet.c,v 2.3 1995/10/24 02:19:29 prb Exp */
/*
* Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
* All rights reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -16,7 +16,7 @@
* 3. Neither the name of the project 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 PROJECT 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
@@ -64,7 +64,7 @@
#if 0
static char sccsid[] = "@(#)inet.c 8.4 (Berkeley) 4/20/94";
#else
-__RCSID("$NetBSD: inet6.c,v 1.69 2016/12/17 09:12:22 mlelstv Exp $");
+__RCSID("$NetBSD: inet6.c,v 1.69.6.1 2022/09/12 14:29:19 martin Exp $");
#endif
#endif /* not lint */
@@ -148,7 +148,6 @@ struct tcp6cb tcp6cb;
#else
struct tcpcb tcpcb;
#endif
-struct socket sockb;
char *inet6name(const struct in6_addr *);
void inet6print(const struct in6_addr *, int, const char *);
@@ -169,20 +168,20 @@ static struct timeval now;
static void
ip6protoprhdr(void)
{
-
+
printf("Active Internet6 connections");
-
+
if (aflag)
printf(" (including servers)");
putchar('\n');
-
+
if (Aflag) {
printf("%-8.8s ", "PCB");
width = 18;
}
printf(
Vflag ? "%-5.5s %-6.6s %-6.6s %*.*s %*.*s %-13.13s Expires\n"
- : "%-5.5s %-6.6s %-6.6s %*.*s %*.*s %s\n",
+ : "%-5.5s %-6.6s %-6.6s %*.*s %*.*s %s\n",
"Proto", "Recv-Q", "Send-Q",
-width, width, "Local Address",
-width, width, "Foreign Address", "(state)");
@@ -190,14 +189,14 @@ ip6protoprhdr(void)
static void
ip6protopr0(intptr_t ppcb, u_long rcv_sb_cc, u_long snd_sb_cc,
- const struct in6_addr *laddr, u_int16_t lport,
- const struct in6_addr *faddr, u_int16_t fport,
+ const struct in6_addr *laddr, uint16_t lport,
+ const struct in6_addr *faddr, uint16_t fport,
short t_state, const char *name, const struct timeval *expires)
{
static const char *shorttcpstates[] = {
"CLOSED", "LISTEN", "SYNSEN", "SYSRCV",
"ESTABL", "CLWAIT", "FWAIT1", "CLOSNG",
- "LASTAK", "FWAIT2", "TMWAIT",
+ "LASTAK", "FWAIT2", "TMWAIT"
};
int istcp;
@@ -241,10 +240,11 @@ ip6protopr0(intptr_t ppcb, u_long rcv_sb
static void
dbg_printf(const char *fmt, ...)
{
+
return;
}
-void
+void
print_vtw_v6(const vtw_t *vtw)
{
const vtw_v6_t *v6 = (const vtw_v6_t *)vtw;
@@ -258,23 +258,23 @@ print_vtw_v6(const vtw_t *vtw)
timersub(&vtw->expire, &now, &delta);
if (vtw->expire.tv_sec == 0 && vtw->expire.tv_usec == -1) {
- dbg_printf("%15.15s:%d %15.15s:%d reclaimed\n"
- ,buf[0], ntohs(v6->lport)
- ,buf[1], ntohs(v6->fport));
+ dbg_printf("%15.15s:%d %15.15s:%d reclaimed\n",
+ buf[0], ntohs(v6->lport),
+ buf[1], ntohs(v6->fport));
if (!(Vflag && vflag))
return;
} else if (vtw->expire.tv_sec == 0)
return;
else if (timercmp(&delta, &zero, <) && !(Vflag && vflag)) {
- dbg_printf("%15.15s:%d %15.15s:%d expired\n"
- ,buf[0], ntohs(v6->lport)
- ,buf[1], ntohs(v6->fport));
+ dbg_printf("%15.15s:%d %15.15s:%d expired\n",
+ buf[0], ntohs(v6->lport),
+ buf[1], ntohs(v6->fport));
return;
} else {
- dbg_printf("%15.15s:%d %15.15s:%d expires in %.3fms\n"
- ,buf[0], ntohs(v6->lport)
- ,buf[1], ntohs(v6->fport)
- ,delta.tv_sec * 1000.0 + delta.tv_usec / 1000.0);
+ dbg_printf("%15.15s:%d %15.15s:%d expires in %.3fms\n",
+ buf[0], ntohs(v6->lport),
+ buf[1], ntohs(v6->fport),
+ delta.tv_sec * 1000.0 + delta.tv_usec / 1000.0);
}
ip6protopr0(0, 0, 0,
&v6->laddr, v6->lport,
@@ -284,8 +284,9 @@ print_vtw_v6(const vtw_t *vtw)
static struct kinfo_pcb *
-getpcblist_kmem(u_long off, const char *name, size_t *len) {
-
+getpcblist_kmem(u_long off, const char *name, size_t *len)
+{
+ struct socket sockb;
struct inpcbtable table;
struct inpcb_hdr *next, *prev;
int istcp = strcmp(name, "tcp6") == 0;
@@ -315,7 +316,7 @@ getpcblist_kmem(u_long off, const char *
if (in6pcb.in6p_af != AF_INET6)
continue;
- kread((u_long)in6pcb.in6p_socket, (char *)&sockb,
+ kread((u_long)in6pcb.in6p_socket, (char *)&sockb,
sizeof (sockb));
if (istcp) {
#ifdef TCP6
@@ -326,7 +327,7 @@ getpcblist_kmem(u_long off, const char *
(char *)&tcpcb, sizeof (tcpcb));
#endif
}
- pcblist[i].ki_ppcbaddr =
+ pcblist[i].ki_ppcbaddr =
istcp ? (uintptr_t) in6pcb.in6p_ppcb : (uintptr_t) prev;
pcblist[i].ki_rcvq = (uint64_t)sockb.so_rcv.sb_cc;
pcblist[i].ki_sndq = (uint64_t)sockb.so_snd.sb_cc;
@@ -427,56 +428,61 @@ tcp6_stats(u_long off, const char *name)
printf ("%s:\n", name);
-#define p(f, m) if (tcp6stat.f || sflag <= 1) \
- printf(m, tcp6stat.f, plural(tcp6stat.f))
-#define p2(f1, f2, m) if (tcp6stat.f1 || tcp6stat.f2 || sflag <= 1) \
- printf(m, tcp6stat.f1, plural(tcp6stat.f1), tcp6stat.f2, plural(tcp6stat.f2))
-#define p3(f, m) if (tcp6stat.f || sflag <= 1) \
- printf(m, tcp6stat.f, plurales(tcp6stat.f))
+#define p(f, m) if (tcp6stat.f || sflag <= 1) \
+ printf(m, tcp6stat.f, plural(tcp6stat.f))
+#define p2(f1, f2, m) if (tcp6stat.f1 || tcp6stat.f2 || sflag <= 1) \
+ printf(m, tcp6stat.f1, plural(tcp6stat.f1), tcp6stat.f2, \
+ plural(tcp6stat.f2))
+#define p3(f, m) if (tcp6stat.f || sflag <= 1) \
+ printf(m, tcp6stat.f, plurales(tcp6stat.f))
p(tcp6s_sndtotal, "\t%ld packet%s sent\n");
p2(tcp6s_sndpack,tcp6s_sndbyte,
- "\t\t%ld data packet%s (%ld byte%s)\n");
+ "\t\t%ld data packet%s (%ld byte%s)\n");
p2(tcp6s_sndrexmitpack, tcp6s_sndrexmitbyte,
- "\t\t%ld data packet%s (%ld byte%s) retransmitted\n");
+ "\t\t%ld data packet%s (%ld byte%s) retransmitted\n");
p2(tcp6s_sndacks, tcp6s_delack,
- "\t\t%ld ack-only packet%s (%ld packet%s delayed)\n");
+ "\t\t%ld ack-only packet%s (%ld packet%s delayed)\n");
p(tcp6s_sndurg, "\t\t%ld URG only packet%s\n");
p(tcp6s_sndprobe, "\t\t%ld window probe packet%s\n");
p(tcp6s_sndwinup, "\t\t%ld window update packet%s\n");
p(tcp6s_sndctrl, "\t\t%ld control packet%s\n");
p(tcp6s_rcvtotal, "\t%ld packet%s received\n");
- p2(tcp6s_rcvackpack, tcp6s_rcvackbyte, "\t\t%ld ack%s (for %ld byte%s)\n");
+ p2(tcp6s_rcvackpack, tcp6s_rcvackbyte,
+ "\t\t%ld ack%s (for %ld byte%s)\n");
p(tcp6s_rcvdupack, "\t\t%ld duplicate ack%s\n");
p(tcp6s_rcvacktoomuch, "\t\t%ld ack%s for unsent data\n");
p2(tcp6s_rcvpack, tcp6s_rcvbyte,
- "\t\t%ld packet%s (%ld byte%s) received in-sequence\n");
+ "\t\t%ld packet%s (%ld byte%s) received in-sequence\n");
p2(tcp6s_rcvduppack, tcp6s_rcvdupbyte,
- "\t\t%ld completely duplicate packet%s (%ld byte%s)\n");
+ "\t\t%ld completely duplicate packet%s (%ld byte%s)\n");
p(tcp6s_pawsdrop, "\t\t%ld old duplicate packet%s\n");
p2(tcp6s_rcvpartduppack, tcp6s_rcvpartdupbyte,
- "\t\t%ld packet%s with some dup. data (%ld byte%s duped)\n");
+ "\t\t%ld packet%s with some dup. data (%ld byte%s duped)\n");
p2(tcp6s_rcvoopack, tcp6s_rcvoobyte,
- "\t\t%ld out-of-order packet%s (%ld byte%s)\n");
+ "\t\t%ld out-of-order packet%s (%ld byte%s)\n");
p2(tcp6s_rcvpackafterwin, tcp6s_rcvbyteafterwin,
- "\t\t%ld packet%s (%ld byte%s) of data after window\n");
+ "\t\t%ld packet%s (%ld byte%s) of data after window\n");
p(tcp6s_rcvwinprobe, "\t\t%ld window probe%s\n");
p(tcp6s_rcvwinupd, "\t\t%ld window update packet%s\n");
p(tcp6s_rcvafterclose, "\t\t%ld packet%s received after close\n");
p(tcp6s_rcvbadsum, "\t\t%ld discarded for bad checksum%s\n");
- p(tcp6s_rcvbadoff, "\t\t%ld discarded for bad header offset field%s\n");
+ p(tcp6s_rcvbadoff,
+ "\t\t%ld discarded for bad header offset field%s\n");
p(tcp6s_rcvshort, "\t\t%ld discarded because packet%s too short\n");
p(tcp6s_connattempt, "\t%ld connection request%s\n");
p(tcp6s_accepts, "\t%ld connection accept%s\n");
p(tcp6s_badsyn, "\t%ld bad connection attempt%s\n");
- p(tcp6s_connects, "\t%ld connection%s established (including accepts)\n");
+ p(tcp6s_connects,
+ "\t%ld connection%s established (including accepts)\n");
p2(tcp6s_closed, tcp6s_drops,
- "\t%ld connection%s closed (including %ld drop%s)\n");
+ "\t%ld connection%s closed (including %ld drop%s)\n");
p(tcp6s_conndrops, "\t%ld embryonic connection%s dropped\n");
p2(tcp6s_rttupdated, tcp6s_segstimed,
- "\t%ld segment%s updated rtt (of %ld attempt%s)\n");
+ "\t%ld segment%s updated rtt (of %ld attempt%s)\n");
p(tcp6s_rexmttimeo, "\t%ld retransmit timeout%s\n");
- p(tcp6s_timeoutdrop, "\t\t%ld connection%s dropped by rexmit timeout\n");
+ p(tcp6s_timeoutdrop,
+ "\t\t%ld connection%s dropped by rexmit timeout\n");
p(tcp6s_persisttimeo, "\t%ld persist timeout%s\n");
p(tcp6s_persistdrop, "\t%ld connection%s timed out in persist\n");
p(tcp6s_keeptimeo, "\t%ld keepalive timeout%s\n");
@@ -511,10 +517,10 @@ udp6_stats(u_long off, const char *name)
return;
}
printf("%s:\n", name);
-#define p(f, m) if (udp6stat[f] || sflag <= 1) \
- printf(m, (unsigned long long)udp6stat[f], plural(udp6stat[f]))
-#define p1(f, m) if (udp6stat[f] || sflag <= 1) \
- printf(m, (unsigned long long)udp6stat[f])
+#define p(f, m) if (udp6stat[f] || sflag <= 1) \
+ printf(m, (unsigned long long)udp6stat[f], plural(udp6stat[f]))
+#define p1(f, m) if (udp6stat[f] || sflag <= 1) \
+ printf(m, (unsigned long long)udp6stat[f])
p(UDP6_STAT_IPACKETS, "\t%llu datagram%s received\n");
p1(UDP6_STAT_HDROPS, "\t%llu with incomplete header\n");
p1(UDP6_STAT_BADLEN, "\t%llu with bad data length field\n");
@@ -630,7 +636,7 @@ static const char *ip6nh[] = {
/*220*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
/*240*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL
};
/*
@@ -656,10 +662,10 @@ ip6_stats(u_long off, const char *name)
}
printf("%s:\n", name);
-#define p(f, m) if (ip6stat[f] || sflag <= 1) \
- printf(m, (unsigned long long)ip6stat[f], plural(ip6stat[f]))
-#define p1(f, m) if (ip6stat[f] || sflag <= 1) \
- printf(m, (unsigned long long)ip6stat[f])
+#define p(f, m) if (ip6stat[f] || sflag <= 1) \
+ printf(m, (unsigned long long)ip6stat[f], plural(ip6stat[f]))
+#define p1(f, m) if (ip6stat[f] || sflag <= 1) \
+ printf(m, (unsigned long long)ip6stat[f])
p(IP6_STAT_TOTAL, "\t%llu total packet%s received\n");
p1(IP6_STAT_TOOSMALL, "\t%llu with size smaller than minimum\n");
@@ -675,14 +681,15 @@ ip6_stats(u_long off, const char *name)
p(IP6_STAT_DELIVERED, "\t%llu packet%s for this host\n");
p(IP6_STAT_FORWARD, "\t%llu packet%s forwarded\n");
p(IP6_STAT_FASTFORWARD, "\t%llu packet%s fast forwarded\n");
- p1(IP6_STAT_FASTFORWARDFLOWS, "\t%llu fast forward flows\n");
+ p1(IP6_STAT_FASTFORWARDFLOWS, "\t%llu fast forward flows\n");
p(IP6_STAT_CANTFORWARD, "\t%llu packet%s not forwardable\n");
p(IP6_STAT_REDIRECTSENT, "\t%llu redirect%s sent\n");
p(IP6_STAT_LOCALOUT, "\t%llu packet%s sent from this host\n");
p(IP6_STAT_RAWOUT, "\t%llu packet%s sent with fabricated ip header\n");
p(IP6_STAT_ODROPPED,
"\t%llu output packet%s dropped due to no bufs, etc.\n");
- p(IP6_STAT_NOROUTE, "\t%llu output packet%s discarded due to no route\n");
+ p(IP6_STAT_NOROUTE,
+ "\t%llu output packet%s discarded due to no route\n");
p(IP6_STAT_FRAGMENTED, "\t%llu output datagram%s fragmented\n");
p(IP6_STAT_OFRAGMENTS, "\t%llu fragment%s created\n");
p(IP6_STAT_CANTFRAG, "\t%llu datagram%s that can't be fragmented\n");
@@ -710,14 +717,14 @@ ip6_stats(u_long off, const char *name)
p(IP6_STAT_M1, "\t\t%llu one mbuf%s\n");
for (first = 1, i = 0; i < 32; i++) {
char ifbuf[IFNAMSIZ];
- if (ip6stat[IP6_STAT_M2M + i] != 0) {
+ if (ip6stat[IP6_STAT_M2M + i] != 0) {
if (first) {
printf("\t\ttwo or more mbuf:\n");
first = 0;
}
printf("\t\t\t%s = %llu\n",
- if_indextoname(i, ifbuf),
- (unsigned long long)ip6stat[IP6_STAT_M2M + i]);
+ if_indextoname(i, ifbuf),
+ (unsigned long long)ip6stat[IP6_STAT_M2M + i]);
}
}
p(IP6_STAT_MEXT1, "\t\t%llu one ext mbuf%s\n");
@@ -725,28 +732,30 @@ ip6_stats(u_long off, const char *name)
p(IP6_STAT_EXTHDRTOOLONG,
"\t%llu packet%s whose headers are not continuous\n");
p(IP6_STAT_NOGIF, "\t%llu tunneling packet%s that can't find gif\n");
+ p(IP6_STAT_NOIPSEC,
+ "\t%llu tunneling packet%s that can't find ipsecif\n");
p(IP6_STAT_TOOMANYHDR,
"\t%llu packet%s discarded due to too many headers\n");
/* for debugging source address selection */
-#define PRINT_SCOPESTAT(s,i) do {\
- switch(i) { /* XXX hardcoding in each case */\
- case 1:\
- p(s, "\t\t%llu node-local%s\n");\
- break;\
- case 2:\
- p(s, "\t\t%llu link-local%s\n");\
- break;\
- case 5:\
- p(s, "\t\t%llu site-local%s\n");\
- break;\
- case 14:\
- p(s, "\t\t%llu global%s\n");\
- break;\
- default:\
- printf("\t\t%llu addresses scope=%x\n",\
- (unsigned long long)ip6stat[s], i);\
- }\
+#define PRINT_SCOPESTAT(s, i) do { \
+ switch (i) { /* XXX hardcoding in each case */ \
+ case 1: \
+ p(s, "\t\t%llu node-local%s\n"); \
+ break; \
+ case 2: \
+ p(s, "\t\t%llu link-local%s\n"); \
+ break; \
+ case 5: \
+ p(s, "\t\t%llu site-local%s\n"); \
+ break; \
+ case 14: \
+ p(s, "\t\t%llu global%s\n"); \
+ break; \
+ default: \
+ printf("\t\t%llu addresses scope=%x\n", \
+ (unsigned long long)ip6stat[s], i); \
+ } \
} while(/*CONSTCOND*/0);
p(IP6_STAT_SOURCES_NONE,
@@ -811,11 +820,11 @@ ip6_ifstats(const char *ifname)
{
struct in6_ifreq ifr;
int s;
-#define p(f, m) if (ifr.ifr_ifru.ifru_stat.f || sflag <= 1) \
- printf(m, (unsigned long long)ifr.ifr_ifru.ifru_stat.f, \
- plural(ifr.ifr_ifru.ifru_stat.f))
-#define p_5(f, m) if (ifr.ifr_ifru.ifru_stat.f || sflag <= 1) \
- printf(m, (unsigned long long)ip6stat.f)
+#define p(f, m) if (ifr.ifr_ifru.ifru_stat.f || sflag <= 1) \
+ printf(m, (unsigned long long)ifr.ifr_ifru.ifru_stat.f, \
+ plural(ifr.ifr_ifru.ifru_stat.f))
+#define p_5(f, m) if (ifr.ifr_ifru.ifru_stat.f || sflag <= 1) \
+ printf(m, (unsigned long long)ip6stat.f)
if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
perror("Warning: socket(AF_INET6)");
@@ -836,17 +845,19 @@ ip6_ifstats(const char *ifname)
p(ifs6_in_noroute, "\t%llu datagram%s with no route received\n");
p(ifs6_in_addrerr, "\t%llu datagram%s with invalid dst received\n");
p(ifs6_in_truncated, "\t%llu truncated datagram%s received\n");
- p(ifs6_in_protounknown, "\t%llu datagram%s with unknown proto received\n");
+ p(ifs6_in_protounknown,
+ "\t%llu datagram%s with unknown proto received\n");
p(ifs6_in_discard, "\t%llu input datagram%s discarded\n");
p(ifs6_in_deliver,
- "\t%llu datagram%s delivered to an upper layer protocol\n");
+ "\t%llu datagram%s delivered to an upper layer protocol\n");
p(ifs6_out_forward, "\t%llu datagram%s forwarded to this interface\n");
p(ifs6_out_request,
- "\t%llu datagram%s sent from an upper layer protocol\n");
+ "\t%llu datagram%s sent from an upper layer protocol\n");
p(ifs6_out_discard, "\t%llu total discarded output datagram%s\n");
p(ifs6_out_fragok, "\t%llu output datagram%s fragmented\n");
p(ifs6_out_fragfail, "\t%llu output datagram%s failed on fragment\n");
- p(ifs6_out_fragcreat, "\t%llu output datagram%s succeeded on fragment\n");
+ p(ifs6_out_fragcreat,
+ "\t%llu output datagram%s succeeded on fragment\n");
p(ifs6_reass_reqd, "\t%llu incoming datagram%s fragmented\n");
p(ifs6_reass_ok, "\t%llu datagram%s reassembled\n");
p(ifs6_reass_fail, "\t%llu datagram%s failed on reassembling\n");
@@ -860,7 +871,7 @@ ip6_ifstats(const char *ifname)
#undef p_5
}
-static const char *icmp6names[] = {
+static const char *icmp6names[256] = {
"#0",
"unreach",
"packet too big",
@@ -880,7 +891,7 @@ static const char *icmp6names[] = {
"#16",
"#17",
"#18",
- "#19",
+ "#19",
"#20",
"#21",
"#22",
@@ -890,7 +901,7 @@ static const char *icmp6names[] = {
"#26",
"#27",
"#28",
- "#29",
+ "#29",
"#30",
"#31",
"#32",
@@ -900,7 +911,7 @@ static const char *icmp6names[] = {
"#36",
"#37",
"#38",
- "#39",
+ "#39",
"#40",
"#41",
"#42",
@@ -910,7 +921,7 @@ static const char *icmp6names[] = {
"#46",
"#47",
"#48",
- "#49",
+ "#49",
"#50",
"#51",
"#52",
@@ -920,7 +931,7 @@ static const char *icmp6names[] = {
"#56",
"#57",
"#58",
- "#59",
+ "#59",
"#60",
"#61",
"#62",
@@ -930,7 +941,7 @@ static const char *icmp6names[] = {
"#66",
"#67",
"#68",
- "#69",
+ "#69",
"#70",
"#71",
"#72",
@@ -940,7 +951,7 @@ static const char *icmp6names[] = {
"#76",
"#77",
"#78",
- "#79",
+ "#79",
"#80",
"#81",
"#82",
@@ -950,7 +961,7 @@ static const char *icmp6names[] = {
"#86",
"#87",
"#88",
- "#89",
+ "#89",
"#80",
"#91",
"#92",
@@ -960,7 +971,7 @@ static const char *icmp6names[] = {
"#96",
"#97",
"#98",
- "#99",
+ "#99",
"#100",
"#101",
"#102",
@@ -970,7 +981,7 @@ static const char *icmp6names[] = {
"#106",
"#107",
"#108",
- "#109",
+ "#109",
"#110",
"#111",
"#112",
@@ -980,7 +991,7 @@ static const char *icmp6names[] = {
"#116",
"#117",
"#118",
- "#119",
+ "#119",
"#120",
"#121",
"#122",
@@ -990,7 +1001,7 @@ static const char *icmp6names[] = {
"#126",
"#127",
"echo",
- "echo reply",
+ "echo reply",
"multicast listener query",
"multicast listener report",
"multicast listener done",
@@ -1004,23 +1015,23 @@ static const char *icmp6names[] = {
"node information reply",
"#141",
"#142",
- "#143",
- "#144",
- "#145",
- "#146",
- "#147",
+ "multicast listener report (v2)",
+ "home agent discovery request",
+ "home agent discovery reply",
+ "mobile prefix solicitation",
+ "mobile prefix advertisement",
"#148",
- "#149",
+ "#149",
"#150",
- "#151",
- "#152",
- "#153",
+ "multicast router advertisement",
+ "multicast router solicitation",
+ "multicast router termination",
"#154",
"#155",
"#156",
"#157",
"#158",
- "#159",
+ "#159",
"#160",
"#161",
"#162",
@@ -1030,7 +1041,7 @@ static const char *icmp6names[] = {
"#166",
"#167",
"#168",
- "#169",
+ "#169",
"#170",
"#171",
"#172",
@@ -1040,7 +1051,7 @@ static const char *icmp6names[] = {
"#176",
"#177",
"#178",
- "#179",
+ "#179",
"#180",
"#181",
"#182",
@@ -1050,7 +1061,7 @@ static const char *icmp6names[] = {
"#186",
"#187",
"#188",
- "#189",
+ "#189",
"#180",
"#191",
"#192",
@@ -1060,7 +1071,7 @@ static const char *icmp6names[] = {
"#196",
"#197",
"#198",
- "#199",
+ "#199",
"#200",
"#201",
"#202",
@@ -1070,7 +1081,7 @@ static const char *icmp6names[] = {
"#206",
"#207",
"#208",
- "#209",
+ "#209",
"#210",
"#211",
"#212",
@@ -1080,7 +1091,7 @@ static const char *icmp6names[] = {
"#216",
"#217",
"#218",
- "#219",
+ "#219",
"#220",
"#221",
"#222",
@@ -1090,7 +1101,7 @@ static const char *icmp6names[] = {
"#226",
"#227",
"#228",
- "#229",
+ "#229",
"#230",
"#231",
"#232",
@@ -1100,7 +1111,7 @@ static const char *icmp6names[] = {
"#236",
"#237",
"#238",
- "#239",
+ "#239",
"#240",
"#241",
"#242",
@@ -1110,13 +1121,13 @@ static const char *icmp6names[] = {
"#246",
"#247",
"#248",
- "#249",
+ "#249",
"#250",
"#251",
"#252",
"#253",
"#254",
- "#255",
+ "#255"
};
/*
@@ -1138,13 +1149,15 @@ icmp6_stats(u_long off, const char *name
warnx("%s stats not available via KVM.", name);
return;
}
-
+
printf("%s:\n", name);
-#define p(f, m) if (icmp6stat[f] || sflag <= 1) \
- printf(m, (unsigned long long)icmp6stat[f], plural(icmp6stat[f]))
+#define p(f, m) if (icmp6stat[f] || sflag <= 1) \
+ printf(m, (unsigned long long)icmp6stat[f], \
+ plural(icmp6stat[f]))
#define p_oerr(f, m) if (icmp6stat[ICMP6_STAT_OUTERRHIST + f] || sflag <= 1) \
- printf(m, (unsigned long long)icmp6stat[ICMP6_STAT_OUTERRHIST + f])
+ printf(m, \
+ (unsigned long long)icmp6stat[ICMP6_STAT_OUTERRHIST + f])
p(ICMP6_STAT_ERROR, "\t%llu call%s to icmp6_error\n");
p(ICMP6_STAT_CANTERROR,
@@ -1175,27 +1188,38 @@ icmp6_stats(u_long off, const char *name
}
printf("\tHistogram of error messages to be generated:\n");
p_oerr(ICMP6_ERRSTAT_DST_UNREACH_NOROUTE, "\t\t%llu no route\n");
- p_oerr(ICMP6_ERRSTAT_DST_UNREACH_ADMIN, "\t\t%llu administratively prohibited\n");
- p_oerr(ICMP6_ERRSTAT_DST_UNREACH_BEYONDSCOPE, "\t\t%llu beyond scope\n");
- p_oerr(ICMP6_ERRSTAT_DST_UNREACH_ADDR, "\t\t%llu address unreachable\n");
- p_oerr(ICMP6_ERRSTAT_DST_UNREACH_NOPORT, "\t\t%llu port unreachable\n");
+ p_oerr(ICMP6_ERRSTAT_DST_UNREACH_ADMIN,
+ "\t\t%llu administratively prohibited\n");
+ p_oerr(ICMP6_ERRSTAT_DST_UNREACH_BEYONDSCOPE,
+ "\t\t%llu beyond scope\n");
+ p_oerr(ICMP6_ERRSTAT_DST_UNREACH_ADDR,
+ "\t\t%llu address unreachable\n");
+ p_oerr(ICMP6_ERRSTAT_DST_UNREACH_NOPORT,
+ "\t\t%llu port unreachable\n");
p_oerr(ICMP6_ERRSTAT_PACKET_TOO_BIG, "\t\t%llu packet too big\n");
- p_oerr(ICMP6_ERRSTAT_TIME_EXCEED_TRANSIT, "\t\t%llu time exceed transit\n");
- p_oerr(ICMP6_ERRSTAT_TIME_EXCEED_REASSEMBLY, "\t\t%llu time exceed reassembly\n");
- p_oerr(ICMP6_ERRSTAT_PARAMPROB_HEADER, "\t\t%llu erroneous header field\n");
- p_oerr(ICMP6_ERRSTAT_PARAMPROB_NEXTHEADER, "\t\t%llu unrecognized next header\n");
- p_oerr(ICMP6_ERRSTAT_PARAMPROB_OPTION, "\t\t%llu unrecognized option\n");
+ p_oerr(ICMP6_ERRSTAT_TIME_EXCEED_TRANSIT,
+ "\t\t%llu time exceed transit\n");
+ p_oerr(ICMP6_ERRSTAT_TIME_EXCEED_REASSEMBLY,
+ "\t\t%llu time exceed reassembly\n");
+ p_oerr(ICMP6_ERRSTAT_PARAMPROB_HEADER,
+ "\t\t%llu erroneous header field\n");
+ p_oerr(ICMP6_ERRSTAT_PARAMPROB_NEXTHEADER,
+ "\t\t%llu unrecognized next header\n");
+ p_oerr(ICMP6_ERRSTAT_PARAMPROB_OPTION,
+ "\t\t%llu unrecognized option\n");
p_oerr(ICMP6_ERRSTAT_REDIRECT, "\t\t%llu redirect\n");
p_oerr(ICMP6_ERRSTAT_UNKNOWN, "\t\t%llu unknown\n");
p(ICMP6_STAT_REFLECT, "\t%llu message response%s generated\n");
- p(ICMP6_STAT_ND_TOOMANYOPT, "\t%llu message%s with too many ND options\n");
+ p(ICMP6_STAT_ND_TOOMANYOPT,
+ "\t%llu message%s with too many ND options\n");
p(ICMP6_STAT_ND_BADOPT, "\t%llu message%s with bad ND options\n");
p(ICMP6_STAT_BADNS, "\t%llu bad neighbor solicitation message%s\n");
p(ICMP6_STAT_BADNA, "\t%llu bad neighbor advertisement message%s\n");
p(ICMP6_STAT_BADRS, "\t%llu bad router solicitation message%s\n");
p(ICMP6_STAT_BADRA, "\t%llu bad router advertisement message%s\n");
- p(ICMP6_STAT_DROPPED_RAROUTE, "\t%llu router advertisement route%s dropped\n");
+ p(ICMP6_STAT_DROPPED_RAROUTE,
+ "\t%llu router advertisement route%s dropped\n");
p(ICMP6_STAT_BADREDIRECT, "\t%llu bad redirect message%s\n");
p(ICMP6_STAT_PMTUCHG, "\t%llu path MTU change%s\n");
#undef p
@@ -1210,9 +1234,9 @@ icmp6_ifstats(const char *ifname)
{
struct in6_ifreq ifr;
int s;
-#define p(f, m) if (ifr.ifr_ifru.ifru_icmp6stat.f || sflag <= 1) \
- printf(m, (unsigned long long)ifr.ifr_ifru.ifru_icmp6stat.f, \
- plural(ifr.ifr_ifru.ifru_icmp6stat.f))
+#define p(f, m) if (ifr.ifr_ifru.ifru_icmp6stat.f || sflag <= 1) \
+ printf(m, (unsigned long long)ifr.ifr_ifru.ifru_icmp6stat.f, \
+ plural(ifr.ifr_ifru.ifru_icmp6stat.f))
if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
perror("Warning: socket(AF_INET6)");
@@ -1228,9 +1252,11 @@ icmp6_ifstats(const char *ifname)
}
p(ifs6_in_msg, "\t%llu total input message%s\n");
- p(ifs6_in_error, "\t%llu total input error message%s\n");
- p(ifs6_in_dstunreach, "\t%llu input destination unreachable error%s\n");
- p(ifs6_in_adminprohib, "\t%llu input administratively prohibited error%s\n");
+ p(ifs6_in_error, "\t%llu total input error message%s\n");
+ p(ifs6_in_dstunreach,
+ "\t%llu input destination unreachable error%s\n");
+ p(ifs6_in_adminprohib,
+ "\t%llu input administratively prohibited error%s\n");
p(ifs6_in_timeexceed, "\t%llu input time exceeded error%s\n");
p(ifs6_in_paramprob, "\t%llu input parameter problem error%s\n");
p(ifs6_in_pkttoobig, "\t%llu input packet too big error%s\n");
@@ -1247,8 +1273,10 @@ icmp6_ifstats(const char *ifname)
p(ifs6_out_msg, "\t%llu total output message%s\n");
p(ifs6_out_error, "\t%llu total output error message%s\n");
- p(ifs6_out_dstunreach, "\t%llu output destination unreachable error%s\n");
- p(ifs6_out_adminprohib, "\t%llu output administratively prohibited error%s\n");
+ p(ifs6_out_dstunreach,
+ "\t%llu output destination unreachable error%s\n");
+ p(ifs6_out_adminprohib,
+ "\t%llu output administratively prohibited error%s\n");
p(ifs6_out_timeexceed, "\t%llu output time exceeded error%s\n");
p(ifs6_out_paramprob, "\t%llu output parameter problem error%s\n");
p(ifs6_out_pkttoobig, "\t%llu output packet too big error%s\n");
@@ -1282,18 +1310,22 @@ pim6_stats(u_long off, const char *name)
if (sysctlbyname("net.inet6.pim6.stats", pim6stat, &size,
NULL, 0) == -1)
return;
- } else {
+ } else {
warnx("%s stats not available via KVM.", name);
return;
}
printf("%s:\n", name);
-#define p(f, m) if (pim6stat[f] || sflag <= 1) \
- printf(m, (unsigned long long)pim6stat[f], plural(pim6stat[f]))
+#define p(f, m) if (pim6stat[f] || sflag <= 1) \
+ printf(m, (unsigned long long)pim6stat[f], plural(pim6stat[f]))
+
p(PIM6_STAT_RCV_TOTAL, "\t%llu message%s received\n");
- p(PIM6_STAT_RCV_TOOSHORT, "\t%llu message%s received with too few bytes\n");
- p(PIM6_STAT_RCV_BADSUM, "\t%llu message%s received with bad checksum\n");
- p(PIM6_STAT_RCV_BADVERSION, "\t%llu message%s received with bad version\n");
+ p(PIM6_STAT_RCV_TOOSHORT,
+ "\t%llu message%s received with too few bytes\n");
+ p(PIM6_STAT_RCV_BADSUM,
+ "\t%llu message%s received with bad checksum\n");
+ p(PIM6_STAT_RCV_BADVERSION,
+ "\t%llu message%s received with bad version\n");
p(PIM6_STAT_RCV_REGISTERS, "\t%llu register%s received\n");
p(PIM6_STAT_RCV_BADREGISTERS, "\t%llu bad register%s received\n");
p(PIM6_STAT_SND_REGISTERS, "\t%llu register%s sent\n");
@@ -1349,15 +1381,16 @@ rip6_stats(u_long off, const char *name)
void
inet6print(const struct in6_addr *in6, int port, const char *proto)
{
-#define GETSERVBYPORT6(port, proto, ret)\
-do {\
- if (strcmp((proto), "tcp6") == 0)\
- (ret) = getservbyport((int)(port), "tcp");\
- else if (strcmp((proto), "udp6") == 0)\
- (ret) = getservbyport((int)(port), "udp");\
- else\
- (ret) = getservbyport((int)(port), (proto));\
-} while (0)
+#define GETSERVBYPORT6(port, proto, ret) \
+ do { \
+ if (strcmp((proto), "tcp6") == 0) \
+ (ret) = getservbyport((int)(port), "tcp"); \
+ else if (strcmp((proto), "udp6") == 0) \
+ (ret) = getservbyport((int)(port), "udp"); \
+ else \
+ (ret) = getservbyport((int)(port), (proto)); \
+ } while (0)
+
struct servent *sp = 0;
char line[80], *cp;
int lwidth;
@@ -1426,14 +1459,14 @@ inet6name(const struct in6_addr *in6p)
sin6.sin6_len = sizeof(sin6);
sin6.sin6_family = AF_INET6;
sin6.sin6_addr = *in6p;
- inet6_getscopeid(&sin6, INET6_IS_ADDR_LINKLOCAL|
- INET6_IS_ADDR_MC_LINKLOCAL);
+ inet6_getscopeid(&sin6,
+ INET6_IS_ADDR_LINKLOCAL | INET6_IS_ADDR_MC_LINKLOCAL);
if (getnameinfo((struct sockaddr *)&sin6, sin6.sin6_len,
hbuf, sizeof(hbuf), NULL, 0, niflag) != 0)
strlcpy(hbuf, "?", sizeof(hbuf));
strlcpy(line, hbuf, sizeof(line));
}
- return (line);
+ return line;
}
/*
@@ -1453,9 +1486,9 @@ tcp6_dump(u_long off, const char *name,
size_t j, len;
if (use_sysctl)
- pcblist = getpcblist_sysctl(name, &len);
+ pcblist = getpcblist_sysctl(name, &len);
else
- pcblist = getpcblist_kmem(off, name, &len);
+ pcblist = getpcblist_kmem(off, name, &len);
for (j = 0; j < len; j++)
if (pcblist[j].ki_ppcbaddr == pcbaddr)
@@ -1495,7 +1528,7 @@ tcp6_dump(u_long off, const char *name,
printf("peermaxseg %u, maxseg %u, force %d\n\n", mypcb.t_peermaxseg,
mypcb.t_maxseg, mypcb.t_force);
#else
- printf("peermss %u, ourmss %u, segsz %u, segqlen %u\n\n",
+ printf("peermss %u, ourmss %u, segsz %u, segqlen %u\n\n",
tcpcb.t_peermss, tcpcb.t_ourmss, tcpcb.t_segsz, tcpcb.t_segqlen);
#endif
Index: src/usr.bin/netstat/main.c
diff -u src/usr.bin/netstat/main.c:1.99 src/usr.bin/netstat/main.c:1.99.8.1
--- src/usr.bin/netstat/main.c:1.99 Thu Jul 14 20:13:10 2016
+++ src/usr.bin/netstat/main.c Mon Sep 12 14:29:19 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.99 2016/07/14 20:13:10 christos Exp $ */
+/* $NetBSD: main.c,v 1.99.8.1 2022/09/12 14:29:19 martin Exp $ */
/*
* Copyright (c) 1983, 1988, 1993
@@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 19
#if 0
static char sccsid[] = "from: @(#)main.c 8.4 (Berkeley) 3/1/94";
#else
-__RCSID("$NetBSD: main.c,v 1.99 2016/07/14 20:13:10 christos Exp $");
+__RCSID("$NetBSD: main.c,v 1.99.8.1 2022/09/12 14:29:19 martin Exp $");
#endif
#endif /* not lint */
@@ -67,6 +67,38 @@ __RCSID("$NetBSD: main.c,v 1.99 2016/07/
#include "rtutil.h"
#include "prog_ops.h"
+int Aflag;
+int aflag;
+int Bflag;
+int bflag;
+int dflag;
+#ifndef SMALL
+int gflag;
+#endif
+int hflag;
+int iflag;
+int Lflag;
+int lflag;
+int mflag;
+int numeric_addr;
+int numeric_port;
+int nflag;
+int Pflag;
+int pflag;
+int qflag;
+int rflag;
+int sflag;
+int tagflag;
+int tflag;
+int Vflag;
+int vflag;
+
+char *interface;
+
+int af;
+int use_sysctl;
+int force_sysctl;
+
struct nlist nl[] = {
#define N_MBSTAT 0
{ "_mbstat", 0, 0, 0, 0 },
@@ -175,8 +207,8 @@ struct protox {
(u_long, const char *);
void (*pr_stats) /* statistics printing routine */
(u_long, const char *);
- void (*pr_istats)
- (const char *); /* per/if statistics printing routine */
+ void (*pr_istats) /* per/if statistics printing routine */
+ (const char *);
void (*pr_dump) /* PCB state dump routine */
(u_long, const char *, u_long);
const char *pr_name; /* well-known name */
@@ -200,7 +232,7 @@ struct protox {
{ -1, N_PIMSTAT, 1, 0,
pim_stats, NULL, 0, "pim" },
{ -1, N_PFSYNCSTAT, 1, 0,
- pfsync_stats, NULL, 0, "pfsync" },
+ pfsync_stats, NULL, 0, "pfsync" },
{ -1, -1, 0, 0,
0, NULL, 0, 0 }
};
@@ -324,6 +356,7 @@ void
prepare(const char *nf, const char *mf, struct protox *tp)
{
char buf[_POSIX2_LINE_MAX];
+
/*
* Try to figure out if we can use sysctl or not.
*/
@@ -354,7 +387,7 @@ prepare(const char *nf, const char *mf,
if (force_sysctl && !use_sysctl) {
/* Let the user know what's about to happen. */
- warnx("forcing sysctl usage even though it might not be "\
+ warnx("forcing sysctl usage even though it might not be "
"supported");
use_sysctl = 1;
}
@@ -456,13 +489,13 @@ main(int argc, char *argv[])
errno = 0;
pcbaddr = strtoul(optarg, &cp, 16);
if (*cp != '\0' || errno == ERANGE)
- errx(1, "invalid PCB address %s",
- optarg);
+ errx(1, "invalid PCB address %s", optarg);
Pflag = 1;
break;
case 'p':
if ((tp = name2protox(optarg)) == NULL)
- errx(1, "%s: unknown or uninstrumented protocol",
+ errx(1,
+ "%s: unknown or uninstrumented protocol",
optarg);
pflag = 1;
break;
@@ -557,7 +590,8 @@ main(int argc, char *argv[])
}
if (pflag) {
if (iflag && tp->pr_istats)
- intpr(interval, nl[N_IFNET_LIST].n_value, tp->pr_istats);
+ intpr(interval, nl[N_IFNET_LIST].n_value,
+ tp->pr_istats);
else if (tp->pr_stats)
(*tp->pr_stats)(nl[tp->pr_sindex].n_value,
tp->pr_name);
@@ -616,7 +650,8 @@ main(int argc, char *argv[])
}
if (rflag) {
if (sflag)
- rt_stats(use_sysctl ? 0 : nl[N_RTSTAT].n_value);
+ rt_stats(use_sysctl ? 0 :
+ nl[N_RTSTAT].n_value);
else {
if (use_sysctl)
p_rttables(af,
@@ -712,7 +747,7 @@ printproto(struct protox *tp, const char
if (iflag) {
if (tp->pr_istats)
intpr(interval, nl[N_IFNET_LIST].n_value,
- tp->pr_istats);
+ tp->pr_istats);
return;
}
else {
@@ -723,9 +758,8 @@ printproto(struct protox *tp, const char
pr = tp->pr_cblocks;
off = nl[tp->pr_index].n_value;
}
- if (pr != NULL && ((off || af != AF_UNSPEC) || use_sysctl)) {
+ if (pr != NULL && ((off || af != AF_UNSPEC) || use_sysctl))
(*pr)(off, name);
- }
}
/*
@@ -760,9 +794,9 @@ kread(u_long addr, char *buf, int size)
if (kvm_read(kvmd, addr, buf, size) != size) {
warnx("%s", kvm_geterr(kvmd));
- return (-1);
+ return -1;
}
- return (0);
+ return 0;
}
const char *
@@ -786,7 +820,7 @@ get_hardticks(void)
kread(nl[N_HARDCLOCK_TICKS].n_value, (char *)&hardticks,
sizeof(hardticks));
- return (hardticks);
+ return hardticks;
}
/*
@@ -800,8 +834,8 @@ knownname(const char *name)
for (tpp = protoprotox; *tpp; tpp++)
for (tp = *tpp; tp->pr_name; tp++)
if (strcmp(tp->pr_name, name) == 0)
- return (tp);
- return (NULL);
+ return tp;
+ return NULL;
}
/*
@@ -819,7 +853,7 @@ name2protox(const char *name)
* fails, check if name is an alias for an Internet protocol.
*/
if ((tp = knownname(name)) != NULL)
- return (tp);
+ return tp;
setprotoent(1); /* make protocol lookup cheaper */
while ((p = getprotoent()) != NULL) {
@@ -827,11 +861,11 @@ name2protox(const char *name)
for (alias = p->p_aliases; *alias; alias++)
if (strcmp(name, *alias) == 0) {
endprotoent();
- return (knownname(p->p_name));
+ return knownname(p->p_name);
}
}
endprotoent();
- return (NULL);
+ return NULL;
}
static void
@@ -842,7 +876,7 @@ usage(void)
(void)fprintf(stderr,
"usage: %s [-Aan] [-f address_family[,family ...]] [-M core] [-N system]\n", progname);
(void)fprintf(stderr,
-" %s [-bdgiLmnqrsSv] [-f address_family[,family ...]] [-M core] [-N system]\n",
+" %s [-bdgiLmnqrsSv] [-f address_family[,family ...]] [-M core] [-N system]\n",
progname);
(void)fprintf(stderr,
" %s [-dn] [-I interface] [-M core] [-N system] [-w wait]\n", progname);
Index: src/usr.bin/netstat/mbuf.c
diff -u src/usr.bin/netstat/mbuf.c:1.33 src/usr.bin/netstat/mbuf.c:1.33.8.1
--- src/usr.bin/netstat/mbuf.c:1.33 Tue Jul 28 19:46:42 2015
+++ src/usr.bin/netstat/mbuf.c Mon Sep 12 14:29:19 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: mbuf.c,v 1.33 2015/07/28 19:46:42 christos Exp $ */
+/* $NetBSD: mbuf.c,v 1.33.8.1 2022/09/12 14:29:19 martin Exp $ */
/*
* Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "from: @(#)mbuf.c 8.1 (Berkeley) 6/6/93";
#else
-__RCSID("$NetBSD: mbuf.c,v 1.33 2015/07/28 19:46:42 christos Exp $");
+__RCSID("$NetBSD: mbuf.c,v 1.33.8.1 2022/09/12 14:29:19 martin Exp $");
#endif
#endif /* not lint */
@@ -101,7 +101,7 @@ mbpr(u_long mbaddr, u_long msizeaddr, u_
if (nmbtypes != 256) {
fprintf(stderr,
"%s: unexpected change to mbstat; check source\n",
- getprogname());
+ getprogname());
return;
}
@@ -172,29 +172,29 @@ mbpr(u_long mbaddr, u_long msizeaddr, u_
goto dump_drain;
printf("%lu/%lu mapped pages in use\n",
- (u_long)(mclpool.pr_nget - mclpool.pr_nput),
- ((u_long)mclpool.pr_npages * mclpool.pr_itemsperpage));
+ (u_long)(mclpool.pr_nget - mclpool.pr_nput),
+ ((u_long)mclpool.pr_npages * mclpool.pr_itemsperpage));
totmem = (mbpool.pr_npages << mbpa.pa_pageshift) +
(mclpool.pr_npages << mclpa.pa_pageshift);
totused = (mbpool.pr_nget - mbpool.pr_nput) * mbpool.pr_size +
(mclpool.pr_nget - mclpool.pr_nput) * mclpool.pr_size;
if (totmem == 0)
totpct = 0;
- else if (totused < (ULONG_MAX/100))
+ else if (totused < (ULONG_MAX / 100))
totpct = (totused * 100)/totmem;
else {
- u_long totmem1 = totmem/100;
- u_long totused1 = totused/100;
- totpct = (totused1 * 100)/totmem1;
+ u_long totmem1 = totmem / 100;
+ u_long totused1 = totused / 100;
+ totpct = (totused1 * 100) / totmem1;
}
-
+
printf("%lu Kbytes allocated to network (%lu%% in use)\n",
totmem / 1024, totpct);
dump_drain:
printf("%lu calls to protocol drain routines\n", mbstat.m_drain);
- if (sflag < 2)
+ if (sflag < 2)
return;
if (!use_sysctl)
@@ -239,7 +239,7 @@ dump_drain:
mo->mo_counter[MOWNER_COUNTER_CLUSTER_CLAIMS] ==
mo->mo_counter[MOWNER_COUNTER_CLUSTER_RELEASES])
continue;
- snprintf(buf, sizeof(buf), "%16s %-13s",
+ snprintf(buf, sizeof(buf), "%16.16s %-13s",
mo->mo_name, mo->mo_descr);
if ((lines % 24) == 0 || lines > 24) {
printf("%30s %-8s %10s %10s %10s\n",
Index: src/usr.bin/netstat/mroute.c
diff -u src/usr.bin/netstat/mroute.c:1.25 src/usr.bin/netstat/mroute.c:1.25.8.1
--- src/usr.bin/netstat/mroute.c:1.25 Thu Nov 6 21:30:09 2014
+++ src/usr.bin/netstat/mroute.c Mon Sep 12 14:29:19 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: mroute.c,v 1.25 2014/11/06 21:30:09 christos Exp $ */
+/* $NetBSD: mroute.c,v 1.25.8.1 2022/09/12 14:29:19 martin Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -76,7 +76,7 @@
#if 0
static char sccsid[] = "from: @(#)mroute.c 8.1 (Berkeley) 6/6/93";
#else
-__RCSID("$NetBSD: mroute.c,v 1.25 2014/11/06 21:30:09 christos Exp $");
+__RCSID("$NetBSD: mroute.c,v 1.25.8.1 2022/09/12 14:29:19 martin Exp $");
#endif
#endif /* not lint */
@@ -125,7 +125,7 @@ pktscale(u_long n)
}
(void)snprintf(buf, sizeof buf, "%lu%c", n, t);
- return (buf);
+ return buf;
}
void
@@ -230,7 +230,8 @@ mroutepr(u_long mrpaddr, u_long mfchasht
pktscale(mfc.mfc_pkt_cnt), mfc.mfc_parent);
for (vifi = 0; vifi <= numvifs; ++vifi)
if (mfc.mfc_ttls[vifi])
- printf(" %u/%u", vifi, mfc.mfc_ttls[vifi]);
+ printf(" %u/%u", vifi,
+ mfc.mfc_ttls[vifi]);
printf("\n");
@@ -241,12 +242,12 @@ mroutepr(u_long mrpaddr, u_long mfchasht
bwm = mfc.mfc_bw_meter;
while (bwm) {
- kread((u_long)bwm,
- (char *)&bw_meter,
- sizeof bw_meter);
- print_bw_meter(&bw_meter,
- &banner_printed2);
- bwm = bw_meter.bm_mfc_next;
+ kread((u_long)bwm,
+ (char *)&bw_meter,
+ sizeof bw_meter);
+ print_bw_meter(&bw_meter,
+ &banner_printed2);
+ bwm = bw_meter.bm_mfc_next;
}
#if 0 /* Don't ever print it? */
if (! banner_printed2)
@@ -269,7 +270,7 @@ mroutepr(u_long mrpaddr, u_long mfchasht
static void
print_bw_meter(struct bw_meter *bw_meter, int *banner_printed)
{
- char s0[256], s1[256], s2[256], s3[256];
+ char s0[256*3], s1[256], s2[256], s3[256];
struct timeval now, end, delta;
gettimeofday(&now, NULL);
@@ -286,37 +287,41 @@ print_bw_meter(struct bw_meter *bw_meter
/* The measured values */
if (bw_meter->bm_flags & BW_METER_UNIT_PACKETS)
- sprintf(s1, "%llu", (unsigned long long)bw_meter->bm_measured.b_packets);
+ snprintf(s1, sizeof s1, "%llu",
+ (unsigned long long)bw_meter->bm_measured.b_packets);
else
- sprintf(s1, "?");
+ snprintf(s1, sizeof s1, "?");
if (bw_meter->bm_flags & BW_METER_UNIT_BYTES)
- sprintf(s2, "%llu", (unsigned long long)bw_meter->bm_measured.b_bytes);
+ snprintf(s2, sizeof s2, "%llu",
+ (unsigned long long)bw_meter->bm_measured.b_bytes);
else
- sprintf(s2, "?");
- sprintf(s0, "%lld.%ld|%s|%s",
+ snprintf(s2, sizeof s2, "?");
+ snprintf(s0, sizeof s0, "%lld.%ld|%s|%s",
(long long)bw_meter->bm_start_time.tv_sec,
(long)bw_meter->bm_start_time.tv_usec,
s1, s2);
printf(" %-30s", s0);
/* The type of entry */
- sprintf(s0, "%s", "?");
+ snprintf(s0, sizeof s0, "%s", "?");
if (bw_meter->bm_flags & BW_METER_GEQ)
- sprintf(s0, "%s", ">=");
+ snprintf(s0, sizeof s0, "%s", ">=");
else if (bw_meter->bm_flags & BW_METER_LEQ)
- sprintf(s0, "%s", "<=");
+ snprintf(s0, sizeof s0, "%s", "<=");
printf(" %-3s", s0);
/* The threshold values */
if (bw_meter->bm_flags & BW_METER_UNIT_PACKETS)
- sprintf(s1, "%llu", (unsigned long long)bw_meter->bm_threshold.b_packets);
+ snprintf(s1, sizeof s1, "%llu",
+ (unsigned long long)bw_meter->bm_threshold.b_packets);
else
- sprintf(s1, "?");
+ snprintf(s1, sizeof s1, "?");
if (bw_meter->bm_flags & BW_METER_UNIT_BYTES)
- sprintf(s2, "%llu", (unsigned long long)bw_meter->bm_threshold.b_bytes);
+ snprintf(s2, sizeof s2, "%llu",
+ (unsigned long long)bw_meter->bm_threshold.b_bytes);
else
- sprintf(s2, "?");
- sprintf(s0, "%lld.%ld|%s|%s",
+ snprintf(s2, sizeof s2, "?");
+ snprintf(s0, sizeof s0, "%lld.%ld|%s|%s",
(long long)bw_meter->bm_threshold.b_time.tv_sec,
(long)bw_meter->bm_threshold.b_time.tv_usec,
s1, s2);
@@ -327,12 +332,12 @@ print_bw_meter(struct bw_meter *bw_meter
&bw_meter->bm_threshold.b_time, &end);
if (timercmp(&now, &end, <=)) {
timersub(&end, &now, &delta);
- sprintf(s3, "%lld.%ld",
+ snprintf(s3, sizeof s3, "%lld.%ld",
(long long)delta.tv_sec, (long)delta.tv_usec);
} else {
/* Negative time */
timersub(&now, &end, &delta);
- sprintf(s3, "-%lld.%ld",
+ snprintf(s3, sizeof s3, "-%lld.%ld",
(long long)delta.tv_sec, (long)delta.tv_usec);
}
printf(" %s", s3);
Index: src/usr.bin/netstat/mroute6.c
diff -u src/usr.bin/netstat/mroute6.c:1.15 src/usr.bin/netstat/mroute6.c:1.15.8.1
--- src/usr.bin/netstat/mroute6.c:1.15 Thu Nov 6 21:30:09 2014
+++ src/usr.bin/netstat/mroute6.c Mon Sep 12 14:29:19 2022
@@ -1,9 +1,9 @@
-/* $NetBSD: mroute6.c,v 1.15 2014/11/06 21:30:09 christos Exp $ */
+/* $NetBSD: mroute6.c,v 1.15.8.1 2022/09/12 14:29:19 martin Exp $ */
/*
* Copyright (C) 1998 WIDE Project.
* All rights reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -15,7 +15,7 @@
* 3. Neither the name of the project 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 PROJECT 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
@@ -121,8 +121,10 @@
#ifdef INET6
-#define WID_ORG (lflag ? 39 : (numeric_addr ? 29 : 18)) /* width of origin column */
-#define WID_GRP (lflag ? 18 : (numeric_addr ? 16 : 18)) /* width of group column */
+/* Width of origin column */
+#define WID_ORG (lflag ? 39 : (numeric_addr ? 29 : 18))
+/* Width of group column */
+#define WID_GRP (lflag ? 18 : (numeric_addr ? 16 : 18))
void
mroute6pr(u_long mrpaddr, u_long mfcaddr, u_long mifaddr)
@@ -201,7 +203,7 @@ mroute6pr(u_long mrpaddr, u_long mfcaddr
banner_printed = 0;
for (i = 0; i < MF6CTBLSIZ; ++i) {
mfcp = mf6ctable[i];
- while(mfcp) {
+ while (mfcp) {
kread((u_long)mfcp, (char *)&mfc, sizeof(mfc));
if (!banner_printed) {
printf ("\nIPv6 Multicast Forwarding Cache\n");
@@ -211,7 +213,7 @@ mroute6pr(u_long mrpaddr, u_long mfcaddr
" Packets Waits In-Mif Out-Mifs\n");
banner_printed = 1;
}
-
+
printf(" %-*.*s", WID_ORG, WID_ORG,
routename6(&mfc.mf6c_origin, nflag));
printf(" %-*.*s", WID_GRP, WID_GRP,
Index: src/usr.bin/netstat/netstat.1
diff -u src/usr.bin/netstat/netstat.1:1.73 src/usr.bin/netstat/netstat.1:1.73.8.1
--- src/usr.bin/netstat/netstat.1:1.73 Thu May 12 03:44:11 2016
+++ src/usr.bin/netstat/netstat.1 Mon Sep 12 14:29:19 2022
@@ -1,4 +1,4 @@
-.\" $NetBSD: netstat.1,v 1.73 2016/05/12 03:44:11 ozaki-r Exp $
+.\" $NetBSD: netstat.1,v 1.73.8.1 2022/09/12 14:29:19 martin Exp $
.\"
.\" Copyright (c) 1983, 1990, 1992, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -29,7 +29,7 @@
.\"
.\" @(#)netstat.1 8.8 (Berkeley) 4/18/94
.\"
-.Dd May 12, 2016
+.Dd July 21, 2020
.Dt NETSTAT 1
.Os
.Sh NAME
@@ -432,12 +432,17 @@ And the fifth character shows the header
.Xr sockstat 1 ,
.Xr vmstat 1 ,
.Xr inet 3 ,
+.Xr kvm 3 ,
+.Xr kvm_openfiles 3 ,
+.Xr sysctl 3 ,
.Xr bpf 4 ,
+.Xr route 4 ,
.Xr hosts 5 ,
.Xr networks 5 ,
.Xr protocols 5 ,
.Xr services 5 ,
.Xr iostat 8 ,
+.Xr route 8 ,
.Xr trpt 8
.Sh HISTORY
The
Index: src/usr.bin/netstat/netstat.h
diff -u src/usr.bin/netstat/netstat.h:1.51 src/usr.bin/netstat/netstat.h:1.51.8.1
--- src/usr.bin/netstat/netstat.h:1.51 Thu Nov 6 21:30:09 2014
+++ src/usr.bin/netstat/netstat.h Mon Sep 12 14:29:19 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: netstat.h,v 1.51 2014/11/06 21:30:09 christos Exp $ */
+/* $NetBSD: netstat.h,v 1.51.8.1 2022/09/12 14:29:19 martin Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -34,37 +34,37 @@
#include <sys/cdefs.h>
#include <kvm.h>
-int Aflag; /* show addresses of protocol control block */
-int aflag; /* show all sockets (including servers) */
-int Bflag; /* show Berkeley Packet Filter information */
-int bflag; /* show i/f byte stats */
-int dflag; /* show i/f dropped packets */
+extern int Aflag; /* show addresses of protocol control block */
+extern int aflag; /* show all sockets (including servers) */
+extern int Bflag; /* show Berkeley Packet Filter information */
+extern int bflag; /* show i/f byte stats */
+extern int dflag; /* show i/f dropped packets */
#ifndef SMALL
-int gflag; /* show group (multicast) routing or stats */
+extern int gflag; /* show group (multicast) routing or stats */
#endif
-int hflag; /* humanize byte counts */
-int iflag; /* show interfaces */
-int Lflag; /* don't show LLINFO entries */
-int lflag; /* show routing table with use and ref */
-int mflag; /* show memory stats */
-int numeric_addr; /* show addresses numerically */
-int numeric_port; /* show ports numerically */
-int nflag; /* same as above, for show.c compat */
-int Pflag; /* dump a PCB */
-int pflag; /* show given protocol */
-int qflag; /* show softintrq */
-int rflag; /* show routing tables (or routing stats) */
-int sflag; /* show protocol statistics */
-int tagflag; /* show route tags */
-int tflag; /* show i/f watchdog timers */
-int Vflag; /* show Vestigial TIME_WAIT (VTW) information */
-int vflag; /* verbose route information or don't truncate names */
-
-char *interface; /* desired i/f for stats, or NULL for all i/fs */
-
-int af; /* address family */
-int use_sysctl; /* use sysctl instead of kmem */
-int force_sysctl; /* force use of sysctl (or exit) - for testing */
+extern int hflag; /* humanize byte counts */
+extern int iflag; /* show interfaces */
+extern int Lflag; /* don't show LLINFO entries */
+extern int lflag; /* show routing table with use and ref */
+extern int mflag; /* show memory stats */
+extern int numeric_addr; /* show addresses numerically */
+extern int numeric_port; /* show ports numerically */
+extern int nflag; /* same as above, for show.c compat */
+extern int Pflag; /* dump a PCB */
+extern int pflag; /* show given protocol */
+extern int qflag; /* show softintrq */
+extern int rflag; /* show routing tables (or routing stats) */
+extern int sflag; /* show protocol statistics */
+extern int tagflag; /* show route tags */
+extern int tflag; /* show i/f watchdog timers */
+extern int Vflag; /* show Vestigial TIME_WAIT (VTW) information */
+extern int vflag; /* verbose route information or don't truncate names */
+
+extern char *interface; /* desired i/f for stats, or NULL for all i/fs */
+
+extern int af; /* address family */
+extern int use_sysctl; /* use sysctl instead of kmem */
+extern int force_sysctl; /* force use of sysctl (or exit) - for testing */
int kread(u_long addr, char *buf, int size);
Index: src/usr.bin/netstat/pfkey.c
diff -u src/usr.bin/netstat/pfkey.c:1.1 src/usr.bin/netstat/pfkey.c:1.1.34.1
--- src/usr.bin/netstat/pfkey.c:1.1 Fri Jan 6 14:21:16 2012
+++ src/usr.bin/netstat/pfkey.c Mon Sep 12 14:29:19 2022
@@ -1,10 +1,10 @@
-/* $NetBSD: pfkey.c,v 1.1 2012/01/06 14:21:16 drochner Exp $ */
+/* $NetBSD: pfkey.c,v 1.1.34.1 2022/09/12 14:29:19 martin Exp $ */
/* $KAME: ipsec.c,v 1.33 2003/07/25 09:54:32 itojun Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
* All rights reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -16,7 +16,7 @@
* 3. Neither the name of the project 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 PROJECT 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
@@ -65,7 +65,7 @@
static char sccsid[] = "from: @(#)inet.c 8.4 (Berkeley) 4/20/94";
#else
#ifdef __NetBSD__
-__RCSID("$NetBSD: pfkey.c,v 1.1 2012/01/06 14:21:16 drochner Exp $");
+__RCSID("$NetBSD: pfkey.c,v 1.1.34.1 2022/09/12 14:29:19 martin Exp $");
#endif
#endif
#endif /* not lint */
@@ -85,7 +85,7 @@ __RCSID("$NetBSD: pfkey.c,v 1.1 2012/01/
#include <unistd.h>
#include "netstat.h"
-#ifdef IPSEC
+#ifdef IPSEC
static const char *pfkey_msgtypenames[] = {
"reserved", "getspi", "update", "add", "delete",
@@ -129,7 +129,7 @@ pfkey_stats(u_long off, const char *name
printf ("%s:\n", name);
-#define p(f, m) if (pfkeystat[f] || sflag <= 1) \
+#define p(f, m) if (pfkeystat[f] || sflag <= 1) \
printf(m, (unsigned long long)pfkeystat[f], plural(pfkeystat[f]))
/* userland -> kernel */
@@ -145,15 +145,24 @@ pfkey_stats(u_long off, const char *name
printf("\t\t%s: %llu\n", pfkey_msgtype_names(type),
(unsigned long long)pfkeystat[PFKEY_STAT_OUT_MSGTYPE + type]);
}
- p(PFKEY_STAT_OUT_INVLEN, "\t%llu message%s with invalid length field\n");
- p(PFKEY_STAT_OUT_INVVER, "\t%llu message%s with invalid version field\n");
- p(PFKEY_STAT_OUT_INVMSGTYPE, "\t%llu message%s with invalid message type field\n");
- p(PFKEY_STAT_OUT_TOOSHORT, "\t%llu message%s too short\n");
- p(PFKEY_STAT_OUT_NOMEM, "\t%llu message%s with memory allocation failure\n");
- p(PFKEY_STAT_OUT_DUPEXT, "\t%llu message%s with duplicate extension\n");
- p(PFKEY_STAT_OUT_INVEXTTYPE, "\t%llu message%s with invalid extension type\n");
- p(PFKEY_STAT_OUT_INVSATYPE, "\t%llu message%s with invalid sa type\n");
- p(PFKEY_STAT_OUT_INVADDR, "\t%llu message%s with invalid address extension\n");
+ p(PFKEY_STAT_OUT_INVLEN,
+ "\t%llu message%s with invalid length field\n");
+ p(PFKEY_STAT_OUT_INVVER,
+ "\t%llu message%s with invalid version field\n");
+ p(PFKEY_STAT_OUT_INVMSGTYPE,
+ "\t%llu message%s with invalid message type field\n");
+ p(PFKEY_STAT_OUT_TOOSHORT,
+ "\t%llu message%s too short\n");
+ p(PFKEY_STAT_OUT_NOMEM,
+ "\t%llu message%s with memory allocation failure\n");
+ p(PFKEY_STAT_OUT_DUPEXT,
+ "\t%llu message%s with duplicate extension\n");
+ p(PFKEY_STAT_OUT_INVEXTTYPE,
+ "\t%llu message%s with invalid extension type\n");
+ p(PFKEY_STAT_OUT_INVSATYPE,
+ "\t%llu message%s with invalid sa type\n");
+ p(PFKEY_STAT_OUT_INVADDR,
+ "\t%llu message%s with invalid address extension\n");
/* kernel -> userland */
p(PFKEY_STAT_IN_TOTAL, "\t%llu request%s sent to userland\n");
@@ -174,7 +183,8 @@ pfkey_stats(u_long off, const char *name
"\t%llu message%s toward all sockets\n");
p(PFKEY_STAT_IN_MSGTARGET + KEY_SENDUP_REGISTERED,
"\t%llu message%s toward registered sockets\n");
- p(PFKEY_STAT_IN_NOMEM, "\t%llu message%s with memory allocation failure\n");
+ p(PFKEY_STAT_IN_NOMEM,
+ "\t%llu message%s with memory allocation failure\n");
#undef p
}
#endif /*IPSEC*/
Index: src/usr.bin/netstat/pfsync.c
diff -u src/usr.bin/netstat/pfsync.c:1.1 src/usr.bin/netstat/pfsync.c:1.1.38.1
--- src/usr.bin/netstat/pfsync.c:1.1 Tue Mar 1 19:01:59 2011
+++ src/usr.bin/netstat/pfsync.c Mon Sep 12 14:29:19 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: pfsync.c,v 1.1 2011/03/01 19:01:59 dyoung Exp $ */
+/* $NetBSD: pfsync.c,v 1.1.38.1 2022/09/12 14:29:19 martin Exp $ */
/*
* Copyright (c) 1983, 1988, 1993
@@ -31,7 +31,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: pfsync.c,v 1.1 2011/03/01 19:01:59 dyoung Exp $");
+__RCSID("$NetBSD: pfsync.c,v 1.1.38.1 2022/09/12 14:29:19 martin Exp $");
#endif /* not lint */
#define _CALLOUT_PRIVATE /* for defs in sys/callout.h */
@@ -82,7 +82,7 @@ pfsync_stats(u_long off, const char *nam
size_t size = sizeof(pfsyncstat);
if (sysctlbyname("net.inet.pfsync.stats", pfsyncstat, &size,
- NULL, 0) == -1)
+ NULL, 0) == -1)
return;
} else {
warnx("%s stats not available via KVM.", name);
@@ -98,20 +98,34 @@ pfsync_stats(u_long off, const char *nam
p(PFSYNC_STAT_IPACKETS, "\t%" PRIu64 " packet%s received (IPv4)\n");
p(PFSYNC_STAT_IPACKETS6,"\t%" PRIu64 " packet%s received (IPv6)\n");
- p(PFSYNC_STAT_BADIF, "\t\t%" PRIu64 " packet%s discarded for bad interface\n");
- p(PFSYNC_STAT_BADTTL, "\t\t%" PRIu64 " packet%s discarded for bad ttl\n");
- p(PFSYNC_STAT_HDROPS, "\t\t%" PRIu64 " packet%s shorter than header\n");
- p(PFSYNC_STAT_BADVER, "\t\t%" PRIu64 " packet%s discarded for bad version\n");
- p(PFSYNC_STAT_BADAUTH, "\t\t%" PRIu64 " packet%s discarded for bad HMAC\n");
- p(PFSYNC_STAT_BADACT,"\t\t%" PRIu64 " packet%s discarded for bad action\n");
- p(PFSYNC_STAT_BADLEN, "\t\t%" PRIu64 " packet%s discarded for short packet\n");
- p(PFSYNC_STAT_BADVAL, "\t\t%" PRIu64 " state%s discarded for bad values\n");
- p(PFSYNC_STAT_STALE, "\t\t%" PRIu64 " stale state%s\n");
- p(PFSYNC_STAT_BADSTATE, "\t\t%" PRIu64 " failed state lookup/insert%s\n");
- p(PFSYNC_STAT_OPACKETS, "\t%" PRIu64 " packet%s sent (IPv4)\n");
- p(PFSYNC_STAT_OPACKETS6, "\t%" PRIu64 " packet%s sent (IPv6)\n");
- p2(PFSYNC_STAT_ONOMEM, "\t\t%" PRIu64 " send failed due to mbuf memory error\n");
- p2(PFSYNC_STAT_OERRORS, "\t\t%" PRIu64 " send error\n");
+ p(PFSYNC_STAT_BADIF,
+ "\t\t%" PRIu64 " packet%s discarded for bad interface\n");
+ p(PFSYNC_STAT_BADTTL,
+ "\t\t%" PRIu64 " packet%s discarded for bad ttl\n");
+ p(PFSYNC_STAT_HDROPS,
+ "\t\t%" PRIu64 " packet%s shorter than header\n");
+ p(PFSYNC_STAT_BADVER,
+ "\t\t%" PRIu64 " packet%s discarded for bad version\n");
+ p(PFSYNC_STAT_BADAUTH,
+ "\t\t%" PRIu64 " packet%s discarded for bad HMAC\n");
+ p(PFSYNC_STAT_BADACT,
+ "\t\t%" PRIu64 " packet%s discarded for bad action\n");
+ p(PFSYNC_STAT_BADLEN,
+ "\t\t%" PRIu64 " packet%s discarded for short packet\n");
+ p(PFSYNC_STAT_BADVAL,
+ "\t\t%" PRIu64 " state%s discarded for bad values\n");
+ p(PFSYNC_STAT_STALE,
+ "\t\t%" PRIu64 " stale state%s\n");
+ p(PFSYNC_STAT_BADSTATE,
+ "\t\t%" PRIu64 " failed state lookup/insert%s\n");
+ p(PFSYNC_STAT_OPACKETS,
+ "\t%" PRIu64 " packet%s sent (IPv4)\n");
+ p(PFSYNC_STAT_OPACKETS6,
+ "\t%" PRIu64 " packet%s sent (IPv6)\n");
+ p2(PFSYNC_STAT_ONOMEM,
+ "\t\t%" PRIu64 " send failed due to mbuf memory error\n");
+ p2(PFSYNC_STAT_OERRORS,
+ "\t\t%" PRIu64 " send error\n");
#undef p
#undef p2
}
Index: src/usr.bin/netstat/route.c
diff -u src/usr.bin/netstat/route.c:1.85 src/usr.bin/netstat/route.c:1.85.8.1
--- src/usr.bin/netstat/route.c:1.85 Mon Apr 4 07:37:08 2016
+++ src/usr.bin/netstat/route.c Mon Sep 12 14:29:19 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: route.c,v 1.85 2016/04/04 07:37:08 ozaki-r Exp $ */
+/* $NetBSD: route.c,v 1.85.8.1 2022/09/12 14:29:19 martin Exp $ */
/*
* Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "from: @(#)route.c 8.3 (Berkeley) 3/9/94";
#else
-__RCSID("$NetBSD: route.c,v 1.85 2016/04/04 07:37:08 ozaki-r Exp $");
+__RCSID("$NetBSD: route.c,v 1.85.8.1 2022/09/12 14:29:19 martin Exp $");
#endif
#endif /* not lint */
@@ -101,7 +101,7 @@ void
routepr(u_long rtree)
{
struct radix_node_head *rnh, head;
- struct radix_node_head *rt_nodes[AF_MAX+1];
+ struct radix_node_head *rt_nodes[AF_MAX + 1];
int i;
printf("Routing tables\n");
@@ -159,8 +159,9 @@ again:
if (Aflag)
p_rtnode();
} else {
- p_sockaddr(kgetsa((const struct sockaddr *)rnode.rn_key),
- NULL, 0, 44, nflag);
+ p_sockaddr(
+ kgetsa((const struct sockaddr *)rnode.rn_key),
+ NULL, 0, 44, nflag);
putchar('\n');
}
if ((rn = rnode.rn_dupedkey) != NULL)
@@ -185,8 +186,9 @@ p_rtnode(void)
if (rnode.rn_b < 0) {
if (rnode.rn_mask) {
printf("\t mask ");
- p_sockaddr(kgetsa((const struct sockaddr *)rnode.rn_mask),
- NULL, 0, -1, nflag);
+ p_sockaddr(
+ kgetsa((const struct sockaddr *)rnode.rn_mask),
+ NULL, 0, -1, nflag);
} else if (rm == 0)
return;
} else {
@@ -204,10 +206,11 @@ p_rtnode(void)
printf(" <normal>, ");
kget(rmask.rm_leaf, rnode_aux);
p_sockaddr(kgetsa((const struct sockaddr *)rnode_aux.rn_mask),
- NULL, 0, -1, nflag);
- } else
- p_sockaddr(kgetsa((const struct sockaddr *)rmask.rm_mask),
NULL, 0, -1, nflag);
+ } else
+ p_sockaddr(
+ kgetsa((const struct sockaddr *)rmask.rm_mask),
+ NULL, 0, -1, nflag);
putchar('}');
if ((rm = rmask.rm_mklist) != NULL)
printf(" ->");
@@ -250,11 +253,12 @@ p_krtentry(struct rtentry *rt)
else
mask = sockcopy(NULL, &mask_un);
p_addr(addr, mask, rt->rt_flags, nflag);
- p_gwaddr(kgetsa(rt->rt_gateway), kgetsa(rt->rt_gateway)->sa_family, nflag);
+ p_gwaddr(kgetsa(rt->rt_gateway), kgetsa(rt->rt_gateway)->sa_family,
+ nflag);
p_flags(rt->rt_flags);
printf("%6d %8"PRIu64" ", rt->rt_refcnt, rt->rt_use);
if (rt->rt_rmx.rmx_mtu)
- printf("%6"PRIu64, rt->rt_rmx.rmx_mtu);
+ printf("%6"PRIu64, rt->rt_rmx.rmx_mtu);
else
printf("%6s", "-");
putchar((rt->rt_rmx.rmx_locks & RTV_MTU) ? 'L' : ' ');
@@ -270,8 +274,7 @@ p_krtentry(struct rtentry *rt)
printf("%7s", tagstr);
else
printf("%s", tagstr);
- }
- else
+ } else
printf("%7s", "-");
} else
#endif
@@ -306,7 +309,7 @@ rt_stats(u_long off)
if (sysctlbyname("net.route.stats", &rtstats, &rtsize,
NULL, 0) == -1)
err(1, "rt_stats: sysctl");
- } else if (off == 0) {
+ } else if (off == 0) {
printf("rtstat: symbol not in namelist\n");
return;
} else
@@ -314,18 +317,18 @@ rt_stats(u_long off)
printf("routing:\n");
printf("\t%llu bad routing redirect%s\n",
- (unsigned long long)rtstats.rts_badredirect,
- plural(rtstats.rts_badredirect));
+ (unsigned long long)rtstats.rts_badredirect,
+ plural(rtstats.rts_badredirect));
printf("\t%llu dynamically created route%s\n",
- (unsigned long long)rtstats.rts_dynamic,
- plural(rtstats.rts_dynamic));
+ (unsigned long long)rtstats.rts_dynamic,
+ plural(rtstats.rts_dynamic));
printf("\t%llu new gateway%s due to redirects\n",
- (unsigned long long)rtstats.rts_newgateway,
- plural(rtstats.rts_newgateway));
+ (unsigned long long)rtstats.rts_newgateway,
+ plural(rtstats.rts_newgateway));
printf("\t%llu destination%s found unreachable\n",
- (unsigned long long)rtstats.rts_unreach,
- plural(rtstats.rts_unreach));
+ (unsigned long long)rtstats.rts_unreach,
+ plural(rtstats.rts_unreach));
printf("\t%llu use%s of a wildcard route\n",
- (unsigned long long)rtstats.rts_wildcard,
- plural(rtstats.rts_wildcard));
+ (unsigned long long)rtstats.rts_wildcard,
+ plural(rtstats.rts_wildcard));
}
Index: src/usr.bin/netstat/unix.c
diff -u src/usr.bin/netstat/unix.c:1.35 src/usr.bin/netstat/unix.c:1.35.6.1
--- src/usr.bin/netstat/unix.c:1.35 Fri Jan 13 04:22:51 2017
+++ src/usr.bin/netstat/unix.c Mon Sep 12 14:29:19 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: unix.c,v 1.35 2017/01/13 04:22:51 christos Exp $ */
+/* $NetBSD: unix.c,v 1.35.6.1 2022/09/12 14:29:19 martin Exp $ */
/*-
* Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "from: @(#)unix.c 8.1 (Berkeley) 6/6/93";
#else
-__RCSID("$NetBSD: unix.c,v 1.35 2017/01/13 04:22:51 christos Exp $");
+__RCSID("$NetBSD: unix.c,v 1.35.6.1 2022/09/12 14:29:19 martin Exp $");
#endif
#endif /* not lint */
@@ -79,8 +79,8 @@ unixdomainprhdr(void)
{
printf("Active UNIX domain sockets\n");
printf("%-8.8s %-6.6s %-6.6s %-6.6s %8.8s %8.8s %8.8s %8.8s Addr\n",
- "Address", "Type", "Recv-Q", "Send-Q", "Inode", "Conn", "Refs",
- "Nextref");
+ "Address", "Type", "Recv-Q", "Send-Q", "Inode", "Conn", "Refs",
+ "Nextref");
}
static const char * const socktype[] =
@@ -92,12 +92,12 @@ unixdomainpr0(u_long so_pcb, u_long so_t
u_long addr, struct sockaddr_un *sun, int remote)
{
printf("%8lx %-6.6s %6ld %6ld %8lx %8lx %8lx %8lx",
- so_pcb, socktype[so_type], rcvq, sndq, inode, conn, refs,
- nextref);
+ so_pcb, socktype[so_type], rcvq, sndq, inode, conn, refs,
+ nextref);
if (addr || remote)
printf((remote ? " -> %.*s" : " %.*s"),
- (int)(sun->sun_len - (sizeof(*sun) - sizeof(sun->sun_path))),
- sun->sun_path);
+ (int)(sun->sun_len - (sizeof(*sun) - sizeof(sun->sun_path))),
+ sun->sun_path);
putchar('\n');
}
@@ -161,8 +161,7 @@ unixpr(u_long off)
for (mibname = mibnames; *mibname; mibname++) {
memset(mib, 0, sizeof(mib));
- if (sysctlnametomib(*mibname, mib,
- &namelen) == -1)
+ if (sysctlnametomib(*mibname, mib, &namelen) == -1)
err(1, "sysctlnametomib: %s", *mibname);
if (prog_sysctl(mib, sizeof(mib) / sizeof(*mib),
@@ -176,7 +175,7 @@ unixpr(u_long off)
mib[6] = sizeof(*pcblist);
mib[7] = size / sizeof(*pcblist);
- if (prog_sysctl(mib, sizeof(mib) / sizeof(*mib),
+ if (prog_sysctl(mib, sizeof(mib) / sizeof(*mib),
pcblist, &size, NULL, 0) == -1)
err(1, "sysctl (copy)");
@@ -197,10 +196,10 @@ unixpr(u_long off)
sun = (struct sockaddr_un *)&ki->ki_src;
}
- unixdomainpr0(ki->ki_pcbaddr, ki->ki_type,
+ unixdomainpr0(ki->ki_pcbaddr, ki->ki_type,
ki->ki_rcvq, ki->ki_sndq,
- ki->ki_vnode, ki->ki_conn,
- ki->ki_refs, ki->ki_nextref,
+ ki->ki_vnode, ki->ki_conn,
+ ki->ki_refs, ki->ki_nextref,
ki->ki_sockaddr, sun, remote);
}
@@ -208,11 +207,11 @@ unixpr(u_long off)
}
} else {
- filebuf = (char *)kvm_getfiles(get_kvmd(), KERN_FILE,
+ filebuf = (char *)kvm_getfiles(get_kvmd(), KERN_FILE,
0, &ns_nfiles);
if (filebuf == 0) {
- printf("file table read error: %s",
- kvm_geterr(get_kvmd()));
+ printf("file table read error: %s",
+ kvm_geterr(get_kvmd()));
return;
}
file = (struct file *)(filebuf + sizeof(fp));
@@ -223,7 +222,8 @@ unixpr(u_long off)
if (kread((u_long)fp->f_data, (char *)so, sizeof (*so)))
continue;
/* kludge */
- if (so->so_proto >= unixsw && so->so_proto <= unixsw + 2)
+ if (so->so_proto >= unixsw &&
+ so->so_proto <= unixsw + 2)
if (so->so_pcb)
unixdomainpr(so, fp->f_data);
}
Index: src/usr.bin/netstat/vtw.c
diff -u src/usr.bin/netstat/vtw.c:1.9 src/usr.bin/netstat/vtw.c:1.9.8.1
--- src/usr.bin/netstat/vtw.c:1.9 Mon Feb 29 18:19:46 2016
+++ src/usr.bin/netstat/vtw.c Mon Sep 12 14:29:19 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: vtw.c,v 1.9 2016/02/29 18:19:46 christos Exp $ */
+/* $NetBSD: vtw.c,v 1.9.8.1 2022/09/12 14:29:19 martin Exp $ */
/*
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
#if 0
static char sccsid[] = "from: @(#)inet.c 8.4 (Berkeley) 4/20/94";
#else
-__RCSID("$NetBSD: vtw.c,v 1.9 2016/02/29 18:19:46 christos Exp $");
+__RCSID("$NetBSD: vtw.c,v 1.9.8.1 2022/09/12 14:29:19 martin Exp $");
#endif
#endif /* not lint */
@@ -116,11 +116,28 @@ __RCSID("$NetBSD: vtw.c,v 1.9 2016/02/29
#include "vtw.h"
#include "prog_ops.h"
+static bool vtw_enabled(void);
static void snarf(const void *, void *, size_t);
static void *lookup(const char *);
static void process_vtw(const vtw_ctl_t *, void (*)(const vtw_t *));
-static void
+static bool
+vtw_enabled(void)
+{
+
+ if (use_sysctl) {
+ int enabled;
+ size_t size = sizeof(enabled);
+
+ if (sysctlbyname("net.inet.tcp.vtw.enable",
+ &enabled, &size, NULL, 0) == -1)
+ return true;
+ return enabled ? true : false;
+ } else
+ return true;
+}
+
+static void
snarf(const void *addr, void *buf, size_t len)
{
size_t cc;
@@ -173,6 +190,11 @@ timebase(struct timeval *tv)
void *p;
struct bintime timebasebin;
+ if (!vtw_enabled()) {
+ memset(tv, 0, sizeof(*tv));
+ return;
+ }
+
p = lookup("timebasebin");
if (!p)
return;
@@ -180,7 +202,7 @@ timebase(struct timeval *tv)
bintime2timeval(&timebasebin, tv);
}
-static void
+static void
process_vtw(const vtw_ctl_t * ctl, void (*print)(const vtw_t *))
{
vtw_t *vp;
@@ -210,6 +232,9 @@ show_vtw_stats(void)
if (!Vflag)
return;
+ if (!vtw_enabled())
+ return;
+
if ((p = lookup("vtw_stats")) == NULL)
return;
snarf(p, &stats, sizeof(stats));
@@ -237,7 +262,7 @@ show_vtw_stats(void)
printf("\t\t%" PRIu64 " max_loss\n", stats.max_loss[1]);
}
-void
+void
show_vtw_v4(void (*print)(const vtw_t *))
{
fatp_t *base, *lim;
@@ -249,6 +274,9 @@ show_vtw_v4(void (*print)(const vtw_t *)
int mem = 0;
void *p;
+ if (!vtw_enabled())
+ return;
+
if ((p = lookup("fat_tcpv4")) == NULL)
return;
snarf(p, &fat_tcpv4, sizeof(fat_tcpv4));
@@ -280,9 +308,8 @@ show_vtw_v4(void (*print)(const vtw_t *)
snarf(kbase, ubase, n * sizeof(*ubase));
mem += n * sizeof(*ubase);
- } else {
+ } else
ubase = vtw_tcpv4[0].base.v4;
- }
delta = ubase - kbase;
@@ -332,14 +359,14 @@ end:
#if 0
if (Vflag && vflag) {
- printf("total memory for VTW in current config: %d bytes %f MB\n"
- ,mem
- ,mem / (1024.0 * 1024));
+ printf("total memory for VTW in current config: "
+ "%d bytes %f MB\n",
+ mem, mem / (1024.0 * 1024));
}
#endif
}
-void
+void
show_vtw_v6(void (*print)(const vtw_t *))
{
fatp_t *base, *lim;
@@ -351,6 +378,9 @@ show_vtw_v6(void (*print)(const vtw_t *)
int mem = 0;
void *p;
+ if (!vtw_enabled())
+ return;
+
if ((p = lookup("fat_tcpv6")) == NULL)
return;
snarf(p, &fat_tcpv6, sizeof(fat_tcpv6));
@@ -381,9 +411,8 @@ show_vtw_v6(void (*print)(const vtw_t *)
snarf(kbase, ubase, n * sizeof(*ubase));
mem += n * sizeof(*ubase);
- } else {
+ } else
ubase = vtw_tcpv6[0].base.v6;
- }
delta = ubase - kbase;
@@ -431,9 +460,9 @@ end:
process_vtw(&vtw_tcpv6[0], print);
#if 0
if (Vflag && vflag) {
- printf("total memory for VTW in current config: %d bytes %f MB\n"
- ,mem
- ,mem / (1024.0 * 1024));
+ printf("total memory for VTW in current config: "
+ "%d bytes %f MB\n",
+ mem, mem / (1024.0 * 1024));
}
#endif
}