summaryrefslogtreecommitdiffstats
path: root/kernel/include/linux/netfilter/ip_set_slist.h
blob: abc5afeec9ea36be502014c285c0abaf77625c3d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#ifndef _IP_SET_SLIST_H
#define _IP_SET_SLIST_H

#include <linux/stddef.h>
#include <linux/prefetch.h>
#include <asm/system.h>

/*
 * Single linked lists with a single pointer.
 * Mostly useful for hash tables where the two pointer list head 
 * and list node is too wasteful.
 */

struct slist {
	struct slist *next;
};

#define SLIST(name) struct slist name = {  .next = NULL }
#define INIT_SLIST(ptr) ((ptr)->next = NULL)

#define slist_entry(ptr, type, member) container_of(ptr,type,member)

#define slist_for_each(pos, head) \
	for (pos = (head)->next; pos && ({ prefetch(pos->next); 1; }); \
	     pos = pos->next)

#define slist_for_each_prev(prev, pos, head) \
	for (prev = head, pos = (head)->next; pos && ({ prefetch(pos->next); 1; }); \
	     prev = pos, pos = pos->next)

#define slist_for_each_safe(pos, n, head) \
	for (pos = (head)->next; pos && ({ n = pos->next; 1; }); \
	     pos = n)

/**
 * slist_for_each_entry	- iterate over list of given type
 * @tpos:	the type * to use as a loop cursor.
 * @pos:	the &struct slist to use as a loop cursor.
 * @head:	the head for your list.
 * @member:	the name of the slist within the struct.
 */
#define slist_for_each_entry(tpos, pos, head, member)			 \
	for (pos = (head)->next;					 \
	     pos && ({ prefetch(pos->next); 1;}) &&			 \
		({ tpos = slist_entry(pos, typeof(*tpos), member); 1;}); \
	     pos = pos->next)

/**
 * slist_for_each_entry_continue - iterate over a hlist continuing after current point
 * @tpos:	the type * to use as a loop cursor.
 * @pos:	the &struct slist to use as a loop cursor.
 * @member:	the name of the slist within the struct.
 */
#define slist_for_each_entry_continue(tpos, pos, member)		 \
	for (pos = (pos)->next;						 \
	     pos && ({ prefetch(pos->next); 1;}) &&			 \
		({ tpos = slist_entry(pos, typeof(*tpos), member); 1;}); \
	     pos = pos->next)

/**
 * slist_for_each_entry_from - iterate over a hlist continuing from current point
 * @tpos:	the type * to use as a loop cursor.
 * @pos:	the &struct slist to use as a loop cursor.
 * @member:	the name of the slist within the struct.
 */
#define slist_for_each_entry_from(tpos, pos, member)			 \
	for (; pos && ({ prefetch(pos->next); 1;}) &&			 \
		({ tpos = slist_entry(pos, typeof(*tpos), member); 1;}); \
	     pos = pos->next)

/**
 * slist_for_each_entry_safe - iterate over list of given type safe against
 *			       removal of list entry
 * @tpos:	the type * to use as a loop cursor.
 * @pos:	the &struct slist to use as a loop cursor.
 * @n:		another &struct slist to use as temporary storage
 * @head:	the head for your list.
 * @member:	the name of the slist within the struct.
 */
#define slist_for_each_entry_safe(tpos, pos, n, head, member) 		 \
	for (pos = (head)->next;					 \
	     pos && ({ n = pos->next; 1; }) && 				 \
		({ tpos = slist_entry(pos, typeof(*tpos), member); 1;}); \
	     pos = n)

#endif /* _IP_SET_SLIST_H */