libnl 1.1.4
Modules
Cache

Modules

 Object
 
 Cache Implementation
 

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.
 
struct nl_cache_opsnl_cache_get_ops (struct nl_cache *cache)
 Return the operations set of the cache.
 
struct nl_object * nl_cache_get_first (struct nl_cache *cache)
 Return the first element in the cache.
 
struct nl_object * nl_cache_get_last (struct nl_cache *cache)
 Return the last element in the cache.
 
struct nl_object * nl_cache_get_next (struct nl_object *obj)
 Return the next element in the cache.
 
struct nl_object * nl_cache_get_prev (struct nl_object *obj)
 Return the previous element in the cache.
 

Cache Creation/Deletion

struct nl_cache * nl_cache_alloc (struct nl_cache_ops *ops)
 Allocate an empty cache.
 
struct nl_cache * nl_cache_alloc_name (const char *kind)
 Allocate an empty cache based on type name.
 
struct nl_cache * nl_cache_subset (struct nl_cache *orig, struct nl_object *filter)
 Allocate a new cache containing a subset of a cache.
 
void nl_cache_clear (struct nl_cache *cache)
 Clear a cache.
 
void nl_cache_get (struct nl_cache *cache)
 Increase reference counter of 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 object to a cache.
 
int nl_cache_move (struct nl_cache *cache, struct nl_object *obj)
 Move object from one cache to another.
 
void nl_cache_remove (struct nl_object *obj)
 Removes an object from a cache.
 
struct nl_object * nl_cache_search (struct nl_cache *cache, struct nl_object *needle)
 Search for an object in a cache.
 

Synchronization

int nl_cache_request_full_dump (struct nl_handle *handle, struct nl_cache *cache)
 Request a full dump from the kernel to fill a cache.
 
int __cache_pickup (struct nl_handle *handle, struct nl_cache *cache, struct nl_parser_param *param)
 
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_include (struct nl_cache *cache, struct nl_object *obj, change_func_t change_cb)
 
