]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
OSPF: Update to new timers
authorOndrej Zajicek (work) <santiago@crfreenet.org>
Tue, 20 Jun 2017 16:03:06 +0000 (18:03 +0200)
committerOndrej Zajicek (work) <santiago@crfreenet.org>
Thu, 7 Dec 2017 12:53:42 +0000 (13:53 +0100)
Note that recurrent timers are currently limited to ~1 hour.

proto/ospf/dbdes.c
proto/ospf/iface.c
proto/ospf/lsalib.h
proto/ospf/lsupd.c
proto/ospf/neighbor.c
proto/ospf/ospf.c
proto/ospf/ospf.h
proto/ospf/packet.c
proto/ospf/rt.c
proto/ospf/topology.c
proto/ospf/topology.h

index a4452cc82315d49f75f0792057d55f15cadf57a9..270259a71bb21a0d252a5564c12fea91a527ea6a 100644 (file)
@@ -279,8 +279,8 @@ ospf_process_dbdes(struct ospf_proto *p, struct ospf_packet *pkt, struct ospf_ne
       req->lsa = lsa;
       req->lsa_body = LSA_BODY_DUMMY;
 
-      if (!tm_active(n->lsrq_timer))
-       tm_start(n->lsrq_timer, 0);
+      if (!tm2_active(n->lsrq_timer))
+       tm2_start(n->lsrq_timer, 0);
     }
   }
 
@@ -366,7 +366,7 @@ ospf_receive_dbdes(struct ospf_packet *pkt, struct ospf_iface *ifa,
       n->options = rcv_options;
       n->myimms &= ~DBDES_MS;
       n->imms = rcv_imms;
-      tm_stop(n->dbdes_timer);
+      tm2_stop(n->dbdes_timer);
       ospf_neigh_sm(n, INM_NEGDONE);
       ospf_send_dbdes(p, n);
       break;
@@ -422,13 +422,13 @@ ospf_receive_dbdes(struct ospf_packet *pkt, struct ospf_iface *ifa,
 
       if (!(n->myimms & DBDES_M) && !(n->imms & DBDES_M))
       {
-       tm_stop(n->dbdes_timer);
+       tm2_stop(n->dbdes_timer);
        ospf_neigh_sm(n, INM_EXDONE);
        break;
       }
 
       ospf_send_dbdes(p, n);
-      tm_start(n->dbdes_timer, n->ifa->rxmtint);
+      tm2_start(n->dbdes_timer, n->ifa->rxmtint S);
     }
     else
     {
index d1f9365eff69cd5ce5e5e61ef4fc1a1a505e9077..33ec21fb643c142378dcab74cdc7a6394e332c9e 100644 (file)
@@ -263,13 +263,13 @@ ospf_iface_down(struct ospf_iface *ifa)
     ospf_neigh_sm(n, INM_KILLNBR);
 
   if (ifa->hello_timer)
-    tm_stop(ifa->hello_timer);
+    tm2_stop(ifa->hello_timer);
 
   if (ifa->poll_timer)
-    tm_stop(ifa->poll_timer);
+    tm2_stop(ifa->poll_timer);
 
   if (ifa->wait_timer)
-    tm_stop(ifa->wait_timer);
+    tm2_stop(ifa->wait_timer);
 
   ospf_flush2_lsa(p, &ifa->link_lsa);
   ospf_flush2_lsa(p, &ifa->net_lsa);
@@ -396,15 +396,15 @@ ospf_iface_sm(struct ospf_iface *ifa, int event)
        {
          ospf_iface_chstate(ifa, OSPF_IS_WAITING);
          if (ifa->wait_timer)
-           tm_start(ifa->wait_timer, ifa->waitint);
+           tm2_start(ifa->wait_timer, ifa->waitint S);
        }
       }
 
       if (ifa->hello_timer)
-       tm_start(ifa->hello_timer, ifa->helloint);
+       tm2_start(ifa->hello_timer, ifa->helloint S);
 
       if (ifa->poll_timer)
-       tm_start(ifa->poll_timer, ifa->pollint);
+       tm2_start(ifa->poll_timer, ifa->pollint S);
 
       ospf_send_hello(ifa, OHS_HELLO, NULL);
     }
