【问题标题】:net-snmp parse code, How to parse MIB?net-snmp 解析代码,如何解析 MIB?
【发布时间】:2012-09-29 17:10:50
【问题描述】:

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

parse.c and parse.h 代码中保留了一个哈希桶。 (indexed bucket (tree list)).
还有一个树形结构,其中包含一个指向Next node in hashed list of names.的next指针

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->之后出现的对象名称之间的关系我不明白?

基于哪些对象名称在一起的标准是什么? 目前我还不清楚该准则。

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

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

parse.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 */
    };

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

【问题讨论】:

    标签: c network-programming snmp net-snmp nms


    【解决方案1】:

    我也与 Net-snmp 合作了很长一段时间,我正在与您分享我的观察。
    可能这会对你有所帮助。

    1.结构树 *next;

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

    Net-snmp 功能提供按模块的“名称”查询,
    Object 当查询的对象名称(字符串)为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)。 通过如下链接解决冲突。 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 modid;

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

    parse.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
    

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

      • 不,'modid' 不是模块 OID 的一部分(听说是这样)。 'next' 也是一个节点指针,但 'next' 不是用于遍历的。出于纯粹的遍历目的,给出了 *child、*parent 和 *peer!...next 与哈希桶有一些关系(算法的一些内部目的),我无法理解这一点。
      • 当 mib 存储在哈希表中时,它只是一个用于解决冲突的内部指针。参见例如en.wikipedia.org/wiki/Hash_table#Separate_chaining 。因此->next 中的 mib 只是其他 mib,其哈希函数解析为哈希表中的相同存储桶。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-19
      • 1970-01-01
      相关资源
      最近更新 更多