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_tspecmiblen;
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 existance. 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 systems 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. If 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: