summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorroopa <roopa@cumulusnetworks.com>2012-11-09 14:41:32 -0800
committerThomas Graf <tgraf@redhat.com>2012-11-10 00:12:36 +0100
commitc6f89ed02f04ac4984be34418774a7b06ff54f79 (patch)
tree4e8197ac2af4e9199180aa961483e31c5a3885df /include
parenta8741fab8e48e55fe10cfb080ba4b28ed4441fb0 (diff)
Add nl hashtable structures and access functions
This patch adds the required structures and access functions to create and manage hashtables for netlink cache objects 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>
Diffstat (limited to 'include')
-rw-r--r--include/netlink/hashtable.h52
-rw-r--r--include/netlink/object-api.h10
-rw-r--r--include/netlink/object.h2
3 files changed, 64 insertions, 0 deletions
diff --git a/include/netlink/hashtable.h b/include/netlink/hashtable.h
new file mode 100644
index 0000000..d9e6ee4
--- /dev/null
+++ b/include/netlink/hashtable.h
@@ -0,0 +1,52 @@
+/*
+ * netlink/hashtable.h Netlink hashtable Utilities
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2012 Cumulus Networks, Inc
+ */
+
+#ifndef NETLINK_HASHTABLE_H_
+#define NETLINK_HASHTABLE_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct nl_hash_node {
+ uint32_t key;
+ uint32_t key_size;
+ struct nl_object * obj;
+ struct nl_hash_node * next;
+} nl_hash_node_t;
+
+typedef struct nl_hash_table {
+ int size;
+ nl_hash_node_t ** nodes;
+} nl_hash_table_t;
+
+/* Default hash table size */
+#define NL_MAX_HASH_ENTRIES 1024
+
+/* Access Functions */
+extern nl_hash_table_t * nl_hash_table_alloc(int size);
+extern void nl_hash_table_free(nl_hash_table_t *ht);
+
+extern int nl_hash_table_add(nl_hash_table_t *ht,
+ struct nl_object *obj);
+extern int nl_hash_table_del(nl_hash_table_t *ht,
+ struct nl_object *obj);
+
+extern struct nl_object * nl_hash_table_lookup(nl_hash_table_t *ht,
+ struct nl_object *obj);
+extern uint32_t nl_hash(void *k, size_t length,
+ uint32_t initval);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* NETLINK_HASHTABLE_H_ */
diff --git a/include/netlink/object-api.h b/include/netlink/object-api.h
index ec2192b..ae6180a 100644
--- a/include/netlink/object-api.h
+++ b/include/netlink/object-api.h
@@ -348,6 +348,16 @@ struct nl_object_ops
*/
int (*oo_update)(struct nl_object *, struct nl_object *);
+ /**
+ * Hash Key generator function
+ *
+ * When called returns a hash key for the object being
+ * referenced. This key will be used by higher level hash functions
+ * to build association lists. Each object type gets to specify
+ * it's own key formulation
+ */
+ void (*oo_keygen)(struct nl_object *, uint32_t *, uint32_t);
+
char *(*oo_attrs2str)(int, char *, size_t);
/**
diff --git a/include/netlink/object.h b/include/netlink/object.h
index 788ae48..f25713e 100644
--- a/include/netlink/object.h
+++ b/include/netlink/object.h
@@ -50,6 +50,8 @@ extern char * nl_object_attrs2str(struct nl_object *,
size_t);
extern char * nl_object_attr_list(struct nl_object *,
char *, size_t);
+extern void nl_object_keygen(struct nl_object *,
+ uint32_t *, uint32_t);
/* Marks */
extern void nl_object_mark(struct nl_object *);