int nl_cache_resync (struct nl_handle *handle, 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.
 
int nl_cache_refill (struct nl_handle *handle, struct nl_cache *cache)
 (Re)fill a cache with the contents in the kernel.
 

Utillities

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

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

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
int nl_cache_add(struct nl_cache *cache, struct nl_object *obj)
Add object to a cache.
Definition: cache.c:320
int nl_recv(struct nl_handle *handle, struct sockaddr_nl *nla, unsigned char **buf, struct ucred **creds)
Receive data from netlink socket.
Definition: nl.c:460
int nl_recvmsgs(struct nl_handle *handle, struct nl_cb *cb)
Receive a set of messages from a netlink socket.
Definition: nl.c:768

Function Documentation

◆ nl_cache_nitems()

int nl_cache_nitems ( struct nl_cache *  cache)
Parameters
cachecache handle

Definition at line 58 of file cache.c.

59{
60 return cache->c_nitems;
61}

◆ nl_cache_nitems_filter()

int nl_cache_nitems_filter ( struct nl_cache *  cache,
struct nl_object *  filter 
)
Parameters
cacheCache object.
filterFilter object.

Definition at line 68 of file cache.c.

69{
70 struct nl_object *obj;
71 int nitems = 0;
72
73 if (cache->c_ops == NULL)
74 BUG();
75
76 nl_list_for_each_entry(obj, &cache->c_items, ce_list) {
77 if (filter && !nl_object_match_filter(obj, filter))
78 continue;
79
80 nitems++;
81 }
82
83 return nitems;
84}
int nl_object_match_filter(struct nl_object *obj, struct nl_object *filter)
Match a filter against an object.
Definition: object.c:318

References nl_object_match_filter().

◆ nl_cache_is_empty()

int nl_cache_is_empty ( struct nl_cache *  cache)
Parameters
cacheCache to check
Returns
true if the cache is empty, otherwise false is returned.

Definition at line 91 of file cache.c.

92{
93 return nl_list_empty(&cache->c_items);
94}

◆ nl_cache_get_ops()

struct nl_cache_ops * nl_cache_get_ops ( struct nl_cache *  cache)
Parameters
cachecache handle

Definition at line 100 of file cache.c.

101{
102 return cache->c_ops;
103}

◆ nl_cache_get_first()

struct nl_object * nl_cache_get_first ( struct nl_cache *  cache)
Parameters
cachecache handle

Definition at line 109 of file cache.c.

110{
111 if (nl_list_empty(&cache->c_items))
112 return NULL;
113
114 return nl_list_entry(cache->c_items.next,
115 struct nl_object, ce_list);
116}

◆ nl_cache_get_last()

struct nl_object * nl_cache_get_last ( struct nl_cache *  cache)
Parameters
cachecache handle

Definition at line 122 of file cache.c.

123{
124 if (nl_list_empty(&cache->c_items))
125 return NULL;
126
127 return nl_list_entry(cache->c_items.prev,
128 struct nl_object, ce_list);
129}

◆ nl_cache_get_next()

struct nl_object * nl_cache_get_next ( struct nl_object *  obj)
Parameters
objcurrent object

Definition at line 135 of file cache.c.

136{
137 if (nl_list_at_tail(obj, &obj->ce_cache->c_items, ce_list))
138 return NULL;
139 else
140 return nl_list_entry(obj->ce_list.next,
141 struct nl_object, ce_list);
142}

◆ nl_cache_get_prev()

struct nl_object * nl_cache_get_prev ( struct nl_object *  obj)
Parameters
objcurrent object

Definition at line 148 of file cache.c.

149{
150 if (nl_list_at_head(obj, &obj->ce_cache->c_items, ce_list))
151 return NULL;
152 else
153 return nl_list_entry(obj->ce_list.prev,
154 struct nl_object, ce_list);
155}

◆ nl_cache_alloc()

struct nl_cache * nl_cache_alloc ( struct nl_cache_ops ops)
Parameters
opscache operations to base the cache on
Returns
A newly allocated and initialized cache.

Definition at line 170 of file cache.c.

171{
172 struct nl_cache *cache;
173
174 cache = calloc(1, sizeof(*cache));
175 if (!cache) {
176 nl_errno(ENOMEM);
177 return NULL;
178 }
179
180 nl_init_list_head(&cache->c_items);
181 cache->c_ops = ops;
182 cache->c_refcnt = 1;
183
184 NL_DBG(2, "Allocated cache %p <%s>.\n", cache, nl_cache_name(cache));
185
186 return cache;
187}

Referenced by flnl_result_alloc_cache(), nfnl_ct_alloc_cache(), nl_cache_alloc_name(), nl_cache_mngr_add(), nl_cache_subset(), 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().

◆ nl_cache_alloc_name()

struct nl_cache * nl_cache_alloc_name ( const char *  kind)
Parameters
kindName of cache type
Returns
A newly allocated and initialized cache.

Definition at line 194 of file cache.c.

195{
196 struct nl_cache_ops *ops;
197
198 ops = nl_cache_ops_lookup(kind);
199 if (!ops) {
200 nl_error(ENOENT, "Unable to lookup cache \"%s\"", kind);
201 return NULL;
202 }
203
204 return nl_cache_alloc(ops);
205}
struct nl_cache_ops * nl_cache_ops_lookup(const char *name)
Lookup cache operations by name.
Definition: cache_mngt.c:68
struct nl_cache * nl_cache_alloc(struct nl_cache_ops *ops)
Allocate an empty cache.
Definition: cache.c:170
Cache Operations.
Definition: cache-api.h:164

References nl_cache_alloc(), and nl_cache_ops_lookup().

◆ nl_cache_subset()

struct nl_cache * nl_cache_subset ( struct nl_cache *  orig,
struct nl_object *  filter 
)
Parameters
origOriginal cache to be based on
filterFilter defining the subset to be filled into new cache
Returns
A newly allocated cache or NULL.

Definition at line 213 of file cache.c.

215{
216 struct nl_cache *cache;
217 struct nl_object *obj;
218
219 if (!filter)
220 BUG();
221
222 cache = nl_cache_alloc(orig->c_ops);
223 if (!cache)
224 return NULL;
225
226 nl_list_for_each_entry(obj, &orig->c_items, ce_list) {
227 if (!nl_object_match_filter(obj, filter))
228 continue;
229
230 nl_cache_add(cache, obj);
231 }
232
233 return cache;
234}

References nl_cache_add(), nl_cache_alloc(), and nl_object_match_filter().

◆ nl_cache_clear()

void nl_cache_clear ( struct nl_cache *  cache)
Parameters
cachecache to clear

Removes all elements of a cache.

Definition at line 242 of file cache.c.

243{
244 struct nl_object *obj, *tmp;
245
246 NL_DBG(1, "Clearing cache %p <%s>...\n", cache, nl_cache_name(cache));
247
248 nl_list_for_each_entry_safe(obj, tmp, &cache->c_items, ce_list)
249 nl_cache_remove(obj);
250}
void nl_cache_remove(struct nl_object *obj)
Removes an object from a cache.
Definition: cache.c:374

References nl_cache_remove().

Referenced by nl_cache_refill().

◆ nl_cache_get()

void nl_cache_get ( struct nl_cache *  cache)
Parameters
cacheCache

Definition at line 264 of file cache.c.

265{
266 cache->c_refcnt++;
267}

Referenced by nl_cache_mngt_provide().

◆ nl_cache_free()

void nl_cache_free ( struct nl_cache *  cache)
Parameters
cacheCache 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 277 of file cache.c.

278{
279 if (!cache)
280 return;
281
282 cache->c_refcnt--;
283 NL_DBG(4, "Returned cache reference %p, %d remaining\n",
284 cache, cache->c_refcnt);
285
286 if (cache->c_refcnt <= 0)
287 __nl_cache_free(cache);
288}

Referenced by genl_ctrl_resolve(), nl_cache_mngr_add(), nl_cache_mngt_unprovide(), 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().

◆ nl_cache_add()

int nl_cache_add ( struct nl_cache *  cache,
struct nl_object *  obj 
)
Parameters
cacheCache to add object to
objObject 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.

Definition at line 320 of file cache.c.

321{
322 struct nl_object *new;
323
324 if (cache->c_ops->co_obj_ops != obj->ce_ops)
325 return nl_error(EINVAL, "Object mismatches cache type");
326
327 if (!nl_list_empty(&obj->ce_list)) {
328 new = nl_object_clone(obj);
329 if (!new)
330 return nl_errno(ENOMEM);
331 } else {
332 nl_object_get(obj);
333 new = obj;
334 }
335
336 return __cache_add(cache, new);
337}
struct nl_object * nl_object_clone(struct nl_object *obj)
Allocate a new object and copy all data from an existing object.
Definition: object.c:95
void nl_object_get(struct nl_object *obj)
Acquire a reference on a object.
Definition: object.c:167

References nl_object_clone(), and nl_object_get().

Referenced by nl_cache_subset().

◆ nl_cache_move()

int nl_cache_move ( struct nl_cache *  cache,
struct nl_object *  obj 
)
Parameters
cacheCache to move object to.
objObject 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.

Definition at line 349 of file cache.c.

350{
351 if (cache->c_ops->co_obj_ops != obj->ce_ops)
352 return nl_error(EINVAL, "Object mismatches cache type");
353
354 NL_DBG(3, "Moving object %p to cache %p\n", obj, cache);
355
356 /* Acquire reference, if already in a cache this will be
357 * reverted during removal */
358 nl_object_get(obj);
359
360 if (!nl_list_empty(&obj->ce_list))
361 nl_cache_remove(obj);
362
363 return __cache_add(cache, obj);
364}

References nl_cache_remove(), and nl_object_get().

◆ nl_cache_remove()

void nl_cache_remove ( struct nl_object *  obj)
Parameters
objObject 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.

Definition at line 374 of file cache.c.

375{
376 struct nl_cache *cache = obj->ce_cache;
377
378 if (cache == NULL)
379 return;
380
381 nl_list_del(&obj->ce_list);
382 obj->ce_cache = NULL;
383 nl_object_put(obj);
384 cache->c_nitems--;
385
386 NL_DBG(1, "Deleted %p from cache %p <%s>.\n",
387 obj, cache, nl_cache_name(cache));
388}
void nl_object_put(struct nl_object *obj)
Release a reference from an object.
Definition: object.c:178

References nl_object_put().

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

◆ nl_cache_search()

struct nl_object * nl_cache_search ( struct nl_cache *  cache,
struct nl_object *  needle 
)
Parameters
cacheCache to search in.
needleObject 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().

Definition at line 401 of file cache.c.

403{
404 struct nl_object *obj;
405
406 nl_list_for_each_entry(obj, &cache->c_items, ce_list) {
407 if (nl_object_identical(obj, needle)) {
408 nl_object_get(obj);
409 return obj;
410 }
411 }
412
413 return NULL;
414}
int nl_object_identical(struct nl_object *a, struct nl_object *b)
Check if the identifiers of two objects are identical.
Definition: object.c:263

References nl_object_get(), and nl_object_identical().

◆ nl_cache_request_full_dump()

int nl_cache_request_full_dump ( struct nl_handle *  handle,
struct nl_cache *  cache 
)
Parameters
handleNetlink handle
cacheCache 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.

Definition at line 435 of file cache.c.

436{
437 NL_DBG(2, "Requesting dump from kernel for cache %p <%s>...\n",
438 cache, nl_cache_name(cache));
439
440 if (cache->c_ops->co_request_update == NULL)
441 return nl_error(EOPNOTSUPP, "Operation not supported");
442
443 return cache->c_ops->co_request_update(cache, handle);
444}

Referenced by nl_cache_refill().

◆ __cache_pickup()

int __cache_pickup ( struct nl_handle *  handle,
struct nl_cache *  cache,
struct nl_parser_param param 
)

Definition at line 460 of file cache.c.

462{
463 int err;
464 struct nl_cb *cb;
465 struct update_xdata x = {
466 .ops = cache->c_ops,
467 .params = param,
468 };
469
470 NL_DBG(1, "Picking up answer for cache %p <%s>...\n",
471 cache, nl_cache_name(cache));
472
473 cb = nl_cb_clone(handle->h_cb);
474 if (cb == NULL)
475 return nl_get_errno();
476
477 nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, update_msg_parser, &x);
478
479 err = nl_recvmsgs(handle, cb);
480 if (err < 0)
481 NL_DBG(2, "While picking up for %p <%s>, recvmsgs() returned " \
482 "%d: %s", cache, nl_cache_name(cache),
483 err, nl_geterror());
484
485 nl_cb_put(cb);
486
487 return err;
488}
int nl_cb_set(struct nl_cb *cb, enum nl_cb_type type, enum nl_cb_kind kind, nl_recvmsg_msg_cb_t func, void *arg)
Set up a callback.
Definition: handlers.c:338
struct nl_cb * nl_cb_clone(struct nl_cb *orig)
Clone an existing callback handle.
Definition: handlers.c:286
@ NL_CB_VALID
Message is valid.
Definition: handlers.h:96
@ NL_CB_CUSTOM
Customized handler specified by the user.
Definition: handlers.h:84
char * nl_geterror(void)
Return error message for an error code.
Definition: utils.c:142

