route: Update time while adding/removing routes

So we seen when adding/removing a lot of them if that takes a long time
This commit is contained in:
Samuel Thibault 2025-03-30 16:10:55 +02:00
parent ebb8784ec3
commit c9aac241ea

View file

@ -319,6 +319,12 @@ static clockt now(double *f)
return (t.tv_sec - basetime) * 10 + t.tv_usec / 100000 + 1;
}
static void update_time_now_string(void)
{
strftime(time_now_string, sizeof(time_now_string), "%Y-%m-%d %H:%M:%S", localtime(&time_now));
}
// work out a retry time based on try number
// This is a straight bounded exponential backoff.
// Maximum re-try time is 32 seconds. (2^5).
@ -1592,6 +1598,9 @@ static void routeset(sessionidt s, in_addr_t ip, int prefixlen, in_addr_t gw, in
metric = config->route_metric;
rtnetlink_addattr(&req.nh, RTA_PRIORITY, &metric, sizeof(metric));
// Update time stamp to see in logs if adding/removing routes is very long
now(NULL);
update_time_now_string();
LOG(1, s, session[s].tunnel, "Route %s %s/%d%s%s\n", add ? "add" : "del",
fmtaddr(htonl(ip), 0), prefixlen,
gw ? " via" : "", gw ? fmtaddr(htonl(gw), 2) : "");
@ -1713,6 +1722,9 @@ void route6set(sessionidt s, struct in6_addr ip, int prefixlen, int add)
metric = config->route_metric;
rtnetlink_addattr(&req.nh, RTA_PRIORITY, &metric, sizeof(metric));
// Update time stamp to see in logs if adding/removing routes is very long
now(NULL);
update_time_now_string();
LOG(1, s, session[s].tunnel, "Route %s %s/%d\n",
add ? "add" : "del",
inet_ntop(AF_INET6, &ip, ipv6addr, INET6_ADDRSTRLEN),
@ -6286,7 +6298,7 @@ static void mainloop(void)
printf("%s\n", config->bandwidth);
// Update the internal time counter
strftime(time_now_string, sizeof(time_now_string), "%Y-%m-%d %H:%M:%S", localtime(&time_now));
update_time_now_string();
{
// Run timer hooks
@ -7081,7 +7093,7 @@ int main(int argc, char *argv[])
// Start the timer routine off
time(&time_now);
strftime(time_now_string, sizeof(time_now_string), "%Y-%m-%d %H:%M:%S", localtime(&time_now));
update_time_now_string();
initplugins();
initdata(optdebug, optconfig);