summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorroopa <roopa@cumulusnetworks.com>2012-11-09 14:41:35 -0800
committerThomas Graf <tgraf@redhat.com>2012-11-10 00:12:57 +0100
commit6f24cf12caae88e1a09f0516e00188966a232290 (patch)
tree387e8d08d2a26fdb35a33ef1f5c0ebf5a256ac1f
parente16e8fdcdbacbd8179ec7a53fa678211d79e550e (diff)
downloadlibnl-6f24cf12caae88e1a09f0516e00188966a232290.tar.gz
Add hash support to neigh cache
This patch adds keygen function to the neigh object 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/neigh.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/route/neigh.c b/lib/route/neigh.c
index bb61571..1986ef5 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,50 @@ 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;
+ unsigned int nkey_sz;
+ struct nl_addr *addr = NULL;
+ struct neigh_hash_key {
+ uint32_t n_family;
+ uint32_t n_ifindex;
+ char n_addr[0];
+ } __attribute__((packed)) *nkey;
+ char buf[INET6_ADDRSTRLEN+5];
+
+ if (neigh->n_dst)
+ addr = neigh->n_dst;
+
+ nkey_sz = sizeof(*nkey);
+ if (addr)
+ nkey_sz += nl_addr_get_len(addr);
+
+ nkey = calloc(1, nkey_sz);
+ if (!nkey) {
+ *hashkey = 0;
+ return;
+ }
+ nkey->n_family = neigh->n_family;
+ nkey->n_ifindex = neigh->n_ifindex;
+ if (addr)
+ memcpy(nkey->n_addr,
+ nl_addr_get_binary_addr(addr),
+ nl_addr_get_len(addr));
+
+ *hashkey = nl_hash(nkey, nkey_sz, 0) % table_sz;
+
+ NL_DBG(5, "neigh %p key (fam %d dev %d addr %s) keysz %d hash 0x%x\n",
+ neigh, nkey->n_family, nkey->n_ifindex,
+ nl_addr2str(addr, buf, sizeof(buf)),
+ nkey_sz, *hashkey);
+
+ free(nkey);
+
+ return;
+}
+
static int neigh_compare(struct nl_object *_a, struct nl_object *_b,
uint32_t attrs, int flags)
{
@@ -825,6 +870,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),
};