summaryrefslogtreecommitdiffstats
path: root/lib/cache_mngr.c
Commit message (Collapse)AuthorAgeFilesLines
* license: fix and add SPDX license identifiers and drop license commentsThomas Haller2020-04-161-7/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This also fixes a few wrong SPDX license identifiers, where the original license comment indicates GPL-2.0-only. This is not done manually, but by running the following script: --- #!/bin/bash # Tool to drop license comments, adding SPDX license identifiers, while preserving # copyright comments. The point is not to manually do this task, but perform some # hacked up string replacement. _cp() { /bin/cp "$@" } _cat() { /bin/cat "$@" } in_file() { local T=$(mktemp) _cp -f "$1" "$T" _cat "$T" rm -f "$T" } out_file() { local T=$(mktemp) _cat - > "$T" _cp -f "$T" "$1" rm -f "$T" } join() { _cat "$@" | awk '{ printf("%s#x#", $0)}' } unjoin() { _cat - | sed 's/#x#/\n/g' } files_all() { git ls-files | grep -v '\.png$' | grep -v '^include/linux-private/' } adjust() { NEWLINES='\(#x#\)\+' COPYRIGHTS='\(\( \* Copyright (c) 20..\(-20..\|, 20..\)\? [^#]\+#x#\)\+\( \*#x# \* \(Stolen[^#]*\|Based on [^#]*\)#x#\)\?\)' _cat - | \ sed '1s%^\(/\* SPDX-License-Identifier: LGPL-2.1-only \*/\|\)#x#/\*#x# \* [^#]*#x# \*#x# \*[ ]\+This library is free software; you can redistribute it and/or#x# \*[ ]\+modify it under the terms of the GNU Lesser General Public#x# \*[ ]\+License as published by the Free Software Foundation version 2.1#x# \*[ ]\+of the License.#x# \*#x#'"$COPYRIGHTS"' \*/'"$NEWLINES"'%/\* SPDX-License-Identifier: LGPL-2.1-only \*/#x#/*#x#\2 */#x##x#%' | \ sed '1s%^/\*#x# \* [^#]*#x# \*#x# \*[ ]\+This library is free software; you can redistribute it and/or#x# \*[ ]\+modify it under the terms of the GNU Lesser General Public#x# \*[ ]\+License as published by the Free Software Foundation version 2.1#x# \*[ ]\+of the License.#x# \*/'"$NEWLINES"'%/\* SPDX-License-Identifier: LGPL-2.1-only \*/#x##x#%' | \ sed '1s%^\(\)/\*#x# \* [^#]*#x# \*#x# \*[ ]\+This library is free software; you can redistribute it and/or#x# \*[ ]\+modify it under the terms of the GNU Lesser General Public#x# \*[ ]\+License as published by the Free Software Foundation version 2.1#x# \*[ ]\+of the License.#x# \*#x#'"$COPYRIGHTS"' \*/'"$NEWLINES"'%/\* SPDX-License-Identifier: LGPL-2.1-only \*/#x#/*#x#\2 */#x##x#%' | \ sed '1s%^\(/\* SPDX-License-Identifier: LGPL-2.1-only \*/\|\)#x#/\*#x# \* [^#]*#x# \*#x# \*[ ]\+This library is free software; you can redistribute it and/or#x# \*[ ]\+modify it under the terms of the GNU General Public License as#x# \*[ ]\+published by the Free Software Foundation version 2 of the License.#x# \*#x#'"$COPYRIGHTS"' \*/'"$NEWLINES"'%/\* SPDX-License-Identifier: GPL-2.0-only \*/#x#/*#x#\2 */#x##x#%' } FILES=( $(files_all) ) for f in "${FILES[@]}"; do echo "processing \"$f\"..." in_file "$f" | join | adjust | unjoin | out_file "$f" done
* Add SPDX identifiersYegor Yefremov2019-08-121-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Software Package Data Exchange identifiers help to detect source file licenses and hence simplify the FOSS compliance process. Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com> https://github.com/thom311/libnl/pull/219 --- FILES=( lib/addr.c lib/attr.c lib/cache.c lib/cache_mngr.c lib/cache_mngt.c lib/data.c lib/error.c lib/fib_lookup/lookup.c lib/fib_lookup/request.c lib/genl/ctrl.c lib/genl/family.c lib/genl/genl.c lib/genl/mngt.c lib/handlers.c lib/hash.c lib/hashtable.c lib/idiag/idiag.c lib/idiag/idiag_meminfo_obj.c lib/idiag/idiag_msg_obj.c lib/idiag/idiag_req_obj.c lib/idiag/idiag_vegasinfo_obj.c lib/mpls.c lib/msg.c lib/netfilter/ct.c lib/netfilter/ct_obj.c lib/netfilter/exp.c lib/netfilter/exp_obj.c lib/netfilter/log.c lib/netfilter/log_msg.c lib/netfilter/log_msg_obj.c lib/netfilter/log_obj.c lib/netfilter/netfilter.c lib/netfilter/nfnl.c lib/netfilter/queue.c lib/netfilter/queue_msg.c lib/netfilter/queue_msg_obj.c lib/netfilter/queue_obj.c lib/nl.c lib/object.c lib/route/act.c lib/route/addr.c lib/route/class.c lib/route/classid.c lib/route/cls.c lib/route/link.c lib/route/neigh.c lib/route/neightbl.c lib/route/netconf.c lib/route/nexthop.c lib/route/nexthop_encap.c lib/route/nh_encap_mpls.c lib/route/pktloc.c lib/route/qdisc.c lib/route/route.c lib/route/route_obj.c lib/route/route_utils.c lib/route/rtnl.c lib/route/rule.c lib/route/tc.c lib/socket.c lib/utils.c lib/version.c lib/xfrm/ae.c lib/xfrm/lifetime.c lib/xfrm/sa.c lib/xfrm/selector.c lib/xfrm/sp.c lib/xfrm/template.c src/genl-ctrl-list.c src/idiag-socket-details.c src/lib/addr.c src/lib/class.c src/lib/cls.c src/lib/ct.c src/lib/exp.c src/lib/link.c src/lib/neigh.c src/lib/qdisc.c src/lib/route.c src/lib/rule.c src/lib/tc.c src/lib/utils.c src/nf-ct-add.c src/nf-ct-events.c src/nf-ct-list.c src/nf-exp-add.c src/nf-exp-delete.c src/nf-exp-list.c src/nf-log.c src/nf-monitor.c src/nf-queue.c src/nl-addr-add.c src/nl-addr-delete.c src/nl-addr-list.c src/nl-class-add.c src/nl-class-delete.c src/nl-class-list.c src/nl-classid-lookup.c src/nl-cls-add.c src/nl-cls-delete.c src/nl-cls-list.c src/nl-fib-lookup.c src/nl-link-enslave.c src/nl-link-ifindex2name.c src/nl-link-list.c src/nl-link-name2ifindex.c src/nl-link-release.c src/nl-link-set.c src/nl-link-stats.c src/nl-list-caches.c src/nl-list-sockets.c src/nl-monitor.c src/nl-neigh-add.c src/nl-neigh-delete.c src/nl-neigh-list.c src/nl-neightbl-list.c src/nl-pktloc-lookup.c src/nl-qdisc-add.c src/nl-qdisc-delete.c src/nl-qdisc-list.c src/nl-route-add.c src/nl-route-delete.c src/nl-route-get.c src/nl-route-list.c src/nl-rule-list.c src/nl-tctree-list.c src/nl-util-addr.c ) sed '1s#^#/* SPDX-License-Identifier: LGPL-2.1-only */\n#' "${FILES[@]}" -i
* cache: make "result" output argument for nl_cache_mngr_add() optionalTuetuopay2018-04-111-1/+5
| | | | | | | [thaller@redhat.com: rewritten commit message] https://github.com/thom311/libnl/issues/178 https://github.com/thom311/libnl/pull/183
* lib/cache_mgr.c: remove pointless gotoRasmus Villemoes2017-06-081-2/+0
| | | | | | | | | The only way we can enter the block containing this goto is if i is equal to (the old value of) mngr->cm_nassocs, and that slot is now guaranteed to exist and be vacant after the succesful realloc call, while no earlier slots can have become available [there's no locking involved, so I assume that avoiding concurrent operations on a struct nl_cache_mngr is up to the caller].
* lib/cache_mngr.c: avoid memleak if realloc failsRasmus Villemoes2017-06-081-6/+9
| | | | | | | | | | | | foo = realloc(foo, ...) is almost always a bug - the only exceptions being if (a) one just exits the process in case of failure or (b) if one has made a copy of the foo pointer before the realloc call, and takes care to either reinstate it afterwards or free() it and make sure that the data structure is updated to handle foo now being NULL (in this case for example setting ->cm_nassocs to 0). (a) is not an option in libraries, and (b) is more cumbersome than just doing it the canonical way: use local variables for the new pointer and size, and only install them when realloc succeeds.
* cache_mngr: add include callback v2Tobias Jungel2016-12-011-2/+107
| | | | | | | | | | | | | | | | | | | | | 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
* lib: switch to using strerror_l() instead of strerror_r()André Draszik2016-08-251-3/+2
| | | | | | | | | | | | | | | | | | | | | | | | | glibc provides two versions of strerror_r(), which can be chosen between using feature test macros _GNU_SOURCE and _POSIX_C_SOURCE. libnl is built using the former, hence we get the glibc special version, and all code so far has been written for this. Other C libraries like musl on the other hand only try to be posix compliant, and only ever provide the posix version of strerror_r(), which has a different signature. Uses in libnl hence generally cause printf() of an *int* with a *string format* specifier for that reason. Additionally, strerror_r() has been deprecated: http://austingroupbugs.net/view.php?id=655 Switch to using strerror_l() (via our wrapper just introduced). Signed-off-by: André Draszik <adraszik@tycoint.com> Reviewed-by: Stephane Ayotte <sayotte@tycoint.com> Signed-off-by: Thomas Haller <thaller@redhat.com>
* lib: log errors from platformLubomir Rintel2015-02-171-1/+6
| | | | | | | | | | | | nl_syserr2nlerr() reduces a lot of platform errors to NLE_FAILURE -- "Unspecific failure" which makes it somehow hard to track down the real reason behind a failure. Logging them with level of 4 makes it a little less painful. https://github.com/thom311/libnl/pull/65 Signed-off-by: Thomas Haller <thaller@redhat.com>
* cache_mngr: Fix assignment of error code in nl_cache_mngr_alloc()Tobias Klauser2014-06-171-2/+2
| | | | | | | | | | | In the current form, the parentheses in these two if (...) statements lead to err being assigned the result of nl_connect(...) < 0 and nl_socket_set_nonblocking(...) < 0 instead of the return value of these functions. Adjust the parentheses to assign the returned error code to err. Signed-off-by: Tobias Klauser <tklauser@distanz.ch> Signed-off-by: Thomas Haller <thaller@redhat.com>
* cache_mngr: Return proper error code if nl_socket_alloc() failsTobias Klauser2014-06-171-1/+3
| | | | | | | | | | If nl_socket_alloc() failes in nl_cache_mngr_alloc() we would currently return 0 due to the previous assignment of the err variable, even though the failed allocation is an error condition. Fix this by setting err to -NLE_NOMEM if nl_socket_alloc() fails. Signed-off-by: Tobias Klauser <tklauser@distanz.ch> Signed-off-by: Thomas Haller <thaller@redhat.com>
* lib: reorder free() after printf("%p") statementsThomas Haller2014-06-101-1/+2
| | | | | | | | | | Previously coverity was complaining about a use-after-free. This was not a real problem, because the printf statement does not dereferenciate the pointer. Change it to avoid the warning. Acked-by: Thomas Graf <tgraf@suug.ch> Signed-off-by: Thomas Haller <thaller@redhat.com>
* Handle -NLE_AGAIN in nl_cache_mngr_data_readyAndrew Collins2013-06-261-1/+1
| | | | | | | | | Since commit "nl: Return -NLE_AGAIN if non-blocking socket would block", nl_cache_mngr_data_ready returns -NLE_AGAIN to callers on non-blocking sockets. Change it to consider -NLE_AGAIN as a non-error case as it is expected behavior with the nl_recv changes. Signed-off-by: Thomas Graf <tgraf@suug.ch>
* Move private header files to <netlink-private/*>Thomas Graf2013-01-241-1/+1
| | | | | | | This clarifies the seperation between public and private header files. Signed-off-by: Thomas Graf <tgraf@suug.ch>
* Bug Fix: Add new fill socket to cache managerroopa2012-11-191-1/+15
| | | | | | | | | | | | | | | | | | | | | | | | | This patch adds a new socket to cache manager to request fill's on. cache manager today uses cm_sock to request dump from the kernel. It also listens to netlink async events on the same sock. The problem with this is that when libnl is waiting to process the response to get dump request sent to the kernel during fill, it may receive an async event, resulting in libnl complaining about unexpected msg This is usually reproducible when there is heavy netlink async event traffic during nl_cache_mngr_add. This patch adds a new cm_sync_sock to use for fill during cache manager add cache. The other option is to provide an api to set the cm_sync_sock. But since this is a bug fix its probably better to fix the cache manager add api like this patch does. Please suggest otherwise. Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com> Reviewed-by: Nolan Leake <nolan@cumulusnetworks.com> Reviewed-by: Shrijeet Mukherjee <shm@cumulusnetworks.com> Signed-off-by: Thomas Graf <tgraf@suug.ch>
* use safe cache lookup variants internallyThomas Graf2012-11-151-1/+2
| | | | Signed-off-by: Thomas Graf <tgraf@suug.ch>
* New cache manager add cache apiroopa2012-11-121-21/+65
| | | | | | | | | | | | | | | | | | | This patch is an attempt to add a new nl_cache_mngr_add_cache api to allow adding an existing cache to cache manager. Since the new api is similar to nl_cache_mngr_add except for allocating the cache, the patch moves most of the nl_cache_mngr_add code to nl_cache_mngr_add_cache and changes nl_cache_mngr_add to call nl_cache_mngr_add_cache. One use case for this api as pointed out by thomas would be to set cache flags before associating the cache with a cache manager. nl_cache_alloc_name("route/link", &cache); nl_cache_set_flags(cache, NL_CACHE_AF_ITER); nl_cache_mngr_add_cache(mngr, cache, ...); Signed-off-by: Thomas Graf <tgraf@suug.ch>
* doc: documentation restructuringThomas Graf2012-05-101-1/+16
| | | | | | | | | | - changes the modules hierarchy to better represent the set of libaries - list the header file that needs to be included - remove examples/doc from api ref that is included in the guide - add references to the guide - fix doxygen api linking for version 1.8.0 - readd doxygen mainpage to config file - fix a couple of doxygen doc bugs
* nl: Fix return value of nl_recvmsgs()Thomas Graf2012-05-081-1/+1
| | | | | | | | | | | | Apparently the change to have nl_recvmsgs() return the number of parsed messages broke nl_wait_for_ack() among other applications. This patch reverts to the old behaviour and provides a new function nl_recvmsgs_report() which provides the additional information for use by the cache manager and possibly other applications. Reported-by: Scott Bonar <sbonar@cradlepoint.com> Signed-off-by: Thomas Graf <tgraf@redhat.com>
* cache: Add co_include_event allowing caches to provide their own ↵Thomas Graf2012-04-221-1/+5
| | | | nl_cache_include() implementation
* cache_mngr: Make providing the result pointer to nl_cache_mngr_add() optionalThomas Graf2012-04-211-2/+3
|
* cache_mngr: Provide nl_cache_mngr_info() to pring cache manager detailsThomas Graf2012-04-211-0/+42
| | | | Useful for debugging and testing
* cache_mngr: API doc updatesThomas Graf2012-04-211-12/+30
|
* cache_mngr: Let nl_cache_mngr_data_ready() read multiple messagesThomas Graf2012-04-211-3/+8
| | | | | | Having nl_recvmsgs() return the number of read messages allows to continue reading until the underlying recvmsg() will return EAGAIN for the non blocking socket.
* cache_mngr: Fix memory corruption after resizingThomas Graf2012-04-211-7/+12
| | | | | | | | | | | | | | The reallocated part of the enlarged association array was left uninitialized which would have resulted in trying to free random pointers. This was a theoretical bug because it wasn't possible to register more than 32 cache types since no netlink family supports that many individual cache types. Nevertheless this patch fixes the bug and also reduces the default size of the allocation table and expandations a bit to reduce the memory footprint slightly.
* cache_mngr: Automatically allocate socket if neededThomas Graf2012-04-211-22/+53
| | | | | | | | | | | The requirement to have the caller provide the socket does not make much sense. Automatically allocate the socket if none was provided. This may also avoid some future abuse of reusing request sockets for handling notifications. Also rename cm_handle to cm_sock for clarity (no API change)
* cache_manager: Move documentation to doc/core.txtThomas Graf2012-04-211-65/+1
|
* cache_mngr: Don't modify callback setup of socketThomas Graf2012-04-211-4/+12
| | | | | | | Instead, clone it and modify a temporary copy. Although it is not recommended to use the same socket for requests and to serve a cache manager, this change might prevent some unwanted side effects if done so.
* cache_mngr: document uncommon error codesThomas Graf2012-04-211-0/+5
|
* avoid dangling co_major_cache reference to NL_AUTO_PROVIDE cachesAlexander Sack2012-01-111-2/+5
|
* cache: event_filter() cache operation to filter notificationsThomas Graf2011-10-211-0/+6
| | | | | Certain notifications need to be filtered out and should not be applied to a cache when a cache is handled by a cache manager.
* Documentation updatesThomas Graf2011-03-211-1/+3
| | | | Mostly killing doxygen warnings, some doc updates to caching
* add user data to change_func_t for cachesAndreas Fett2010-10-131-2/+3
| | | | | | | | | | | the patch below adds the possibility to pass user data to callbacks of type change_func_t when using the nl_cache_mngr_* family of functions. If there is any better way to do this, without duplicating the code in cache_mngr.c please let me know.
* Fix up naming changesThomas Graf2008-12-101-1/+1
|
* Rename struct nl_handle to struct nl_sockThomas Graf2008-05-151-4/+4
| | | | | | | | The idea of a common handle is long revised and only misleading, nl_handle really represents a socket with some additional action handlers assigned to it. Alias for nl_handle is kept for backwards compatibility.
* Thread-safe error handlingThomas Graf2008-05-141-44/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In order for the interface to become more thread safe, the error handling was revised to no longer depend on a static errno and error string buffer. This patch converts all error paths to return a libnl specific error code which can be translated to a error message using nl_geterror(int error). The functions nl_error() and nl_get_errno() are therefore obsolete. This change required various sets of function prototypes to be changed in order to return an error code, the most prominent are: struct nl_cache *foo_alloc_cache(...); changed to: int foo_alloc_cache(..., struct nl_cache **); struct nl_msg *foo_build_request(...); changed to: int foo_build_request(..., struct nl_msg **); struct foo *foo_parse(...); changed to: int foo_parse(..., struct foo **); This pretty much only leaves trivial allocation functions to still return a pointer object which can still return NULL to signal out of memory. This change is a serious API and ABI breaker, sorry!
* Free associated caches when freeing cache managerThomas Graf2008-02-051-5/+9
| | | | | | Caches allocated by the cache manager must be freed again when the cache manager itself is freed. However, the netlink socket is allocated indepdently so it should not be freed.
* Fix documentation of cache manager.Thomas Graf2008-01-141-0/+2
|
* Fix cache manager to not give back a reference it does not ownThomas Graf2007-12-171-6/+1
|
* Initial importThomas Graf2007-09-141-0/+392