Skip to content

Commit f9383d7

Browse files
committed
misc: add more list methods
The following methods are added: - nl_list_insert_before - nl_list_insert_after - nl_list_insert_list_after - nl_list_join - nl_list_last_entry - nl_list_for_each_entry_reverse - nl_list_for_each_entry_safe_reverse These methods are added to support an upcoming patch implementing bridge vlan support which requires additional list operations to be available.
1 parent bdfdf73 commit f9383d7

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

include/netlink/list.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,35 @@ static inline void nl_list_add_head(struct nl_list_head *obj,
4646
__nl_list_add(obj, head, head->next);
4747
}
4848

49+
static inline void nl_list_insert_before(struct nl_list_head *obj,
50+
struct nl_list_head *ref)
51+
{
52+
__nl_list_add(obj, ref->prev, ref);
53+
}
54+
55+
static inline void nl_list_insert_after(struct nl_list_head *obj,
56+
struct nl_list_head *ref)
57+
{
58+
__nl_list_add(obj, ref, ref->next);
59+
}
60+
61+
static inline void nl_list_insert_list_after(struct nl_list_head *head,
62+
struct nl_list_head *ref)
63+
{
64+
ref->next->prev = head->prev;
65+
head->prev->next = ref->next;
66+
ref->next = head->next;
67+
head->next->prev = ref;
68+
head->next = head;
69+
head->prev = head;
70+
}
71+
72+
static inline void nl_list_join(struct nl_list_head *head_1,
73+
struct nl_list_head *head_2)
74+
{
75+
nl_list_insert_list_after(head_2, head_1->prev);
76+
}
77+
4978
static inline void nl_list_del(struct nl_list_head *obj)
5079
{
5180
obj->next->prev = obj->prev;
@@ -76,17 +105,31 @@ static inline int nl_list_empty(struct nl_list_head *head)
76105
#define nl_list_first_entry(head, type, member) \
77106
nl_list_entry((head)->next, type, member)
78107

108+
#define nl_list_last_entry(head, type, member) \
109+
nl_list_entry((head)->prev, type, member)
110+
79111
#define nl_list_for_each_entry(pos, head, member) \
80112
for (pos = nl_list_entry((head)->next, __typeof__(*pos), member); \
81113
&(pos)->member != (head); \
82114
(pos) = nl_list_entry((pos)->member.next, __typeof__(*(pos)), member))
83115

116+
#define nl_list_for_each_entry_reverse(pos, head, member) \
117+
for (pos = nl_list_entry((head)->prev, __typeof__(*pos), member); \
118+
&(pos)->member != (head); \
119+
(pos) = nl_list_entry((pos)->member.prev, __typeof__(*(pos)), member))
120+
84121
#define nl_list_for_each_entry_safe(pos, n, head, member) \
85122
for (pos = nl_list_entry((head)->next, __typeof__(*pos), member), \
86123
n = nl_list_entry(pos->member.next, __typeof__(*pos), member); \
87124
&(pos)->member != (head); \
88125
pos = n, n = nl_list_entry(n->member.next, __typeof__(*n), member))
89126

127+
#define nl_list_for_each_entry_safe_reverse(pos, n, head, member) \
128+
for (pos = nl_list_entry((head)->prev, __typeof__(*pos), member), \
129+
n = nl_list_entry(pos->member.prev, __typeof__(*pos), member); \
130+
&(pos)->member != (head); \
131+
pos = n, n = nl_list_entry(n->member.prev, __typeof__(*n), member))
132+
90133
#define nl_init_list_head(head) \
91134
do { (head)->next = (head); (head)->prev = (head); } while (0)
92135

0 commit comments

Comments
 (0)