]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
mrt.c: period mrt logging works (but routes in v3 seem to have less attributes)
authorKaterina Kubecova <katerina.kubecova@nic.cz>
Tue, 18 Jun 2024 13:33:07 +0000 (15:33 +0200)
committerKaterina Kubecova <katerina.kubecova@nic.cz>
Mon, 24 Jun 2024 07:42:03 +0000 (09:42 +0200)
mrt: mrt looks working

mrt: mrt looks working

mrt: mrt looks workingfrom both period and cli

mrt: mrt looks workingfrom both period and from cli

mrt: mrt looks workingfrom both period and from cli

lib/io-loop.h
lib/route.h
nest/proto.c
nest/protocol.h
nest/rt-attr.c
proto/bgp/attrs.c
proto/bgp/bgp.c
proto/bgp/bgp.h
proto/mrt/mrt.c
proto/mrt/mrt.h
sysdep/unix/io-loop.c

index 6c9465314f82e692857b89d3e06864a3c5a7b132..852b9793e027b4c2a6761a2f626290c0f298a58b 100644 (file)
@@ -19,6 +19,9 @@ extern struct birdloop main_birdloop;
 /* Currently running birdloop */
 extern _Thread_local struct birdloop *this_birdloop;
 
+/* The metaloop connected with thread */
+extern _Thread_local struct birdloop *this_metaloop;
+
 /* Check that the task has enough time to do a bit more */
 _Bool task_still_in_limit(void);
 
index 7087386da285c28048670ff50616deffe319d264..d29c93ec4ecddf2e6fcde75517cc8d688d4a80dc 100644 (file)
@@ -445,9 +445,12 @@ extern struct ea_class ea_gen_from;
 extern struct ea_class ea_gen_mpls_label,
        ea_gen_mpls_policy, ea_gen_mpls_class;
 
+/* protocol journal attributes */
 extern struct ea_class ea_proto_name, ea_proto_protocol_name, ea_proto_table,
        ea_proto_state, ea_proto_old_state, ea_proto_last_modified, ea_proto_info,
        ea_proto_id, ea_proto_deleted;
+/* bgp protocol journal attributes */
+extern struct ea_class ea_proto_bgp_rem_id, ea_proto_bgp_rem_as, ea_proto_bgp_rem_ip;
 
 /* Source: An old method to devise the route source protocol and kind.
  * To be superseded in a near future by something more informative. */
index 43f61aec2540bbe1a2d21a3cfd54bc0bcf05639e..cb4ccc429b6b8292f2aead0c0cb1c34b3866b98c 100644 (file)
@@ -22,6 +22,7 @@
 #include "nest/cli.h"
 #include "filter/filter.h"
 #include "filter/f-inst.h"
+#include "proto/bgp/bgp.h"
 
 pool *proto_pool;
 static TLIST_LIST(proto) global_proto_list;
@@ -2800,9 +2801,8 @@ protos_attr_field_grow(void)
 }
 
 void
-cleanup_journal_item(struct lfjour * UNUSED, struct lfjour_item *i)
+cleanup_journal_item(struct lfjour * journal UNUSED, struct lfjour_item *i)
 {
-  log("clean item");
   struct proto_pending_update *pupdate = SKIP_BACK(struct proto_pending_update, li, i);
   ea_free_later(pupdate->old_attr);
   eattr *new_ea = ea_find(pupdate->proto_attr, &ea_proto_deleted);
@@ -2811,7 +2811,7 @@ cleanup_journal_item(struct lfjour * UNUSED, struct lfjour_item *i)
 }
 
 void
-after_journal_birdloop_stop(void* UNUSED){}
+after_journal_birdloop_stop(void* arg UNUSED){}
 
 void
 init_proto_journal(void)
