]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Static: Implement reload hook
authorOndrej Zajicek (work) <santiago@crfreenet.org>
Wed, 10 Mar 2021 14:07:19 +0000 (15:07 +0100)
committerOndrej Zajicek (work) <santiago@crfreenet.org>
Wed, 10 Mar 2021 14:07:19 +0000 (15:07 +0100)
proto/static/static.c
proto/static/static.h

index 31b7f5d609528d1e35c743b81abb3867df3deaeb..661f1aac96e94e3db34f5f9b948553393277a725 100644 (file)
@@ -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;
 }
 
index af714b727227351a5d66a42346574e797d94bb77..fc91f71c6ead13241a62126234abb99bb1410b67 100644 (file)
@@ -26,6 +26,7 @@ struct static_proto {
 
   struct event *event;                 /* Event for announcing updated routes */
   BUFFER_(struct static_route *) marked; /* Routes marked for reannouncement */
+  int marked_all;                      /* All routes are marked */
   rtable *igp_table_ip4;               /* Table for recursive IPv4 next hop lookups */
   rtable *igp_table_ip6;               /* Table for recursive IPv6 next hop lookups */
 };