IFMIB(4)

πŸ’– IFMIB πŸ’–

okay bestie, so this is the manual page for ifmib β€” the Management Information Base for network interfaces 🫢 it's a section 4 page (kernel interfaces, iykyk), and honestly? it's giving "the kernel's little gossip spreadsheet about your network cards." let's get into it ✨


🌸 SYNOPSIS 🌸

like, include all of these, in this order, no skips:

#include <sys/types.h>
#include <sys/socket.h>
#include <sys/sysctl.h>
#include <sys/time.h>
#include <net/if.h>
#include <net/if_mib.h>

✨ DESCRIPTION ✨

so the ifmib facility is literally an application of the sysctl(3) interface, and its whole job is handing out management information about network interfaces to client applications β€” think netstat(1), slstat(8), and SNMP management agents πŸ‘‘ they all come here for the tea.

and the way this info is structured? it's a table πŸ“‹ where every row is one logical network interface β€” either a hardware device or a software pseudo-device like lo(4). two columns, bestie, and each one holds a single structure:

  • one column = generic info that's relevant to all interfaces
  • the other column = info specific to that particular class of interface. (generally the latter will implement the SNMP MIB defined for that particular interface class, if one exists and can actually be implemented in the kernel πŸ’…)

you get to all of this through the "net.link.generic" branch of the sysctl(3) MIB. the manifest constants for each level in the sysctl(3) name live in <net/if_mib.h>. and the index of the last row in the table? that's "net.link.generic.system.ifcount" β€” or, if you're speaking manifest-constant, CTL_NET, PF_LINK, NETLINK_GENERIC, IFMIB_SYSTEM, IFMIB_IFCOUNT ⭐

so a management application hunting for a specific interface should start at row 1 and just keep going row-by-row until it finds the one it wants, or until it hits the interface count. and here's the thing πŸ‘‡

the table may be sparse β€” meaning a given row may not exist at all, and that shows up as an errno of ENOENT. do not panic. that error should be ignored, and you just check the next row. πŸ’€

πŸ¦‹ getting the generic info πŸ¦‹

the generic interface information β€” the stuff common to all interfaces β€” is accessed via this exact procedure, no cap:

int
get_ifmib_general(int row, struct ifmibdata *ifmd)
{
        int name[6];
        size_t len;

        name[0] = CTL_NET;
        name[1] = PF_LINK;
        name[2] = NETLINK_GENERIC;
        name[3] = IFMIB_IFDATA;
        name[4] = row;
        name[5] = IFDATA_GENERAL;

        len = sizeof(*ifmd);

        return sysctl(name, 6, ifmd, &len, (void *)0, 0);
}

πŸŽ€ the fields in struct ifmibdata πŸŽ€

here's the whole lineup, main character energy only:

  • ifmd_name β€” (char []) the name of the interface, including the unit number
  • ifmd_pcount β€” (int) the number of promiscuous listeners
  • ifmd_flags β€” (int) the interface's flags (defined in <net/if.h>)
  • ifmd_snd_len β€” (int) the current instantaneous length of the send queue
  • ifmd_snd_drops β€” (int) the number of packets dropped at this interface because the send queue was full
  • ifmd_data β€” (struct if_data) more information from a structure defined in <net/if.h> (see if_data(9))

🧚 class-specific info 🧚

want the stuff that's specific to a class of interface? you retrieve that by examining the IFDATA_LINKSPECIFIC column instead πŸ‘‘ and heads up β€” the form and the length of that structure depend entirely on the class of interface, so don't assume.

for IFT_ETHER, IFT_ISO88023, and IFT_STARLAN interfaces, that structure is called "struct ifmib_iso_8802_3" (defined in <net/if_mib.h>), and it implements a superset of the RFC 1650 MIB for Ethernet-like networks 🌈 slay.


🌈 SEE ALSO 🌈


⭐ HISTORY ⭐

the ifmib interface first appeared in FreeBSD 2.2 🫢 ancient. iconic. still here.


πŸ’€ BUGS πŸ’€

ngl, a lot of Ethernet-like interfaces do not yet support the Ethernet MIB 😭 the interfaces known to support it include ed(4) and de(4). but regardless β€” all interfaces automatically support the generic MIB, so you're never fully left on read πŸ’…


and that's the whole page, bestie πŸŽ€ this was IFMIB(4) from the Debian distribution, dated October 28, 2009 β€” go forth and query your interfaces, mwah πŸ’–βœ¨

πŸ“¦ where this page comes from