12 #ifndef NETLINK_LIST_H_ 13 #define NETLINK_LIST_H_ 23 static inline void NL_INIT_LIST_HEAD(
struct nl_list_head *list)
29 static inline void __nl_list_add(
struct nl_list_head *obj,
39 static inline void nl_list_add_tail(
struct nl_list_head *obj,
42 __nl_list_add(obj, head->prev, head);
45 static inline void nl_list_add_head(
struct nl_list_head *obj,
48 __nl_list_add(obj, head, head->next);
53 obj->next->prev = obj->prev;
54 obj->prev->next = obj->next;
57 static inline int nl_list_empty(
struct nl_list_head *head)
59 return head->next == head;
62 #define nl_container_of(ptr, type, member) ({ \ 63 const __typeof__( ((type *)0)->member ) *__mptr = (ptr);\ 64 (type *)( (char *)__mptr - (offsetof(type, member)));}) 66 #define nl_list_entry(ptr, type, member) \ 67 nl_container_of(ptr, type, member) 69 #define nl_list_at_tail(pos, head, member) \ 70 ((pos)->member.next == (head)) 72 #define nl_list_at_head(pos, head, member) \ 73 ((pos)->member.prev == (head)) 75 #define NL_LIST_HEAD(name) \ 76 struct nl_list_head name = { &(name), &(name) } 78 #define nl_list_first_entry(head, type, member) \ 79 nl_list_entry((head)->next, type, member) 81 #define nl_list_for_each_entry(pos, head, member) \ 82 for (pos = nl_list_entry((head)->next, __typeof__(*pos), member); \ 83 &(pos)->member != (head); \ 84 (pos) = nl_list_entry((pos)->member.next, __typeof__(*(pos)), member)) 86 #define nl_list_for_each_entry_safe(pos, n, head, member) \ 87 for (pos = nl_list_entry((head)->next, __typeof__(*pos), member), \ 88 n = nl_list_entry(pos->member.next, __typeof__(*pos), member); \ 89 &(pos)->member != (head); \ 90 pos = n, n = nl_list_entry(n->member.next, __typeof__(*n), member)) 92 #define nl_init_list_head(head) \ 93 do { (head)->next = (head); (head)->prev = (head); } while (0)