Helps keeping caches up to date. More...
Functions | |
int | nl_cache_mngr_alloc (struct nl_sock *sk, int protocol, int flags, struct nl_cache_mngr **result) |
Allocate new cache manager. More... | |
int | nl_cache_mngr_add (struct nl_cache_mngr *mngr, const char *name, change_func_t cb, struct nl_cache **result) |
Add cache responsibility to cache manager. More... | |
int | nl_cache_mngr_get_fd (struct nl_cache_mngr *mngr) |
Get file descriptor. More... | |
int | nl_cache_mngr_poll (struct nl_cache_mngr *mngr, int timeout) |
Check for event notifications. More... | |
int | nl_cache_mngr_data_ready (struct nl_cache_mngr *mngr) |
Receive available event notifications. More... | |
void | nl_cache_mngr_free (struct nl_cache_mngr *mngr) |
Free cache manager and all caches. More... | |
Helps keeping caches up to date.
The purpose of a cache manager is to keep track of caches and automatically receive event notifications to keep the caches up to date with the kernel state. Each manager has exactly one netlink socket assigned which limits the scope of each manager to exactly one netlink family. Therefore all caches committed to a manager must be part of the same netlink family. Due to the nature of a manager, it is not possible to have a cache maintain two instances of the same cache type. The socket is subscribed to the event notification group of each cache and also put into non-blocking mode. Functions exist to poll() on the socket to wait for new events to be received.
int nl_cache_mngr_add | ( | struct nl_cache_mngr * | mngr, |
const char * | name, | ||
change_func_t | cb, | ||
struct nl_cache ** | result | ||
) |
Add cache responsibility to cache manager.
Allocates a new cache of the specified type and adds it to the manager. The operation will trigger a full dump request from the kernel to initially fill the contents of the cache. The manager will subscribe to the notification group of the cache to keep track of any further changes.
References nl_af_group::ag_group, nl_cache::c_ops, nl_cache_assoc::ca_cache, nl_cache_assoc::ca_change, nl_cache_mngr::cm_assocs, nl_cache_mngr::cm_flags, nl_cache_mngr::cm_handle, nl_cache_mngr::cm_nassocs, nl_cache_mngr::cm_protocol, nl_cache_ops::co_groups, nl_cache_ops::co_protocol, NL_AUTO_PROVIDE, nl_cache_alloc(), nl_cache_free(), nl_cache_mngt_provide(), nl_cache_ops_lookup(), nl_cache_refill(), NL_DBG, nl_socket_add_membership(), nl_socket_drop_membership(), NLE_EXIST, NLE_NOCACHE, NLE_NOMEM, NLE_OPNOTSUPP, NLE_PROTO_MISMATCH, and NULL.
int nl_cache_mngr_alloc | ( | struct nl_sock * | sk, |
int | protocol, | ||
int | flags, | ||
struct nl_cache_mngr ** | result | ||
) |
Allocate new cache manager.
References BUG, nl_cache_mngr::cm_assocs, nl_cache_mngr::cm_flags, nl_cache_mngr::cm_handle, nl_cache_mngr::cm_nassocs, nl_cache_mngr::cm_protocol, flags, nl_cache_mngr_free(), NL_CB_CUSTOM, NL_CB_VALID, nl_connect(), NL_DBG, nl_socket_disable_seq_check(), nl_socket_modify_cb(), nl_socket_set_nonblocking(), NLE_NOMEM, and NULL.
int nl_cache_mngr_data_ready | ( | struct nl_cache_mngr * | mngr | ) |
Receive available event notifications.
This function can be called if the socket associated to the manager contains updates to be received. This function should not be used if nl_cache_mngr_poll() is used.
References nl_cache_mngr::cm_handle, and nl_recvmsgs_default().
Referenced by nl_cache_mngr_poll().
void nl_cache_mngr_free | ( | struct nl_cache_mngr * | mngr | ) |
Free cache manager and all caches.
Release all resources after usage of a cache manager.
References nl_cache_assoc::ca_cache, nl_cache_mngr::cm_assocs, nl_cache_mngr::cm_handle, nl_cache_mngr::cm_nassocs, nl_cache_free(), nl_close(), and NL_DBG.
Referenced by nl_cache_mngr_alloc().
int nl_cache_mngr_get_fd | ( | struct nl_cache_mngr * | mngr | ) |
Get file descriptor.
Get the file descriptor of the socket associated to the manager. This can be used to change socket options or monitor activity using poll()/select().
References nl_cache_mngr::cm_handle, and nl_socket_get_fd().
int nl_cache_mngr_poll | ( | struct nl_cache_mngr * | mngr, |
int | timeout | ||
) |
Check for event notifications.
Causes poll() to be called to check for new event notifications being available. Automatically receives and handles available notifications.
This functionally is ideally called regularly during an idle period.
References nl_cache_mngr::cm_handle, nl_cache_mngr_data_ready(), NL_DBG, nl_socket_get_fd(), and nl_syserr2nlerr().