The branch main has been updated by jhibbits:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=19850ee07363ffd97b4ba3c06361392ce9834440

commit 19850ee07363ffd97b4ba3c06361392ce9834440
Author:     Justin Hibbits <jhibb...@freebsd.org>
AuthorDate: 2023-02-21 23:13:00 +0000
Commit:     Justin Hibbits <jhibb...@freebsd.org>
CommitDate: 2023-02-21 23:17:26 +0000

    Revert "linprocfs: Migrate to IfAPI"
    
    This reverts commit 5243598927a95e77b3bb9804b049539b87353a5b.
    
    Requested by:   dchagin
---
 sys/compat/linprocfs/linprocfs.c | 107 ++++++++++++++++-----------------------
 1 file changed, 43 insertions(+), 64 deletions(-)

diff --git a/sys/compat/linprocfs/linprocfs.c b/sys/compat/linprocfs/linprocfs.c
index f2a8c5833c82..15c4d3c41749 100644
--- a/sys/compat/linprocfs/linprocfs.c
+++ b/sys/compat/linprocfs/linprocfs.c
@@ -1474,79 +1474,26 @@ 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 linux_ifname_cb_s arg;
+       struct ifnet *ifscan;
+       int ethno;
 
        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, if_name(ifp), buflen));
+               return (strlcpy(buffer, ifp->if_xname, buflen));
 
        /* Determine the (relative) unit number for ethernet interfaces */
-       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 */
+       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 (0);
 }
@@ -1557,6 +1504,9 @@ linprocfs_donetdev_cb(if_t ifp, void *arg)
 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",
@@ -1566,7 +1516,36 @@ linprocfs_donetdev(PFS_FILL_ARGS)
 
        CURVNET_SET(TD_TO_VNET(curthread));
        IFNET_RLOCK();
-       if_foreach(linprocfs_donetdev_cb, sb);
+       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 */
+       }
        IFNET_RUNLOCK();
        CURVNET_RESTORE();
 

Reply via email to