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

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

parse.c and parse.h代码保留一个哈希桶。 (indexed bucket (tree list))
还有一个树结构,其中包含指向Next node in hashed list of names.的下一个指针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 Next- > ‘ipSystemStatsHCOctetGroup ipSystemStatsOutFragReqds ifStackGroup2 ifOutErrors’

我无法理解在Next->之后出现的对象名称之间的关系是什么?

基于哪些对象名称在一起的标准是什么? 在这一点上,我不清楚该守则。

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

注意 :对于MIB树中的纯粹遍历目的,有* child,* parent&* peer给出! modid也不是OID的一部分。

parse.h中名为’module compatability’的数据结构:

 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. struct tree * next;

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

Net-snmpfunction通过模块的“名称”提供查询,
对象当查询的对象名称(字符串)是ASCII时,

 $ snmptranslate -On -IR bundleSize - - .1.3.6.1.4.1.26149.2.1.2.2.1.9 

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

哈希函数:

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

然后将此哈希值传递给宏NBUCKET(x) – 返回索引(0-127) 。 通过链接对碰撞进行如下处理。 桶[I] – >下一步 – >下一步 – >下一个……..


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 modid;

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

parse.h中名为’module compatability’的数据结构:

 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有树forms。 节点可能包含其他节点等。您引用的结构表示节点。 因此,通过使用“下一个”指针,您将遍历解析器读取的节点。