From 034647bb05007b461e9a2cd86cacee020ae71cad Mon Sep 17 00:00:00 2001 From: Katerina Kubecova Date: Thu, 11 Jul 2024 14:43:32 +0200 Subject: [PATCH] wip bmp: compilable version, but mrt test detected some peer problems, bmp not tested --- configure.ac | 1 - filter/data.c | 2 - lib/route.h | 6 +-- lib/type.h | 2 - nest/proto.c | 11 ++---- nest/rt-attr.c | 42 ++++++++++++++++---- proto/bgp/bgp.c | 22 ++++++----- proto/bgp/bgp.h | 20 +++++----- proto/bgp/packets.c | 44 +++++++++++++++++---- proto/bmp/bmp.c | 96 ++++++++++++++++++++++++--------------------- proto/bmp/bmp.h | 2 +- proto/mrt/mrt.c | 16 ++++---- proto/mrt/mrt.h | 2 +- 13 files changed, 165 insertions(+), 101 deletions(-) diff --git a/configure.ac b/configure.ac index aaf4d851..25e1b159 100644 --- a/configure.ac +++ b/configure.ac @@ -308,7 +308,6 @@ if test "$enable_mpls_kernel" != no ; then fi fi -<<<<<<< HEAD BIRD_CHECK_CLOCK(CLOCK_MONOTONIC) if test "$bird_cv_clock_CLOCK_MONOTONIC" != yes ; then AC_MSG_ERROR([Monotonic clock not supported]) diff --git a/filter/data.c b/filter/data.c index db4a6bbe..6311ac30 100644 --- a/filter/data.c +++ b/filter/data.c @@ -654,8 +654,6 @@ mem_hash_mix_f_val(u64 *h, struct f_val *v) case T_PTR: case T_ENUM_STATE: case T_BTIME: - case T_POINTER: - case T_BGP_CONN: bug("Invalid type %s in f_val hashing", f_type_name(v->type)); } } diff --git a/lib/route.h b/lib/route.h index 2def61c3..af7cca6b 100644 --- a/lib/route.h +++ b/lib/route.h @@ -370,7 +370,7 @@ void ea_list_copy(ea_list *dest, ea_list *src, uint size); #define EA_LITERAL_STORE_PTR(_class, _flags, _ptr) ({ \ btype _type = (_class)->type; \ - ASSERT_DIE(!(_type == T_PTR)); \ + ASSERT_DIE(_type == T_PTR); \ EA_LITERAL_GENERIC((_class)->id, _type, _flags, .u.v_ptr = _ptr); \ }) @@ -469,9 +469,9 @@ extern struct ea_class ea_gen_mpls_label, /* protocol journal attributes */ extern struct ea_class ea_name, ea_protocol_name, ea_protocol_type, ea_table, ea_state, ea_old_state, ea_last_modified, ea_info, ea_proto_id, - ea_channel_id, ea_deleted, ea_bgp_conn, ea_rtable, ea_bgp_afi; + ea_channel_id, ea_deleted, ea_bgp_conn, ea_bgp_in_conn, ea_bgp_out_conn, ea_rtable, ea_bgp_afi; /* bgp protocol journal attributes */ -extern struct ea_class ea_bgp_rem_id, ea_bgp_rem_as, ea_bgp_rem_ip; +extern struct ea_class ea_bgp_rem_id, ea_bgp_rem_as, ea_bgp_loc_as, ea_bgp_rem_ip, ea_bgp_peer_type; /* Source: An old method to devise the route source protocol and kind. * To be superseded in a near future by something more informative. */ diff --git a/lib/type.h b/lib/type.h index b09ed86f..135da81c 100644 --- a/lib/type.h +++ b/lib/type.h @@ -121,8 +121,6 @@ enum btype { /* protocol */ T_ENUM_STATE = 0xd1, T_BTIME = 0xd4, - T_POINTER = 0xd8, - T_BGP_CONN = 0xcb, } PACKED; typedef enum btype btype; diff --git a/nest/proto.c b/nest/proto.c index 933c4553..4f50ecaa 100644 --- a/nest/proto.c +++ b/nest/proto.c @@ -2503,7 +2503,7 @@ proto_cmd_show(struct proto *p, union cmd_arg verbose, int cnt) p->proto->get_status(p, buf); } const btime *time = (btime *)ea_get_adata(eal, &ea_last_modified)->data; - tm_format_time(tbuf, &config->tf_proto, *time); + tm_format_time(tbuf, &atomic_load_explicit(&global_runtime, memory_order_acquire)->tf_proto, *time); //todo readlock???? cli_msg(-1002, "%-10s %-10s %-10s %-6s %-12s %s", name, @@ -2922,14 +2922,14 @@ proto_state_to_eattr(struct proto *p, int old_state, int proto_deleting) { struct { ea_list l; - eattr a[15]; + eattr a[9+9]; } eattrs; eattrs.l = (ea_list) {}; eattrs.a[eattrs.l.count++] = EA_LITERAL_STORE_STRING(&ea_name, 0, p->name); //eattrs.a[eattrs.l.count++] = EA_LITERAL_STORE_STRING(&ea_protocol_name, 0, p->proto->name); this info is stored in ea_protocol_type - eattrs.a[eattrs.l.count++] = EA_LITERAL_STORE_ADATA(&ea_protocol_type, 0, &p->proto, sizeof(struct protocol *)); + eattrs.a[eattrs.l.count++] = EA_LITERAL_STORE_PTR(&ea_protocol_type, 0, p->proto); if (p->main_channel) eattrs.a[eattrs.l.count++] = EA_LITERAL_STORE_STRING(&ea_table, 0, p->main_channel->table->name); eattrs.a[eattrs.l.count++] = EA_LITERAL_EMBEDDED(&ea_state, 0, p->proto_state); @@ -2954,10 +2954,7 @@ channel_state_to_eattr(struct channel *ch, int proto_deleting) eattrs.a[eattrs.l.count++] = EA_LITERAL_EMBEDDED(&ea_proto_id, 0, ch->proto->id); eattrs.a[eattrs.l.count++] = EA_LITERAL_EMBEDDED(&ea_deleted, 0, proto_deleting); if (ch->table) - { - struct rtable_adata rad = (struct rtable_adata){.table = h->table}; - eattrs.a[eattrs.l.count++] = EA_LITERAL_STORE_ADATA(&ea_gen_rtable, 0, &rad, sizeof(rtable *)); - } + eattrs.a[eattrs.l.count++] = EA_LITERAL_STORE_PTR(&ea_rtable, 0, &ch->table); if (ch->proto->proto == &proto_bgp && ch != ch->proto->mpls_channel) { struct bgp_channel *bc = (struct bgp_channel *) ch; diff --git a/nest/rt-attr.c b/nest/rt-attr.c index e490ad70..1d3aa8d0 100644 --- a/nest/rt-attr.c +++ b/nest/rt-attr.c @@ -171,15 +171,15 @@ struct ea_class ea_gen_hostentry_version = { static void ea_gen_rtable_stored(const eattr *ea) { - struct rtable_adata *had = (struct rtable_adata *) ea->u.ptr; - rt_lock_table(had->table); + rtable *r = (rtable *) ea->u.v_ptr; + rt_lock_table(r); } static void ea_gen_rtable_freed(const eattr *ea) { - struct rtable_adata *had = (struct rtable_adata *) ea->u.ptr; - rt_unlock_table(had->table); + rtable *r = (rtable *) ea->u.v_ptr; + rt_unlock_table(r); } struct ea_class ea_gen_rtable = { @@ -1859,7 +1859,7 @@ struct ea_class ea_protocol_name = { struct ea_class ea_protocol_type = { .name = "proto_protocol_type", - .type = T_POINTER, + .type = T_PTR, }; struct ea_class ea_table = { @@ -1912,6 +1912,11 @@ struct ea_class ea_bgp_rem_as = { .type = T_INT, }; +struct ea_class ea_bgp_loc_as = { + .name = "proto_bgp_loc_as", + .type = T_INT, +}; + struct ea_class ea_bgp_rem_ip = { .name = "proto_bgp_rem_ip", .type = T_IP, @@ -1919,7 +1924,17 @@ struct ea_class ea_bgp_rem_ip = { struct ea_class ea_bgp_conn = { .name = "proto_bgp_rem_conn", - .type = T_BGP_CONN, + .type = T_PTR, +}; + +struct ea_class ea_bgp_in_conn = { + .name = "proto_bgp_rem_in_conn", + .type = T_PTR, +}; + +struct ea_class ea_bgp_out_conn = { + .name = "proto_bgp_rem_out_conn", + .type = T_PTR, }; struct ea_class ea_bgp_afi = { @@ -1927,6 +1942,16 @@ struct ea_class ea_bgp_afi = { .type = T_INT, }; +struct ea_class ea_bgp_peer_type = { + .name = "bgp_peer_type", + .type = T_INT, +}; + +struct ea_class ea_rtable = { + .name = "rtable", + .type = T_PTR, +}; + /** * rta_init - initialize route attribute cache * @@ -1984,11 +2009,14 @@ rta_init(void) /* Protocol bgp attributes */ ea_register_init(&ea_bgp_rem_id); ea_register_init(&ea_bgp_rem_as); + ea_register_init(&ea_bgp_loc_as); ea_register_init(&ea_bgp_rem_ip); ea_register_init(&ea_bgp_conn); + ea_register_init(&ea_bgp_in_conn); + ea_register_init(&ea_bgp_out_conn); ea_register_init(&ea_rtable); + ea_register_init(&ea_bgp_peer_type); ea_register_init(&ea_bgp_afi); - ea_register_init(&ea_gen_rtable); } /* diff --git a/proto/bgp/bgp.c b/proto/bgp/bgp.c index 222952a9..a19a3ea6 100644 --- a/proto/bgp/bgp.c +++ b/proto/bgp/bgp.c @@ -678,6 +678,9 @@ bgp_conn_enter_established_state(struct bgp_conn *conn) conn->sk->fast_rx = 0; p->conn = conn; + ea_list *eal = proto_state_table->attrs[p->p.id]; + ea_set_attr(&eal, EA_LITERAL_STORE_PTR(&ea_bgp_conn, 0, p->conn)); + proto_journal_state_push(eal, &p->p); p->last_error_class = 0; p->last_error_code = 0; @@ -795,7 +798,7 @@ bgp_conn_enter_established_state(struct bgp_conn *conn) proto_notify_state(&p->p, PS_UP); #ifdef CONFIG_BMP - bmp_peer_up(p, conn->local_open_msg, conn->local_open_length, + bmp_peer_up(proto_state_table->attrs[p->p.id], conn->local_open_msg, conn->local_open_length, conn->remote_open_msg, conn->remote_open_length); #endif } @@ -2370,6 +2373,9 @@ bgp_reconfigure(struct proto *P, struct proto_config *CF) /* We should update our copy of configuration ptr as old configuration will be freed */ p->cf = new; + ea_list *eal = proto_state_table->attrs[p->p.id]; + ea_set_attr(&eal, EA_LITERAL_EMBEDDED(&ea_bgp_peer_type, 0, p->cf->peer_type)); + proto_journal_state_push(eal, &p->p); /* Check whether existing connections are compatible with required capabilities */ struct bgp_conn *ci = &p->incoming_conn; @@ -2581,16 +2587,14 @@ bgp_state_to_eattr(struct proto *P, ea_list *l, eattr *attributes) attributes[l->count++] = EA_LITERAL_EMBEDDED(&ea_bgp_rem_id, 0, p->remote_id); attributes[l->count++] = EA_LITERAL_EMBEDDED(&ea_bgp_rem_as, 0, p->remote_as); attributes[l->count++] = EA_LITERAL_STORE_ADATA(&ea_bgp_rem_ip, 0, &p->remote_ip, sizeof(ip_addr)); + attributes[l->count++] = EA_LITERAL_EMBEDDED(&ea_bgp_peer_type, 0, p->cf->peer_type); + attributes[l->count++] = EA_LITERAL_EMBEDDED(&ea_bgp_loc_as, 0, p->local_as); + attributes[l->count++] = EA_LITERAL_EMBEDDED(&ea_bgp_rem_as, 0, p->remote_as); if (p->conn) { - struct journal_bgp_conn conn = { - .state = p->conn->state, - .local_open_msg = p->conn->local_open_msg, - .remote_open_msg = p->conn->remote_open_msg, - .local_open_length = p->conn->local_open_length, - .remote_open_length = p->conn->remote_open_length, - }; - attributes[l->count++] = EA_LITERAL_STORE_ADATA(&ea_bgp_conn, 0, &conn, sizeof(struct journal_bgp_conn)); + attributes[l->count++] = EA_LITERAL_STORE_PTR(&ea_bgp_conn, 0, &p->conn); + attributes[l->count++] = EA_LITERAL_STORE_PTR(&ea_bgp_in_conn, 0, &p->incoming_conn); + attributes[l->count++] = EA_LITERAL_STORE_PTR(&ea_bgp_out_conn, 0, &p->outgoing_conn); } } diff --git a/proto/bgp/bgp.h b/proto/bgp/bgp.h index a85c2552..83e85df5 100644 --- a/proto/bgp/bgp.h +++ b/proto/bgp/bgp.h @@ -290,15 +290,6 @@ struct bgp_stats { uint fsm_established_transitions; }; -struct journal_bgp_conn { - u8 state; - - byte *local_open_msg; - byte *remote_open_msg; - uint local_open_length; - uint remote_open_length; -}; - struct bgp_conn { struct bgp_proto *bgp; struct birdsock *sk; @@ -329,6 +320,13 @@ struct bgp_conn { uint hold_time, keepalive_time, send_hold_time; /* Times calculated from my and neighbor's requirements */ }; + +struct journal_bgp_conn { + struct bgp_conn *conn; + struct bgp_conn outgoing_conn; + struct bgp_conn incoming_conn; +}; + struct bgp_listen_request { node n; /* Node in bgp_socket / pending list */ struct bgp_socket *sock; /* Assigned socket */ @@ -690,7 +688,8 @@ static inline struct bgp_proto *bgp_rte_proto(const rte *rte) SKIP_BACK(struct bgp_proto, p.sources, rte->src->owner) : NULL; } -byte * bgp_bmp_encode_rte(struct bgp_channel *c, byte *buf, const net_addr *n, const struct rte *new, const struct rte_src *src); +byte * bgp_bmp_encode_rte(ea_list *c, struct bgp_proto *bgp_p, byte *buf, const net_addr *n, + const struct rte *new, const struct rte_src *src); #define BGP_AIGP_METRIC 1 #define BGP_AIGP_MAX U64(0xffffffffffffffff) @@ -726,6 +725,7 @@ void bgp_log_error(struct bgp_proto *p, u8 class, char *msg, unsigned code, unsi void bgp_update_next_hop(struct bgp_export_state *s, eattr *a, ea_list **to); byte *bgp_create_end_mark_(struct bgp_channel *c, byte *buf); +byte *bgp_create_end_mark_ea_(ea_list *c, byte *buf); /* Packet types */ diff --git a/proto/bgp/packets.c b/proto/bgp/packets.c index 2dbcef08..86097756 100644 --- a/proto/bgp/packets.c +++ b/proto/bgp/packets.c @@ -2451,23 +2451,28 @@ bgp_create_mp_unreach(struct bgp_write_state *s, struct bgp_bucket *buck, byte * #ifdef CONFIG_BMP static byte * -bgp_create_update_bmp(struct bgp_channel *c, byte *buf, struct bgp_bucket *buck, bool update) +bgp_create_update_bmp(ea_list *channel_ea, struct bgp_proto *bgp_p, byte *buf, struct bgp_bucket *buck, bool update) { - struct bgp_proto *p = (void *) c->c.proto; + struct bgp_channel *c; + int c_id = ea_get_int(channel_ea, &ea_channel_id, 0); + BGP_WALK_CHANNELS(bgp_p, c) + if (c->c.id == c_id) + break; + byte *end = buf + (BGP_MAX_EXT_MSG_LENGTH - BGP_HEADER_LENGTH); byte *res = NULL; /* FIXME: must be a bit shorter */ - struct bgp_caps *peer = p->conn->remote_caps; + struct bgp_caps *peer = bgp_p->conn->remote_caps; const struct bgp_af_caps *rem = bgp_find_af_caps(peer, c->afi); struct bgp_write_state s = { - .proto = p, + .proto = bgp_p, .pool = tmp_linpool, .mp_reach = (c->afi != BGP_AF_IPV4) || rem->ext_next_hop, .as4_session = 1, .add_path = c->add_path_rx, - .mpls = c->desc->mpls, + .mpls = c->desc->mpls, //this is problem, but we can have proto. What about find correct channel in proto? TODO }; if (!update) @@ -2497,7 +2502,7 @@ bgp_bmp_prepare_bgp_hdr(byte *buf, const u16 msg_size, const u8 msg_type) } byte * -bgp_bmp_encode_rte(struct bgp_channel *c, byte *buf, const net_addr *n, +bgp_bmp_encode_rte(ea_list *c, struct bgp_proto *bgp_p, byte *buf, const net_addr *n, const struct rte *new, const struct rte_src *src) { // struct bgp_proto *p = (void *) c->c.proto; @@ -2525,7 +2530,7 @@ bgp_bmp_encode_rte(struct bgp_channel *c, byte *buf, const net_addr *n, //FIXME net_copy(px->net, n); add_tail(&b->prefixes, &px->buck_node); // why was there _xx ? - byte *end = bgp_create_update_bmp(c, pkt, b, !!new); + byte *end = bgp_create_update_bmp(c, bgp_p, pkt, b, !!new); if (end) bgp_bmp_prepare_bgp_hdr(buf, end - buf, PKT_UPDATE); @@ -2633,6 +2638,31 @@ bgp_create_mp_end_mark(struct bgp_channel *c, byte *buf) return buf+10; } +static byte * +bgp_create_mp_end_mark_ea(ea_list *c, byte *buf) +{ + put_u16(buf+0, 0); + put_u16(buf+2, 6); /* length 4--9 */ + + /* Empty MP_UNREACH_NLRI atribute */ + buf[4] = BAF_OPTIONAL; + buf[5] = BA_MP_UNREACH_NLRI; + buf[6] = 3; /* Length 7--9 */ + int afi = ea_get_int(c, &ea_bgp_afi, 0); + put_af3(buf+7, afi); + + return buf+10; +} + +byte * +bgp_create_end_mark_ea_(ea_list *c, byte *buf) +{ + int afi = ea_get_int(c, &ea_bgp_afi, 0); + return (afi == BGP_AF_IPV4) ? + bgp_create_ip_end_mark(NULL, buf): + bgp_create_mp_end_mark_ea(c, buf); +} + byte * bgp_create_end_mark_(struct bgp_channel *c, byte *buf) { diff --git a/proto/bmp/bmp.c b/proto/bmp/bmp.c index 5252c1a3..53a57739 100644 --- a/proto/bmp/bmp.c +++ b/proto/bmp/bmp.c @@ -219,7 +219,7 @@ static void bmp_sock_err(sock *sk, int err); static void bmp_close_socket(struct bmp_proto *p); static void -bmp_send_peer_up_notif_msg(struct bmp_proto *p, const ea_list *bgp, +bmp_send_peer_up_notif_msg(struct bmp_proto *p, ea_list *bgp, const byte *tx_data, const size_t tx_data_size, const byte *rx_data, const size_t rx_data_size); @@ -551,7 +551,7 @@ static inline bool bmp_stream_policy(struct bmp_stream *bs) { return !!(bs->key & BMP_STREAM_KEY_POLICY); } static struct bmp_stream * -bmp_find_stream(struct bmp_proto *p, ea_list *bgp_attr, u32 afi, bool policy) +bmp_find_stream(struct bmp_proto *p, struct bgp_proto *bgp_attr, u32 afi, bool policy) { return HASH_FIND(p->stream_map, HASH_STREAM, (void*)bgp_attr, bmp_stream_key(afi, policy)); } @@ -649,7 +649,7 @@ bmp_peer_up_(struct bmp_proto *p, ea_list *bgp_attr, bool sync, if (bp) return; - const char *name = ea_find(bgp_attr, &ea_name)->u.ad->data; + const char *name = ea_get_adata(bgp_attr, &ea_name)->data; TRACE(D_STATES, "Peer up for %s", name); bp = bmp_add_peer(p, bgp_attr); @@ -685,7 +685,7 @@ bmp_peer_up(ea_list *bgp, static void bmp_peer_init(struct bmp_proto *p, ea_list *bgp_attr) { - struct journal_bgp_conn *conn = (struct journal_bgp_conn *) ea_find(bgp_attr, &ea_bgp_conn)->u.ad->data; + const struct bgp_conn *conn = (const struct bgp_conn *) ea_get_ptr(bgp_attr, &ea_bgp_conn, 0); if (!conn || (conn->state != BS_ESTABLISHED) || !conn->local_open_msg || !conn->remote_open_msg) @@ -698,28 +698,31 @@ bmp_peer_init(struct bmp_proto *p, ea_list *bgp_attr) static const struct birdsock * -bmp_get_birdsock(const struct bgp_proto *bgp) +bmp_get_birdsock(ea_list *bgp) { - if (bgp->conn && bgp->conn->sk) - return bgp->conn->sk; + struct bgp_conn *conn = (struct bgp_conn *) ea_get_ptr(bgp, &ea_bgp_conn, 0); + if (conn && conn->sk) + return conn->sk; return NULL; } static const struct birdsock * -bmp_get_birdsock_ext(const struct bgp_proto *bgp) +bmp_get_birdsock_ext(ea_list *bgp) { const struct birdsock *sk = bmp_get_birdsock(bgp); if (sk != NULL) return sk; - if (bgp->incoming_conn.sk) + struct bgp_conn *in_conn = (struct bgp_conn *) ea_get_ptr(bgp, &ea_bgp_in_conn, 0); + struct bgp_conn *out_conn = (struct bgp_conn *) ea_get_ptr(bgp, &ea_bgp_out_conn, 0); + if (in_conn->sk) { - sk = bgp->incoming_conn.sk; + sk = in_conn->sk; } - else if (bgp->outgoing_conn.sk) + else if (out_conn->sk) { - sk = bgp->outgoing_conn.sk; + sk = out_conn->sk; } return sk; @@ -754,16 +757,19 @@ bmp_get_bgp_remote_caps_ext(const struct bgp_proto *bgp) } static bool -bmp_is_peer_global_instance(const struct bgp_proto *bgp) +bmp_is_peer_global_instance(ea_list *bgp) { - return (bgp->cf->peer_type != BGP_PT_EXTERNAL && - bgp->cf->peer_type != BGP_PT_INTERNAL) - ? (bgp->local_as != bgp->remote_as) - : (bgp->cf->peer_type == BGP_PT_EXTERNAL); + int peer_type = ea_get_int(bgp, &ea_bgp_peer_type, 0); + int local_as = ea_get_int(bgp, &ea_bgp_loc_as, 0); + int remote_as = ea_get_int(bgp, &ea_bgp_rem_as, 0); + return (peer_type != BGP_PT_EXTERNAL && + peer_type != BGP_PT_INTERNAL) + ? (local_as != remote_as) + : (peer_type == BGP_PT_EXTERNAL); } static void -bmp_send_peer_up_notif_msg(struct bmp_proto *p, const struct bgp_proto *bgp, +bmp_send_peer_up_notif_msg(struct bmp_proto *p, ea_list *bgp, const byte *tx_data, const size_t tx_data_size, const byte *rx_data, const size_t rx_data_size) { @@ -775,10 +781,12 @@ bmp_send_peer_up_notif_msg(struct bmp_proto *p, const struct bgp_proto *bgp, "[BMP] No BGP socket" ); + const int rem_as = ea_get_int(bgp, &ea_bgp_rem_as, 0); + const int rem_id = ea_get_int(bgp, &ea_bgp_rem_id, 0); const bool is_global_instance_peer = bmp_is_peer_global_instance(bgp); buffer payload = bmp_buffer_alloc(p->buffer_mpool, DEFAULT_MEM_BLOCK_SIZE); bmp_peer_up_notif_msg_serialize(&payload, is_global_instance_peer, - bgp->remote_as, bgp->remote_id, 1, + rem_as, rem_id, 1, sk->saddr, sk->daddr, sk->sport, sk->dport, tx_data, tx_data_size, rx_data, rx_data_size); bmp_schedule_tx_packet(p, bmp_buffer_data(&payload), bmp_buffer_pos(&payload)); @@ -796,10 +804,10 @@ bmp_route_monitor_put_update(struct bmp_proto *p, struct bmp_stream *bs, const b add_tail(&p->update_msg_queue, &upd_msg->n); /* Save some metadata */ - struct bgp_proto *bgp = bs->bgp; - upd_msg->remote_as = bgp->remote_as; - upd_msg->remote_id = bgp->remote_id; - upd_msg->remote_ip = bgp->remote_ip; + ea_list *bgp = bs->bgp; + upd_msg->remote_as = ea_get_int(bgp, &ea_bgp_rem_as, 0); + upd_msg->remote_id = ea_get_int(bgp, &ea_bgp_rem_id, 0); + upd_msg->remote_ip = ea_get_ip(bgp, &ea_bgp_rem_ip, IPA_NONE); upd_msg->timestamp = timestamp; upd_msg->global_peer = bmp_is_peer_global_instance(bgp); upd_msg->policy = bmp_stream_policy(bs); @@ -810,11 +818,11 @@ bmp_route_monitor_put_update(struct bmp_proto *p, struct bmp_stream *bs, const b } static void -bmp_route_monitor_notify(struct bmp_proto *p, struct bmp_stream *bs, +bmp_route_monitor_notify(struct bmp_proto *p, struct bgp_proto *bgp_p, struct bmp_stream *bs, const net_addr *n, const struct rte *new, const struct rte_src *src) { byte buf[BGP_MAX_EXT_MSG_LENGTH]; - byte *end = bgp_bmp_encode_rte(bs->sender, buf, n, new, src); + byte *end = bgp_bmp_encode_rte(bs->sender, bgp_p, buf, n, new, src); btime delta_t = new ? current_time() - new->lastmod : 0; btime timestamp = current_real_time() - delta_t; @@ -860,10 +868,10 @@ bmp_route_monitor_commit(void *p_) static void bmp_route_monitor_end_of_rib(struct bmp_proto *p, struct bmp_stream *bs) { - TRACE(D_PACKETS, "Sending END-OF-RIB for %s.%s", bs->bgp->p.name, ea_get_adata(bs->sender, &ea_name)->adata); + TRACE(D_PACKETS, "Sending END-OF-RIB for %s.%s", ea_get_adata(bs->bgp, &ea_name)->data, ea_get_adata(bs->sender, &ea_name)->data); byte rx_end_payload[DEFAULT_MEM_BLOCK_SIZE]; - byte *pos = bgp_create_end_mark_(bs->sender, rx_end_payload + BGP_HEADER_LENGTH); + byte *pos = bgp_create_end_mark_ea_(bs->sender, rx_end_payload + BGP_HEADER_LENGTH); memset(rx_end_payload + BGP_MSG_HDR_MARKER_POS, 0xff, BGP_MSG_HDR_MARKER_SIZE); // BGP UPDATE MSG marker put_u16(rx_end_payload + BGP_MSG_HDR_LENGTH_POS, pos - rx_end_payload); @@ -879,7 +887,7 @@ bmp_send_peer_down_notif_msg(struct bmp_proto *p, const struct bgp_proto *bgp, ASSERT(p->started); const struct bgp_caps *remote_caps = bmp_get_bgp_remote_caps_ext(bgp); - bool is_global_instance_peer = bmp_is_peer_global_instance(bgp); + bool is_global_instance_peer = bmp_is_peer_global_instance(proto_state_table->attrs[bgp->p.id]); buffer payload = bmp_buffer_alloc(p->buffer_mpool, DEFAULT_MEM_BLOCK_SIZE); bmp_peer_down_notif_msg_serialize(&payload, is_global_instance_peer, @@ -898,7 +906,7 @@ bmp_peer_down_(struct bmp_proto *p, const struct bgp_proto *bgp, if (!p->started) return; - struct bmp_peer *bp = bmp_find_peer(p, bgp); + struct bmp_peer *bp = bmp_find_peer(p, proto_state_table->attrs[bgp->p.id]); if (!bp) return; @@ -1004,7 +1012,7 @@ bmp_preexport(struct channel *C UNUSED, rte *e) static void bmp_rt_notify(struct proto *P, struct channel *c, const net_addr *net, - struct rte *new, struct rte *old) + struct rte *new, const struct rte *old) { struct bmp_proto *p = (void *) P; @@ -1023,7 +1031,7 @@ bmp_rt_notify(struct proto *P, struct channel *c, const net_addr *net, if (!bs) return; - bmp_route_monitor_notify(p, bs, net, new, (new ?: old)->src); + bmp_route_monitor_notify(p, bgp, bs, net, new, (new ?: old)->src); } static void @@ -1080,16 +1088,16 @@ bmp_startup(struct bmp_proto *p) bmp_buffer_free(&payload); /* Send Peer Up messages */ - for (int i = 0; i < bgp_attributes->length; i++) + for (u32 i = 0; i < proto_state_table->length; i++) { - ea_list *bgp_attr = bgp_attributes->attrs[i]; - if (bgp_attr == NULL) + ea_list *proto_attr = proto_state_table->attrs[i]; + if (proto_attr == NULL) continue; - struct protocol *proto = (struct protocol *) ea_find(bgp_attr, &ea_protocol_type)->u.ad->data; - const int state = ea_find(bgp_attr, &ea_state)->u.i; + struct protocol *proto = (struct protocol *) ea_get_ptr(proto_attr, &ea_protocol_type, 0); + const int state = ea_get_int(proto_attr, &ea_state, 0); if (proto != &proto_bgp || state != PS_UP) continue; - bmp_peer_init(p, bgp_attr); + bmp_peer_init(p, proto_attr); } /*struct proto *peer; WALK_LIST(peer, proto_list) @@ -1151,7 +1159,7 @@ bmp_connect(struct bmp_proto *p) TRACE(D_EVENTS, "Connecting to %I port %u", sk->daddr, sk->dport); - int rc = sk_open(sk); + int rc = sk_open(sk, p->p.loop); if (rc < 0) sk_log_error(sk, p->p.name); @@ -1243,7 +1251,7 @@ bmp_init(struct proto_config *CF) P->rt_notify = bmp_rt_notify; P->preexport = bmp_preexport; - P->feed_end = bmp_feed_end; + //P->feed_end = bmp_feed_end; I am confused. It looks like feed_end and bmp_feed_end exist only here p->cf = cf; p->local_addr = cf->local_addr; @@ -1266,10 +1274,10 @@ bmp_start(struct proto *P) { struct bmp_proto *p = (void *) P; - p->buffer_mpool = rp_new(P->pool, "BMP Buffer"); - p->map_mem_pool = rp_new(P->pool, "BMP Map"); - p->tx_mem_pool = rp_new(P->pool, "BMP Tx"); - p->update_msg_mem_pool = rp_new(P->pool, "BMP Update"); + p->buffer_mpool = rp_new(P->pool, proto_domain(&p->p), "BMP Buffer"); + p->map_mem_pool = rp_new(P->pool, proto_domain(&p->p), "BMP Map"); + p->tx_mem_pool = rp_new(P->pool, proto_domain(&p->p), "BMP Tx"); + p->update_msg_mem_pool = rp_new(P->pool, proto_domain(&p->p), "BMP Update"); p->tx_ev = ev_new_init(p->p.pool, bmp_fire_tx, p); p->update_ev = ev_new_init(p->p.pool, bmp_route_monitor_commit, p); p->connect_retry_timer = tm_new_init(p->p.pool, bmp_connection_retry, p, 0, 0); @@ -1371,7 +1379,7 @@ bmp_show_proto_info(struct proto *P) struct protocol proto_bmp = { .name = "BMP", .template = "bmp%d", - .class = PROTOCOL_BMP, + //.class = PROTOCOL_BMP, looks like there are no classes for protocols anymore .proto_size = sizeof(struct bmp_proto), .config_size = sizeof(struct bmp_config), .postconfig = bmp_postconfig, diff --git a/proto/bmp/bmp.h b/proto/bmp/bmp.h index 4819cbcf..09d51fab 100644 --- a/proto/bmp/bmp.h +++ b/proto/bmp/bmp.h @@ -108,7 +108,7 @@ struct bmp_table { * bmp_peer_up - send notification that BGP peer connection is established */ void -bmp_peer_up(struct bgp_proto *bgp, +bmp_peer_up(struct ea_list *bgp, const byte *tx_open_msg, uint tx_open_length, const byte *rx_open_msg, uint rx_open_length); diff --git a/proto/mrt/mrt.c b/proto/mrt/mrt.c index e19bac65..510639f8 100644 --- a/proto/mrt/mrt.c +++ b/proto/mrt/mrt.c @@ -52,6 +52,7 @@ #include "proto/bgp/bgp.h" #include "sysdep/unix/unix.h" #include "sysdep/unix/io-loop.h" +#include "conf/conf.h" #ifdef PATH_MAX @@ -376,7 +377,7 @@ static void mrt_peer_table_dump(struct mrt_table_dump_state *s) { mrt_init_message(&s->buf, MRT_TABLE_DUMP_V2, MRT_PEER_INDEX_TABLE); - mrt_peer_table_header(s, config->router_id, get_tab(s)->name); + mrt_peer_table_header(s, OBSREF_GET(config)->router_id, get_tab(s)->name); /* 0 is fake peer for non-BGP routes */ mrt_peer_table_entry(s, 0, 0, IPA_NONE); @@ -394,7 +395,7 @@ mrt_peer_table_dump(struct mrt_table_dump_state *s) continue; } rcu_read_unlock(); - struct protocol **type = (struct protocol **)ea_get_adata(eal, &ea_protocol_type)->data; + struct protocol **type = (struct protocol **)ea_get_ptr(eal, &ea_protocol_type, 0); int state = ea_get_int(eal, &ea_state, 0); if ((*type == &proto_bgp) && (state != PS_DOWN)) { @@ -408,6 +409,7 @@ mrt_peer_table_dump(struct mrt_table_dump_state *s) /* Fix Peer Count */ put_u16(s->buf.start + s->peer_count_offset, s->peer_count); + log("peer count %i", s->peer_count); mrt_dump_message(&s->buf, s->fd); } @@ -603,8 +605,8 @@ mrt_table_dump_init(pool *pp) mrt_buffer_init(&s->buf, pool, 2 * MRT_ATTR_BUFFER_SIZE); /* We lock the current config as we may reference it indirectly by filter */ - s->config = config; - config_add_obstacle(s->config); + + OBSREF_SET(s->config, OBSREF_GET(config)); s->fd = -1; @@ -614,7 +616,7 @@ mrt_table_dump_init(pool *pp) static void mrt_table_dump_free(struct mrt_table_dump_state *s) { - config_del_obstacle(s->config); + OBSREF_CLEAR(s->config); rp_free(s->pool); } @@ -841,7 +843,7 @@ mrt_dump_bgp_message(struct mrt_bgp_data *d) 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(config->mrtdump_file)); + mrt_dump_message(b, rf_fileno(OBSREF_GET(config)->mrtdump_file)); } void @@ -861,7 +863,7 @@ mrt_dump_bgp_state_change(struct mrt_bgp_data *d) 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(config->mrtdump_file)); + mrt_dump_message(b, rf_fileno(OBSREF_GET(config)->mrtdump_file)); } diff --git a/proto/mrt/mrt.h b/proto/mrt/mrt.h index 925c88a4..c1ba0530 100644 --- a/proto/mrt/mrt.h +++ b/proto/mrt/mrt.h @@ -55,7 +55,7 @@ struct mrt_peer_entry { struct mrt_table_dump_state { struct mrt_proto *proto; /* Protocol for regular MRT dumps (or NULL) */ struct cli *cli; /* CLI for irregular MRT dumps (or NULL) */ - struct config *config; /* Config valid during start of dump, locked */ + config_ref config; /* Config valid during start of dump, locked */ /* Configuration information */ const char *table_expr; /* Wildcard for table name (or NULL) */