summaryrefslogtreecommitdiff
path: root/nest/proto.c
diff options
context:
space:
mode:
authorMaria Matejka <mq@ucw.cz>2022-09-09 15:04:36 +0200
committerMaria Matejka <mq@ucw.cz>2022-09-09 18:53:15 +0200
commit974f16b1f70ae8b7fa4efa6a217988e1811069e7 (patch)
tree4a0f0851c92f8c4e6ef1fb5496b85391062ef981 /nest/proto.c
parent31e881bcbd59cf55c8614a7a7324d4a7ed8f3ed8 (diff)
Created a dedicated settle timer structure
Diffstat (limited to 'nest/proto.c')
-rw-r--r--nest/proto.c53
1 files changed, 22 insertions, 31 deletions
diff --git a/nest/proto.c b/nest/proto.c
index 783a936c..8c8daa0a 100644
--- a/nest/proto.c
+++ b/nest/proto.c
@@ -315,16 +315,15 @@ proto_remove_channels(struct proto *p)
struct roa_subscription {
node roa_node;
- timer t;
- btime base_settle_time; /* Start of settling interval */
+ struct settle settle;
struct channel *c;
struct rt_export_request req;
};
static void
-channel_roa_in_changed(struct timer *t)
+channel_roa_in_changed(struct settle *se)
{
- struct roa_subscription *s = SKIP_BACK(struct roa_subscription, t, t);
+ struct roa_subscription *s = SKIP_BACK(struct roa_subscription, settle, se);
struct channel *c = s->c;
int active = !!c->reload_req.hook;
@@ -337,9 +336,9 @@ channel_roa_in_changed(struct timer *t)
}
static void
-channel_roa_out_changed(struct timer *t)
+channel_roa_out_changed(struct settle *se)
{
- struct roa_subscription *s = SKIP_BACK(struct roa_subscription, t, t);
+ struct roa_subscription *s = SKIP_BACK(struct roa_subscription, settle, se);
struct channel *c = s->c;
CD(c, "Feeding triggered by RPKI change");
@@ -356,17 +355,7 @@ channel_export_one_roa(struct rt_export_request *req, const net_addr *net UNUSED
struct roa_subscription *s = SKIP_BACK(struct roa_subscription, req, req);
/* TODO: use the information about what roa has changed */
-
- if (!tm_active(&s->t))
- {
- s->base_settle_time = current_time();
- tm_start(&s->t, s->base_settle_time + s->c->min_settle_time);
- }
- else
- tm_set(&s->t,
- MIN(s->base_settle_time + s->c->max_settle_time,
- current_time() + s->c->min_settle_time));
-
+ settle_kick(&s->settle, &main_birdloop);
rpe_mark_seen_all(req->hook, first, NULL);
}
@@ -380,14 +369,14 @@ channel_dump_roa_req(struct rt_export_request *req)
debug(" Channel %s.%s ROA %s change notifier from table %s request %p\n",
c->proto->name, c->name,
- (s->t.hook == channel_roa_in_changed) ? "import" : "export",
+ (s->settle.hook == channel_roa_in_changed) ? "import" : "export",
tab->name, req);
}
static int
channel_roa_is_subscribed(struct channel *c, rtable *tab, int dir)
{
- void (*hook)(struct timer *) =
+ void (*hook)(struct settle *) =
dir ? channel_roa_in_changed : channel_roa_out_changed;
struct roa_subscription *s;
@@ -395,7 +384,7 @@ channel_roa_is_subscribed(struct channel *c, rtable *tab, int dir)
WALK_LIST2(s, n, c->roa_subscriptions, roa_node)
if ((tab == SKIP_BACK(rtable, priv.exporter.e, s->req.hook->table))
- && (s->t.hook == hook))
+ && (s->settle.hook == hook))
return 1;
return 0;
@@ -410,7 +399,7 @@ channel_roa_subscribe(struct channel *c, rtable *tab, int dir)
struct roa_subscription *s = mb_allocz(c->proto->pool, sizeof(struct roa_subscription));
*s = (struct roa_subscription) {
- .t = { .hook = dir ? channel_roa_in_changed : channel_roa_out_changed, },
+ .settle = SETTLE_INIT(&c->roa_settle, dir ? channel_roa_in_changed : channel_roa_out_changed, NULL),
.c = c,
.req = {
.name = mb_sprintf(c->proto->pool, "%s.%s.roa-%s.%s",
@@ -934,8 +923,10 @@ channel_config_new(const struct channel_class *cc, const char *name, uint net_ty
cf->debug = new_config->channel_default_debug;
cf->rpki_reload = 1;
- cf->min_settle_time = 1 S;
- cf->max_settle_time = 20 S;
+ cf->roa_settle = (struct settle_config) {
+ .min = 1 S,
+ .max = 20 S,
+ };
add_tail(&proto->channels, &cf->n);
@@ -1017,20 +1008,20 @@ channel_reconfigure(struct channel *c, struct channel_config *cf)
c->in_req.trace_routes = c->out_req.trace_routes = c->debug | c->proto->debug;
c->rpki_reload = cf->rpki_reload;
- if ( (c->min_settle_time != cf->min_settle_time)
- || (c->max_settle_time != cf->max_settle_time))
+ if ( (c->roa_settle.min != cf->roa_settle.min)
+ || (c->roa_settle.max != cf->roa_settle.max))
{
- c->min_settle_time = cf->min_settle_time;
- c->max_settle_time = cf->max_settle_time;
+ c->roa_settle = cf->roa_settle;
struct roa_subscription *s;
node *n;
WALK_LIST2(s, n, c->roa_subscriptions, roa_node)
- if (tm_active(&s->t))
- tm_set(&s->t,
- MIN(s->base_settle_time + c->max_settle_time,
- current_time() + c->min_settle_time));
+ {
+ s->settle.cf = cf->roa_settle;
+ if (settle_active(&s->settle))
+ settle_kick(&s->settle, &main_birdloop);
+ }
}
/* Execute channel-specific reconfigure hook */