cache.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 int nl_cache_move(struct nl_cache *,
  65. struct nl_object *);
  66. extern void nl_cache_remove(struct nl_object *);
  67. extern int nl_cache_refill(struct nl_sock *,
  68. struct nl_cache *);
  69. extern int nl_cache_pickup(struct nl_sock *,
  70. struct nl_cache *);
  71. extern int nl_cache_resync(struct nl_sock *,
  72. struct nl_cache *,
  73. change_func_t,
  74. void *);
  75. extern int nl_cache_include(struct nl_cache *,
  76. struct nl_object *,
  77. change_func_t,
  78. void *);
  79. extern void nl_cache_set_arg1(struct nl_cache *, int);
  80. extern void nl_cache_set_arg2(struct nl_cache *, int);
  81. extern void nl_cache_set_flags(struct nl_cache *, unsigned int);
  82. /* General */
  83. extern int nl_cache_is_empty(struct nl_cache *);
  84. extern struct nl_object * nl_cache_search(struct nl_cache *,
  85. struct nl_object *);
  86. extern struct nl_object *nl_cache_find(struct nl_cache *,
  87. struct nl_object *);
  88. extern void nl_cache_mark_all(struct nl_cache *);
  89. /* Dumping */
  90. extern void nl_cache_dump(struct nl_cache *,
  91. struct nl_dump_params *);
  92. extern void nl_cache_dump_filter(struct nl_cache *,
  93. struct nl_dump_params *,
  94. struct nl_object *);
  95. /* Iterators */
  96. extern void nl_cache_foreach(struct nl_cache *,
  97. void (*cb)(struct nl_object *,
  98. void *),
  99. void *arg);
  100. extern void nl_cache_foreach_filter(struct nl_cache *,
  101. struct nl_object *,
  102. void (*cb)(struct
  103. nl_object *,
  104. void *),
  105. void *arg);
  106. /* --- cache management --- */
  107. /* Cache type management */
  108. extern struct nl_cache_ops * nl_cache_ops_lookup(const char *);
  109. extern struct nl_cache_ops * nl_cache_ops_lookup_safe(const char *);
  110. extern struct nl_cache_ops * nl_cache_ops_associate(int, int);
  111. extern struct nl_cache_ops * nl_cache_ops_associate_safe(int, int);
  112. extern struct nl_msgtype * nl_msgtype_lookup(struct nl_cache_ops *, int);
  113. extern void nl_cache_ops_foreach(void (*cb)(struct nl_cache_ops *, void *), void *);
  114. extern int nl_cache_mngt_register(struct nl_cache_ops *);
  115. extern int nl_cache_mngt_unregister(struct nl_cache_ops *);
  116. /* Global cache provisioning/requiring */
  117. extern void nl_cache_mngt_provide(struct nl_cache *);
  118. extern void nl_cache_mngt_unprovide(struct nl_cache *);
  119. extern struct nl_cache * nl_cache_mngt_require(const char *);
  120. extern struct nl_cache * nl_cache_mngt_require_safe(const char *);
  121. extern struct nl_cache * __nl_cache_mngt_require(const char *);
  122. struct nl_cache_mngr;
  123. #define NL_AUTO_PROVIDE 1
  124. #define NL_ALLOCATED_SOCK 2 /* For internal use only, do not use */
  125. extern int nl_cache_mngr_alloc(struct nl_sock *,
  126. int, int,
  127. struct nl_cache_mngr **);
  128. extern int nl_cache_mngr_add(struct nl_cache_mngr *,
  129. const char *,
  130. change_func_t,
  131. void *,
  132. struct nl_cache **);
  133. extern int nl_cache_mngr_add_cache(struct nl_cache_mngr *mngr,
  134. struct nl_cache *cache,
  135. change_func_t cb, void *data);
  136. extern int nl_cache_mngr_get_fd(struct nl_cache_mngr *);
  137. extern int nl_cache_mngr_poll(struct nl_cache_mngr *,
  138. int);
  139. extern int nl_cache_mngr_data_ready(struct nl_cache_mngr *);
  140. extern void nl_cache_mngr_info(struct nl_cache_mngr *,
  141. struct nl_dump_params *);
  142. extern void nl_cache_mngr_free(struct nl_cache_mngr *);
  143. extern void nl_cache_ops_get(struct nl_cache_ops *);
  144. extern void nl_cache_ops_put(struct nl_cache_ops *);
  145. #ifdef __cplusplus
  146. }
  147. #endif
  148. #endif