[PATCH 1/3] Add support for per cache flags

roopa at cumulusnetworks.com roopa at cumulusnetworks.com
Sun Nov 11 20:08:46 EST 2012


From: roopa <roopa at cumulusnetworks.com>

This patch adds support for per cache flags
and adds a flag NL_CACHE_AF_ITER to iter over all
supported families when filling the cache.
---
 include/netlink/cache-api.h |   18 ++++++++++++++++++
 include/netlink/cache.h     |    1 +
 lib/cache.c                 |   30 ++++++++++++++++++++++++++++++
 3 files changed, 49 insertions(+), 0 deletions(-)

diff --git a/include/netlink/cache-api.h b/include/netlink/cache-api.h
index aa5eeb6..1ebbbd8 100644
--- a/include/netlink/cache-api.h
+++ b/include/netlink/cache-api.h
@@ -169,6 +169,11 @@ struct nl_parser_param
 };
 
 /**
+ * Cache flags
+ */
+#define NL_CACHE_AF_ITER	0x0001
+
+/**
  * Cache Operations
  *
  * This structure defines the characterstics of a cache type. It contains
@@ -189,6 +194,9 @@ struct nl_cache_ops
 	/** cache object hash size **/
 	int			co_hash_size;
 
+	/** cache flags */
+	unsigned int		co_flags;
+
 	/** Group definition */
 	struct nl_af_group *	co_groups;
 	
@@ -246,6 +254,16 @@ struct nl_cache_ops
 	int   (*co_include_event)(struct nl_cache *cache, struct nl_object *obj,
 				  change_func_t change_cb, void *data);
 
+	/**
+	 * Called to set cache flags
+	 */
+	int   (*co_set_flags)(struct nl_cache *, unsigned int flags);
+
+	/**
+	 * Called to get cache flags
+	 */
+	unsigned int    (*co_get_flags)(struct nl_cache *);
+
 	/** Object operations */
 	struct nl_object_ops *	co_obj_ops;
 
diff --git a/include/netlink/cache.h b/include/netlink/cache.h
index c919e6b..ee3b5d8 100644
--- a/include/netlink/cache.h
+++ b/include/netlink/cache.h
@@ -66,6 +66,7 @@ extern int			nl_cache_include(struct nl_cache *,
 						 void *);
 extern void			nl_cache_set_arg1(struct nl_cache *, int);
 extern void			nl_cache_set_arg2(struct nl_cache *, int);
+extern void			nl_cache_set_flags(struct nl_cache *, unsigned int);
 
 /* General */
 extern int			nl_cache_is_empty(struct nl_cache *);
diff --git a/lib/cache.c b/lib/cache.c
index af4ee95..831a12d 100644
--- a/lib/cache.c
+++ b/lib/cache.c
@@ -566,6 +566,36 @@ void nl_cache_set_arg2(struct nl_cache *cache, int arg)
 }
 
 /**
+ * Set cache flags
+ * @arg cache		Cache
+ * @arg arg		flags
+ *
+ */
+void nl_cache_set_flags(struct nl_cache *cache, unsigned int flags)
+{
+	if (cache->c_ops->co_set_flags) {
+		cache->c_ops->co_set_flags(cache, flags);
+		return;
+	}
+
+	cache->c_ops->co_flags |= flags;
+}
+
+/**
+ * Get cache flags
+ * @arg cache		Cache
+ * @arg arg		argument
+ *
+ */
+unsigned int nl_cache_get_flags(struct nl_cache *cache)
+{
+	if (cache->c_ops->co_get_flags)
+		return cache->c_ops->co_get_flags(cache);
+
+	return cache->c_ops->co_flags;
+}
+
+/**
  * Invoke the request-update operation
  * @arg sk		Netlink socket.
  * @arg cache		Cache
-- 
1.7.2.5




More information about the libnl mailing list