From 344dc0773ccdcae4006412acea124ec05a16c782 Mon Sep 17 00:00:00 2001 From: Katerina Kubecova Date: Wed, 4 Sep 2024 13:48:40 +0200 Subject: [PATCH] looks like i understood it wrong... So lets save old and change it.now, the hooks do not work, request is at wrong place and there is chaos between import and main table --- proto/bmp/bmp.c | 114 ++++++++++++++++++++++++++++++++++++++++++++++-- proto/bmp/bmp.h | 2 + 2 files changed, 112 insertions(+), 4 deletions(-) diff --git a/proto/bmp/bmp.c b/proto/bmp/bmp.c index dafa67b2..39e95c10 100644 --- a/proto/bmp/bmp.c +++ b/proto/bmp/bmp.c @@ -48,6 +48,7 @@ #include "filter/filter.h" #include "proto/bgp/bgp.h" #include "sysdep/unix/unix.h" +#include "sysdep/unix/io-loop.h" #include "lib/event.h" #include "lib/ip.h" #include "lib/lists.h" @@ -214,6 +215,7 @@ enum bmp_term_reason { static void bmp_connected(struct birdsock *sk); static void bmp_sock_err(sock *sk, int err); static void bmp_close_socket(struct bmp_proto *p); +static void bmp_rt_notify_exp_req(void *p_); static void bmp_send_peer_up_notif_msg(struct bmp_proto *p, ea_list *bgp, @@ -526,6 +528,40 @@ bmp_add_table(struct bmp_proto *p, rtable *tab) return bt; } +static struct bmp_table * +bmp_add_table_exp_req(struct bmp_proto *p, rtable *tab) +{ + struct bmp_table *bt = mb_allocz(p->p.pool, sizeof(struct bmp_table)); + log("adding table %x", bt); + bt->table = tab; + rt_lock_table(bt->table); + + HASH_INSERT(p->table_map, HASH_TABLE, bt); + + event *e = mb_allocz(p->p.pool, sizeof(struct event)); + e->hook = bmp_rt_notify_exp_req; + e->data = p; + + p->out_req = (struct rt_export_request) { + .name = mb_sprintf(p->p.pool, "%s.exp_request", p->p.name), + .r = (struct lfjour_recipient) { + .target = &p->p.loop->event_list, + .event = e, + }, + .pool = p->p.pool, + //.feeder.prefilter = { + // .mode = c->out_subprefix ? TE_ADDR_IN : TE_ADDR_NONE, + // .addr = c->out_subprefix, + //}, + .trace_routes = p->p.debug, + //.dump = channel_dump_export_req, + //.fed = channel_export_fed, + }; + rt_export_subscribe(tab, all, &p->out_req); + + return bt; +} + static void bmp_remove_table(struct bmp_proto *p, struct bmp_table *bt) { @@ -543,14 +579,31 @@ bmp_remove_table(struct bmp_proto *p, struct bmp_table *bt) mb_free(bt); } +static void +bmp_remove_table_rt(struct bmp_proto *p, struct bmp_table *bt) +{ + log("removing table - bmp table %x chann %x, (subscr %x uc %x)",bt, bt->channel, &bt->channel->roa_subscriptions, &bt->uc); + channel_set_state(bt->channel, CS_STOP); + channel_set_state(bt->channel, CS_DOWN); + rt_export_unsubscribe(all, &p->out_req); + + HASH_REMOVE(p->table_map, HASH_TABLE, bt); + + rt_unlock_table(bt->table); + bt->table = NULL; + + log("free table %x", bt); + mb_free(bt); +} + static inline struct bmp_table *bmp_get_table(struct bmp_proto *p, rtable *tab) -{ return bmp_find_table(p, tab) ?: bmp_add_table(p, tab); } +{ return bmp_find_table(p, tab) ?: bmp_add_table_exp_req(p, tab); } static inline void bmp_lock_table(struct bmp_proto *p UNUSED, struct bmp_table *bt) { bt->uc++; } static inline void bmp_unlock_table(struct bmp_proto *p, struct bmp_table *bt) -{ bt->uc--; if (!bt->uc) bmp_remove_table(p, bt); } ////AUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU +{ bt->uc--; if (!bt->uc) bmp_remove_table_rt(p, bt); } // TODO: should it be atomic? /* @@ -638,7 +691,7 @@ bmp_add_peer(struct bmp_proto *p, ea_list *bgp_attr) HASH_INSERT(p->peer_map, HASH_PEER, bp); - int proto_id = ea_get_int(bgp_attr, &ea_proto_id, 0); + //int proto_id = ea_get_int(bgp_attr, &ea_proto_id, 0); #if 0 /* XXXXX FIXME */ struct channel_attrs *chan_attr; @@ -1092,6 +1145,60 @@ bmp_rt_notify(struct proto *P, struct channel *c, const net_addr *net, bmp_route_monitor_notify(p, bgp, bs, net, new, (new ?: old)->src); } +static void +bmp_rt_notify_exp_req(void *p_) +{ + log("ok in notify exp req"); + struct bmp_proto *p = (struct bmp_proto*) p_; + RT_EXPORT_WALK(&p->out_req, u) //const struct rt_export_union *_u; + { + switch (u->kind) + { + case RT_EXPORT_STOP: + bug("Main table export stopped"); + + case RT_EXPORT_FEED: + uint oldpos = 0; + while ((oldpos < u->feed->count_routes) && !(u->feed->block[oldpos].flags & REF_OBSOLETE)) + oldpos++; + + /* Send updates one after another */ + for (uint i = 0; i < oldpos; i++) + { + rte *new = &u->feed->block[i]; + struct bgp_proto *bgp = (struct bgp_proto*) SKIP_BACK(struct proto, sources, new->src->owner); + struct bgp_channel *bc = (struct bgp_channel *) SKIP_BACK(struct channel, in_req, new->sender->req); + struct bgp_channel *src = SKIP_BACK(struct bgp_channel, c.in_req, new->sender->req); + bool policy = (bc->c.table == src->c.table); //TODO? + struct bmp_stream *bs = bmp_find_stream(p, bgp, src->afi, policy); + if (!bs) + { + log("bmp stream not found in p %i", p); + return; + } + log("bmp stream found"); + bmp_route_monitor_notify(p, bgp, bs, new->net, new, new->src); + } + break; + case RT_EXPORT_UPDATE: + const rte *new = u->update->new; + const rte *old = u->update->old; + struct bgp_proto *bgp = (struct bgp_proto*) SKIP_BACK(struct proto, sources, new->src->owner); + struct bgp_channel *bc = (struct bgp_channel *) SKIP_BACK(struct channel, in_req, new->sender->req); + struct bgp_channel *src = SKIP_BACK(struct bgp_channel, c.in_req, (new ?: old)->sender->req); + bool policy = (bc->c.table == src->c.table); //TODO? + struct bmp_stream *bs = bmp_find_stream(p, bgp, src->afi, policy); + if (!bs) + { + log("bmp stream not found in p %i", p); + return; + } + log("bmp stream found"); + bmp_route_monitor_notify(p, bgp, bs, new->net, new, (new ?: old)->src); + } + } +} + static void bmp_feed_end(struct channel *c) { @@ -1338,7 +1445,6 @@ fc_for_bmp_recipient(void *_p) int r_len = ea_get_int(pupdate->proto_attr, &ea_bgp_remote_open_msg_len, 0); bmp_peer_up_(p, proto_state_table->attrs[id], true, tx_open_msg, l_len, rx_open_msg, r_len); - /* !!! or bmp_peer_down_() or ignore if irrelevant */ } else if (ea_get_int(pupdate->proto_attr, &ea_bgp_close_bmp_set, 0)) { diff --git a/proto/bmp/bmp.h b/proto/bmp/bmp.h index 3ca47402..e9a7c22f 100644 --- a/proto/bmp/bmp.h +++ b/proto/bmp/bmp.h @@ -76,6 +76,8 @@ struct bmp_proto { struct lfjour_recipient proto_state_reader; // Reader of protocol states event proto_state_changed; int lf_jour_inited; + + struct rt_export_request out_req; }; struct bmp_peer {