18 #include <netlink-local.h>
19 #include <netlink/netlink.h>
20 #include <netlink/cache.h>
21 #include <netlink/object.h>
22 #include <netlink/utils.h>
24 static inline struct nl_object_ops *obj_ops(
struct nl_object *obj)
44 struct nl_object *
new;
46 if (ops->
oo_size <
sizeof(*
new))
56 nl_init_list_head(&new->ce_list);
62 NL_DBG(4,
"Allocated new object %p\n",
new);
78 nl_error(ENOENT,
"Unable to lookup cache kind \"%s\"", kind);
97 struct nl_object *
new;
110 new->ce_ops = obj->ce_ops;
111 new->ce_msgtype = obj->ce_msgtype;
114 memcpy((
void *)
new + doff, (
void *)obj + doff, size);
142 if (obj->ce_refcnt > 0)
143 NL_DBG(1,
"Warning: Freeing object in use...\n");
153 NL_DBG(4,
"Freed object %p\n", obj);
170 NL_DBG(4,
"New reference to object %p, total %d\n",
171 obj, obj->ce_refcnt);
184 NL_DBG(4,
"Returned object reference %p, %d remaining\n",
185 obj, obj->ce_refcnt);
187 if (obj->ce_refcnt < 0)
190 if (obj->ce_refcnt <= 0)
201 return obj->ce_refcnt > 1;
217 obj->ce_flags |= NL_OBJ_MARK;
226 obj->ce_flags &= ~NL_OBJ_MARK;
236 return (obj->ce_flags & NL_OBJ_MARK);
253 dump_from_ops(obj, params);
269 if (ops != obj_ops(b))
272 req_attrs = ops->oo_id_attrs;
276 if ((a->ce_mask & req_attrs) != req_attrs ||
277 (b->ce_mask & req_attrs) != req_attrs)
284 return !(ops->
oo_compare(a, b, req_attrs, 0));
303 if (ops != obj_ops(b) || ops->
oo_compare == NULL)
322 if (ops != obj_ops(filter) || ops->
oo_compare == NULL)
325 return !(ops->
oo_compare(obj, filter, filter->ce_mask,
326 LOOSE_FLAG_COMPARISON));
342 char *buf,
size_t len)
346 if (ops->oo_attrs2str != NULL)
347 return ops->oo_attrs2str(attrs, buf, len);
374 int nl_object_get_refcnt(
struct nl_object *obj)
376 return obj->ce_refcnt;
379 struct nl_cache *nl_object_get_cache(
struct nl_object *obj)
381 return obj->ce_cache;