I want to find an exact match in the FIB. Is there already a function which
does this?
I came up with a function to get AN answer, I'm just wondering if there
is a better way.
I copied code from a similar function and came up with this:
--------------------------------------------------------------------------
struct fib_info *fn_hash_exact(u32 prefix,int z)
{
struct fib_table *tb = fib_get_table(RT_TABLE_MAIN);
/* JLEU: this doesn't support MULTIPLE_TABLES */
struct fn_hash *table = (struct fn_hash*)tb->tb_data;
struct fib_node **fp, **del_fp, *f;
struct fn_zone *fz;
fn_key_t key;
#ifdef CONFIG_IP_ROUTE_TOS
u8 tos = r->rtm_tos;
#endif
printk("tb(%d)_exact: %d %08x/%d %d\n", tb->tb_id, RTN_UNICAST, prefix, z, -1);
if (z > 32)
return NULL;
if ((fz = table->fn_zones[z]) == NULL)
return NULL;
fz_key_0(key);
{
if (prefix & ~FZ_MASK(fz))
return NULL;
key = fz_key(prefix, fz);
}
fp = fz_chain_p(key, fz);
FIB_SCAN(f, fp) {
if (fn_key_eq(f->fn_key, key))
break;
if (fn_key_leq(key, f->fn_key))
return NULL;
}
#ifdef CONFIG_IP_ROUTE_TOS
FIB_SCAN_KEY(f, fp, key) {
if (f->fn_tos == tos)
break;
}
#endif
/* JLEU last match wins ! */
del_fp = NULL;
FIB_SCAN_TOS(f, fp, key, tos) {
if (f->fn_state&FN_S_ZOMBIE)
return NULL;
del_fp = fp;
}
if(del_fp && *del_fp) return FIB_INFO(*del_fp);
return NULL;
}
--
James R. Leu | Ericsson Datacom, Inc
Software Engineer | IP Infrastructure
jleu@xxxxxxxxxxxxxx | Morrisville, NC USA
|