From nobody Fri Feb 3 14:45:19 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4P7djq3Vn7z2pCD6; Fri, 3 Feb 2023 14:45:19 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4P7djq2YwTz4M2r; Fri, 3 Feb 2023 14:45:19 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675435519; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=38LSKOxxyJ0MwyVOaU1G2p0GSqSx2b1k6DfhvMvMzpw=; b=YFTli0+mx+WwxVmzCdtR5gBat1paDqtyV553atOZsKsPPVYMUHg218kbzlvNWzaPbua+pj fGQ7F0LQopxjLOF1Y68FsQ1sr7hthD3csfXs0ee9AucFpvjU2O9tmjvfZvKMrZcXbi24QN yvQYAaC0qk7S+NbA3lTF4JcgpvL0g4IAmlRPZSFEckWqXD/zHjkIvE7IWwvimjwRXX33Tb zgQMze7l6gG0Wnm4U/r79Ur4CvaIaMG4VFHs706AmVMFOn8PncPrPKtmx0AQMUVHlXSmVs oWaHbDLwdyd0VyX2VVFBXAojgf3gwnkhUCM/m0Wq1dM4EvjlLqJjANZXDCteeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675435519; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=38LSKOxxyJ0MwyVOaU1G2p0GSqSx2b1k6DfhvMvMzpw=; b=M2LuhtcnSz0vKlYkMAMihsMLzdWOFE3zw2qEek3fCuPv120TNIMkvzcQUx+qDxJHNzoi/m 8B/8DUf5k2mZtah7468Ed8BTIFEgYzmst43srvNqbiC9FQ4NuYUAqmxwWBCz2ZAkGJuPgU T31dJz9lF1cyP/MX6hAs11XE9Knr1vRU5cQPzLrRbhWAXkVfbx+IbNS2x43t2etjLPVHpI fvGw1qA3/mdP7F9aUzTolSpS5rL5zXkzCKHAyaNyysF8oj1bx+lcO/upKGiZ5CZf7LF9xW Uktceju6WhX47k42hS1Ewlvel1R9gjdpBiXauA7KKPmfRREWkA66ZynHvez5xA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1675435519; a=rsa-sha256; cv=none; b=q7MnBw+lg0hiFML/EGK1Tok5VRJmWxaMuic4HlL+mSLGkdi9aKcge0XzPrf59C+Uj54mbD UiZwlFch39ZZYTiYJVaA/XV9qLR4e3uHJRMbDbguB/29hcNIuau4gfGlMjiC/uwqW4F4Ne iDYmxksp3uehaJVTfvOTrSqMQx1mALNveHh6N3xD/yjs8yNA29YiYbwluhb3ofAUiI2KF9 wofh6YD1+wi3P29tJXc5r5uZxc86ItBHkxHKBwjOqiPZWm6tO7QuUaXRvYm0XSk8Hm7x3k WNA7X7GQX7BXOxshu+E/tVC4J33Az564wA1ZyiVOziiDiEoWOlvV3AZrUXTjkA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4P7djq1ZGgzdZl; Fri, 3 Feb 2023 14:45:19 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 313EjJd8027876; Fri, 3 Feb 2023 14:45:19 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 313EjJ2L027875; Fri, 3 Feb 2023 14:45:19 GMT (envelope-from git) Date: Fri, 3 Feb 2023 14:45:19 GMT Message-Id: <202302031445.313EjJ2L027875@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Justin Hibbits Subject: git: 5243598927a9 - main - linprocfs: Migrate to IfAPI List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhibbits X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 5243598927a95e77b3bb9804b049539b87353a5b Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by jhibbits: URL: https://cgit.FreeBSD.org/src/commit/?id=5243598927a95e77b3bb9804b049539b87353a5b commit 5243598927a95e77b3bb9804b049539b87353a5b Author: Justin Hibbits AuthorDate: 2023-02-02 21:48:22 +0000 Commit: Justin Hibbits CommitDate: 2023-02-03 14:38:03 +0000 linprocfs: Migrate to IfAPI Summary: Migrate linprocfs to use the IfAPI interfaces instead of direct ifnet accesses. Reviewed by: dchagin Sponsored by: Juniper Networks, Inc. Differential Revision: https://reviews.freebsd.org/D38358 --- sys/compat/linprocfs/linprocfs.c | 107 +++++++++++++++++++++++---------------- 1 file changed, 64 insertions(+), 43 deletions(-) diff --git a/sys/compat/linprocfs/linprocfs.c b/sys/compat/linprocfs/linprocfs.c index 15c4d3c41749..f2a8c5833c82 100644 --- a/sys/compat/linprocfs/linprocfs.c +++ b/sys/compat/linprocfs/linprocfs.c @@ -1474,26 +1474,79 @@ linprocfs_doprocmem(PFS_FILL_ARGS) return (error); } +struct linux_ifname_cb_s { + struct ifnet *ifp; + int ethno; + char *buffer; + size_t buflen; +}; + +static int +linux_ifname_cb(if_t ifp, void *arg) +{ + struct linux_ifname_cb_s *cbs = arg; + + if (ifp == cbs->ifp) + return (snprintf(cbs->buffer, cbs->buflen, "eth%d", cbs->ethno)); + if (!linux_use_real_ifname(ifp)) + cbs->ethno++; + return (0); +} + static int linux_ifname(struct ifnet *ifp, char *buffer, size_t buflen) { - struct ifnet *ifscan; - int ethno; + struct linux_ifname_cb_s arg; IFNET_RLOCK_ASSERT(); + arg.ifp = ifp; + arg.buffer = buffer; + arg.buflen = buflen; + arg.ethno = 0; + /* Short-circuit non ethernet interfaces */ if (linux_use_real_ifname(ifp)) - return (strlcpy(buffer, ifp->if_xname, buflen)); + return (strlcpy(buffer, if_name(ifp), buflen)); /* Determine the (relative) unit number for ethernet interfaces */ - ethno = 0; - CK_STAILQ_FOREACH(ifscan, &V_ifnet, if_link) { - if (ifscan == ifp) - return (snprintf(buffer, buflen, "eth%d", ethno)); - if (!linux_use_real_ifname(ifscan)) - ethno++; - } + return (if_foreach(linux_ifname_cb, &arg)); +} + +static int +linprocfs_donetdev_cb(if_t ifp, void *arg) +{ + char ifname[16]; /* XXX LINUX_IFNAMSIZ */ + struct sbuf *sb = arg; + + linux_ifname(ifp, ifname, sizeof ifname); + sbuf_printf(sb, "%6.6s: ", ifname); + sbuf_printf(sb, "%7ju %7ju %4ju %4ju %4lu %5lu %10lu %9ju ", + (uintmax_t )if_getcounter(ifp, IFCOUNTER_IBYTES), + (uintmax_t )if_getcounter(ifp, IFCOUNTER_IPACKETS), + (uintmax_t )if_getcounter(ifp, IFCOUNTER_IERRORS), + (uintmax_t )if_getcounter(ifp, IFCOUNTER_IQDROPS), + /* rx_missed_errors */ + 0UL, /* rx_fifo_errors */ + 0UL, /* rx_length_errors + + * rx_over_errors + + * rx_crc_errors + + * rx_frame_errors */ + 0UL, /* rx_compressed */ + (uintmax_t )if_getcounter(ifp, IFCOUNTER_IMCASTS)); + /* XXX-BZ rx only? */ + sbuf_printf(sb, "%8ju %7ju %4ju %4ju %4lu %5ju %7lu %10lu\n", + (uintmax_t )if_getcounter(ifp, IFCOUNTER_OBYTES), + (uintmax_t )if_getcounter(ifp, IFCOUNTER_OPACKETS), + (uintmax_t )if_getcounter(ifp, IFCOUNTER_OERRORS), + (uintmax_t )if_getcounter(ifp, IFCOUNTER_OQDROPS), + 0UL, /* tx_fifo_errors */ + (uintmax_t )if_getcounter(ifp, IFCOUNTER_COLLISIONS), + 0UL, /* tx_carrier_errors + + * tx_aborted_errors + + * tx_window_errors + + * tx_heartbeat_errors*/ + 0UL); /* tx_compressed */ return (0); } @@ -1504,9 +1557,6 @@ linux_ifname(struct ifnet *ifp, char *buffer, size_t buflen) static int linprocfs_donetdev(PFS_FILL_ARGS) { - char ifname[16]; /* XXX LINUX_IFNAMSIZ */ - struct ifnet *ifp; - sbuf_printf(sb, "%6s|%58s|%s\n" "%6s|%58s|%58s\n", "Inter-", " Receive", " Transmit", @@ -1516,36 +1566,7 @@ linprocfs_donetdev(PFS_FILL_ARGS) CURVNET_SET(TD_TO_VNET(curthread)); IFNET_RLOCK(); - CK_STAILQ_FOREACH(ifp, &V_ifnet, if_link) { - linux_ifname(ifp, ifname, sizeof ifname); - sbuf_printf(sb, "%6.6s: ", ifname); - sbuf_printf(sb, "%7ju %7ju %4ju %4ju %4lu %5lu %10lu %9ju ", - (uintmax_t )ifp->if_get_counter(ifp, IFCOUNTER_IBYTES), - (uintmax_t )ifp->if_get_counter(ifp, IFCOUNTER_IPACKETS), - (uintmax_t )ifp->if_get_counter(ifp, IFCOUNTER_IERRORS), - (uintmax_t )ifp->if_get_counter(ifp, IFCOUNTER_IQDROPS), - /* rx_missed_errors */ - 0UL, /* rx_fifo_errors */ - 0UL, /* rx_length_errors + - * rx_over_errors + - * rx_crc_errors + - * rx_frame_errors */ - 0UL, /* rx_compressed */ - (uintmax_t )ifp->if_get_counter(ifp, IFCOUNTER_IMCASTS)); - /* XXX-BZ rx only? */ - sbuf_printf(sb, "%8ju %7ju %4ju %4ju %4lu %5ju %7lu %10lu\n", - (uintmax_t )ifp->if_get_counter(ifp, IFCOUNTER_OBYTES), - (uintmax_t )ifp->if_get_counter(ifp, IFCOUNTER_OPACKETS), - (uintmax_t )ifp->if_get_counter(ifp, IFCOUNTER_OERRORS), - (uintmax_t )ifp->if_get_counter(ifp, IFCOUNTER_OQDROPS), - 0UL, /* tx_fifo_errors */ - (uintmax_t )ifp->if_get_counter(ifp, IFCOUNTER_COLLISIONS), - 0UL, /* tx_carrier_errors + - * tx_aborted_errors + - * tx_window_errors + - * tx_heartbeat_errors*/ - 0UL); /* tx_compressed */ - } + if_foreach(linprocfs_donetdev_cb, sb); IFNET_RUNLOCK(); CURVNET_RESTORE();