◆ nl_cache_pickup()

int nl_cache_pickup ( struct nl_handle *  handle,
struct nl_cache *  cache 
)
Parameters
handleNetlink handle.
cacheCache 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 505 of file cache.c.

506{
507 struct nl_parser_param p = {
508 .pp_cb = pickup_cb,
509 .pp_arg = cache,
510 };
511
512 return __cache_pickup(handle, cache, &p);
513}

Referenced by flnl_lookup(), and nl_cache_refill().

◆ nl_cache_include()

int nl_cache_include ( struct nl_cache *  cache,
struct nl_object *  obj,
change_func_t  change_cb 
)

Definition at line 553 of file cache.c.

555{
556 struct nl_cache_ops *ops = cache->c_ops;
557 int i;
558
559 if (ops->co_obj_ops != obj->ce_ops)
560 return nl_error(EINVAL, "Object mismatches cache type");
561
562 for (i = 0; ops->co_msgtypes[i].mt_id >= 0; i++)
563 if (ops->co_msgtypes[i].mt_id == obj->ce_msgtype)
564 return cache_include(cache, obj, &ops->co_msgtypes[i],
565 change_cb);
566
567 return nl_errno(EINVAL);
568}
int mt_id
Netlink message type.
Definition: cache-api.h:131

◆ nl_cache_resync()

