]> granicus.if.org Git - libnl/commitdiff
Add hash support to link cache
authorroopa <roopa@cumulusnetworks.com>
Fri, 9 Nov 2012 22:41:34 +0000 (14:41 -0800)
committerThomas Graf <tgraf@redhat.com>
Fri, 9 Nov 2012 23:12:51 +0000 (00:12 +0100)
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>
lib/route/link.c

index 3f9d9dc54d6364a13fbe876f1c7982050a2d7c85..f8646d174b8e62f5160d0388d26c345fc47f6115 100644 (file)
@@ -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,
 };