netfilter
firewalling, NAT, and packet mangling for linux
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Cache
Collaboration diagram for Cache:

Modules

 Cache Implementation
 
 Object
 

Access Functions

int nl_cache_nitems (struct nl_cache *cache)
 Return the number of items in the cache. More...
 
int nl_cache_nitems_filter (struct nl_cache *cache, struct nl_object *filter)
 Return the number of items matching a filter in the cache. More...
 
int nl_cache_is_empty (struct nl_cache *cache)
 Returns true if the cache is empty. More...
 
struct nl_cache_opsnl_cache_get_ops (struct nl_cache *cache)
 Return the operations set of the cache. More...
 
struct nl_objectnl_cache_get_first (struct nl_cache *cache)
 Return the first element in the cache. More...
 
struct nl_objectnl_cache_get_last (struct nl_cache *cache)
 Return the last element in the cache. More...
 
struct nl_objectnl_cache_get_next (struct nl_object *obj)
 Return the next element in the cache. More...
 
struct nl_objectnl_cache_get_prev (struct nl_object *obj)
 Return the previous element in the cache. More...
 

Cache Creation/Deletion

struct nl_cachenl_cache_alloc (struct nl_cache_ops *ops)
 Allocate an empty cache. More...
 
int nl_cache_alloc_and_fill (struct nl_cache_ops *ops, struct nl_sock *sock, struct nl_cache **result)
 
int nl_cache_alloc_name (const char *kind, struct nl_cache **result)
 Allocate an empty cache based on type name. More...
 
struct nl_cachenl_cache_subset (struct nl_cache *orig, struct nl_object *filter)
 Allocate a new cache containing a subset of a cache. More...
 
void nl_cache_clear (struct nl_cache *cache)
 Clear a cache. More...
 
void nl_cache_free (struct nl_cache *cache)
 Free a cache. More...
 

Cache Modifications

int nl_cache_add (struct nl_cache *cache, struct nl_object *obj)
 Add object to a cache. More...
 
int nl_cache_move (struct nl_cache *cache, struct nl_object *obj)
 Move object from one cache to another. More...
 
void nl_cache_remove (struct nl_object *obj)
 Removes an object from a cache. More...
 
struct nl_objectnl_cache_search (struct nl_cache *cache, struct nl_object *needle)
 Search for an object in a cache. More...
 

Synchronization

int nl_cache_request_full_dump (struct nl_sock *sk, struct nl_cache *cache)
 Request a full dump from the kernel to fill a cache. More...
 
int __cache_pickup (struct nl_sock *sk, struct nl_cache *cache, struct nl_parser_param *param)
 
int nl_cache_pickup (struct nl_sock *sk, struct nl_cache *cache)
 Pickup a netlink dump response and put it into a cache. More...
 
int nl_cache_include (struct nl_cache *cache, struct nl_object *obj, change_func_t change_cb)
 
int nl_cache_resync (struct nl_sock *sk, struct nl_cache *cache, change_func_t change_cb)
 

Parsing

int nl_cache_parse_and_add (struct nl_cache *cache, struct nl_msg *msg)
 Parse a netlink message and add it to the cache. More...
 
int nl_cache_refill (struct nl_sock *sk, struct nl_cache *cache)
 (Re)fill a cache with the contents in the kernel. More...
 

Utillities

void nl_cache_mark_all (struct nl_cache *cache)
 Mark all objects in a cache. More...
 

Dumping

void nl_cache_dump (struct nl_cache *cache, struct nl_dump_params *params)
 Dump all elements of a cache. More...
 
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). More...
 

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. More...
 
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). More...
 

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- -|- - - - - - - - - - -
+--------------+ | | +-------------+
| | +-----|-^-----+
+---v-|---+
| | | nl_recv |
+---------+
| | Core Netlink

Function Documentation

int __cache_pickup ( struct nl_sock sk,
struct nl_cache cache,
struct nl_parser_param param 
)

References nl_cache::c_ops, nl_cb_clone(), NL_CB_CUSTOM, nl_cb_put(), nl_cb_set(), NL_CB_VALID, NL_DBG, nl_geterror(), nl_recvmsgs(), NLE_NOMEM, NULL, and nl_sock::s_cb.

Referenced by nl_cache_pickup(), and nl_cache_resync().

Here is the call graph for this function:

Here is the caller graph for this function:

int nl_cache_add ( struct nl_cache cache,
struct nl_object obj 
)

Add object to a cache.

  • cache Cache to add object to
  • obj Object to be added to the cache

