Debian Codegraph @

include/netlink/cache.h

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