0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-09-19 20:05:21 +00:00

Miscellaneous refactoring

This commit is contained in:
Maria Matejka 2022-08-31 11:58:27 +02:00
parent 83ceb91b50
commit 7450eea071
4 changed files with 43 additions and 42 deletions

View File

@ -450,12 +450,8 @@ channel_start_import(struct channel *c)
return; return;
} }
int nlen = strlen(c->name) + strlen(c->proto->name) + 2;
char *rn = mb_allocz(c->proto->pool, nlen);
bsprintf(rn, "%s.%s", c->proto->name, c->name);
c->in_req = (struct rt_import_request) { c->in_req = (struct rt_import_request) {
.name = rn, .name = mb_sprintf(c->proto->pool, "%s.%s", c->proto->name, c->name),
.trace_routes = c->debug | c->proto->debug, .trace_routes = c->debug | c->proto->debug,
.dump_req = channel_dump_import_req, .dump_req = channel_dump_import_req,
.log_state_change = channel_import_log_state_change, .log_state_change = channel_import_log_state_change,
@ -483,12 +479,9 @@ channel_start_export(struct channel *c)
} }
ASSERT(c->channel_state == CS_UP); ASSERT(c->channel_state == CS_UP);
int nlen = strlen(c->name) + strlen(c->proto->name) + 2;
char *rn = mb_allocz(c->proto->pool, nlen);
bsprintf(rn, "%s.%s", c->proto->name, c->name);
c->out_req = (struct rt_export_request) { c->out_req = (struct rt_export_request) {
.name = rn, .name = mb_sprintf(c->proto->pool, "%s.%s", c->proto->name, c->name),
.list = proto_work_list(c->proto), .list = proto_work_list(c->proto),
.addr = c->out_subprefix, .addr = c->out_subprefix,
.addr_mode = c->out_subprefix ? TE_ADDR_IN : TE_ADDR_NONE, .addr_mode = c->out_subprefix ? TE_ADDR_IN : TE_ADDR_NONE,

View File

@ -908,7 +908,7 @@ channel_rpe_mark_seen(struct rt_export_request *req, struct rt_pending_export *r
} }
void void
rt_notify_accepted(struct rt_export_request *req, const net_addr *n, struct rt_pending_export *rpe, rt_notify_accepted(struct rt_export_request *req, const net_addr *n, struct rt_pending_export *first,
struct rte **feed, uint count) struct rte **feed, uint count)
{ {
struct channel *c = SKIP_BACK(struct channel, out_req, req); struct channel *c = SKIP_BACK(struct channel, out_req, req);
@ -952,7 +952,7 @@ rt_notify_accepted(struct rt_export_request *req, const net_addr *n, struct rt_p
done: done:
/* Check obsolete routes for previously exported */ /* Check obsolete routes for previously exported */
while (rpe) RPE_WALK(first, rpe, NULL)
{ {
channel_rpe_mark_seen(req, rpe); channel_rpe_mark_seen(req, rpe);
if (rpe->old) if (rpe->old)
@ -963,7 +963,6 @@ done:
old_best = &rpe->old->rte; old_best = &rpe->old->rte;
} }
} }
rpe = rpe_next(rpe, NULL);
} }
/* Nothing to export */ /* Nothing to export */
@ -1036,7 +1035,7 @@ rt_export_merged(struct channel *c, struct rte **feed, uint count, linpool *pool
} }
void void
rt_notify_merged(struct rt_export_request *req, const net_addr *n, struct rt_pending_export *rpe, rt_notify_merged(struct rt_export_request *req, const net_addr *n, struct rt_pending_export *first,
struct rte **feed, uint count) struct rte **feed, uint count)
{ {
struct channel *c = SKIP_BACK(struct channel, out_req, req); struct channel *c = SKIP_BACK(struct channel, out_req, req);
@ -1062,7 +1061,7 @@ rt_notify_merged(struct rt_export_request *req, const net_addr *n, struct rt_pen
} }
/* Check obsolete routes for previously exported */ /* Check obsolete routes for previously exported */
while (rpe) RPE_WALK(first, rpe, NULL)
{ {
channel_rpe_mark_seen(req, rpe); channel_rpe_mark_seen(req, rpe);
if (rpe->old) if (rpe->old)
@ -1073,7 +1072,6 @@ rt_notify_merged(struct rt_export_request *req, const net_addr *n, struct rt_pen
old_best = &rpe->old->rte; old_best = &rpe->old->rte;
} }
} }
rpe = rpe_next(rpe, NULL);
} }
/* Prepare new merged route */ /* Prepare new merged route */
@ -1084,17 +1082,16 @@ rt_notify_merged(struct rt_export_request *req, const net_addr *n, struct rt_pen
} }
void void
rt_notify_optimal(struct rt_export_request *req, const net_addr *net, struct rt_pending_export *rpe) rt_notify_optimal(struct rt_export_request *req, const net_addr *net, struct rt_pending_export *first)
{ {
struct channel *c = SKIP_BACK(struct channel, out_req, req); struct channel *c = SKIP_BACK(struct channel, out_req, req);
rte *o = RTE_VALID_OR_NULL(rpe->old_best); rte *o = RTE_VALID_OR_NULL(first->old_best);
struct rte_storage *new_best = rpe->new_best; struct rte_storage *new_best = first->new_best;
while (rpe) RPE_WALK(first, rpe, NULL)
{ {
channel_rpe_mark_seen(req, rpe); channel_rpe_mark_seen(req, rpe);
new_best = rpe->new_best; new_best = rpe->new_best;
rpe = rpe_next(rpe, NULL);
} }
rte n0 = RTE_COPY_VALID(new_best); rte n0 = RTE_COPY_VALID(new_best);
@ -1103,27 +1100,26 @@ rt_notify_optimal(struct rt_export_request *req, const net_addr *net, struct rt_
} }
void void
rt_notify_any(struct rt_export_request *req, const net_addr *net, struct rt_pending_export *rpe) rt_notify_any(struct rt_export_request *req, const net_addr *net, struct rt_pending_export *first)
{ {
struct channel *c = SKIP_BACK(struct channel, out_req, req); struct channel *c = SKIP_BACK(struct channel, out_req, req);
rte *n = RTE_VALID_OR_NULL(rpe->new); rte *n = RTE_VALID_OR_NULL(first->new);
rte *o = RTE_VALID_OR_NULL(rpe->old); rte *o = RTE_VALID_OR_NULL(first->old);
if (!n && !o) if (!n && !o)
{ {
channel_rpe_mark_seen(req, rpe); channel_rpe_mark_seen(req, first);
return; return;
} }
struct rte_src *src = n ? n->src : o->src; struct rte_src *src = n ? n->src : o->src;
struct rte_storage *new_latest = rpe->new; struct rte_storage *new_latest = first->new;
while (rpe) RPE_WALK(first, rpe, src)
{ {
channel_rpe_mark_seen(req, rpe); channel_rpe_mark_seen(req, rpe);
new_latest = rpe->new; new_latest = rpe->new;
rpe = rpe_next(rpe, src);
} }
rte n0 = RTE_COPY_VALID(new_latest); rte n0 = RTE_COPY_VALID(new_latest);
@ -1918,8 +1914,13 @@ rt_table_export_done(struct rt_export_hook *hook)
struct rt_exporter *re = hook->table; struct rt_exporter *re = hook->table;
struct rtable *tab = SKIP_BACK(struct rtable, exporter, re); struct rtable *tab = SKIP_BACK(struct rtable, exporter, re);
rt_unlock_table(tab);
DBG("Export hook %p in table %s finished uc=%u\n", hook, tab->name, tab->use_count); DBG("Export hook %p in table %s finished uc=%u\n", hook, tab->name, tab->use_count);
/* Free the hook before unlocking the table */
rfree(hook->pool);
/* Unlock the table; this may free it */
rt_unlock_table(tab);
} }
static void static void
@ -1935,13 +1936,10 @@ rt_export_stopped(void *data)
rem_node(&hook->n); rem_node(&hook->n);
/* Report the channel as stopped. */ /* Report the channel as stopped. */
hook->stopped(hook->req); CALL(hook->stopped, hook->req);
/* Reporting the hook as finished. */ /* Reporting the hook as finished. */
CALL(tab->done, hook); CALL(tab->done, hook);
/* Free the hook. */
rfree(hook->pool);
} }
static inline void static inline void
@ -1950,8 +1948,7 @@ rt_set_import_state(struct rt_import_hook *hook, u8 state)
hook->last_state_change = current_time(); hook->last_state_change = current_time();
hook->import_state = state; hook->import_state = state;
if (hook->req->log_state_change) CALL(hook->req->log_state_change, hook->req, state);
hook->req->log_state_change(hook->req, state);
} }
void void
@ -1960,8 +1957,7 @@ rt_set_export_state(struct rt_export_hook *hook, u8 state)
hook->last_state_change = current_time(); hook->last_state_change = current_time();
atomic_store_explicit(&hook->export_state, state, memory_order_release); atomic_store_explicit(&hook->export_state, state, memory_order_release);
if (hook->req->log_state_change) CALL(hook->req->log_state_change, hook->req, state);
hook->req->log_state_change(hook->req, state);
} }
void void
@ -3931,9 +3927,7 @@ rt_feed_net(struct rt_export_hook *c, net *n)
count = 1; count = 1;
} }
for (struct rt_pending_export *rpe = n->first; rpe; rpe = rpe_next(rpe, NULL)) rpe_mark_seen_all(c, n->first, NULL);
rpe_mark_seen(c, rpe);
return count; return count;
} }

