linux 2.6 conntrack stats
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

269 lines
7.5KB

  1. #ifndef _LIST_H_
  2. #define _LIST_H_
  3. /*
  4. * stolen from linux kernel 2.6.11 (http://kernel.org/)
  5. * linux/include/linux/stddef.h (offsetoff)
  6. * linux/include/linux/kernel.h (container_of)
  7. * linux/include/linux/list.h (*list*)
  8. * linux/include/linux/netfilter_ipv4/listhelp.h (LIST_FIND)
  9. *
  10. * modified by Olaf Rempel <razzor@kopf-tisch.de>
  11. */
  12. #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
  13. #define container_of(ptr, type, member) ({ \
  14. const typeof( ((type *)0)->member ) *__mptr = (ptr); \
  15. (type *)( (char *)__mptr - offsetof(type,member) );})
  16. struct list_head {
  17. struct list_head *next, *prev;
  18. };
  19. #define LIST_HEAD_INIT(name) { &(name), &(name) }
  20. #define LIST_HEAD(name) \
  21. struct list_head name = LIST_HEAD_INIT(name)
  22. #define INIT_LIST_HEAD(ptr) do { \
  23. (ptr)->next = (ptr); (ptr)->prev = (ptr); \
  24. } while (0)
  25. /*
  26. * Insert a new entry between two known consecutive entries.
  27. *
  28. * This is only for internal list manipulation where we know
  29. * the prev/next entries already!
  30. */
  31. static inline void __list_add(struct list_head *new,
  32. struct list_head *prev,
  33. struct list_head *next)
  34. {
  35. next->prev = new;
  36. new->next = next;
  37. new->prev = prev;
  38. prev->next = new;
  39. }
  40. /*
  41. * list_add - add a new entry
  42. * @new: new entry to be added
  43. * @head: list head to add it after
  44. *
  45. * Insert a new entry after the specified head.
  46. * This is good for implementing stacks.
  47. */
  48. static inline void list_add(struct list_head *new, struct list_head *head)
  49. {
  50. __list_add(new, head, head->next);
  51. }
  52. /*
  53. * list_add_tail - add a new entry
  54. * @new: new entry to be added
  55. * @head: list head to add it before
  56. *
  57. * Insert a new entry before the specified head.
  58. * This is useful for implementing queues.
  59. */
  60. static inline void list_add_tail(struct list_head *new, struct list_head *head)
  61. {
  62. __list_add(new, head->prev, head);
  63. }
  64. /*
  65. * Delete a list entry by making the prev/next entries
  66. * point to each other.
  67. *
  68. * This is only for internal list manipulation where we know
  69. * the prev/next entries already!
  70. */
  71. static inline void __list_del(struct list_head * prev, struct list_head * next)
  72. {
  73. next->prev = prev;
  74. prev->next = next;
  75. }
  76. /*
  77. * list_del - deletes entry from list.
  78. * @entry: the element to delete from the list.
  79. * Note: list_empty on entry does not return true after this, the entry is
  80. * in an undefined state.
  81. */
  82. static inline void list_del(struct list_head *entry)
  83. {
  84. __list_del(entry->prev, entry->next);
  85. entry->next = NULL;
  86. entry->prev = NULL;
  87. }
  88. /*
  89. * list_del_init - deletes entry from list and reinitialize it.
  90. * entry: the element to delete from the list.
  91. */
  92. static inline void list_del_init(struct list_head *entry)
  93. {
  94. __list_del(entry->prev, entry->next);
  95. INIT_LIST_HEAD(entry);
  96. }
  97. /*
  98. * list_move - delete from one list and add as another's head
  99. * @list: the entry to move
  100. * @head: the head that will precede our entry
  101. */
  102. static inline void list_move(struct list_head *list, struct list_head *head)
  103. {
  104. __list_del(list->prev, list->next);
  105. list_add(list, head);
  106. }
  107. /*
  108. * list_move_tail - delete from one list and add as another's tail
  109. * @list: the entry to move
  110. * @head: the head that will follow our entry
  111. */
  112. static inline void list_move_tail(struct list_head *list,
  113. struct list_head *head)
  114. {
  115. __list_del(list->prev, list->next);
  116. list_add_tail(list, head);
  117. }
  118. /*
  119. * list_empty - tests whether a list is empty
  120. * @head: the list to test.
  121. */
  122. static inline int list_empty(const struct list_head *head)
  123. {
  124. return head->next == head;
  125. }
  126. static inline void __list_splice(struct list_head *list,
  127. struct list_head *head)
  128. {
  129. struct list_head *first = list->next;
  130. struct list_head *last = list->prev;
  131. struct list_head *at = head->next;
  132. first->prev = head;
  133. head->next = first;
  134. last->next = at;
  135. at->prev = last;
  136. }
  137. /*
  138. * list_splice - join two lists
  139. * @list: the new list to add.
  140. * @head: the place to add it in the first list.
  141. */
  142. static inline void list_splice(struct list_head *list, struct list_head *head)
  143. {
  144. if (!list_empty(list))
  145. __list_splice(list, head);
  146. }
  147. /*
  148. * list_splice_init - join two lists and reinitialise the emptied list.
  149. * @list: the new list to add.
  150. * @head: the place to add it in the first list.
  151. *
  152. * The list at @list is reinitialised
  153. */
  154. static inline void list_splice_init(struct list_head *list,
  155. struct list_head *head)
  156. {
  157. if (!list_empty(list)) {
  158. __list_splice(list, head);
  159. INIT_LIST_HEAD(list);
  160. }
  161. }
  162. /*
  163. * list_entry - get the struct for this entry
  164. * @ptr: the &struct list_head pointer.
  165. * @type: the type of the struct this is embedded in.
  166. * @member: the name of the list_struct within the struct.
  167. */
  168. #define list_entry(ptr, type, member) \
  169. container_of(ptr, type, member)
  170. /*
  171. * list_for_each - iterate over a list
  172. * @pos: the &struct list_head to use as a loop counter.
  173. * @head: the head for your list.
  174. */
  175. #define list_for_each(pos, head) \
  176. for (pos = (head)->next; pos != (head); pos = pos->next)
  177. /*
  178. * list_for_each_prev - iterate over a list backwards
  179. * @pos: the &struct list_head to use as a loop counter.
  180. * @head: the head for your list.
  181. */
  182. #define list_for_each_prev(pos, head) \
  183. for (pos = (head)->prev; pos != (head); pos = pos->prev)
  184. /*
  185. * list_for_each_safe - iterate over a list safe against removal of list entry
  186. * @pos: the &struct list_head to use as a loop counter.
  187. * @n: another &struct list_head to use as temporary storage
  188. * @head: the head for your list.
  189. */
  190. #define list_for_each_safe(pos, n, head) \
  191. for (pos = (head)->next, n = pos->next; pos != (head); \
  192. pos = n, n = pos->next)
  193. /*
  194. * list_for_each_entry - iterate over list of given type
  195. * @pos: the type * to use as a loop counter.
  196. * @head: the head for your list.
  197. * @member: the name of the list_struct within the struct.
  198. */
  199. #define list_for_each_entry(pos, head, member) \
  200. for (pos = list_entry((head)->next, typeof(*pos), member); \
  201. &pos->member != (head); \
  202. pos = list_entry(pos->member.next, typeof(*pos), member))
  203. /*
  204. * list_for_each_entry_reverse - iterate backwards over list of given type.
  205. * @pos: the type * to use as a loop counter.
  206. * @head: the head for your list.
  207. * @member: the name of the list_struct within the struct.
  208. */
  209. #define list_for_each_entry_reverse(pos, head, member) \
  210. for (pos = list_entry((head)->prev, typeof(*pos), member); \
  211. &pos->member != (head); \
  212. pos = list_entry(pos->member.prev, typeof(*pos), member))
  213. /*
  214. * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
  215. * @pos: the type * to use as a loop counter.
  216. * @n: another type * to use as temporary storage
  217. * @head: the head for your list.
  218. * @member: the name of the list_struct within the struct.
  219. */
  220. #define list_for_each_entry_safe(pos, n, head, member) \
  221. for (pos = list_entry((head)->next, typeof(*pos), member), \
  222. n = list_entry(pos->member.next, typeof(*pos), member); \
  223. &pos->member != (head); \
  224. pos = n, n = list_entry(n->member.next, typeof(*n), member))
  225. /* Return pointer to first true entry, if any, or NULL. A macro
  226. required to allow inlining of cmpfn. */
  227. #define LIST_FIND(head, cmpfn, type, args...) \
  228. ({ \
  229. const struct list_head *__i, *__j = NULL; \
  230. \
  231. list_for_each(__i, (head)) \
  232. if (cmpfn((const type)__i , ## args)) { \
  233. __j = __i; \
  234. break; \
  235. } \
  236. (type)__j; \
  237. })
  238. #endif /* _LIST_H_ */