diff options
author | Tobias Jungel <tobias.jungel@bisdn.de> | 2016-11-13 14:21:46 (GMT) |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2016-12-01 15:49:43 (GMT) |
commit | 66d032ad443a9d67bd26ed3e801cddf9f0e71ae7 (patch) | |
tree | cf155e8a84ec4943ecd1e1ea383337319012195a /lib/xfrm | |
parent | 55ea6e6b6cd805f441b410971c9dd7575e783ef4 (diff) | |
download | libnl-66d032ad443a9d67bd26ed3e801cddf9f0e71ae7.zip libnl-66d032ad443a9d67bd26ed3e801cddf9f0e71ae7.tar.gz libnl-66d032ad443a9d67bd26ed3e801cddf9f0e71ae7.tar.bz2 |
cache_mngr: add include callback v2
This patch adds change_func_v2_t to add a more detailed callback in
case of a cache change. The change function is registered using the new
nl_cache_mngr_add_cache_v2. In case the new change function is set,
nl_cache_include_v2 and thus cache_include_v2 will be used to perform the cache
inclusion.
The parameter of change_func_v2_t are the following:
* struct nl_cache * => cache
* struct nl_object * => the old/deleted nl_object
* struct nl_object * => the new nl_object
* uint64_t => the result of nl_object_diff64 in case of a change
* int => NL_ACT_*
* void * => data
https://github.com/thom311/libnl/issues/71
http://lists.infradead.org/pipermail/libnl/2016-September/002214.html
http://lists.infradead.org/pipermail/libnl/2016-October/002229.html
http://lists.infradead.org/pipermail/libnl/2016-November/002250.html
Diffstat (limited to 'lib/xfrm')
-rw-r--r-- | lib/xfrm/sa.c | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/lib/xfrm/sa.c b/lib/xfrm/sa.c index f25c7eb..5bd9952 100644 --- a/lib/xfrm/sa.c +++ b/lib/xfrm/sa.c @@ -918,7 +918,8 @@ errout: } static int xfrm_sa_update_cache (struct nl_cache *cache, struct nl_object *obj, - change_func_t change_cb, void *data) + change_func_t change_cb, change_func_v2_t change_cb_v2, + void *data) { struct nl_object* old_sa; struct xfrmnl_sa* sa = (struct xfrmnl_sa*)obj; @@ -947,18 +948,29 @@ static int xfrm_sa_update_cache (struct nl_cache *cache, struct nl_object *obj, * cache and notify application of the expiry event. */ nl_cache_move (cache, obj); - if (old_sa == NULL && change_cb) + if (old_sa == NULL) { /* Application CB present, no previous instance of SA object present. * Notify application CB as a NEW event */ - change_cb (cache, obj, NL_ACT_NEW, data); + if (change_cb_v2) + change_cb_v2(cache, NULL, obj, 0, NL_ACT_NEW, data); + else if (change_cb) + change_cb(cache, obj, NL_ACT_NEW, data); } else if (old_sa) { + uint64_t diff = 0; + if (change_cb || change_cb_v2) + diff = nl_object_diff64(old_sa, obj); + /* Application CB present, a previous instance of SA object present. * Notify application CB as a CHANGE1 event */ - if (nl_object_diff (old_sa, obj) && change_cb) - change_cb (cache, obj, NL_ACT_CHANGE, data); + if (diff) { + if (change_cb_v2) { + change_cb_v2(cache, old_sa, obj, diff, NL_ACT_CHANGE, data); + } else if (change_cb) + change_cb(cache, obj, NL_ACT_CHANGE, data); + } nl_object_put (old_sa); } } @@ -966,7 +978,9 @@ static int xfrm_sa_update_cache (struct nl_cache *cache, struct nl_object *obj, { /* Hard expiry event: Delete the object from the * cache and notify application of the expiry event. */ - if (change_cb) + if (change_cb_v2) + change_cb_v2(cache, obj, NULL, 0, NL_ACT_DEL, data); + else if (change_cb) change_cb (cache, obj, NL_ACT_DEL, data); nl_object_put (old_sa); } @@ -978,7 +992,10 @@ static int xfrm_sa_update_cache (struct nl_cache *cache, struct nl_object *obj, { /* All other messages other than Expire, let the standard Libnl cache * module handle it. */ - return nl_cache_include (cache, obj, change_cb, data); + if (change_cb_v2) + return nl_cache_include_v2(cache, obj, change_cb_v2, data); + else + return nl_cache_include (cache, obj, change_cb, data); } } |