---
name: "snmp_mibII"
section: "3"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["freebsd"]
url: "https://new.carta.tech/snmp_mibII"
---

# snmp\_mibII(3)

mib-2 module for bsnmpd.

## NAME

**mibII**, **mibif\_notify\_f**, **mib\_netsock**, **mib\_if\_set\_dyn**, **mib\_refresh\_iflist**, **mib\_find\_if**, **mib\_find\_if\_sys**, **mib\_find\_if\_name**, **mib\_first\_if**, **mib\_next\_if**, **mib\_register\_newif**, **mib\_unregister\_newif**, **mib\_fetch\_ifmib**, **mib\_if\_admin**, **mib\_find\_ifa**, **mib\_first\_ififa**, **mib\_next\_ififa**, **mib\_ifstack\_create**, **mib\_ifstack\_delete**, **mib\_find\_rcvaddr**, **mib\_rcvaddr\_create**, **mib\_rcvaddr\_delete**, **mibif\_notify**, **mibif\_unnotify** – mib-2 module for bsnmpd.

## LIBRARY

(begemotSnmpdModulePath."mibII" = /usr/lib/snmp\_mibII.so)

## SYNOPSIS

**#include \<net/if.h\>**

**#include \<net/if\_mib.h\>**

**#include \<bsnmp/snmpmod.h\>**

**#include \<bsnmp/snmp\_mibII.h\>**

*typedef* *void*\

**(\*mibif\_notify\_f)**(*struct mibif \*ifp*, *enum mibif\_notify event*, *void \*uarg*); *extern* *int* *mib\_netsock*;

*void*\

**mib\_if\_set\_dyn**(*const char \*ifname*);

*void*\

**mib\_refresh\_iflist**(*void*);

*struct* *mibif* *\**\

**mib\_find\_if**(*u\_int ifindex*);

*struct* *mibif* *\**\

**mib\_find\_if\_sys**(*u\_int sysindex*);

*struct* *mibif* *\**\

**mib\_find\_if\_name**(*const char \*ifname*);

*struct* *mibif* *\**\

**mib\_first\_if**(*void*);

*struct* *mibif* *\**\

**mib\_next\_if**(*const struct mibif \*ifp*);

*int*\

**mib\_register\_newif**(*int (\*func)(struct mibif \*)*, *const struct lmodule \*mod*);

*void*\

**mib\_unregister\_newif**(*const struct lmodule \*mod*);

*int*\

**mib\_fetch\_ifmib**(*struct mibif \*ifp*);

*int*\

**mib\_if\_admin**(*struct mibif \*ifp*, *int up*);

*struct* *mibifa* *\**\

**mib\_find\_ifa**(*struct in\_addr ipa*);

*struct* *mibifa* *\**\

**mib\_first\_ififa**(*const struct mibif \*ifp*);

*struct* *mibifa* *\**\

**mib\_next\_ififa**(*struct mibifa \*ifa*);

*int*\

**mib\_ifstack\_create**(*const struct mibif \*lower*, *const struct mibif \*upper*);

*void*\

**mib\_ifstack\_delete**(*const struct mibif \*lower*, *const struct mibif \*upper*);

*struct* *mibrcvaddr* *\**\

**mib\_find\_rcvaddr**(*u\_int ifindex*, *const u\_char \*addr*, *size\_t addrlen*);

*struct* *mibrcvaddr* *\**\

**mib\_rcvaddr\_create**(*struct mibif \*ifp*, *const u\_char \*addr*, *size\_t addrlen*);

*void*\

**mib\_rcvaddr\_delete**(*struct mibrcvaddr \*addr*);

*void* *\**\

**mibif\_notify**(*struct mibif \*ifp*, *const struct lmodule \*mod*, *mibif\_notify\_f func*, *void \*uarg*);

*void*\

**mibif\_unnotify**(*void \*reg*);

## DESCRIPTION

The **snmp\_mibII** module implements parts of the internet standard MIB-2. Most of the relevant MIBs are implemented. Some of the tables are restricted to be read-only instead of read-write. The exact current implementation can be found in */usr/share/snmp/defs/mibII\_tree.def*. The module also exports a number of functions and global variables for use by other modules, that need to handle network interfaces. This man page describes these functions.

### DIRECT NETWORK ACCESS

The **mibII** module opens a socket that is used to execute all network related [ioctl(2)](/ioctl/2.md) functions. This socket is globally available under the name *mib\_netsock*.

### NETWORK INTERFACES

The **mibII** module handles a list of all currently existing network interfaces. It allows other modules to handle their own interface lists with special information by providing a mechanism to register to events that change the interface list (see below). The basic data structure is the interface structure:

```
struct mibif {
	TAILQ_ENTRY(mibif) link;
	u_int		flags;
	u_int		index;	/* logical ifindex */
	u_int		sysindex;
	char		name[IFNAMSIZ];
	char		descr[256];
	struct ifmibdata mib;
	uint64_t	mibtick;
	void		*specmib;
	size_t		specmiblen;
	u_char		*physaddr;
	u_int		physaddrlen;
	int		has_connector;
	int		trap_enable;
	uint64_t	counter_disc;
	mibif_notify_f	xnotify;
	void		*xnotify_data;
	const struct lmodule *xnotify_mod;
	struct asn_oid	spec_oid;
};
```

