28 #include <netlink-local.h>
29 #include <netlink/netlink.h>
30 #include <netlink/cache.h>
31 #include <netlink/utils.h>
34 static NL_RW_LOCK(cache_ops_lock);
41 struct nl_cache_ops *__nl_cache_ops_lookup(
const char *name)
45 for (ops = cache_ops; ops; ops = ops->
co_next)
46 if (!strcmp(ops->
co_name, name))
83 nl_read_lock(&cache_ops_lock);
84 ops = __nl_cache_ops_lookup(name);
85 nl_read_unlock(&cache_ops_lock);
103 nl_write_lock(&cache_ops_lock);
104 if ((ops = __nl_cache_ops_lookup(name)))
106 nl_write_unlock(&cache_ops_lock);
111 static struct nl_cache_ops *__cache_ops_associate(
int protocol,
int msgtype)
116 for (ops = cache_ops; ops; ops = ops->
co_next) {
120 for (i = 0; ops->co_msgtypes[i].
mt_id >= 0; i++)
121 if (ops->co_msgtypes[i].
mt_id == msgtype)
144 nl_read_lock(&cache_ops_lock);
145 ops = __cache_ops_associate(protocol, msgtype);
146 nl_read_unlock(&cache_ops_lock);
168 nl_write_lock(&cache_ops_lock);
169 if ((ops = __cache_ops_associate(protocol, msgtype)))
171 nl_write_unlock(&cache_ops_lock);
193 for (i = 0; ops->co_msgtypes[i].
mt_id >= 0; i++)
194 if (ops->co_msgtypes[i].
mt_id == msgtype)
195 return &ops->co_msgtypes[i];
205 for (ops = cache_ops; ops; ops = ops->
co_next)
222 nl_read_lock(&cache_ops_lock);
223 for (ops = cache_ops; ops; ops = ops->
co_next)
225 nl_read_unlock(&cache_ops_lock);
238 nl_write_lock(&cache_ops_lock);
240 nl_write_unlock(&cache_ops_lock);
257 nl_write_lock(&cache_ops_lock);
258 if (__nl_cache_ops_lookup(ops->
co_name)) {
259 nl_write_unlock(&cache_ops_lock);
266 nl_write_unlock(&cache_ops_lock);
268 NL_DBG(1,
"Registered cache operations %s\n", ops->
co_name);
289 nl_write_lock(&cache_ops_lock);
296 for (tp = &cache_ops; (t=*tp) != NULL; tp = &t->
co_next)
305 NL_DBG(1,
"Unregistered cache operations %s\n", ops->
co_name);
309 nl_write_unlock(&cache_ops_lock);
333 nl_write_lock(&cache_ops_lock);
335 ops = cache_ops_lookup_for_obj(cache->c_ops->co_obj_ops);
345 if (!ops->co_major_cache)
348 ops->co_major_cache = cache;
351 nl_write_unlock(&cache_ops_lock);
366 nl_write_lock(&cache_ops_lock);
368 ops = cache_ops_lookup_for_obj(cache->c_ops->co_obj_ops);
371 else if (ops->co_major_cache == cache) {
374 ops->co_major_cache = NULL;
377 nl_write_unlock(&cache_ops_lock);
380 struct nl_cache *__nl_cache_mngt_require(
const char *name)
383 struct nl_cache *cache = NULL;
387 cache = ops->co_major_cache;
407 struct nl_cache *cache;
409 if (!(cache = __nl_cache_mngt_require(name)))
410 NL_DBG(1,
"Application BUG: Your application must "
411 "call nl_cache_mngt_provide() and\nprovide a valid "
412 "%s cache to be used for internal lookups.\nSee the "
413 " API documentation for more details.\n", name);
429 struct nl_cache *cache;