forked from wanlill/lua-ipforest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathipforest_types.h
More file actions
90 lines (68 loc) · 1.87 KB
/
ipforest_types.h
File metadata and controls
90 lines (68 loc) · 1.87 KB
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
87
88
89
90
#ifndef IPFOREST_TYPES
#define IPFOREST_TYPES
#include <stdint.h>
#include <assert.h>
typedef struct ipforest_ipaddr_s {
uint32_t addr;
uint32_t mask;
} ipforest_ipaddr_t;
typedef enum {
IPFOREST_FALSE,
IPFOREST_TRUE
} IPFOREST_BOOLEAN;
#define IPFOREST_IPSTR_MAX_LEN 15
#define IPFOREST_IPSTR_BUF_LEN 32
/* [i, 31] is set to 1 */
#define IPFOREST_MASK_UP(i) ((uint32_t) \
(0xffffffff ^ ((1 << (i)) - 1)))
/* [0, i] is set to 1 */
#define IPFOREST_MASK_DOWN(i) ((uint32_t) \
((1 << ((i) + 1)) - 1))
typedef struct ipforest_list_entry_s {
struct ipforest_list_entry_s *prev;
struct ipforest_list_entry_s *next;
} ipforest_list_entry_t;
inline static void
_list_init(ipforest_list_entry_t *head)
{
head->prev = head;
head->next = head;
}
inline static IPFOREST_BOOLEAN
_list_empty(ipforest_list_entry_t *node)
{
return node->next == node && node->prev == node;
}
inline static void
_list_insert_after(ipforest_list_entry_t *old, ipforest_list_entry_t *new)
{
ipforest_list_entry_t *next;
next = old->next;
old->next = new;
new->prev = old;
new->next = next;
next->prev = new;
}
inline static void
_list_insert_before(ipforest_list_entry_t *old, ipforest_list_entry_t *new)
{
ipforest_list_entry_t *prev;
prev = old->prev;
old->prev = new;
new->next = old;
new->prev = prev;
prev->next = new;
}
inline static void
_list_unlink(ipforest_list_entry_t *node)
{
/* should not delete a empty list */
assert(!_list_empty(node));
node->prev->next = node->next;
node->next->prev = node->prev;
}
#define CONTAINER_OF(p, field, container) \
((container *)((size_t)p - (size_t)(&(((container *)0)->field))))
#define LIST_FOREACH(head, p, safep) \
for (p = (head)->next, safep = p->next; p != head; p = safep, safep = p->next)
#endif