3 #include <linux/config.h>
4 #include <linux/list.h>
5 #include <linux/netfilter_ipv4/lockhelp.h>
7 /* Header to do more comprehensive job than linux/list.h; assume list
8 is first entry in structure. */
10 /* Return pointer to first true entry, if any, or NULL. A macro
11 required to allow inlining of cmpfn. */
12 #define LIST_FIND(head, cmpfn, type, args...) \
14 const struct list_head *__i = (head); \
16 ASSERT_READ_LOCK(head); \
19 if (__i == (head)) { \
23 } while (!cmpfn((const type)__i , ## args)); \
27 #define LIST_FIND_W(head, cmpfn, type, args...) \
29 const struct list_head *__i = (head); \
31 ASSERT_WRITE_LOCK(head); \
34 if (__i == (head)) { \
38 } while (!cmpfn((type)__i , ## args)); \
42 /* Just like LIST_FIND but we search backwards */
43 #define LIST_FIND_B(head, cmpfn, type, args...) \
45 const struct list_head *__i = (head); \
47 ASSERT_READ_LOCK(head); \
50 if (__i == (head)) { \
54 } while (!cmpfn((const type)__i , ## args)); \
59 __list_cmp_same(const void *p1
, const void *p2
) { return p1
== p2
; }
61 /* Is this entry in the list? */
63 list_inlist(struct list_head
*head
, const void *entry
)
65 return LIST_FIND(head
, __list_cmp_same
, void *, entry
) != NULL
;
68 /* Delete from list. */
69 #ifdef CONFIG_NETFILTER_DEBUG
70 #define LIST_DELETE(head, oldentry) \
72 ASSERT_WRITE_LOCK(head); \
73 if (!list_inlist(head, oldentry)) \
74 printk("LIST_DELETE: %s:%u `%s'(%p) not in %s.\n", \
75 __FILE__, __LINE__, #oldentry, oldentry, #head); \
76 else list_del((struct list_head *)oldentry); \
79 #define LIST_DELETE(head, oldentry) list_del((struct list_head *)oldentry)
84 list_append(struct list_head
*head
, void *new)
86 ASSERT_WRITE_LOCK(head
);
87 list_add((new), (head
)->prev
);
92 list_prepend(struct list_head
*head
, void *new)
94 ASSERT_WRITE_LOCK(head
);
98 /* Insert according to ordering function; insert before first true. */
99 #define LIST_INSERT(head, new, cmpfn) \
101 struct list_head *__i; \
102 ASSERT_WRITE_LOCK(head); \
103 for (__i = (head)->next; \
104 !cmpfn((new), (typeof (new))__i) && __i != (head); \
106 list_add((struct list_head *)(new), __i->prev); \
109 /* If the field after the list_head is a nul-terminated string, you
110 can use these functions. */
111 static inline int __list_cmp_name(const void *i
, const char *name
)
113 return strcmp(name
, i
+sizeof(struct list_head
)) == 0;
116 /* Returns false if same name already in list, otherwise does insert. */
118 list_named_insert(struct list_head
*head
, void *new)
120 if (LIST_FIND(head
, __list_cmp_name
, void *,
121 new + sizeof(struct list_head
)))
123 list_prepend(head
, new);
127 /* Find this named element in the list. */
128 #define list_named_find(head, name) \
129 LIST_FIND(head, __list_cmp_name, void *, name)
131 #endif /*_LISTHELP_H*/