]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Timers: Add typecast to unit-converting macros
authorOndrej Zajicek (work) <santiago@crfreenet.org>
Tue, 20 Jun 2017 13:55:39 +0000 (15:55 +0200)
committerOndrej Zajicek (work) <santiago@crfreenet.org>
Thu, 7 Dec 2017 12:53:42 +0000 (13:53 +0100)
conf/confbase.Y
lib/birdlib.h
nest/password.c
proto/radv/radv.c
proto/rip/config.Y
proto/rpki/rpki.c
sysdep/unix/io.c

index 390041c4ba9976184896315cc0c6aa2e4b77e677..16330984aa164b1d446e8a2b8b4264036f9b1865 100644 (file)
@@ -80,8 +80,7 @@ CF_DECLS
 %type <iface> ipa_scope
 
 %type <i> expr bool pxlen4
-%type <i32> expr_us
-%type <time> time
+%type <time> expr_us time
 %type <a> ipa
 %type <net> net_ip4_ net_ip6_ net_ip6 net_ip_ net_ip net_or_ipa
 %type <net_ptr> net_ net_any net_vpn4_ net_vpn6_ net_vpn_ net_roa4_ net_roa6_ net_roa_
@@ -137,9 +136,9 @@ expr:
 
 
 expr_us:
-   expr S  { $$ = (u32) $1 * 1000000; }
- | expr MS { $$ = (u32) $1 * 1000; }
- | expr US { $$ = (u32) $1 * 1; }
+   expr S  { $$ = $1 S_; }
+ | expr MS { $$ = $1 MS_; }
+ | expr US { $$ = $1 US_; }
  ;
 
 /* Switches */
index a0826aabbe8a1b456b38a03a36204b06c47b5923..9a77fc7bc691bf0cb5893cd3f859172f3ea14412 100644 (file)
@@ -71,9 +71,9 @@ static inline int u64_cmp(u64 i1, u64 i2)
 typedef s64 btime;
 typedef s64 bird_clock_t;
 
-#define S_     *1000000
-#define MS_    *1000
-#define US_    *1
+#define S_     * (btime) 1000000
+#define MS_    * (btime) 1000
+#define US_    * (btime) 1
 #define TO_S   /1000000
 #define TO_MS  /1000
 #define TO_US  /1
@@ -82,6 +82,7 @@ typedef s64 bird_clock_t;
 #define S      S_
 #define MS     MS_
 #define US     US_
+#define NS     /1000
 #endif
 
 
index 72f23f5d7aa00c7fa4ea64d0605958849706b0f8..6f87af218d6b2e290e16ba737591b0406b668e96 100644 (file)
@@ -10,6 +10,7 @@
 #include "nest/bird.h"
 #include "nest/password.h"
 #include "lib/string.h"
+#include "lib/timer.h"
 #include "lib/mac.h"
 
 struct password_item *last_password_item = NULL;
index 978d209199820e4f68cfd2ba5bb0a5e6dcea4573..415cd1d92c52fe64d95c476bb393cd797f29e69e 100644 (file)
@@ -55,8 +55,8 @@ radv_timer(timer *tm)
 
   /* Update timer */
   ifa->last = current_time();
-  btime t = (btime) ifa->cf->min_ra_int S;
-  btime r = (btime) (ifa->cf->max_ra_int - ifa->cf->min_ra_int) S;
+  btime t = ifa->cf->min_ra_int S;
+  btime r = (ifa->cf->max_ra_int - ifa->cf->min_ra_int) S;
   t += random() % (r + 1);
 
   if (ifa->initial)
@@ -93,7 +93,7 @@ radv_iface_notify(struct radv_iface *ifa, int event)
   }
 
   /* Update timer */
-  btime t = ifa->last + (btime) ifa->cf->min_delay S - current_time();
+  btime t = ifa->last + ifa->cf->min_delay S - current_time();
   tm2_start(ifa->timer, t);
 }
 
index ba9ac20b4680a027b62f1a8405bf36930b6523ac..e3bc4ae3294217211ae1df67a74e4438b630af79 100644 (file)
@@ -147,9 +147,9 @@ rip_iface_item:
  | SPLIT HORIZON bool  { RIP_IFACE->split_horizon = $3; }
  | POISON REVERSE bool { RIP_IFACE->poison_reverse = $3; }
  | CHECK ZERO bool     { RIP_IFACE->check_zero = $3; }
- | UPDATE TIME expr    { RIP_IFACE->update_time = (btime) $3 S_; if ($3<=0) cf_error("Update time must be positive"); }
- | TIMEOUT TIME expr   { RIP_IFACE->timeout_time = (btime) $3 S_; if ($3<=0) cf_error("Timeout time must be positive"); }
- | GARBAGE TIME expr   { RIP_IFACE->garbage_time = (btime) $3 S_; if ($3<=0) cf_error("Garbage time must be positive"); }
+ | UPDATE TIME expr    { RIP_IFACE->update_time = $3 S_; if ($3<=0) cf_error("Update time must be positive"); }
+ | TIMEOUT TIME expr   { RIP_IFACE->timeout_time = $3 S_; if ($3<=0) cf_error("Timeout time must be positive"); }
+ | GARBAGE TIME expr   { RIP_IFACE->garbage_time = $3 S_; if ($3<=0) cf_error("Garbage time must be positive"); }
  | ECMP WEIGHT expr    { RIP_IFACE->ecmp_weight = $3 - 1; if (($3<1) || ($3>256)) cf_error("ECMP weight must be in range 1-256"); }
  | RX BUFFER expr      { RIP_IFACE->rx_buffer = $3; if (($3<256) || ($3>65535)) cf_error("RX length must be in range 256-65535"); }
  | TX LENGTH expr      { RIP_IFACE->tx_length = $3; if (($3<256) || ($3>65535)) cf_error("TX length must be in range 256-65535"); }
index cddbf017092932bbc058aa78c55b289ccf57bc2c..f17024fe1dfc6f8b217d9d256a946c29bdf000c2 100644 (file)
@@ -318,7 +318,7 @@ rpki_cache_change_state(struct rpki_cache *cache, const enum rpki_cache_state ne
 static void
 rpki_schedule_next_refresh(struct rpki_cache *cache)
 {
-  btime t = (btime) cache->refresh_interval S;
+  btime t = cache->refresh_interval S;
 
   CACHE_DBG(cache, "after %t s", t);
   tm2_start(cache->refresh_timer, t);
@@ -327,7 +327,7 @@ rpki_schedule_next_refresh(struct rpki_cache *cache)
 static void
 rpki_schedule_next_retry(struct rpki_cache *cache)
 {
-  btime t = (btime) cache->retry_interval S;
+  btime t = cache->retry_interval S;
 
   CACHE_DBG(cache, "after %t s", t);
   tm2_start(cache->retry_timer, t);
@@ -337,7 +337,7 @@ static void
 rpki_schedule_next_expire_check(struct rpki_cache *cache)
 {
   /* A minimum time to wait is 1 second */
-  btime t = cache->last_update + (btime) cache->expire_interval S - current_time();
+  btime t = cache->last_update + cache->expire_interval S - current_time();
   t = MAX(t, 1 S);
 
   CACHE_DBG(cache, "after %t s", t);
@@ -483,7 +483,7 @@ rpki_expire_hook(timer *tm)
 
   CACHE_DBG(cache, "%s", rpki_cache_state_to_str(cache->state));
 
-  btime t = cache->last_update + (btime) cache->expire_interval S - current_time();
+  btime t = cache->last_update + cache->expire_interval S - current_time();
   if (t <= 0)
   {
     CACHE_TRACE(D_EVENTS, cache, "All ROAs expired");
index 99f52aa904724c53f646ab82a7bad7fab73c4a8f..25121d74269605cc1aa74f16483524b325c4192d 100644 (file)
@@ -406,7 +406,7 @@ times_init(struct timeloop *loop)
   if ((ts.tv_sec < 0) || (((s64) ts.tv_sec) > ((s64) 1 << 40)))
     log(L_WARN "Monotonic clock is crazy");
 
-  loop->last_time = ((s64) ts.tv_sec S) + (ts.tv_nsec / 1000);
+  loop->last_time = ts.tv_sec S + ts.tv_nsec NS;
   loop->real_time = 0;
 }
 
@@ -420,7 +420,7 @@ times_update(struct timeloop *loop)
   if (rv < 0)
     die("clock_gettime: %m");
 
-  btime new_time = ((s64) ts.tv_sec S) + (ts.tv_nsec / 1000);
+  btime new_time = ts.tv_sec S + ts.tv_nsec NS;
 
   if (new_time < loop->last_time)
     log(L_ERR "Monotonic clock is broken");
@@ -439,7 +439,7 @@ times_update_real_time(struct timeloop *loop)
   if (rv < 0)
     die("clock_gettime: %m");
 
-  loop->real_time = ((s64) ts.tv_sec S) + (ts.tv_nsec / 1000);
+  loop->real_time = ts.tv_sec S + ts.tv_nsec NS;
 }
 
 
@@ -2281,7 +2281,7 @@ io_update_time(void)
   if (rv < 0)
     die("clock_gettime: %m");
 
-  last_time = ((s64) ts.tv_sec S) + (ts.tv_nsec / 1000);
+  last_time = ts.tv_sec S + ts.tv_nsec NS;
 
   if (event_open)
   {