Iterating all VNETs from userspace application

From: Özkan KIRIK <ozkan.kirik_at_gmail.com>
Date: Mon, 18 Oct 2021 04:46:03 UTC
Hi,

I'm trying to gather all even within jails/vnet interface stats which
interface type ifmd_data.ifi_type == IFT_ETHER (6) for bsnmpd. Related
function (not modified) is here:

https://github.com/freebsd/freebsd-src/blob/main/contrib/bsnmp/snmp_mibII/mibII.c#L926-L985

It's possible to add a filter interface type adding a line below line 961:
if (mib.ifmd_data.ifi_type != IFT_ETHER) return;

I'm looking for a way to iterate VNET instances, but net/vnet.h is
only for kernel space.
        VNET_LIST_RLOCK_NOSLEEP();
        VNET_FOREACH(vnet_iter) {
                CURVNET_SET(vnet_iter);
                mib_refresh_iflist();
                CURVNET_RESTORE();
        }
        VNET_LIST_RUNLOCK_NOSLEEP();
The code above not working in userspace.

Also I wonder that if it's possible to switch between jails. The
pseudo code I want to write:

JAIL_FOREACH(jail_iter) {
    jail_attach(jail_iter);
    mib_refresh_iflist();
    jail_detach();
}

What is the right way to gather all interface stats ?

Have a nice day
Regards