Adds the given object to the specified cache. The object is cloned if it has been added to another cache already.

Returns
0 or a negative error code.

References nl_cache::c_ops, nl_cache_ops::co_obj_ops, nl_object_clone(), nl_object_get(), NLE_NOMEM, and NLE_OBJ_MISMATCH.

Referenced by nl_cache_subset().

Here is the call graph for this function:

Here is the caller graph for this function:

int nl_cache_alloc_and_fill ( struct nl_cache_ops ops,
struct nl_sock sock,
struct nl_cache **  result 
)
int nl_cache_alloc_name ( const char *  kind,
struct nl_cache **  result 
)

Allocate an empty cache based on type name.

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

References nl_cache_alloc(), nl_cache_ops_lookup(), NLE_NOCACHE, and NLE_NOMEM.

Here is the call graph for this function:

void nl_cache_clear ( struct nl_cache cache)

Clear a cache.

  • cache cache to clear

Removes all elements of a cache.

References nl_cache::c_items, nl_cache_remove(), NL_DBG, and nl_list_for_each_entry_safe.

Referenced by nl_cache_free(), and nl_cache_refill().

Here is the call graph for this function:

Here is the caller graph for this function:

void nl_cache_dump ( struct nl_cache cache,
struct nl_dump_params params 
)

Dump all elements of a cache.

  • cache cache to dump
  • params dumping parameters

Dumps all elements of the cache to the file descriptor fd.

References nl_cache_dump_filter(), and NULL.

Referenced by main().

Here is the call graph for this function:

Here is the caller graph for this function:

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).

  • 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.

References BUG, nl_cache::c_items, nl_cache::c_ops, nl_cache_ops::co_obj_ops, nl_dump_params::dp_type, dump_from_ops(), NL_DBG, NL_DUMP_DETAILS, NL_DUMP_MAX, nl_list_for_each_entry, nl_object_match_filter(), NULL, and nl_object_ops::oo_dump.

Referenced by main(), and nl_cache_dump().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

  • 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.

References nl_cache_foreach_filter(), and NULL.

Referenced by main().

Here is the call graph for this function:

Here is the caller graph for this function:

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).

  • 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.

References BUG, nl_cache::c_items, nl_cache::c_ops, nl_cache_ops::co_obj_ops, nl_list_for_each_entry_safe, nl_object_match_filter(), and NULL.

Referenced by nl_cache_foreach().

Here is the call graph for this function:

Here is the caller graph for this function:

void nl_cache_free ( struct nl_cache cache)

Free a cache.

  • 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.

References nl_cache_clear(), and NL_DBG.

Referenced by genl_ctrl_resolve(), genl_mngt_resolve(), genl_ops_resolve(), main(), nl_cache_alloc_and_fill(), nl_cache_mngr_add(), nl_cache_mngr_free(), rtnl_class_alloc_cache(), and rtnl_cls_alloc_cache().

Here is the call graph for this function:

Here is the caller graph for this function:

struct nl_object* nl_cache_get_first ( struct nl_cache cache)

Return the first element in the cache.

  • cache cache handle

References nl_cache::c_items, nl_list_head::next, nl_list_entry, and NULL.

struct nl_object* nl_cache_get_last ( struct nl_cache cache)

Return the last element in the cache.

  • cache cache handle

References nl_cache::c_items, nl_list_entry, NULL, and nl_list_head::prev.

struct nl_object* nl_cache_get_next ( struct nl_object obj)

Return the next element in the cache.

  • obj current object

References nl_list_at_tail, nl_list_entry, and NULL.

struct nl_cache_ops* nl_cache_get_ops ( struct nl_cache cache)

Return the operations set of the cache.

  • cache cache handle

References nl_cache::c_ops.

struct nl_object* nl_cache_get_prev ( struct nl_object obj)

Return the previous element in the cache.

  • obj current object

References nl_list_at_head, nl_list_entry, and NULL.

int nl_cache_is_empty ( struct nl_cache cache)

Returns true if the cache is empty.

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

References nl_cache::c_items.

void nl_cache_mark_all ( struct nl_cache cache)

Mark all objects in a cache.

  • cache Cache to mark all objects in

References nl_cache::c_items, NL_DBG, nl_list_for_each_entry, and nl_object_mark().

Referenced by nl_cache_resync().

Here is the call graph for this function:

Here is the caller graph for this function:

int nl_cache_move ( struct nl_cache cache,
struct nl_object obj 
)

Move object from one cache to another.

  • cache Cache to move object to.
  • obj Object subject to be moved

Removes the given object from its associated cache if needed and adds it to the new cache.

