int CreateNewOID(req *response, uint8_t i, req *r, tlv *auth) { tlv *oid; tlv new_leaf; // get the OID oid = &(r->oid[i]); // populate a new leaf TLV new_leaf.type = r->value[i].type; new_leaf.len = r->value[i].len; new_leaf.value = r->value[i].value; // Insert the new leaf if (InsertLeaf(oid->value, oid->len, &new_leaf, auth, 1) == NULL) { fprintf(stderr, "Failed to insert leaf\n"); exit(-1); } // form up the response response->value[i].type = new_leaf.type; response->value[i].len = new_leaf.len; response->value[i].value = new_leaf.value; return(0); }
// Create a proxy in the tree as a leaf node. We return the index // of the node instead of a pointer so that we can grow // the node pool. int32 b2DynamicTree::CreateProxy(const b2AABB& aabb, void* userData) { int32 proxyId = AllocateNode(); // Fatten the aabb. b2Vec2 r(b2_aabbExtension, b2_aabbExtension); m_nodes[proxyId].aabb.lowerBound = aabb.lowerBound - r; m_nodes[proxyId].aabb.upperBound = aabb.upperBound + r; m_nodes[proxyId].userData = userData; InsertLeaf(proxyId); // Rebalance if necessary. int32 iterationCount = m_nodeCount >> 4; int32 tryCount = 0; int32 height = ComputeHeight(); while (height > 64 && tryCount < 10) { Rebalance(iterationCount); height = ComputeHeight(); ++tryCount; } return proxyId; }
bool b2DynamicTree::MoveProxy(int32 proxyId, const b2AABB& aabb, const b2Vec2& displacement) { b2Assert(0 <= proxyId && proxyId < m_nodeCapacity); b2Assert(m_nodes[proxyId].IsLeaf()); if (m_nodes[proxyId].aabb.Contains(aabb)) { return false; } RemoveLeaf(proxyId); // Extend AABB. b2AABB b = aabb; b2Vec2 r(b2_aabbExtension, b2_aabbExtension); b.lowerBound = b.lowerBound - r; b.upperBound = b.upperBound + r; // Predict AABB displacement. b2Vec2 d = b2_aabbMultiplier * displacement; if (d.x < 0.0f) { b.lowerBound.x += d.x; } else { b.upperBound.x += d.x; } if (d.y < 0.0f) { b.lowerBound.y += d.y; } else { b.upperBound.y += d.y; } m_nodes[proxyId].aabb = b; printf(" moved_aabb: %.2f %.2f to %.2f %.2f\n", b.lowerBound.x, b.lowerBound.y, b.upperBound.x, b.upperBound.y); InsertLeaf(proxyId); return true; }
// Create a proxy in the tree as a leaf node. We return the index // of the node instead of a pointer so that we can grow // the node pool. int32 b2DynamicTree::CreateProxy(const b2AABB& aabb, void* userData) { int32 proxyId = AllocateNode(); // Fatten the aabb. b2Vec2 r(b2_aabbExtension, b2_aabbExtension); m_nodes[proxyId].aabb.lowerBound = aabb.lowerBound - r; m_nodes[proxyId].aabb.upperBound = aabb.upperBound + r; m_nodes[proxyId].userData = userData; m_nodes[proxyId].height = 0; InsertLeaf(proxyId); return proxyId; }
// Create a proxy in the tree as a leaf node. We return the index // of the node instead of a pointer so that we can grow // the node pool. uint16 b2DynamicTree::CreateProxy(const b2AABB& aabb, void* userData) { uint16 node = AllocateNode(); // Fatten the aabb. b2Vec2 center = aabb.GetCenter(); b2Vec2 extents = b2_fatAABBFactor * aabb.GetExtents(); m_nodes[node].aabb.lowerBound = center - extents; m_nodes[node].aabb.upperBound = center + extents; m_nodes[node].userData = userData; InsertLeaf(node); return node; }
void b2DynamicTree::MoveProxy(uint16 proxyId, const b2AABB& aabb) { b2Assert(proxyId < m_nodeCount); b2Assert(m_nodes[proxyId].IsLeaf()); if (m_nodes[proxyId].aabb.Contains(aabb)) { return; } RemoveLeaf(proxyId); b2Vec2 center = aabb.GetCenter(); b2Vec2 extents = b2_fatAABBFactor * aabb.GetExtents(); m_nodes[proxyId].aabb.lowerBound = center - extents; m_nodes[proxyId].aabb.upperBound = center + extents; InsertLeaf(proxyId); }
void b2DynamicTree::Rebalance(int32 iterations) { if (m_root == b2_nullNode) { return; } for (int32 i = 0; i < iterations; ++i) { int32 node = m_root; uint32 bit = 0; while (m_nodes[node].IsLeaf() == false) { int32* children = &m_nodes[node].child1; node = children[(m_path >> bit) & 1]; bit = (bit + 1) & (8* sizeof(uint32) - 1); } ++m_path; RemoveLeaf(node); InsertLeaf(node); } }
void PopulateMIB(void) { tlv data; unsigned char oid[256]; tree *leaf; int i; public_comm = calloc(1,6); memcpy(public_comm, "public", 6); private_comm = calloc(1,PRIV_COMM_LEN); RndStr(private_comm, PRIV_COMM_LEN); // // public access // oid[0] = 0x2b; oid[1] = 6; oid[2] = 1; oid[3] = 6; oid[4] = 3; oid[5] = 18; // snmpCommunityMIB oid[6] = 1; // snmpCommunityMIBObjects oid[7] = 1; // snmpCommunityTable oid[8] = 1; // snmpCommunityEntry oid[9] = 1; // snmpCommunityIndex oid[10] = 2; // snmpCommunityName data.type = TYPE_OCTETSTRING; data.len = 6; data.value = public_comm; if (InsertLeaf(oid, 11, &data, NULL, 0) == NULL) { fprintf(stderr, "Failed to insert leaf\n"); exit(-1); } oid[0] = 0x2b; oid[1] = 6; oid[2] = 1; oid[3] = 6; oid[4] = 3; oid[5] = 18; // snmpCommunityMIB oid[6] = 1; // snmpCommunityMIBObjects oid[7] = 1; // snmpCommunityTable oid[8] = 1; // snmpCommunityEntry oid[9] = 1; // snmpCommunityIndex oid[10] = 8; // snmpCommunityStatus data.type = TYPE_INTEGER; data.len = 1; data.value = calloc(1, 1); *((uint8_t *)(data.value)) = 2; if (InsertLeaf(oid, 11, &data, NULL, 0) == NULL) { fprintf(stderr, "Failed to insert leaf\n"); exit(-1); } // // 'private' access // oid[0] = 0x2b; oid[1] = 6; oid[2] = 1; oid[3] = 6; oid[4] = 3; oid[5] = 18; // snmpCommunityMIB oid[6] = 1; // snmpCommunityMIBObjects oid[7] = 1; // snmpCommunityTable oid[8] = 1; // snmpCommunityEntry oid[9] = 2; // snmpCommunityIndex oid[10] = 2; // snmpCommunityName data.type = TYPE_OCTETSTRING; data.len = PRIV_COMM_LEN; data.value = private_comm; if ((leaf = InsertLeaf(oid, 11, &data, NULL, 0)) == NULL) { fprintf(stderr, "Failed to insert leaf\n"); exit(-1); } leaf->auth = &(leaf->data); oid[0] = 0x2b; oid[1] = 6; oid[2] = 1; oid[3] = 6; oid[4] = 3; oid[5] = 18; // snmpCommunityMIB oid[6] = 1; // snmpCommunityMIBObjects oid[7] = 1; // snmpCommunityTable oid[8] = 1; // snmpCommunityEntry oid[9] = 2; // snmpCommunityIndex oid[10] = 8; // snmpCommunityStatus data.type = TYPE_INTEGER; data.len = 1; data.value = calloc(1, 1); *((uint8_t *)(data.value)) = 2; if (InsertLeaf(oid, 11, &data, leaf->auth, 0) == NULL) { fprintf(stderr, "Failed to insert leaf\n"); exit(-1); } oid[0] = 0x2b; oid[1] = 8; oid[2] = 10; data.type = TYPE_INTEGER; data.len = 1; data.value = calloc(1, 1); *(uint8_t *)data.value = 1; if (InsertLeaf(oid, 3, &data, NULL, 0) == NULL) { fprintf(stderr, "Failed to insert leaf\n"); exit(-1); } // BUG leak stack address oid[0] = 0x2b; oid[1] = 8; oid[2] = 0x8A; oid[3] = 0x39; data.type = TYPE_OCTETSTRING; data.len = 8; data.value = calloc(1, 8); *(uint64_t *)data.value = (uint64_t)&leaf ^ 0xdeadbeefcafebabe; if (InsertLeaf(oid, 4, &data, NULL, 0) == NULL) { fprintf(stderr, "Failed to insert leaf\n"); exit(-1); } }