@@ -494,13 +494,13 @@ ospf_iface_add(struct object_lock *lock)
 
   if (! ifa->stub)
   {
-    ifa->hello_timer = tm_new_set(ifa->pool, hello_timer_hook, ifa, 0, ifa->helloint);
+    ifa->hello_timer = tm2_new_init(ifa->pool, hello_timer_hook, ifa, ifa->helloint S, 0);
 
     if (ifa->type == OSPF_IT_NBMA)
-      ifa->poll_timer = tm_new_set(ifa->pool, poll_timer_hook, ifa, 0, ifa->pollint);
+      ifa->poll_timer = tm2_new_init(ifa->pool, poll_timer_hook, ifa, ifa->pollint S, 0);
 
     if ((ifa->type == OSPF_IT_BCAST) || (ifa->type == OSPF_IT_NBMA))
-      ifa->wait_timer = tm_new_set(ifa->pool, wait_timer_hook, ifa, 0, 0);
+      ifa->wait_timer = tm2_new_init(ifa->pool, wait_timer_hook, ifa, 0, 0);
 
     ifa->flood_queue_size = ifa_flood_queue_size(ifa);
     ifa->flood_queue = mb_allocz(ifa->pool, ifa->flood_queue_size * sizeof(void *));
@@ -703,7 +703,7 @@ ospf_iface_new_vlink(struct ospf_proto *p, struct ospf_iface_patt *ip)
 
   add_tail(&p->iface_list, NODE ifa);
 
-  ifa->hello_timer = tm_new_set(ifa->pool, hello_timer_hook, ifa, 0, ifa->helloint);
+  ifa->hello_timer = tm2_new_init(ifa->pool, hello_timer_hook, ifa, ifa->helloint S, 0);
 
   ifa->flood_queue_size = ifa_flood_queue_size(ifa);
   ifa->flood_queue = mb_allocz(ifa->pool, ifa->flood_queue_size * sizeof(void *));
@@ -717,8 +717,8 @@ ospf_iface_change_timer(timer *tm, uint val)
 
   tm->recurrent = val S;
 
-  if (tm_active(tm))
-    tm_start(tm, val);
+  if (tm2_active(tm))
+    tm2_start(tm, val S);
 }
 
 static inline void
@@ -801,8 +801,8 @@ ospf_iface_reconfigure(struct ospf_iface *ifa, struct ospf_iface_patt *new)
               ifname, ifa->waitint, new->waitint);
 
     ifa->waitint = new->waitint;
-    if (ifa->wait_timer && ifa->wait_timer->expires)
-      tm_start(ifa->wait_timer, ifa->waitint);
+    if (ifa->wait_timer && tm2_active(ifa->wait_timer))
+      tm2_start(ifa->wait_timer, ifa->waitint S);
   }
 
   /* DEAD TIMER */
