libnl  3.5.0
cache.h
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 typedef void (*change_func_v2_t)(struct nl_cache *, struct nl_object *old_obj,
39  struct nl_object *new_obj, uint64_t, int, void *);
40 
41 /**
42  * @ingroup cache
43  * Explicitely iterate over all address families when updating the cache
44  */
45 #define NL_CACHE_AF_ITER 0x0001
46 
47 /* Access Functions */
48 extern int nl_cache_nitems(struct nl_cache *);
49 extern int nl_cache_nitems_filter(struct nl_cache *,
50  struct nl_object *);
51 extern struct nl_cache_ops * nl_cache_get_ops(struct nl_cache *);
52 extern struct nl_object * nl_cache_get_first(struct nl_cache *);
53 extern struct nl_object * nl_cache_get_last(struct nl_cache *);
54 extern struct nl_object * nl_cache_get_next(struct nl_object *);
55 extern struct nl_object * nl_cache_get_prev(struct nl_object *);
56 
57 extern struct nl_cache * nl_cache_alloc(struct nl_cache_ops *);
58 extern int nl_cache_alloc_and_fill(struct nl_cache_ops *,
59  struct nl_sock *,
60  struct nl_cache **);
61 extern int nl_cache_alloc_name(const char *,
62  struct nl_cache **);
63 extern struct nl_cache * nl_cache_subset(struct nl_cache *,
64  struct nl_object *);
65 extern struct nl_cache * nl_cache_clone(struct nl_cache *);
66 extern void nl_cache_clear(struct nl_cache *);
67 extern void nl_cache_get(struct nl_cache *);
68 extern void nl_cache_free(struct nl_cache *);
69 extern void nl_cache_put(struct nl_cache *cache);
70 
71 /* Cache modification */
72 extern int nl_cache_add(struct nl_cache *,
73  struct nl_object *);
74 extern int nl_cache_parse_and_add(struct nl_cache *,
75  struct nl_msg *);
76 extern int nl_cache_move(struct nl_cache *,
77  struct nl_object *);
78 extern void nl_cache_remove(struct nl_object *);
79 extern int nl_cache_refill(struct nl_sock *,
80  struct nl_cache *);
81 extern int nl_cache_pickup(struct nl_sock *,
82  struct nl_cache *);
83 extern int nl_cache_pickup_checkdup(struct nl_sock *,
84  struct nl_cache *);
85 extern int nl_cache_resync(struct nl_sock *,
86  struct nl_cache *,
87  change_func_t,
88  void *);
89 extern int nl_cache_include(struct nl_cache *,
90  struct nl_object *,
91  change_func_t,
92  void *);
93 extern int nl_cache_include_v2(struct nl_cache *,
94  struct nl_object *,
95  change_func_v2_t,
96  void *);
97 extern void nl_cache_set_arg1(struct nl_cache *, int);
98 extern void nl_cache_set_arg2(struct nl_cache *, int);
99 extern void nl_cache_set_flags(struct nl_cache *, unsigned int);
100 
101 /* General */
102 extern int nl_cache_is_empty(struct nl_cache *);
103 extern struct nl_object * nl_cache_search(struct nl_cache *,
104  struct nl_object *);
105 extern struct nl_object *nl_cache_find(struct nl_cache *,
106  struct nl_object *);
107 extern void nl_cache_mark_all(struct nl_cache *);
108 
109 /* Dumping */
110 extern void nl_cache_dump(struct nl_cache *,
111  struct nl_dump_params *);
112 extern void nl_cache_dump_filter(struct nl_cache *,
113  struct nl_dump_params *,
114  struct nl_object *);
115 
116 /* Iterators */
117 extern void nl_cache_foreach(struct nl_cache *,
118  void (*cb)(struct nl_object *,
119  void *),
120  void *arg);
121 extern void nl_cache_foreach_filter(struct nl_cache *,
122  struct nl_object *,
123  void (*cb)(struct
124  nl_object *,
125  void *),
126  void *arg);
127 
128 /* --- cache management --- */
129 
130 /* Cache type management */
131 extern struct nl_cache_ops * nl_cache_ops_lookup(const char *);
132 extern struct nl_cache_ops * nl_cache_ops_lookup_safe(const char *);
133 extern struct nl_cache_ops * nl_cache_ops_associate(int, int);
134 extern struct nl_cache_ops * nl_cache_ops_associate_safe(int, int);
135 extern struct nl_msgtype * nl_msgtype_lookup(struct nl_cache_ops *, int);
136 extern void nl_cache_ops_foreach(void (*cb)(struct nl_cache_ops *, void *), void *);
137 extern int nl_cache_mngt_register(struct nl_cache_ops *);
138 extern int nl_cache_mngt_unregister(struct nl_cache_ops *);
139 
140 /* Global cache provisioning/requiring */
141 extern void nl_cache_mngt_provide(struct nl_cache *);
142 extern void nl_cache_mngt_unprovide(struct nl_cache *);
143 extern struct nl_cache * nl_cache_mngt_require(const char *);
144 extern struct nl_cache * nl_cache_mngt_require_safe(const char *);
145 extern struct nl_cache * __nl_cache_mngt_require(const char *);
146 
147 struct nl_cache_mngr;
148 
149 #define NL_AUTO_PROVIDE 1
150 #define NL_ALLOCATED_SOCK 2 /* For internal use only, do not use */
151 
152 extern int nl_cache_mngr_alloc(struct nl_sock *,
153  int, int,
154  struct nl_cache_mngr **);
155 extern int nl_cache_mngr_add(struct nl_cache_mngr *,
156  const char *,
157  change_func_t,
158  void *,
159  struct nl_cache **);
160 extern int nl_cache_mngr_add_cache(struct nl_cache_mngr *mngr,
161  struct nl_cache *cache,
162  change_func_t cb, void *data);
163 extern int nl_cache_mngr_add_cache_v2(struct nl_cache_mngr *mngr,
164  struct nl_cache *cache,
165  change_func_v2_t cb, void *data);
166 extern int nl_cache_mngr_get_fd(struct nl_cache_mngr *);
167 extern int nl_cache_mngr_poll(struct nl_cache_mngr *,
168  int);
169 extern int nl_cache_mngr_data_ready(struct nl_cache_mngr *);
170 extern void nl_cache_mngr_info(struct nl_cache_mngr *,
171  struct nl_dump_params *);
172 extern void nl_cache_mngr_free(struct nl_cache_mngr *);
173 
174 extern void nl_cache_ops_get(struct nl_cache_ops *);
175 extern void nl_cache_ops_put(struct nl_cache_ops *);
176 extern void nl_cache_ops_set_flags(struct nl_cache_ops *,
177  unsigned int);
178 
179 #ifdef __cplusplus
180 }
181 #endif
182 
183 #endif
void nl_cache_mngt_provide(struct nl_cache *)
Provide a cache for global use.
Definition: cache_mngt.c:333
void nl_cache_ops_put(struct nl_cache_ops *)
Decrement reference counter.
Definition: cache_mngt.c:66
struct nl_object * nl_cache_get_prev(struct nl_object *)
Return the previous element in the cache.
Definition: cache.c:159
int nl_cache_alloc_name(const char *, struct nl_cache **)
Allocate new cache based on type name.
Definition: cache.c:265
struct nl_cache * nl_cache_subset(struct nl_cache *, struct nl_object *)
Allocate new cache containing a subset of an existing cache.
Definition: cache.c:298
void nl_cache_ops_get(struct nl_cache_ops *)
Increment reference counter.
Definition: cache_mngt.c:57
int nl_cache_mngr_alloc(struct nl_sock *, int, int, struct nl_cache_mngr **)
Allocate new cache manager.
Definition: cache_mngr.c:143
int nl_cache_mngr_get_fd(struct nl_cache_mngr *)
Get socket file descriptor.
Definition: cache_mngr.c:471
int nl_cache_mngt_unregister(struct nl_cache_ops *)
Unregister a set of cache operations.
Definition: cache_mngt.c:288
struct nl_cache * nl_cache_mngt_require_safe(const char *)
Return cache previously provided via nl_cache_mngt_provide()
Definition: cache_mngt.c:431
void nl_cache_get(struct nl_cache *)
Increase reference counter of cache.
Definition: cache.c:392
struct nl_object * nl_cache_find(struct nl_cache *, struct nl_object *)
Find object in cache.
Definition: cache.c:1149
void nl_cache_dump_filter(struct nl_cache *, struct nl_dump_params *, struct nl_object *)
Dump all elements of a cache (filtered).
Definition: cache.c:1217
void nl_cache_mngr_info(struct nl_cache_mngr *, struct nl_dump_params *)
Print information about cache manager.
Definition: cache_mngr.c:570
void nl_cache_foreach_filter(struct nl_cache *, struct nl_object *, void(*cb)(struct nl_object *, void *), void *arg)
Call a callback on each element of the cache (filtered).
Definition: cache.c:1283
struct nl_object * nl_cache_get_last(struct nl_cache *)
Return the last element in the cache.
Definition: cache.c:133
int nl_cache_mngr_poll(struct nl_cache_mngr *, int)
Check for event notifications.
Definition: cache_mngr.c:495
struct nl_cache_ops * nl_cache_ops_lookup(const char *)
Lookup cache operations by name.
Definition: cache_mngt.c:80
int nl_cache_pickup_checkdup(struct nl_sock *, struct nl_cache *)
Pickup a netlink dump response and put it into a cache.
Definition: cache.c:764
void nl_cache_free(struct nl_cache *)
Free a cache.
Definition: cache.c:409
void nl_cache_set_arg1(struct nl_cache *, int)
Set synchronization arg1 of cache.
Definition: cache.c:591
int nl_cache_mngt_register(struct nl_cache_ops *)
Register a set of cache operations.
Definition: cache_mngt.c:253
struct nl_object * nl_cache_search(struct nl_cache *, struct nl_object *)
Search object in cache.
Definition: cache.c:1114
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:391
void nl_cache_foreach(struct nl_cache *, void(*cb)(struct nl_object *, void *), void *arg)
Call a callback on each element of the cache.
Definition: cache.c:1266
void nl_cache_remove(struct nl_object *)
Remove object from cache.
Definition: cache.c:552
struct nl_cache * nl_cache_mngt_require(const char *)
Return cache previously provided via nl_cache_mngt_provide()
Definition: cache_mngt.c:409
int nl_cache_is_empty(struct nl_cache *)
Returns true if the cache is empty.
Definition: cache.c:102
void nl_cache_clear(struct nl_cache *)
Remove all objects of a cache.
Definition: cache.c:367
struct nl_cache_ops * nl_cache_ops_lookup_safe(const char *)
Lookup cache operations by name.
Definition: cache_mngt.c:100
void nl_cache_set_arg2(struct nl_cache *, int)
Set synchronization arg2 of cache.
Definition: cache.c:604
void nl_cache_dump(struct nl_cache *, struct nl_dump_params *)
Dump all elements of a cache.
Definition: cache.c:1203
void nl_cache_mngt_unprovide(struct nl_cache *)
Unprovide a cache for global use.
Definition: cache_mngt.c:366
int nl_cache_parse_and_add(struct nl_cache *, struct nl_msg *)
Parse a netlink message and add it to the cache.
Definition: cache.c:1021
int nl_cache_nitems(struct nl_cache *)
Return the number of items in the cache.
Definition: cache.c:69
void nl_cache_ops_set_flags(struct nl_cache_ops *, unsigned int)
Set default flags for caches of this type.
Definition: cache_mngt.c:237
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:293
struct nl_object * nl_cache_get_next(struct nl_object *)
Return the next element in the cache.
Definition: cache.c:146
int nl_cache_refill(struct nl_sock *, struct nl_cache *)
(Re)fill a cache with the contents in the kernel.
Definition: cache.c:1041
void nl_cache_ops_foreach(void(*cb)(struct nl_cache_ops *, void *), void *)
Call a function for each registered cache operation.
Definition: cache_mngt.c:219
void nl_cache_mark_all(struct nl_cache *)
Mark all objects of a cache.
Definition: cache.c:1178
int nl_cache_move(struct nl_cache *, struct nl_object *)
Move object from one cache to another.
Definition: cache.c:524
int nl_cache_mngr_data_ready(struct nl_cache_mngr *)
Receive available event notifications.
Definition: cache_mngr.c:534
int nl_cache_nitems_filter(struct nl_cache *, struct nl_object *)
Return the number of items matching a filter in the cache.
Definition: cache.c:79
struct nl_cache_ops * nl_cache_ops_associate(int, int)
Associate protocol and message type to cache operations.
Definition: cache_mngt.c:141
Dumping parameters.
Definition: types.h:33
void nl_cache_mngr_free(struct nl_cache_mngr *)
Free cache manager and all caches.
Definition: cache_mngr.c:609
void nl_cache_set_flags(struct nl_cache *, unsigned int)
Set cache flags.
Definition: cache.c:614
struct nl_cache_ops * nl_cache_get_ops(struct nl_cache *)
Return the operations set of the cache.
Definition: cache.c:111
int nl_cache_mngr_add(struct nl_cache_mngr *, const char *, change_func_t, void *, struct nl_cache **)
Add cache to cache manager.
Definition: cache_mngr.c:432
struct nl_cache * nl_cache_clone(struct nl_cache *)
Allocate new cache and copy the contents of an existing cache.
Definition: cache.c:338
int nl_cache_add(struct nl_cache *, struct nl_object *)
Add object to cache.
Definition: cache.c:480
struct nl_msgtype * nl_msgtype_lookup(struct nl_cache_ops *, int)
Lookup message type cache association.
Definition: cache_mngt.c:190
struct nl_cache_ops * nl_cache_ops_associate_safe(int, int)
Associate protocol and message type to cache operations.
Definition: cache_mngt.c:165
struct nl_object * nl_cache_get_first(struct nl_cache *)
Return the first element in the cache.
Definition: cache.c:120
int nl_cache_alloc_and_fill(struct nl_cache_ops *, struct nl_sock *, struct nl_cache **)
Allocate new cache and fill it.
Definition: cache.c:234
struct nl_cache * nl_cache_alloc(struct nl_cache_ops *)
Allocate new cache.
Definition: cache.c:184
int nl_cache_pickup(struct nl_sock *, struct nl_cache *)
Pickup a netlink dump response and put it into a cache.
Definition: cache.c:782