New routers supported
[tomato.git] / release / src / router / ipset / ipset.h
blobc49418d3cfbe6788c16edb80f5b494c7efddf14b
1 #ifndef __IPSET_H
2 #define __IPSET_H
4 /* Copyright 2000-2004 Joakim Axelsson (gozem@linux.nu)
5 * Patrick Schaaf (bof@bof.de)
6 * Jozsef Kadlecsik (kadlec@blackhole.kfki.hu)
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <getopt.h> /* struct option */
24 #include <stdint.h>
25 #include <sys/types.h>
27 #include <linux/netfilter_ipv4/ip_set.h>
29 #define IPSET_LIB_NAME "/libipset_%s.so"
30 #define PROC_SYS_MODPROBE "/proc/sys/kernel/modprobe"
32 #define LIST_TRIES 5
34 #ifdef IPSET_DEBUG
35 extern int option_debug;
36 #define DP(format, args...) if (option_debug) \
37 do { \
38 fprintf(stderr, "%s: %s (DBG): ", __FILE__, __FUNCTION__);\
39 fprintf(stderr, format "\n" , ## args); \
40 } while (0)
41 #else
42 #define DP(format, args...)
43 #endif
45 /* Commands */
46 enum set_commands {
47 CMD_NONE,
48 CMD_CREATE, /* -N */
49 CMD_DESTROY, /* -X */
50 CMD_FLUSH, /* -F */
51 CMD_RENAME, /* -E */
52 CMD_SWAP, /* -W */
53 CMD_LIST, /* -L */
54 CMD_SAVE, /* -S */
55 CMD_RESTORE, /* -R */
56 CMD_ADD, /* -A */
57 CMD_DEL, /* -D */
58 CMD_TEST, /* -T */
59 CMD_HELP, /* -H */
60 CMD_VERSION, /* -V */
61 NUMBER_OF_CMD = CMD_VERSION,
62 /* Internal commands */
63 CMD_MAX_SETS,
64 CMD_LIST_SIZE,
65 CMD_SAVE_SIZE,
66 CMD_ADT_GET,
69 enum exittype {
70 OTHER_PROBLEM = 1,
71 PARAMETER_PROBLEM,
72 VERSION_PROBLEM
75 /* The view of an ipset in userspace */
76 struct set {
77 char name[IP_SET_MAXNAMELEN]; /* Name of the set */
78 ip_set_id_t id; /* Unique set id */
79 ip_set_id_t index; /* Array index */
80 unsigned ref; /* References in kernel */
81 struct settype *settype; /* Pointer to set type functions */
84 struct settype {
85 struct settype *next;
87 char typename[IP_SET_MAXNAMELEN];
89 int protocol_version;
92 * Create set
95 /* Size of create data. Will be sent to kernel */
96 u_int32_t create_size;
98 /* Initialize the create. */
99 void (*create_init) (void *data);
101 /* Function which parses command options; returns true if it ate an option */
102 int (*create_parse) (int c, char *argv[], void *data,
103 unsigned *flags);
105 /* Final check; exit if not ok. */
106 void (*create_final) (void *data, unsigned int flags);
108 /* Pointer to list of extra command-line options for create */
109 const struct option *create_opts;
112 * Add/del/test IP
115 /* Size of data. Will be sent to kernel */
116 u_int32_t adt_size;
118 /* Function which parses command options */
119 ip_set_ip_t (*adt_parser) (int cmd, const char *optarg, void *data);
122 * Printing
125 /* Size of header. */
126 u_int32_t header_size;
128 /* Initialize the type-header */
129 void (*initheader) (struct set *set, const void *data);
131 /* Pretty print the type-header */
132 void (*printheader) (struct set *set, unsigned options);
134 /* Pretty print all IPs */
135 void (*printips) (struct set *set, void *data, u_int32_t len,
136 unsigned options, char dont_align);
138 /* Pretty print all IPs sorted */
139 void (*printips_sorted) (struct set *set, void *data, u_int32_t len,
140 unsigned options, char dont_align);
142 /* Print save arguments for creating the set */
143 void (*saveheader) (struct set *set, unsigned options);
145 /* Print save for all IPs */
146 void (*saveips) (struct set *set, void *data, u_int32_t len,
147 unsigned options, char dont_align);
149 /* Print usage */
150 void (*usage) (void);
152 /* Internal data */
153 void *header;
154 void *data;
155 int option_offset;
156 unsigned int flags;
159 extern void settype_register(struct settype *settype);
161 /* extern void unregister_settype(set_type_t *set_type); */
163 extern void exit_error(int status, const char *msg, ...);
165 extern char *binding_ip_tostring(struct set *set,
166 ip_set_ip_t ip, unsigned options);
167 extern char *ip_tostring(ip_set_ip_t ip, unsigned options);
168 extern char *ip_tostring_numeric(ip_set_ip_t ip);
169 extern void parse_ip(const char *str, ip_set_ip_t * ip);
170 extern void parse_mask(const char *str, ip_set_ip_t * mask);
171 extern void parse_ipandmask(const char *str, ip_set_ip_t * ip,
172 ip_set_ip_t * mask);
173 extern char *port_tostring(ip_set_ip_t port, unsigned options);
174 extern void parse_port(const char *str, ip_set_ip_t * port);
175 extern int string_to_number(const char *str, unsigned int min, unsigned int max,
176 ip_set_ip_t *port);
178 extern void *ipset_malloc(size_t size);
179 extern char *ipset_strdup(const char *);
180 extern void ipset_free(void *data);
182 extern struct set *set_find_byname(const char *name);
183 extern struct set *set_find_byid(ip_set_id_t id);
185 extern unsigned warn_once;
187 #define BITS_PER_LONG (8*sizeof(ip_set_ip_t))
188 #define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
190 static inline int test_bit(int nr, const ip_set_ip_t *addr)
192 return 1 & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1)));
195 #define UNUSED __attribute__ ((unused))
196 #define CONSTRUCTOR(module) \
197 void __attribute__ ((constructor)) module##_init(void); \
198 void module##_init(void)
200 #endif /* __IPSET_H */