The **mibII** module tries to implement the semantic if *ifIndex* as described in RFC-2863. This RFC states, that an interface indexes may not be reused. That means, for example, if *tun* is a synthetic interface type and the system creates the interface *tun0*, destroys this interfaces and again creates a *tun* *0*, then these interfaces must have different interface indexes, because in fact they are different interfaces. If, on the other hand, there is a hardware interface *xl0* and this interface disappears, because its driver is unloaded and appears again, because the driver is loaded again, the interface index must stay the same. **mibII** implements this by differentiating between real and synthetic (dynamic) interfaces. An interface type can be declared dynamic by calling the function **mib\_if\_set\_dyn**() with the name if the interface type (for example "tun )." For real interfaces, the module keeps the mapping between the interface name and its *ifIndex* in a special list, if the interface is unloaded. For dynamic interfaces a new *ifIndex* is generated each time the interface comes into existence. This means, that the interface index as seen by SNMP is not the same index as used by the system. The SNMP *ifIndex* is held in field *index*, the system's interface index is *sysindex*.

A call to **mib\_refresh\_iflist** causes the entire interface list to be re-created.

The interface list can be traversed with the functions **mib\_first\_if**() and **mib\_next\_if**(). Be sure not to change the interface list while traversing the list with these two calls.

There are three functions to find an interface by name or index. **mib\_find\_if**() finds an interface by searching for an SNMP *ifIndex*, **mib\_find\_if\_sys**() finds an interface by searching for a system interface index and **mib\_find\_if\_name**() finds an interface by looking for an interface name. Each of the function returns NULL if the interface cannot be found.

The function **mib\_fetch\_ifmib**() causes the interface MIB to be refreshed from the kernel.

The function **mib\_if\_admin**() can be used to change the interface administrative state to up (argument is 1) or down (argument is 0).

### INTERFACE EVENTS

A module can register itself to receive a notification when a new entry is created in the interface list. This is done by calling **mib\_register\_newif**(). A module can register only one function, a second call to **mib\_register\_newif**() causes the registration to be overwritten. The registration can be removed with a call to **mib\_unregister\_newif**(). It is unregistered automatically, when the registering module is unloaded.

A module can also register to events on a specific interface. This is done by calling **mibif\_notify**(). This causes the given callback *func* to be called with the interface pointer, a notification code and the user argument *uarg* when any of the following events occur:

- MIBIF\_NOTIFY\_DESTROY

  The interface is destroyed.

This mechanism can be used to implement interface type specific MIB parts in other modules. The registration can be removed with **mib\_unnotify**() which the return value from *mib\_notify*. Any notification registration is removed automatically when the interface is destroyed or the registering module is unloaded. *Note* *that* *only* *one* *module* *can* *register* *to* *any* *given* *interface*.

### INTERFACE ADDRESSES

The **mibII** module handles a table of interface IP-addresses. These addresses are held in a

```
struct mibifa {
	TAILQ_ENTRY(mibifa) link;
	struct in_addr	inaddr;
	struct in_addr	inmask;
	struct in_addr	inbcast;
	struct asn_oid	index;
	u_int		ifindex;
	u_int		flags;
};
```

The (ordered) list of IP-addresses on a given interface can be traversed by calling **mib\_first\_ififa**() and **mib\_next\_ififa**(). The list should not be considered read-only.

### INTERFACE RECEIVE ADDRESSES

The internet MIB-2 contains a table of interface receive addresses. These addresses are handled in:

```
struct mibrcvaddr {
	TAILQ_ENTRY(mibrcvaddr) link;
	struct asn_oid	index;
	u_int		ifindex;
	u_char		addr[ASN_MAXOIDLEN];
	size_t		addrlen;
	u_int		flags;
};
enum {
	MIBRCVADDR_VOLATILE	= 0x00000001,
	MIBRCVADDR_BCAST	= 0x00000002,
	MIBRCVADDR_HW		= 0x00000004,
};
```

Note, that the assignment of MIBRCVADDR\_BCAST is based on a list of known interface types. The flags should be handled by modules implementing interface type specific MIBs.

A receive address can be created with **mib\_rcvaddr\_create**() and deleted with **mib\_rcvaddr\_delete**(). This needs to be done only for addresses that are not automatically handled by the system.

A receive address can be found with **mib\_find\_rcvaddr**().

### INTERFACE STACK TABLE

The **mibII** module maintains also the interface stack table. Because for complex stacks, there is no system supported generic way of getting this information, interface type specific modules need to help setting up stack entries. The **mibII** module handles only the top and bottom entries.

A table entry is created with **mib\_ifstack\_create**() and deleted with **mib\_ifstack\_delete**(). Both functions need the pointers to the interfaces. Entries are automatically deleted if any of the interfaces of the entry is destroyed. The functions handle both the stack table and the reverse stack table.

## FILES

- */usr/share/snmp/defs/mibII\_tree.def*

  The description of the MIB tree implemented by **mibII**.

- */usr/local/share/snmp/mibs*

  - */usr/share/snmp/mibs/*

  The various internet MIBs.

## SEE ALSO

[gensnmptree(1)](/gensnmptree/1.md), [snmpmod(3)](/snmpmod/3.md)

## STANDARDS

This implementation conforms to the applicable IETF RFCs.

## AUTHORS

Hartmut Brandt ⟨harti@FreeBSD.org⟩
