Fri Aug 28 07:23:48 2020 UTC ()
netstat: strengthen against kernel changes

netstat uses sysctlbyname to get counter data from the kernel.
sysctlbyname fails with ENOMEM if actual counter data in the kernel is
larger than a passed buffer.  netstat just skips showing counters of a
category if sysctlbyname fails, so if we added new counters of the
category to the kernel, nestat shows nothing for the category.

Fortunately sysctlbyname fills data as much as possible even if a passed
buffer is short.  So we can allow netstat to show the filled data anyway
if sysctlbyname fails with ENOMEM.

Note that this backcompat mechanism works only if new counters are
appended, and doesn't work if new counters are inserted into the middle
or counters are moved.


(ozaki-r)
diff -r1.18 -r1.19 src/usr.bin/netstat/atalk.c
diff -r1.14 -r1.15 src/usr.bin/netstat/bpf.c
diff -r1.112 -r1.113 src/usr.bin/netstat/inet.c
diff -r1.76 -r1.77 src/usr.bin/netstat/inet6.c
diff -r1.2 -r1.3 src/usr.bin/netstat/pfkey.c
diff -r1.2 -r1.3 src/usr.bin/netstat/pfsync.c

cvs diff -r1.18 -r1.19 src/usr.bin/netstat/atalk.c (expand / switch to unified diff)

