Source-Changes-HG archive

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

[src/netbsd-8]: src/usr.bin/netstat Pull up the following, requested by msait...



details:   https://anonhg.NetBSD.org/src/rev/44d293296e87
branches:  netbsd-8
changeset: 370020:44d293296e87
user:      martin <martin%NetBSD.org@localhost>
date:      Mon Sep 12 14:29:19 2022 +0000

description:
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.

diffstat:

 usr.bin/netstat/atalk.c      |   48 ++--
 usr.bin/netstat/bpf.c        |   39 ++--
 usr.bin/netstat/fast_ipsec.c |  214 +++++++++++++-----------
 usr.bin/netstat/if.c         |  173 ++++++++++++-------
 usr.bin/netstat/inet.c       |  339 +++++++++++++++++++++++----------------
 usr.bin/netstat/inet6.c      |  363 +++++++++++++++++++++++-------------------
 usr.bin/netstat/main.c       |   80 ++++++--
 usr.bin/netstat/mbuf.c       |   24 +-
 usr.bin/netstat/mroute.c     |   57 +++---
 usr.bin/netstat/mroute6.c    |   16 +-
 usr.bin/netstat/netstat.1    |    9 +-
 usr.bin/netstat/netstat.h    |   56 +++---
 usr.bin/netstat/pfkey.c      |   42 +++-
 usr.bin/netstat/pfsync.c     |   48 +++--
 usr.bin/netstat/route.c      |   53 +++--
 usr.bin/netstat/unix.c       |   36 ++--
 usr.bin/netstat/vtw.c        |   61 +++++-
 17 files changed, 957 insertions(+), 701 deletions(-)

diffs (truncated from 3704 to 300 lines):

diff -r 8c3de0e0a16b -r 44d293296e87 usr.bin/netstat/atalk.c
--- a/usr.bin/netstat/atalk.c   Sat Sep 10 08:22:38 2022 +0000
+++ b/usr.bin/netstat/atalk.c   Mon Sep 12 14:29:19 2022 +0000
@@ -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 @@
 #include <string.h>
 #include "netstat.h"
 
-struct ddpcb    ddpcb;
-struct socket   sockb;
-
 static int first = 1;
 
 /*
@@ -84,11 +81,12 @@
                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 @@
                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 @@
 
        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 @@
                (void)snprintf(mybuf, sizeof(mybuf), "%d",
                        ntohs(sat->sat_range.r_netrange.nr_firstnet));
        }
-       return (mybuf);
+       return mybuf;
 }
 
 
@@ -182,7 +180,7 @@
                (void)snprintf(mybuf + strlen(mybuf),
                    sizeof(mybuf) - strlen(mybuf), ".%s", at_pr_port(sat));
        }
-       return (mybuf);
+       return mybuf;
 }
 
 const char *
@@ -223,12 +221,14 @@
                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 @@
                        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 @@
                        }
                        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 @@
                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 @@
        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
diff -r 8c3de0e0a16b -r 44d293296e87 usr.bin/netstat/bpf.c
--- a/usr.bin/netstat/bpf.c     Sat Sep 10 08:22:38 2022 +0000
+++ b/usr.bin/netstat/bpf.c     Mon Sep 12 14:29:19 2022 +0000
@@ -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 @@
        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 @@
                u_int   namelen;
                void    *v;
                struct kinfo_proc2 p;
-       
+
                /* adapted from sockstat.c by Andrew Brown */
 
                sz = CTL_MAXNAME;
@@ -89,7 +88,7 @@
 
                name[namelen++] = sizeof(*dpe);
                name[namelen++] = INT_MAX;
-               
+
                v = NULL;
                sz = 0;
                do {
@@ -117,19 +116,19 @@
 #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 @@
                                printf("-");
                                break;
                        }
-                       
+
                        printf("%c", BPFEXT(bde_promisc) ? 'P' : '-');
                        printf("%c", BPFEXT(bde_immediate) ? 'R' : '-');
                        printf("%c", BPFEXT(bde_seesent) ? 'S' : '-');
@@ -160,7 +159,7 @@
                        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 @@
                }
                free(v);
        } else {
-                /* XXX */
-                errx(1, "bpf_dump not implemented using kvm");
-        }
+               /* XXX */
+               errx(1, "bpf_dump not implemented using kvm");
+       }
 }
diff -r 8c3de0e0a16b -r 44d293296e87 usr.bin/netstat/fast_ipsec.c
--- a/usr.bin/netstat/fast_ipsec.c      Sat Sep 10 08:22:38 2022 +0000
+++ b/usr.bin/netstat/fast_ipsec.c      Mon Sep 12 14:29:19 2022 +0000
@@ -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 @@
 
 /*
  * 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 @@
 
        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],



Home | Main Index | Thread Index | Old Index