#define SNMP_OID_SIZE_FROM_LEN(x) (sizeof(struct oid) + (x) * sizeof(u32))
/* trap OID bgpEstablishedNotification (.1.3.6.1.2.1.0.1) */
- struct oid *head = mb_alloc(p->p.pool, SNMP_OID_SIZE_FROM_LEN(3));
+ struct oid *head = mb_alloc(p->pool, SNMP_OID_SIZE_FROM_LEN(3));
head->n_subid = 3;
head->prefix = 2;
head->include = head->pad = 0;
/* Paylaod OIDs */
- void *data = mb_alloc(p->p.pool, sz);
+ void *data = mb_alloc(p->pool, sz);
struct agentx_varbind *addr_vb = data;
/* +4 for varbind header, +8 for octet string */
struct agentx_varbind *error_vb = data + SNMP_OID_SIZE_FROM_LEN(9) + 4 + 8;
/* Register the whole BGP4-MIB::bgp root tree node */
struct snmp_register *registering = snmp_register_create(p, SNMP_BGP4_MIB);
- struct oid *oid = mb_alloc(p->p.pool, snmp_oid_sizeof(2));
+ struct oid *oid = mb_alloc(p->pool, snmp_oid_sizeof(2));
STORE_U8(oid->n_subid, 2);
STORE_U8(oid->prefix, SNMP_MGMT);
struct snmp_register *registering = snmp_register_create(p, SNMP_BGP4_MIB);
- struct oid *oid = mb_alloc(p->p.pool, snmp_oid_sizeof(9));
+ struct oid *oid = mb_alloc(p->pool, snmp_oid_sizeof(9));
STORE_U8(oid->n_subid, 9);
STORE_U8(oid->prefix, SNMP_MGMT);
snmp_log("ip4_less() returned true");
// TODO repair
- struct oid *o = snmp_oid_duplicate(p->p.pool, o_start);
+ struct oid *o = snmp_oid_duplicate(p->pool, o_start);
snmp_oid_ip4_index(o, 5, net4_prefix(&net));
return o;
mb_free(p->context_id_map);
p->context_id_map = NULL;
- // TODO cleanup trie
+ rfree(p->lp);
+ p->bgp_trie = NULL;
- return (p->state = SNMP_DOWN);
+ p->state = SNMP_DOWN;
+ return PS_DOWN;
}
void
p->state = SNMP_LOCKED;
sock *s = p->sock;
+ if (!p->bgp_trie)
+ p->bgp_trie = f_new_trie(p->lp, 0); // TODO user-data attachment size
+
if (!s)
{
- s = sk_new(p->p.pool);
+ s = sk_new(p->pool);
s->type = SK_TCP_ACTIVE;
s->saddr = p->local_ip;
s->daddr = p->remote_ip;
/* Starting AgentX communicaiton channel. */
struct object_lock *lock;
-
- lock = p->lock = olock_new(p->p.pool);
+ lock = p->lock = olock_new(p->pool);
// lock->addr
// lock->port
p->errs = 0;
p->partial_response = NULL;
- p->startup_timer = tm_new_init(p->p.pool, snmp_startup_timeout, p, 0, 0);
- p->ping_timer = tm_new_init(p->p.pool, snmp_ping_timeout, p, 0, 0);
+ p->startup_timer = tm_new_init(p->pool, snmp_startup_timeout, p, 0, 0);
+ p->ping_timer = tm_new_init(p->pool, snmp_ping_timeout, p, 0, 0);
- p->pool = lp_new(p->p.pool);
- p->bgp_trie = f_new_trie(p->pool, cf->bonds);
+ p->pool = p->p.pool;
+ p->lp = lp_new(p->pool);
+ p->bgp_trie = f_new_trie(p->lp, 0);
+ //p->bgp_trie = f_new_trie(lp, cf->bonds); // TODO user-data attachment size
init_list(&p->register_queue);
init_list(&p->bgp_registered);
/* We create copy of bonds to BGP protocols. */
- HASH_INIT(p->bgp_hash, p->p.pool, 10);
- HASH_INIT(p->context_hash, p->p.pool, 10);
+ HASH_INIT(p->bgp_hash, p->pool, 10);
+ HASH_INIT(p->context_hash, p->pool, 10);
/* We always have at least the default context */
- p->context_id_map = mb_allocz(p->p.pool, cf->contexts * sizeof(struct snmp_context *));
+ p->context_id_map = mb_allocz(p->pool, cf->contexts * sizeof(struct snmp_context *));
log(L_INFO "number of context allocated %d", cf->contexts);
- struct snmp_context *defaultc = mb_alloc(p->p.pool, sizeof(struct snmp_context));
+ struct snmp_context *defaultc = mb_alloc(p->pool, sizeof(struct snmp_context));
defaultc->context = "";
defaultc->context_id = 0;
defaultc->flags = 0; /* TODO Default context fl. */
HASH_INSERT(p->context_hash, SNMP_H_CONTEXT, defaultc);
p->context_id_map[0] = defaultc;
+ p->bgp_trie = NULL;
struct snmp_bond *b;
WALK_LIST(b, cf->bgp_entries)
if (bc && !ipa_zero(bc->remote_ip))
{
struct snmp_bgp_peer *peer = \
- mb_allocz(p->p.pool, sizeof(struct snmp_bgp_peer));
+ mb_allocz(p->pool, sizeof(struct snmp_bgp_peer));
peer->config = bc;
peer->peer_ip = bc->remote_ip;
struct snmp_proto {
struct proto p;
struct object_lock *lock;
- struct linpool *pool;
+ pool *pool; /* a shortcut to the procotol mem. pool */
+ linpool *lp;
ip_addr local_ip;
ip_addr remote_ip;
if (!o_curr)
{
- o_curr = snmp_oid_duplicate(p->p.pool, o_start);
+ o_curr = snmp_oid_duplicate(p->pool, o_start);
// XXX is it right time to free o_start right now (here) ?
// not for use in snmp_get_next2() the o_start comes and ends in _gets2_()
}
default:
if (o_curr) mb_free(o_curr);
- o_curr = snmp_oid_duplicate(p->p.pool, o_start);
+ o_curr = snmp_oid_duplicate(p->pool, o_start);
*result = SNMP_SEARCH_END_OF_VIEW;
break;
}
/* already in prefixed form */
else if (oid->prefix != 0) {
- struct oid *new = snmp_oid_duplicate(proto->p.pool, oid);
+ struct oid *new = snmp_oid_duplicate(proto->pool, oid);
snmp_log("already prefixed");
return new;
}
if (oid->ids[4] >= 256)
{ snmp_log("outside byte first id"); return NULL; }
- struct oid *new = mb_alloc(proto->p.pool,
+ struct oid *new = mb_alloc(proto->pool,
sizeof(struct oid) + MAX((oid->n_subid - 5) * sizeof(u32), 0));
memcpy(new, oid, sizeof(struct oid));
#define COPY_STR(proto, buf, str, length, byte_order) ({ \
length = LOAD_PTR(buf, byte_order); \
- log(L_INFO "LOAD_STR(), %p %u", proto->p.pool, length + 1); \
- str = mb_alloc(proto->p.pool, length + 1); \
+ log(L_INFO "LOAD_STR(), %p %u", proto->pool, length + 1); \
+ str = mb_alloc(proto->pool, length + 1); \
memcpy(str, buf+4, length); \
str[length] = '\0'; /* set term. char */ \
buf += 4 + snmp_str_size_from_len(length); })