Caching
[Utilities]


Detailed Description

   Cache Management             |    | Type Specific Cache Operations
                                      
                                |    | +----------------+ +------------+
                                       | request update | | msg_parser |
                                |    | +----------------+ +------------+
                                     +- - - - -^- - - - - - - -^- -|- - - -
    nl_cache_update:            |              |               |   |
          1) --------- co_request_update ------+               |   |
                                |                              |   |
          2) destroy old cache     +----------- pp_cb ---------|---+
                                |  |                           |
          3) ---------- nl_recvmsgs ----------+   +- cb_valid -+
             +--------------+   |  |          |   |
             | nl_cache_add |<-----+   + - - -v- -|- - - - - - - - - - -
             +--------------+   |      | +-------------+
                                         | nl_recvmsgs |
                                |      | +-----|-^-----+
                                           +---v-|---+
                                |      |   | nl_recv |
                                           +---------+
                                |      |                 Core Netlink


Modules

 Cacheable Object

Access Functions

int nl_cache_nitems (struct nl_cache *cache)
 Return the number of items in the cache.
int nl_cache_nitems_filter (struct nl_cache *cache, struct nl_object *filter)
 Return the number of items matching a filter in the cache.
int nl_cache_is_empty (struct nl_cache *cache)
 Returns true if the cache is empty.
nl_cache_ops * nl_cache_get_ops (struct nl_cache *cache)
 Return the operations set of the cache.
nl_object * nl_cache_get_first (struct nl_cache *cache)
 Return the first element in the cache.
nl_object * nl_cache_get_last (struct nl_cache *cache)
 Return the last element in the cache.
nl_object * nl_cache_get_next (struct nl_object *obj)
 Return the next element in the cache.
nl_object * nl_cache_get_prev (struct nl_object *obj)
 Return the previous element in the cache.

Cache Creation/Deletion

nl_cache * nl_cache_alloc (void)
 Allocate an empty cache of no certain type.
nl_cache * nl_cache_alloc_from_ops (struct nl_cache_ops *ops)
 Allocate an empty cache based on cache operations.
nl_cache * nl_cache_alloc_name (const char *kind)
 Allocate an empty cache based on type name.
void nl_cache_clear (struct nl_cache *cache)
 Clear a cache.
void nl_cache_free (struct nl_cache *cache)
 Free a cache.

Cache Modifications

int nl_cache_add (struct nl_cache *cache, struct nl_object *obj)
 Add an element to the cache.
int nl_cache_parse_and_add (struct nl_cache *cache, struct nl_msg *msg)
 Parse a netlink message and add it to the cache.
void nl_cache_delete (struct nl_cache *cache, struct nl_object *obj)
 Delete an element from a cache.
int nl_cache_pickup (struct nl_handle *handle, struct nl_cache *cache)
 Pickup a netlink dump response and put it into a cache.
int nl_cache_update (struct nl_handle *handle, struct nl_cache *cache)
 Update (synchronize) a local cache with the kernel.

Dumping

void nl_cache_dump (struct nl_cache *cache, struct nl_dump_params *params)
 Dump all elements of a cache.
void nl_cache_dump_filter (struct nl_cache *cache, struct nl_dump_params *params, struct nl_object *filter)
 Dump all elements of a cache (filtered).

Iterators

void nl_cache_foreach (struct nl_cache *cache, void(*cb)(struct nl_object *, void *), void *arg)
 Call a callback on each element of the cache.
void nl_cache_foreach_filter (struct nl_cache *cache, struct nl_object *filter, void(*cb)(struct nl_object *, void *), void *arg)
 Call a callback on each element of the cache (filtered).


Function Documentation

int nl_cache_nitems ( struct nl_cache *  cache  ) 

Return the number of items in the cache.

Parameters:
cache cache handle

Definition at line 63 of file cache.c.

int nl_cache_nitems_filter ( struct nl_cache *  cache,
struct nl_object *  filter 
)

Return the number of items matching a filter in the cache.

Parameters:
cache Cache object.
filter Filter object.

