c++linuxyoctosnmpnet-snmp

SNMP Subagent - dropping bad AgentX request (wrong mode 2)


Context: I am building a snmp subagent with the c++ net-snmp library. I am working on adding data validation for set requests. Doing so, I am required to wait for the value in the set request to be written to hardware. While the subagent is waiting to hear back the the hardware has updated properly, the subagent will sleep in a loop (will exit after 5 seconds without hearing back from the hardware callback).

Issue: The issue I am noticing with this implementation, is that when the subagent sleeps for longer then ~1 second, I see a net-snmp error dropping bad AgentX request (wrong mode 2). When I adjust the sleep period, I see multiple of the same error message. So it seems correlated to the agent sleeping.

Notes: I have confirmed with wireshark, that my mib browser I am using is only sending 1 set request. With logs on the subagent, I can confirm that on a successful set request, adding this sleep period causes this error message, which causes the set request to fail with a GENERAL_ERROR.

I am using net-snmp v5.9.3.

I can confirm, without this sleeping loop, the set requests will return as successful in my subagent (since we always assume that the value updates to hardware successfully).

The error dropping bad AgentX request (wrong mode 2) will show up in the console at the end of the set request (when it should be successful)

This is what the sleep loop looks like

while (callbackNotRecieved && elapsedTime.count() <= setRequestTimeout) {
  std::this_thread::sleep_for(std::chrono::milliseconds(_sleepTimer)); // sleep for 1 second
  callbackNotRecieved = CheckCallback();
  currentTime = std::chrono::system_clock::now();
  elapsedTime = std::chrono::duration_cast<std::chrono::milliseconds>(currentTime - startingTime);
}

I have seen this issue on other forums with no resolution


I am open to all ideas to resolve this/debug this. I didn't post any subagent code as I wasn't sure what parts would be relevant since the subagent does work and this seems like a very obscure bug. If anyone wants to see some code snippets which may be useful, I can update this post.


Solution

  • I am using a yocto environment to build net-snmp so I am able to include a patch with my solution to work around this issue. The patch I have generated is fairy simple. It removes this line, that will send the agentx_error.

    Although I am not fully aware of the implications doing this has. Applying this patch, allows me to sleep in the subagent request handler for MODE_SET_ACTION. I've observed that the behavior when applying this patch, is that, when the agent is sleeping, net-snmp will continue to send the request, until it passes in a timely manner. I'm not sure what/why that is, but with logging, I can see my subagent handling 2-3 versions of the same set request after the initial. This has not seemed to cause an issue, as on the second/third/etc set request, my subagent, will not sleep waiting for the value to update, as it has already updated.

    I have also made a net-snmp issue in github that should hopefully bring more attention to this bug. As I don't think this is a bug in the subagent side. https://github.com/net-snmp/net-snmp/issues/691