libnl  3.3.0
cache_mngr.c
1 /*
2  * lib/cache_mngr.c Cache Manager
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation version 2.1
7  * of the License.
8  *
9  * Copyright (c) 2003-2012 Thomas Graf <tgraf@suug.ch>
10  */
11 
12 /**
13  * @ingroup cache_mngt
14  * @defgroup cache_mngr Manager
15  * @brief Manager keeping caches up to date automatically.
16  *
17  * The cache manager keeps caches up to date automatically by listening to
18  * netlink notifications and integrating the received information into the
19  * existing cache.
20  *
21  * @note This functionality is still considered experimental.
22  *
23  * Related sections in the development guide:
24  * - @core_doc{_cache_manager,Cache Manager}
25  *
26  * @{
27  *
28  * Header
29  * ------
30  * ~~~~{.c}
31  * #include <netlink/cache.h>
32  * ~~~~
33  */
34 
35 #include <netlink-private/netlink.h>
36 #include <netlink-private/utils.h>
37 #include <netlink/netlink.h>
38 #include <netlink/cache.h>
39 #include <netlink/utils.h>
40 
41 /** @cond SKIP */
42 #define NASSOC_INIT 16
43 #define NASSOC_EXPAND 8
44 /** @endcond */
45 
46 static int include_cb(struct nl_object *obj, struct nl_parser_param *p)
47 {
48  struct nl_cache_assoc *ca = p->pp_arg;
49  struct nl_cache_ops *ops = ca->ca_cache->c_ops;
50 
51  NL_DBG(2, "Including object %p into cache %p\n", obj, ca->ca_cache);
52 #ifdef NL_DEBUG
53  if (nl_debug >= 4)
54  nl_object_dump(obj, &nl_debug_dp);
55 #endif
56 
57  if (ops->co_event_filter)
58  if (ops->co_event_filter(ca->ca_cache, obj) != NL_OK)
59  return 0;
60 
61  if (ops->co_include_event)
62  return ops->co_include_event(ca->ca_cache, obj, ca->ca_change,
63  ca->ca_change_v2,
64  ca->ca_change_data);
65  else {
66  if (ca->ca_change_v2)
67  return nl_cache_include_v2(ca->ca_cache, obj, ca->ca_change_v2, ca->ca_change_data);
68  else
69  return nl_cache_include(ca->ca_cache, obj, ca->ca_change, ca->ca_change_data);
70  }
71 
72 }
73 
74 static int event_input(struct nl_msg *msg, void *arg)
75 {
76  struct nl_cache_mngr *mngr = arg;
77  int protocol = nlmsg_get_proto(msg);
78  int type = nlmsg_hdr(msg)->nlmsg_type;
79  struct nl_cache_ops *ops;
80  int i, n;
81  struct nl_parser_param p = {
82  .pp_cb = include_cb,
83  };
84 
85  NL_DBG(2, "Cache manager %p, handling new message %p as event\n",
86  mngr, msg);
87 #ifdef NL_DEBUG
88  if (nl_debug >= 4)
89  nl_msg_dump(msg, stderr);
90 #endif
91 
92  if (mngr->cm_protocol != protocol)
93  BUG();
94 
95  for (i = 0; i < mngr->cm_nassocs; i++) {
96  if (mngr->cm_assocs[i].ca_cache) {
97  ops = mngr->cm_assocs[i].ca_cache->c_ops;
98  for (n = 0; ops->co_msgtypes[n].mt_id >= 0; n++)
99  if (ops->co_msgtypes[n].mt_id == type)
100  goto found;
101  }
102  }
103 
104  return NL_SKIP;
105 
106 found:
107  NL_DBG(2, "Associated message %p to cache %p\n",
108  msg, mngr->cm_assocs[i].ca_cache);
109  p.pp_arg = &mngr->cm_assocs[i];
110 
111  return nl_cache_parse(ops, NULL, nlmsg_hdr(msg), &p);
112 }
113 
114 /**
115  * Allocate new cache manager
116  * @arg sk Netlink socket or NULL to auto allocate
117  * @arg protocol Netlink protocol this manager is used for
118  * @arg flags Flags (\c NL_AUTO_PROVIDE)
119  * @arg result Result pointer
120  *
121  * Allocates a new cache manager for the specified netlink protocol.
122  *
123  * 1. If sk is not specified (\c NULL) a netlink socket matching the
124  * specified protocol will be automatically allocated.
125  *
126  * 2. The socket will be put in non-blocking mode and sequence checking
127  * will be disabled regardless of whether the socket was provided by
128  * the caller or automatically allocated.
129  *
130  * 3. The socket will be connected.
131  *
132  * If the flag \c NL_AUTO_PROVIDE is specified, any cache added to the
133  * manager will automatically be made available to other users using
134  * nl_cache_mngt_provide().
135  *
136  * @note If the socket is provided by the caller, it is NOT recommended
137  * to use the socket for anything else besides receiving netlink
138  * notifications.
139  *
140  * @return 0 on success or a negative error code.
141  */
142 int nl_cache_mngr_alloc(struct nl_sock *sk, int protocol, int flags,
143  struct nl_cache_mngr **result)
144 {
145  struct nl_cache_mngr *mngr;
146  int err = -NLE_NOMEM;
147 
148  /* Catch abuse of flags */
149  if (flags & NL_ALLOCATED_SOCK)
150  BUG();
151 
152  mngr = calloc(1, sizeof(*mngr));
153  if (!mngr)
154  return -NLE_NOMEM;
155 
156  if (!sk) {
157  if (!(sk = nl_socket_alloc()))
158  goto errout;
159 
160  flags |= NL_ALLOCATED_SOCK;
161  }
162 
163  mngr->cm_sock = sk;
164  mngr->cm_nassocs = NASSOC_INIT;
165  mngr->cm_protocol = protocol;
166  mngr->cm_flags = flags;
167  mngr->cm_assocs = calloc(mngr->cm_nassocs,
168  sizeof(struct nl_cache_assoc));
169  if (!mngr->cm_assocs)
170  goto errout;
171 
172  /* Required to receive async event notifications */
173  nl_socket_disable_seq_check(mngr->cm_sock);
174 
175  if ((err = nl_connect(mngr->cm_sock, protocol)) < 0)
176  goto errout;
177 
178  if ((err = nl_socket_set_nonblocking(mngr->cm_sock)) < 0)
179  goto errout;
180 
181  /* Create and allocate socket for sync cache fills */
182  mngr->cm_sync_sock = nl_socket_alloc();
183  if (!mngr->cm_sync_sock) {
184  err = -NLE_NOMEM;
185  goto errout;
186  }
187  if ((err = nl_connect(mngr->cm_sync_sock, protocol)) < 0)
188  goto errout_free_sync_sock;
189 
190  NL_DBG(1, "Allocated cache manager %p, protocol %d, %d caches\n",
191  mngr, protocol, mngr->cm_nassocs);
192 
193  *result = mngr;
194  return 0;
195 
196 errout_free_sync_sock:
197  nl_socket_free(mngr->cm_sync_sock);
198 errout:
199  nl_cache_mngr_free(mngr);
200  return err;
201 }
202 
203 /**
204  * Set change_func_v2 for cache manager
205  * @arg mngr Cache manager.
206  * @arg cache Cache associated with the callback
207  * @arg cb Function to be called upon changes.
208  * @arg data Argument passed on to change callback
209  *
210  * Adds callback change_func_v2 to a registered cache. This callback provides
211  * in like the standard change_func the added or remove netlink object. In case
212  * of a change the old and the new object is provided as well as the according
213  * diff. If this callback is registered this has a higher priority then the
214  * change_func registered during cache registration. Hence only one callback is
215  * executed.
216  *
217  * The first netlink object in the callback is refering to the old object and
218  * the second to the new. This means on NL_ACT_CHANGE the first is the previous
219  * object in the cache and the second the updated version. On NL_ACT_DEL the
220  * first is the deleted object the second is NULL. On NL_ACT_NEW the first is
221  * NULL and the second the new netlink object.
222  *
223  * The user is responsible for calling nl_cache_mngr_poll() or monitor
224  * the socket and call nl_cache_mngr_data_ready() to allow the library
225  * to process netlink notification events.
226  *
227  * @see nl_cache_mngr_poll()
228  * @see nl_cache_mngr_data_ready()
229  *
230  * @return 0 on success or a negative error code.
231  * @return -NLE_PROTO_MISMATCH Protocol mismatch between cache manager and
232  * cache type
233  * @return -NLE_OPNOTSUPP Cache type does not support updates
234  * @return -NLE_RANGE Cache of this type is not registered
235  */
236 static int nl_cache_mngr_set_change_func_v2(struct nl_cache_mngr *mngr,
237  struct nl_cache *cache,
238  change_func_v2_t cb, void *data)
239 {
240  struct nl_cache_ops *ops;
241  int i;
242 
243  ops = cache->c_ops;
244  if (!ops)
245  return -NLE_INVAL;
246 
247  if (ops->co_protocol != mngr->cm_protocol)
248  return -NLE_PROTO_MISMATCH;
249 
250  if (ops->co_groups == NULL)
251  return -NLE_OPNOTSUPP;
252 
253  for (i = 0; i < mngr->cm_nassocs; i++)
254  if (mngr->cm_assocs[i].ca_cache == cache)
255  break;
256 
257  if (i >= mngr->cm_nassocs) {
258  return -NLE_RANGE;
259  }
260 
261  mngr->cm_assocs[i].ca_change_v2 = cb;
262  mngr->cm_assocs[i].ca_change_data = data;
263 
264  return 0;
265 }
266 
267 /**
268  * Add cache to cache manager
269  * @arg mngr Cache manager.
270  * @arg cache Cache to be added to cache manager
271  * @arg cb Function to be called upon changes.
272  * @arg data Argument passed on to change callback
273  *
274  * Adds cache to the manager. The operation will trigger a full
275  * dump request from the kernel to initially fill the contents
276  * of the cache. The manager will subscribe to the notification group
277  * of the cache and keep track of any further changes.
278  *
279  * The user is responsible for calling nl_cache_mngr_poll() or monitor
280  * the socket and call nl_cache_mngr_data_ready() to allow the library
281  * to process netlink notification events.
282  *
283  * @see nl_cache_mngr_poll()
284  * @see nl_cache_mngr_data_ready()
285  *
286  * @return 0 on success or a negative error code.
287  * @return -NLE_PROTO_MISMATCH Protocol mismatch between cache manager and
288  * cache type
289  * @return -NLE_OPNOTSUPP Cache type does not support updates
290  * @return -NLE_EXIST Cache of this type already being managed
291  */
292 int nl_cache_mngr_add_cache(struct nl_cache_mngr *mngr, struct nl_cache *cache,
293  change_func_t cb, void *data)
294 {
295  struct nl_cache_ops *ops;
296  struct nl_af_group *grp;
297  int err, i;
298 
299  ops = cache->c_ops;
300  if (!ops)
301  return -NLE_INVAL;
302 
303  if (ops->co_protocol != mngr->cm_protocol)
304  return -NLE_PROTO_MISMATCH;
305 
306  if (ops->co_groups == NULL)
307  return -NLE_OPNOTSUPP;
308 
309  for (i = 0; i < mngr->cm_nassocs; i++)
310  if (mngr->cm_assocs[i].ca_cache &&
311  mngr->cm_assocs[i].ca_cache->c_ops == ops)
312  return -NLE_EXIST;
313 
314 retry:
315  for (i = 0; i < mngr->cm_nassocs; i++)
316  if (!mngr->cm_assocs[i].ca_cache)
317  break;
318 
319  if (i >= mngr->cm_nassocs) {
320  mngr->cm_nassocs += NASSOC_EXPAND;
321  mngr->cm_assocs = realloc(mngr->cm_assocs,
322  mngr->cm_nassocs *
323  sizeof(struct nl_cache_assoc));
324  if (mngr->cm_assocs == NULL)
325  return -NLE_NOMEM;
326 
327  memset(mngr->cm_assocs + (mngr->cm_nassocs - NASSOC_EXPAND), 0,
328  NASSOC_EXPAND * sizeof(struct nl_cache_assoc));
329 
330  NL_DBG(1, "Increased capacity of cache manager %p " \
331  "to %d\n", mngr, mngr->cm_nassocs);
332  goto retry;
333  }
334 
335  for (grp = ops->co_groups; grp->ag_group; grp++) {
336  err = nl_socket_add_membership(mngr->cm_sock, grp->ag_group);
337  if (err < 0)
338  return err;
339  }
340 
341  err = nl_cache_refill(mngr->cm_sync_sock, cache);
342  if (err < 0)
343  goto errout_drop_membership;
344 
345  mngr->cm_assocs[i].ca_cache = cache;
346  mngr->cm_assocs[i].ca_change = cb;
347  mngr->cm_assocs[i].ca_change_data = data;
348 
349  if (mngr->cm_flags & NL_AUTO_PROVIDE)
350  nl_cache_mngt_provide(cache);
351 
352  NL_DBG(1, "Added cache %p <%s> to cache manager %p\n",
353  cache, nl_cache_name(cache), mngr);
354 
355  return 0;
356 
357 errout_drop_membership:
358  for (grp = ops->co_groups; grp->ag_group; grp++)
359  nl_socket_drop_membership(mngr->cm_sock, grp->ag_group);
360 
361  return err;
362 }
363 
364 /**
365  * Add cache to cache manager
366  * @arg mngr Cache manager.
367  * @arg cache Cache to be added to cache manager
368  * @arg cb V2 function to be called upon changes.
369  * @arg data Argument passed on to change callback
370  *
371  * Adds cache to the manager. The operation will trigger a full
372  * dump request from the kernel to initially fill the contents
373  * of the cache. The manager will subscribe to the notification group
374  * of the cache and keep track of any further changes.
375  *
376  * The user is responsible for calling nl_cache_mngr_poll() or monitor
377  * the socket and call nl_cache_mngr_data_ready() to allow the library
378  * to process netlink notification events.
379  *
380  * @see nl_cache_mngr_poll()
381  * @see nl_cache_mngr_data_ready()
382  *
383  * @return 0 on success or a negative error code.
384  * @return -NLE_PROTO_MISMATCH Protocol mismatch between cache manager and
385  * cache type
386  * @return -NLE_OPNOTSUPP Cache type does not support updates
387  * @return -NLE_EXIST Cache of this type already being managed
388  */
389 int nl_cache_mngr_add_cache_v2(struct nl_cache_mngr *mngr, struct nl_cache *cache,
390  change_func_v2_t cb, void *data) {
391  int err;
392  err = nl_cache_mngr_add_cache(mngr, cache, NULL, NULL);
393  if (err < 0)
394  return err;
395 
396  return nl_cache_mngr_set_change_func_v2(mngr, cache, cb, data);
397 }
398 
399 /**
400  * Add cache to cache manager
401  * @arg mngr Cache manager.
402  * @arg name Name of cache to keep track of
403  * @arg cb Function to be called upon changes.
404  * @arg data Argument passed on to change callback
405  * @arg result Pointer to store added cache (optional)
406  *
407  * Allocates a new cache of the specified type and adds it to the manager.
408  * The operation will trigger a full dump request from the kernel to
409  * initially fill the contents of the cache. The manager will subscribe
410  * to the notification group of the cache and keep track of any further
411  * changes.
412  *
413  * The user is responsible for calling nl_cache_mngr_poll() or monitor
414  * the socket and call nl_cache_mngr_data_ready() to allow the library
415  * to process netlink notification events.
416  *
417  * @see nl_cache_mngr_poll()
418  * @see nl_cache_mngr_data_ready()
419  *
420  * @return 0 on success or a negative error code.
421  * @return -NLE_NOCACHE Unknown cache type
422  * @return -NLE_PROTO_MISMATCH Protocol mismatch between cache manager and
423  * cache type
424  * @return -NLE_OPNOTSUPP Cache type does not support updates
425  * @return -NLE_EXIST Cache of this type already being managed
426  */
427 int nl_cache_mngr_add(struct nl_cache_mngr *mngr, const char *name,
428  change_func_t cb, void *data, struct nl_cache **result)
429 {
430  struct nl_cache_ops *ops;
431  struct nl_cache *cache;
432  int err;
433 
434  ops = nl_cache_ops_lookup_safe(name);
435  if (!ops)
436  return -NLE_NOCACHE;
437 
438  cache = nl_cache_alloc(ops);
439  nl_cache_ops_put(ops);
440  if (!cache)
441  return -NLE_NOMEM;
442 
443  err = nl_cache_mngr_add_cache(mngr, cache, cb, data);
444  if (err < 0)
445  goto errout_free_cache;
446 
447  *result = cache;
448  return 0;
449 
450 errout_free_cache:
451  nl_cache_free(cache);
452 
453  return err;
454 }
455 
456 /**
457  * Get socket file descriptor
458  * @arg mngr Cache Manager
459  *
460  * Get the file descriptor of the socket associated with the manager.
461  *
462  * @note Do not use the socket for anything besides receiving
463  * notifications.
464  */
465 int nl_cache_mngr_get_fd(struct nl_cache_mngr *mngr)
466 {
467  return nl_socket_get_fd(mngr->cm_sock);
468 }
469 
470 /**
471  * Check for event notifications
472  * @arg mngr Cache Manager
473  * @arg timeout Upper limit poll() will block, in milliseconds.
474  *
475  * Causes poll() to be called to check for new event notifications
476  * being available. Calls nl_cache_mngr_data_ready() to process
477  * available data.
478  *
479  * This functionally is ideally called regularly during an idle
480  * period.
481  *
482  * A timeout can be specified in milliseconds to limit the time the
483  * function will wait for updates.
484  *
485  * @see nl_cache_mngr_data_ready()
486  *
487  * @return The number of messages processed or a negative error code.
488  */
489 int nl_cache_mngr_poll(struct nl_cache_mngr *mngr, int timeout)
490 {
491  int ret;
492  struct pollfd fds = {
493  .fd = nl_socket_get_fd(mngr->cm_sock),
494  .events = POLLIN,
495  };
496 
497  NL_DBG(3, "Cache manager %p, poll() fd %d\n", mngr, fds.fd);
498  ret = poll(&fds, 1, timeout);
499  NL_DBG(3, "Cache manager %p, poll() returned %d\n", mngr, ret);
500  if (ret < 0) {
501  NL_DBG(4, "nl_cache_mngr_poll(%p): poll() failed with %d (%s)\n",
502  mngr, errno, nl_strerror_l(errno));
503  return -nl_syserr2nlerr(errno);
504  }
505 
506  /* No events, return */
507  if (ret == 0)
508  return 0;
509 
510  return nl_cache_mngr_data_ready(mngr);
511 }
512 
513 /**
514  * Receive available event notifications
515  * @arg mngr Cache manager
516  *
517  * This function can be called if the socket associated to the manager
518  * contains updates to be received. This function should only be used
519  * if nl_cache_mngr_poll() is not used.
520  *
521  * The function will process messages until there is no more data to
522  * be read from the socket.
523  *
524  * @see nl_cache_mngr_poll()
525  *
526  * @return The number of messages processed or a negative error code.
527  */
528 int nl_cache_mngr_data_ready(struct nl_cache_mngr *mngr)
529 {
530  int err, nread = 0;
531  struct nl_cb *cb;
532 
533  NL_DBG(2, "Cache manager %p, reading new data from fd %d\n",
534  mngr, nl_socket_get_fd(mngr->cm_sock));
535 
536  cb = nl_cb_clone(mngr->cm_sock->s_cb);
537  if (cb == NULL)
538  return -NLE_NOMEM;
539 
540  nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, event_input, mngr);
541 
542  while ((err = nl_recvmsgs_report(mngr->cm_sock, cb)) > 0) {
543  NL_DBG(2, "Cache manager %p, recvmsgs read %d messages\n",
544  mngr, err);
545  nread += err;
546  }
547 
548  nl_cb_put(cb);
549  if (err < 0 && err != -NLE_AGAIN)
550  return err;
551 
552  return nread;
553 }
554 
555 /**
556  * Print information about cache manager
557  * @arg mngr Cache manager
558  * @arg p Dumping parameters
559  *
560  * Prints information about the cache manager including all managed caches.
561  *
562  * @note This is a debugging function.
563  */
564 void nl_cache_mngr_info(struct nl_cache_mngr *mngr, struct nl_dump_params *p)
565 {
566  char buf[128];
567  int i;
568 
569  nl_dump_line(p, "cache-manager <%p>\n", mngr);
570  nl_dump_line(p, " .protocol = %s\n",
571  nl_nlfamily2str(mngr->cm_protocol, buf, sizeof(buf)));
572  nl_dump_line(p, " .flags = %#x\n", mngr->cm_flags);
573  nl_dump_line(p, " .nassocs = %u\n", mngr->cm_nassocs);
574  nl_dump_line(p, " .sock = <%p>\n", mngr->cm_sock);
575 
576  for (i = 0; i < mngr->cm_nassocs; i++) {
577  struct nl_cache_assoc *assoc = &mngr->cm_assocs[i];
578 
579  if (assoc->ca_cache) {
580  nl_dump_line(p, " .cache[%d] = <%p> {\n", i, assoc->ca_cache);
581  nl_dump_line(p, " .name = %s\n", assoc->ca_cache->c_ops->co_name);
582  nl_dump_line(p, " .change_func = <%p>\n", assoc->ca_change);
583  nl_dump_line(p, " .change_data = <%p>\n", assoc->ca_change_data);
584  nl_dump_line(p, " .nitems = %u\n", nl_cache_nitems(assoc->ca_cache));
585  nl_dump_line(p, " .objects = {\n");
586 
587  p->dp_prefix += 6;
588  nl_cache_dump(assoc->ca_cache, p);
589  p->dp_prefix -= 6;
590 
591  nl_dump_line(p, " }\n");
592  nl_dump_line(p, " }\n");
593  }
594  }
595 }
596 
597 /**
598  * Free cache manager and all caches.
599  * @arg mngr Cache manager.
600  *
601  * Release all resources held by a cache manager.
602  */
603 void nl_cache_mngr_free(struct nl_cache_mngr *mngr)
604 {
605  int i;
606 
607  if (!mngr)
608  return;
609 
610  if (mngr->cm_sock)
611  nl_close(mngr->cm_sock);
612 
613  if (mngr->cm_sync_sock) {
614  nl_close(mngr->cm_sync_sock);
615  nl_socket_free(mngr->cm_sync_sock);
616  }
617 
618  if (mngr->cm_flags & NL_ALLOCATED_SOCK)
619  nl_socket_free(mngr->cm_sock);
620 
621  for (i = 0; i < mngr->cm_nassocs; i++) {
622  if (mngr->cm_assocs[i].ca_cache) {
623  nl_cache_mngt_unprovide(mngr->cm_assocs[i].ca_cache);
624  nl_cache_free(mngr->cm_assocs[i].ca_cache);
625  }
626  }
627 
628  free(mngr->cm_assocs);
629 
630  NL_DBG(1, "Cache manager %p freed\n", mngr);
631 
632  free(mngr);
633 }
634 
635 /** @} */
void nl_cache_mngt_provide(struct nl_cache *cache)
Provide a cache for global use.
Definition: cache_mngt.c:332
void nl_cache_ops_put(struct nl_cache_ops *ops)
Decrement reference counter.
Definition: cache_mngt.c:65
int nl_cache_mngr_alloc(struct nl_sock *sk, int protocol, int flags, struct nl_cache_mngr **result)
Allocate new cache manager.
Definition: cache_mngr.c:142
int nl_cache_mngr_get_fd(struct nl_cache_mngr *mngr)
Get socket file descriptor.
Definition: cache_mngr.c:465
Customized handler specified by the user.
Definition: handlers.h:83
int nl_socket_get_fd(const struct nl_sock *sk)
Return the file descriptor of the backing socket.
Definition: socket.c:583
void nl_cache_mngr_info(struct nl_cache_mngr *mngr, struct nl_dump_params *p)
Print information about cache manager.
Definition: cache_mngr.c:564
int nl_cache_mngr_poll(struct nl_cache_mngr *mngr, int timeout)
Check for event notifications.
Definition: cache_mngr.c:489
struct nl_cb * nl_cb_clone(struct nl_cb *orig)
Clone an existing callback handle.
Definition: handlers.c:230
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:293
struct nl_sock * nl_socket_alloc(void)
Allocate new netlink socket.
Definition: socket.c:205
int nl_connect(struct nl_sock *sk, int protocol)
Create file descriptor and bind socket.
Definition: nl.c:103
void nl_cache_free(struct nl_cache *cache)
Free a cache.
Definition: cache.c:408
int nl_cache_mngr_add_cache_v2(struct nl_cache_mngr *mngr, struct nl_cache *cache, change_func_v2_t cb, void *data)
Add cache to cache manager.
Definition: cache_mngr.c:389
void nl_object_dump(struct nl_object *obj, struct nl_dump_params *params)
Dump this object according to the specified parameters.
Definition: object.c:288
void nl_msg_dump(struct nl_msg *msg, FILE *ofd)
Dump message in human readable format to file descriptor.
Definition: msg.c:973
Skip this message.
Definition: handlers.h:66
void nl_socket_disable_seq_check(struct nl_sock *sk)
Disable sequence number checking.
Definition: socket.c:282
struct nlmsghdr * nlmsg_hdr(struct nl_msg *n)
Return actual netlink message.
Definition: msg.c:540
int nl_socket_set_nonblocking(const struct nl_sock *sk)
Set file descriptor of socket to non-blocking state.
Definition: socket.c:702
void nl_socket_free(struct nl_sock *sk)
Free a netlink socket.
Definition: socket.c:243
struct nl_cache_ops * nl_cache_ops_lookup_safe(const char *name)
Lookup cache operations by name.
Definition: cache_mngt.c:99
void nl_cache_dump(struct nl_cache *cache, struct nl_dump_params *params)
Dump all elements of a cache.
Definition: cache.c:1202
void nl_cache_mngt_unprovide(struct nl_cache *cache)
Unprovide a cache for global use.
Definition: cache_mngt.c:365
Message is valid.
Definition: handlers.h:95
int nl_cache_nitems(struct nl_cache *cache)
Return the number of items in the cache.
Definition: cache.c:68
int nl_cache_mngr_add_cache(struct nl_cache_mngr *mngr, struct nl_cache *cache, change_func_t cb, void *data)
Add cache to cache manager.
Definition: cache_mngr.c:292
int nl_cache_refill(struct nl_sock *sk, struct nl_cache *cache)
(Re)fill a cache with the contents in the kernel.
Definition: cache.c:1040
Proceed with wathever would come next.
Definition: handlers.h:64
int dp_prefix
Specifies the number of whitespaces to be put in front of every new line (indentation).
Definition: types.h:44
int nl_cache_mngr_data_ready(struct nl_cache_mngr *mngr)
Receive available event notifications.
Definition: cache_mngr.c:528
void nl_close(struct nl_sock *sk)
Close Netlink socket.
Definition: nl.c:230
Dumping parameters.
Definition: types.h:33
void nl_cache_mngr_free(struct nl_cache_mngr *mngr)
Free cache manager and all caches.
Definition: cache_mngr.c:603
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 to cache manager.
Definition: cache_mngr.c:427
int nl_recvmsgs_report(struct nl_sock *sk, struct nl_cb *cb)
Receive a set of messages from a netlink socket and report parsed messages.
Definition: nl.c:1052
int nl_debug
Global variable indicating the desired level of debugging output.
Definition: utils.c:53
struct nl_cache * nl_cache_alloc(struct nl_cache_ops *ops)
Allocate new cache.
Definition: cache.c:183