From: yasuoka Date: Sun, 16 Jul 2023 03:01:31 +0000 (+0000) Subject: Make the mbstat preserve the same size which is actually used. Also X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=cea35e798e12953fe0c2bf514e802d209589bc05;p=openbsd Make the mbstat preserve the same size which is actually used. Also revert the previous that the mbstat is located on the stack. ok claudio --- diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c index b71f9824be1..10c6b5acad8 100644 --- a/sys/kern/kern_sysctl.c +++ b/sys/kern/kern_sysctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_sysctl.c,v 1.417 2023/07/07 16:27:46 bluhm Exp $ */ +/* $OpenBSD: kern_sysctl.c,v 1.418 2023/07/16 03:01:31 yasuoka Exp $ */ /* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */ /*- @@ -515,22 +515,20 @@ kern_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, case KERN_MBSTAT: { extern struct cpumem *mbstat; uint64_t counters[MBSTAT_COUNT]; - struct mbstat *mbs; + struct mbstat mbs; unsigned int i; - int ret; - mbs = malloc(sizeof(*mbs), M_TEMP, M_WAITOK | M_ZERO); + memset(&mbs, 0, sizeof(mbs)); counters_read(mbstat, counters, MBSTAT_COUNT); for (i = 0; i < MBSTAT_TYPES; i++) - mbs->m_mtypes[i] = counters[i]; + mbs.m_mtypes[i] = counters[i]; - mbs->m_drops = counters[MBSTAT_DROPS]; - mbs->m_wait = counters[MBSTAT_WAIT]; - mbs->m_drain = counters[MBSTAT_DRAIN]; + mbs.m_drops = counters[MBSTAT_DROPS]; + mbs.m_wait = counters[MBSTAT_WAIT]; + mbs.m_drain = counters[MBSTAT_DRAIN]; - ret = sysctl_rdstruct(oldp, oldlenp, newp, mbs, sizeof(*mbs)); - free(mbs, M_TEMP, sizeof(*mbs)); - return (ret); + return (sysctl_rdstruct(oldp, oldlenp, newp, + &mbs, sizeof(mbs))); } case KERN_MSGBUFSIZE: case KERN_CONSBUFSIZE: { diff --git a/sys/sys/mbuf.h b/sys/sys/mbuf.h index 8e8fb131f58..b0c76c2e704 100644 --- a/sys/sys/mbuf.h +++ b/sys/sys/mbuf.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mbuf.h,v 1.260 2023/07/07 14:17:34 yasuoka Exp $ */ +/* $OpenBSD: mbuf.h,v 1.261 2023/07/16 03:01:31 yasuoka Exp $ */ /* $NetBSD: mbuf.h,v 1.19 1996/02/09 18:25:14 christos Exp $ */ /* @@ -363,6 +363,12 @@ u_int mextfree_register(void (*)(caddr_t, u_int, void *)); /* length to m_copy to copy all */ #define M_COPYALL 1000000000 +#define MBSTAT_TYPES MT_NTYPES +#define MBSTAT_DROPS (MBSTAT_TYPES + 0) +#define MBSTAT_WAIT (MBSTAT_TYPES + 1) +#define MBSTAT_DRAIN (MBSTAT_TYPES + 2) +#define MBSTAT_COUNT (MBSTAT_TYPES + 3) + /* * Mbuf statistics. * For statistics related to mbuf and cluster allocations, see also the @@ -372,15 +378,10 @@ struct mbstat { u_long m_drops; /* times failed to find space */ u_long m_wait; /* times waited for space */ u_long m_drain; /* times drained protocols for space */ - u_long m_mtypes[256]; /* type specific mbuf allocations */ + u_long m_mtypes[MBSTAT_COUNT]; + /* type specific mbuf allocations */ }; -#define MBSTAT_TYPES MT_NTYPES -#define MBSTAT_DROPS (MBSTAT_TYPES + 0) -#define MBSTAT_WAIT (MBSTAT_TYPES + 1) -#define MBSTAT_DRAIN (MBSTAT_TYPES + 2) -#define MBSTAT_COUNT (MBSTAT_TYPES + 3) - #include struct mbuf_list { diff --git a/usr.bin/netstat/mbuf.c b/usr.bin/netstat/mbuf.c index dfb7695b737..6eeeebe96f2 100644 --- a/usr.bin/netstat/mbuf.c +++ b/usr.bin/netstat/mbuf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mbuf.c,v 1.44 2023/07/07 14:17:35 yasuoka Exp $ */ +/* $OpenBSD: mbuf.c,v 1.45 2023/07/16 03:01:31 yasuoka Exp $ */ /* $NetBSD: mbuf.c,v 1.9 1996/05/07 02:55:03 thorpej Exp $ */ /* @@ -79,7 +79,7 @@ static struct mbtypes { }; int nmbtypes = sizeof(mbstat.m_mtypes) / sizeof(u_long); -bool seen[256]; /* "have we seen this type yet?" */ +bool seen[MBSTAT_COUNT]; /* "have we seen this type yet?" */ /* * Print mbuf statistics. @@ -93,7 +93,7 @@ mbpr(void) struct mbtypes *mp; size_t size; - if (nmbtypes != 256) { + if (nmbtypes != MBSTAT_COUNT) { fprintf(stderr, "%s: unexpected change to mbstat; check source\n", __progname);