Commit 75df5876 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Allow arbitrary number of redistributed routes.

parent b790929c
...@@ -126,12 +126,19 @@ int ...@@ -126,12 +126,19 @@ int
check_xroutes(int send_updates) check_xroutes(int send_updates)
{ {
int i, j, metric, export, change = 0, rc; int i, j, metric, export, change = 0, rc;
struct kernel_route routes[240]; struct kernel_route *routes;
int numroutes; int numroutes, maxroutes;
const int maxmaxroutes = 16 * 1024;
debugf("\nChecking kernel routes.\n"); debugf("\nChecking kernel routes.\n");
rc = kernel_addresses(routes, 240); maxroutes = 8;
routes = malloc(maxroutes * sizeof(struct kernel_route));
if(routes == NULL)
return -1;
again:
rc = kernel_addresses(routes, maxroutes);
if(rc < 0) { if(rc < 0) {
perror("kernel_addresses"); perror("kernel_addresses");
numroutes = 0; numroutes = 0;
...@@ -139,17 +146,17 @@ check_xroutes(int send_updates) ...@@ -139,17 +146,17 @@ check_xroutes(int send_updates)
numroutes = rc; numroutes = rc;
} }
if(numroutes <= 240) { if(numroutes >= maxroutes)
rc = kernel_routes(routes + numroutes, 240 - numroutes); goto resize;
if(rc < 0) {
fprintf(stderr, "Couldn't get kernel routes.\n"); rc = kernel_routes(routes + numroutes, maxroutes - numroutes);
} else { if(rc < 0)
numroutes += rc; fprintf(stderr, "Couldn't get kernel routes.\n");
} else
} else { numroutes += rc;
fprintf(stderr,
"Too many local addresses -- ignoring kernel routes.\n"); if(numroutes >= maxroutes)
} goto resize;
/* Check for any routes that need to be flushed */ /* Check for any routes that need to be flushed */
...@@ -225,5 +232,16 @@ check_xroutes(int send_updates) ...@@ -225,5 +232,16 @@ check_xroutes(int send_updates)
} }
} }
free(routes);
return change; return change;
resize:
free(routes);
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