Returns
0 on success or a negative error code.

References nl_cache::c_ops, nl_cache_ops::co_obj_ops, nl_cache_remove(), NL_DBG, nl_object_get(), and NLE_OBJ_MISMATCH.

Here is the call graph for this function:

int nl_cache_nitems ( struct nl_cache cache)

Return the number of items in the cache.

  • cache cache handle

References nl_cache::c_nitems.

int nl_cache_nitems_filter ( struct nl_cache cache,
struct nl_object filter 
)

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

  • cache Cache object.
  • filter Filter object.

References BUG, nl_cache::c_items, nl_cache::c_ops, nl_cache_ops::co_obj_ops, nl_list_for_each_entry, nl_object_match_filter(), and NULL.

Here is the call graph for this function:

int nl_cache_parse_and_add ( struct nl_cache cache,
struct nl_msg msg 
)

Parse a netlink message and add it to the cache.

  • 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.

References nl_cache::c_ops, nl_cache_parse(), nlmsg_hdr(), NULL, and nl_parser_param::pp_cb.

Here is the call graph for this function:

int nl_cache_pickup ( struct nl_sock sk,
struct nl_cache cache 
)

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

  • sk Netlink socket.
  • 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.

References __cache_pickup(), and nl_parser_param::pp_cb.

Referenced by flnl_lookup(), and nl_cache_refill().

Here is the call graph for this function:

Here is the caller graph for this function:

int nl_cache_refill ( struct nl_sock sk,
struct nl_cache cache 
)

(Re)fill a cache with the contents in the kernel.

  • sk Netlink socket.
  • cache cache to update

Clears the specified cache and fills it with the current state in the kernel.

Returns
0 or a negative error code.

References nl_cache_clear(), nl_cache_pickup(), nl_cache_request_full_dump(), and NL_DBG.

Referenced by nfnl_nft_chain_alloc_cache(), nfnl_nft_rule_alloc_cache(), nfnl_nft_set_alloc_cache(), nfnl_nft_setelem_alloc_cache(), nfnl_nft_table_alloc_cache(), nl_cache_alloc_and_fill(), nl_cache_mngr_add(), rtnl_class_alloc_cache(), rtnl_cls_alloc_cache(), rtnl_route_alloc_cache(), and rtnl_rule_alloc_cache().

Here is the call graph for this function:

Here is the caller graph for this function:

void nl_cache_remove ( struct nl_object obj)

Removes an object from a cache.

  • obj Object to remove from its cache

Removes the object obj from the cache it is assigned to, since an object can only be assigned to one cache at a time, the cache must ne be passed along with it.

References nl_cache::c_nitems, NL_DBG, nl_object_put(), and NULL.

Referenced by nl_cache_clear(), nl_cache_move(), nl_cache_resync(), and nl_object_free().

Here is the call graph for this function:

Here is the caller graph for this function:

int nl_cache_request_full_dump ( struct nl_sock sk,
struct nl_cache cache 
)

Request a full dump from the kernel to fill a cache.

  • sk Netlink socket.
  • cache Cache subjected to be filled.

Send a dumping request to the kernel causing it to dump all objects related to the specified cache to the netlink socket.

Use nl_cache_pickup() to read the objects from the socket and fill them into a cache.

References nl_cache::c_ops, nl_cache_ops::co_request_update, NL_DBG, NLE_OPNOTSUPP, and NULL.

Referenced by nl_cache_refill(), and nl_cache_resync().

Here is the caller graph for this function:

struct nl_object* nl_cache_search ( struct nl_cache cache,
struct nl_object needle 
)

Search for an object in a cache.

  • cache Cache to search in.
  • needle Object to look for.

Iterates over the cache and looks for an object with identical identifiers as the needle.

Returns
Reference to object or NULL if not found.
Note
The returned object must be returned via nl_object_put().

References nl_cache::c_items, nl_list_for_each_entry, nl_object_get(), nl_object_identical(), and NULL.

Here is the call graph for this function:

struct nl_cache* nl_cache_subset ( struct nl_cache orig,
struct nl_object filter 
)

Allocate a new cache containing a subset of a cache.

  • orig Original cache to be based on
  • filter Filter defining the subset to be filled into new cache
    Returns
    A newly allocated cache or NULL.

References BUG, nl_cache::c_items, nl_cache::c_ops, nl_cache_ops::co_obj_ops, nl_cache_add(), nl_cache_alloc(), nl_list_for_each_entry, nl_object_match_filter(), and NULL.

Here is the call graph for this function: