Idea to support Agents that only support 16-bit Request IDs
craigermcgreger opened this issue · 3 comments
Sharp SNMP has special support for broken Agents that don't support negative Request IDs via Messenger.UseFullRange = false
, which restricts Request IDs to 0 thru int.MaxValue
(2,147,483,647).
There is another type of broken Agent that only supports 16-bit Request IDs. In fact, they are so common that support for them was added to net-snmp almost 20 years ago:
$ man snmp.conf
16bitIDs yes
restricts requestIDs, etc to 16-bit values.
The SNMP specifications define these ID fields as
32-bit quantities, and the Net-SNMP library typically
initialises them to random values for security. However
certain (broken) agents cannot handle ID values greater
than 2^16 - this option allows interoperability with such agents.
Currently, the only way to work with these agents in Sharp SNMP is to specify the Request ID manually by creating GetRequestMessage
, SetRequestMessage
, etc. It would be great if we could use Messenger
with them, too. To do this, we could use a new enum, Messenger.RequestIDRange
:
Full
(default):int.MinValue
thruint.MaxValue
Positive32Bit
: 0 thruint.MaxValue
Positive16Bit
: 0 thrushort.MaxValue
(32,767)
Messenger.UseFullRange
could be obsoleted, but for backwards compatibility, setting Messenger.UseFullRange = true
would set Messenger.RequestIDRange = Full
and setting Messenger.UseFullRange = false
would set Messenger.RequestIDRange = Positive32Bit
.
It makes no sense to add more hacks in Messenger
for specific agents (as we cannot assume how bad an agent can be). But it is possible to extract ID generation policies to their own classes so that anyone can customize further via a standardized API.
Might deliver it in the next release, as it shouldn't be a hard task.
You can try 12.5.0 Beta 6 and set Messenger.RequestCounter
to control the ID range immediately when your program starts.
https://www.nuget.org/packages/Lextm.SharpSnmpLib/12.5.0-beta6
I installed 12.5.0-beta6 and tried Messenger.RequestCounter = new NumberGenerator(0, short.MaxValue)
. It worked perfectly with the Agent that only accepts 16-bit Request IDs. Plus, it is much more flexible than my idea. Thank you!