diff options
author | Ondrej Zajicek (work) <santiago@crfreenet.org> | 2015-12-24 15:52:03 +0100 |
---|---|---|
committer | Ondrej Zajicek (work) <santiago@crfreenet.org> | 2015-12-24 15:56:04 +0100 |
commit | 04632fd77f291f67753341d12d540f7dac341bd3 (patch) | |
tree | 94b319a0fe0e312539857e76e0b9d6982ce81555 /nest/rt-fib.c | |
parent | 70b90dde23a684c4d32aa53685f76a73ecba941d (diff) |
Follow-up work on integration
Diffstat (limited to 'nest/rt-fib.c')
-rw-r--r-- | nest/rt-fib.c | 43 |
1 files changed, 23 insertions, 20 deletions
diff --git a/nest/rt-fib.c b/nest/rt-fib.c index c12d0519..c83ae171 100644 --- a/nest/rt-fib.c +++ b/nest/rt-fib.c @@ -43,7 +43,7 @@ #define HASH_DEF_ORDER 10 #define HASH_HI_MARK *4 #define HASH_HI_STEP 2 -#define HASH_HI_MAX 16 /* Must be at most 16 */ +#define HASH_HI_MAX 16 #define HASH_LO_MARK /5 #define HASH_LO_STEP 2 #define HASH_LO_MIN 10 @@ -266,38 +266,32 @@ fib_get(struct fib *f, const net_addr *a) return b; } -static void * -fib_route_ip4(struct fib *f, const net_addr *n0) +static inline void * +fib_route_ip4(struct fib *f, net_addr_ip4 *n) { - net_addr net; - net_addr_ip4 *n = (net_addr_ip4 *) &net; - void *b; + void *r; - net_copy(&net, n0); - while (!(b = fib_find(f, &net)) && (n->pxlen > 0)) + while (!(r = fib_find(f, (net_addr *) n)) && (n->pxlen > 0)) { n->pxlen--; ip4_clrbit(&n->prefix, n->pxlen); } - return b; + return r; } -static void * -fib_route_ip6(struct fib *f, const net_addr *n0) +static inline void * +fib_route_ip6(struct fib *f, net_addr_ip6 *n) { - net_addr net; - net_addr_ip6 *n = (net_addr_ip6 *) &net; - void *b; + void *r; - net_copy(&net, n0); - while (!(b = fib_find(f, &net)) && (n->pxlen > 0)) + while (!(r = fib_find(f, (net_addr *) n)) && (n->pxlen > 0)) { n->pxlen--; ip6_clrbit(&n->prefix, n->pxlen); } - return b; + return r; } /** @@ -314,21 +308,25 @@ fib_route(struct fib *f, const net_addr *n) { ASSERT(f->addr_type == n->type); + net_addr *n0 = alloca(n->length); + net_copy(n0, n); + switch (n->type) { case NET_IP4: case NET_VPN4: - return fib_route_ip4(f, n); + return fib_route_ip4(f, (net_addr_ip4 *) n0); case NET_IP6: case NET_VPN6: - return fib_route_ip6(f, n); + return fib_route_ip6(f, (net_addr_ip6 *) n0); default: return NULL; } } + static inline void fib_merge_readers(struct fib_iterator *i, struct fib_node *to) { @@ -398,7 +396,12 @@ fib_delete(struct fib *f, void *E) } fib_merge_readers(it, l); } - sl_free(f->fib_slab, e); + + if (f->fib_slab) + sl_free(f->fib_slab, E); + else + mb_free(E); + if (f->entries-- < f->entries_min) fib_rehash(f, -HASH_LO_STEP); return; |