View File

@ -386,9 +386,16 @@ void rte_import(struct rt_import_request *req, const net_addr *net, rte *new, st
/* Get next rpe. If src is given, it must match. */ /* Get next rpe. If src is given, it must match. */
struct rt_pending_export *rpe_next(struct rt_pending_export *rpe, struct rte_src *src); struct rt_pending_export *rpe_next(struct rt_pending_export *rpe, struct rte_src *src);
/* Walk all rpe's */
#define RPE_WALK(first, it, src) \
for (struct rt_pending_export *it = (first); it; it = rpe_next(it, (src)))
/* Mark the pending export processed */ /* Mark the pending export processed */
void rpe_mark_seen(struct rt_export_hook *hook, struct rt_pending_export *rpe); void rpe_mark_seen(struct rt_export_hook *hook, struct rt_pending_export *rpe);
#define rpe_mark_seen_all(hook, first, src) \
RPE_WALK(first, rpe, src) rpe_mark_seen((hook), rpe)
/* Get pending export seen status */ /* Get pending export seen status */
int rpe_get_seen(struct rt_export_hook *hook, struct rt_pending_export *rpe); int rpe_get_seen(struct rt_export_hook *hook, struct rt_pending_export *rpe);

View File

@ -1977,6 +1977,12 @@ bgp_out_table_export_start(struct rt_exporter *re, struct rt_export_request *req
return hook; return hook;
} }
static void
bgp_out_table_export_done(struct rt_export_hook *hook)
{
rfree(hook->pool);
}
void void
bgp_setup_out_table(struct bgp_channel *c) bgp_setup_out_table(struct bgp_channel *c)
{ {
@ -1985,6 +1991,7 @@ bgp_setup_out_table(struct bgp_channel *c)
c->prefix_exporter = (struct rt_exporter) { c->prefix_exporter = (struct rt_exporter) {
.addr_type = c->c.table->addr_type, .addr_type = c->c.table->addr_type,
.start = bgp_out_table_export_start, .start = bgp_out_table_export_start,
.done = bgp_out_table_export_done,
}; };
init_list(&c->prefix_exporter.hooks); init_list(&c->prefix_exporter.hooks);