c-net snmp解析代码,如何解析MIB



我正在学习net snmp代码库。解析MIB。

parse.c and parse.h中,代码保存一个散列桶。CCD_ 2
还有一个树结构,它包含指向Next node in hashed list of names.的下一个指针

struct tree{  
.
.
struct tree    *next;       // Next node in hashed list of names 
int             modid;     // The module containing this node 
}

我打印了MIB,

SNMP-FRAMEWORK-MIB:snmpFrameworkMIB(10)type=24下一步->"ipSystemStatsHCecttGroup ipSystemStats OutFragReqds ifStackGroup2 ifOutErrors">

我不明白下一步->之后出现的对象名称之间的关系

对象名称组合在一起的标准是什么目前我还不清楚《守则》

什么是modid?其值不等于模块OID!

注意:出于纯粹的遍历目的,MIB树中有*child、*parent&同龄人被给予!此外,modid不是OID的一部分。

解析中名为"模块兼容性"的数据结构。h:

struct module_compatability {
const char     *old_module;
const char     *new_module;
const char     *tag;    /* NULL implies unconditional replacement,
* otherwise node identifier or prefix */
size_t          tag_len;        /* 0 implies exact match (or unconditional) */
struct module_compatability *next;      /* linked list */
};

这个结构有什么用?在什么意义上兼容

我也在使用Net-snmp很长一段时间了,我将与您分享我的观察结果
也许这会对你有所帮助。

1.结构树*next

struct tree    * next; /* Next node in hashed list of names */   

Net snmp功能通过模块的"名称"提供查询,
对象当查询的对象名称(字符串)为ASCII时,

$ snmptranslate -On -IR bundleSize  
-   
-  
.1.3.6.1.4.1.26149.2.1.2.2.1.9  

它有一个大小为128的哈希表(内部)数据结构"bucket"。

哈希函数:

name_hash(str*) - return some of ASCII value. 

然后,此哈希值被传递到宏中NBUCKET(x)-返回索引(0-127)。碰撞通过以下链接来解决。bucket[i]->next->next->next。。。。。。。。


这方面的代码存在于parse.c--中

tree->next'bucket'的管理方式如下:

tp->hash = name_hash(tp->name); // Fist find hash value as some of ASCII
b = BUCKET(tp->hash);           // map hash value into (0-127)
if (buckets[b])                 // check for collision 
tp->next = buckets[b];     // collision is resolved ny chan chain 
buckets[b] = tp;           // new coming node become first node in chain

2.int修改

  • 包含此节点的模块。
    • 有一个类型为"struct-module"的链表
    • modid是模块链表中的序列号
    • 序列号以0开头
    • modid=模块开始读取的编号
    • parse.h"findmodule(int-moid)"中定义的函数返回节点地址存储关于模块的信息

解析中名为"模块兼容性"的数据结构。h:

This is an array of structre 'module compatability' use to store compatible 
basic MIB name (RFC's defined).   
const char     *old_module;   // snmp-v1  
const char     *new_module;   // snmp-v2

modid不是模块OID。它是定义模块标识的单个数字(包含在OID中)。此MIB模块引入的所有OID都将包含此数字作为OID前缀。modid对于下面定义的所有节点都将是常量。我相信,在你的情况下,modid是31(ipTrafficStats)?

正如你可能知道的,MIB有一个树形结构。节点可能包含其他节点等。你所指的结构代表一个节点。因此,通过使用"下一个"指针,您可以遍历解析器读取的节点。

最新更新