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, *__j = NULL; \
16 ASSERT_READ_LOCK(head); \
17 list_for_each(__i, (head)) \
18 if (cmpfn((const type)__i , ## args)) { \
25 #define LIST_FIND_W(head, cmpfn, type, args...) \
27 const struct list_head *__i, *__j = NULL; \
29 ASSERT_WRITE_LOCK(head); \
30 list_for_each(__i, (head)) \
31 if (cmpfn((type)__i , ## args)) { \
38 /* Just like LIST_FIND but we search backwards */
39 #define LIST_FIND_B(head, cmpfn, type, args...) \
41 const struct list_head *__i, *__j = NULL; \
43 ASSERT_READ_LOCK(head); \
44 list_for_each_prev(__i, (head)) \
45 if (cmpfn((const type)__i , ## args)) { \
53 __list_cmp_same(const void *p1, const void *p2) { return p1 == p2; }
55 /* Is this entry in the list? */
57 list_inlist(struct list_head *head, const void *entry)
59 return LIST_FIND(head, __list_cmp_same, void *, entry) != NULL;
62 /* Delete from list. */
63 #ifdef CONFIG_NETFILTER_DEBUG
64 #define LIST_DELETE(head, oldentry) \
66 ASSERT_WRITE_LOCK(head); \
67 if (!list_inlist(head, oldentry)) \
68 printk("LIST_DELETE: %s:%u `%s'(%p) not in %s.\n", \
69 __FILE__, __LINE__, #oldentry, oldentry, #head); \
70 else list_del((struct list_head *)oldentry); \
73 #define LIST_DELETE(head, oldentry) list_del((struct list_head *)oldentry)
78 list_append(struct list_head *head, void *new)
80 ASSERT_WRITE_LOCK(head);
81 list_add((new), (head)->prev);
86 list_prepend(struct list_head *head, void *new)
88 ASSERT_WRITE_LOCK(head);
92 /* Insert according to ordering function; insert before first true. */
93 #define LIST_INSERT(head, new, cmpfn) \
95 struct list_head *__i; \
96 ASSERT_WRITE_LOCK(head); \
97 list_for_each(__i, (head)) \
98 if ((new), (typeof (new))__i) \
100 list_add((struct list_head *)(new), __i->prev); \
103 /* If the field after the list_head is a nul-terminated string, you
104 can use these functions. */
105 static inline int __list_cmp_name(const void *i, const char *name)
107 return strcmp(name, i+sizeof(struct list_head)) == 0;
110 /* Returns false if same name already in list, otherwise does insert. */
112 list_named_insert(struct list_head *head, void *new)
114 if (LIST_FIND(head, __list_cmp_name, void *,
115 new + sizeof(struct list_head)))
117 list_prepend(head, new);
121 /* Find this named element in the list. */
122 #define list_named_find(head, name) \
123 LIST_FIND(head, __list_cmp_name, void *, name)
125 #endif /*_LISTHELP_H*/