SNMP is a protocol for querying network hardware like routers and switches for status data, and PHP's SNMP extension wraps the NET-SNMP library. This RFC from Steven Wilton adds three improvements to the extension. Steven Wilton ran into these gaps while trying to use the extension in the LibreNMS project in place of the SNMP command line tools.
More SNMPv3 encryption options#
NET-SNMP can be built with support for AES192, AES192C, AES256 and AES256C. This change lets you use them as the SNMPv3 security protocol in PHP, as long as the library on your system supports them.
Resetting the MIB#
A MIB is a file that maps names to the numeric IDs SNMP uses. Once PHP loaded a MIB, there was no way to clear it, which caused problems when two vendors reused the same ID in different MIBs. You also couldn't change the directories where NET-SNMP looks for MIB files.
The new snmp_init_mib() function clears the loaded MIBs and sets the directories to search:
snmp_init_mib("/path/to/mibs:/path/to/more_mibs");
$results = snmp2_get("hostname", "community", "MIB::object");
snmp_init_mib();
PHP also resets the MIBs between FPM requests, so one request's MIBs don't leak into the next.
More output controls#
New functions let you control how NET-SNMP parses MIBs and formats values, for example by accepting MIBs with underscores in their names. The output options are also available as properties on the SNMP object, so you can set them per request. During code review, the output settings moved to PHP enums:
snmp_set_output_format(Snmp\Output::ExtendedIndex, true);
$snmp = new SNMP(...);
$snmp->dont_print_units = true;
$snmp->setStringOutputFormat(Snmp\StringOutput::Ascii);
The old constant values still work too.
What it means for existing code#
Nothing breaks, since the RFC only adds new functions and options. It does note one side effect: an FPM process that loads MIBs leaks about 5 KB per request until a fix lands in NET-SNMP itself.