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 */
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"
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...)
61 NUMBER_OF_CMD
= CMD_VERSION
,
62 /* Internal commands */
75 /* The view of an ipset in userspace */
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 */
87 char typename
[IP_SET_MAXNAMELEN
];
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
,
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
;
115 /* Size of data. Will be sent to kernel */
118 /* Function which parses command options */
119 ip_set_ip_t (*adt_parser
) (int cmd
, const char *optarg
, void *data
);
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
);
150 void (*usage
) (void);
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
,
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
,
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 */