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);
124 size = ops->oo_size - doff;
128 new->ce_ops = obj->ce_ops;
129 new->ce_msgtype = obj->ce_msgtype;
130 new->ce_mask = obj->ce_mask;
133 memcpy((
void *)
new + doff, (
void *)obj + doff, size);
136 if (ops->oo_clone(
new, obj) < 0) {
140 }
else if (size && ops->oo_free_data)
155 struct nl_object_ops *ops = obj_ops(dst);
158 return ops->oo_update(dst, src);
160 return -NLE_OPNOTSUPP;
171 struct nl_object_ops *ops;
178 if (obj->ce_refcnt > 0)
179 NL_DBG(1,
"Warning: Freeing object in use...\n");
184 if (ops->oo_free_data)
185 ops->oo_free_data(obj);
189 NL_DBG(4,
"Freed object %p\n", obj);
206 NL_DBG(4,
"New reference to object %p, total %d\n",
207 obj, obj->ce_refcnt);
220 NL_DBG(4,
"Returned object reference %p, %d remaining\n",
221 obj, obj->ce_refcnt);
223 if (obj->ce_refcnt < 0)
226 if (obj->ce_refcnt <= 0)
237 return obj->ce_refcnt > 1;
253 obj->ce_flags |= NL_OBJ_MARK;
262 obj->ce_flags &= ~NL_OBJ_MARK;
272 return (obj->ce_flags & NL_OBJ_MARK);
292 dump_from_ops(obj, params);
295 void nl_object_dump_buf(
struct nl_object *obj,
char *buf,
size_t len)
314 struct nl_object_ops *ops = obj_ops(a);
318 if (ops != obj_ops(b))
321 if (ops->oo_id_attrs_get) {
322 int req_attrs_a = ops->oo_id_attrs_get(a);
323 int req_attrs_b = ops->oo_id_attrs_get(b);
324 if (req_attrs_a != req_attrs_b)
326 req_attrs = req_attrs_a;
327 }
else if (ops->oo_id_attrs) {
328 req_attrs = ops->oo_id_attrs;
330 req_attrs = 0xFFFFFFFF;
332 if (req_attrs == 0xFFFFFFFF)
333 req_attrs = a->ce_mask & b->ce_mask;
337 if ((a->ce_mask & req_attrs) != req_attrs ||
338 (b->ce_mask & req_attrs) != req_attrs)
342 if (ops->oo_compare == NULL)
345 return !(ops->oo_compare(a, b, req_attrs, 0));
362 struct nl_object_ops *ops = obj_ops(a);
364 if (ops != obj_ops(b) || ops->oo_compare == NULL)
367 return ops->oo_compare(a, b, ~0, 0);
381 struct nl_object_ops *ops = obj_ops(obj);
383 if (ops != obj_ops(filter) || ops->oo_compare == NULL)
386 return !(ops->oo_compare(obj, filter, filter->ce_mask,
403 char *buf,
size_t len)
405 struct nl_object_ops *ops = obj_ops(obj);
407 if (ops->oo_attrs2str != NULL)
408 return ops->oo_attrs2str(attrs, buf, len);
439 struct nl_object_ops *ops = obj_ops(obj);
442 ops->oo_keygen(obj, hashkey, hashtbl_sz);
464 return obj->ce_refcnt;
478 return obj->ce_cache;
494 return obj->ce_ops->oo_name;
505 return obj->ce_msgtype;
527 struct nl_object_ops *ops = obj_ops(obj);
533 if (ops->oo_id_attrs_get)
534 id_attrs = ops->oo_id_attrs_get(obj);
536 id_attrs = ops->oo_id_attrs;