[PATCH 5/6] Add hash support to neigh cache
roopa at cumulusnetworks.com
roopa at cumulusnetworks.com
Mon Nov 5 00:13:05 EST 2012
From: roopa <roopa at cumulusnetworks.com>
This patch adds keygen function to the neigh 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/neigh.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 50 insertions(+), 0 deletions(-)
diff --git a/lib/route/neigh.c b/lib/route/neigh.c
index bb61571..a9ab736 100644
--- a/lib/route/neigh.c
+++ b/lib/route/neigh.c
@@ -151,6 +151,7 @@
#include <netlink-local.h>
#include <netlink/netlink.h>
#include <netlink/utils.h>
+#include <netlink/hashtable.h>
#include <netlink/route/rtnl.h>
#include <netlink/route/neighbour.h>
#include <netlink/route/link.h>
@@ -197,6 +198,54 @@ static int neigh_clone(struct nl_object *_dst, struct nl_object *_src)
return 0;
}
+static void neigh_keygen(struct nl_object *obj, uint32_t *hashkey,
+ uint32_t table_sz)
+{
+ struct rtnl_neigh *neigh = (struct rtnl_neigh *) obj;
+ struct neigh_hash_key *_key;
+ char *_key_b;
+ unsigned int _key_sz;
+ unsigned int sz_dst = 0;
+ void *dst = NULL;
+ struct neigh_hash_key {
+ uint32_t n_family;
+ uint32_t n_ifindex;
+ void *n_addr;
+ };
+
+ if (neigh->n_dst) {
+ sz_dst = nl_addr_get_len(neigh->n_dst);
+ dst = nl_addr_get_binary_addr(neigh->n_dst);
+ }
+
+ _key_sz = sizeof(struct neigh_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->n_addr);
+ _key->n_family = neigh->n_family;
+ _key->n_ifindex = neigh->n_ifindex;
+
+ NL_DBG(5, "neigh %p dst_a %p, size %d\n",
+ neigh,
+ &(_key->n_addr),
+ _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 neigh_compare(struct nl_object *_a, struct nl_object *_b,
uint32_t attrs, int flags)
{
@@ -825,6 +874,7 @@ static struct nl_object_ops neigh_obj_ops = {
[NL_DUMP_STATS] = neigh_dump_stats,
},
.oo_compare = neigh_compare,
+ .oo_keygen = neigh_keygen,
.oo_attrs2str = neigh_attrs2str,
.oo_id_attrs = (NEIGH_ATTR_IFINDEX | NEIGH_ATTR_DST | NEIGH_ATTR_FAMILY),
};
--
1.7.2.5
More information about the libnl
mailing list