Commit e7aad3be authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Allow resizing routes on table overflow.

parent 702d05ce
...@@ -20,7 +20,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN ...@@ -20,7 +20,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. THE SOFTWARE.
*/ */
#define MAXROUTES 512
#define MAXSRCS 256 #define MAXSRCS 256
#define MAXNEIGHBOURS 64 #define MAXNEIGHBOURS 64
......
...@@ -38,8 +38,8 @@ THE SOFTWARE. ...@@ -38,8 +38,8 @@ THE SOFTWARE.
#include "resend.h" #include "resend.h"
#include "filter.h" #include "filter.h"
struct route routes[MAXROUTES]; struct route *routes = NULL;
int numroutes = 0; int numroutes = 0, maxroutes = 0;
int kernel_metric = 0; int kernel_metric = 0;
int route_timeout_delay = 160; int route_timeout_delay = 160;
int route_gc_delay = 180; int route_gc_delay = 180;
...@@ -317,49 +317,6 @@ update_network_metric(struct network *net) ...@@ -317,49 +317,6 @@ 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. */ /* This is called whenever we receive an update. */
struct route * struct route *
update_route(const unsigned char *a, const unsigned char *p, unsigned char plen, update_route(const unsigned char *a, const unsigned char *p, unsigned char plen,
...@@ -440,11 +397,16 @@ update_route(const unsigned char *a, const unsigned char *p, unsigned char plen, ...@@ -440,11 +397,16 @@ update_route(const unsigned char *a, const unsigned char *p, unsigned char plen,
if(refmetric >= INFINITY) if(refmetric >= INFINITY)
/* Somebody's retracting a route we never saw. */ /* Somebody's retracting a route we never saw. */
return NULL; return NULL;
if(numroutes >= MAXROUTES) if(numroutes >= maxroutes) {
drop_some_routes(); struct route *new_routes;
if(numroutes >= MAXROUTES) { int n = maxroutes < 1 ? 8 : 2 * maxroutes;
fprintf(stderr, "Too many routes -- ignoring update.\n"); new_routes = routes == NULL ?
return NULL; malloc(n * sizeof(struct route)) :
realloc(routes, n * sizeof(struct route));
if(new_routes == NULL)
return NULL;
maxroutes = n;
routes = new_routes;
} }
route = &routes[numroutes]; route = &routes[numroutes];
route->src = src; route->src = src;
......
...@@ -31,8 +31,8 @@ struct route { ...@@ -31,8 +31,8 @@ struct route {
int installed; int installed;
}; };
extern struct route routes[MAXROUTES]; extern struct route *routes;
extern int numroutes; extern int numroutes, maxroutes;
extern int kernel_metric; extern int kernel_metric;
extern int route_timeout_delay; extern int route_timeout_delay;
extern int route_gc_delay; extern int route_gc_delay;
......
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