cache.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * netlink/cache.h Caching Module
  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. #ifndef NETLINK_CACHE_H_
  12. #define NETLINK_CACHE_H_
  13. #include <netlink/netlink.h>
  14. #include <netlink/msg.h>
  15. #include <netlink/utils.h>
  16. #include <netlink/object.h>
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. enum {
  21. NL_ACT_UNSPEC,
  22. NL_ACT_NEW,
  23. NL_ACT_DEL,
  24. NL_ACT_GET,
  25. NL_ACT_SET,
  26. NL_ACT_CHANGE,
  27. __NL_ACT_MAX,
  28. };
  29. #define NL_ACT_MAX (__NL_ACT_MAX - 1)
  30. struct nl_cache;
  31. typedef void (*change_func_t)(struct nl_cache *, struct nl_object *, int, void *);
  32. /**
  33. * @ingroup cache
  34. * Explicitely iterate over all address families when updating the cache
  35. */
  36. #define NL_CACHE_AF_ITER 0x0001
  37. /* Access Functions */
  38. extern int nl_cache_nitems(struct nl_cache *);
  39. extern int nl_cache_nitems_filter(struct nl_cache *,
  40. struct nl_object *);
  41. extern struct nl_cache_ops * nl_cache_get_ops(struct nl_cache *);
  42. extern struct nl_object * nl_cache_get_first(struct nl_cache *);
  43. extern struct nl_object * nl_cache_get_last(struct nl_cache *);
  44. extern struct nl_object * nl_cache_get_next(struct nl_object *);
  45. extern struct nl_object * nl_cache_get_prev(struct nl_object *);
  46. extern struct nl_cache * nl_cache_alloc(struct nl_cache_ops *);
  47. extern int nl_cache_alloc_and_fill(struct nl_cache_ops *,
  48. struct nl_sock *,
  49. struct nl_cache **);
  50. extern int nl_cache_alloc_name(const char *,
  51. struct nl_cache **);
  52. extern struct nl_cache * nl_cache_subset(struct nl_cache *,
  53. struct nl_object *);
  54. extern struct nl_cache * nl_cache_clone(struct nl_cache *);
  55. extern void nl_cache_clear(struct nl_cache *);
  56. extern void nl_cache_get(struct nl_cache *);
  57. extern void nl_cache_free(struct nl_cache *);
  58. extern void nl_cache_put(struct nl_cache *cache);
  59. /* Cache modification */
  60. extern int nl_cache_add(struct nl_cache *,
  61. struct nl_object *);
  62. extern int nl_cache_parse_and_add(struct nl_cache *,
  63. struct nl_msg *);
  64. extern void nl_cache_remove(struct nl_object *);
  65. extern int nl_cache_refill(struct nl_sock *,
  66. struct nl_cache *);
  67. extern int nl_cache_pickup(struct nl_sock *,
  68. struct nl_cache *);
  69. extern int nl_cache_resync(struct nl_sock *,
  70. struct nl_cache *,
  71. change_func_t,
  72. void *);
  73. extern int nl_cache_include(struct nl_cache *,
  74. struct nl_object *,
  75. change_func_t,
  76. void *);
  77. extern void nl_cache_set_arg1(struct nl_cache *, int);
  78. extern void nl_cache_set_arg2(struct nl_cache *, int);
  79. extern void nl_cache_set_flags(struct nl_cache *, unsigned int);
  80. /* General */
  81. extern int nl_cache_is_empty(struct nl_cache *);
  82. extern struct nl_object * nl_cache_search(struct nl_cache *,
  83. struct nl_object *);
  84. extern struct nl_object * nl_cache_lookup(struct nl_cache *,
  85. struct nl_object *);
  86. extern void nl_cache_mark_all(struct nl_cache *);
  87. /* Dumping */
  88. extern void nl_cache_dump(struct nl_cache *,
  89. struct nl_dump_params *);
  90. extern void nl_cache_dump_filter(struct nl_cache *,
  91. struct nl_dump_params *,
  92. struct nl_object *);
  93. /* Iterators */
  94. extern void nl_cache_foreach(struct nl_cache *,
  95. void (*cb)(struct nl_object *,
  96. void *),
  97. void *arg);
  98. extern void nl_cache_foreach_filter(struct nl_cache *,
  99. struct nl_object *,
  100. void (*cb)(struct
  101. nl_object *,
  102. void *),
  103. void *arg);
  104. /* --- cache management --- */
  105. /* Cache type management */
  106. extern struct nl_cache_ops * nl_cache_ops_lookup(const char *);
  107. extern struct nl_cache_ops * nl_cache_ops_lookup_safe(const char *);
  108. extern struct nl_cache_ops * nl_cache_ops_associate(int, int);
  109. extern struct nl_cache_ops * nl_cache_ops_associate_safe(int, int);
  110. extern struct nl_msgtype * nl_msgtype_lookup(struct nl_cache_ops *, int);
  111. extern void nl_cache_ops_foreach(void (*cb)(struct nl_cache_ops *, void *), void *);
  112. extern int nl_cache_mngt_register(struct nl_cache_ops *);
  113. extern int nl_cache_mngt_unregister(struct nl_cache_ops *);
  114. /* Global cache provisioning/requiring */
  115. extern void nl_cache_mngt_provide(struct nl_cache *);
  116. extern void nl_cache_mngt_unprovide(struct nl_cache *);
  117. extern struct nl_cache * nl_cache_mngt_require(const char *);
  118. extern struct nl_cache * nl_cache_mngt_require_safe(const char *);
  119. extern struct nl_cache * __nl_cache_mngt_require(const char *);
  120. struct nl_cache_mngr;
  121. #define NL_AUTO_PROVIDE 1
  122. #define NL_ALLOCATED_SOCK 2 /* For internal use only, do not use */
  123. extern int nl_cache_mngr_alloc(struct nl_sock *,
  124. int, int,
  125. struct nl_cache_mngr **);
  126. extern int nl_cache_mngr_add(struct nl_cache_mngr *,
  127. const char *,
  128. change_func_t,
  129. void *,
  130. struct nl_cache **);
  131. extern int nl_cache_mngr_add_cache(struct nl_cache_mngr *mngr,
  132. struct nl_cache *cache,
  133. change_func_t cb, void *data);
  134. extern int nl_cache_mngr_get_fd(struct nl_cache_mngr *);
  135. extern int nl_cache_mngr_poll(struct nl_cache_mngr *,
  136. int);
  137. extern int nl_cache_mngr_data_ready(struct nl_cache_mngr *);
  138. extern void nl_cache_mngr_info(struct nl_cache_mngr *,
  139. struct nl_dump_params *);
  140. extern void nl_cache_mngr_free(struct nl_cache_mngr *);
  141. extern void nl_cache_ops_get(struct nl_cache_ops *);
  142. extern void nl_cache_ops_put(struct nl_cache_ops *);
  143. #ifdef __cplusplus
  144. }
  145. #endif
  146. #endif