From afce92ac77f67d0a805ddca4df33040a66647a0e Mon Sep 17 00:00:00 2001
From: Maria Matejka <mq@ucw.cz>
Date: Tue, 27 Aug 2024 14:59:15 +0200
Subject: [PATCH] TMP: drop bmp_proto_list

---
 proto/bmp/bmp.c | 39 ++++++++++++---------------------------
 proto/bmp/bmp.h |  3 +++
 2 files changed, 15 insertions(+), 27 deletions(-)

diff --git a/proto/bmp/bmp.c b/proto/bmp/bmp.c
index 6b077db6..fc6d8828 100644
--- a/proto/bmp/bmp.c
+++ b/proto/bmp/bmp.c
@@ -56,9 +56,6 @@
 #include "nest/iface.h"
 #include "nest/route.h"
 
-// List of BMP instances
-static list STATIC_LIST_INIT(bmp_proto_list);
-
 #define HASH_PEER_KEY(n)		n->bgp
 #define HASH_PEER_NEXT(n)		n->next
 #define HASH_PEER_EQ(b1,b2)		b1 == b2
@@ -727,26 +724,6 @@ bmp_peer_up(ea_list *bgp,
     DG_UNLOCK(p->p.pool->domain);
 }
 
-void
-bmp_peer_up_jour(int bmp_id, ea_list *bgp,
-	    const byte *tx_open_msg, uint tx_open_length,
-	    const byte *rx_open_msg, uint rx_open_length)
-{
-  int need_unlock = 1;
-  if (DG_IS_LOCKED(p->p.pool->domain))
-    need_unlock = 0;
-  else
-    DG_LOCK(p->p.pool->domain);
-
-  struct bmp_proto *p; node *n;
-  WALK_LIST2(p, n, bmp_proto_list, bmp_node)
-    if (p->p.id == bmp_id)
-      bmp_peer_up_(p, bgp, true, tx_open_msg, tx_open_length, rx_open_msg, rx_open_length);
-
-  if (need_unlock)
-    DG_UNLOCK(p->p.pool->domain);
-}
-
 static void
 bmp_peer_init(struct bmp_proto *p, ea_list *bgp_attr)
 {
@@ -1024,6 +1001,7 @@ bmp_peer_down_(struct bmp_proto *p, const struct bgp_proto *bgp,
   bmp_remove_peer(p, bp);
 }
 
+#if 0
 void
 bmp_peer_down(const struct bgp_proto *bgp,
 	      int err_class, int code, int subcode, const byte *data, int length)
@@ -1041,6 +1019,7 @@ bmp_peer_down(const struct bgp_proto *bgp,
   if (need_unlock)
     DG_UNLOCK(p->p.pool->domain);
 }
+#endif
 
 static void
 bmp_send_termination_msg(struct bmp_proto *p,
@@ -1331,8 +1310,12 @@ bmp_postconfig(struct proto_config *CF)
 }
 
 void
-fc_for_bmp_recipient(void *rec)
+fc_for_bmp_recipient(void *_p)
 {
+  struct bmp_proto *p = _p;
+
+  ASSERT_DIE(birdloop_inside(p->p.loop));
+
   //log("received update, locked %i", locking_stack.service);
   struct lfjour_item *last_up;
   struct proto_pending_update *pupdate;
@@ -1355,7 +1338,9 @@ fc_for_bmp_recipient(void *rec)
       const byte *rx_open_msg = ea_get_adata(pupdate->proto_attr, &ea_bgp_remote_open_msg)->data;
       int l_len = ea_get_int(pupdate->proto_attr, &ea_bgp_remote_open_msg_len, 0);
       int r_len = ea_get_int(pupdate->proto_attr, &ea_bgp_remote_open_msg_len, 0);
-      bmp_peer_up(proto_state_table->attrs[id], tx_open_msg, l_len, rx_open_msg, r_len);
+      bmp_peer_up_(p, proto_state_table->attrs[id], tx_open_msg, l_len, rx_open_msg, r_len);
+
+      /* !!! or bmp_peer_down_() or ignore if irrelevant */
     }
 	    
 	    
@@ -1364,7 +1349,7 @@ fc_for_bmp_recipient(void *rec)
 }
 
 void
-create_bmp_recipient(struct proto *P)
+create_bmp_recipient(struct bmp_proto *p)
 {
   struct lfjour_recipient *r = mb_allocz(&root_pool, sizeof(struct lfjour_recipient));
   log("recipient %x", r);
@@ -1436,7 +1421,7 @@ bmp_start(struct proto *P)
   tm_start(p->connect_retry_timer, CONNECT_INIT_TIME);
 
   log("end of start locked %i", locking_stack.service);
-  create_bmp_recipient(P);
+  create_bmp_recipient(p);
   return PS_START;
 }
 
diff --git a/proto/bmp/bmp.h b/proto/bmp/bmp.h
index cb691f86..ed1ee7f7 100644
--- a/proto/bmp/bmp.h
+++ b/proto/bmp/bmp.h
@@ -73,6 +73,9 @@ struct bmp_proto {
   list update_msg_queue;           // Stores all composed BGP UPDATE MSGs
   bool started;                    // Flag that stores running status of BMP instance
   int sock_err;                    // Last socket error code
+
+  struct lfjour_recipient proto_state_reader; // Reader of protocol states
+  event proto_state_changed;
 };
 
 struct bmp_peer {