Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/netstat Don't show any of the completely and utterly...



details:   https://anonhg.NetBSD.org/src/rev/60c195009500
branches:  trunk
changeset: 953242:60c195009500
user:      simonb <simonb%NetBSD.org@localhost>
date:      Tue Mar 02 01:02:12 2021 +0000

description:
Don't show any of the completely and utterly undocumented VTW info if
the feature isn't enabled (by checking net.inet.tcp.vtw.enable).

diffstat:

 usr.bin/netstat/vtw.c |  36 ++++++++++++++++++++++++++++++++++--
 1 files changed, 34 insertions(+), 2 deletions(-)

diffs (89 lines):

diff -r 30ad15f85965 -r 60c195009500 usr.bin/netstat/vtw.c
--- a/usr.bin/netstat/vtw.c     Tue Mar 02 00:28:55 2021 +0000
+++ b/usr.bin/netstat/vtw.c     Tue Mar 02 01:02:12 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vtw.c,v 1.10 2018/05/03 07:13:48 maxv Exp $    */
+/*     $NetBSD: vtw.c,v 1.11 2021/03/02 01:02:12 simonb 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.10 2018/05/03 07:13:48 maxv Exp $");
+__RCSID("$NetBSD: vtw.c,v 1.11 2021/03/02 01:02:12 simonb Exp $");
 #endif
 #endif /* not lint */
 
@@ -115,10 +115,28 @@
 #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 bool
+vtw_enabled(void)
+{
+
+       if (use_sysctl) {
+               int enabled;
+               size_t size = sizeof(enabled);
+
+               if (prog_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)
 {
@@ -172,6 +190,11 @@
        void *p;
        struct bintime timebasebin;
 
+       if (!vtw_enabled()) {
+               memset(tv, 0, sizeof(*tv));
+               return;
+       }
+
        p = lookup("timebasebin");
        if (!p)
                return;
@@ -209,6 +232,9 @@
        if (!Vflag)
                return;
 
+       if (!vtw_enabled())
+               return;
+
        if ((p = lookup("vtw_stats")) == NULL)
                return;
        snarf(p, &stats, sizeof(stats));
@@ -248,6 +274,9 @@
        int mem = 0;
        void *p;
 
+       if (!vtw_enabled())
+               return;
+
        if ((p = lookup("fat_tcpv4")) == NULL)
                return;
        snarf(p, &fat_tcpv4, sizeof(fat_tcpv4));
@@ -350,6 +379,9 @@
        int mem = 0;
        void *p;
 
+       if (!vtw_enabled())
+               return;
+
        if ((p = lookup("fat_tcpv6")) == NULL)
                return;
        snarf(p, &fat_tcpv6, sizeof(fat_tcpv6));



Home | Main Index | Thread Index | Old Index