Definition at line 73 of file cache.c.

int nl_cache_is_empty ( struct nl_cache *  cache  ) 

Returns true if the cache is empty.

Parameters:
cache Cache to check
Returns:
true if the cache is empty, otherwise false is returned.

Definition at line 94 of file cache.c.

struct nl_cache_ops* nl_cache_get_ops ( struct nl_cache *  cache  ) 

Return the operations set of the cache.

Parameters:
cache cache handle

Definition at line 103 of file cache.c.

struct nl_object* nl_cache_get_first ( struct nl_cache *  cache  ) 

Return the first element in the cache.

Parameters:
cache cache handle

Definition at line 112 of file cache.c.

struct nl_object* nl_cache_get_last ( struct nl_cache *  cache  ) 

Return the last element in the cache.

Parameters:
cache cache handle

Definition at line 125 of file cache.c.

struct nl_object* nl_cache_get_next ( struct nl_object *  obj  ) 

Return the next element in the cache.

Parameters:
obj current object

Definition at line 138 of file cache.c.

struct nl_object* nl_cache_get_prev ( struct nl_object *  obj  ) 

Return the previous element in the cache.

Parameters:
obj current object

Definition at line 151 of file cache.c.

struct nl_cache* nl_cache_alloc ( void   ) 

Allocate an empty cache of no certain type.

Returns:
A newly allocated and initialized cache.

Definition at line 172 of file cache.c.

Referenced by nl_cache_alloc_from_ops().

struct nl_cache* nl_cache_alloc_from_ops ( struct nl_cache_ops *  ops  ) 

Allocate an empty cache based on cache operations.

Parameters:
ops cache operations to base the cache on
Returns:
A newly allocated and initialized cache.

Definition at line 193 of file cache.c.

References nl_cache_alloc().

Referenced by flnl_result_alloc_cache(), nl_cache_alloc_name(), rtnl_addr_alloc_cache(), rtnl_class_alloc_cache(), rtnl_cls_alloc_cache(), rtnl_link_alloc_cache(), rtnl_neigh_alloc_cache(), rtnl_neightbl_alloc_cache(), rtnl_qdisc_alloc_cache(), rtnl_route_alloc_cache(), and rtnl_rule_alloc_cache_by_family().

struct nl_cache* nl_cache_alloc_name ( const char *  kind  ) 

Allocate an empty cache based on type name.

Parameters:
kind Name of cache type
Returns:
A newly allocated and initialized cache.

Definition at line 211 of file cache.c.

References nl_cache_alloc_from_ops(), and nl_cache_mngt_lookup().

void nl_cache_clear ( struct nl_cache *  cache  ) 

Clear a cache.

Parameters:
cache cache to clear
Removes all elements of a cache.

Definition at line 230 of file cache.c.

References nl_cache_delete().

Referenced by nl_cache_free(), and nl_cache_update().

void nl_cache_free ( struct nl_cache *  cache  ) 

Free a cache.

Parameters:
cache Cache to free.
Removes all elements of a cache and frees all memory.

Note:
Use this function if you are working with allocated caches.

Definition at line 248 of file cache.c.

References nl_cache_clear().

Referenced by rtnl_addr_alloc_cache(), rtnl_class_alloc_cache(), rtnl_cls_alloc_cache(), rtnl_link_alloc_cache(), rtnl_neigh_alloc_cache(), rtnl_neightbl_alloc_cache(), and rtnl_qdisc_alloc_cache().

int nl_cache_add ( struct nl_cache *  cache,
struct nl_object *  obj 
)

Add an element to the cache.

Parameters:
cache cache to add a element to
obj Common obj to be added to the cache
Adds the object obj to the tail of the cache cache and. The cache is enlarged as needed.

Returns:
0 or a negative error code.

Definition at line 272 of file cache.c.

References nl_object_clone(), nl_object_put(), and nl_object_shared().

int nl_cache_parse_and_add ( struct nl_cache *  cache,
struct nl_msg *  msg 
)

Parse a netlink message and add it to the cache.

