libnl 3.12.0
cache.h
1/* SPDX-License-Identifier: LGPL-2.1-only */
2/*
3 * Copyright (c) 2003-2012 Thomas Graf <tgraf@suug.ch>
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
15extern "C" {
16#endif
17
18enum {
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
30struct nl_cache;
31typedef void (*change_func_t)(struct nl_cache *, struct nl_object *, int, void *);
32typedef 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 */
42extern int nl_cache_nitems(struct nl_cache *);
43extern int nl_cache_nitems_filter(struct nl_cache *,
44 struct nl_object *);
45extern struct nl_cache_ops * nl_cache_get_ops(struct nl_cache *);
46extern struct nl_object * nl_cache_get_first(struct nl_cache *);
47extern struct nl_object * nl_cache_get_last(struct nl_cache *);
48extern struct nl_object * nl_cache_get_next(struct nl_object *);
49extern struct nl_object * nl_cache_get_prev(struct nl_object *);
50
51extern struct nl_cache * nl_cache_alloc(struct nl_cache_ops *);
52extern int nl_cache_alloc_and_fill(struct nl_cache_ops *,
53 struct nl_sock *,
54 struct nl_cache **);
55extern int nl_cache_alloc_name(const char *,
56 struct nl_cache **);
57extern struct nl_cache * nl_cache_subset(struct nl_cache *,
58 struct nl_object *);
59extern struct nl_cache * nl_cache_clone(struct nl_cache *);
60extern void nl_cache_clear(struct nl_cache *);
61extern void nl_cache_get(struct nl_cache *);
62extern void nl_cache_free(struct nl_cache *);
63extern void nl_cache_put(struct nl_cache *cache);
64
65/* Cache modification */
66extern int nl_cache_add(struct nl_cache *,
67 struct nl_object *);
68extern int nl_cache_parse_and_add(struct nl_cache *,
69 struct nl_msg *);
70extern int nl_cache_move(struct nl_cache *,
71 struct nl_object *);
72extern void nl_cache_remove(struct nl_object *);
73extern int nl_cache_refill(struct nl_sock *,
74 struct nl_cache *);
75extern int nl_cache_pickup(struct nl_sock *,
76 struct nl_cache *);
77extern int nl_cache_pickup_checkdup(struct nl_sock *,
78 struct nl_cache *);
79extern int nl_cache_resync(struct nl_sock *,
80 struct nl_cache *,
81 change_func_t,
82 void *);
83extern int nl_cache_resync_v2(struct nl_sock *,
84 struct nl_cache *,
85 change_func_v2_t,
86 void *);
87extern int nl_cache_include(struct nl_cache *,
88 struct nl_object *,
89 change_func_t,
90 void *);
91extern int nl_cache_include_v2(struct nl_cache *,
92 struct nl_object *,
93 change_func_v2_t,
94 void *);
95extern void nl_cache_set_arg1(struct nl_cache *, int);
96extern void nl_cache_set_arg2(struct nl_cache *, int);
97extern void nl_cache_set_flags(struct nl_cache *, unsigned int);
98
99/* General */
100extern int nl_cache_is_empty(struct nl_cache *);
101extern struct nl_object * nl_cache_search(struct nl_cache *,
102 struct nl_object *);
103extern struct nl_object *nl_cache_find(struct nl_cache *,
104 struct nl_object *);
105extern void nl_cache_mark_all(struct nl_cache *);
106
107/* Dumping */
108extern void nl_cache_dump(struct nl_cache *,
109 struct nl_dump_params *);
110extern void nl_cache_dump_filter(struct nl_cache *,
111 struct nl_dump_params *,
112 struct nl_object *);
113
114/* Iterators */
115extern void nl_cache_foreach(struct nl_cache *,
116 void (*cb)(struct nl_object *,
117 void *),
118 void *arg);
119extern 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 */
129extern struct nl_cache_ops * nl_cache_ops_lookup(const char *);
130extern struct nl_cache_ops * nl_cache_ops_lookup_safe(const char *);
131extern struct nl_cache_ops * nl_cache_ops_associate(int, int);
132extern struct nl_cache_ops * nl_cache_ops_associate_safe(int, int);
133extern struct nl_msgtype * nl_msgtype_lookup(struct nl_cache_ops *, int);
134extern void nl_cache_ops_foreach(void (*cb)(struct nl_cache_ops *, void *), void *);
135extern int nl_cache_mngt_register(struct nl_cache_ops *);
136extern int nl_cache_mngt_unregister(struct nl_cache_ops *);
137
138/* Global cache provisioning/requiring */
139extern void nl_cache_mngt_provide(struct nl_cache *);
140extern void nl_cache_mngt_unprovide(struct nl_cache *);
141extern struct nl_cache * nl_cache_mngt_require(const char *);
142extern struct nl_cache * nl_cache_mngt_require_safe(const char *);
143extern struct nl_cache * __nl_cache_mngt_require(const char *);
144
145struct nl_cache_mngr;
146
147#define NL_AUTO_PROVIDE 1
148#define NL_ALLOCATED_SOCK 2 /* For internal use only, do not use */
149
150extern int nl_cache_mngr_alloc(struct nl_sock *,
151 int, int,
152 struct nl_cache_mngr **);
153extern int nl_cache_mngr_alloc_ex(struct nl_sock *,
154 struct nl_sock *,
155 int, int,
156 struct nl_cache_mngr **);
157extern int nl_cache_mngr_add(struct nl_cache_mngr *,
158 const char *,
159 change_func_t,
160 void *,
161 struct nl_cache **);
162extern int nl_cache_mngr_add_cache(struct nl_cache_mngr *mngr,
163 struct nl_cache *cache,
164 change_func_t cb, void *data);
165extern 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);
168extern int nl_cache_mngr_get_fd(struct nl_cache_mngr *);
169extern int nl_cache_mngr_poll(struct nl_cache_mngr *,
170 int);
171extern int nl_cache_mngr_data_ready(struct nl_cache_mngr *);
172extern void nl_cache_mngr_info(struct nl_cache_mngr *,
173 struct nl_dump_params *);
174extern void nl_cache_mngr_free(struct nl_cache_mngr *);
175
176extern void nl_cache_ops_get(struct nl_cache_ops *);
177extern void nl_cache_ops_put(struct nl_cache_ops *);
178extern void nl_cache_ops_set_flags(struct nl_cache_ops *,
179 unsigned int);
180
181#ifdef __cplusplus
182}
183#endif
184
185#endif
int nl_cache_mngr_alloc(struct nl_sock *, int, int, struct nl_cache_mngr **)
Allocate new cache manager.
Definition cache_mngr.c:151
void nl_cache_mngr_free(struct nl_cache_mngr *)
Free cache manager and all caches.
Definition cache_mngr.c:630
void nl_cache_mngr_info(struct nl_cache_mngr *, struct nl_dump_params *)
Print information about cache manager.
Definition cache_mngr.c:591
int nl_cache_mngr_poll(struct nl_cache_mngr *, int)
Check for event notifications.
Definition cache_mngr.c:516
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:412
int nl_cache_mngr_alloc_ex(struct nl_sock *, struct nl_sock *, int, int, struct nl_cache_mngr **)
Allocate new cache manager, with custom callback on refill socket.
Definition cache_mngr.c:168
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:453
int nl_cache_mngr_get_fd(struct nl_cache_mngr *)
Get socket file descriptor.
Definition cache_mngr.c:492
int nl_cache_mngr_data_ready(struct nl_cache_mngr *)
Receive available event notifications.
Definition cache_mngr.c:555
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:314
int nl_cache_mngt_unregister(struct nl_cache_ops *)
Unregister a set of cache operations.
Definition cache_mngt.c:287
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:218
int nl_cache_mngt_register(struct nl_cache_ops *)
Register a set of cache operations.
Definition cache_mngt.c:252
void nl_cache_mngt_unprovide(struct nl_cache *)
Unprovide a cache for global use.
Definition cache_mngt.c:365
void nl_cache_ops_set_flags(struct nl_cache_ops *, unsigned int)
Set default flags for caches of this type.
Definition cache_mngt.c:236
struct nl_cache_ops * nl_cache_ops_associate(int, int)
Associate protocol and message type to cache operations.
Definition cache_mngt.c:140
struct nl_cache * nl_cache_mngt_require(const char *)
Return cache previously provided via nl_cache_mngt_provide()
Definition cache_mngt.c:408
struct nl_cache_ops * nl_cache_ops_lookup(const char *)
Lookup cache operations by name.
Definition cache_mngt.c:79
void nl_cache_mngt_provide(struct nl_cache *)
Provide a cache for global use.
Definition cache_mngt.c:332
void nl_cache_ops_get(struct nl_cache_ops *)
Increment reference counter.
Definition cache_mngt.c:56
struct nl_msgtype * nl_msgtype_lookup(struct nl_cache_ops *, int)
Lookup message type cache association.
Definition cache_mngt.c:189
struct nl_cache * nl_cache_mngt_require_safe(const char *)
Return cache previously provided via nl_cache_mngt_provide()
Definition cache_mngt.c:430
struct nl_cache_ops * nl_cache_ops_lookup_safe(const char *)
Lookup cache operations by name.
Definition cache_mngt.c:99
struct nl_cache_ops * nl_cache_ops_associate_safe(int, int)
Associate protocol and message type to cache operations.
Definition cache_mngt.c:164
void nl_cache_ops_put(struct nl_cache_ops *)
Decrement reference counter.
Definition cache_mngt.c:65
int nl_cache_refill(struct nl_sock *, struct nl_cache *)
(Re)fill a cache with the contents in the kernel.
Definition cache.c:1043
void nl_cache_set_flags(struct nl_cache *, unsigned int)
Set cache flags.
Definition cache.c:608
void nl_cache_set_arg1(struct nl_cache *, int)
Set synchronization arg1 of cache.
Definition cache.c:585
struct nl_object * nl_cache_search(struct nl_cache *, struct nl_object *)
Search object in cache.
Definition cache.c:1116
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:1285
int nl_cache_nitems(struct nl_cache *)
Return the number of items in the cache.
Definition cache.c:70
struct nl_object * nl_cache_find(struct nl_cache *, struct nl_object *)
Find object in cache.
Definition cache.c:1151
void nl_cache_free(struct nl_cache *)
Free a cache.
Definition cache.c:403
void nl_cache_get(struct nl_cache *)
Increase reference counter of cache.
Definition cache.c:386
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:80
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:1219
int nl_cache_add(struct nl_cache *, struct nl_object *)
Add object to cache.
Definition cache.c:474
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:1302
int nl_cache_pickup(struct nl_sock *, struct nl_cache *)
Pickup a netlink dump response and put it into a cache.
Definition cache.c:773
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:1023
struct nl_object * nl_cache_get_last(struct nl_cache *)
Return the last element in the cache.
Definition cache.c:134
struct nl_cache * nl_cache_alloc(struct nl_cache_ops *)
Allocate new cache.
Definition cache.c:185
struct nl_object * nl_cache_get_next(struct nl_object *)
Return the next element in the cache.
Definition cache.c:147
void nl_cache_remove(struct nl_object *)
Remove object from cache.
Definition cache.c:546
void nl_cache_dump(struct nl_cache *, struct nl_dump_params *)
Dump all elements of a cache.
Definition cache.c:1205
int nl_cache_is_empty(struct nl_cache *)
Returns true if the cache is empty.
Definition cache.c:103
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:228
struct nl_object * nl_cache_get_first(struct nl_cache *)
Return the first element in the cache.
Definition cache.c:121
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:758
struct nl_object * nl_cache_get_prev(struct nl_object *)
Return the previous element in the cache.
Definition cache.c:160
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:292
int nl_cache_alloc_name(const char *, struct nl_cache **)
Allocate new cache based on type name.
Definition cache.c:259
void nl_cache_clear(struct nl_cache *)
Remove all objects of a cache.
Definition cache.c:361
struct nl_cache * nl_cache_clone(struct nl_cache *)
Allocate new cache and copy the contents of an existing cache.
Definition cache.c:332
void nl_cache_set_arg2(struct nl_cache *, int)
Set synchronization arg2 of cache.
Definition cache.c:598
struct nl_cache_ops * nl_cache_get_ops(struct nl_cache *)
Return the operations set of the cache.
Definition cache.c:112
int nl_cache_move(struct nl_cache *, struct nl_object *)
Move object from one cache to another.
Definition cache.c:518
void nl_cache_mark_all(struct nl_cache *)
Mark all objects of a cache.
Definition cache.c:1180
Dumping parameters.
Definition types.h:32