0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2025-01-15 13:31:54 +00:00

before merge

This commit is contained in:
Katerina Kubecova 2024-08-27 15:02:38 +02:00 committed by Maria Matejka
parent ef2f4422e9
commit ab1f7f1138
3 changed files with 108 additions and 40 deletions

View File

@ -229,6 +229,7 @@ rfree(void *res)
pool *orig = resource_parent(r);
ASSERT_DIE(DG_IS_LOCKED(orig->domain));
//log("rfree %x", r);
resource_rem_node(&orig->inside, r);
r->class->free(r);
@ -377,8 +378,9 @@ struct mblock {
byte data[0];
};
static void mbl_free(resource *r UNUSED)
static void mbl_free(resource *r)// UNUSED)
{
//log("mbl free %x", r);
}
static void mbl_debug(resource *r, unsigned indent UNUSED)
@ -436,9 +438,11 @@ mb_alloc(pool *p, unsigned size)
ASSERT_DIE(DG_IS_LOCKED(p->domain));
struct mblock *b = xmalloc(sizeof(struct mblock) + size);
//log("allocated %x", b);
b->r.class = &mb_class;
b->r.n = (struct resource_node) {};
log("mb alloc %x %x %x", b, b->r.n, b->data);
resource_add_tail(&p->inside, &b->r);
b->size = size;
return b->data;
@ -509,6 +513,7 @@ mb_free(void *m)
return;
SKIP_BACK_DECLARE(struct mblock, b, data, m);
//log("wil be freed %x", b);
rfree(&b->r);
}

View File

@ -220,8 +220,8 @@ proto_find_channel_by_name(struct proto *p, const char *n)
struct channel *
proto_add_channel(struct proto *p, struct channel_config *cf)
{
log("add channed to protocol %s id %i", p->name, p->id);
struct channel *c = mb_allocz(proto_pool, cf->class->channel_size);
log("add channel to protocol %s id %i channel %x", p->name, p->id, c);
c->name = cf->name;
c->class = cf->class;
@ -266,10 +266,12 @@ proto_add_channel(struct proto *p, struct channel_config *cf)
struct channel *
proto_add_main_channel(struct proto *p, struct channel_config *cf)
{
//log("before proto add chann proto_add_main_channel");
p->main_channel = proto_add_channel(p, cf);
log("after proto add chann proto_add_main_channel %x proto id %i, chann id %i", p->main_channel, p->id, p->main_channel->id);
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);
//log("adding main table ea_rtable added eattrs %i", eal);
proto_journal_state_push(eal, p, 1);
return p->main_channel;
}
@ -281,6 +283,7 @@ proto_remove_channel(struct proto *p UNUSED, struct channel *c)
CD(c, "Removed", c->name);
//log("proto_remove_channel get channel %i proto %i got %x", c->id, c->proto->id, get_channel_ea(c));
ea_list *eal = get_channel_ea(c)->attrs;
ea_set_attr(&eal, EA_LITERAL_EMBEDDED(&ea_deleted, 0, 1));
channel_journal_state_push(eal,c);
@ -322,6 +325,7 @@ static void
proto_remove_channels(struct proto *p)
{
struct channel *c;
WALK_LIST_FIRST(c, p->channels)
proto_remove_channel(p, c);
}
@ -520,6 +524,7 @@ channel_roa_subscribe(struct channel *c, rtable *tab, int dir)
.data = s,
},
};
log("roa %x", s);
add_tail(&c->roa_subscriptions, &s->roa_node);
@ -1194,7 +1199,6 @@ proto_configure_channel(struct proto *p, struct channel **pc, struct channel_con
log(L_INFO "Cannot add channel %s.%s", p->name, cf->name);
return 0;
}
*pc = proto_add_channel(p, cf);
}
else if (c && !cf)
@ -1307,12 +1311,15 @@ proto_new(struct proto_config *cf)
p->id = hmap_first_zero(proto_state_table->proto_id_maker);
hmap_set(proto_state_table->proto_id_maker, p->id);
log("protocol %s has id %i", p->name, p->id);
if (p->id >= proto_state_table->length)
log("protocol %s %x has id %i", p->name, p, p->id);
if (p->id >= proto_state_table->length) //TODO check
protos_attr_field_grow();
init_list(&proto_state_table->channels_attrs[p->id]);
//log("init chann list %x (pid %i)", &proto_state_table->channels_attrs[p->id], p->id);
init_list(&p->channels);
//log("philgrim init %x", p->channels);
//log("init chann list %x (pid %i)", &proto_state_table->channels_attrs[p->id], p->id);
return p;
}
@ -1741,6 +1748,7 @@ proto_shutdown(struct proto *p)
/* Going down */
DBG("Kicking %s down\n", p->name);
PD(p, "Shutting down");
log("shutdown");
proto_notify_state(p, (p->proto->shutdown ? p->proto->shutdown(p) : PS_DOWN));
if (p->reconfiguring)
{
@ -2165,6 +2173,7 @@ proto_set_message(struct proto *p, char *msg, int len)
p->message = mb_alloc(proto_pool, len + 1);
memcpy(p->message, msg, len);
p->message[len] = 0;
log("p mess %x", p->message);
}
@ -2540,7 +2549,7 @@ proto_cmd_show(struct proto *p, union cmd_arg verbose, int cnt)
ea_list *eal = proto_get_state_list(p->id);
const char *name = ea_get_adata(eal, &ea_name)->data;
struct protocol **type = (struct protocol **)ea_get_adata(eal, &ea_protocol_type)->data;
struct protocol *proto = (struct protocol *) ea_get_ptr(eal, &ea_protocol_type, 0);
const int state = ea_get_int(eal, &ea_state, 0);
const char *table = ea_get_adata(eal, &ea_table)->data;
buf[0] = 0;
@ -2554,7 +2563,7 @@ proto_cmd_show(struct proto *p, union cmd_arg verbose, int cnt)
cli_msg(-1002, "%-10s %-10s %-10s %-6s %-12s %s",
name,
(*type)->name,
proto->name,
table ? table : "---",
proto_state_name_from_int(state),
tbuf,
@ -2905,6 +2914,7 @@ proto_iterate_named(struct symbol *sym, struct protocol *proto, struct proto *ol
void
protos_attr_field_init(void)
{
log("start of protos_attr_field_init");
int init_length = 16;
proto_state_table = mb_allocz(&root_pool, sizeof(struct proto_attrs));
proto_state_table->attrs = mb_allocz(&root_pool, sizeof(ea_list)*init_length);
@ -2915,33 +2925,37 @@ protos_attr_field_init(void)
hmap_init(proto_state_table->proto_id_maker, &root_pool, init_length);
hmap_init(proto_state_table->channel_id_maker, &root_pool, init_length*2);
//TODO free? or have self pool?
log("end of protos_attr_field_init (%x %x %x %x )", proto_state_table, proto_state_table->attrs, proto_state_table->channels_attrs, proto_state_table->proto_id_maker);
}
void
protos_attr_field_grow(void)
{
log("grow");
ea_list *_Atomic * new_field = mb_allocz(&root_pool, sizeof(ea_list *_Atomic)*proto_state_table->length*2);
list * new_chann = mb_allocz(&root_pool, sizeof(list)*proto_state_table->length*2);
memcpy(new_field, proto_state_table->attrs, proto_state_table->length*(sizeof(ea_list* _Atomic)));
memcpy(new_chann, proto_state_table->channels_attrs, proto_state_table->length*(sizeof(list)));
ea_list *_Atomic * new_field = mb_allocz(&root_pool, proto_state_table->length * sizeof(ea_list *_Atomic) * 2);
log("for realocated field allocated %x", new_field);
list * new_chann = mb_allocz(&root_pool, proto_state_table->length * sizeof(list) * 2);
log("for realocated chann field allocated %x", new_chann);
memcpy(new_field, proto_state_table->attrs, proto_state_table->length * (sizeof(ea_list* _Atomic)));
memcpy(new_chann, proto_state_table->channels_attrs, proto_state_table->length * (sizeof(list)));
atomic_store(&proto_state_table->attrs, new_field);
proto_state_table->channels_attrs = new_chann; //TODO atomic
atomic_store(&proto_state_table->channels_attrs, new_chann); //TODO atomic
atomic_store(&proto_state_table->length, (proto_state_table->length*2));
}
void
cleanup_journal_item(struct lfjour * journal UNUSED, struct lfjour_item *i)
{
log("cleanup_journal_item");
//log("cleanup_journal_item");
struct proto_pending_update *pupdate = SKIP_BACK(struct proto_pending_update, li, i);
//log("cleaning %x", pupdate->proto_attr, ea_get_int(pupdate->proto_attr, &ea_deleted, 0));
//ea_free_later(pupdate->old_attr);
int deleting = ea_get_int(pupdate->proto_attr, &ea_deleted, 0);
//TODO temporal eatters
if (deleting)
{
log("try to delete");
//log("try to delete");
ea_free_later(pupdate->proto_attr);
}
}
@ -2953,6 +2967,7 @@ void
init_journal(int item_size, char *loop_name)
{
proto_journal = mb_allocz(&root_pool, sizeof(struct lfjour));
log("for new jour allocated %x", proto_journal);
struct settle_config cf = {.min = 0, .max = 0};
proto_journal->item_done = cleanup_journal_item;
proto_journal->item_size = item_size;
@ -2974,7 +2989,7 @@ init_journals(void)
ea_list *
proto_state_to_eattr(struct proto *p, int old_state, int proto_deleting)
{
log("protocol %s to eattr", p->name);
//log("protocol %s to eattr", p->name);
struct {
ea_list l;
eattr a[9+15];
@ -3003,17 +3018,18 @@ channel_state_to_eattr(struct channel *ch, int proto_deleting)
{
struct {
ea_list l;
eattr a[5];
eattr a[6];
} eattrs;
eattrs.l = (ea_list) {};
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_channel_id, 0, ch->id);
eattrs.a[eattrs.l.count++] = EA_LITERAL_EMBEDDED(&ea_deleted, 0, proto_deleting);
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);
log("ea_rtable added (%x), eattrs %x, str %x", ch->table, eattrs.l, eattrs.a[0].u.ad->data);
if (ch->proto->proto == &proto_bgp && ch != ch->proto->mpls_channel)
@ -3021,7 +3037,7 @@ channel_state_to_eattr(struct channel *ch, int proto_deleting)
struct bgp_channel *bc = (struct bgp_channel *) ch;
eattrs.a[eattrs.l.count++] = EA_LITERAL_EMBEDDED(&ea_bgp_afi, 0, bc->afi);
}
log("to lookup goes %i (%i)", eattrs.l, &eattrs.l);
//log("to lookup goes %i (%i)", eattrs.l, &eattrs.l);
return ea_lookup_slow(&eattrs.l, 0, EALS_CUSTOM);
}
@ -3030,8 +3046,8 @@ channel_state_to_eattr(struct channel *ch, int proto_deleting)
void
proto_journal_state_push(ea_list *attr, struct proto *p, int save_to_jour)
{
log("proto_journal_state_push %i", p->id);
log("push state for %s", ea_get_adata(attr, &ea_name)->data);
//log("proto_journal_state_push %i", p->id);
//log("push state for %s", ea_get_adata(attr, &ea_name)->data);
ea_set_attr(&attr, EA_LITERAL_STORE_ADATA(&ea_last_modified, 0, &p->last_state_change, sizeof(btime)));
attr = ea_lookup(attr, 0, EALS_CUSTOM);
@ -3088,6 +3104,7 @@ void
channel_journal_state_push(ea_list *attr, struct channel *ch)
{
attr = ea_lookup(attr, 0, EALS_CUSTOM);
return; // do we need the journal?
ea_list *old_attr = get_channel_ea(ch)->attrs;
LOCK_DOMAIN(rtable, proto_journal_domain);
struct channel_pending_update *pupdate = SKIP_BACK(struct channel_pending_update, li, lfjour_push_prepare(channel_journal));
@ -3120,17 +3137,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, table %i", ch->proto->name, ch->proto->id, ch->table);
if (!NODE_VALID(HEAD(proto_state_table->channels_attrs[ch->proto->id])))
init_list(&proto_state_table->channels_attrs[ch->proto->id]); // if we realocated channels lists, earlier inicialization would be problematic. But it does not seem to be problem for nonempty lists
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);
struct channel_attrs *attr = mb_allocz(&root_pool, 1230);//sizeof(struct channel_attrs));
log("for new channel allocated %x, eal %x", attr, 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)", &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);
log("added tail to lis %x ch id %i, p id %i", &proto_state_table->channels_attrs[ch->proto->id], ch->id, ch->proto->id);
if (get_channel_ea(ch) == 0)
bug("channel not stored ch id %i, p id %i", ch->id, ch->proto->id);
}
void dummy_log_proto_attr_list(void)
@ -3143,11 +3160,11 @@ void dummy_log_proto_attr_list(void)
if (eal)
{
const char *name = ea_find(eal, &ea_name)->u.ad->data;
struct protocol **t = (struct protocol **)ea_get_adata(eal, &ea_protocol_type)->data;
struct protocol *proto = (struct protocol *) ea_get_ptr(eal, &ea_protocol_type, 0);
const int state = ea_get_int(eal, &ea_state, 0);
const char *table = ea_get_adata(eal, &ea_table)->data;
const btime *time = (btime *)ea_get_adata(eal, &ea_last_modified)->data;
log("protocol %s of type %s is in state %i (table %s, last modified %t)", name, (*t)->name, state, table, time);
log("protocol %s of type %s is in state %i (table %s, last modified %t)", name, proto->name, state, table, time);
}
}
}

View File

@ -281,6 +281,7 @@ bmp_schedule_tx_packet(struct bmp_proto *p, const byte *payload, const size_t si
struct bmp_data_node *tx_data = mb_allocz(p->tx_mem_pool, sizeof (struct bmp_data_node));
tx_data->data = mb_allocz(p->tx_mem_pool, size);
log("tx_data %x data %x", tx_data, tx_data->data);
memcpy(tx_data->data, payload, size);
tx_data->data_size = size;
add_tail(&p->tx_queue, &tx_data->n);
@ -504,8 +505,8 @@ const struct channel_class channel_bmp = {
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));
log("adding table %x", bt);
bt->table = tab;
rt_lock_table(bt->table);
@ -531,7 +532,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");
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);
proto_remove_channel(&p->p, bt->channel);
@ -541,6 +542,7 @@ bmp_remove_table(struct bmp_proto *p, struct bmp_table *bt)
rt_unlock_table(bt->table);
bt->table = NULL;
log("free table %x", bt);
mb_free(bt);
}
@ -551,7 +553,7 @@ static inline void bmp_lock_table(struct bmp_proto *p UNUSED, struct bmp_table *
{ 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); }
{ bt->uc--; if (!bt->uc) bmp_remove_table(p, bt); } ////AUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU
/*
@ -577,8 +579,8 @@ bmp_find_stream(struct bmp_proto *p, const struct bgp_proto *bgp, u32 afi, bool
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));
log("add stream to p %i bs %x", p, bs);
bs->bgp = bp->bgp;
bs->key = bmp_stream_key(afi, policy);
@ -598,7 +600,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);
log("go to unlock table");
rem_node(&bs->n);
HASH_REMOVE(p->stream_map, HASH_STREAM, bs);
@ -632,6 +634,7 @@ bmp_add_peer(struct bmp_proto *p, ea_list *bgp_attr)
bp = mb_allocz(p->p.pool, sizeof(struct bmp_peer));
DG_UNLOCK(p->p.pool->domain);
}
log("bmp_peer %x", bp);
bp->bgp = bgp_attr;
init_list(&bp->streams);
@ -710,9 +713,38 @@ bmp_peer_up(ea_list *bgp,
const byte *tx_open_msg, uint tx_open_length,
const byte *rx_open_msg, uint rx_open_length)
{
int need_unlock = 1;
if (DG_IS_LOCKED(p->p.pool->domain))
need_unlock = 0;
else
DG_LOCK(p->p.pool->domain);
struct bmp_proto *p; node *n;
WALK_LIST2(p, n, bmp_proto_list, bmp_node)
bmp_peer_up_(p, bgp, true, tx_open_msg, tx_open_length, rx_open_msg, rx_open_length);
if (need_unlock)
DG_UNLOCK(p->p.pool->domain);
}
void
bmp_peer_up_jour(int bmp_id, ea_list *bgp,
const byte *tx_open_msg, uint tx_open_length,
const byte *rx_open_msg, uint rx_open_length)
{
int need_unlock = 1;
if (DG_IS_LOCKED(p->p.pool->domain))
need_unlock = 0;
else
DG_LOCK(p->p.pool->domain);
struct bmp_proto *p; node *n;
WALK_LIST2(p, n, bmp_proto_list, bmp_node)
if (p->p.id == bmp_id)
bmp_peer_up_(p, bgp, true, tx_open_msg, tx_open_length, rx_open_msg, rx_open_length);
if (need_unlock)
DG_UNLOCK(p->p.pool->domain);
}
static void
@ -832,6 +864,7 @@ bmp_route_monitor_put_update(struct bmp_proto *p, struct bmp_stream *bs, const b
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);
log("upd_msg %x, data %x", upd_msg, upd_msg->data);
memcpy(upd_msg->data, data, length);
upd_msg->data_size = length;
add_tail(&p->update_msg_queue, &upd_msg->n);
@ -995,9 +1028,18 @@ void
bmp_peer_down(const struct bgp_proto *bgp,
int err_class, int code, int subcode, const byte *data, int length)
{
int need_unlock = 1;
if (DG_IS_LOCKED(p->p.pool->domain))
need_unlock = 0;
else
DG_LOCK(p->p.pool->domain);
struct bmp_proto *p; node *n;
WALK_LIST2(p, n, bmp_proto_list, bmp_node)
bmp_peer_down_(p, bgp, err_class, code, subcode, data, length);
if (need_unlock)
DG_UNLOCK(p->p.pool->domain);
}
static void
@ -1019,6 +1061,7 @@ bmp_send_termination_msg(struct bmp_proto *p,
"Failed to send BMP termination message"
);
log("bmp_send_termination_msg free %x", stream);
bmp_buffer_free(&stream);
}
@ -1168,6 +1211,7 @@ bmp_down(struct bmp_proto *p)
/* Unregister existing peer structures */
HASH_WALK_DELSAFE(p->peer_map, next, bp)
{
log("bmp_remove_peer(p %x, bp %x)", p, bp);
bmp_remove_peer(p, bp);
}
HASH_WALK_END;
@ -1289,7 +1333,7 @@ bmp_postconfig(struct proto_config *CF)
void
fc_for_bmp_recipient(void *rec)
{
log("received update, locked %i", locking_stack.service);
//log("received update, locked %i", locking_stack.service);
struct lfjour_item *last_up;
struct proto_pending_update *pupdate;
while (last_up = lfjour_get((struct lfjour_recipient *)rec))
@ -1298,13 +1342,13 @@ fc_for_bmp_recipient(void *rec)
const byte *tx_open_msg = ea_get_adata(pupdate->proto_attr, &ea_bgp_local_open_msg)->data;
int id = ea_get_int(pupdate->proto_attr, &ea_proto_id, 0);
log("id %i, tx = %i, l %i", id, tx_open_msg, ea_get_int(pupdate->proto_attr, &ea_bgp_local_open_msg_len, 0)); //FIXME why WHY are bmp eattrs able to give not null pointer?
//log("id %i, tx = %i, l %i", id, tx_open_msg, ea_get_int(pupdate->proto_attr, &ea_bgp_local_open_msg_len, 0)); //FIXME why WHY are bmp eattrs able to give not null pointer?
if (ea_get_int(pupdate->proto_attr, &ea_bgp_local_open_msg_len, 0))
{
struct protocol *proto = (struct protocol *) ea_get_ptr(pupdate->proto_attr, &ea_protocol_type, 0);
//if (proto != &proto_bgp)
//{
log("protocol %s is bgp %i", proto->name, proto == &proto_bgp);
//log("protocol %s is bgp %i", proto->name, proto == &proto_bgp);
//bug("wrong protocol");
//}
//int id = ea_get_int(pupdate->proto_attr, &ea_proto_id, 0);
@ -1323,6 +1367,7 @@ void
create_bmp_recipient(struct proto *P)
{
struct lfjour_recipient *r = mb_allocz(&root_pool, sizeof(struct lfjour_recipient));
log("recipient %x", r);
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(P->loop);
@ -1386,7 +1431,7 @@ bmp_start(struct proto *P)
init_list(&p->update_msg_queue);
p->started = false;
p->sock_err = 0;
add_tail(&bmp_proto_list, &p->bmp_node);
add_tail(&bmp_proto_list, &p->bmp_node); //TODO remove
tm_start(p->connect_retry_timer, CONNECT_INIT_TIME);
@ -1407,6 +1452,7 @@ bmp_shutdown(struct proto *P)
}
p->sock_err = 0;
log("rem_node(&p->bmp_node %x)", p->bmp_node);
rem_node(&p->bmp_node);
return PS_DOWN;