usm: unknown securityname error

I am using SNMP++ in a multi-threaded program. I am assuming that I do not have to do any external locking when making calls to the SNMP++ library as I understand it is thread-safe. There is only one Snmp_pp::Snmp object that is shared with all threads. I have 20 threads running as fast as they can go with no waits. There are 100 different security names divided about equally between the three different v3 security levels (auth-priv, auth-nopriv, and no auth). About every couple hundred calls, I get a "usm: unknown securityname " error from :

  // search for user in usmUserTable
  user = get_user(securityEngineID, securityName);

  if (!user) {
debugprintf(0, "USM: User unknown!");
return SNMPv3_USM_UNKNOWN_SECURITY_NAME;
  }

in module usm_v3.cpp.

I am guessing that I am getting this error because I am not using the library correctly in a multi-threaded environment. Should I be doing locking external to SNMP++ and if so, where.

Any guidance would be much appreciated.
Regards
Gary

Hi Gary,

Are you modifying the usmUserTable while you are executing the threads?
Otherwise the error condition in your code should not be possible.

Best regards,
Frank

Hi,

as Frank wrote, this can only happen, if the user/engineId combination is not within the USM user tables at that moment. If your code does not modify the USM users, maybe the following could help.

Can you verify from the log message at the start of USM::get_user() that the user/engineId are valid? You can lower the log level of the debugprintf() command.

It could also happen that there are memory problems where new returns null. This would also lead to the “User unknown” message. For this, you could add log statements to USM::get_user() and USMUserTable::get_cloned_entry() wherever a pointer check fails.

Best regards,
Jochen

Gentleman,

Thank you both for your replies. I do modify the usmUserTable on a per-thread basis. Is there some lock I should take out when I modify the usmUserTable? Would it be a better design to just have one SNMP object per thread and not try to share one SNMP object with all the other threads?

Thanks
Gary

Hi Gary,

my question is: Why do you have to modify the usmUserTable regularly? This table has the localized users for each agent, i.e. for each engineId. You should only need to update the table if you have changed the authentication/privacy keys for that agent. And for this purpose the function USMUserTable::update_key() could be used.

There is no lock inside snmp++ that you could use to synchronize changes to the USM user table. This has to be a part of the application code.

Best regards,
Jochen

Hi Jochen,

Thanks for the information. The current design of the application is based on a thread pool and a worklist. The worklist is asynchronously modified by a UI thread. Consequently, the thread does not know if the item it has been worked on has been executed or modified before. I will take a look at adding the usmUserTable maintenance to the UI thread.

Thank you very much for your help with this issue.
Regards
Gary