From 9cf3d533110313d55b60d47c134f1b7050d6be78 Mon Sep 17 00:00:00 2001 From: "Ondrej Zajicek (work)" Date: Wed, 10 Mar 2021 15:07:19 +0100 Subject: Static: Implement reload hook --- proto/static/static.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 3 deletions(-) (limited to 'proto/static/static.c') diff --git a/proto/static/static.c b/proto/static/static.c index 31b7f5d6..661f1aac 100644 --- a/proto/static/static.c +++ b/proto/static/static.c @@ -148,15 +148,48 @@ static_mark_rte(struct static_proto *p, struct static_route *r) ev_schedule(p->event); } +static void +static_mark_all(struct static_proto *p) +{ + struct static_config *cf = (void *) p->p.cf; + struct static_route *r; + + /* We want to reload all routes, mark them as dirty */ + + WALK_LIST(r, cf->routes) + if (r->state == SRS_CLEAN) + r->state = SRS_DIRTY; + + p->marked_all = 1; + BUFFER_FLUSH(p->marked); + + if (!ev_active(p->event)) + ev_schedule(p->event); +} + + static void static_announce_marked(void *P) { struct static_proto *p = P; + struct static_config *cf = (void *) p->p.cf; + struct static_route *r; - BUFFER_WALK(p->marked, r) - static_announce_rte(P, r); + if (p->marked_all) + { + WALK_LIST(r, cf->routes) + if (r->state == SRS_DIRTY) + static_announce_rte(p, r); - BUFFER_FLUSH(p->marked); + p->marked_all = 0; + } + else + { + BUFFER_WALK(p->marked, r) + static_announce_rte(p, r); + + BUFFER_FLUSH(p->marked); + } } static void @@ -367,6 +400,16 @@ static_bfd_notify(struct bfd_request *req) static_mark_rte(p, r->mp_head); } +static void +static_reload_routes(struct channel *C) +{ + struct static_proto *p = (void *) C->proto; + + TRACE(D_EVENTS, "Scheduling route reload"); + + static_mark_all(p); +} + static int static_rte_better(rte *new, rte *old) { @@ -421,6 +464,7 @@ static_init(struct proto_config *CF) P->main_channel = proto_add_channel(P, proto_cf_main_channel(CF)); P->neigh_notify = static_neigh_notify; + P->reload_routes = static_reload_routes; P->rte_better = static_rte_better; P->rte_mergable = static_rte_mergable; @@ -633,6 +677,10 @@ static_reconfigure(struct proto *P, struct proto_config *CF) xfree(orbuf); xfree(nrbuf); + /* All dirty routes were announced anyways */ + BUFFER_FLUSH(p->marked); + p->marked_all = 0; + return 1; } -- cgit v1.2.3