summaryrefslogtreecommitdiff
path: root/proto
diff options
context:
space:
mode:
authorOndrej Zajicek (work) <santiago@crfreenet.org>2017-06-01 12:33:20 +0200
committerOndrej Zajicek (work) <santiago@crfreenet.org>2017-12-07 13:49:27 +0100
commit025525266f6861437ca54aca2a86eb505a486baf (patch)
tree8a4f2035ef7edbcd77224ed76598ec0806f24512 /proto
parent28a7d3943ef915c405b3552ae06f639a86f4dc1e (diff)
Timers: Replace old timers with microsecond timers
The old timer interface is still kept, but implemented by new timers. The plan is to switch from the old inteface to the new interface, then clean it up.
Diffstat (limited to 'proto')
-rw-r--r--proto/babel/babel.c4
-rw-r--r--proto/bgp/bgp.c19
-rw-r--r--proto/bgp/bgp.h16
-rw-r--r--proto/ospf/iface.c4
-rw-r--r--proto/ospf/neighbor.c2
-rw-r--r--proto/ospf/ospf.c2
-rw-r--r--proto/radv/radv.c7
-rw-r--r--proto/rip/rip.c4
-rw-r--r--proto/rpki/rpki.c10
9 files changed, 33 insertions, 35 deletions
diff --git a/proto/babel/babel.c b/proto/babel/babel.c
index 23746155..bab2e8b3 100644
--- a/proto/babel/babel.c
+++ b/proto/babel/babel.c
@@ -1367,7 +1367,7 @@ babel_iface_timer(timer *t)
static inline void
babel_iface_kick_timer(struct babel_iface *ifa)
{
- if (ifa->timer->expires > (now + 1))
+ if (ifa->timer->expires TO_S > (now + 1))
tm_start(ifa->timer, 1);
}
@@ -1948,7 +1948,7 @@ babel_timer(timer *t)
static inline void
babel_kick_timer(struct babel_proto *p)
{
- if (p->timer->expires > (now + 1))
+ if (p->timer->expires TO_S > (now + 1))
tm_start(p->timer, 1);
}
diff --git a/proto/bgp/bgp.c b/proto/bgp/bgp.c
index a8d5cf9d..dba7c875 100644
--- a/proto/bgp/bgp.c
+++ b/proto/bgp/bgp.c
@@ -103,6 +103,8 @@
#undef LOCAL_DEBUG
+#include <stdlib.h>
+
#include "nest/bird.h"
#include "nest/iface.h"
#include "nest/protocol.h"
@@ -324,8 +326,8 @@ bgp_start_timer(timer *t, int value)
if (value)
{
/* The randomization procedure is specified in RFC 1771: 9.2.3.3 */
- t->randomize = value / 4;
- tm_start(t, value - t->randomize);
+ int randomize = random() % ((value / 4) + 1);
+ tm_start(t, value - randomize);
}
else
tm_stop(t);
@@ -2006,17 +2008,18 @@ bgp_show_proto_info(struct proto *P)
struct bgp_conn *oc = &p->outgoing_conn;
if ((p->start_state < BSS_CONNECT) &&
- (p->startup_timer->expires))
+ (tm_active(p->startup_timer)))
cli_msg(-1006, " Error wait: %d/%d",
- p->startup_timer->expires - now, p->startup_delay);
+ (int) tm_remains(p->startup_timer), p->startup_delay);
if ((oc->state == BS_ACTIVE) &&
- (oc->connect_timer->expires))
+ (tm_active(oc->connect_timer)))
cli_msg(-1006, " Connect delay: %d/%d",
- oc->connect_timer->expires - now, p->cf->connect_delay_time);
+ (int) tm_remains(oc->connect_timer), p->cf->connect_delay_time);
- if (p->gr_active_num && p->gr_timer->expires)
- cli_msg(-1006, " Restart timer: %d/-", p->gr_timer->expires - now);
+ if (p->gr_active_num && tm_active(p->gr_timer))
+ cli_msg(-1006, " Restart timer: %d/-",
+ (int) tm_remains(p->gr_timer));
}
else if (P->proto_state == PS_UP)
{
diff --git a/proto/bgp/bgp.h b/proto/bgp/bgp.h
index 7ffcb68a..3b38c05f 100644
--- a/proto/bgp/bgp.h
+++ b/proto/bgp/bgp.h
@@ -210,10 +210,10 @@ struct bgp_conn {
struct bgp_caps *local_caps;
struct bgp_caps *remote_caps;
- struct timer *connect_timer;
- struct timer *hold_timer;
- struct timer *keepalive_timer;
- struct event *tx_ev;
+ timer *connect_timer;
+ timer *hold_timer;
+ timer *keepalive_timer;
+ event *tx_ev;
u32 packets_to_send; /* Bitmap of packet types to be sent */
u32 channels_to_send; /* Bitmap of channels with packets to be sent */
u8 last_channel; /* Channel used last time for TX */
@@ -254,9 +254,9 @@ struct bgp_proto {
struct bfd_request *bfd_req; /* BFD request, if BFD is used */
ip_addr source_addr; /* Local address used as an advertised next hop */
ip_addr link_addr; /* Link-local version of source_addr */
- struct event *event; /* Event for respawning and shutting process */
- struct timer *startup_timer; /* Timer used to delay protocol startup due to previous errors (startup_delay) */
- struct timer *gr_timer; /* Timer waiting for reestablishment after graceful restart */
+ event *event; /* Event for respawning and shutting process */
+ timer *startup_timer; /* Timer used to delay protocol startup due to previous errors (startup_delay) */
+ timer *gr_timer; /* Timer waiting for reestablishment after graceful restart */
unsigned startup_delay; /* Time to delay protocol startup by due to errors */
bird_clock_t last_proto_error; /* Time of last error that leads to protocol stop */
u8 last_error_class; /* Error class of last error */
@@ -422,7 +422,7 @@ extern struct linpool *bgp_linpool;
extern struct linpool *bgp_linpool2;
-void bgp_start_timer(struct timer *t, int value);
+void bgp_start_timer(timer *t, int value);
void bgp_check_config(struct bgp_config *c);
void bgp_error(struct bgp_conn *c, unsigned code, unsigned subcode, byte *data, int len);
void bgp_close_conn(struct bgp_conn *c);
diff --git a/proto/ospf/iface.c b/proto/ospf/iface.c
index 98d48aa1..d1f9365e 100644
--- a/proto/ospf/iface.c
+++ b/proto/ospf/iface.c
@@ -715,9 +715,9 @@ ospf_iface_change_timer(timer *tm, uint val)
if (!tm)
return;
- tm->recurrent = val;
+ tm->recurrent = val S;
- if (tm->expires)
+ if (tm_active(tm))
tm_start(tm, val);
}
diff --git a/proto/ospf/neighbor.c b/proto/ospf/neighbor.c
index b68ba6f4..64165e46 100644
--- a/proto/ospf/neighbor.c
+++ b/proto/ospf/neighbor.c
@@ -654,7 +654,7 @@ ospf_sh_neigh_info(struct ospf_neighbor *n)
char etime[6];
int exp, sec, min;
- exp = n->inactim->expires - now;
+ exp = tm_remains(n->inactim);
sec = exp % 60;
min = exp / 60;
if (min > 59)
diff --git a/proto/ospf/ospf.c b/proto/ospf/ospf.c
index 7ce6698e..a9081ed0 100644
--- a/proto/ospf/ospf.c
+++ b/proto/ospf/ospf.c
@@ -676,7 +676,7 @@ ospf_reconfigure(struct proto *P, struct proto_config *CF)
p->asbr = new->asbr;
p->ecmp = new->ecmp;
p->tick = new->tick;
- p->disp_timer->recurrent = p->tick;
+ p->disp_timer->recurrent = p->tick S;
tm_start(p->disp_timer, 1);
/* Mark all areas and ifaces */
diff --git a/proto/radv/radv.c b/proto/radv/radv.c
index 2c0a23ad..34a3f473 100644
--- a/proto/radv/radv.c
+++ b/proto/radv/radv.c
@@ -154,12 +154,7 @@ radv_iface_new(struct radv_proto *p, struct iface *iface, struct radv_iface_conf
add_tail(&p->iface_list, NODE ifa);
- timer *tm = tm_new(pool);
- tm->hook = radv_timer;
- tm->data = ifa;
- tm->randomize = 0;
- tm->recurrent = 0;
- ifa->timer = tm;
+ ifa->timer = tm_new_set(pool, radv_timer, ifa, 0, 0);
struct object_lock *lock = olock_new(pool);
lock->addr = IPA_NONE;
diff --git a/proto/rip/rip.c b/proto/rip/rip.c
index 820c5117..2583b49b 100644
--- a/proto/rip/rip.c
+++ b/proto/rip/rip.c
@@ -902,7 +902,7 @@ rip_timer(timer *t)
static inline void
rip_kick_timer(struct rip_proto *p)
{
- if (p->timer->expires > (now + 1))
+ if (p->timer->expires TO_S > (now + 1))
tm_start(p->timer, 1); /* Or 100 ms */
}
@@ -962,7 +962,7 @@ rip_iface_timer(timer *t)
static inline void
rip_iface_kick_timer(struct rip_iface *ifa)
{
- if (ifa->timer->expires > (now + 1))
+ if (ifa->timer->expires TO_S > (now + 1))
tm_start(ifa->timer, 1); /* Or 100 ms */
}
diff --git a/proto/rpki/rpki.c b/proto/rpki/rpki.c
index 349d2f70..a331e45e 100644
--- a/proto/rpki/rpki.c
+++ b/proto/rpki/rpki.c
@@ -382,7 +382,7 @@ rpki_do_we_recv_prefix_pdu_in_last_seconds(struct rpki_cache *cache)
* |End of Data| PDU and has run by some &ERROR is occurred.
*/
static void
-rpki_refresh_hook(struct timer *tm)
+rpki_refresh_hook(timer *tm)
{
struct rpki_cache *cache = tm->data;
@@ -428,7 +428,7 @@ rpki_refresh_hook(struct timer *tm)
* ends by reaching of &ESTABLISHED state again.
*/
static void
-rpki_retry_hook(struct timer *tm)
+rpki_retry_hook(timer *tm)
{
struct rpki_cache *cache = tm->data;
@@ -473,7 +473,7 @@ rpki_retry_hook(struct timer *tm)
* of the protocol.
*/
static void
-rpki_expire_hook(struct timer *tm)
+rpki_expire_hook(timer *tm)
{
struct rpki_cache *cache = tm->data;
@@ -789,8 +789,8 @@ rpki_get_status(struct proto *P, byte *buf)
static void
rpki_show_proto_info_timer(const char *name, uint num, timer *t)
{
- if (t->expires)
- cli_msg(-1006, " %-17s %us (remains %us)", name, num, tm_remains(t));
+ if (tm_active(t))
+ cli_msg(-1006, " %-17s %us (remains %ds)", name, num, (int) tm_remains(t));
else
cli_msg(-1006, " %-17s ---", name);
}