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