• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
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_include(struct nl_cache *,
84 						 struct nl_object *,
85 						 change_func_t,
86 						 void *);
87 extern int			nl_cache_include_v2(struct nl_cache *,
88 						    struct nl_object *,
89 						    change_func_v2_t,
90 						    void *);
91 extern void			nl_cache_set_arg1(struct nl_cache *, int);
92 extern void			nl_cache_set_arg2(struct nl_cache *, int);
93 extern void			nl_cache_set_flags(struct nl_cache *, unsigned int);
94 
95 /* General */
96 extern int			nl_cache_is_empty(struct nl_cache *);
97 extern struct nl_object *	nl_cache_search(struct nl_cache *,
98 						struct nl_object *);
99 extern struct nl_object *nl_cache_find(struct nl_cache *,
100 				       struct nl_object *);
101 extern void			nl_cache_mark_all(struct nl_cache *);
102 
103 /* Dumping */
104 extern void			nl_cache_dump(struct nl_cache *,
105 					      struct nl_dump_params *);
106 extern void			nl_cache_dump_filter(struct nl_cache *,
107 						     struct nl_dump_params *,
108 						     struct nl_object *);
109 
110 /* Iterators */
111 extern void			nl_cache_foreach(struct nl_cache *,
112 						 void (*cb)(struct nl_object *,
113 							    void *),
114 						 void *arg);
115 extern void			nl_cache_foreach_filter(struct nl_cache *,
116 							struct nl_object *,
117 							void (*cb)(struct
118 								   nl_object *,
119 								   void *),
120 							void *arg);
121 
122 /* --- cache management --- */
123 
124 /* Cache type management */
125 extern struct nl_cache_ops *	nl_cache_ops_lookup(const char *);
126 extern struct nl_cache_ops *	nl_cache_ops_lookup_safe(const char *);
127 extern struct nl_cache_ops *	nl_cache_ops_associate(int, int);
128 extern struct nl_cache_ops *	nl_cache_ops_associate_safe(int, int);
129 extern struct nl_msgtype *	nl_msgtype_lookup(struct nl_cache_ops *, int);
130 extern void			nl_cache_ops_foreach(void (*cb)(struct nl_cache_ops *, void *), void *);
131 extern int			nl_cache_mngt_register(struct nl_cache_ops *);
132 extern int			nl_cache_mngt_unregister(struct nl_cache_ops *);
133 
134 /* Global cache provisioning/requiring */
135 extern void			nl_cache_mngt_provide(struct nl_cache *);
136 extern void			nl_cache_mngt_unprovide(struct nl_cache *);
137 extern struct nl_cache *	nl_cache_mngt_require(const char *);
138 extern struct nl_cache *	nl_cache_mngt_require_safe(const char *);
139 extern struct nl_cache *	__nl_cache_mngt_require(const char *);
140 
141 struct nl_cache_mngr;
142 
143 #define NL_AUTO_PROVIDE		1
144 #define NL_ALLOCATED_SOCK	2  /* For internal use only, do not use */
145 
146 extern int			nl_cache_mngr_alloc(struct nl_sock *,
147 						    int, int,
148 						    struct nl_cache_mngr **);
149 extern int			nl_cache_mngr_add(struct nl_cache_mngr *,
150 						  const char *,
151 						  change_func_t,
152 						  void *,
153 						  struct nl_cache **);
154 extern int			nl_cache_mngr_add_cache(struct nl_cache_mngr *mngr,
155 							struct nl_cache *cache,
156 							change_func_t cb, void *data);
157 extern int			nl_cache_mngr_add_cache_v2(struct nl_cache_mngr *mngr,
158 							   struct nl_cache *cache,
159 							   change_func_v2_t cb, void *data);
160 extern int			nl_cache_mngr_get_fd(struct nl_cache_mngr *);
161 extern int			nl_cache_mngr_poll(struct nl_cache_mngr *,
162 						   int);
163 extern int			nl_cache_mngr_data_ready(struct nl_cache_mngr *);
164 extern void			nl_cache_mngr_info(struct nl_cache_mngr *,
165 						   struct nl_dump_params *);
166 extern void			nl_cache_mngr_free(struct nl_cache_mngr *);
167 
168 extern void			nl_cache_ops_get(struct nl_cache_ops *);
169 extern void			nl_cache_ops_put(struct nl_cache_ops *);
170 extern void			nl_cache_ops_set_flags(struct nl_cache_ops *,
171 						       unsigned int);
172 
173 #ifdef __cplusplus
174 }
175 #endif
176 
177 #endif
178