int nl_cache_resync ( struct nl_handle *  handle,
struct nl_cache *  cache,
change_func_t  change_cb 
)

Definition at line 577 of file cache.c.

579{
580 struct nl_object *obj, *next;
581 struct nl_cache_assoc ca = {
582 .ca_cache = cache,
583 .ca_change = change_cb,
584 };
585 struct nl_parser_param p = {
586 .pp_cb = resync_cb,
587 .pp_arg = &ca,
588 };
589 int err;
590
591 NL_DBG(1, "Resyncing cache %p <%s>...\n", cache, nl_cache_name(cache));
592
593 /* Mark all objects so we can see if some of them are obsolete */
594 nl_cache_mark_all(cache);
595
596 err = nl_cache_request_full_dump(handle, cache);
597 if (err < 0)
598 goto errout;
599
600 err = __cache_pickup(handle, cache, &p);
601 if (err < 0)
602 goto errout;
603
604 nl_list_for_each_entry_safe(obj, next, &cache->c_items, ce_list)
605 if (nl_object_is_marked(obj))
606 nl_cache_remove(obj);
607
608 NL_DBG(1, "Finished resyncing %p <%s>\n", cache, nl_cache_name(cache));
609
610 err = 0;
611errout:
612 return err;
613}
int nl_cache_request_full_dump(struct nl_handle *handle, struct nl_cache *cache)
Request a full dump from the kernel to fill a cache.
Definition: cache.c:435
void nl_cache_mark_all(struct nl_cache *cache)
Mark all objects in a cache.
Definition: cache.c:706
int nl_object_is_marked(struct nl_object *obj)
Return true if object is marked.
Definition: object.c:234

