Skip to content
Snippets Groups Projects
Commit efeef43d authored by Martin Karlgren's avatar Martin Karlgren
Browse files

Support REQUEST_GETNEXT by allowing callback to return a different OID.

Previously, the API only supported returning the requested OID, which made
it impossible for the callback to return the "next" OID (the one actually
used in REQUEST_GETNEXT requests).
parent d85dc28f
No related branches found
No related tags found
No related merge requests found
...@@ -60,12 +60,15 @@ private void request_received(mapping rdata) { ...@@ -60,12 +60,15 @@ private void request_received(mapping rdata) {
else if(oid_get_callbacks["*"]) else if(oid_get_callbacks["*"])
{ {
mixed r=oid_get_callbacks["*"](oid, rv[n[0]]); mixed r=oid_get_callbacks["*"](oid, rv[n[0]]);
// We got a different OID than the requested
// one. Typically happens with REQUEST_GETNEXT requests.
string ret_oid = (sizeof (r) >= 4 && r[3]) || oid;
if(r[0]==0) // we had an error if(r[0]==0) // we had an error
{ {
return_error(rv, @r[1..]); return_error(rv, @r[1..2]);
return; return;
} }
else varlist[oid]=r[1..]; else varlist[ret_oid]=r[1..2];
} }
} }
} }
...@@ -303,13 +306,18 @@ void|function get_set_oid_callback(string oid) ...@@ -303,13 +306,18 @@ void|function get_set_oid_callback(string oid)
//! the function to call when oid is requested by a manager //! the function to call when oid is requested by a manager
//! the function should take 2 arguments: a string containing the //! the function should take 2 arguments: a string containing the
//! requested oid and the body of the request as a mapping. //! requested oid and the body of the request as a mapping.
//! The function should return an array containing 3 elements: //! The function should return an array containing 3 or 4 elements:
//! The first is a boolean indicating success or failure. //! The first is a boolean indicating success or failure.
//! If success, the next 2 elements should be the SNMP data type of //! If success, the next 2 elements should be the SNMP data type of
//! the result followed by the result itself. //! the result followed by the result itself.
//! If failure, the next 2 elements should be the error-status //! If failure, the next 2 elements should be the error-status
//! such as @[Protocols.SNMP.ERROR_TOOBIG] and the second //! such as @[Protocols.SNMP.ERROR_TOOBIG] and the second
//! is the error-index, if any. //! is the error-index, if any.
//! If a fourth array element is returned, it should contain the OID
//! that the callback actually fetched (typically different from the
//! requested OID for REQUEST_GETNEXT requests). This is needed for
//! e.g. snmpwalk to work properly.
//!
//! @note //! @note
//! there can be only one callback per object identifier. //! there can be only one callback per object identifier.
//! calling this function more than once with the same oid will //! calling this function more than once with the same oid will
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment