0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-12-22 17:51:53 +00:00

Nest: proto/channel state table naming convention cleanup

This commit is contained in:
Maria Matejka 2024-12-09 15:34:11 +01:00
parent d503204aa0
commit dc692ae06a
5 changed files with 44 additions and 44 deletions

View File

@ -260,21 +260,21 @@ proto_add_channel(struct proto *p, struct channel_config *cf)
hmap_set(&ts->channel_id_map, c->id); hmap_set(&ts->channel_id_map, c->id);
/* The current channel state table may be too small */ /* The current channel state table may be too small */
if (c->id >= ts->length_channels) if (c->id >= ts->channels_len)
{ {
ea_list **l = mb_allocz(ts->pool, sizeof(ea_list*) * ts->length_channels * 2); ea_list **l = mb_allocz(ts->pool, sizeof(ea_list*) * ts->channels_len * 2);
memcpy(l, ts->channels, sizeof(ea_list*) * ts->length_channels); memcpy(l, ts->channel_states, sizeof(ea_list*) * ts->channels_len);
mb_free(ts->channels); mb_free(ts->channel_states);
ts->channels = l; ts->channel_states = l;
ts->length_channels = ts->length_channels * 2; ts->channels_len = ts->channels_len * 2;
} }
ASSERT_DIE(c->id < ts->length_channels); ASSERT_DIE(c->id < ts->channels_len);
ASSERT_DIE(ts->channels[c->id] == NULL); ASSERT_DIE(ts->channel_states[c->id] == NULL);
/* Set the channel info */ /* Set the channel info */
ts->channels[c->id] = ea_lookup_slow(ca, 0, EALS_IN_TABLE); ts->channel_states[c->id] = ea_lookup_slow(ca, 0, EALS_IN_TABLE);
} }
/* Update channel list in protocol state */ /* Update channel list in protocol state */
@ -317,9 +317,9 @@ proto_remove_channel(struct proto *p UNUSED, struct channel *c)
*/ */
PST_LOCKED(ts) PST_LOCKED(ts)
{ {
ASSERT_DIE(c->id < ts->length_channels); ASSERT_DIE(c->id < ts->channels_len);
ea_free_later(ts->channels[c->id]); ea_free_later(ts->channel_states[c->id]);
ts->channels[c->id] = NULL; ts->channel_states[c->id] = NULL;
hmap_clear(&ts->channel_id_map, c->id); hmap_clear(&ts->channel_id_map, c->id);
} }
@ -1348,15 +1348,15 @@ proto_new(struct proto_config *cf)
p->id = hmap_first_zero(&tp->proto_id_map); p->id = hmap_first_zero(&tp->proto_id_map);
hmap_set(&tp->proto_id_map, p->id); hmap_set(&tp->proto_id_map, p->id);
if (p->id >= tp->length_states) if (p->id >= tp->proto_len)
{ {
/* Grow the states array */ /* Grow the states array */
ea_list **new_states = mb_allocz(tp->pool, sizeof *new_states * tp->length_states * 2); ea_list **new_states = mb_allocz(tp->pool, sizeof *new_states * tp->proto_len * 2);
memcpy(new_states, tp->states, tp->length_states * sizeof *new_states); memcpy(new_states, tp->proto_states, tp->proto_len * sizeof *new_states);
mb_free(tp->states); mb_free(tp->proto_states);
tp->states = new_states; tp->proto_states = new_states;
tp->length_states *= 2; tp->proto_len *= 2;
} }
} }
@ -2140,15 +2140,15 @@ protos_build(void)
PST_LOCKED(ts) PST_LOCKED(ts)
{ {
ts->length_channels = 64; ts->channels_len = 64;
ts->length_states = 32; ts->proto_len = 32;
hmap_init(&ts->proto_id_map, p, ts->length_states); /* for proto ids. Value of proto id is the same as index of that proto in ptoto_state_table->attrs */ hmap_init(&ts->proto_id_map, p, ts->proto_len); /* for proto ids. Value of proto id is the same as index of that proto in ptoto_state_table->attrs */
hmap_init(&ts->channel_id_map, p, ts->length_channels); hmap_init(&ts->channel_id_map, p, ts->channels_len);
ts->pool = p; ts->pool = p;
ts->states = mb_allocz(p, sizeof(ea_list *) * ts->length_states); ts->proto_states = mb_allocz(p, sizeof(ea_list *) * ts->proto_len);
ts->channels = mb_allocz(p, sizeof(ea_list *) * ts->length_channels * 2); ts->channel_states = mb_allocz(p, sizeof(ea_list *) * ts->channels_len * 2);
} }
/* Init proto state journal */ /* Init proto state journal */
@ -2939,7 +2939,7 @@ proto_journal_item_cleanup_(bool withdrawal, ea_list *old_attr)
{ {
u32 id = ea_get_int(old_attr, &ea_proto_id, 0); u32 id = ea_get_int(old_attr, &ea_proto_id, 0);
ASSERT_DIE(id); ASSERT_DIE(id);
ASSERT_DIE(tp->states[id] == NULL); ASSERT_DIE(tp->proto_states[id] == NULL);
hmap_clear(&tp->proto_id_map, id); hmap_clear(&tp->proto_id_map, id);
} }
} }
@ -2955,7 +2955,7 @@ proto_journal_item_cleanup(struct lfjour * journal UNUSED, struct lfjour_item *i
/* /*
* Protocol state announcement. * Protocol state announcement.
* *
* The authoritative protocol state is always stored in ts->states[p->id] * The authoritative protocol state is always stored in ts->proto_states[p->id]
* and it holds a reference. But sometimes it's too clumsy to announce all * and it holds a reference. But sometimes it's too clumsy to announce all
* protocol changes happening in a fast succession, so there is a * protocol changes happening in a fast succession, so there is a
* state-to-be-announced stored in the protocol itself, in p->ea_state. * state-to-be-announced stored in the protocol itself, in p->ea_state.
@ -3014,15 +3014,15 @@ proto_announce_state_locked(struct proto_state_table_private* ts, struct proto *
} }
/* Then we check the public state */ /* Then we check the public state */
ASSERT_DIE(p->id < ts->length_states); ASSERT_DIE(p->id < ts->proto_len);
ea_list *old_state = ts->states[p->id]; ea_list *old_state = ts->proto_states[p->id];
/* Nothing has changed? */ /* Nothing has changed? */
if (p->ea_state == old_state) if (p->ea_state == old_state)
return; return;
/* Set the new state */ /* Set the new state */
ts->states[p->id] = p->ea_state ? ea_ref(p->ea_state) : NULL; ts->proto_states[p->id] = p->ea_state ? ea_ref(p->ea_state) : NULL;
/* Announce the new state */ /* Announce the new state */
struct lfjour_item *li = lfjour_push_prepare(&proto_state_table_pub.journal); struct lfjour_item *li = lfjour_push_prepare(&proto_state_table_pub.journal);
@ -3094,9 +3094,9 @@ channel_get_state(int id)
{ {
PST_LOCKED(ts) PST_LOCKED(ts)
{ {
ASSERT_DIE((u32) id < ts->length_channels); ASSERT_DIE((u32) id < ts->channels_len);
if (ts->channels[id]) if (ts->channel_states[id])
return ea_ref_tmp(ts->channels[id]); return ea_ref_tmp(ts->channel_states[id]);
} }
return NULL; return NULL;
} }
@ -3107,8 +3107,8 @@ proto_get_state(int id)
ea_list *eal; ea_list *eal;
PST_LOCKED(ts) PST_LOCKED(ts)
{ {
ASSERT_DIE((u32)id < ts->length_states); ASSERT_DIE((u32)id < ts->proto_len);
eal = ts->states[id]; eal = ts->proto_states[id];
} }
if (eal) if (eal)
return ea_ref_tmp(eal); return ea_ref_tmp(eal);

View File

@ -412,10 +412,10 @@ struct proto_state_table_private {
PROTO_STATE_TABLE_PUBLIC; PROTO_STATE_TABLE_PUBLIC;
}; };
struct proto_state_table_private **locked_at; struct proto_state_table_private **locked_at;
ea_list ** states; ea_list ** proto_states;
ea_list ** channels; ea_list ** channel_states;
u32 length_states; u32 proto_len;
u32 length_channels; u32 channels_len;
struct hmap proto_id_map; struct hmap proto_id_map;
struct hmap channel_id_map; struct hmap channel_id_map;
pool *pool; pool *pool;

View File

@ -2025,9 +2025,9 @@ bgp_channel_init(struct channel *C, struct channel_config *CF)
PST_LOCKED(ts) PST_LOCKED(ts)
{ {
ea_list *eal = ea_free_later(ts->channels[c->c.id]); ea_list *eal = ea_free_later(ts->channel_states[c->c.id]);
ea_set_attr(&eal, EA_LITERAL_EMBEDDED(&ea_bgp_afi, 0, c->afi)); ea_set_attr(&eal, EA_LITERAL_EMBEDDED(&ea_bgp_afi, 0, c->afi));
ts->channels[c->c.id] = ea_lookup_slow(eal, 0, EALS_IN_TABLE); ts->channel_states[c->c.id] = ea_lookup_slow(eal, 0, EALS_IN_TABLE);
} }
} }

View File

@ -702,7 +702,7 @@ bmp_add_peer(struct bmp_proto *p, ea_list *bgp_attr)
{ {
ea_list *chan_attr; ea_list *chan_attr;
PST_LOCKED(ts) PST_LOCKED(ts)
chan_attr = ts->channels[chann_ids[i]]; chan_attr = ts->channel_states[chann_ids[i]];
if (chan_attr == NULL) if (chan_attr == NULL)
continue; continue;
@ -1117,7 +1117,7 @@ bmp_startup(struct bmp_proto *p)
/* Send Peer Up messages */ /* Send Peer Up messages */
u32 length; u32 length;
PST_LOCKED(ts) /* The size of protos field will never decrease, the inconsistency caused by growing is not important */ PST_LOCKED(ts) /* The size of protos field will never decrease, the inconsistency caused by growing is not important */
length = ts->length_states; length = ts->proto_len;
/* Subscribe to protocol state changes */ /* Subscribe to protocol state changes */
p->proto_state_reader = (struct lfjour_recipient) { p->proto_state_reader = (struct lfjour_recipient) {

View File

@ -335,9 +335,9 @@ mrt_peer_table_dump(struct mrt_table_dump_state *s)
#ifdef CONFIG_BGP #ifdef CONFIG_BGP
PST_LOCKED(ts) PST_LOCKED(ts)
{ {
for(u32 i = 0; i < ts->length_states; i++) for(u32 i = 0; i < ts->proto_len; i++)
{ {
ea_list *eal = ts->states[i]; ea_list *eal = ts->proto_states[i];
if (eal) if (eal)
ea_free_later(ea_ref(eal)); ea_free_later(ea_ref(eal));
else else