index 0d477f58b44db415e3300aa02f1dd51184b55667..fca7faec78bd5ef9f3944a25903b23a55f683980 100644 (file)
@@ -60,4 +60,7 @@ void lsa_parse_sum_rt(struct top_hash_entry *en, int ospf2, u32 *drid, u32 *metr
 void lsa_parse_ext(struct top_hash_entry *en, int ospf2, int af, struct ospf_lsa_ext_local *rt);
 int lsa_validate(struct ospf_lsa_header *lsa, u32 lsa_type, int ospf2, void *body);
 
+static inline btime lsa_inst_age(struct top_hash_entry *en)
+{ return current_time() - en->inst_time; }
+
 #endif /* _BIRD_OSPF_LSALIB_H_ */
index 157d96281862eccbaa6d0e1dfe10864a2e4ec6ee..18811392a791e06620575213d6e2f60eea98ff0e 100644 (file)
@@ -115,7 +115,7 @@ ospf_lsa_lsrq_down(struct top_hash_entry *req, struct ospf_neighbor *n)
 
   if (EMPTY_SLIST(n->lsrql))
   {
-    tm_stop(n->lsrq_timer);
+    tm2_stop(n->lsrq_timer);
 
     if (n->state == NEIGHBOR_LOADING)
       ospf_neigh_sm(n, INM_LOADDONE);
@@ -136,8 +136,8 @@ ospf_lsa_lsrt_up(struct top_hash_entry *en, struct ospf_neighbor *n)
   ret->lsa = en->lsa;
   ret->lsa_body = LSA_BODY_DUMMY;
 
-  if (!tm_active(n->lsrt_timer))
-    tm_start(n->lsrt_timer, n->ifa->rxmtint);
+  if (!tm2_active(n->lsrt_timer))
+    tm2_start(n->lsrt_timer, n->ifa->rxmtint S);
 }
 
 void
@@ -150,7 +150,7 @@ ospf_lsa_lsrt_down_(struct top_hash_entry *en, struct ospf_neighbor *n, struct t
   ospf_hash_delete(n->lsrth, ret);
 
   if (EMPTY_SLIST(n->lsrtl))
-    tm_stop(n->lsrt_timer);
+    tm2_stop(n->lsrt_timer);
 }
 
 static inline int
@@ -175,8 +175,8 @@ ospf_add_flushed_to_lsrt(struct ospf_proto *p, struct ospf_neighbor *n)
       ospf_lsa_lsrt_up(en, n);
 
   /* If we found any flushed LSA, we send them ASAP */
-  if (tm_active(n->lsrt_timer))
-    tm_start(n->lsrt_timer, 0);
+  if (tm2_active(n->lsrt_timer))
+    tm2_start(n->lsrt_timer, 0);
 }
 
 static int ospf_flood_lsupd(struct ospf_proto *p, struct top_hash_entry **lsa_list, uint lsa_count, uint lsa_min_count, struct ospf_iface *ifa);
@@ -572,7 +572,7 @@ ospf_receive_lsupd(struct ospf_packet *pkt, struct ospf_iface *ifa,
     {
       /* 13. (5a) - enforce minimum time between updates for received LSAs */
       /* We also use this to ratelimit reactions to received self-originated LSAs */
-      if (en && ((now - en->inst_time) < MINLSARRIVAL))
+      if (en && (lsa_inst_age(en) < MINLSARRIVAL))
       {
        OSPF_TRACE(D_EVENTS, "Skipping LSA received in less that MinLSArrival");
        continue;
@@ -700,7 +700,7 @@ ospf_receive_lsupd(struct ospf_packet *pkt, struct ospf_iface *ifa,
   if (!EMPTY_SLIST(n->lsrql) && (n->lsrqi == SHEAD(n->lsrql)))
   {
     ospf_send_lsreq(p, n);
-    tm_start(n->lsrq_timer, n->ifa->rxmtint);
+    tm2_start(n->lsrq_timer, n->ifa->rxmtint S);
   }
 
   return;
index 74ea63d02d9f123828497862bc7d38887694c67e..12eb9e848c9ccaa2d713b2d44433892dc34251ea 100644 (file)
@@ -66,10 +66,10 @@ reset_lists(struct ospf_proto *p, struct ospf_neighbor *n)
   ospf_top_free(n->lsrth);
   ospf_reset_lsack_queue(n);
 
-  tm_stop(n->dbdes_timer);
-  tm_stop(n->lsrq_timer);
-  tm_stop(n->lsrt_timer);
-  tm_stop(n->ackd_timer);
+  tm2_stop(n->dbdes_timer);
+  tm2_stop(n->lsrq_timer);
+  tm2_stop(n->lsrt_timer);
+  tm2_stop(n->ackd_timer);
 
   init_lists(p, n);
 }
@@ -94,11 +94,11 @@ ospf_neighbor_new(struct ospf_iface *ifa)
   init_list(&n->ackl[ACKL_DIRECT]);
   init_list(&n->ackl[ACKL_DELAY]);
 
-  n->inactim = tm_new_set(pool, inactivity_timer_hook, n, 0, 0);
-  n->dbdes_timer = tm_new_set(pool, dbdes_timer_hook, n, 0, ifa->rxmtint);
-  n->lsrq_timer = tm_new_set(pool, lsrq_timer_hook, n, 0, ifa->rxmtint);
-  n->lsrt_timer = tm_new_set(pool, lsrt_timer_hook, n, 0, ifa->rxmtint);
-  n->ackd_timer = tm_new_set(pool, ackd_timer_hook, n, 0, ifa->rxmtint / 2);
+  n->inactim = tm2_new_init(pool, inactivity_timer_hook, n, 0, 0);
+  n->dbdes_timer = tm2_new_init(pool, dbdes_timer_hook, n, ifa->rxmtint S, 0);
+  n->lsrq_timer = tm2_new_init(pool, lsrq_timer_hook, n, ifa->rxmtint S, 0);
+  n->lsrt_timer = tm2_new_init(pool, lsrt_timer_hook, n, ifa->rxmtint S, 0);
+  n->ackd_timer = tm2_new_init(pool, ackd_timer_hook, n, ifa->rxmtint S / 2, 0);
 
   return (n);
 }
@@ -185,8 +185,8 @@ ospf_neigh_chstate(struct ospf_neighbor *n, u8 state)
     n->dds++;
     n->myimms = DBDES_IMMS;
 
-    tm_start(n->dbdes_timer, 0);
-    tm_start(n->ackd_timer, ifa->rxmtint / 2);
+    tm2_start(n->dbdes_timer, 0);
+    tm2_start(n->ackd_timer, ifa->rxmtint S / 2);
   }
 
   if (state > NEIGHBOR_EXSTART)
@@ -231,7 +231,7 @@ ospf_neigh_sm(struct ospf_neighbor *n, int event)
       ospf_neigh_chstate(n, NEIGHBOR_INIT);
 
     /* Restart inactivity timer */
-    tm_start(n->inactim, n->ifa->deadint);
+    tm2_start(n->inactim, n->ifa->deadint S);
     break;
 
   case INM_2WAYREC:
index a9081ed02933f9713eda7d686e5895c83c5cc2b5..13f3845b9a55e20feef20de9aeafa08e390ae942 100644 (file)
@@ -241,8 +241,8 @@ ospf_start(struct proto *P)
   p->asbr = c->asbr;
   p->ecmp = c->ecmp;
   p->tick = c->tick;
-  p->disp_timer = tm_new_set(P->pool, ospf_disp, p, 0, p->tick);
-  tm_start(p->disp_timer, 1);
+  p->disp_timer = tm2_new_init(P->pool, ospf_disp, p, p->tick S, 0);
+  tm2_start(p->disp_timer, 100 MS);
   p->lsab_size = 256;
   p->lsab_used = 0;
   p->lsab = mb_alloc(P->pool, p->lsab_size);
@@ -677,7 +677,7 @@ ospf_reconfigure(struct proto *P, struct proto_config *CF)
   p->ecmp = new->ecmp;
   p->tick = new->tick;
   p->disp_timer->recurrent = p->tick S;
-  tm_start(p->disp_timer, 1);
+  tm2_start(p->disp_timer, 100 MS);
 
   /* Mark all areas and ifaces */
   WALK_LIST(oa, p->area_list)
index 1530b26a5c47fdeabe5f0ff5166dd15cefc4313e..5aa27a1649839c1ab73ec4da6d18e511936038fa 100644 (file)
 
 #define OSPF_PROTO 89
 
-#define LSREFRESHTIME 1800     /* 30 minutes */
-#define MINLSINTERVAL 5
-#define MINLSARRIVAL 1
-#define LSINFINITY 0xffffff
+#define LSREFRESHTIME          1800    /* 30 minutes */
+#define MINLSINTERVAL          (5 S_)
+#define MINLSARRIVAL           (1 S_)
+#define LSINFINITY             0xffffff
 
 #define OSPF_DEFAULT_TICK 1
 #define OSPF_DEFAULT_STUB_COST 1000
@@ -283,8 +283,8 @@ struct ospf_iface
                                   interface.  LSAs contained in the update */
   u16 helloint;                        /* number of seconds between hello sending */
   list *passwords;
-  u32 csn;                      /* Last used crypt seq number */
-  bird_clock_t csn_use;         /* Last time when packet with that CSN was sent */
+  u32 csn;                     /* Last used crypt seq number */
+  btime csn_use;               /* Last time when packet with that CSN was sent */
   ip_addr all_routers;         /* Multicast (or broadcast) address for all routers */
   ip_addr des_routers;         /* Multicast (or NULL) address for designated routers */
   ip_addr drip;                        /* Designated router IP */
index 7f9f3b39c993c77ed65a1ac0aa5c2520ad4974c9..38d7a75face5181bda39b2c1a63537ed60ca6733 100644 (file)
@@ -77,16 +77,16 @@ ospf_pkt_finalize(struct ospf_iface *ifa, struct ospf_packet *pkt, uint *plen)
        reboot when system does not have independent RTC? */
     if (!ifa->csn)
     {
-      ifa->csn = (u32) now;
-      ifa->csn_use = now;
+      ifa->csn = (u32) (current_real_time() TO_S);
+      ifa->csn_use = current_time();
     }
 
     /* We must have sufficient delay between sending a packet and increasing
        CSN to prevent reordering of packets (in a network) with different CSNs */
-    if ((now - ifa->csn_use) > 1)
+    if ((current_time() - ifa->csn_use) > 1 S)
       ifa->csn++;
 
-    ifa->csn_use = now;
+    ifa->csn_use = current_time();
 
     uint auth_len = mac_type_length(pass->alg);
     byte *auth_tail = ((byte *) pkt + *plen);
index b289d7671ea2d28eac7c4959703671979f1a16b8..36bf0387b07325dd5c1602c5bfc2f050525b111f 100644 (file)
@@ -1321,7 +1321,7 @@ ospf_rt_abr2(struct ospf_proto *p)
       if (translate && (oa->translate != TRANS_ON))
       {
        if (oa->translate == TRANS_WAIT)
-         tm_stop(oa->translator_timer);
+         tm2_stop(oa->translator_timer);
 
        oa->translate = TRANS_ON;
       }
@@ -1329,10 +1329,10 @@ ospf_rt_abr2(struct ospf_proto *p)
       if (!translate && (oa->translate == TRANS_ON))
       {
        if (oa->translator_timer == NULL)
-         oa->translator_timer = tm_new_set(p->p.pool, translator_timer_hook, oa, 0, 0);
+         oa->translator_timer = tm2_new_init(p->p.pool, translator_timer_hook, oa, 0, 0);
 
        /* Schedule the end of translation */
-       tm_start(oa->translator_timer, oa->ac->transint);
+       tm2_start(oa->translator_timer, oa->ac->transint S);
        oa->translate = TRANS_WAIT;
       }
     }
