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);
255 nl_write_lock(&cache_ops_lock);
256 if (__nl_cache_ops_lookup(ops->
co_name)) {
257 nl_write_unlock(&cache_ops_lock);
264 nl_write_unlock(&cache_ops_lock);
266 NL_DBG(1,
"Registered cache operations %s\n", ops->
co_name);
287 nl_write_lock(&cache_ops_lock);
294 for (tp = &cache_ops; (t=*tp) != NULL; tp = &t->
co_next)
303 NL_DBG(1,
"Unregistered cache operations %s\n", ops->
co_name);
307 nl_write_unlock(&cache_ops_lock);
331 nl_write_lock(&cache_ops_lock);
333 ops = cache_ops_lookup_for_obj(cache->c_ops->co_obj_ops);
343 if (!ops->co_major_cache)
346 ops->co_major_cache = cache;
349 nl_write_unlock(&cache_ops_lock);
364 nl_write_lock(&cache_ops_lock);
366 ops = cache_ops_lookup_for_obj(cache->c_ops->co_obj_ops);
369 else if (ops->co_major_cache == cache) {
372 ops->co_major_cache = NULL;
375 nl_write_unlock(&cache_ops_lock);
378 struct nl_cache *__nl_cache_mngt_require(
const char *name)
381 struct nl_cache *cache = NULL;
385 cache = ops->co_major_cache;
405 struct nl_cache *cache;
407 if (!(cache = __nl_cache_mngt_require(name)))
408 NL_DBG(1,
"Application BUG: Your application must "
409 "call nl_cache_mngt_provide() and\nprovide a valid "
410 "%s cache to be used for internal lookups.\nSee the "
411 " API documentation for more details.\n", name);
427 struct nl_cache *cache;