summaryrefslogtreecommitdiffstats
path: root/include/libipset/data.h
blob: cb3539330100e30a8f3e763c19b5fcca4e1bc850 (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
/* Copyright 2007-2010 Jozsef Kadlecsik (kadlec@blackhole.kfki.hu)
 *
 * 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_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_NETMASK,
	IPSET_OPT_PROBES,
	IPSET_OPT_RESIZE,
	IPSET_OPT_SIZE,
	/* 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_PROTO,
	/* Swap/rename to */
	IPSET_OPT_SETNAME2,
	/* Flags */
	IPSET_OPT_EXIST,
	IPSET_OPT_BEFORE,
	/* 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_MAX,
};

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

#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_NETMASK)	\
	| IPSET_FLAG(IPSET_OPT_PROBES)	\
	| IPSET_FLAG(IPSET_OPT_RESIZE)	\
	| IPSET_FLAG(IPSET_OPT_SIZE))

#define IPSET_ADT_FLAGS			\
	( 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_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_CADT_FLAGS)\
	| IPSET_FLAG(IPSET_OPT_BEFORE))

struct ipset_data;

extern void ipset_strncpy(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 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);

#endif /* LIBIPSET_DATA_H */