使用int64类型的snmp v2c oid?

时间:2013-11-13 04:42:44

标签: snmp net-snmp int64 oid

我正在为整数溢出问题调试一些snmp代码。基本上我们使用整数来存储KB的磁盘/ raid容量。但是,当使用超过2TB的磁盘/ raid时,它会溢出。

我从一些互联网论坛上读到,snmp v2c支持integer64或unsigned64。在我的测试中,即使我将类型设置为integer64或unsigned64,它仍然只发送低32位。

我是这样做的:

  1. 独立程序将获取容量并将数据写入文件。 raid容量的示例行

    my-sub-oid
    Counter64
    7813857280
    
  2. /etc/snmp/snmpd.conf有一个通过oid传递的子句:

    pass_persist mymiboid /path/to/snmpagent
    
  3. 在mysnmpagent源代码中,
  4. 从文件中读取oidmap到oid / type / value结构,然后打印到stdout。

    printf("%s\n", it->first.c_str());
    printf("%s\n", it->second.type.c_str());
    printf("%s\n", it->second.value.c_str());
    fflush(stdout);
    
  5. 使用snmpget获取子oid,然后返回:

    mysuboid = Counter32: 3518889984
    
  6. 我使用tcpdump,值部分的最后一段是:

    41 0500 d1be 0000
    
  7. 41应该是标签,05应该是长度,并且该值仅承载容量的低32位。 (注意7813857280是0x1.d1.be.00.00)

    我确实发现使用字符串类型会发送正确的值(以八位字符串格式)。但我想知道是否有办法在snmp v2c中使用64位整数。

    我正在运行NET-SNMP 5.4.2.1。 非常感谢。

    更新

    在snmpd.conf中找到以下关于net-snmp doc page中的pass(也可能是pass_persist)的内容。我想这是迫使Counter64到Counter32。

    Note:
    The SMIv2 type counter64 and SNMPv2 noSuchObject exception are not supported.
    

2 个答案:

答案 0 :(得分:1)

SNMP SMIv2定义了一个新类型Counter64,

http://tools.ietf.org/html/rfc2578#page-24

实际上是无符号的64位整数。因此,如果您的数据属于该范围,则使用Counter64是正确的。

“在我的测试中它仍然只是发送低32位,即使我已经将类型设置为integer64或unsigned64”听起来像一个问题,但除非你显示更多的细节(如显示一些代码)你如何测试它结果并且收到了结果,没有人可能会进一步帮助。

答案 1 :(得分:1)

对于大数字的低位和高位字节,你应该使用两个Unsigned32。

Counter64并不意味着以这种方式用于大数字。

供参考:17 Common MIB Design Errors (last one)