◆ nl_cache_parse_and_add()

int nl_cache_parse_and_add ( struct nl_cache *  cache,
struct nl_msg *  msg 
)
Parameters
cachecache to add element to
msgnetlink 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 660 of file cache.c.

661{
662 struct nl_parser_param p = {
663 .pp_cb = pickup_cb,
664 .pp_arg = cache,
665 };
666
667 return nl_cache_parse(cache->c_ops, NULL, nlmsg_hdr(msg), &p);
668}
struct nlmsghdr * nlmsg_hdr(struct nl_msg *n)
Return actual netlink message.
Definition: msg.c:643

References nlmsg_hdr().

◆ nl_cache_refill()

int nl_cache_refill ( struct nl_handle *  handle,
struct nl_cache *  cache 
)
Parameters
handlenetlink handle
cachecache to update

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

Returns
0 or a negative error code.

Definition at line 680 of file cache.c.

681{
682 int err;
683
684 err = nl_cache_request_full_dump(handle, cache);
685 if (err < 0)
686 return err;
687
688 NL_DBG(2, "Upading cache %p <%s>, request sent, waiting for dump...\n",
689 cache, nl_cache_name(cache));
690 nl_cache_clear(cache);
691
692 return nl_cache_pickup(handle, cache);
693}
void nl_cache_clear(struct nl_cache *cache)
Clear a cache.
Definition: cache.c:242
int nl_cache_pickup(struct nl_handle *handle, struct nl_cache *cache)
Pickup a netlink dump response and put it into a cache.
Definition: cache.c:505

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