@@ -2831,9 +2831,12 @@ init_proto_journal(void)
 ea_list *
 proto_state_to_eattr(struct proto *p, int old_state, int proto_deleting)
 {
+  int eatt_len = 8;
+  if (p->proto == &proto_bgp)
+    eatt_len += 3;
   struct {
        ea_list l;
-       eattr a[8];
+       eattr a[eatt_len];
   } eattrs;
 
   eattrs.l = (ea_list) {};
@@ -2846,6 +2849,8 @@ proto_state_to_eattr(struct proto *p, int old_state, int proto_deleting)
   eattrs.a[eattrs.l.count++] = EA_LITERAL_STORE_ADATA(&ea_proto_last_modified, 0, &p->last_state_change, sizeof(btime));
   eattrs.a[eattrs.l.count++] = EA_LITERAL_EMBEDDED(&ea_proto_id, 0, p->id);
   eattrs.a[eattrs.l.count++] = EA_LITERAL_EMBEDDED(&ea_proto_deleted, 0, proto_deleting);
+  if (p->proto == &proto_bgp)
+    bgp_state_to_eattr(p, &eattrs.l, eattrs.a);
   byte buf[256];
   buf[0] = 0;
   if (p->proto->get_status)
@@ -2861,10 +2866,6 @@ proto_journal_state_changed(ea_list *attr, ea_list *old_attr, struct proto *p)
   struct proto_pending_update *pupdate = SKIP_BACK(struct proto_pending_update, li, lfjour_push_prepare(proto_journal));
   if (!pupdate)
   {
-    log("no recievers");
-    //if (free_add_data)
-    //  free_add_data(add_data);
-    log("returning");
     UNLOCK_DOMAIN(rtable, proto_journal_domain);
     return;
   }
@@ -2875,7 +2876,6 @@ proto_journal_state_changed(ea_list *attr, ea_list *old_attr, struct proto *p)
     .protocol = p
   };
   lfjour_push_commit(proto_journal);
-  log("in journal state change, proto %s, jfjour %i - pushed", p->name, proto_journal);
   UNLOCK_DOMAIN(rtable, proto_journal_domain);
 }
 
@@ -2932,6 +2932,5 @@ create_dummy_recipient(void)
   LOCK_DOMAIN(rtable, proto_journal_domain);
   lfjour_register(proto_journal, r);
   UNLOCK_DOMAIN(rtable, proto_journal_domain);
-  log("recipient created r %i j %i", r, proto_journal);
   dummy_log_proto_attr_list();
 }
index 06b0b2b5746a1ca48b15ed4e4745c924f4b14a11..47050bd7d47fc120aa69728900d65d6fb068e917 100644 (file)
@@ -93,6 +93,7 @@ extern struct protocol
   proto_ospf, proto_l3vpn, proto_aggregator,
   proto_pipe, proto_bgp, proto_bmp, proto_bfd, proto_babel, proto_rpki;
 
+void bgp_state_to_eattr(struct proto *P, ea_list *l, eattr *attributes);
 /*
  *     Routing Protocol Instance
  */
index 0be51efb03465921127344caf9d4828752d48dbb..16be0d5ec7ef7c9af38b013193f5b6b724c9f947 100644 (file)
@@ -1811,6 +1811,21 @@ struct ea_class ea_proto_id = {
   .type = T_INT,
 };
 
