]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Settle timer revised version
authorVojtech Vilimek <vojtech.vilimek@nic.cz>
Thu, 28 Jul 2022 07:25:26 +0000 (09:25 +0200)
committerVojtech Vilimek <vojtech.vilimek@nic.cz>
Thu, 28 Jul 2022 07:25:26 +0000 (09:25 +0200)
Settle timer now doesn't inherit from timer and is meant to be embeded in other
structures.

lib/timer.c
lib/timer.h
nest/rt-table.c
nest/rt.h

index a975a3ef7f58cef5f40f927c91ebaf3a46620714..ca6af34ccbef886f2eef224975f4786114563e51 100644 (file)
@@ -386,11 +386,9 @@ static inline btime
 settled_time(struct settle_timer *st)
 {
   ASSUME(st->base_settle_time != 0);
-  if (st->base_settle_time + *(st->max_settle_time) <
-      st->last_change + *(st->min_settle_time))
-    log(L_INFO "settle_timer will be triggered by MAX SETTLE TIME");
-  return MIN_(st->last_change + *(st->min_settle_time),
-             st->base_settle_time + *(st->max_settle_time));
+
+  return MIN_(st->last_change + st->min_settle_time,
+             st->base_settle_time + st->max_settle_time);
 }
 
 inline void
@@ -402,7 +400,7 @@ settle_timer_changed(struct settle_timer *st)
 void
 settle_timer(timer *t)
 {
-  struct settle_timer *st = (void *) t;
+  struct settle_timer *st = t->data;
 
   if (!st->base_settle_time)
     return;
@@ -410,31 +408,29 @@ settle_timer(timer *t)
   btime settled_t = settled_time(st);
   if (current_time() < settled_t)
   {
-    tm_set((timer *) st, settled_t);
+    tm_set(t, settled_t);
     return;
   }
 
+
   /* Settled */
   st->base_settle_time = 0;
 
-  if (st->class->action)
-    st->class->action(st);
+  /* t->hook already occupied by settle_timer() */
+  if (st->settle_hook)
+    st->settle_hook(st);
 }
 
-struct settle_timer *
-stm_new_timer(pool *p, void *data, struct settle_timer_class *class)
+void
+stm_init(struct settle_timer *st, pool *p, void *data, 
+         void (*settle_hook)(struct settle_timer *st))
 {
-  struct settle_timer *st;
-  st = mb_allocz(p, sizeof(struct settle_timer));
-  st->class = class;
-
-  /* timer option randomize and recurrent are set to zero */
-  timer *t = (void *) st;
-  t->index = -1;
-  t->hook = settle_timer;
-  t->data = data;
+  st->t = tm_new_init(p, (void *) st, settle_timer, 0, 0); 
+  st->t->hook = settle_timer;
+  st->t->data = (void *) st;
 
-  return st;
+  st->settle_data = data;
+  st->settle_hook = settle_hook;
 }
 
 void
@@ -444,7 +440,7 @@ kick_settle_timer(struct settle_timer *st)
 
   st->base_settle_time = current_time();
 
-  timer *t = (void *) st;
+  timer *t = st->t;
   if (!tm_active(t))
     tm_set(t, settled_time(st));
 }
index 00950e08f4fe5437c94176e8080c9246ce0d8f8e..8f047319ad32ba5bda6447057d51b21510607f61 100644 (file)
@@ -129,21 +129,16 @@ int tm_format_real_time(char *x, size_t max, const char *fmt, btime t);
  */
 
 struct settle_timer {
-  timer tm;
-  btime *min_settle_time;
-  btime *max_settle_time;
+  btime min_settle_time;
+  btime max_settle_time;
   btime base_settle_time;
   btime last_change;
-  const struct settle_timer_class *class;
+  timer *t;
+  void (*settle_hook)(struct settle_timer *t);
+  void *settle_data;
 };
 
