diff --git a/lib/event.c b/lib/event.c index 6ad0bbae..9ccb3095 100644 --- a/lib/event.c +++ b/lib/event.c @@ -333,7 +333,6 @@ ev_run_list_limited(event_list *l, uint limit) edlog(l, e, next, 7, EDL_RUN_LIST); /* Run the event */ - log("lock service in event.c? locked %i", locking_stack.service); e->hook(e->data); tmp_flush(); diff --git a/nest/proto.c b/nest/proto.c index 706b3b89..610290db 100644 --- a/nest/proto.c +++ b/nest/proto.c @@ -269,6 +269,7 @@ proto_add_main_channel(struct proto *p, struct channel_config *cf) p->main_channel = proto_add_channel(p, cf); ea_list *eal = proto_state_table->attrs[p->id]; ea_set_attr(&eal, EA_LITERAL_STORE_STRING(&ea_table, 0, p->main_channel->table->name)); + log("adding main table ea_rtable added eattrs %i", eal); proto_journal_state_push(eal, p, 1); return p->main_channel; } @@ -3010,8 +3011,11 @@ channel_state_to_eattr(struct channel *ch, int proto_deleting) eattrs.a[eattrs.l.count++] = EA_LITERAL_STORE_STRING(&ea_name, 0, ch->name); 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) - eattrs.a[eattrs.l.count++] = EA_LITERAL_STORE_PTR(&ea_rtable, 0, &ch->table); + + eattrs.a[eattrs.l.count++] = EA_LITERAL_STORE_PTR(&ea_rtable, 0, ch->table); + log("ea_rtable added (%i), eattrs %i", ch->table, eattrs.l); + + if (ch->proto->proto == &proto_bgp && ch != ch->proto->mpls_channel) { struct bgp_channel *bc = (struct bgp_channel *) ch; @@ -3043,11 +3047,12 @@ proto_journal_state_push(ea_list *attr, struct proto *p, int save_to_jour) if (!pupdate) { UNLOCK_DOMAIN(rtable, proto_journal_domain); + log("why am i not creating pupdate?"); return; } *pupdate = (struct proto_pending_update) { .li = pupdate->li, /* Keep the item's internal state */ - .proto_attr = proto_state_table->attrs[p->id], + .proto_attr = save_to_jour ? proto_state_table->attrs[p->id] : attr, .old_attr = old_attr, .protocol = p }; @@ -3115,14 +3120,17 @@ channel_journal_state_change(struct channel *ch, int old_state, int new_state) void add_journal_channel(struct channel *ch) { - log("adding channel to %s %i", ch->proto->name, ch->proto->id); + log("adding channel to %s %i, table %i", ch->proto->name, ch->proto->id, ch->table); ea_list *eal = channel_state_to_eattr(ch, 0); log("eal %i", eal); struct channel_attrs *attr = mb_allocz(&root_pool, sizeof(struct channel_attrs)); //atomic_store(attr->attrs, eal); attr->attrs = eal; add_tail(&proto_state_table->channels_attrs[ch->proto->id], &attr->n); - log("really, added %i to id %i (attr %i attrs %i)", proto_state_table->channels_attrs[ch->proto->id], ch->proto->id, attr, attr->attrs); + log("really, added %i to id %i (attr %i attrs %i)", &attr->n, ch->proto->id, attr, attr->attrs); + + rtable *ch_table = (rtable *) ea_get_ptr(attr->attrs, &ea_rtable, 0); + log("test presence ch_table %i", ch_table); } void dummy_log_proto_attr_list(void) diff --git a/proto/bgp/bgp.c b/proto/bgp/bgp.c index 62165dc3..470f0658 100644 --- a/proto/bgp/bgp.c +++ b/proto/bgp/bgp.c @@ -800,14 +800,15 @@ bgp_conn_enter_established_state(struct bgp_conn *conn) #ifdef CONFIG_BMP //TODO not to repeat done eatters log("in bgp nesmysl, protocol %s id %i", p->p.name, p->p.id); - ea_list *ea = proto_state_table->attrs[p->p.id]; - ea_set_attr(&ea, EA_LITERAL_STORE_ADATA(&ea_bgp_local_open_msg, 0, conn->local_open_msg, conn->local_open_length)); - ea_set_attr(&ea, EA_LITERAL_STORE_ADATA(&ea_bgp_remote_open_msg, 0, conn->remote_open_msg, conn->remote_open_length)); - ea_set_attr(&ea, EA_LITERAL_EMBEDDED(&ea_bgp_local_open_msg_len, 0, conn->local_open_length)); - ea_set_attr(&ea, EA_LITERAL_EMBEDDED(&ea_bgp_remote_open_msg_len, 0, conn->remote_open_length)); - ea = ea_lookup(ea, 0, EALS_CUSTOM); - proto_journal_state_push(ea, &p->p, 0); - log("send to bmp locked %i (p %i)", locking_stack.service, p->p.id); + ea_list *ea_l = proto_state_table->attrs[p->p.id]; + ea_set_attr(&ea_l, EA_LITERAL_STORE_ADATA(&ea_bgp_local_open_msg, 0, conn->local_open_msg, conn->local_open_length)); + ea_set_attr(&ea_l, EA_LITERAL_STORE_ADATA(&ea_bgp_remote_open_msg, 0, conn->remote_open_msg, conn->remote_open_length)); + ea_set_attr(&ea_l, EA_LITERAL_EMBEDDED(&ea_bgp_local_open_msg_len, 0, conn->local_open_length)); + ea_set_attr(&ea_l, EA_LITERAL_EMBEDDED(&ea_bgp_remote_open_msg_len, 0, conn->remote_open_length)); + ea_l = ea_lookup(ea_l, 0, EALS_CUSTOM); + proto_journal_state_push(ea_l, &p->p, 0); + log("send to bmp locked %i (p %i), msg len loc %i rem %i", locking_stack.service, p->p.id, conn->local_open_length, conn->remote_open_length); + log("in bgp id %i, tx = %i, l= %i", p->p.id, ea_get_adata(ea_l, &ea_bgp_local_open_msg)->data, ea_get_int(ea_l, &ea_bgp_local_open_msg_len, 0)); //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 diff --git a/proto/bmp/bmp.c b/proto/bmp/bmp.c index d2d4b2e0..6d3fd8a4 100644 --- a/proto/bmp/bmp.c +++ b/proto/bmp/bmp.c @@ -295,6 +295,7 @@ bmp_schedule_tx_packet(struct bmp_proto *p, const byte *payload, const size_t si static void bmp_fire_tx(void *p_) { + log("fire"); struct bmp_proto *p = p_; if (!p->started) @@ -310,6 +311,7 @@ bmp_fire_tx(void *p_) struct bmp_data_node *tx_data_next; WALK_LIST_DELSAFE(tx_data, tx_data_next, p->tx_queue) { + log("WALK_LIST_DELSAFE"); if (tx_data->data_size > p->sk->tbsize) { sk_set_tbsize(p->sk, tx_data->data_size); @@ -320,6 +322,8 @@ bmp_fire_tx(void *p_) mb_free(tx_data->data); rem_node((node *) tx_data); mb_free(tx_data); + + log("walk ifs for returns socket %i, data size %i", p->sk, data_size); if (sk_send(p->sk, data_size) <= 0) return; @@ -487,9 +491,20 @@ bmp_find_table(struct bmp_proto *p, rtable *tab) return HASH_FIND(p->table_map, HASH_TABLE, tab); } +const struct channel_class channel_bmp = { + .channel_size = sizeof(struct channel), + .config_size = sizeof(struct channel_config), + /*.init = + .start = + .shutdown = + .cleanup = + .reconfigure = */ +}; + static struct bmp_table * bmp_add_table(struct bmp_proto *p, rtable *tab) { + log("adding table"); struct bmp_table *bt = mb_allocz(p->p.pool, sizeof(struct bmp_table)); bt->table = tab; rt_lock_table(bt->table); @@ -504,6 +519,7 @@ bmp_add_table(struct bmp_proto *p, rtable *tab) .net_type = tab->addr_type, .ra_mode = RA_ANY, //.bmp_hack = 1, + .class = &channel_bmp, }; bt->channel = proto_add_channel(&p->p, &cc); @@ -515,6 +531,7 @@ bmp_add_table(struct bmp_proto *p, rtable *tab) static void bmp_remove_table(struct bmp_proto *p, struct bmp_table *bt) { + log("removing table"); channel_set_state(bt->channel, CS_STOP); channel_set_state(bt->channel, CS_DOWN); proto_remove_channel(&p->p, bt->channel); @@ -551,14 +568,16 @@ 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, struct bgp_proto *bgp_attr, u32 afi, bool policy) +bmp_find_stream(struct bmp_proto *p, const struct bgp_proto *bgp, u32 afi, bool policy) { - return HASH_FIND(p->stream_map, HASH_STREAM, (void*)bgp_attr, bmp_stream_key(afi, policy)); + ea_list *bgp_attr = proto_state_table->attrs[bgp->p.id]; + return HASH_FIND(p->stream_map, HASH_STREAM, bgp_attr, bmp_stream_key(afi, policy)); } static struct bmp_stream * bmp_add_stream(struct bmp_proto *p, struct bmp_peer *bp, u32 afi, bool policy, rtable *tab, ea_list *sender, int in_pre_policy) { + log("add stream to p %i", p); struct bmp_stream *bs = mb_allocz(p->p.pool, sizeof(struct bmp_stream)); bs->bgp = bp->bgp; bs->key = bmp_stream_key(afi, policy); @@ -579,6 +598,7 @@ bmp_add_stream(struct bmp_proto *p, struct bmp_peer *bp, u32 afi, bool policy, r static void bmp_remove_stream(struct bmp_proto *p, struct bmp_stream *bs) { + log("remove stream from p %i", p); rem_node(&bs->n); HASH_REMOVE(p->stream_map, HASH_STREAM, bs); @@ -596,7 +616,7 @@ bmp_remove_stream(struct bmp_proto *p, struct bmp_stream *bs) static struct bmp_peer * bmp_find_peer(struct bmp_proto *p, ea_list *bgp_attr) { - return HASH_FIND(p->peer_map, HASH_PEER, (void *)bgp_attr); //TODO this is wrong, hash find is not for eattrs. but. + return HASH_FIND(p->peer_map, HASH_PEER, bgp_attr); } static struct bmp_peer * @@ -620,18 +640,19 @@ bmp_add_peer(struct bmp_proto *p, ea_list *bgp_attr) int proto_id = ea_get_int(bgp_attr, &ea_proto_id, 0); - ea_list *chan_attr; + struct channel_attrs *chan_attr; log("before while id %i, eattrs %i", proto_id, proto_state_table->channels_attrs[proto_id]); WALK_LIST(chan_attr, proto_state_table->channels_attrs[proto_id]) { - log("chan_attr in bmp_add_peer %i", chan_attr); - rtable *ch_table = (rtable *) ea_get_ptr(chan_attr, &ea_rtable, 0); - log("has table ptr %i", ch_table); + log("chan_attr in bmp_add_peer %i, attrs %i", chan_attr, chan_attr->attrs); + rtable *ch_table = (rtable *) ea_get_ptr(chan_attr->attrs, &ea_rtable, 0); + + log("name %i ch_table %i first if %i second if %i", &ch_table->name, ch_table, p->monitoring_rib.in_pre_policy, p->monitoring_rib.in_post_policy); if (p->monitoring_rib.in_pre_policy && ch_table) - bmp_add_stream(p, bp, ea_get_int(chan_attr, &ea_bgp_afi, 0), false, ch_table, chan_attr, 1); + bmp_add_stream(p, bp, ea_get_int(chan_attr->attrs, &ea_bgp_afi, 0), false, ch_table, chan_attr->attrs, 1); if (p->monitoring_rib.in_post_policy && ch_table) - bmp_add_stream(p, bp, ea_get_int(chan_attr, &ea_bgp_afi, 0), true, ch_table, chan_attr, 0); + bmp_add_stream(p, bp, ea_get_int(chan_attr->attrs, &ea_bgp_afi, 0), true, ch_table, chan_attr->attrs, 0); } return bp; @@ -808,7 +829,7 @@ bmp_send_peer_up_notif_msg(struct bmp_proto *p, ea_list *bgp, static void bmp_route_monitor_put_update(struct bmp_proto *p, struct bmp_stream *bs, const byte *data, size_t length, btime timestamp) { - struct bmp_data_node *upd_msg = mb_alloc(p->update_msg_mem_pool, + struct bmp_data_node *upd_msg = mb_allocz(p->update_msg_mem_pool, sizeof (struct bmp_data_node)); upd_msg->data = mb_alloc(p->update_msg_mem_pool, length); memcpy(upd_msg->data, data, length); @@ -1041,8 +1062,12 @@ bmp_rt_notify(struct proto *P, struct channel *c, const net_addr *net, 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, net, new, (new ?: old)->src); } @@ -1053,8 +1078,12 @@ bmp_feed_end(struct channel *c) struct bmp_table *bt = bmp_find_table(p, c->table); if (!bt) + { + log("bmp table not found"); return; + } +log("bmp table found"); /* * Unsynced streams are added in one moment during BMP session establishment, * therefore we can assume that all unsynced streams (for given channel) @@ -1104,10 +1133,12 @@ bmp_startup(struct bmp_proto *p) for (u32 i = 0; i < proto_state_table->length; i++) { ea_list *proto_attr = proto_state_table->attrs[i]; + log("startup proto attr %i", proto_attr); if (proto_attr == NULL) continue; 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); + log("proto bgp and up %i %i", proto != &proto_bgp, state != PS_UP); if (proto != &proto_bgp || state != PS_UP) continue; bmp_peer_init(p, proto_attr); @@ -1288,12 +1319,12 @@ fc_for_bmp_recipient(void *rec) } void -create_bmp_recipient(void) +create_bmp_recipient(struct proto *P) { struct lfjour_recipient *r = mb_allocz(&root_pool, sizeof(struct lfjour_recipient)); r->event = ev_new_init(&root_pool, fc_for_bmp_recipient, r); - struct birdloop *loop = birdloop_new(&root_pool, DOMAIN_ORDER(service), 1, "bmp recipient loop"); - r->target = birdloop_event_list(loop); + //struct birdloop *loop = birdloop_new(&root_pool, DOMAIN_ORDER(service), 1, "bmp recipient loop"); + r->target = birdloop_event_list(P->loop); LOCK_DOMAIN(rtable, proto_journal_domain); lfjour_register(proto_journal, r); @@ -1321,7 +1352,7 @@ bmp_init(struct proto_config *CF) strcpy(p->sys_name, cf->sys_name); p->monitoring_rib.in_pre_policy = cf->monitoring_rib_in_pre_policy; p->monitoring_rib.in_post_policy = cf->monitoring_rib_in_post_policy; - create_bmp_recipient(); + //create_bmp_recipient(P); should be here, but. log("new proto created locked %i", locking_stack.service); return P; @@ -1359,6 +1390,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); return PS_START; }