Exemplo n.º 1
0
static void
mib_tree_delete(const oid_t *oid, uint32_t id_len)
{
  struct node_pair pair;
  struct mib_node *node;

  node = mib_tree_node_search(oid, id_len, &pair);
  if (node != NULL) {
    __mib_tree_delete(&pair);
  }
}
Exemplo n.º 2
0
/* This function create group node(s) in mib-tree according to oid given in
 * which the prefix can be already created as group node(s) and the last id
 * number must not be created yet. the id number before the last one will be
 * created as new dummy group node(s).
 */
static struct mib_group_node *
mib_tree_group_insert(const oid_t *oid, uint32_t id_len)
{
  struct mib_node *node;
  struct mib_group_node *gn;
  struct node_pair pair;

  /* Init something */
  pair.parent = pair.child = NULL;
  node = (struct mib_node *)&internet_group;
  oid += INTERNET_PREFIX_LENGTH;
  id_len -= INTERNET_PREFIX_LENGTH;

  while (id_len > 0) {
    switch (node->type) {

      case MIB_OBJ_GROUP:
        gn = (struct mib_group_node *)node;

        if (is_raw_group_node(gn)) {
          /* Allocate intermediate group node */
          node = gn->sub_ptr[0] = mib_group_node_new();
          gn->sub_id_cnt++;
          gn->sub_id[0] = *oid++;
          id_len--;
        } else {
          /* Search in exist sub-ids */
          int i = oid_binary_search(gn->sub_id, gn->sub_id_cnt, *oid);
          if (i >= 0) {
            /* Sub-id found, go on traversing */
            oid++;
            id_len--;
            node = gn->sub_ptr[i];
          } else {
            /* Sub-id not found, that's it. */
            i = -i - 1;
            /* realloc sub_id[] */
            group_node_resize(gn, i);
            /* Allocate new group node */
            node = gn->sub_ptr[i] = mib_group_node_new();
            gn->sub_id_cnt++;
            gn->sub_id[i] = *oid++;
            id_len--;
            /* Record the new allocated root group node */
            if (pair.child == NULL && pair.parent == NULL) {
              pair.parent = (struct mib_node *)gn;
              pair.child = (struct mib_node *)node;
              pair.sub_idx = i;
            }
          }
        }
        continue;

      case MIB_OBJ_INSTANCE:
        /* Bad traversal, clear all temporarily built group nodes */
        __mib_tree_delete(&pair);
        return NULL;

      default:
        assert(0);
        break;
    }
  }

  /* id_len == 0 */
  return (struct mib_group_node *)node;
}