]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
SNMP: Add bgp trie cleanup
authorVojtech Vilimek <vojtech.vilimek@nic.cz>
Wed, 18 Oct 2023 14:51:21 +0000 (16:51 +0200)
committerVojtech Vilimek <vojtech.vilimek@nic.cz>
Wed, 18 Oct 2023 15:39:36 +0000 (17:39 +0200)
proto/snmp/bgp_mib.c
proto/snmp/snmp.c
proto/snmp/snmp.h
proto/snmp/subagent.c
proto/snmp/subagent.h

index 2628ace1d141f70f771ce8ee3ee9d7f5792be349..46e097895b3aea0a862c22b51015cb4fea2daf15 100644 (file)
@@ -61,7 +61,7 @@ snmp_bgp_notify_common(struct snmp_proto *p, uint type, ip4_addr ip4, char last_
 #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;
@@ -75,7 +75,7 @@ snmp_bgp_notify_common(struct snmp_proto *p, uint type, ip4_addr ip4, char last_
 
   /* 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;
@@ -175,7 +175,7 @@ snmp_bgp_register(struct snmp_proto *p)
     /* 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);
 
@@ -201,7 +201,7 @@ snmp_bgp_register(struct snmp_proto *p)
 
     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);
 
@@ -772,7 +772,7 @@ bgp_find_dynamic_oid(struct snmp_proto *p, struct oid *o_start, const struct oid
       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;
index 31f3391d60868ea4716ba21e1ca169fbb15b3cd6..8f49997c984fd5b16fa8160a0a6ca0b2675214a3 100644 (file)
@@ -160,9 +160,11 @@ snmp_cleanup(struct snmp_proto *p)
   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
@@ -230,9 +232,12 @@ snmp_start_locked(struct object_lock *lock)
   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;
@@ -284,8 +289,7 @@ snmp_startup(struct snmp_proto *p)
   /* 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
@@ -347,30 +351,33 @@ snmp_start(struct proto *P)
   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)
@@ -379,7 +386,7 @@ snmp_start(struct proto *P)
     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;
 
index 60e460299325c432a1c31dff9153445c47236aed..6cfa9bb0f02c80159e5eaee298e9b1c2a5f6e85c 100644 (file)
@@ -120,7 +120,8 @@ struct snmp_context {
 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;
index 692372b56b5216f7495f04c3b720efb31ed2027a..739fdc20204bea9403dfbfd108bee6827ecb15fc 100644 (file)
@@ -1236,7 +1236,7 @@ search_mib(struct snmp_proto *p, const struct oid *o_start, const struct oid *o_
 
   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_()
   }
@@ -1268,7 +1268,7 @@ search_mib(struct snmp_proto *p, const struct oid *o_start, const struct oid *o_
 
     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;
   }
@@ -1304,7 +1304,7 @@ snmp_prefixize(struct snmp_proto *proto, const struct oid *oid, int byte_ord)
 
   /* 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;
   }
@@ -1320,7 +1320,7 @@ snmp_prefixize(struct snmp_proto *proto, const struct oid *oid, int byte_ord)
   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));
index 26fb07a044fa1eb8e57ac171f7441ea1fb1ffaa0..a4be3b8bde6ab254d07e60a76394e01f26c304cd 100644 (file)
@@ -115,8 +115,8 @@ enum snmp_search_res {
 
 #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); })