summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaria Matejka <mq@ucw.cz>2022-08-31 11:58:27 +0200
committerMaria Matejka <mq@ucw.cz>2022-09-01 18:46:40 +0200
commit7450eea071941c683da158d6dfe8365288eed5b8 (patch)
tree2c3c7a8251870b0623e89ec0b9ce7deb9000d042
parent83ceb91b50ae75ee5509faa74e2f6d4bdcf78505 (diff)
Miscellaneous refactoring
-rw-r--r--nest/proto.c11
-rw-r--r--nest/rt-table.c60
-rw-r--r--nest/rt.h7
-rw-r--r--proto/bgp/attrs.c7
4 files changed, 43 insertions, 42 deletions
diff --git a/nest/proto.c b/nest/proto.c
index ef3e3f4d..d2374792 100644
--- a/nest/proto.c
+++ b/nest/proto.c
@@ -450,12 +450,8 @@ channel_start_import(struct channel *c)
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) {
- .name = rn,
+ .name = mb_sprintf(c->proto->pool, "%s.%s", c->proto->name, c->name),
.trace_routes = c->debug | c->proto->debug,
.dump_req = channel_dump_import_req,
.log_state_change = channel_import_log_state_change,
@@ -483,12 +479,9 @@ channel_start_export(struct channel *c)
}
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) {
- .name = rn,
+ .name = mb_sprintf(c->proto->pool, "%s.%s", c->proto->name, c->name),
.list = proto_work_list(c->proto),
.addr = c->out_subprefix,
.addr_mode = c->out_subprefix ? TE_ADDR_IN : TE_ADDR_NONE,
diff --git a/nest/rt-table.c b/nest/rt-table.c
index 7fc0d280..d4e0d63c 100644
--- a/nest/rt-table.c
+++ b/nest/rt-table.c
@@ -908,7 +908,7 @@ channel_rpe_mark_seen(struct rt_export_request *req, struct rt_pending_export *r
}
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 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:
/* Check obsolete routes for previously exported */
- while (rpe)
+ RPE_WALK(first, rpe, NULL)
{
channel_rpe_mark_seen(req, rpe);
if (rpe->old)
@@ -963,7 +963,6 @@ done:
old_best = &rpe->old->rte;
}
}
- rpe = rpe_next(rpe, NULL);
}
/* Nothing to export */
@@ -1036,7 +1035,7 @@ rt_export_merged(struct channel *c, struct rte **feed, uint count, linpool *pool
}
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 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 */
- while (rpe)
+ RPE_WALK(first, rpe, NULL)
{
channel_rpe_mark_seen(req, rpe);
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;
}
}
- rpe = rpe_next(rpe, NULL);
}
/* Prepare new merged route */
@@ -1084,17 +1082,16 @@ rt_notify_merged(struct rt_export_request *req, const net_addr *n, struct rt_pen
}
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);
- rte *o = RTE_VALID_OR_NULL(rpe->old_best);
- struct rte_storage *new_best = rpe->new_best;
+ rte *o = RTE_VALID_OR_NULL(first->old_best);
+ struct rte_storage *new_best = first->new_best;
- while (rpe)
+ RPE_WALK(first, rpe, NULL)
{
channel_rpe_mark_seen(req, rpe);
new_best = rpe->new_best;
- rpe = rpe_next(rpe, NULL);
}
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
-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);
- rte *n = RTE_VALID_OR_NULL(rpe->new);
- rte *o = RTE_VALID_OR_NULL(rpe->old);
+ rte *n = RTE_VALID_OR_NULL(first->new);
+ rte *o = RTE_VALID_OR_NULL(first->old);
if (!n && !o)
{
- channel_rpe_mark_seen(req, rpe);
+ channel_rpe_mark_seen(req, first);
return;
}
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);
new_latest = rpe->new;
- rpe = rpe_next(rpe, src);
}
rte n0 = RTE_COPY_VALID(new_latest);
@@ -1362,7 +1358,7 @@ rte_announce(rtable *tab, net *net, struct rte_storage *new, struct rte_storage
&net->last->next, &rpenull, rpe,
memory_order_relaxed,
memory_order_relaxed));
-
+
}
net->last = rpe;
@@ -1918,8 +1914,13 @@ rt_table_export_done(struct rt_export_hook *hook)
struct rt_exporter *re = hook->table;
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);
+
+ /* Free the hook before unlocking the table */
+ rfree(hook->pool);
+
+ /* Unlock the table; this may free it */
+ rt_unlock_table(tab);
}
static void
@@ -1935,13 +1936,10 @@ rt_export_stopped(void *data)
rem_node(&hook->n);
/* Report the channel as stopped. */
- hook->stopped(hook->req);
+ CALL(hook->stopped, hook->req);
/* Reporting the hook as finished. */
CALL(tab->done, hook);
-
- /* Free the hook. */
- rfree(hook->pool);
}
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->import_state = state;
- if (hook->req->log_state_change)
- hook->req->log_state_change(hook->req, state);
+ CALL(hook->req->log_state_change, hook->req, state);
}
void
@@ -1960,8 +1957,7 @@ rt_set_export_state(struct rt_export_hook *hook, u8 state)
hook->last_state_change = current_time();
atomic_store_explicit(&hook->export_state, state, memory_order_release);
- if (hook->req->log_state_change)
- hook->req->log_state_change(hook->req, state);
+ CALL(hook->req->log_state_change, hook->req, state);
}
void
@@ -2919,7 +2915,7 @@ rt_export_cleanup(rtable *tab)
net *net = SKIP_BACK(struct network, n.addr, (net_addr (*)[0]) n);
ASSERT_DIE(net->first == first);
-
+
if (first == net->last)
/* The only export here */
net->last = net->first = NULL;
@@ -2949,7 +2945,7 @@ rt_export_cleanup(rtable *tab)
ASSERT_DIE(pos < end);
struct rt_pending_export *next = NULL;
-
+
if (++pos < end)
next = &reb->export[pos];
else
@@ -3931,9 +3927,7 @@ rt_feed_net(struct rt_export_hook *c, net *n)
count = 1;
}
- for (struct rt_pending_export *rpe = n->first; rpe; rpe = rpe_next(rpe, NULL))
- rpe_mark_seen(c, rpe);
-
+ rpe_mark_seen_all(c, n->first, NULL);
return count;
}
diff --git a/nest/rt.h b/nest/rt.h
index 66edf227..e7ba55f6 100644
--- a/nest/rt.h
+++ b/nest/rt.h
@@ -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. */
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 */
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 */
int rpe_get_seen(struct rt_export_hook *hook, struct rt_pending_export *rpe);
diff --git a/proto/bgp/attrs.c b/proto/bgp/attrs.c
index 2543ee73..84a0b023 100644
--- a/proto/bgp/attrs.c
+++ b/proto/bgp/attrs.c
@@ -1977,6 +1977,12 @@ bgp_out_table_export_start(struct rt_exporter *re, struct rt_export_request *req
return hook;
}
+static void
+bgp_out_table_export_done(struct rt_export_hook *hook)
+{
+ rfree(hook->pool);
+}
+
void
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) {
.addr_type = c->c.table->addr_type,
.start = bgp_out_table_export_start,
+ .done = bgp_out_table_export_done,
};
init_list(&c->prefix_exporter.hooks);