-struct settle_timer_class {
-  void (*action)(struct settle_timer *st);
-  void (*changed)(struct settle_timer *st);
-  void (*kick)(struct settle_timer *st);
-};
-
-struct settle_timer *stm_new_timer(pool *p, void *data, struct settle_timer_class *class);
+void stm_init(struct settle_timer *st, pool *p, void *data, void (*settle_hook)(struct settle_timer *st));
 void kick_settle_timer(struct settle_timer *st);
 void settle_timer_changed(struct settle_timer *st);
 
index 428628ebc1d917645a3ada9c4d4549c9f9cd1dba..7caa956ff625930b3bec18db24f126c75f0e9af4 100644 (file)
@@ -1365,7 +1365,7 @@ rte_recalculate(struct rt_import_hook *c, net *net, rte *new, struct rte_src *sr
     stats->withdraws_ignored++;
 
   if (old_ok || new_ok)
-    settle_timer_changed(table->settle_timer);
+    settle_timer_changed(&table->settle_timer);
 
   if (table->config->sorted)
     {
@@ -2019,7 +2019,7 @@ rt_dump_hooks(rtable *tab)
   debug("  nhu_state=%u hcu_scheduled=%u use_count=%d rt_count=%u\n",
       tab->nhu_state, tab->hcu_scheduled, tab->use_count, tab->rt_count);
   debug("  last_rt_change=%t gc_time=%t gc_counter=%d prune_state=%u\n",
-      tab->settle_timer->last_change, tab->gc_time, tab->gc_counter, tab->prune_state);
+      tab->settle_timer.last_change, tab->gc_time, tab->gc_counter, tab->prune_state);
 
   struct rt_import_hook *ih;
   WALK_LIST(ih, tab->imports)
@@ -2136,29 +2136,23 @@ rt_kick_prune_timer(rtable *tab)
 static void
 rt_settle_timer(struct settle_timer *st)
 {
-  timer *t = (void *) st;
-  rtable *tab = t->data;
+  rtable *tab = st->settle_data;
 
   struct rt_subscription *s;
   WALK_LIST(s, tab->subscribers)
     s->hook(s);
 }
 
-static struct settle_timer_class rt_settle_class = {
-  .action = rt_settle_timer,
-  .kick = NULL,
-};
-
 static inline void
 rt_schedule_notify(rtable *tab)
 {
   if (EMPTY_LIST(tab->subscribers))
     return;
 
-  if (tab->settle_timer->base_settle_time)
+  if (tab->settle_timer.base_settle_time)
     return;
 
-  kick_settle_timer(tab->settle_timer);
+  kick_settle_timer(&tab->settle_timer);
 }
 
 void
@@ -2344,9 +2338,9 @@ rt_setup(pool *pp, struct rtable_config *cf)
 
   t->rt_event = ev_new_init(p, rt_event, t);
   t->prune_timer = tm_new_init(p, rt_prune_timer, t, 0, 0);
-  t->settle_timer = stm_new_timer(p, t, &rt_settle_class);
+  stm_init(&t->settle_timer, p, t, rt_settle_timer);
 
-  settle_timer_changed(t->settle_timer);
+  settle_timer_changed(&t->settle_timer);
   t->gc_time = current_time();
 
   t->rl_pipe = (struct tbf) TBF_DEFAULT_LOG_LIMITS;
index 6c19677bf00b861d962cb0ae9c524cc875ec031c..4abb269c78d79b7d22022f0ea87dfa110102e74b 100644 (file)
--- a/nest/rt.h
+++ b/nest/rt.h
@@ -106,7 +106,7 @@ typedef struct rtable {
   struct tbf rl_pipe;                  /* Rate limiting token buffer for pipe collisions */
 
   list subscribers;                    /* Subscribers for notifications */
-  struct settle_timer *settle_timer;   /* Settle time for notifications */
+  struct settle_timer settle_timer;    /* Settle time for notifications */
   list flowspec_links;                 /* List of flowspec links, src for NET_IPx and dst for NET_FLOWx */
   struct f_trie *flowspec_trie;                /* Trie for evaluation of flowspec notifications */
 } rtable;