Commit 1aa43eb8 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Make kernel route parsing more efficient.

We now remember the number of kernel routes from one call of check_xroutes
to the next to avoid calling down into the kernel multiple times.
parent b0b9a92f
......@@ -127,17 +127,17 @@ check_xroutes(int send_updates)
{
int i, j, metric, export, change = 0, rc;
struct kernel_route *routes;
int numroutes, maxroutes;
int numroutes;
static int maxroutes = 8;
const int maxmaxroutes = 16 * 1024;
debugf("\nChecking kernel routes.\n");
maxroutes = 8;
again:
routes = malloc(maxroutes * sizeof(struct kernel_route));
if(routes == NULL)
return -1;
again:
rc = kernel_addresses(routes, maxroutes);
if(rc < 0) {
perror("kernel_addresses");
......@@ -233,6 +233,8 @@ check_xroutes(int send_updates)
}
free(routes);
/* Set up maxroutes for the next call. */
maxroutes = MIN(numroutes + 8, maxmaxroutes);
return change;
resize:
......@@ -240,8 +242,5 @@ check_xroutes(int send_updates)
if(maxroutes >= maxmaxroutes)
return -1;
maxroutes = MIN(maxmaxroutes, 2 * maxroutes);
routes = malloc(maxroutes * sizeof(struct kernel_route));
if(routes == NULL)
return -1;
goto again;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment