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
24 #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"
35 extern int option_debug;
36 #define DP(format, args...) if (option_debug) \
38 fprintf(stderr, "%s: %s (DBG): ", __FILE__, __FUNCTION__);\
39 fprintf(stderr, format "\n" , ## args); \
42 #define DP(format, args...)
63 NUMBER_OF_CMD = CMD_VERSION,
64 /* Internal commands */
77 /* The view of an ipset in userspace */
79 char name[IP_SET_MAXNAMELEN]; /* Name of the set */
80 ip_set_id_t id; /* Unique set id */
81 ip_set_id_t index; /* Array index */
82 unsigned ref; /* References in kernel */
83 struct settype *settype; /* Pointer to set type functions */
89 char typename[IP_SET_MAXNAMELEN];
97 /* Size of create data. Will be sent to kernel */
100 /* Initialize the create. */
101 void (*create_init) (void *data);
103 /* Function which parses command options; returns true if it ate an option */
104 int (*create_parse) (int c, char *argv[], void *data,
107 /* Final check; exit if not ok. */
108 void (*create_final) (void *data, unsigned int flags);
110 /* Pointer to list of extra command-line options for create */
111 struct option *create_opts;
117 /* Size of data. Will be sent to kernel */
120 /* Function which parses command options */
121 ip_set_ip_t (*adt_parser) (unsigned cmd, const char *optarg, void *data);
127 /* Size of header. */
130 /* Initialize the type-header */
131 void (*initheader) (struct set *set, const void *data);
133 /* Pretty print the type-header */
134 void (*printheader) (struct set *set, unsigned options);
136 /* Pretty print all IPs */
137 void (*printips) (struct set *set, void *data, size_t len, unsigned options);
139 /* Pretty print all IPs sorted */
140 void (*printips_sorted) (struct set *set, void *data, size_t len, unsigned options);
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, size_t len, unsigned options);
148 /* Conver a single IP (binding) to string */
149 char * (*bindip_tostring)(struct set *set, ip_set_ip_t ip, unsigned options);
151 /* Parse an IP at restoring bindings. FIXME */
152 void (*bindip_parse) (const char *str, ip_set_ip_t * ip);
155 void (*usage) (void);
160 unsigned int option_offset;
164 extern void settype_register(struct settype *settype);
166 /* extern void unregister_settype(set_type_t *set_type); */
168 extern void exit_error(enum exittype status, char *msg, ...);
170 extern char *binding_ip_tostring(struct set *set,
171 ip_set_ip_t ip, unsigned options);
172 extern char *ip_tostring(ip_set_ip_t ip, unsigned options);
173 extern char *ip_tostring_numeric(ip_set_ip_t ip);
174 extern void parse_ip(const char *str, ip_set_ip_t * ip);
175 extern void parse_mask(const char *str, ip_set_ip_t * mask);
176 extern void parse_ipandmask(const char *str, ip_set_ip_t * ip,
178 extern char *port_tostring(ip_set_ip_t port, unsigned options);
179 extern void parse_port(const char *str, ip_set_ip_t * port);
180 extern int string_to_number(const char *str, unsigned int min, unsigned int max,
183 extern void *ipset_malloc(size_t size);
184 extern char *ipset_strdup(const char *);
185 extern void ipset_free(void **data);
187 #define BITSPERBYTE (8*sizeof(char))
188 #define ID2BYTE(id) ((id)/BITSPERBYTE)
189 #define ID2MASK(id) (1 << ((id)%BITSPERBYTE))
190 #define test_bit(id, heap) ((((char *)(heap))[ID2BYTE(id)] & ID2MASK(id)) != 0)
192 #endif /* __IPSET_H */