Commit fd83431d authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Drop routes when overflowing the route table.

parent 63178e83
......@@ -309,6 +309,49 @@ update_network_metric(struct network *net)
}
}
/* We're overflowing the route table. Find some hopefully useless
routes and drop them. */
static void
drop_some_routes(void)
{
int i;
i = 0;
while(i < numroutes) {
if(!routes[i].installed && routes[i].time < now.tv_sec - 90) {
flush_route(&routes[i]);
continue;
}
if(routes[i].metric >= INFINITY && routes[i].time < now.tv_sec - 90) {
flush_route(&routes[i]);
continue;
}
}
if(numroutes < MAXROUTES)
return;
/* We didn't manage to free a table entry just by dropping useless
routes. Let's take more drastic action. */
for(i = 0; i < numroutes; i++) {
if(!route_feasible(&routes[i])) {
flush_route(&routes[i]);
return;
}
}
for(i = 0; i < numroutes; i++) {
if(!routes[i].installed) {
flush_route(&routes[i]);
return;
}
}
return;
}
/* This is called whenever we receive an update. */
struct route *
update_route(const unsigned char *a, const unsigned char *p, unsigned char plen,
......@@ -388,6 +431,8 @@ update_route(const unsigned char *a, const unsigned char *p, unsigned char plen,
if(refmetric >= INFINITY)
/* Somebody's retracting a route we never saw. */
return NULL;
if(numroutes >= MAXROUTES)
drop_some_routes();
if(numroutes >= MAXROUTES) {
fprintf(stderr, "Too many routes -- ignoring update.\n");
return NULL;
......
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