[PATCH 6/6] Add hash support to route cache
roopa at cumulusnetworks.com
roopa at cumulusnetworks.com
Mon Nov 5 00:13:06 EST 2012
From: roopa <roopa at cumulusnetworks.com>
This patch adds keygen function to route object
Signed-off-by: Shrijeet Mukherjee <shm at cumulusnetworks.com>
Signed-off-by: Nolan Leake <nolan at cumulusnetworks.com>
Signed-off-by: Roopa Prabhu <roopa at cumulusnetworks.com>
Reviewed-by: Wilson Kok <wkok at cumulusnetworks.com>
---
lib/route/route_obj.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 55 insertions(+), 0 deletions(-)
diff --git a/lib/route/route_obj.c b/lib/route/route_obj.c
index 54df023..c01c347 100644
--- a/lib/route/route_obj.c
+++ b/lib/route/route_obj.c
@@ -35,6 +35,7 @@
#include <netlink/cache.h>
#include <netlink/utils.h>
#include <netlink/data.h>
+#include <netlink/hashtable.h>
#include <netlink/route/rtnl.h>
#include <netlink/route/route.h>
#include <netlink/route/link.h>
@@ -289,6 +290,59 @@ static void route_dump_stats(struct nl_object *obj, struct nl_dump_params *p)
}
}
+static void route_keygen(struct nl_object *obj, uint32_t *hashkey,
+ uint32_t table_sz)
+{
+ struct rtnl_route *route = (struct rtnl_route *) obj;
+ struct route_hash_key *_key;
+ char *_key_b;
+ unsigned int _key_sz;
+ unsigned int sz_dst = 0;
+ void *dst = NULL;
+ struct route_hash_key {
+ uint8_t rt_family;
+ uint8_t rt_tos;
+ uint32_t rt_table;
+ void *rt_addr;
+ };
+
+ if (route->rt_dst) {
+ sz_dst = nl_addr_get_len(route->rt_dst);
+ dst = nl_addr_get_binary_addr(route->rt_dst);
+ }
+
+ _key_sz = sizeof(struct route_hash_key) -
+ sizeof(void *) + sz_dst;
+
+ _key = calloc(1, _key_sz);
+
+ if (!_key) {
+ NL_DBG(2, "Warning: calloc failed for %d bytes...\n", _key_sz);
+ *hashkey = 0;
+ }
+
+ _key_b = (char *) &(_key->rt_addr);
+ _key->rt_family = route->rt_family;
+ _key->rt_tos = route->rt_tos;
+ _key->rt_table = route->rt_table;
+
+ NL_DBG(5, "route %p buffer %p, source %p, size %d\n",
+ route,
+ _key,
+ nl_addr_get_binary_addr(route->rt_dst),
+ _key_sz);
+
+
+ if (sz_dst)
+ memcpy((void *)_key_b, dst, sz_dst);
+
+ *hashkey = nl_hash(_key, _key_sz, 0) % table_sz;
+
+ free(_key);
+
+ return;
+}
+
static int route_compare(struct nl_object *_a, struct nl_object *_b,
uint32_t attrs, int flags)
{
@@ -1151,6 +1205,7 @@ struct nl_object_ops route_obj_ops = {
[NL_DUMP_STATS] = route_dump_stats,
},
.oo_compare = route_compare,
+ .oo_keygen = route_keygen,
.oo_attrs2str = route_attrs2str,
.oo_id_attrs = (ROUTE_ATTR_FAMILY | ROUTE_ATTR_TOS |
ROUTE_ATTR_TABLE | ROUTE_ATTR_DST),
--
1.7.2.5
More information about the libnl
mailing list