3 #include <linux/list.h>
5 /* Header to do more comprehensive job than linux/list.h; assume list
6 is first entry in structure. */
8 /* Return pointer to first true entry, if any, or NULL. A macro
9 required to allow inlining of cmpfn. */
10 #define LIST_FIND(head, cmpfn, type, args...) \
12 const struct list_head *__i, *__j = NULL; \
14 ASSERT_READ_LOCK(head); \
15 list_for_each(__i, (head)) \
16 if (cmpfn((const type)__i , ## args)) { \
23 #define LIST_FIND_W(head, cmpfn, type, args...) \
25 const struct list_head *__i, *__j = NULL; \
27 ASSERT_WRITE_LOCK(head); \
28 list_for_each(__i, (head)) \
29 if (cmpfn((type)__i , ## args)) { \
36 /* Just like LIST_FIND but we search backwards */
37 #define LIST_FIND_B(head, cmpfn, type, args...) \
39 const struct list_head *__i, *__j = NULL; \
41 ASSERT_READ_LOCK(head); \
42 list_for_each_prev(__i, (head)) \
43 if (cmpfn((const type)__i , ## args)) { \
51 __list_cmp_same(const void *p1, const void *p2) { return p1 == p2; }
53 /* Is this entry in the list? */
55 list_inlist(struct list_head *head, const void *entry)
57 return LIST_FIND(head, __list_cmp_same, void *, entry) != NULL;
60 /* Delete from list. */
61 #ifdef CONFIG_NETFILTER_DEBUG
62 #define LIST_DELETE(head, oldentry) \
64 ASSERT_WRITE_LOCK(head); \
65 if (!list_inlist(head, oldentry)) \
66 printk("LIST_DELETE: %s:%u `%s'(%p) not in %s.\n", \
67 __FILE__, __LINE__, #oldentry, oldentry, #head); \
68 else list_del((struct list_head *)oldentry); \
71 #define LIST_DELETE(head, oldentry) list_del((struct list_head *)oldentry)
76 list_append(struct list_head *head, void *new)
78 ASSERT_WRITE_LOCK(head);
79 list_add((new), (head)->prev);
84 list_prepend(struct list_head *head, void *new)
86 ASSERT_WRITE_LOCK(head);
90 /* Insert according to ordering function; insert before first true. */
91 #define LIST_INSERT(head, new, cmpfn) \
93 struct list_head *__i; \
94 ASSERT_WRITE_LOCK(head); \
95 list_for_each(__i, (head)) \
96 if ((new), (typeof (new))__i) \
98 list_add((struct list_head *)(new), __i->prev); \
101 /* If the field after the list_head is a nul-terminated string, you
102 can use these functions. */
103 static inline int __list_cmp_name(const void *i, const char *name)
105 return strcmp(name, i+sizeof(struct list_head)) == 0;
108 /* Returns false if same name already in list, otherwise does insert. */
110 list_named_insert(struct list_head *head, void *new)
112 if (LIST_FIND(head, __list_cmp_name, void *,
113 new + sizeof(struct list_head)))
115 list_prepend(head, new);
119 /* Find this named element in the list. */
120 #define list_named_find(head, name) \
121 LIST_FIND(head, __list_cmp_name, void *, name)
123 #endif /*_LISTHELP_H*/