+struct ea_class ea_proto_bgp_rem_id = {
+  .name = "proto_bgp_rem_id",
+  .type = T_INT,
+};
+
+struct ea_class ea_proto_bgp_rem_as = {
+  .name = "proto_bgp_rem_as",
+  .type = T_INT,
+};
+
+struct ea_class ea_proto_bgp_rem_ip = {
+  .name = "proto_bgp_rem_ip",
+  .type = T_IP,
+};
+
 /**
  * rta_init - initialize route attribute cache
  *
@@ -1866,6 +1881,11 @@ rta_init(void)
   ea_register_init(&ea_proto_info);
   ea_register_init(&ea_proto_id);
   ea_register_init(&ea_proto_deleted);
+
+  /* Protocol bgp attributes */
+  ea_register_init(&ea_proto_bgp_rem_id);
+  ea_register_init(&ea_proto_bgp_rem_as);
+  ea_register_init(&ea_proto_bgp_rem_ip);
 }
 
 /*
index 80bedb31dcc29460163dfee6d11bd423f1e6aa99..230fb8edb8488136d944b7b29fc0b363e7c72029 100644 (file)
@@ -1318,7 +1318,10 @@ static inline int
 bgp_encode_attr(struct bgp_write_state *s, eattr *a, byte *buf, uint size)
 {
   const union bgp_attr_desc *desc = bgp_find_attr_desc(a);
-  ASSERT_DIE(desc);
+  if (s->ignore_non_bgp_attrs == 0)
+    ASSERT_DIE(desc);
+  else if (desc == NULL)
+    return 0;
   return desc->encode(s, a, buf, size);
 }
 
index 437201e957a9ace397987f705d72d92a1d2a3265..4063782ecc2e4a5f2934be293e1088d8b227d155 100644 (file)
@@ -2574,6 +2574,15 @@ bgp_get_status(struct proto *P, byte *buf)
     bsprintf(buf, "%-14s%s%s", bgp_state_dsc(p), err1, err2);
 }
 
+void
+bgp_state_to_eattr(struct proto *P, ea_list *l, eattr *attributes)
+{
+  struct bgp_proto *p = (struct bgp_proto *) P;
+  attributes[l->count++] = EA_LITERAL_EMBEDDED(&ea_proto_bgp_rem_id, 0, p->remote_id);
+  attributes[l->count++] = EA_LITERAL_EMBEDDED(&ea_proto_bgp_rem_as, 0, p->remote_as);
+  attributes[l->count++] = EA_LITERAL_STORE_ADATA(&ea_proto_bgp_rem_ip, 0, &p->remote_ip, sizeof(ip_addr));
+}
+
 static void
 bgp_show_afis(int code, char *s, u32 *afis, uint count)
 {
index e61873b9af2d657486e9fafc1de0654b4f2a21e1..61fece84f3db2e419a45917bfcd3d7507ebea2f4 100644 (file)
@@ -498,6 +498,7 @@ struct bgp_write_state {
   int as4_session;
   int add_path;
   int mpls;
+  int ignore_non_bgp_attrs;
 
   eattr *mp_next_hop;
   const adata *mpls_labels;
index f97e257174fa5f15f0a991954ef55e3bc8570e59..fc1914d53f9f07006f087b31e7a4c4179fb6d5e2 100644 (file)
 
 #include "mrt.h"
 
+#include "lib/io-loop.h"
 #include "nest/cli.h"
 #include "filter/filter.h"
 #include "proto/bgp/bgp.h"
 #include "sysdep/unix/unix.h"
+#include "sysdep/unix/io-loop.h"
 
 
 #ifdef PATH_MAX
@@ -234,10 +236,6 @@ mrt_next_table_(rtable *tab, rtable *tab_ptr, const char *pattern)
     return !tab ? tab_ptr : NULL;
 
   /* Walk routing_tables list, starting after tab (if non-NULL) */
-  log("tab is? %i", tab);
-  if (tab){
-    log("its node is %s", tab->name);
-    log("next is %i", tab->n.next);}
   for (node *tn = tab ? tab->n.next : HEAD(routing_tables);
        NODE_VALID(tn);
        tn = tn->next)
@@ -260,12 +258,20 @@ mrt_next_table(struct mrt_table_dump_state *s)
     RT_LOCKED(get_tab(s), tab)
       rt_unlock_table(tab);
 
+  if (tab == NULL)
+  {
+    s->ipv4 = 0;
+    return NULL;
+  }
   s->table->head = &tab->n;
   s->ipv4 = tab ? (tab->addr_type == NET_IP4) : 0;
 
   if (s->table->head)
-    RT_LOCKED(get_tab(s), tab)
+  {
+    rtable *t = get_tab(s);
+    RT_LOCKED(t, tab)
       rt_lock_table(tab);
+  }
 
   return get_tab(s);
 }
@@ -286,7 +292,7 @@ mrt_open_file(struct mrt_table_dump_state *s)
     return 0;
   }
 
-  s->file = rf_open(s->pool, name, RF_APPEND, -1); //TODO: is this correct? Do we want to limit appending file (or does it even make sence for append)? 
+  s->file = rf_open(s->pool, name, RF_APPEND, 0);
   if (!s->file)
   {
     mrt_log(s, "Unable to open MRT file '%s': %m", name);
@@ -374,15 +380,30 @@ mrt_peer_table_dump(struct mrt_table_dump_state *s)
   /* 0 is fake peer for non-BGP routes */
   mrt_peer_table_entry(s, 0, 0, IPA_NONE);
 
-/*#ifdef CONFIG_BGP
-  struct proto *P;
-  WALK_LIST(P, proto_list)
-    if ((P->proto == &proto_bgp) && (P->proto_state != PS_DOWN))
+#ifdef CONFIG_BGP
+  for(u32 i = 0; i<proto_attributes->length; i++)
+  {
+    rcu_read_lock();
+    ea_list *eal = proto_attributes->attrs[i];
+    if (eal)
+      ea_free_later(ea_ref(eal));
+    else
+    {
+      rcu_read_unlock();
+      continue;
+    }
+    rcu_read_unlock();
+    eattr *name = ea_find(proto_attributes->attrs[i], &ea_proto_protocol_name);
+    eattr *state = ea_find(proto_attributes->attrs[i], &ea_proto_state);
+    if ((strcmp(name->u.ad->data, "BGP") == 0) && (state->u.i != PS_DOWN))
     {
-      struct bgp_proto *p = (void *) P;
-      mrt_peer_table_entry(s, p->remote_id, p->remote_as, p->remote_ip);
+      eattr *rem_id = ea_find(proto_attributes->attrs[i], &ea_proto_bgp_rem_id);
+      eattr *rem_as = ea_find(proto_attributes->attrs[i], &ea_proto_bgp_rem_as);
+      eattr *rem_ip = ea_find(proto_attributes->attrs[i], &ea_proto_bgp_rem_ip);
+      mrt_peer_table_entry(s, rem_id->u.i, rem_as->u.i, *((ip_addr*) rem_ip->u.ad->data));
     }
-#endif*/
+  }
+#endif
 
   /* Fix Peer Count */
   put_u16(s->buf.start + s->peer_count_offset, s->peer_count);
