]> granicus.if.org Git - libnl/commitdiff
cache: event_filter() cache operation to filter notifications
authorThomas Graf <tgraf@redhat.com>
Fri, 21 Oct 2011 09:31:15 +0000 (11:31 +0200)
committerThomas Graf <tgraf@redhat.com>
Fri, 21 Oct 2011 09:31:15 +0000 (11:31 +0200)
Certain notifications need to be filtered out and should not be applied to
a cache when a cache is handled by a cache manager.

include/netlink/cache-api.h
lib/cache_mngr.c

index efae2eddeac83e22fc06dfb6194de6464bab5b2f..1b3d099feb91c6c2bd02b20e409e1882507186f0 100644 (file)
@@ -201,6 +201,13 @@ struct nl_cache_ops
        int   (*co_msg_parser)(struct nl_cache_ops *, struct sockaddr_nl *,
                               struct nlmsghdr *, struct nl_parser_param *);
 
+       /**
+        * Called whenever a notification has been parsed into an object and
+        * is considered for inclusion into a cache. Must return NL_SKIP if
+        * the object should not be included in the cache.
+        */
+       int   (*co_event_filter)(struct nl_cache *, struct nl_object *obj);
+
        /** Object operations */
        struct nl_object_ops *  co_obj_ops;
 
index cfa676b4248966e7c5008d4bd21c9c1bfd7787c1..cf5a951bc95793ba3a2e7995fd48945bbc346eab 100644 (file)
 static int include_cb(struct nl_object *obj, struct nl_parser_param *p)
 {
        struct nl_cache_assoc *ca = p->pp_arg;
+       struct nl_cache_ops *ops = ca->ca_cache->c_ops;
 
        NL_DBG(2, "Including object %p into cache %p\n", obj, ca->ca_cache);
 #ifdef NL_DEBUG
        if (nl_debug >= 4)
                nl_object_dump(obj, &nl_debug_dp);
 #endif
+
+       if (ops->co_event_filter)
+               if (ops->co_event_filter(ca->ca_cache, obj) != NL_OK)
+                       return 0;
+
        return nl_cache_include(ca->ca_cache, obj, ca->ca_change, ca->ca_change_data);
 }