netdev
[Top] [All Lists]

Finding an exact match in FIB

To: netdev@xxxxxxxxxxx
Subject: Finding an exact match in FIB
From: "James R. Leu" <jleu@xxxxxxxxxxxxxx>
Date: Tue, 21 Dec 1999 13:43:44 -0500
Organization: Ericsson Datacom
Reply-to: jleu@xxxxxxxxxxxxxx
Sender: owner-netdev@xxxxxxxxxxx
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

<Prev in Thread] Current Thread [Next in Thread>