libnl  3.4.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  for (i = 0; i < mngr->cm_nassocs; i++)
315  if (!mngr->cm_assocs[i].ca_cache)
316  break;
317 
318  if (i >= mngr->cm_nassocs) {
319  struct nl_cache_assoc *cm_assocs;
320  int cm_nassocs = mngr->cm_nassocs + NASSOC_EXPAND;
321 
322  cm_assocs = realloc(mngr->cm_assocs,
323  cm_nassocs * sizeof(struct nl_cache_assoc));
324  if (cm_assocs == NULL)
325  return -NLE_NOMEM;
326 
327  memset(cm_assocs + mngr->cm_nassocs, 0,
328  NASSOC_EXPAND * sizeof(struct nl_cache_assoc));
329  mngr->cm_assocs = cm_assocs;
330  mngr->cm_nassocs = cm_nassocs;
331 
332  NL_DBG(1, "Increased capacity of cache manager %p " \
333  "to %d\n", mngr, mngr->cm_nassocs);
334  }
335 
336  for (grp = ops->co_groups; grp->ag_group; grp++) {
337  err = nl_socket_add_membership(mngr->cm_sock, grp->ag_group);
338  if (err < 0)
339  return err;
340  }
341 
342  err = nl_cache_refill(mngr->cm_sync_sock, cache);
343  if (err < 0)
344  goto errout_drop_membership;
345 
346  mngr->cm_assocs[i].ca_cache = cache;
347  mngr->cm_assocs[i].ca_change = cb;
348  mngr->cm_assocs[i].ca_change_data = data;
349 
350  if (mngr->cm_flags & NL_AUTO_PROVIDE)
351  nl_cache_mngt_provide(cache);
352 
353  NL_DBG(1, "Added cache %p <%s> to cache manager %p\n",
354  cache, nl_cache_name(cache), mngr);
355 
356  return 0;
357 
358 errout_drop_membership:
359  for (grp = ops->co_groups; grp->ag_group; grp++)
360  nl_socket_drop_membership(mngr->cm_sock, grp->ag_group);
361 
362  return err;
363 }
364 
365 /**
366  * Add cache to cache manager
367  * @arg mngr Cache manager.
368  * @arg cache Cache to be added to cache manager
369  * @arg cb V2 function to be called upon changes.
370  * @arg data Argument passed on to change callback
371  *
372  * Adds cache to the manager. The operation will trigger a full
373  * dump request from the kernel to initially fill the contents
374  * of the cache. The manager will subscribe to the notification group
375  * of the cache and keep track of any further changes.
376  *
377  * The user is responsible for calling nl_cache_mngr_poll() or monitor
378  * the socket and call nl_cache_mngr_data_ready() to allow the library
379  * to process netlink notification events.
380  *
381  * @see nl_cache_mngr_poll()
382  * @see nl_cache_mngr_data_ready()
383  *
384  * @return 0 on success or a negative error code.
385  * @return -NLE_PROTO_MISMATCH Protocol mismatch between cache manager and
386  * cache type
387  * @return -NLE_OPNOTSUPP Cache type does not support updates
388  * @return -NLE_EXIST Cache of this type already being managed
389  */
390 int nl_cache_mngr_add_cache_v2(struct nl_cache_mngr *mngr, struct nl_cache *cache,
391  change_func_v2_t cb, void *data) {
392  int err;
393  err = nl_cache_mngr_add_cache(mngr, cache, NULL, NULL);
394  if (err < 0)
395  return err;
396 
397  return nl_cache_mngr_set_change_func_v2(mngr, cache, cb, data);
398 }
399 
400 /**
401  * Add cache to cache manager
402  * @arg mngr Cache manager.
403  * @arg name Name of cache to keep track of
404  * @arg cb Function to be called upon changes.
405  * @arg data Argument passed on to change callback
406  * @arg result Pointer to store added cache (optional)
407  *
408  * Allocates a new cache of the specified type and adds it to the manager.
409  * The operation will trigger a full dump request from the kernel to
410  * initially fill the contents of the cache. The manager will subscribe
411  * to the notification group of the cache and keep track of any further
412  * changes.
413  *
414  * The user is responsible for calling nl_cache_mngr_poll() or monitor
415  * the socket and call nl_cache_mngr_data_ready() to allow the library
416  * to process netlink notification events.
417  *
418  * @see nl_cache_mngr_poll()
419  * @see nl_cache_mngr_data_ready()
420  *
421  * @return 0 on success or a negative error code.
422  * @return -NLE_NOCACHE Unknown cache type
423  * @return -NLE_PROTO_MISMATCH Protocol mismatch between cache manager and
424  * cache type
425  * @return -NLE_OPNOTSUPP Cache type does not support updates
426  * @return -NLE_EXIST Cache of this type already being managed
427  */
428 int nl_cache_mngr_add(struct nl_cache_mngr *mngr, const char *name,
429  change_func_t cb, void *data, struct nl_cache **result)
430 {
431  struct nl_cache_ops *ops;
432  struct nl_cache *cache;
433  int err;
434 
435  ops = nl_cache_ops_lookup_safe(name);
436  if (!ops)
437  return -NLE_NOCACHE;
438 
439  cache = nl_cache_alloc(ops);
440  nl_cache_ops_put(ops);
441  if (!cache)
442  return -NLE_NOMEM;
443 
444  err = nl_cache_mngr_add_cache(mngr, cache, cb, data);
445  if (err < 0)
446  goto errout_free_cache;
447 
448  *result = cache;
449  return 0;
450 
451 errout_free_cache:
452  nl_cache_free(cache);
453 
454  return err;
455 }
456 
457 /**
458  * Get socket file descriptor
459  * @arg mngr Cache Manager
460  *
461  * Get the file descriptor of the socket associated with the manager.
462  *
463  * @note Do not use the socket for anything besides receiving
464  * notifications.
465  */
466 int nl_cache_mngr_get_fd(struct nl_cache_mngr *mngr)
467 {
468  return nl_socket_get_fd(mngr->cm_sock);
469 }
470 
471 /**
472  * Check for event notifications
473  * @arg mngr Cache Manager
474  * @arg timeout Upper limit poll() will block, in milliseconds.
475  *
476  * Causes poll() to be called to check for new event notifications
477  * being available. Calls nl_cache_mngr_data_ready() to process
478  * available data.
479  *
480  * This functionally is ideally called regularly during an idle
481  * period.
482  *
483  * A timeout can be specified in milliseconds to limit the time the
484  * function will wait for updates.
485  *
486  * @see nl_cache_mngr_data_ready()
487  *
488  * @return The number of messages processed or a negative error code.
489  */
490 int nl_cache_mngr_poll(struct nl_cache_mngr *mngr, int timeout)
491 {
492  int ret;
493  struct pollfd fds = {
494  .fd = nl_socket_get_fd(mngr->cm_sock),
495  .events = POLLIN,
496  };
497 
498  NL_DBG(3, "Cache manager %p, poll() fd %d\n", mngr, fds.fd);
499  ret = poll(&fds, 1, timeout);
500  NL_DBG(3, "Cache manager %p, poll() returned %d\n", mngr, ret);
501  if (ret < 0) {
502  NL_DBG(4, "nl_cache_mngr_poll(%p): poll() failed with %d (%s)\n",
503  mngr, errno, nl_strerror_l(errno));
504  return -nl_syserr2nlerr(errno);
505  }
506 
507  /* No events, return */
508  if (ret == 0)
509  return 0;
510 
511  return nl_cache_mngr_data_ready(mngr);
512 }
513 
514 /**
515  * Receive available event notifications
516  * @arg mngr Cache manager
517  *
518  * This function can be called if the socket associated to the manager
519  * contains updates to be received. This function should only be used
520  * if nl_cache_mngr_poll() is not used.
521  *
522  * The function will process messages until there is no more data to
523  * be read from the socket.
524  *
525  * @see nl_cache_mngr_poll()
526  *
527  * @return The number of messages processed or a negative error code.
528  */
529 int nl_cache_mngr_data_ready(struct nl_cache_mngr *mngr)
530 {
531  int err, nread = 0;
532  struct nl_cb *cb;
533 
534  NL_DBG(2, "Cache manager %p, reading new data from fd %d\n",
535  mngr, nl_socket_get_fd(mngr->cm_sock));
536 
537  cb = nl_cb_clone(mngr->cm_sock->s_cb);
538  if (cb == NULL)
539  return -NLE_NOMEM;
540 
541  nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, event_input, mngr);
542 
543  while ((err = nl_recvmsgs_report(mngr->cm_sock, cb)) > 0) {
544  NL_DBG(2, "Cache manager %p, recvmsgs read %d messages\n",
545  mngr, err);
546  nread += err;
547  }
548 
549  nl_cb_put(cb);
550  if (err < 0 && err != -NLE_AGAIN)
551  return err;
552 
553  return nread;
554 }
555 
556 /**
557  * Print information about cache manager
558  * @arg mngr Cache manager
559  * @arg p Dumping parameters
560  *
561  * Prints information about the cache manager including all managed caches.
562  *
563  * @note This is a debugging function.
564  */
565 void nl_cache_mngr_info(struct nl_cache_mngr *mngr, struct nl_dump_params *p)
566 {
567  char buf[128];
568  int i;
569 
570  nl_dump_line(p, "cache-manager <%p>\n", mngr);
571  nl_dump_line(p, " .protocol = %s\n",
572  nl_nlfamily2str(mngr->cm_protocol, buf, sizeof(buf)));
573  nl_dump_line(p, " .flags = %#x\n", mngr->cm_flags);
574  nl_dump_line(p, " .nassocs = %u\n", mngr->cm_nassocs);
575  nl_dump_line(p, " .sock = <%p>\n", mngr->cm_sock);
576 
577  for (i = 0; i < mngr->cm_nassocs; i++) {
578  struct nl_cache_assoc *assoc = &mngr->cm_assocs[i];
579 
580  if (assoc->ca_cache) {
581  nl_dump_line(p, " .cache[%d] = <%p> {\n", i, assoc->ca_cache);
582  nl_dump_line(p, " .name = %s\n", assoc->ca_cache->c_ops->co_name);
583  nl_dump_line(p, " .change_func = <%p>\n", assoc->ca_change);
584  nl_dump_line(p, " .change_data = <%p>\n", assoc->ca_change_data);
585  nl_dump_line(p, " .nitems = %u\n", nl_cache_nitems(assoc->ca_cache));
586  nl_dump_line(p, " .objects = {\n");
587 
588  p->dp_prefix += 6;
589  nl_cache_dump(assoc->ca_cache, p);
590  p->dp_prefix -= 6;
591 
592  nl_dump_line(p, " }\n");
593  nl_dump_line(p, " }\n");
594  }
595  }
596 }
597 
598 /**
599  * Free cache manager and all caches.
600  * @arg mngr Cache manager.
601  *
602  * Release all resources held by a cache manager.
603  */
604 void nl_cache_mngr_free(struct nl_cache_mngr *mngr)
605 {
606  int i;
607 
608  if (!mngr)
609  return;
610 
611  if (mngr->cm_sock)
612  nl_close(mngr->cm_sock);
613 
614  if (mngr->cm_sync_sock) {
615  nl_close(mngr->cm_sync_sock);
616  nl_socket_free(mngr->cm_sync_sock);
617  }
618 
619  if (mngr->cm_flags & NL_ALLOCATED_SOCK)
620  nl_socket_free(mngr->cm_sock);
621 
622  for (i = 0; i < mngr->cm_nassocs; i++) {
623  if (mngr->cm_assocs[i].ca_cache) {
624  nl_cache_mngt_unprovide(mngr->cm_assocs[i].ca_cache);
625  nl_cache_free(mngr->cm_assocs[i].ca_cache);
626  }
627  }
628 
629  free(mngr->cm_assocs);
630 
631  NL_DBG(1, "Cache manager %p freed\n", mngr);
632 
633  free(mngr);
634 }
635 
636 /** @} */
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:466
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:565
int nl_cache_mngr_poll(struct nl_cache_mngr *mngr, int timeout)
Check for event notifications.
Definition: cache_mngr.c:490
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:390
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:529
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:604
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:428
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