Referenced by nfnl_ct_alloc_cache(), nl_cache_mngr_add(), 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().

◆ nl_cache_mark_all()

void nl_cache_mark_all ( struct nl_cache *  cache)
Parameters
cacheCache to mark all objects in

Definition at line 706 of file cache.c.

707{
708 struct nl_object *obj;
709
710 NL_DBG(2, "Marking all objects in cache %p <%s>...\n",
711 cache, nl_cache_name(cache));
712
713 nl_list_for_each_entry(obj, &cache->c_items, ce_list)
714 nl_object_mark(obj);
715}
void nl_object_mark(struct nl_object *obj)
Add mark to object.
Definition: object.c:215

References nl_object_mark().

◆ nl_cache_dump()

void nl_cache_dump ( struct nl_cache *  cache,
struct nl_dump_params params 
)
Parameters
cachecache to dump
paramsdumping parameters

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

Definition at line 731 of file cache.c.

732{
733 nl_cache_dump_filter(cache, params, NULL);
734}
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).
Definition: cache.c:745

References nl_cache_dump_filter().

◆ nl_cache_dump_filter()

void nl_cache_dump_filter ( struct nl_cache *  cache,
struct nl_dump_params params,
struct nl_object *  filter 
)
Parameters
cachecache to dump
paramsdumping parameters (optional)
filterfilter object

Dumps all elements of the cache to the file descriptor fd given they match the given filter filter.

Definition at line 745 of file cache.c.

748{
749 int type = params ? params->dp_type : NL_DUMP_FULL;
750 struct nl_object_ops *ops;
751 struct nl_object *obj;
752
753 NL_DBG(2, "Dumping cache %p <%s> filter %p\n",
754 cache, nl_cache_name(cache), filter);
755
756 if (type > NL_DUMP_MAX || type < 0)
757 BUG();
758
759 if (cache->c_ops == NULL)
760 BUG();
761
762 ops = cache->c_ops->co_obj_ops;
763 if (!ops->oo_dump[type])
764 return;
765
766 nl_list_for_each_entry(obj, &cache->c_items, ce_list) {
767 if (filter && !nl_object_match_filter(obj, filter))
768 continue;
769
770 NL_DBG(4, "Dumping object %p...\n", obj);
771 dump_from_ops(obj, params);
772 }
773}
@ NL_DUMP_FULL
Dump all attributes but no statistics.
Definition: types.h:23
enum nl_dump_type dp_type
Specifies the type of dump that is requested.
Definition: types.h:41
Object Operations.
Definition: object-api.h:255
int(* oo_dump[NL_DUMP_MAX+1])(struct nl_object *, struct nl_dump_params *)
Dumping functions.
Definition: object-api.h:307

References nl_dump_params::dp_type, NL_DUMP_FULL, nl_object_match_filter(), and nl_object_ops::oo_dump.

Referenced by nl_cache_dump().

◆ nl_cache_foreach()

void nl_cache_foreach ( struct nl_cache *  cache,
void(*)(struct nl_object *, void *)  cb,
void *  arg 
)
Parameters
cachecache to iterate on
cbcallback function
argargument 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 791 of file cache.c.

793{
794 nl_cache_foreach_filter(cache, NULL, cb, arg);
795}
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).
Definition: cache.c:808

References nl_cache_foreach_filter().

◆ 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 
)
Parameters
cachecache to iterate on
filterfilter object
cbcallback function
argargument 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 808 of file cache.c.

810{
811 struct nl_object *obj, *tmp;
812
813 if (cache->c_ops == NULL)
814 BUG();
815
816 nl_list_for_each_entry_safe(obj, tmp, &cache->c_items, ce_list) {
817 if (filter && !nl_object_match_filter(obj, filter))
818 continue;
819
820 cb(obj, arg);
821 }
822}

References nl_object_match_filter().

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