summaryrefslogtreecommitdiff
path: root/proto/rip
diff options
context:
space:
mode:
authorOndrej Zajicek (work) <santiago@crfreenet.org>2017-06-20 14:30:44 +0200
committerOndrej Zajicek (work) <santiago@crfreenet.org>2017-12-07 13:53:42 +0100
commit92cc1e745758893a57a2432a0e11e4cd3ad289b7 (patch)
tree24e03bf26fd6c4874047dcbb157f6770aa8260fc /proto/rip
parentc521b3ac324e1c97b22581a06172dcb08fd740f6 (diff)
RIP: Update to new timers
Diffstat (limited to 'proto/rip')
-rw-r--r--proto/rip/config.Y10
-rw-r--r--proto/rip/packets.c10
-rw-r--r--proto/rip/rip.c79
-rw-r--r--proto/rip/rip.h32
4 files changed, 68 insertions, 63 deletions
diff --git a/proto/rip/config.Y b/proto/rip/config.Y
index 46f6c177..ba9ac20b 100644
--- a/proto/rip/config.Y
+++ b/proto/rip/config.Y
@@ -57,8 +57,8 @@ rip_proto_start: proto_start rip_variant
init_list(&RIP_CFG->patt_list);
RIP_CFG->rip2 = $2;
RIP_CFG->infinity = RIP_DEFAULT_INFINITY;
- RIP_CFG->min_timeout_time = 60;
- RIP_CFG->max_garbage_time = 60;
+ RIP_CFG->min_timeout_time = 60 S_;
+ RIP_CFG->max_garbage_time = 60 S_;
};
rip_proto_item:
@@ -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 = $3; if ($3<=0) cf_error("Update time must be positive"); }
- | TIMEOUT TIME expr { RIP_IFACE->timeout_time = $3; if ($3<=0) cf_error("Timeout time must be positive"); }
- | GARBAGE TIME expr { RIP_IFACE->garbage_time = $3; if ($3<=0) cf_error("Garbage time must be positive"); }
+ | 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"); }
| 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"); }
diff --git a/proto/rip/packets.c b/proto/rip/packets.c
index de48fd0a..1518dd3f 100644
--- a/proto/rip/packets.c
+++ b/proto/rip/packets.c
@@ -434,6 +434,7 @@ rip_send_response(struct rip_proto *p, struct rip_iface *ifa)
byte *max = rip_tx_buffer(ifa) + ifa->tx_plen -
(rip_is_v2(p) ? RIP_BLOCK_LENGTH : 2*RIP_BLOCK_LENGTH);
ip_addr last_next_hop = IPA_NONE;
+ btime now_ = current_time();
int send = 0;
struct rip_packet *pkt = (void *) pos;
@@ -450,7 +451,7 @@ rip_send_response(struct rip_proto *p, struct rip_iface *ifa)
/* Stale entries that should be removed */
if ((en->valid == RIP_ENTRY_STALE) &&
- ((en->changed + (bird_clock_t) ifa->cf->garbage_time) <= now))
+ ((en->changed + ifa->cf->garbage_time) <= now_))
goto next_entry;
/* Triggered updates */
@@ -540,7 +541,7 @@ break_loop:
* activating the new one.
*/
void
-rip_send_table(struct rip_proto *p, struct rip_iface *ifa, ip_addr addr, bird_clock_t changed)
+rip_send_table(struct rip_proto *p, struct rip_iface *ifa, ip_addr addr, btime changed)
{
DBG("RIP: Opening TX session to %I on %s\n", addr, ifa->iface->name);
@@ -591,6 +592,7 @@ rip_receive_response(struct rip_proto *p, struct rip_iface *ifa, struct rip_pack
byte *pos = (byte *) pkt + sizeof(struct rip_packet);
byte *end = (byte *) pkt + plen;
+ btime now_ = current_time();
for (; pos < end; pos += RIP_BLOCK_LENGTH)
{
@@ -638,7 +640,7 @@ rip_receive_response(struct rip_proto *p, struct rip_iface *ifa, struct rip_pack
.next_hop = ipa_nonzero(rte.next_hop) ? rte.next_hop : from->nbr->addr,
.metric = rte.metric,
.tag = rte.tag,
- .expires = now + ifa->cf->timeout_time
+ .expires = now_ + ifa->cf->timeout_time
};
rip_update_rte(p, &rte.net, &new);
@@ -705,7 +707,7 @@ rip_rx_hook(sock *sk, uint len)
if ((plen - sizeof(struct rip_packet)) % RIP_BLOCK_LENGTH)
DROP("invalid length", plen);
- n->last_seen = now;
+ n->last_seen = current_time();
rip_update_bfd(p, n);
switch (pkt->command)
diff --git a/proto/rip/rip.c b/proto/rip/rip.c
index 2583b49b..782e6f5c 100644
--- a/proto/rip/rip.c
+++ b/proto/rip/rip.c
@@ -364,7 +364,7 @@ rip_rt_notify(struct proto *P, struct channel *ch UNUSED, struct network *net, s
/* Activate triggered updates */
if (en->metric != old_metric)
{
- en->changed = now;
+ en->changed = current_time();
rip_trigger_update(p);
}
}
@@ -506,10 +506,10 @@ rip_iface_start(struct rip_iface *ifa)
TRACE(D_EVENTS, "Starting interface %s", ifa->iface->name);
- ifa->next_regular = now + (random() % ifa->cf->update_time) + 1;
- ifa->next_triggered = now; /* Available immediately */
- ifa->want_triggered = 1; /* All routes in triggered update */
- tm_start(ifa->timer, 1); /* Or 100 ms */
+ ifa->next_regular = current_time() + (random() % ifa->cf->update_time) + 100 MS;
+ ifa->next_triggered = current_time(); /* Available immediately */
+ ifa->want_triggered = 1; /* All routes in triggered update */
+ tm2_start(ifa->timer, 100 MS);
ifa->up = 1;
if (!ifa->cf->passive)
@@ -529,7 +529,7 @@ rip_iface_stop(struct rip_iface *ifa)
WALK_LIST_FIRST(n, ifa->neigh_list)
rip_remove_neighbor(p, n);
- tm_stop(ifa->timer);
+ tm2_stop(ifa->timer);
ifa->up = 0;
}
@@ -642,7 +642,7 @@ rip_add_iface(struct rip_proto *p, struct iface *iface, struct rip_iface_config
add_tail(&p->iface_list, NODE ifa);
- ifa->timer = tm_new_set(p->p.pool, rip_iface_timer, ifa, 0, 0);
+ ifa->timer = tm2_new_init(p->p.pool, rip_iface_timer, ifa, 0, 0);
struct object_lock *lock = olock_new(p->p.pool);
lock->type = OBJLOCK_UDP;
@@ -690,8 +690,8 @@ rip_reconfigure_iface(struct rip_proto *p, struct rip_iface *ifa, struct rip_ifa
rip_iface_update_buffers(ifa);
- if (ifa->next_regular > (now + (bird_clock_t) new->update_time))
- ifa->next_regular = now + (random() % new->update_time) + 1;
+ if (ifa->next_regular > (current_time() + new->update_time))
+ ifa->next_regular = current_time() + (random() % new->update_time) + 100 MS;
if (new->check_link != old->check_link)
rip_iface_update_state(ifa);
@@ -816,8 +816,9 @@ rip_timer(timer *t)
struct rip_iface *ifa;
struct rip_neighbor *n, *nn;
struct fib_iterator fit;
- bird_clock_t next = now + MIN(cf->min_timeout_time, cf->max_garbage_time);
- bird_clock_t expires = 0;
+ btime now_ = current_time();
+ btime next = now_ + MIN(cf->min_timeout_time, cf->max_garbage_time);
+ btime expires = 0;
TRACE(D_EVENTS, "Main timer fired");
@@ -832,7 +833,7 @@ rip_timer(timer *t)
/* Checking received routes for timeout and for dead neighbors */
for (rp = &en->routes; rt = *rp; /* rp = &rt->next */)
{
- if (!rip_valid_rte(rt) || (rt->expires <= now))
+ if (!rip_valid_rte(rt) || (rt->expires <= now_))
{
rip_remove_rte(p, rp);
changed = 1;
@@ -862,7 +863,7 @@ rip_timer(timer *t)
{
expires = en->changed + cf->max_garbage_time;
- if (expires <= now)
+ if (expires <= now_)
{
// TRACE(D_EVENTS, "entry is too old: %N", en->n.addr);
en->valid = 0;
@@ -890,20 +891,20 @@ rip_timer(timer *t)
{
expires = n->last_seen + n->ifa->cf->timeout_time;
- if (expires <= now)
+ if (expires <= now_)
rip_remove_neighbor(p, n);
else
next = MIN(next, expires);
}
- tm_start(p->timer, MAX(next - now, 1));
+ tm2_start(p->timer, MAX(next - now_, 100 MS));
}
static inline void
rip_kick_timer(struct rip_proto *p)
{
- if (p->timer->expires TO_S > (now + 1))
- tm_start(p->timer, 1); /* Or 100 ms */
+ if (p->timer->expires > (current_time() + 100 MS))
+ tm2_start(p->timer, 100 MS);
}
/**
@@ -921,7 +922,8 @@ rip_iface_timer(timer *t)
{
struct rip_iface *ifa = t->data;
struct rip_proto *p = ifa->rip;
- bird_clock_t period = ifa->cf->update_time;
+ btime now_ = current_time();
+ btime period = ifa->cf->update_time;
if (ifa->cf->passive)
return;
@@ -930,40 +932,40 @@ rip_iface_timer(timer *t)
if (ifa->tx_active)
{
- if (now < (ifa->next_regular + period))
- { tm_start(ifa->timer, 1); return; }
+ if (now_ < (ifa->next_regular + period))
+ { tm2_start(ifa->timer, 100 MS); return; }
/* We are too late, reset is done by rip_send_table() */
log(L_WARN "%s: Too slow update on %s, resetting", p->p.name, ifa->iface->name);
}
- if (now >= ifa->next_regular)
+ if (now_ >= ifa->next_regular)
{
/* Send regular update, set timer for next period (or following one if necessay) */
TRACE(D_EVENTS, "Sending regular updates for %s", ifa->iface->name);
rip_send_table(p, ifa, ifa->addr, 0);
- ifa->next_regular += period * (1 + ((now - ifa->next_regular) / period));
+ ifa->next_regular += period * (1 + ((now_ - ifa->next_regular) / period));
ifa->want_triggered = 0;
p->triggered = 0;
}
- else if (ifa->want_triggered && (now >= ifa->next_triggered))
+ else if (ifa->want_triggered && (now_ >= ifa->next_triggered))
{
/* Send triggered update, enforce interval between triggered updates */
TRACE(D_EVENTS, "Sending triggered updates for %s", ifa->iface->name);
rip_send_table(p, ifa, ifa->addr, ifa->want_triggered);
- ifa->next_triggered = now + MIN(5, period / 2 + 1);
+ ifa->next_triggered = now_ + MIN(5 S, period / 2);
ifa->want_triggered = 0;
p->triggered = 0;
}
- tm_start(ifa->timer, ifa->want_triggered ? 1 : (ifa->next_regular - now));
+ tm2_start(ifa->timer, ifa->want_triggered ? (1 S) : (ifa->next_regular - now_));
}
static inline void
rip_iface_kick_timer(struct rip_iface *ifa)
{
- if (ifa->timer->expires TO_S > (now + 1))
- tm_start(ifa->timer, 1); /* Or 100 ms */
+ if (ifa->timer->expires > (current_time() + 100 MS))
+ tm2_start(ifa->timer, 100 MS);
}
static void
@@ -984,7 +986,7 @@ rip_trigger_update(struct rip_proto *p)
continue;
TRACE(D_EVENTS, "Scheduling triggered updates for %s", ifa->iface->name);
- ifa->want_triggered = now;
+ ifa->want_triggered = current_time();
rip_iface_kick_timer(ifa);
}
@@ -1109,7 +1111,7 @@ rip_start(struct proto *P)
fib_init(&p->rtable, P->pool, cf->rip2 ? NET_IP4 : NET_IP6,
sizeof(struct rip_entry), OFFSETOF(struct rip_entry, n), 0, NULL);
p->rte_slab = sl_new(P->pool, sizeof(struct rip_rte));
- p->timer = tm_new_set(P->pool, rip_timer, p, 0, 0);
+ p->timer = tm2_new_init(P->pool, rip_timer, p, 0, 0);
p->rip2 = cf->rip2;
p->ecmp = cf->ecmp;
@@ -1119,7 +1121,7 @@ rip_start(struct proto *P)
p->log_pkt_tbf = (struct tbf){ .rate = 1, .burst = 5 };
p->log_rte_tbf = (struct tbf){ .rate = 4, .burst = 20 };
- tm_start(p->timer, MIN(cf->min_timeout_time, cf->max_garbage_time));
+ tm2_start(p->timer, MIN(cf->min_timeout_time, cf->max_garbage_time));
return PS_UP;
}
@@ -1194,7 +1196,7 @@ rip_show_interfaces(struct proto *P, char *iff)
}
cli_msg(-1021, "%s:", p->p.name);
- cli_msg(-1021, "%-10s %-6s %6s %6s %6s",
+ cli_msg(-1021, "%-10s %-6s %6s %6s %7s",
"Interface", "State", "Metric", "Nbrs", "Timer");
WALK_LIST(ifa, p->iface_list)
@@ -1207,8 +1209,9 @@ rip_show_interfaces(struct proto *P, char *iff)
if (n->last_seen)
nbrs++;
- int timer = MAX(ifa->next_regular - now, 0);
- cli_msg(-1021, "%-10s %-6s %6u %6u %6u",
+ btime now_ = current_time();
+ btime timer = (ifa->next_regular > now_) ? (ifa->next_regular - now_) : 0;
+ cli_msg(-1021, "%-10s %-6s %6u %6u %7t",
ifa->iface->name, (ifa->up ? "Up" : "Down"), ifa->cf->metric, nbrs, timer);
}
@@ -1230,7 +1233,7 @@ rip_show_neighbors(struct proto *P, char *iff)
}
cli_msg(-1022, "%s:", p->p.name);
- cli_msg(-1022, "%-25s %-10s %6s %6s %6s",
+ cli_msg(-1022, "%-25s %-10s %6s %6s %7s",
"IP address", "Interface", "Metric", "Routes", "Seen");
WALK_LIST(ifa, p->iface_list)
@@ -1243,8 +1246,8 @@ rip_show_neighbors(struct proto *P, char *iff)
if (!n->last_seen)
continue;
- int timer = now - n->last_seen;
- cli_msg(-1022, "%-25I %-10s %6u %6u %6u",
+ btime timer = current_time() - n->last_seen;
+ cli_msg(-1022, "%-25I %-10s %6u %6u %7t",
n->nbr->addr, ifa->iface->name, ifa->cf->metric, n->uc, timer);
}
}
@@ -1262,9 +1265,9 @@ rip_dump(struct proto *P)
i = 0;
FIB_WALK(&p->rtable, struct rip_entry, en)
{
- debug("RIP: entry #%d: %N via %I dev %s valid %d metric %d age %d s\n",
+ debug("RIP: entry #%d: %N via %I dev %s valid %d metric %d age %t\n",
i++, en->n.addr, en->next_hop, en->iface->name,
- en->valid, en->metric, now - en->changed);
+ en->valid, en->metric, current_time() - en->changed);
}
FIB_WALK_END;
diff --git a/proto/rip/rip.h b/proto/rip/rip.h
index 03dc9138..2371ea31 100644
--- a/proto/rip/rip.h
+++ b/proto/rip/rip.h
@@ -38,9 +38,9 @@
#define RIP_DEFAULT_ECMP_LIMIT 16
#define RIP_DEFAULT_INFINITY 16
-#define RIP_DEFAULT_UPDATE_TIME 30
-#define RIP_DEFAULT_TIMEOUT_TIME 180
-#define RIP_DEFAULT_GARBAGE_TIME 120
+#define RIP_DEFAULT_UPDATE_TIME (30 S_)
+#define RIP_DEFAULT_TIMEOUT_TIME (180 S_)
+#define RIP_DEFAULT_GARBAGE_TIME (120 S_)
struct rip_config
@@ -52,8 +52,8 @@ struct rip_config
u8 ecmp; /* Maximum number of nexthops in ECMP route, or 0 */
u8 infinity; /* Maximum metric value, representing infinity */
- u32 min_timeout_time; /* Minimum of interface timeout_time */
- u32 max_garbage_time; /* Maximum of interface garbage_time */
+ btime min_timeout_time; /* Minimum of interface timeout_time */
+ btime max_garbage_time; /* Maximum of interface garbage_time */
};
struct rip_iface_config
@@ -78,9 +78,9 @@ struct rip_iface_config
u16 tx_length; /* TX packet length limit (including headers), 0 for MTU */
int tx_tos;
int tx_priority;
- u32 update_time; /* Periodic update interval */
- u32 timeout_time; /* Route expiration timeout */
- u32 garbage_time; /* Unreachable entry GC timeout */
+ btime update_time; /* Periodic update interval */
+ btime timeout_time; /* Route expiration timeout */
+ btime garbage_time; /* Unreachable entry GC timeout */
list *passwords; /* Passwords for authentication */
};
@@ -120,14 +120,14 @@ struct rip_iface
list neigh_list; /* List of iface neighbors (struct rip_neighbor) */
/* Update scheduling */
- bird_clock_t next_regular; /* Next time when regular update should be called */
- bird_clock_t next_triggered; /* Next time when triggerd update may be called */
- bird_clock_t want_triggered; /* Nonzero if triggered update is scheduled */
+ btime next_regular; /* Next time when regular update should be called */
+ btime next_triggered; /* Next time when triggerd update may be called */
+ btime want_triggered; /* Nonzero if triggered update is scheduled */
/* Active update */
int tx_active; /* Update session is active */
ip_addr tx_addr; /* Update session destination address */
- bird_clock_t tx_changed; /* Minimal changed time for triggered update */
+ btime tx_changed; /* Minimal changed time for triggered update */
struct fib_iterator tx_fit; /* FIB iterator in RIP routing table (p.rtable) */
};
@@ -137,7 +137,7 @@ struct rip_neighbor
struct rip_iface *ifa; /* Associated interface, may be NULL if stale */
struct neighbor *nbr; /* Associaded core neighbor, may be NULL if stale */
struct bfd_request *bfd_req; /* BFD request, if BFD is used */
- bird_clock_t last_seen; /* Time of last received and accepted message */
+ btime last_seen; /* Time of last received and accepted message */
u32 uc; /* Use count, number of routes linking the neighbor */
u32 csn; /* Last received crypto sequence number */
};
@@ -153,7 +153,7 @@ struct rip_entry
struct iface *iface; /* Outgoing route iface (for next hop) */
ip_addr next_hop; /* Outgoing route next hop */
- bird_clock_t changed; /* Last time when the outgoing route metric changed */
+ btime changed; /* Last time when the outgoing route metric changed */
struct fib_node n;
};
@@ -167,7 +167,7 @@ struct rip_rte
u16 metric; /* Route metric (after increase) */
u16 tag; /* Route tag */
- bird_clock_t expires; /* Time of route expiration */
+ btime expires; /* Time of route expiration */
};
@@ -211,7 +211,7 @@ void rip_show_neighbors(struct proto *P, char *iff);
/* packets.c */
void rip_send_request(struct rip_proto *p, struct rip_iface *ifa);
-void rip_send_table(struct rip_proto *p, struct rip_iface *ifa, ip_addr addr, bird_clock_t changed);
+void rip_send_table(struct rip_proto *p, struct rip_iface *ifa, ip_addr addr, btime changed);
int rip_open_socket(struct rip_iface *ifa);