From e16e8fdcdbacbd8179ec7a53fa678211d79e550e Mon Sep 17 00:00:00 2001 From: roopa Date: Fri, 9 Nov 2012 14:41:34 -0800 Subject: Add hash support to link cache This patch adds keygen function to link cache Signed-off-by: Shrijeet Mukherjee Signed-off-by: Nolan Leake Signed-off-by: Roopa Prabhu Reviewed-by: Wilson Kok Signed-off-by: Thomas Graf --- lib/route/link.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lib/route/link.c b/lib/route/link.c index 3f9d9dc..f8646d1 100644 --- a/lib/route/link.c +++ b/lib/route/link.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -799,6 +800,27 @@ static int link_handle_event(struct nl_object *a, struct rtnl_link_event_cb *cb) } #endif + +static void link_keygen(struct nl_object *obj, uint32_t *hashkey, + uint32_t table_sz) +{ + struct rtnl_link *link = (struct rtnl_link *) obj; + unsigned int lkey_sz; + struct link_hash_key { + uint32_t l_index; + } __attribute__((packed)) lkey; + + lkey_sz = sizeof(lkey); + lkey.l_index = link->l_index; + + *hashkey = nl_hash(&lkey, lkey_sz, 0) % table_sz; + + NL_DBG(5, "link %p key (dev %d) keysz %d, hash 0x%x\n", + link, lkey.l_index, lkey_sz, *hashkey); + + return; +} + static int link_compare(struct nl_object *_a, struct nl_object *_b, uint32_t attrs, int flags) { @@ -2500,6 +2522,7 @@ static struct nl_object_ops link_obj_ops = { [NL_DUMP_STATS] = link_dump_stats, }, .oo_compare = link_compare, + .oo_keygen = link_keygen, .oo_attrs2str = link_attrs2str, .oo_id_attrs = LINK_ATTR_IFINDEX, }; -- cgit v1.2.1