libnl  3.2.14
Manager

Manager keeping caches up to date automatically. More...


Detailed Description

Manager keeping caches up to date automatically.

The cache manager keeps caches up to date automatically by listening to netlink notifications and integrating the received information into the existing cache.

Note:
This functionality is still considered experimental.

Related sections in the development guide:

Header

#include <netlink/cache.h>

Functions

int nl_cache_mngr_alloc (struct nl_sock *sk, int protocol, int flags, struct nl_cache_mngr **result)
 Allocate new cache manager.
int nl_cache_mngr_add (struct nl_cache_mngr *mngr, const char *name, change_func_t cb, void *data, struct nl_cache **result)
 Add cache responsibility to cache manager.
int nl_cache_mngr_get_fd (struct nl_cache_mngr *mngr)
 Get socket file descriptor.
int nl_cache_mngr_poll (struct nl_cache_mngr *mngr, int timeout)
 Check for event notifications.
int nl_cache_mngr_data_ready (struct nl_cache_mngr *mngr)
 Receive available event notifications.
void nl_cache_mngr_info (struct nl_cache_mngr *mngr, struct nl_dump_params *p)
 Print information about cache manager.
void nl_cache_mngr_free (struct nl_cache_mngr *mngr)
 Free cache manager and all caches.

Function Documentation

int nl_cache_mngr_alloc ( struct nl_sock *  sk,
int  protocol,
int  flags,
struct nl_cache_mngr **  result 
)

Allocate new cache manager.

Parameters:
skNetlink socket or NULL to auto allocate
protocolNetlink protocol this manager is used for
flagsFlags (NL_AUTO_PROVIDE)
resultResult pointer

Allocates a new cache manager for the specified netlink protocol.

  1. If sk is not specified (NULL) a netlink socket matching the specified protocol will be automatically allocated.
  1. The socket will be put in non-blocking mode and sequence checking will be disabled regardless of whether the socket was provided by the caller or automatically allocated.
  1. The socket will be connected.

If the flag NL_AUTO_PROVIDE is specified, any cache added to the manager will automatically be made available to other users using nl_cache_mngt_provide().

Note:
If the socket is provided by the caller, it is NOT recommended to use the socket for anything else besides receiving netlink notifications.
Returns:
0 on success or a negative error code.

Definition at line 135 of file cache_mngr.c.

References nl_cache_mngr_free(), nl_connect(), nl_socket_alloc(), nl_socket_disable_seq_check(), and nl_socket_set_nonblocking().

+ Here is the call graph for this function:

int nl_cache_mngr_add ( struct nl_cache_mngr *  mngr,
const char *  name,
change_func_t  cb,
void *  data,
struct nl_cache **  result 
)

Add cache responsibility to cache manager.

Parameters:
mngrCache manager.
nameName of cache to keep track of
cbFunction to be called upon changes.
dataArgument passed on to change callback
resultPointer to store added cache (optional)

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 and keep track of any further changes.

The user is responsible for calling nl_cache_mngr_poll() or monitor the socket and call nl_cache_mngr_data_ready() to allow the library to process netlink notification events.

See also:
nl_cache_mngr_poll()
nl_cache_mngr_data_ready()
Returns:
0 on success or a negative error code.
-NLE_NOCACHE Unknown cache type
-NLE_PROTO_MISMATCH Protocol mismatch between cache manager and cache type
-NLE_OPNOTSUPP Cache type does not support updates
-NLE_EXIST Cache of this type already being managed

Definition at line 213 of file cache_mngr.c.

References nl_af_group::ag_group, nl_cache_ops::co_groups, nl_cache_ops::co_protocol, nl_cache_alloc(), nl_cache_free(), nl_cache_mngt_provide(), nl_cache_ops_lookup(), and nl_cache_refill().

+ Here is the call graph for this function:

int nl_cache_mngr_get_fd ( struct nl_cache_mngr *  mngr)

Get socket file descriptor.

Parameters:
mngrCache Manager

Get the file descriptor of the socket associated with the manager.

Note:
Do not use the socket for anything besides receiving notifications.

Definition at line 303 of file cache_mngr.c.

int nl_cache_mngr_poll ( struct nl_cache_mngr *  mngr,
int  timeout 
)

Check for event notifications.

Parameters:
mngrCache Manager
timeoutUpper limit poll() will block, in milliseconds.

Causes poll() to be called to check for new event notifications being available. Calls nl_cache_mngr_data_ready() to process available data.

This functionally is ideally called regularly during an idle period.

A timeout can be specified in milliseconds to limit the time the function will wait for updates.

See also:
nl_cache_mngr_data_ready()
Returns:
The number of messages processed or a negative error code.

Definition at line 327 of file cache_mngr.c.

References nl_cache_mngr_data_ready().

+ Here is the call graph for this function:

int nl_cache_mngr_data_ready ( struct nl_cache_mngr *  mngr)

Receive available event notifications.

Parameters:
mngrCache manager

This function can be called if the socket associated to the manager contains updates to be received. This function should only be used if nl_cache_mngr_poll() is not used.

The function will process messages until there is no more data to be read from the socket.

See also:
nl_cache_mngr_poll()
Returns:
The number of messages processed or a negative error code.

Definition at line 363 of file cache_mngr.c.

References nl_cb_clone(), NL_CB_CUSTOM, nl_cb_set(), NL_CB_VALID, and nl_recvmsgs_report().

Referenced by nl_cache_mngr_poll().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void nl_cache_mngr_info ( struct nl_cache_mngr *  mngr,
struct nl_dump_params p 
)

Print information about cache manager.

Parameters:
mngrCache manager
pDumping parameters

Prints information about the cache manager including all managed caches.

Note:
This is a debugging function.

Definition at line 399 of file cache_mngr.c.

References nl_dump_params::dp_prefix, nl_cache_dump(), and nl_cache_nitems().

+ Here is the call graph for this function:

void nl_cache_mngr_free ( struct nl_cache_mngr *  mngr)

Free cache manager and all caches.

Parameters:
mngrCache manager.

Release all resources held by a cache manager.

Definition at line 438 of file cache_mngr.c.

References nl_cache_free(), nl_cache_mngt_unprovide(), nl_close(), and nl_socket_free().

Referenced by nl_cache_mngr_alloc().

+ Here is the call graph for this function:

+ Here is the caller graph for this function: