0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-12-22 09:41:54 +00:00

Added fib_route() which does (although very slow) lookup of longest-match

routing in a FIB.
This commit is contained in:
Martin Mares 2000-05-13 11:42:06 +00:00
parent d3abfbc68d
commit 56d6c530eb
2 changed files with 19 additions and 1 deletions

View File

@ -63,6 +63,7 @@ struct fib {
void fib_init(struct fib *, pool *, unsigned node_size, unsigned hash_order, void (*init)(struct fib_node *)); void fib_init(struct fib *, pool *, unsigned node_size, unsigned hash_order, void (*init)(struct fib_node *));
void *fib_find(struct fib *, ip_addr *, int); /* Find or return NULL if doesn't exist */ void *fib_find(struct fib *, ip_addr *, int); /* Find or return NULL if doesn't exist */
void *fib_get(struct fib *, ip_addr *, int); /* Find or create new if nonexistent */ void *fib_get(struct fib *, ip_addr *, int); /* Find or create new if nonexistent */
void *fib_route(struct fib *, ip_addr, int); /* Longest-match routing lookup */
void fib_delete(struct fib *, void *); /* Remove fib entry */ void fib_delete(struct fib *, void *); /* Remove fib entry */
void fib_free(struct fib *); /* Destroy the fib */ void fib_free(struct fib *); /* Destroy the fib */
void fib_check(struct fib *); /* Consistency check for debugging */ void fib_check(struct fib *); /* Consistency check for debugging */
@ -212,7 +213,7 @@ struct rt_show_data {
int import_mode, primary_only; int import_mode, primary_only;
struct config *running_on_config; struct config *running_on_config;
int net_counter, rt_counter, show_counter; int net_counter, rt_counter, show_counter;
int stats; int stats, show_for;
}; };
void rt_show(struct rt_show_data *); void rt_show(struct rt_show_data *);

View File

@ -152,6 +152,23 @@ fib_get(struct fib *f, ip_addr *a, int len)
return e; return e;
} }
void *
fib_route(struct fib *f, ip_addr a, int len)
{
ip_addr a0;
void *t;
while (len >= 0)
{
a0 = ipa_and(a, ipa_mkmask(len));
t = fib_find(f, &a0, len);
if (t)
return t;
len--;
}
return NULL;
}
static inline void static inline void
fib_merge_readers(struct fib_iterator *i, struct fib_node *to) fib_merge_readers(struct fib_iterator *i, struct fib_node *to)
{ {