From 99abcffc62a9c124aa4eb3aae828d342ce26b6fb Mon Sep 17 00:00:00 2001 From: Steve Wilton Date: Sun, 15 Mar 2026 14:39:46 +0800 Subject: [PATCH 1/2] Add snmp_init_mib function to allow MIB tree to be reset using environment variables --- ext/snmp/snmp.c | 8 ++++++++ ext/snmp/snmp.stub.php | 2 ++ ext/snmp/snmp_arginfo.h | 7 ++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/ext/snmp/snmp.c b/ext/snmp/snmp.c index d116339dd1f40..0a00163306bcd 100644 --- a/ext/snmp/snmp.c +++ b/ext/snmp/snmp.c @@ -1637,6 +1637,14 @@ PHP_FUNCTION(snmp_read_mib) } /* }}} */ +/* {{{ Resets the MIB tree using the MIBDIRS, MIBS and MIBFILES environment variables. */ +PHP_FUNCTION(snmp_init_mib) +{ + shutdown_mib(); + init_mib(); +} +/* }}} */ + /* {{{ Creates a new SNMP session to specified host. */ PHP_METHOD(SNMP, __construct) { diff --git a/ext/snmp/snmp.stub.php b/ext/snmp/snmp.stub.php index 0a303aea77ff0..51f42a4456701 100644 --- a/ext/snmp/snmp.stub.php +++ b/ext/snmp/snmp.stub.php @@ -181,6 +181,8 @@ function snmp_get_valueretrieval(): int {} function snmp_read_mib(string $filename): bool {} +function snmp_init_mib(): void {} + class SNMP { /** @cvalue SNMP_VERSION_1 */ diff --git a/ext/snmp/snmp_arginfo.h b/ext/snmp/snmp_arginfo.h index 1ee821f0538da..5600545328466 100644 --- a/ext/snmp/snmp_arginfo.h +++ b/ext/snmp/snmp_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit snmp.stub.php instead. - * Stub hash: e2451ac3ea0fa5eb1158e8b7252e61c6794d514f */ + * Stub hash: 08a8c1d1f26d62aa9e7333a9f72d4d50ede21932 */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_snmpget, 0, 3, IS_MIXED, 0) ZEND_ARG_TYPE_INFO(0, hostname, IS_STRING, 0) @@ -114,6 +114,9 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_snmp_read_mib, 0, 1, _IS_BOOL, 0 ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_snmp_init_mib, 0, 0, IS_VOID, 0) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SNMP___construct, 0, 0, 3) ZEND_ARG_TYPE_INFO(0, version, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, hostname, IS_STRING, 0) @@ -185,6 +188,7 @@ ZEND_FUNCTION(snmp3_set); ZEND_FUNCTION(snmp_set_valueretrieval); ZEND_FUNCTION(snmp_get_valueretrieval); ZEND_FUNCTION(snmp_read_mib); +ZEND_FUNCTION(snmp_init_mib); ZEND_METHOD(SNMP, __construct); ZEND_METHOD(SNMP, close); ZEND_METHOD(SNMP, setSecurity); @@ -220,6 +224,7 @@ static const zend_function_entry ext_functions[] = { ZEND_FE(snmp_set_valueretrieval, arginfo_snmp_set_valueretrieval) ZEND_FE(snmp_get_valueretrieval, arginfo_snmp_get_valueretrieval) ZEND_FE(snmp_read_mib, arginfo_snmp_read_mib) + ZEND_FE(snmp_init_mib, arginfo_snmp_init_mib) ZEND_FE_END }; From 4912462f5540cff44b2c050e101431ee203b7ea7 Mon Sep 17 00:00:00 2001 From: Steve Wilton Date: Sun, 15 Mar 2026 23:18:27 +0800 Subject: [PATCH 2/2] Fix to make the MIB tree re-initialisation work --- ext/snmp/snmp.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ext/snmp/snmp.c b/ext/snmp/snmp.c index 0a00163306bcd..7a459b0889baa 100644 --- a/ext/snmp/snmp.c +++ b/ext/snmp/snmp.c @@ -1640,7 +1640,10 @@ PHP_FUNCTION(snmp_read_mib) /* {{{ Resets the MIB tree using the MIBDIRS, MIBS and MIBFILES environment variables. */ PHP_FUNCTION(snmp_init_mib) { + // Destroy the old MIB tree and set the internal MIB directory list to NULL shutdown_mib(); + netsnmp_ds_set_string(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_MIBDIRS, NULL); + // Initialise the new MIB tree init_mib(); } /* }}} */