--- src/usr.bin/netstat/atalk.c 2020/04/23 00:23:31 1.18
+++ src/usr.bin/netstat/atalk.c 2020/08/28 07:23:48 1.19
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: atalk.c,v 1.18 2020/04/23 00:23:31 joerg Exp $ */ 1/* $NetBSD: atalk.c,v 1.19 2020/08/28 07:23:48 ozaki-r Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1983, 1988, 1993 4 * Copyright (c) 1983, 1988, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -24,27 +24,27 @@ @@ -24,27 +24,27 @@
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33#ifndef lint 33#ifndef lint
34#if 0 34#if 0
35static char sccsid[] = "from @(#)atalk.c 1.1 (Whistle) 6/6/96"; 35static char sccsid[] = "from @(#)atalk.c 1.1 (Whistle) 6/6/96";
36#else 36#else
37__RCSID("$NetBSD: atalk.c,v 1.18 2020/04/23 00:23:31 joerg Exp $"); 37__RCSID("$NetBSD: atalk.c,v 1.19 2020/08/28 07:23:48 ozaki-r Exp $");
38#endif 38#endif
39#endif /* not lint */ 39#endif /* not lint */
40 40
41#include <sys/param.h> 41#include <sys/param.h>
42#include <sys/queue.h> 42#include <sys/queue.h>
43#include <sys/socket.h> 43#include <sys/socket.h>
44#include <sys/socketvar.h> 44#include <sys/socketvar.h>
45#include <sys/mbuf.h> 45#include <sys/mbuf.h>
46#include <sys/protosw.h> 46#include <sys/protosw.h>
47#include <sys/sysctl.h> 47#include <sys/sysctl.h>
48 48
49#include <net/route.h> 49#include <net/route.h>
50#include <net/if.h> 50#include <net/if.h>
@@ -281,27 +281,27 @@ atalkprotopr(u_long off, const char *nam @@ -281,27 +281,27 @@ atalkprotopr(u_long off, const char *nam
281 281
282/* 282/*
283 * Dump DDP statistics structure. 283 * Dump DDP statistics structure.
284 */ 284 */
285void 285void
286ddp_stats(u_long off, const char *name) 286ddp_stats(u_long off, const char *name)
287{ 287{
288 uint64_t ddpstat[DDP_NSTATS]; 288 uint64_t ddpstat[DDP_NSTATS];
289 289
290 if (use_sysctl) { 290 if (use_sysctl) {
291 size_t size = sizeof(ddpstat); 291 size_t size = sizeof(ddpstat);
292 292
293 if (prog_sysctlbyname("net.atalk.ddp.stats", ddpstat, &size, 293 if (prog_sysctlbyname("net.atalk.ddp.stats", ddpstat, &size,
294 NULL, 0) == -1) 294 NULL, 0) == -1 && errno != ENOMEM)
295 return; 295 return;
296 } else { 296 } else {
297 warnx("%s stats not available via KVM.", name); 297 warnx("%s stats not available via KVM.", name);
298 return; 298 return;
299 } 299 }
300 300
301 printf("%s:\n", name); 301 printf("%s:\n", name);
302 302
303 ANY(ddpstat[DDP_STAT_SHORT], "packet", " with short headers "); 303 ANY(ddpstat[DDP_STAT_SHORT], "packet", " with short headers ");
304 ANY(ddpstat[DDP_STAT_LONG], "packet", " with long headers "); 304 ANY(ddpstat[DDP_STAT_LONG], "packet", " with long headers ");
305 ANY(ddpstat[DDP_STAT_NOSUM], "packet", " with no checksum "); 305 ANY(ddpstat[DDP_STAT_NOSUM], "packet", " with no checksum ");
306 ANY(ddpstat[DDP_STAT_TOOSHORT], "packet", " too short "); 306 ANY(ddpstat[DDP_STAT_TOOSHORT], "packet", " too short ");
307 ANY(ddpstat[DDP_STAT_BADSUM], "packet", " with bad checksum "); 307 ANY(ddpstat[DDP_STAT_BADSUM], "packet", " with bad checksum ");

cvs diff -r1.14 -r1.15 src/usr.bin/netstat/bpf.c (expand / switch to unified diff)

--- src/usr.bin/netstat/bpf.c 2019/08/18 04:14:40 1.14
+++ src/usr.bin/netstat/bpf.c 2020/08/28 07:23:48 1.15
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: bpf.c,v 1.14 2019/08/18 04:14:40 kamil Exp $ */ 1/* $NetBSD: bpf.c,v 1.15 2020/08/28 07:23:48 ozaki-r Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2005 The NetBSD Foundation, Inc. 4 * Copyright (c) 2005 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Rui Paulo. 8 * by Rui Paulo.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -43,27 +43,28 @@ @@ -43,27 +43,28 @@
43#include <sys/sysctl.h> 43#include <sys/sysctl.h>
44#include <net/bpfdesc.h> 44#include <net/bpfdesc.h>
45#include <net/bpf.h> 45#include <net/bpf.h>
46#include "netstat.h" 46#include "netstat.h"
47#include "prog_ops.h" 47#include "prog_ops.h"
48 48
49void 49void
50bpf_stats(void) 50bpf_stats(void)
51{ 51{
52 struct bpf_stat bpf_s; 52 struct bpf_stat bpf_s;
53 size_t len = sizeof(bpf_s); 53 size_t len = sizeof(bpf_s);
54 54
55 if (use_sysctl) { 55 if (use_sysctl) {
56 if (prog_sysctlbyname("net.bpf.stats", &bpf_s, &len, NULL, 0) == -1) 56 if (prog_sysctlbyname("net.bpf.stats", &bpf_s, &len, NULL, 0) == -1 &&
 57 errno != ENOMEM)
57 err(1, "net.bpf.stats"); 58 err(1, "net.bpf.stats");
58  59
59 printf("bpf:\n"); 60 printf("bpf:\n");
60 printf("\t%" PRIu64 " total packets received\n",  61 printf("\t%" PRIu64 " total packets received\n",
61 bpf_s.bs_recv); 62 bpf_s.bs_recv);
62 printf("\t%" PRIu64 " total packets captured\n",  63 printf("\t%" PRIu64 " total packets captured\n",
63 bpf_s.bs_capt); 64 bpf_s.bs_capt);
64 printf("\t%" PRIu64 " total packets dropped\n",  65 printf("\t%" PRIu64 " total packets dropped\n",
65 bpf_s.bs_drop); 66 bpf_s.bs_drop);
66 } else { 67 } else {
67 warnx("BPF stats not available via KVM."); 68 warnx("BPF stats not available via KVM.");
68 } 69 }
69} 70}

cvs diff -r1.112 -r1.113 src/usr.bin/netstat/inet.c (expand / switch to unified diff)

--- src/usr.bin/netstat/inet.c 2020/08/28 06:34:17 1.112
+++ src/usr.bin/netstat/inet.c 2020/08/28 07:23:48 1.113
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: inet.c,v 1.112 2020/08/28 06:34:17 ozaki-r Exp $ */ 1/* $NetBSD: inet.c,v 1.113 2020/08/28 07:23:48 ozaki-r Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1983, 1988, 1993 4 * Copyright (c) 1983, 1988, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -24,27 +24,27 @@ @@ -24,27 +24,27 @@
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33#ifndef lint 33#ifndef lint
34#if 0 34#if 0
35static char sccsid[] = "from: @(#)inet.c 8.4 (Berkeley) 4/20/94"; 35static char sccsid[] = "from: @(#)inet.c 8.4 (Berkeley) 4/20/94";
36#else 36#else
37__RCSID("$NetBSD: inet.c,v 1.112 2020/08/28 06:34:17 ozaki-r Exp $"); 37__RCSID("$NetBSD: inet.c,v 1.113 2020/08/28 07:23:48 ozaki-r Exp $");
38#endif 38#endif
39#endif /* not lint */ 39#endif /* not lint */
40 40
41#define _CALLOUT_PRIVATE /* for defs in sys/callout.h */ 41#define _CALLOUT_PRIVATE /* for defs in sys/callout.h */
42 42
43#include <sys/param.h> 43#include <sys/param.h>
44#include <sys/queue.h> 44#include <sys/queue.h>
45#include <sys/socket.h> 45#include <sys/socket.h>
46#include <sys/socketvar.h> 46#include <sys/socketvar.h>
47#include <sys/mbuf.h> 47#include <sys/mbuf.h>
48#include <sys/protosw.h> 48#include <sys/protosw.h>
49#include <sys/sysctl.h> 49#include <sys/sysctl.h>
50 50
@@ -394,27 +394,27 @@ protopr(u_long off, const char *name) @@ -394,27 +394,27 @@ protopr(u_long off, const char *name)
394 394
395/* 395/*
396 * Dump TCP statistics structure. 396 * Dump TCP statistics structure.
397 */ 397 */
398void 398void
399tcp_stats(u_long off, const char *name) 399tcp_stats(u_long off, const char *name)
400{ 400{
401 uint64_t tcpstat[TCP_NSTATS]; 401 uint64_t tcpstat[TCP_NSTATS];
402 402
403 if (use_sysctl) { 403 if (use_sysctl) {
404 size_t size = sizeof(tcpstat); 404 size_t size = sizeof(tcpstat);
405 405
406 if (prog_sysctlbyname("net.inet.tcp.stats", tcpstat, &size, 406 if (prog_sysctlbyname("net.inet.tcp.stats", tcpstat, &size,
407 NULL, 0) == -1) 407 NULL, 0) == -1 && errno != ENOMEM)
408 return; 408 return;
409 } else { 409 } else {
410 warnx("%s stats not available via KVM.", name); 410 warnx("%s stats not available via KVM.", name);
411 return; 411 return;
412 } 412 }
413 413
414 printf ("%s:\n", name); 414 printf ("%s:\n", name);
415 415
416#define ps(f, m) if (tcpstat[f] || sflag <= 1) \ 416#define ps(f, m) if (tcpstat[f] || sflag <= 1) \
417 printf(m, tcpstat[f]) 417 printf(m, tcpstat[f])
418#define p(f, m) if (tcpstat[f] || sflag <= 1) \ 418#define p(f, m) if (tcpstat[f] || sflag <= 1) \
419 printf(m, tcpstat[f], plural(tcpstat[f])) 419 printf(m, tcpstat[f], plural(tcpstat[f]))
420#define p2(f1, f2, m) if (tcpstat[f1] || tcpstat[f2] || sflag <= 1) \ 420#define p2(f1, f2, m) if (tcpstat[f1] || tcpstat[f2] || sflag <= 1) \
@@ -521,27 +521,27 @@ tcp_stats(u_long off, const char *name) @@ -521,27 +521,27 @@ tcp_stats(u_long off, const char *name)
521/* 521/*
522 * Dump UDP statistics structure. 522 * Dump UDP statistics structure.
523 */ 523 */
524void 524void
525udp_stats(u_long off, const char *name) 525udp_stats(u_long off, const char *name)
526{ 526{
527 uint64_t udpstat[UDP_NSTATS]; 527 uint64_t udpstat[UDP_NSTATS];
528 u_quad_t delivered; 528 u_quad_t delivered;
529 529
530 if (use_sysctl) { 530 if (use_sysctl) {
531 size_t size = sizeof(udpstat); 531 size_t size = sizeof(udpstat);
532 532
533 if (prog_sysctlbyname("net.inet.udp.stats", udpstat, &size, 533 if (prog_sysctlbyname("net.inet.udp.stats", udpstat, &size,
534 NULL, 0) == -1) 534 NULL, 0) == -1 && errno != ENOMEM)
535 return; 535 return;
536 } else { 536 } else {
537 warnx("%s stats not available via KVM.", name); 537 warnx("%s stats not available via KVM.", name);
538 return; 538 return;
539 } 539 }
540 540
541 printf ("%s:\n", name); 541 printf ("%s:\n", name);
542 542
543#define ps(f, m) if (udpstat[f] || sflag <= 1) \ 543#define ps(f, m) if (udpstat[f] || sflag <= 1) \
544 printf(m, udpstat[f]) 544 printf(m, udpstat[f])
545#define p(f, m) if (udpstat[f] || sflag <= 1) \ 545#define p(f, m) if (udpstat[f] || sflag <= 1) \
546 printf(m, udpstat[f], plural(udpstat[f])) 546 printf(m, udpstat[f], plural(udpstat[f]))
547#define p3(f, m) if (udpstat[f] || sflag <= 1) \ 547#define p3(f, m) if (udpstat[f] || sflag <= 1) \
@@ -574,27 +574,27 @@ udp_stats(u_long off, const char *name) @@ -574,27 +574,27 @@ udp_stats(u_long off, const char *name)
574 574
575/* 575/*
576 * Dump IP statistics structure. 576 * Dump IP statistics structure.
577 */ 577 */
578void 578void
579ip_stats(u_long off, const char *name) 579ip_stats(u_long off, const char *name)
580{ 580{
581 uint64_t ipstat[IP_NSTATS]; 581 uint64_t ipstat[IP_NSTATS];
582 582
583 if (use_sysctl) { 583 if (use_sysctl) {
584 size_t size = sizeof(ipstat); 584 size_t size = sizeof(ipstat);
585 585
586 if (prog_sysctlbyname("net.inet.ip.stats", ipstat, &size, 586 if (prog_sysctlbyname("net.inet.ip.stats", ipstat, &size,
587 NULL, 0) == -1) 587 NULL, 0) == -1 && errno != ENOMEM)
588 return; 588 return;
589 } else { 589 } else {
590 warnx("%s stats not available via KVM.", name); 590 warnx("%s stats not available via KVM.", name);
591 return; 591 return;
592 } 592 }
593 593
594 printf("%s:\n", name); 594 printf("%s:\n", name);
595 595
596#define ps(f, m) if (ipstat[f] || sflag <= 1) \ 596#define ps(f, m) if (ipstat[f] || sflag <= 1) \
597 printf(m, ipstat[f]) 597 printf(m, ipstat[f])
598#define p(f, m) if (ipstat[f] || sflag <= 1) \ 598#define p(f, m) if (ipstat[f] || sflag <= 1) \
599 printf(m, ipstat[f], plural(ipstat[f])) 599 printf(m, ipstat[f], plural(ipstat[f]))
600 600
@@ -647,27 +647,27 @@ ip_stats(u_long off, const char *name) @@ -647,27 +647,27 @@ ip_stats(u_long off, const char *name)
647/* 647/*
648 * Dump ICMP statistics. 648 * Dump ICMP statistics.
649 */ 649 */
650void 650void
651icmp_stats(u_long off, const char *name) 651icmp_stats(u_long off, const char *name)
652{ 652{
653 uint64_t icmpstat[ICMP_NSTATS]; 653 uint64_t icmpstat[ICMP_NSTATS];
654 int i, first; 654 int i, first;
655 655
656 if (use_sysctl) { 656 if (use_sysctl) {
657 size_t size = sizeof(icmpstat); 657 size_t size = sizeof(icmpstat);
658 658
659 if (prog_sysctlbyname("net.inet.icmp.stats", icmpstat, &size, 659 if (prog_sysctlbyname("net.inet.icmp.stats", icmpstat, &size,
660 NULL, 0) == -1) 660 NULL, 0) == -1 && errno != ENOMEM)
661 return; 661 return;
662 } else { 662 } else {
663 warnx("%s stats not available via KVM.", name); 663 warnx("%s stats not available via KVM.", name);
664 return; 664 return;
665 } 665 }
666 666
667 printf("%s:\n", name); 667 printf("%s:\n", name);
668 668
669#define p(f, m) if (icmpstat[f] || sflag <= 1) \ 669#define p(f, m) if (icmpstat[f] || sflag <= 1) \
670 printf(m, icmpstat[f], plural(icmpstat[f])) 670 printf(m, icmpstat[f], plural(icmpstat[f]))
671 671
672 p(ICMP_STAT_ERROR, "\t%" PRIu64 " call%s to icmp_error\n"); 672 p(ICMP_STAT_ERROR, "\t%" PRIu64 " call%s to icmp_error\n");
673 p(ICMP_STAT_OLDICMP, 673 p(ICMP_STAT_OLDICMP,
@@ -703,27 +703,27 @@ icmp_stats(u_long off, const char *name) @@ -703,27 +703,27 @@ icmp_stats(u_long off, const char *name)
703 703
704/* 704/*
705 * Dump IGMP statistics structure. 705 * Dump IGMP statistics structure.
706 */ 706 */
707void 707void
708igmp_stats(u_long off, const char *name) 708igmp_stats(u_long off, const char *name)
709{ 709{
710 uint64_t igmpstat[IGMP_NSTATS]; 710 uint64_t igmpstat[IGMP_NSTATS];
711 711
712 if (use_sysctl) { 712 if (use_sysctl) {
713 size_t size = sizeof(igmpstat); 713 size_t size = sizeof(igmpstat);
714 714
715 if (prog_sysctlbyname("net.inet.igmp.stats", igmpstat, &size, 715 if (prog_sysctlbyname("net.inet.igmp.stats", igmpstat, &size,
716 NULL, 0) == -1) 716 NULL, 0) == -1 && errno != ENOMEM)
717 return; 717 return;
718 } else { 718 } else {
719 warnx("%s stats not available via KVM.", name); 719 warnx("%s stats not available via KVM.", name);
720 return; 720 return;
721 } 721 }
722 722
723 printf("%s:\n", name); 723 printf("%s:\n", name);
724 724
725#define p(f, m) if (igmpstat[f] || sflag <= 1) \ 725#define p(f, m) if (igmpstat[f] || sflag <= 1) \
726 printf(m, igmpstat[f], plural(igmpstat[f])) 726 printf(m, igmpstat[f], plural(igmpstat[f]))
727#define py(f, m) if (igmpstat[f] || sflag <= 1) \ 727#define py(f, m) if (igmpstat[f] || sflag <= 1) \
728 printf(m, igmpstat[f], igmpstat[f] != 1 ? "ies" : "y") 728 printf(m, igmpstat[f], igmpstat[f] != 1 ? "ies" : "y")
729 p(IGMP_STAT_RCV_TOTAL, "\t%" PRIu64 " message%s received\n"); 729 p(IGMP_STAT_RCV_TOTAL, "\t%" PRIu64 " message%s received\n");
@@ -741,27 +741,27 @@ igmp_stats(u_long off, const char *name) @@ -741,27 +741,27 @@ igmp_stats(u_long off, const char *name)
741 741
742/* 742/*
743 * Dump CARP statistics structure. 743 * Dump CARP statistics structure.
744 */ 744 */
745void 745void
746carp_stats(u_long off, const char *name) 746carp_stats(u_long off, const char *name)
747{ 747{
748 uint64_t carpstat[CARP_NSTATS]; 748 uint64_t carpstat[CARP_NSTATS];
749 749
750 if (use_sysctl) { 750 if (use_sysctl) {
751 size_t size = sizeof(carpstat); 751 size_t size = sizeof(carpstat);
752 752
753 if (prog_sysctlbyname("net.inet.carp.stats", carpstat, &size, 753 if (prog_sysctlbyname("net.inet.carp.stats", carpstat, &size,
754 NULL, 0) == -1) 754 NULL, 0) == -1 && errno != ENOMEM)
755 return; 755 return;
756 } else { 756 } else {
757 warnx("%s stats not available via KVM.", name); 757 warnx("%s stats not available via KVM.", name);
758 return; 758 return;
759 } 759 }
760 760
761 printf("%s:\n", name); 761 printf("%s:\n", name);
762 762
763#define p(f, m) if (carpstat[f] || sflag <= 1) \ 763#define p(f, m) if (carpstat[f] || sflag <= 1) \
764 printf(m, carpstat[f], plural(carpstat[f])) 764 printf(m, carpstat[f], plural(carpstat[f]))
765#define p2(f, m) if (carpstat[f] || sflag <= 1) \ 765#define p2(f, m) if (carpstat[f] || sflag <= 1) \
766 printf(m, carpstat[f]) 766 printf(m, carpstat[f])
767 767
@@ -827,27 +827,27 @@ pim_stats(u_long off, const char *name) @@ -827,27 +827,27 @@ pim_stats(u_long off, const char *name)
827 827
828/* 828/*
829 * Dump the ARP statistics structure. 829 * Dump the ARP statistics structure.
830 */ 830 */
831void 831void
832arp_stats(u_long off, const char *name) 832arp_stats(u_long off, const char *name)
833{ 833{
834 uint64_t arpstat[ARP_NSTATS]; 834 uint64_t arpstat[ARP_NSTATS];
835 835
836 if (use_sysctl) { 836 if (use_sysctl) {
837 size_t size = sizeof(arpstat); 837 size_t size = sizeof(arpstat);
838 838
839 if (prog_sysctlbyname("net.inet.arp.stats", arpstat, &size, 839 if (prog_sysctlbyname("net.inet.arp.stats", arpstat, &size,
840 NULL, 0) == -1) 840 NULL, 0) == -1 && errno != ENOMEM)
841 return; 841 return;
842 } else { 842 } else {
843 warnx("%s stats not available via KVM.", name); 843 warnx("%s stats not available via KVM.", name);
844 return; 844 return;
845 } 845 }
846 846
847 printf("%s:\n", name); 847 printf("%s:\n", name);
848 848
849#define ps(f, m) if (arpstat[f] || sflag <= 1) \ 849#define ps(f, m) if (arpstat[f] || sflag <= 1) \
850 printf(m, arpstat[f]) 850 printf(m, arpstat[f])
851#define p(f, m) if (arpstat[f] || sflag <= 1) \ 851#define p(f, m) if (arpstat[f] || sflag <= 1) \
852 printf(m, arpstat[f], plural(arpstat[f])) 852 printf(m, arpstat[f], plural(arpstat[f]))
853 853

cvs diff -r1.76 -r1.77 src/usr.bin/netstat/inet6.c (expand / switch to unified diff)

--- src/usr.bin/netstat/inet6.c 2020/08/28 06:34:17 1.76
+++ src/usr.bin/netstat/inet6.c 2020/08/28 07:23:48 1.77
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: inet6.c,v 1.76 2020/08/28 06:34:17 ozaki-r Exp $ */ 1/* $NetBSD: inet6.c,v 1.77 2020/08/28 07:23:48 ozaki-r Exp $ */
2/* BSDI inet.c,v 2.3 1995/10/24 02:19:29 prb Exp */ 2/* BSDI inet.c,v 2.3 1995/10/24 02:19:29 prb Exp */
3 3
4/* 4/*
5 * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project. 5 * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
6 * All rights reserved. 6 * All rights reserved.
7 *  7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -54,27 +54,27 @@ @@ -54,27 +54,27 @@
54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59 * SUCH DAMAGE. 59 * SUCH DAMAGE.
60 */ 60 */
61 61
62#include <sys/cdefs.h> 62#include <sys/cdefs.h>
63#ifndef lint 63#ifndef lint
64#if 0 64#if 0
65static char sccsid[] = "@(#)inet.c 8.4 (Berkeley) 4/20/94"; 65static char sccsid[] = "@(#)inet.c 8.4 (Berkeley) 4/20/94";
66#else 66#else
67__RCSID("$NetBSD: inet6.c,v 1.76 2020/08/28 06:34:17 ozaki-r Exp $"); 67__RCSID("$NetBSD: inet6.c,v 1.77 2020/08/28 07:23:48 ozaki-r Exp $");
68#endif 68#endif
69#endif /* not lint */ 69#endif /* not lint */
70 70
71#define _CALLOUT_PRIVATE 71#define _CALLOUT_PRIVATE
72 72
73#include <sys/param.h> 73#include <sys/param.h>
74#include <sys/socket.h> 74#include <sys/socket.h>
75#include <sys/socketvar.h> 75#include <sys/socketvar.h>
76#include <sys/ioctl.h> 76#include <sys/ioctl.h>
77#include <sys/mbuf.h> 77#include <sys/mbuf.h>
78#include <sys/protosw.h> 78#include <sys/protosw.h>
79#include <sys/sysctl.h> 79#include <sys/sysctl.h>
80 80
@@ -407,27 +407,27 @@ ip6protopr(u_long off, const char *name) @@ -407,27 +407,27 @@ ip6protopr(u_long off, const char *name)
407#ifdef TCP6 407#ifdef TCP6
408/* 408/*
409 * Dump TCP6 statistics structure. 409 * Dump TCP6 statistics structure.
410 */ 410 */
411void 411void
412tcp6_stats(u_long off, const char *name) 412tcp6_stats(u_long off, const char *name)
413{ 413{
414 struct tcp6stat tcp6stat; 414 struct tcp6stat tcp6stat;
415 415
416 if (use_sysctl) { 416 if (use_sysctl) {
417 size_t size = sizeof(tcp6stat); 417 size_t size = sizeof(tcp6stat);
418 418
419 if (prog_sysctlbyname("net.inet6.tcp6.stats", &tcp6stat, &size, 419 if (prog_sysctlbyname("net.inet6.tcp6.stats", &tcp6stat, &size,
420 NULL, 0) == -1) 420 NULL, 0) == -1 && errno != ENOMEM)
421 return; 421 return;
422 } else { 422 } else {
423 warnx("%s stats not available via KVM.", name); 423 warnx("%s stats not available via KVM.", name);
424 return; 424 return;
425 } 425 }
426 426
427 printf ("%s:\n", name); 427 printf ("%s:\n", name);
428 428
429#define p(f, m) if (tcp6stat.f || sflag <= 1) \ 429#define p(f, m) if (tcp6stat.f || sflag <= 1) \
430 printf(m, tcp6stat.f, plural(tcp6stat.f)) 430 printf(m, tcp6stat.f, plural(tcp6stat.f))
431#define p2(f1, f2, m) if (tcp6stat.f1 || tcp6stat.f2 || sflag <= 1) \ 431#define p2(f1, f2, m) if (tcp6stat.f1 || tcp6stat.f2 || sflag <= 1) \
432 printf(m, tcp6stat.f1, plural(tcp6stat.f1), tcp6stat.f2, plural(tcp6stat.f2)) 432 printf(m, tcp6stat.f1, plural(tcp6stat.f1), tcp6stat.f2, plural(tcp6stat.f2))
433#define p3(f, m) if (tcp6stat.f || sflag <= 1) \ 433#define p3(f, m) if (tcp6stat.f || sflag <= 1) \
@@ -493,27 +493,27 @@ tcp6_stats(u_long off, const char *name) @@ -493,27 +493,27 @@ tcp6_stats(u_long off, const char *name)
493/* 493/*
494 * Dump UDP6 statistics structure. 494 * Dump UDP6 statistics structure.
495 */ 495 */
496void 496void
497udp6_stats(u_long off, const char *name) 497udp6_stats(u_long off, const char *name)
498{ 498{
499 uint64_t udp6stat[UDP6_NSTATS]; 499 uint64_t udp6stat[UDP6_NSTATS];
500 u_quad_t delivered; 500 u_quad_t delivered;
501 501
502 if (use_sysctl) { 502 if (use_sysctl) {
503 size_t size = sizeof(udp6stat); 503 size_t size = sizeof(udp6stat);
504 504
505 if (prog_sysctlbyname("net.inet6.udp6.stats", udp6stat, &size, 505 if (prog_sysctlbyname("net.inet6.udp6.stats", udp6stat, &size,
506 NULL, 0) == -1) 506 NULL, 0) == -1 && errno != ENOMEM)
507 return; 507 return;
508 } else { 508 } else {
509 warnx("%s stats not available via KVM.", name); 509 warnx("%s stats not available via KVM.", name);
510 return; 510 return;
511 } 511 }
512 printf("%s:\n", name); 512 printf("%s:\n", name);
513#define p(f, m) if (udp6stat[f] || sflag <= 1) \ 513#define p(f, m) if (udp6stat[f] || sflag <= 1) \
514 printf(m, (unsigned long long)udp6stat[f], plural(udp6stat[f])) 514 printf(m, (unsigned long long)udp6stat[f], plural(udp6stat[f]))
515#define p1(f, m) if (udp6stat[f] || sflag <= 1) \ 515#define p1(f, m) if (udp6stat[f] || sflag <= 1) \
516 printf(m, (unsigned long long)udp6stat[f]) 516 printf(m, (unsigned long long)udp6stat[f])
517 p(UDP6_STAT_IPACKETS, "\t%llu datagram%s received\n"); 517 p(UDP6_STAT_IPACKETS, "\t%llu datagram%s received\n");
518 p1(UDP6_STAT_HDROPS, "\t%llu with incomplete header\n"); 518 p1(UDP6_STAT_HDROPS, "\t%llu with incomplete header\n");
519 p1(UDP6_STAT_BADLEN, "\t%llu with bad data length field\n"); 519 p1(UDP6_STAT_BADLEN, "\t%llu with bad data length field\n");
@@ -637,27 +637,27 @@ static const char *ip6nh[] = { @@ -637,27 +637,27 @@ static const char *ip6nh[] = {
637 */ 637 */
638void 638void
639ip6_stats(u_long off, const char *name) 639ip6_stats(u_long off, const char *name)
640{ 640{
641 uint64_t ip6stat[IP6_NSTATS]; 641 uint64_t ip6stat[IP6_NSTATS];
642 int first, i; 642 int first, i;
643 struct protoent *ep; 643 struct protoent *ep;
644 const char *n; 644 const char *n;
645 645
646 if (use_sysctl) { 646 if (use_sysctl) {
647 size_t size = sizeof(ip6stat); 647 size_t size = sizeof(ip6stat);
648 648
649 if (prog_sysctlbyname("net.inet6.ip6.stats", ip6stat, &size, 649 if (prog_sysctlbyname("net.inet6.ip6.stats", ip6stat, &size,
650 NULL, 0) == -1) 650 NULL, 0) == -1 && errno != ENOMEM)
651 return; 651 return;
652 } else { 652 } else {
653 warnx("%s stats not available via KVM.", name); 653 warnx("%s stats not available via KVM.", name);
654 return; 654 return;
655 } 655 }
656 printf("%s:\n", name); 656 printf("%s:\n", name);
657 657
658#define p(f, m) if (ip6stat[f] || sflag <= 1) \ 658#define p(f, m) if (ip6stat[f] || sflag <= 1) \
659 printf(m, (unsigned long long)ip6stat[f], plural(ip6stat[f])) 659 printf(m, (unsigned long long)ip6stat[f], plural(ip6stat[f]))
660#define p1(f, m) if (ip6stat[f] || sflag <= 1) \ 660#define p1(f, m) if (ip6stat[f] || sflag <= 1) \
661 printf(m, (unsigned long long)ip6stat[f]) 661 printf(m, (unsigned long long)ip6stat[f])
662 662
663 p(IP6_STAT_TOTAL, "\t%llu total packet%s received\n"); 663 p(IP6_STAT_TOTAL, "\t%llu total packet%s received\n");
@@ -1131,27 +1131,27 @@ static const char *icmp6names[256] = { @@ -1131,27 +1131,27 @@ static const char *icmp6names[256] = {
1131/* 1131/*
1132 * Dump ICMPv6 statistics. 1132 * Dump ICMPv6 statistics.
1133 */ 1133 */
1134void 1134void
1135icmp6_stats(u_long off, const char *name) 1135icmp6_stats(u_long off, const char *name)
1136{ 1136{
1137 uint64_t icmp6stat[ICMP6_NSTATS]; 1137 uint64_t icmp6stat[ICMP6_NSTATS];
1138 int i, first; 1138 int i, first;
1139 1139
1140 if (use_sysctl) { 1140 if (use_sysctl) {
1141 size_t size = sizeof(icmp6stat); 1141 size_t size = sizeof(icmp6stat);
1142 1142
1143 if (prog_sysctlbyname("net.inet6.icmp6.stats", icmp6stat, &size, 1143 if (prog_sysctlbyname("net.inet6.icmp6.stats", icmp6stat, &size,
1144 NULL, 0) == -1) 1144 NULL, 0) == -1 && errno != ENOMEM)
1145 return; 1145 return;
1146 } else { 1146 } else {
1147 warnx("%s stats not available via KVM.", name); 1147 warnx("%s stats not available via KVM.", name);
1148 return; 1148 return;
1149 } 1149 }
1150  1150
1151 printf("%s:\n", name); 1151 printf("%s:\n", name);
1152 1152
1153#define p(f, m) if (icmp6stat[f] || sflag <= 1) \ 1153#define p(f, m) if (icmp6stat[f] || sflag <= 1) \
1154 printf(m, (unsigned long long)icmp6stat[f], plural(icmp6stat[f])) 1154 printf(m, (unsigned long long)icmp6stat[f], plural(icmp6stat[f]))
1155#define p_oerr(f, m) if (icmp6stat[ICMP6_STAT_OUTERRHIST + f] || sflag <= 1) \ 1155#define p_oerr(f, m) if (icmp6stat[ICMP6_STAT_OUTERRHIST + f] || sflag <= 1) \
1156 printf(m, (unsigned long long)icmp6stat[ICMP6_STAT_OUTERRHIST + f]) 1156 printf(m, (unsigned long long)icmp6stat[ICMP6_STAT_OUTERRHIST + f])
1157 1157
@@ -1279,27 +1279,27 @@ icmp6_ifstats(const char *ifname) @@ -1279,27 +1279,27 @@ icmp6_ifstats(const char *ifname)
1279 1279
1280/* 1280/*
1281 * Dump PIM statistics structure. 1281 * Dump PIM statistics structure.
1282 */ 1282 */
1283void 1283void
1284pim6_stats(u_long off, const char *name) 1284pim6_stats(u_long off, const char *name)
1285{ 1285{
1286 uint64_t pim6stat[PIM6_NSTATS]; 1286 uint64_t pim6stat[PIM6_NSTATS];
1287 1287
1288 if (use_sysctl) { 1288 if (use_sysctl) {
1289 size_t size = sizeof(pim6stat); 1289 size_t size = sizeof(pim6stat);
1290 1290
1291 if (prog_sysctlbyname("net.inet6.pim6.stats", pim6stat, &size, 1291 if (prog_sysctlbyname("net.inet6.pim6.stats", pim6stat, &size,
1292 NULL, 0) == -1) 1292 NULL, 0) == -1 && errno != ENOMEM)
1293 return; 1293 return;
1294 } else { 1294 } else {
1295 warnx("%s stats not available via KVM.", name); 1295 warnx("%s stats not available via KVM.", name);
1296 return; 1296 return;
1297 } 1297 }
1298 printf("%s:\n", name); 1298 printf("%s:\n", name);
1299 1299
1300#define p(f, m) if (pim6stat[f] || sflag <= 1) \ 1300#define p(f, m) if (pim6stat[f] || sflag <= 1) \
1301 printf(m, (unsigned long long)pim6stat[f], plural(pim6stat[f])) 1301 printf(m, (unsigned long long)pim6stat[f], plural(pim6stat[f]))
1302 p(PIM6_STAT_RCV_TOTAL, "\t%llu message%s received\n"); 1302 p(PIM6_STAT_RCV_TOTAL, "\t%llu message%s received\n");
1303 p(PIM6_STAT_RCV_TOOSHORT, "\t%llu message%s received with too few bytes\n"); 1303 p(PIM6_STAT_RCV_TOOSHORT, "\t%llu message%s received with too few bytes\n");
1304 p(PIM6_STAT_RCV_BADSUM, "\t%llu message%s received with bad checksum\n"); 1304 p(PIM6_STAT_RCV_BADSUM, "\t%llu message%s received with bad checksum\n");
1305 p(PIM6_STAT_RCV_BADVERSION, "\t%llu message%s received with bad version\n"); 1305 p(PIM6_STAT_RCV_BADVERSION, "\t%llu message%s received with bad version\n");
@@ -1312,27 +1312,27 @@ pim6_stats(u_long off, const char *name) @@ -1312,27 +1312,27 @@ pim6_stats(u_long off, const char *name)
1312/* 1312/*
1313 * Dump raw ip6 statistics structure. 1313 * Dump raw ip6 statistics structure.
1314 */ 1314 */
1315void 1315void
1316rip6_stats(u_long off, const char *name) 1316rip6_stats(u_long off, const char *name)
1317{ 1317{
1318 uint64_t rip6stat[RIP6_NSTATS]; 1318 uint64_t rip6stat[RIP6_NSTATS];
1319 u_quad_t delivered; 1319 u_quad_t delivered;
1320 1320
1321 if (use_sysctl) { 1321 if (use_sysctl) {
1322 size_t size = sizeof(rip6stat); 1322 size_t size = sizeof(rip6stat);
1323 1323
1324 if (prog_sysctlbyname("net.inet6.raw6.stats", rip6stat, &size, 1324 if (prog_sysctlbyname("net.inet6.raw6.stats", rip6stat, &size,
1325 NULL, 0) == -1) 1325 NULL, 0) == -1 && errno != ENOMEM)
1326 return; 1326 return;
1327 } else { 1327 } else {
1328 warnx("%s stats not available via KVM.", name); 1328 warnx("%s stats not available via KVM.", name);
1329 return; 1329 return;
1330 } 1330 }
1331 printf("%s:\n", name); 1331 printf("%s:\n", name);
1332 1332
1333#define p(f, m) if (rip6stat[f] || sflag <= 1) \ 1333#define p(f, m) if (rip6stat[f] || sflag <= 1) \
1334 printf(m, (unsigned long long)rip6stat[f], plural(rip6stat[f])) 1334 printf(m, (unsigned long long)rip6stat[f], plural(rip6stat[f]))
1335 p(RIP6_STAT_IPACKETS, "\t%llu message%s received\n"); 1335 p(RIP6_STAT_IPACKETS, "\t%llu message%s received\n");
1336 p(RIP6_STAT_ISUM, "\t%llu checksum calculation%s on inbound\n"); 1336 p(RIP6_STAT_ISUM, "\t%llu checksum calculation%s on inbound\n");
1337 p(RIP6_STAT_BADSUM, "\t%llu message%s with bad checksum\n"); 1337 p(RIP6_STAT_BADSUM, "\t%llu message%s with bad checksum\n");
1338 p(RIP6_STAT_NOSOCK, "\t%llu message%s dropped due to no socket\n"); 1338 p(RIP6_STAT_NOSOCK, "\t%llu message%s dropped due to no socket\n");

cvs diff -r1.2 -r1.3 src/usr.bin/netstat/pfkey.c (expand / switch to unified diff)

--- src/usr.bin/netstat/pfkey.c 2019/08/18 04:14:40 1.2
+++ src/usr.bin/netstat/pfkey.c 2020/08/28 07:23:48 1.3
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: pfkey.c,v 1.2 2019/08/18 04:14:40 kamil Exp $ */ 1/* $NetBSD: pfkey.c,v 1.3 2020/08/28 07:23:48 ozaki-r Exp $ */
2/* $KAME: ipsec.c,v 1.33 2003/07/25 09:54:32 itojun Exp $ */ 2/* $KAME: ipsec.c,v 1.33 2003/07/25 09:54:32 itojun Exp $ */
3 3
4/* 4/*
5 * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project. 5 * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
6 * All rights reserved. 6 * All rights reserved.
7 *  7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -55,41 +55,42 @@ @@ -55,41 +55,42 @@
55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59 * SUCH DAMAGE. 59 * SUCH DAMAGE.
60 */ 60 */
61 61
62#include <sys/cdefs.h> 62#include <sys/cdefs.h>
63#ifndef lint 63#ifndef lint
64#if 0 64#if 0
65static char sccsid[] = "from: @(#)inet.c 8.4 (Berkeley) 4/20/94"; 65static char sccsid[] = "from: @(#)inet.c 8.4 (Berkeley) 4/20/94";
66#else 66#else
67#ifdef __NetBSD__ 67#ifdef __NetBSD__
68__RCSID("$NetBSD: pfkey.c,v 1.2 2019/08/18 04:14:40 kamil Exp $"); 68__RCSID("$NetBSD: pfkey.c,v 1.3 2020/08/28 07:23:48 ozaki-r Exp $");
69#endif 69#endif
70#endif 70#endif
71#endif /* not lint */ 71#endif /* not lint */
72 72
73#include <sys/param.h> 73#include <sys/param.h>
74#include <sys/queue.h> 74#include <sys/queue.h>
75#include <sys/socket.h> 75#include <sys/socket.h>
76#include <sys/sysctl.h> 76#include <sys/sysctl.h>
77 77
78#ifdef IPSEC 78#ifdef IPSEC
79#include <netipsec/keysock.h> 79#include <netipsec/keysock.h>
80#endif 80#endif
81 81
82#include <err.h> 82#include <err.h>
 83#include <errno.h>
83#include <stdio.h> 84#include <stdio.h>
84#include <string.h> 85#include <string.h>
85#include <unistd.h> 86#include <unistd.h>
86#include "netstat.h" 87#include "netstat.h"
87#include "prog_ops.h" 88#include "prog_ops.h"
88 89
89#ifdef IPSEC  90#ifdef IPSEC
90 91
91static const char *pfkey_msgtypenames[] = { 92static const char *pfkey_msgtypenames[] = {
92 "reserved", "getspi", "update", "add", "delete", 93 "reserved", "getspi", "update", "add", "delete",
93 "get", "acquire", "register", "expire", "flush", 94 "get", "acquire", "register", "expire", "flush",
94 "dump", "x_promisc", "x_pchange", "x_spdupdate", "x_spdadd", 95 "dump", "x_promisc", "x_pchange", "x_spdupdate", "x_spdadd",
95 "x_spddelete", "x_spdget", "x_spdacquire", "x_spddump", "x_spdflush", 96 "x_spddelete", "x_spdget", "x_spdacquire", "x_spddump", "x_spdflush",
@@ -111,27 +112,27 @@ pfkey_msgtype_names(int x) @@ -111,27 +112,27 @@ pfkey_msgtype_names(int x)
111 return buf; 112 return buf;
112} 113}
113 114
114void 115void
115pfkey_stats(u_long off, const char *name) 116pfkey_stats(u_long off, const char *name)
116{ 117{
117 uint64_t pfkeystat[PFKEY_NSTATS]; 118 uint64_t pfkeystat[PFKEY_NSTATS];
118 int first, type; 119 int first, type;
119 120
120 if (use_sysctl) { 121 if (use_sysctl) {
121 size_t size = sizeof(pfkeystat); 122 size_t size = sizeof(pfkeystat);
122 123
123 if (prog_sysctlbyname("net.key.stats", pfkeystat, &size, 124 if (prog_sysctlbyname("net.key.stats", pfkeystat, &size,
124 NULL, 0) == -1) 125 NULL, 0) == -1 && errno != ENOMEM)
125 return; 126 return;
126 } else { 127 } else {
127 warnx("%s stats not available via KVM.", name); 128 warnx("%s stats not available via KVM.", name);
128 return; 129 return;
129 } 130 }
130 131
131 printf ("%s:\n", name); 132 printf ("%s:\n", name);
132 133
133#define p(f, m) if (pfkeystat[f] || sflag <= 1) \ 134#define p(f, m) if (pfkeystat[f] || sflag <= 1) \
134 printf(m, (unsigned long long)pfkeystat[f], plural(pfkeystat[f])) 135 printf(m, (unsigned long long)pfkeystat[f], plural(pfkeystat[f]))
135 136
136 /* userland -> kernel */ 137 /* userland -> kernel */
137 p(PFKEY_STAT_OUT_TOTAL, "\t%llu request%s sent from userland\n"); 138 p(PFKEY_STAT_OUT_TOTAL, "\t%llu request%s sent from userland\n");

cvs diff -r1.2 -r1.3 src/usr.bin/netstat/pfsync.c (expand / switch to unified diff)

--- src/usr.bin/netstat/pfsync.c 2019/08/18 04:14:40 1.2
+++ src/usr.bin/netstat/pfsync.c 2020/08/28 07:23:48 1.3
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: pfsync.c,v 1.2 2019/08/18 04:14:40 kamil Exp $ */ 1/* $NetBSD: pfsync.c,v 1.3 2020/08/28 07:23:48 ozaki-r Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1983, 1988, 1993 4 * Copyright (c) 1983, 1988, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -21,27 +21,27 @@ @@ -21,27 +21,27 @@
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33#ifndef lint 33#ifndef lint
34__RCSID("$NetBSD: pfsync.c,v 1.2 2019/08/18 04:14:40 kamil Exp $"); 34__RCSID("$NetBSD: pfsync.c,v 1.3 2020/08/28 07:23:48 ozaki-r Exp $");
35#endif /* not lint */ 35#endif /* not lint */
36 36
37#define _CALLOUT_PRIVATE /* for defs in sys/callout.h */ 37#define _CALLOUT_PRIVATE /* for defs in sys/callout.h */
38 38
39#include <sys/param.h> 39#include <sys/param.h>
40#include <sys/queue.h> 40#include <sys/queue.h>
41#include <sys/socket.h> 41#include <sys/socket.h>
42#include <sys/socketvar.h> 42#include <sys/socketvar.h>
43#include <sys/mbuf.h> 43#include <sys/mbuf.h>
44#include <sys/protosw.h> 44#include <sys/protosw.h>
45#include <sys/sysctl.h> 45#include <sys/sysctl.h>
46 46
47#include <net/if_arp.h> 47#include <net/if_arp.h>
@@ -57,42 +57,43 @@ __RCSID("$NetBSD: pfsync.c,v 1.2 2019/08 @@ -57,42 +57,43 @@ __RCSID("$NetBSD: pfsync.c,v 1.2 2019/08
57#endif 57#endif
58 58
59#include <net/pfvar.h> 59#include <net/pfvar.h>
60#include <net/if_pfsync.h> 60#include <net/if_pfsync.h>
61 61
62#include <arpa/inet.h> 62#include <arpa/inet.h>
63#include <kvm.h> 63#include <kvm.h>
64#include <netdb.h> 64#include <netdb.h>
65#include <stdio.h> 65#include <stdio.h>
66#include <string.h> 66#include <string.h>
67#include <unistd.h> 67#include <unistd.h>
68#include <stdlib.h> 68#include <stdlib.h>
69#include <err.h> 69#include <err.h>
 70#include <errno.h>
70#include "netstat.h" 71#include "netstat.h"
71#include "prog_ops.h" 72#include "prog_ops.h"
72 73
73/* 74/*
74 * Dump PFSYNC statistics structure. 75 * Dump PFSYNC statistics structure.
75 */ 76 */
76void 77void
77pfsync_stats(u_long off, const char *name) 78pfsync_stats(u_long off, const char *name)
78{ 79{
79 uint64_t pfsyncstat[PFSYNC_NSTATS]; 80 uint64_t pfsyncstat[PFSYNC_NSTATS];
80 81
81 if (use_sysctl) { 82 if (use_sysctl) {
82 size_t size = sizeof(pfsyncstat); 83 size_t size = sizeof(pfsyncstat);
83 84
84 if (prog_sysctlbyname("net.inet.pfsync.stats", pfsyncstat, &size, 85 if (prog_sysctlbyname("net.inet.pfsync.stats", pfsyncstat, &size,
85 NULL, 0) == -1) 86 NULL, 0) == -1 && errno != ENOMEM)
86 return; 87 return;
87 } else { 88 } else {
88 warnx("%s stats not available via KVM.", name); 89 warnx("%s stats not available via KVM.", name);
89 return; 90 return;
90 } 91 }
91 92
92 printf("%s:\n", name); 93 printf("%s:\n", name);
93 94
94#define p(f, m) if (pfsyncstat[f] || sflag <= 1) \ 95#define p(f, m) if (pfsyncstat[f] || sflag <= 1) \
95 printf(m, pfsyncstat[f], plural(pfsyncstat[f])) 96 printf(m, pfsyncstat[f], plural(pfsyncstat[f]))
96#define p2(f, m) if (pfsyncstat[f] || sflag <= 1) \ 97#define p2(f, m) if (pfsyncstat[f] || sflag <= 1) \
97 printf(m, pfsyncstat[f]) 98 printf(m, pfsyncstat[f])
98 99