remove rime routes in LRU mode if trying to add a new route to full route table

This commit is contained in:
tpetry 2015-06-19 16:32:19 +02:00
parent 0b1a0d2bd9
commit b3046f1537

View File

@ -121,7 +121,7 @@ int
route_add(const linkaddr_t *dest, const linkaddr_t *nexthop, route_add(const linkaddr_t *dest, const linkaddr_t *nexthop,
uint8_t cost, uint8_t seqno) uint8_t cost, uint8_t seqno)
{ {
struct route_entry *e; struct route_entry *e, *oldest = NULL;
/* Avoid inserting duplicate entries. */ /* Avoid inserting duplicate entries. */
e = route_lookup(dest); e = route_lookup(dest);
@ -131,8 +131,14 @@ route_add(const linkaddr_t *dest, const linkaddr_t *nexthop,
/* Allocate a new entry or reuse the oldest entry with highest cost. */ /* Allocate a new entry or reuse the oldest entry with highest cost. */
e = memb_alloc(&route_mem); e = memb_alloc(&route_mem);
if(e == NULL) { if(e == NULL) {
/* Remove oldest entry. XXX */ /* Remove oldest entry. */
e = list_chop(route_table); for(e = list_head(route_table); e != NULL; e = list_item_next(e)) {
if(oldest == NULL || e->time >= oldest->time) {
oldest = e;
}
}
e = oldest;
list_remove(route_table, e);
PRINTF("route_add: removing entry to %d.%d with nexthop %d.%d and cost %d\n", PRINTF("route_add: removing entry to %d.%d with nexthop %d.%d and cost %d\n",
e->dest.u8[0], e->dest.u8[1], e->dest.u8[0], e->dest.u8[1],
e->nexthop.u8[0], e->nexthop.u8[1], e->nexthop.u8[0], e->nexthop.u8[1],