summaryrefslogtreecommitdiffstats
path: root/include/libipset/data.h
blob: 97498479b5c08dce4b87bb73b7e94eeef1d3f9b6 (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/* Copyright 2007-2010 Jozsef Kadlecsik (kadlec@netfilter.org)
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */
#ifndef LIBIPSET_DATA_H
#define LIBIPSET_DATA_H

#include <stdbool.h>				/* bool */
#include <libipset/nf_inet_addr.h>		/* union nf_inet_addr */

/* Data options */
enum ipset_opt {
	IPSET_OPT_NONE = 0,
	/* Common ones */
	IPSET_SETNAME,
	IPSET_OPT_TYPENAME,
	IPSET_OPT_FAMILY,
	/* CADT options */
	IPSET_OPT_IP,
	IPSET_OPT_IP_FROM = IPSET_OPT_IP,
	IPSET_OPT_IP_TO,
	IPSET_OPT_CIDR,
	IPSET_OPT_MARK,
	IPSET_OPT_PORT,
	IPSET_OPT_PORT_FROM = IPSET_OPT_PORT,
	IPSET_OPT_PORT_TO,
	IPSET_OPT_TIMEOUT,
	/* Create-specific options */
	IPSET_OPT_GC,
	IPSET_OPT_HASHSIZE,
	IPSET_OPT_MAXELEM,
	IPSET_OPT_MARKMASK,
	IPSET_OPT_NETMASK,
	IPSET_OPT_PROBES,
	IPSET_OPT_RESIZE,
	IPSET_OPT_SIZE,
	IPSET_OPT_FORCEADD,
	/* Create-specific options, filled out by the kernel */
	IPSET_OPT_ELEMENTS,
	IPSET_OPT_REFERENCES,
	IPSET_OPT_MEMSIZE,
	/* ADT-specific options */
	IPSET_OPT_ETHER,
	IPSET_OPT_NAME,
	IPSET_OPT_NAMEREF,
	IPSET_OPT_IP2,
	IPSET_OPT_CIDR2,
	IPSET_OPT_IP2_TO,
	IPSET_OPT_PROTO,
	IPSET_OPT_IFACE,
	/* Swap/rename to */
	IPSET_OPT_SETNAME2,
	/* Flags */
	IPSET_OPT_EXIST,
	IPSET_OPT_BEFORE,
	IPSET_OPT_PHYSDEV,
	IPSET_OPT_NOMATCH,
	IPSET_OPT_COUNTERS,
	IPSET_OPT_PACKETS,
	IPSET_OPT_BYTES,
	IPSET_OPT_CREATE_COMMENT,
	IPSET_OPT_ADT_COMMENT,
	IPSET_OPT_SKBINFO,
	IPSET_OPT_SKBMARK,
	IPSET_OPT_SKBPRIO,
	IPSET_OPT_SKBQUEUE,
	/* Internal options */
	IPSET_OPT_FLAGS = 48,	/* IPSET_FLAG_EXIST| */
	IPSET_OPT_CADT_FLAGS,	/* IPSET_FLAG_BEFORE| */
	IPSET_OPT_ELEM,
	IPSET_OPT_TYPE,
	IPSET_OPT_LINENO,
	IPSET_OPT_REVISION,
	IPSET_OPT_REVISION_MIN,
	IPSET_OPT_INDEX,
	IPSET_OPT_MAX,
};

#define IPSET_FLAG(opt)		(1ULL << (opt))
#define IPSET_FLAGS_ALL		(~0ULL)

#define IPSET_CREATE_FLAGS		\
	(IPSET_FLAG(IPSET_OPT_FAMILY)	\
	| IPSET_FLAG(IPSET_OPT_TYPENAME)\
	| IPSET_FLAG(IPSET_OPT_TYPE)	\
	| IPSET_FLAG(IPSET_OPT_IP)	\
	| IPSET_FLAG(IPSET_OPT_IP_TO)	\
	| IPSET_FLAG(IPSET_OPT_CIDR)	\
	| IPSET_FLAG(IPSET_OPT_PORT)	\
	| IPSET_FLAG(IPSET_OPT_PORT_TO)	\
	| IPSET_FLAG(IPSET_OPT_TIMEOUT)	\
	| IPSET_FLAG(IPSET_OPT_GC)	\
	| IPSET_FLAG(IPSET_OPT_HASHSIZE)\
	| IPSET_FLAG(IPSET_OPT_MAXELEM)	\
	| IPSET_FLAG(IPSET_OPT_MARKMASK)\
	| IPSET_FLAG(IPSET_OPT_NETMASK)	\
	| IPSET_FLAG(IPSET_OPT_PROBES)	\
	| IPSET_FLAG(IPSET_OPT_RESIZE)	\
	| IPSET_FLAG(IPSET_OPT_SIZE)	\
	| IPSET_FLAG(IPSET_OPT_COUNTERS)\
	| IPSET_FLAG(IPSET_OPT_CREATE_COMMENT)\
	| IPSET_FLAG(IPSET_OPT_FORCEADD)\
	| IPSET_FLAG(IPSET_OPT_SKBINFO))

#define IPSET_ADT_FLAGS			\
	(IPSET_FLAG(IPSET_OPT_IP)	\
	| IPSET_FLAG(IPSET_OPT_IP_TO)	\
	| IPSET_FLAG(IPSET_OPT_CIDR)	\
	| IPSET_FLAG(IPSET_OPT_MARK)	\
	| IPSET_FLAG(IPSET_OPT_PORT)	\
	| IPSET_FLAG(IPSET_OPT_PORT_TO)	\
	| IPSET_FLAG(IPSET_OPT_TIMEOUT)	\
	| IPSET_FLAG(IPSET_OPT_ETHER)	\
	| IPSET_FLAG(IPSET_OPT_NAME)	\
	| IPSET_FLAG(IPSET_OPT_NAMEREF)	\
	| IPSET_FLAG(IPSET_OPT_IP2)	\
	| IPSET_FLAG(IPSET_OPT_CIDR2)	\
	| IPSET_FLAG(IPSET_OPT_PROTO)	\
	| IPSET_FLAG(IPSET_OPT_IFACE) \
	| IPSET_FLAG(IPSET_OPT_CADT_FLAGS)\
	| IPSET_FLAG(IPSET_OPT_BEFORE) \
	| IPSET_FLAG(IPSET_OPT_PHYSDEV) \
	| IPSET_FLAG(IPSET_OPT_NOMATCH) \
	| IPSET_FLAG(IPSET_OPT_PACKETS)	\
	| IPSET_FLAG(IPSET_OPT_BYTES)	\
	| IPSET_FLAG(IPSET_OPT_ADT_COMMENT)\
	| IPSET_FLAG(IPSET_OPT_SKBMARK)	\
	| IPSET_FLAG(IPSET_OPT_SKBPRIO)	\
	| IPSET_FLAG(IPSET_OPT_SKBQUEUE))

struct ipset_data;

#ifdef __cplusplus
extern "C" {
#endif

extern void ipset_strlcpy(char *dst, const char *src, size_t len);
extern void ipset_strlcat(char *dst, const char *src, size_t len);
extern bool ipset_data_flags_test(const struct ipset_data *data,
				  uint64_t flags);
extern void ipset_data_flags_set(struct ipset_data *data, uint64_t flags);
extern void ipset_data_flags_unset(struct ipset_data *data, uint64_t flags);
extern bool ipset_data_ignored(struct ipset_data *data, enum ipset_opt opt);
extern bool ipset_data_test_ignored(struct ipset_data *data,
				    enum ipset_opt opt);

extern int ipset_data_set(struct ipset_data *data, enum ipset_opt opt,
			  const void *value);
extern const void *ipset_data_get(const struct ipset_data *data,
				  enum ipset_opt opt);

static inline bool
ipset_data_test(const struct ipset_data *data, enum ipset_opt opt)
{
	return ipset_data_flags_test(data, IPSET_FLAG(opt));
}

/* Shortcuts */
extern const char *ipset_data_setname(const struct ipset_data *data);
extern uint8_t ipset_data_family(const struct ipset_data *data);
extern uint8_t ipset_data_cidr(const struct ipset_data *data);
extern uint64_t ipset_data_flags(const struct ipset_data *data);

extern void ipset_data_reset(struct ipset_data *data);
extern struct ipset_data *ipset_data_init(void);
extern void ipset_data_fini(struct ipset_data *data);

extern size_t ipset_data_sizeof(enum ipset_opt opt, uint8_t family);

#ifdef __cplusplus
}
#endif

#endif /* LIBIPSET_DATA_H */