summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorroopa <roopa@cumulusnetworks.com>2012-11-09 14:41:34 -0800
committerThomas Graf <tgraf@redhat.com>2012-11-10 00:12:51 +0100
commite16e8fdcdbacbd8179ec7a53fa678211d79e550e (patch)
tree9e126489ad3b0d732fd5c4ac6e8675f7a2f2b008
parent55c0e036b04b567a81cca441117b4e2ce5e22ef2 (diff)
downloadlibnl-e16e8fdcdbacbd8179ec7a53fa678211d79e550e.tar.gz
Add hash support to link cache
This patch adds keygen function to link cache Signed-off-by: Shrijeet Mukherjee <shm@cumulusnetworks.com> Signed-off-by: Nolan Leake <nolan@cumulusnetworks.com> Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com> Reviewed-by: Wilson Kok <wkok@cumulusnetworks.com> Signed-off-by: Thomas Graf <tgraf@suug.ch>
-rw-r--r--lib/route/link.c23
1 files changed, 23 insertions, 0 deletions
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 <netlink/attr.h>
#include <netlink/utils.h>
#include <netlink/object.h>
+#include <netlink/hashtable.h>
#include <netlink/route/rtnl.h>
#include <netlink/route/link.h>
#include <netlink/route/link/api.h>
@@ -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,
};