2866280b6173e9135b11318594049cb1c0f75fe5
1 #ifndef __NETIFD_UTILS_H
2 #define __NETIFD_UTILS_H
4 #include <libubox/list.h>
5 #include <libubox/avl.h>
6 #include <libubox/blobmsg.h>
8 static inline bool blobmsg_get_bool_default(struct blob_attr
*attr
, bool val
)
13 return blobmsg_get_bool(attr
);
16 #define __init __attribute__((constructor))
21 typedef void (*vlist_update_cb
)(struct vlist_tree
*tree
,
22 struct vlist_node
*node_new
,
23 struct vlist_node
*node_old
);
28 vlist_update_cb update
;
41 void __vlist_init(struct vlist_tree
*tree
, avl_tree_comp cmp
, vlist_update_cb update
, int offset
);
43 #define vlist_init(tree, cmp, update, type, node, key) \
44 __vlist_init(tree, cmp, update, offsetof(type, key) - offsetof(type, node))
46 #define vlist_find(tree, name, element, node_member) \
47 avl_find_element(&(tree)->avl, name, element, node_member.avl)
49 static inline void vlist_update(struct vlist_tree
*tree
)
54 void vlist_add(struct vlist_tree
*tree
, struct vlist_node
*node
);
55 void vlist_delete(struct vlist_tree
*tree
, struct vlist_node
*node
);
56 void vlist_flush(struct vlist_tree
*tree
);
57 void vlist_flush_all(struct vlist_tree
*tree
);
59 #define vlist_for_each_element(tree, element, node_member) \
60 avl_for_each_element(&(tree)->avl, element, node_member.avl)
63 struct vlist_simple_tree
{
64 struct list_head list
;
69 struct vlist_simple_node
{
70 struct list_head list
;
74 #define vlist_simple_init(tree, node, member) \
75 __vlist_simple_init(tree, offsetof(node, member))
77 void __vlist_simple_init(struct vlist_simple_tree
*tree
, int offset
);
78 void vlist_simple_delete(struct vlist_simple_tree
*tree
, struct vlist_simple_node
*node
);
79 void vlist_simple_flush(struct vlist_simple_tree
*tree
);
80 void vlist_simple_flush_all(struct vlist_simple_tree
*tree
);
82 static inline void vlist_simple_update(struct vlist_simple_tree
*tree
)
87 static inline void vlist_simple_add(struct vlist_simple_tree
*tree
, struct vlist_simple_node
*node
)
89 list_add(&node
->list
, &tree
->list
);
92 #define vlist_simple_for_each_element(tree, element, node_member) \
93 list_for_each_entry(element, &(tree)->list, node_member.list)
95 #define vlist_simple_empty(tree) \
96 list_empty(&(tree)->list)
100 static inline int fls(int x
)
106 if (!(x
& 0xffff0000u
)) {
110 if (!(x
& 0xff000000u
)) {
114 if (!(x
& 0xf0000000u
)) {
118 if (!(x
& 0xc0000000u
)) {
122 if (!(x
& 0x80000000u
)) {
130 int avl_strcmp(const void *k1
, const void *k2
, void *ptr
);