index 8dd91a407f9e965f8fee4983574691fd7715ac1b..717c8280843f8dcab4124d8672d1f145c71c768b 100644 (file)
@@ -70,7 +70,7 @@ ospf_install_lsa(struct ospf_proto *p, struct ospf_lsa_header *lsa, u32 type, u3
   en->lsa_body = body;
   en->lsa = *lsa;
   en->init_age = en->lsa.age;
-  en->inst_time = now;
+  en->inst_time = current_time();
 
   /*
    * We do not set en->mode. It is either default LSA_M_BASIC, or in a special
@@ -128,7 +128,7 @@ ospf_advance_lsa(struct ospf_proto *p, struct top_hash_entry *en, struct ospf_ls
       en->lsa.sn = lsa->sn + 1;
       en->lsa.age = 0;
       en->init_age = 0;
-      en->inst_time = now;
+      en->inst_time = current_time();
       lsa_generate_checksum(&en->lsa, en->lsa_body);
 
       OSPF_TRACE(D_EVENTS, "Advancing LSA: Type: %04x, Id: %R, Rt: %R, Seq: %08x",
@@ -160,7 +160,7 @@ ospf_advance_lsa(struct ospf_proto *p, struct top_hash_entry *en, struct ospf_ls
       en->lsa = *lsa;
       en->lsa.age = LSA_MAXAGE;
       en->init_age = lsa->age;
-      en->inst_time = now;
+      en->inst_time = current_time();
 
       OSPF_TRACE(D_EVENTS, "Resetting LSA:  Type: %04x, Id: %R, Rt: %R, Seq: %08x",
                 en->lsa_type, en->lsa.id, en->lsa.rt, en->lsa.sn);
@@ -196,7 +196,7 @@ static int
 ospf_do_originate_lsa(struct ospf_proto *p, struct top_hash_entry *en, void *lsa_body, u16 lsa_blen, u16 lsa_opts)
 {
   /* Enforce MinLSInterval */
-  if ((en->init_age == 0) && en->inst_time && ((en->inst_time + MINLSINTERVAL) > now))
+  if (!en->init_age && en->inst_time && (lsa_inst_age(en) < MINLSINTERVAL))
     return 0;
 
   /* Handle wrapping sequence number */
@@ -237,7 +237,7 @@ ospf_do_originate_lsa(struct ospf_proto *p, struct top_hash_entry *en, void *lsa
   en->lsa.sn++;
   en->lsa.age = 0;
   en->init_age = 0;
-  en->inst_time = now;
+  en->inst_time = current_time();
   lsa_generate_checksum(&en->lsa, en->lsa_body);
 
   OSPF_TRACE(D_EVENTS, "Originating LSA: Type: %04x, Id: %R, Rt: %R, Seq: %08x",
@@ -381,7 +381,7 @@ ospf_refresh_lsa(struct ospf_proto *p, struct top_hash_entry *en)
   en->lsa.sn++;
   en->lsa.age = 0;
   en->init_age = 0;
-  en->inst_time = now;
+  en->inst_time = current_time();
   lsa_generate_checksum(&en->lsa, en->lsa_body);
   ospf_flood_lsa(p, en, NULL);
 }
@@ -476,14 +476,15 @@ void
 ospf_update_lsadb(struct ospf_proto *p)
 {
   struct top_hash_entry *en, *nxt;
-  bird_clock_t real_age;
+  btime now_ = current_time();
+  int real_age;
 
   WALK_SLIST_DELSAFE(en, nxt, p->lsal)
   {
     if (en->next_lsa_body)
       ospf_originate_next_lsa(p, en);
 
-    real_age = en->init_age + (now - en->inst_time);
+    real_age = en->init_age + (now_ - en->inst_time) TO_S;
 
     if (en->lsa.age == LSA_MAXAGE)
     {
@@ -1636,7 +1637,7 @@ ospf_originate_prefix_net_lsa(struct ospf_proto *p, struct ospf_iface *ifa)
 }
 
 static inline int breaks_minlsinterval(struct top_hash_entry *en)
-{ return en && (en->lsa.age < LSA_MAXAGE) && ((en->inst_time + MINLSINTERVAL) > now); }
+{ return en && (en->lsa.age < LSA_MAXAGE) && (lsa_inst_age(en) < MINLSINTERVAL); }
 
 void
 ospf_update_topology(struct ospf_proto *p)
index d1682c54f783616b7507c838f24406a7f00f246a..ac87334bb2c7ba69ef51c48c9f67137b41336d07 100644 (file)
@@ -26,7 +26,7 @@ struct top_hash_entry
   void *next_lsa_body;         /* For postponed LSA origination */
   u16 next_lsa_blen;           /* For postponed LSA origination */
   u16 next_lsa_opts;           /* For postponed LSA origination */
-  bird_clock_t inst_time;      /* Time of installation into DB */
+  btime inst_time;             /* Time of installation into DB */
   struct ort *nf;              /* Reference fibnode for sum and ext LSAs, NULL for otherwise */
   struct nexthop *nhs;         /* Computed nexthops - valid only in ospf_rt_spf() */
   ip_addr lb;                  /* In OSPFv2, link back address. In OSPFv3, any global address in the area useful for vlinks */