30 #include <netlink-private/netlink.h>
31 #include <netlink/netlink.h>
32 #include <netlink/cache.h>
33 #include <netlink/object.h>
34 #include <netlink/utils.h>
36 static inline struct nl_object_ops *obj_ops(
struct nl_object *obj)
56 struct nl_object *
new;
58 if (ops->oo_size <
sizeof(*
new))
61 new = calloc(1, ops->oo_size);
66 nl_init_list_head(&new->ce_list);
69 if (ops->oo_constructor)
70 ops->oo_constructor(
new);
72 NL_DBG(4,
"Allocated new object %p\n",
new);
86 struct nl_cache_ops *ops;
90 return -NLE_OPNOTSUPP;
112 struct nl_object *
new;
113 struct nl_object_ops *ops = obj_ops(obj);
121 size = ops->oo_size - doff;
125 new->ce_ops = obj->ce_ops;
126 new->ce_msgtype = obj->ce_msgtype;
127 new->ce_mask = obj->ce_mask;
130 memcpy((
void *)
new + doff, (
void *)obj + doff, size);
133 if (ops->oo_clone(
new, obj) < 0) {
137 }
else if (size && ops->oo_free_data)
152 struct nl_object_ops *ops = obj_ops(dst);
155 return ops->oo_update(dst, src);
157 return -NLE_OPNOTSUPP;
168 struct nl_object_ops *ops = obj_ops(obj);
170 if (obj->ce_refcnt > 0)
171 NL_DBG(1,
"Warning: Freeing object in use...\n");
176 if (ops->oo_free_data)
177 ops->oo_free_data(obj);
181 NL_DBG(4,
"Freed object %p\n", obj);
198 NL_DBG(4,
"New reference to object %p, total %d\n",
199 obj, obj->ce_refcnt);
212 NL_DBG(4,
"Returned object reference %p, %d remaining\n",
213 obj, obj->ce_refcnt);
215 if (obj->ce_refcnt < 0)
218 if (obj->ce_refcnt <= 0)
229 return obj->ce_refcnt > 1;
245 obj->ce_flags |= NL_OBJ_MARK;
254 obj->ce_flags &= ~NL_OBJ_MARK;
264 return (obj->ce_flags & NL_OBJ_MARK);
284 dump_from_ops(obj, params);
287 void nl_object_dump_buf(
struct nl_object *obj,
char *buf,
size_t len)
306 struct nl_object_ops *ops = obj_ops(a);
310 if (ops != obj_ops(b))
313 if (ops->oo_id_attrs_get) {
314 int req_attrs_a = ops->oo_id_attrs_get(a);
315 int req_attrs_b = ops->oo_id_attrs_get(b);
316 if (req_attrs_a != req_attrs_b)
318 req_attrs = req_attrs_a;
320 req_attrs = ops->oo_id_attrs;
322 if (req_attrs == 0xFFFFFFFF)
323 req_attrs = a->ce_mask & b->ce_mask;
327 if ((a->ce_mask & req_attrs) != req_attrs ||
328 (b->ce_mask & req_attrs) != req_attrs)
332 if (ops->oo_compare == NULL)
335 return !(ops->oo_compare(a, b, req_attrs, 0));
352 struct nl_object_ops *ops = obj_ops(a);
354 if (ops != obj_ops(b) || ops->oo_compare == NULL)
357 return ops->oo_compare(a, b, ~0, 0);
371 struct nl_object_ops *ops = obj_ops(obj);
373 if (ops != obj_ops(filter) || ops->oo_compare == NULL)
376 return !(ops->oo_compare(obj, filter, filter->ce_mask,
393 char *buf,
size_t len)
395 struct nl_object_ops *ops = obj_ops(obj);
397 if (ops->oo_attrs2str != NULL)
398 return ops->oo_attrs2str(attrs, buf, len);
429 struct nl_object_ops *ops = obj_ops(obj);
432 ops->oo_keygen(obj, hashkey, hashtbl_sz);
454 return obj->ce_refcnt;
468 return obj->ce_cache;
484 return obj->ce_ops->oo_name;
495 return obj->ce_msgtype;
517 struct nl_object_ops *ops = obj_ops(obj);
523 if (ops->oo_id_attrs_get)
524 id_attrs = ops->oo_id_attrs_get(obj);
526 id_attrs = ops->oo_id_attrs;