Main index | Section 3 | Options |
#include <net/if.h>
#include <net/if_mib.h>
#include <bsnmp/snmpmod.h>
#include <bsnmp/snmp_mibII.h>
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).
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.
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.
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().
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.
/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. | |
SNMP_MIBII (3) | January 4, 2017 |
Main index | Section 3 | Options |
Please direct any comments about this manual page service to Ben Bullock. Privacy policy.