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;
char * nl_object_attr_list(struct nl_object *obj, char *buf, size_t len)
Return list of attributes present in an object.
void(* oo_constructor)(struct nl_object *)
Constructor function.
struct nl_object * nl_object_alloc(struct nl_object_ops *ops)
Allocate a new object of kind specified by the operations handle.
size_t oo_size
Size of object including its header.
void nl_object_get(struct nl_object *obj)
Acquire a reference on a object.
int nl_object_shared(struct nl_object *obj)
Check whether this object is used by multiple users.
void nl_object_unmark(struct nl_object *obj)
Remove mark from object.
struct nl_cache_ops * nl_cache_ops_lookup(const char *name)
Lookup cache operations by name.
void(* oo_free_data)(struct nl_object *)
Destructor function.
void nl_object_free(struct nl_object *obj)
Free a cacheable object.
void nl_object_dump(struct nl_object *obj, struct nl_dump_params *params)
Dump this object according to the specified parameters.
void nl_cache_remove(struct nl_object *obj)
Removes an object from a cache.
int(* oo_compare)(struct nl_object *, struct nl_object *, uint32_t, int)
Comparison function.
int(* oo_clone)(struct nl_object *, struct nl_object *)
Cloning function.
void nl_object_put(struct nl_object *obj)
Release a reference from an object.
int nl_object_identical(struct nl_object *a, struct nl_object *b)
Check if the identifiers of two objects are identical.
struct nl_object * nl_object_alloc_name(const char *kind)
Allocate a new object of kind specified by the name.
int nl_object_match_filter(struct nl_object *obj, struct nl_object *filter)
Match a filter against an object.
void nl_object_mark(struct nl_object *obj)
Add mark to object.
struct nl_object * nl_object_clone(struct nl_object *obj)
Allocate a new object and copy all data from an existing object.
int nl_object_is_marked(struct nl_object *obj)
Return true if object is marked.
#define NLHDR_COMMON
Common Object Header.
char * nl_object_attrs2str(struct nl_object *obj, uint32_t attrs, char *buf, size_t len)
Convert bitmask of attributes to a character string.
uint32_t nl_object_diff(struct nl_object *a, struct nl_object *b)
Compute bitmask representing difference in attribute values.