@@ -447,14 +468,15 @@ mrt_rib_table_entry_bgp_attrs(struct mrt_table_dump_state *s, rte *r)
     return;
 
   /* Attribute list must be normalized for bgp_encode_attrs() */
-  //if (!rta_is_cached(r->attrs))       rte has no attribute cached... this needs deeper sight into rte struct
-  //  eattrs = ea_normalize(eattrs, 0);
+  if (!r->attrs->stored)
+    eattrs = ea_normalize(eattrs, 0);
 
   mrt_buffer_need(b, MRT_ATTR_BUFFER_SIZE);
   byte *pos = b->pos;
 
   s->bws->mp_reach = !s->ipv4;
   s->bws->mp_next_hop = NULL;
+  s->bws->ignore_non_bgp_attrs = 1;
 
   /* Encode BGP attributes */
   int len = bgp_encode_attrs(s->bws, eattrs, pos, b->end);
@@ -527,7 +549,7 @@ mrt_rib_table_dump(struct mrt_table_dump_state *s, const struct rt_export_feed *
     (!add_path ? MRT_RIB_IPV6_UNICAST : MRT_RIB_IPV6_UNICAST_ADDPATH);
 
   mrt_init_message(&s->buf, MRT_TABLE_DUMP_V2, subtype);
-  mrt_rib_table_header(s, feed->block[0].net); // asi blbe, ale netusim
+  mrt_rib_table_header(s, feed->block[0].net);
 
   for (uint i = 0; i < feed->count_routes; i++)
   {
@@ -570,11 +592,9 @@ mrt_rib_table_dump(struct mrt_table_dump_state *s, const struct rt_export_feed *
 static struct mrt_table_dump_state *
 mrt_table_dump_init(pool *pp)
 {
-  //LOCK_DOMAIN(proto, &pp->domain);
-  pool *pool = rp_new(pp, pp->domain, "MRT Table Dump"); //this domain is maybe not the correct one, but.
+  pool *pool = rp_new(pp, pp->domain, "MRT Table Dump");
   struct mrt_table_dump_state *s = mb_allocz(pool, sizeof(struct mrt_table_dump_state));
   s->table = (list*)mb_allocz(pool, sizeof(list));
-  //UNLOCK_DOMAIN(proto, &pp->domain);
 
   s->pool = pool;
   s->linpool = lp_new(pool);
@@ -593,19 +613,6 @@ mrt_table_dump_init(pool *pp)
 static void
 mrt_table_dump_free(struct mrt_table_dump_state *s)
 {
-  /*if (s->table)
-    RT_LOCKED(s->table, tab)
-    {
-      if (s->table_open)
-       FIB_ITERATE_UNLINK(&s->fit, &tab->fib); //table seems not to have fib iterator anymore
-
-      rt_unlock_table(tab);
-    }*/
-
- /* if (s->table_ptr)       why? Lock and unlock?
-    RT_LOCKED(s->table_ptr, tab)
-      rt_unlock_table(tab); */
-
   config_del_obstacle(s->config);
 
   rp_free(s->pool);
@@ -630,7 +637,6 @@ mrt_table_dump_step(struct mrt_table_dump_state *s)
 
     mrt_peer_table_dump(s);
 
-    // FIB_ITERATE_INIT(&s->fit, &tab->fib);  tab has no fib
     s->table_open = 1;
 
   step:
@@ -639,29 +645,20 @@ mrt_table_dump_step(struct mrt_table_dump_state *s)
     };
     RT_LOCKED(get_tab(s), tab)
     rt_feeder_subscribe(&tab->export_all, &feeder);
-    //FIB_ITERATE_START(&tab->fib, &s->fit, net, n)
     RT_FEED_WALK(&feeder, route_feed)
     {
-     // RT_LOCKED(t, tab)
-      {
-
-      if (s->max < 0) //but what in WALK?
-      {
-       //FIB_ITERATE_PUT(&s->fit); //vracime puvodni stav. asi. ale spis se ma tohle smazat
-       return 0;
-      }
-
+      if (s->max < 0)
+        return 0;
       /* With Always ADD_PATH option, we jump directly to second phase */
       s->want_add_path = s->always_add_path;
 
       if (s->want_add_path == 0)
-       mrt_rib_table_dump(s, route_feed, 0);
+        mrt_rib_table_dump(s, route_feed, 0);
 
       if (s->want_add_path == 1)
-       mrt_rib_table_dump(s, route_feed, 1);
-      }
+        mrt_rib_table_dump(s, route_feed, 1);
     }
-    //FIB_ITERATE_END;*/
+
     s->table_open = 0;
 
     mrt_close_file(s);
@@ -792,8 +789,10 @@ mrt_bgp_buffer(void)
   /* Static buffer for BGP4MP dump, TODO: change to use MRT protocol */
   static buffer b;
 
+  ASSERT(this_metaloop);
+  ASSERT(this_metaloop->pool);
   if (!b.start)
-    mrt_buffer_init(&b, &root_pool, 1024);
+    mrt_buffer_init(&b, this_metaloop->pool, 1024);
 
   return &b;
 }
index 1ef75abcbbe02b7d3c0ef99f510a44c1d4a3c2b7..925c88a49530be5815a5871a8298eca0947aafc7 100644 (file)
@@ -17,7 +17,6 @@
 #include "lib/event.h"
 #include "lib/hash.h"
 
-
 struct mrt_config {
   struct proto_config c;
 
index aa73865e3fc1a9d73c4fae47fba2906766e95914..d1f720187d8fe14889ee6a0db2cee88498641989 100644 (file)
@@ -789,7 +789,7 @@ bird_thread_main(void *arg)
   account_to(&thr->overhead);
 
   birdloop_enter(thr->meta);
-  this_birdloop = thr->meta;
+  this_birdloop = this_metaloop = thr->meta;
 
   tmp_init(thr->pool);
   init_list(&thr->loops);
@@ -1354,6 +1354,7 @@ _Bool task_still_in_limit(void)
 static struct bird_thread main_thread;
 struct birdloop main_birdloop = { .thread = &main_thread, };
 _Thread_local struct birdloop *this_birdloop;
+_Thread_local struct birdloop *this_metaloop;
 
 static void birdloop_enter_locked(struct birdloop *loop);
 
@@ -1381,7 +1382,7 @@ birdloop_init(void)
   timers_init(&main_birdloop.time, &root_pool);
 
   birdloop_enter_locked(&main_birdloop);
-  this_birdloop = &main_birdloop;
+  this_birdloop = this_metaloop = &main_birdloop;
   this_thread = &main_thread;
 
   defer_init(lp_new(&root_pool));
@@ -1430,7 +1431,7 @@ birdloop_stop_internal(struct birdloop *loop)
   ASSERT_DIE(!ev_active(&loop->event));
   loop->ping_pending = 0;
   account_to(&this_thread->overhead);
-  this_birdloop = this_thread->meta;
+  this_birdloop = this_metaloop = this_thread->meta;
   birdloop_leave(loop);
 
   /* Request local socket reload */
@@ -1451,7 +1452,7 @@ birdloop_run(void *_loop)
   struct birdloop *loop = _loop;
   account_to(&loop->locking);
   birdloop_enter(loop);
-  this_birdloop = loop;
+  this_birdloop = this_metaloop = loop;
 
   /* Wait until pingers end to wait for all events to actually arrive */
   for (u32 ltt;
@@ -1506,7 +1507,7 @@ birdloop_run(void *_loop)
   loop->sock_changed = 0;
 
   account_to(&this_thread->overhead);
-  this_birdloop = this_thread->meta;
+  this_birdloop = this_metaloop = this_thread->meta;
   birdloop_leave(loop);
 }