From fb2b3836ea6fd3f01c2be0efa86ce124779315d0 Mon Sep 17 00:00:00 2001 From: Maria Matejka Date: Wed, 28 Aug 2024 16:33:58 +0200 Subject: [PATCH] mrt compile fixup after rebase --- proto/bgp/packets.c | 4 ++-- proto/mrt/mrt.c | 28 ++++++++++++++++------------ proto/mrt/mrt.h | 8 ++++---- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/proto/bgp/packets.c b/proto/bgp/packets.c index da47169c..707da8fe 100644 --- a/proto/bgp/packets.c +++ b/proto/bgp/packets.c @@ -145,7 +145,7 @@ bgp_dump_message(struct bgp_conn *conn, byte *pkt, uint len) d.msg_len = len; d.add_path = bgp_estimate_add_path(conn->bgp, pkt, len); - mrt_dump_bgp_message(&d); + mrt_dump_bgp_message(&d, conn->bgp->p.pool); } void @@ -157,7 +157,7 @@ bgp_dump_state_change(struct bgp_conn *conn, uint old, uint new) d.old_state = old; d.new_state = new; - mrt_dump_bgp_state_change(&d); + mrt_dump_bgp_state_change(&d, conn->bgp->p.pool); } static byte * diff --git a/proto/mrt/mrt.c b/proto/mrt/mrt.c index 7e1e0b40..cd9db1c6 100644 --- a/proto/mrt/mrt.c +++ b/proto/mrt/mrt.c @@ -83,6 +83,13 @@ mrt_buffer_init(buffer *b, pool *pool, size_t n) b->end = b->start + n; } +static void +mrt_buffer_free(buffer *b) +{ + mb_free(b->start); + b->start = b->pos = b->end = NULL; +} + static void mrt_buffer_grow(buffer *b, size_t n) { @@ -786,17 +793,12 @@ mrt_dump_cmd(struct mrt_dump_data *d) */ static buffer * -mrt_bgp_buffer(void) +mrt_bgp_buffer(pool *p) { /* Static buffer for BGP4MP dump, TODO: change to use MRT protocol */ - static buffer b; - - ASSERT(this_metaloop); - log("loop in mrt %x, pool %i (main loop is %x, pool %i)", this_metaloop, this_metaloop->pool, &main_birdloop, main_birdloop.pool); - ASSERT(this_metaloop->pool); - if (!b.start) - mrt_buffer_init(&b, this_metaloop->pool, 1024); + static _Thread_local buffer b; + mrt_buffer_init(&b, p, 1024); return &b; } @@ -830,7 +832,7 @@ mrt_bgp_header(buffer *b, struct mrt_bgp_data *d) } void -mrt_dump_bgp_message(struct mrt_bgp_data *d) +mrt_dump_bgp_message(struct mrt_bgp_data *d, pool *p) { const u16 subtypes[] = { MRT_BGP4MP_MESSAGE, MRT_BGP4MP_MESSAGE_AS4, @@ -839,15 +841,16 @@ mrt_dump_bgp_message(struct mrt_bgp_data *d) MRT_BGP4MP_MESSAGE_LOCAL_ADDPATH, MRT_BGP4MP_MESSAGE_AS4_LOCAL_ADDPATH, }; - buffer *b = mrt_bgp_buffer(); + buffer *b = mrt_bgp_buffer(p); mrt_init_message(b, MRT_BGP4MP, subtypes[d->as4 + 4*d->add_path]); mrt_bgp_header(b, d); mrt_put_data(b, d->message, d->msg_len); mrt_dump_message(b, rf_fileno(OBSREF_GET(config)->mrtdump_file)); + mrt_buffer_free(b); } void -mrt_dump_bgp_state_change(struct mrt_bgp_data *d) +mrt_dump_bgp_state_change(struct mrt_bgp_data *d, pool *p) { /* Convert state from our BS_* values to values used in MRTDump */ const u16 states[BS_MAX] = {1, 2, 3, 4, 5, 6, 1}; @@ -858,12 +861,13 @@ mrt_dump_bgp_state_change(struct mrt_bgp_data *d) /* Always use AS4 mode for STATE_CHANGE */ d->as4 = 1; - buffer *b = mrt_bgp_buffer(); + buffer *b = mrt_bgp_buffer(p); mrt_init_message(b, MRT_BGP4MP, MRT_BGP4MP_STATE_CHANGE_AS4); mrt_bgp_header(b, d); mrt_put_u16(b, states[d->old_state]); mrt_put_u16(b, states[d->new_state]); mrt_dump_message(b, rf_fileno(OBSREF_GET(config)->mrtdump_file)); + mrt_buffer_free(b); } diff --git a/proto/mrt/mrt.h b/proto/mrt/mrt.h index c1ba0530..4d31b0ad 100644 --- a/proto/mrt/mrt.h +++ b/proto/mrt/mrt.h @@ -146,12 +146,12 @@ struct mrt_bgp_data { #ifdef CONFIG_MRT void mrt_dump_cmd(struct mrt_dump_data *d); -void mrt_dump_bgp_message(struct mrt_bgp_data *d); -void mrt_dump_bgp_state_change(struct mrt_bgp_data *d); +void mrt_dump_bgp_message(struct mrt_bgp_data *d, pool *p); +void mrt_dump_bgp_state_change(struct mrt_bgp_data *d, pool *p); void mrt_check_config(struct proto_config *C); #else -static inline void mrt_dump_bgp_message(struct mrt_bgp_data *d UNUSED) { } -static inline void mrt_dump_bgp_state_change(struct mrt_bgp_data *d UNUSED) { } +static inline void mrt_dump_bgp_message(struct mrt_bgp_data *d UNUSED, pool *p UNUSED) { } +static inline void mrt_dump_bgp_state_change(struct mrt_bgp_data *d UNUSED, pool *p UNUSED) { } #endif #endif /* _BIRD_MRT_H_ */