Parameters:
cache cache to add element to
msg netlink message
Parses a netlink message by calling the cache specific message parser and adds the new element to the cache.

Returns:
0 or a negative error code.

Definition at line 336 of file cache.c.

References nlmsg_hdr().

void nl_cache_delete ( struct nl_cache *  cache,
struct nl_object *  obj 
)

Delete an element from a cache.

Parameters:
cache cache to delete the element from
obj Object to delete
Deletes the object obj from the cache cache.

Definition at line 353 of file cache.c.

References nl_object_put().

Referenced by nl_cache_clear().

int nl_cache_pickup ( struct nl_handle *  handle,
struct nl_cache *  cache 
)

Pickup a netlink dump response and put it into a cache.

Parameters:
handle Netlink handle.
cache Cache to put items into.
Waits for netlink messages to arrive, parses them and puts them into the specified cache.

Returns:
0 on success or a negative error code.

Definition at line 391 of file cache.c.

References nl_cb_clone(), NL_CB_CUSTOM, nl_cb_destroy(), nl_cb_set(), NL_CB_VALID, nl_geterror(), nl_handle_get_cb(), and nl_recvmsgs().

Referenced by flnl_lookup(), and nl_cache_update().

int nl_cache_update ( struct nl_handle *  handle,
struct nl_cache *  cache 
)

Update (synchronize) a local cache with the kernel.

Parameters:
handle netlink handle
cache cache to update
Updates the local cache cache with the state in the kernel. During this process the cache gets emptied and refilled with the new content received from the kernel.

Returns:
0 or a negative error code.

Definition at line 432 of file cache.c.

References nl_cache_clear(), and nl_cache_pickup().

Referenced by rtnl_addr_alloc_cache(), rtnl_class_alloc_cache(), rtnl_cls_alloc_cache(), rtnl_link_alloc_cache(), rtnl_neigh_alloc_cache(), rtnl_neightbl_alloc_cache(), rtnl_qdisc_alloc_cache(), rtnl_route_alloc_cache(), and rtnl_rule_alloc_cache_by_family().

void nl_cache_dump ( struct nl_cache *  cache,
struct nl_dump_params params 
)

Dump all elements of a cache.

Parameters:
cache cache to dump
params dumping parameters
Dumps all elements of the cache to the file descriptor fd.

Definition at line 462 of file cache.c.

References nl_cache_dump_filter().

void nl_cache_dump_filter ( struct nl_cache *  cache,
struct nl_dump_params params,
struct nl_object *  filter 
)

Dump all elements of a cache (filtered).

Parameters:
cache cache to dump
params dumping parameters (optional)
filter filter object
Dumps all elements of the cache to the file descriptor fd given they match the given filter filter.

Definition at line 477 of file cache.c.

References nl_dump_params::dp_type, and NL_DUMP_FULL.

Referenced by nl_cache_dump().

void nl_cache_foreach ( struct nl_cache *  cache,
void(*)(struct nl_object *, void *)  cb,
void *  arg 
)

Call a callback on each element of the cache.

Parameters:
cache cache to iterate on
cb callback function
arg argument passed to callback function
Calls a callback function cb on each element of the cache. The argument arg is passed on the callback function.

Definition at line 518 of file cache.c.

References nl_cache_foreach_filter().

void nl_cache_foreach_filter ( struct nl_cache *  cache,
struct nl_object *  filter,
void(*)(struct nl_object *, void *)  cb,
void *  arg 
)

Call a callback on each element of the cache (filtered).

Parameters:
cache cache to iterate on
filter filter object
cb callback function
arg argument passed to callback function
Calls a callback function cb on each element of the cache that matches the filter. The argument arg is passed on to the callback function.

Definition at line 535 of file cache.c.

Referenced by nl_cache_foreach(), rtnl_class_foreach_child(), rtnl_class_foreach_cls(), rtnl_qdisc_foreach_child(), and rtnl_qdisc_foreach_cls().


Generated on Fri Apr 27 14:14:07 2007 for libnl by  doxygen 1.5.1