summaryrefslogtreecommitdiffstats
path: root/include/libipset
diff options
context:
space:
mode:
authorJozsef Kadlecsik <kadlec@blackhole.kfki.hu>2018-10-18 17:27:49 +0200
committerJozsef Kadlecsik <kadlec@blackhole.kfki.hu>2018-10-18 17:27:49 +0200
commit55fdd96e331e920ee62bd816a572ac24f6dcd1ae (patch)
tree74e53ff7174e08b035b85f95977ff6919e315b01 /include/libipset
parenta27741493db0d824a51775e387cf3972a471f64e (diff)
Library reworked to support embedding ipset completely
The ipset library is rewritten/extended to support embedding ipset, so that sets can fully be managed without calling the ipset binary. The ipset binary relies completely on the new library. The libipset.3 manpage was written about the library functions and usage. Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Diffstat (limited to 'include/libipset')
-rw-r--r--include/libipset/Makefile.am2
-rw-r--r--include/libipset/ipset.h90
-rw-r--r--include/libipset/parse.h2
-rw-r--r--include/libipset/session.h36
-rw-r--r--include/libipset/ui.h56
5 files changed, 119 insertions, 67 deletions
diff --git a/include/libipset/Makefile.am b/include/libipset/Makefile.am
index 79a1357..c7f7b2b 100644
--- a/include/libipset/Makefile.am
+++ b/include/libipset/Makefile.am
@@ -16,7 +16,7 @@ pkginclude_HEADERS = \
session.h \
transport.h \
types.h \
- ui.h \
+ ipset.h \
utils.h
EXTRA_DIST = debug.h icmp.h icmpv6.h
diff --git a/include/libipset/ipset.h b/include/libipset/ipset.h
new file mode 100644
index 0000000..7eba74e
--- /dev/null
+++ b/include/libipset/ipset.h
@@ -0,0 +1,90 @@
+/* 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_IPSET_H
+#define LIBIPSET_IPSET_H
+
+#include <stdbool.h> /* bool */
+#include <libipset/linux_ip_set.h> /* enum ipset_cmd */
+#include <libipset/session.h> /* ipset_session_* */
+#include <libipset/types.h> /* ipset_load_types */
+
+#define IPSET_CMD_ALIASES 3
+
+/* Commands in userspace */
+struct ipset_commands {
+ enum ipset_cmd cmd;
+ int has_arg;
+ const char *name[IPSET_CMD_ALIASES];
+ const char *help;
+};
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern const struct ipset_commands ipset_commands[];
+
+struct ipset_session;
+struct ipset_data;
+struct ipset;
+
+
+/* Environment options */
+struct ipset_envopts {
+ int flag;
+ int has_arg;
+ const char *name[2];
+ const char *help;
+ int (*parse)(struct ipset *ipset, int flag, const char *str);
+ int (*print)(char *buf, unsigned int len,
+ const struct ipset_data *data, int flag, uint8_t env);
+};
+
+extern const struct ipset_envopts ipset_envopts[];
+
+extern bool ipset_match_cmd(const char *arg, const char * const name[]);
+extern bool ipset_match_option(const char *arg, const char * const name[]);
+extern bool ipset_match_envopt(const char *arg, const char * const name[]);
+extern void ipset_port_usage(void);
+extern int ipset_parse_filename(struct ipset *ipset, int opt, const char *str);
+extern int ipset_parse_output(struct ipset *ipset,
+ int opt, const char *str);
+extern int ipset_envopt_parse(struct ipset *ipset,
+ int env, const char *str);
+
+enum ipset_exittype {
+ IPSET_NO_PROBLEM = 0,
+ IPSET_OTHER_PROBLEM,
+ IPSET_PARAMETER_PROBLEM,
+ IPSET_VERSION_PROBLEM,
+ IPSET_SESSION_PROBLEM,
+};
+
+typedef int (*ipset_custom_errorfn)(struct ipset *ipset, void *p,
+ int status, const char *msg, ...)
+ __attribute__ ((format (printf, 4, 5)));
+typedef int (*ipset_standard_errorfn)(struct ipset *ipset, void *p);
+
+extern struct ipset_session * ipset_session(struct ipset *ipset);
+extern bool ipset_is_interactive(struct ipset *ipset);
+extern int ipset_custom_printf(struct ipset *ipset,
+ ipset_custom_errorfn custom_error,
+ ipset_standard_errorfn standard_error,
+ ipset_print_outfn outfn,
+ void *p);
+
+extern int ipset_parse_argv(struct ipset *ipset, int argc, char *argv[]);
+extern int ipset_parse_line(struct ipset *ipset, char *line);
+extern int ipset_parse_stream(struct ipset *ipset, FILE *f);
+extern struct ipset * ipset_init(void);
+extern int ipset_fini(struct ipset *ipset);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* LIBIPSET_IPSET_H */
diff --git a/include/libipset/parse.h b/include/libipset/parse.h
index 9223eeb..4bd5df5 100644
--- a/include/libipset/parse.h
+++ b/include/libipset/parse.h
@@ -104,8 +104,6 @@ extern int ipset_parse_skbmark(struct ipset_session *session,
enum ipset_opt opt, const char *str);
extern int ipset_parse_skbprio(struct ipset_session *session,
enum ipset_opt opt, const char *str);
-extern int ipset_parse_output(struct ipset_session *session,
- int opt, const char *str);
extern int ipset_parse_ignored(struct ipset_session *session,
enum ipset_opt opt, const char *str);
extern int ipset_parse_elem(struct ipset_session *session,
diff --git a/include/libipset/session.h b/include/libipset/session.h
index bac4d19..825d2c8 100644
--- a/include/libipset/session.h
+++ b/include/libipset/session.h
@@ -19,7 +19,6 @@
struct ipset_session;
struct ipset_data;
-struct ipset_handle;
#ifdef __cplusplus
extern "C" {
@@ -33,6 +32,7 @@ extern const struct ipset_type *
ipset_saved_type(const struct ipset_session *session);
extern void ipset_session_lineno(struct ipset_session *session,
uint32_t lineno);
+extern void * ipset_session_printf_private(struct ipset_session *session);
enum ipset_err_type {
IPSET_ERROR,
@@ -80,10 +80,12 @@ enum ipset_envopt {
IPSET_ENV_LIST_HEADER = (1 << IPSET_ENV_BIT_LIST_HEADER),
};
-extern int ipset_envopt_parse(struct ipset_session *session,
- int env, const char *str);
extern bool ipset_envopt_test(struct ipset_session *session,
enum ipset_envopt env);
+extern void ipset_envopt_set(struct ipset_session *session,
+ enum ipset_envopt env);
+extern void ipset_envopt_unset(struct ipset_session *session,
+ enum ipset_envopt env);
enum ipset_output_mode {
IPSET_LIST_NONE,
@@ -99,12 +101,30 @@ extern int ipset_commit(struct ipset_session *session);
extern int ipset_cmd(struct ipset_session *session, enum ipset_cmd cmd,
uint32_t lineno);
-typedef int (*ipset_outfn)(const char *fmt, ...)
- __attribute__ ((format (printf, 1, 2)));
+typedef int (*ipset_print_outfn)(struct ipset_session *session,
+ void *p, const char *fmt, ...)
+ __attribute__ ((format (printf, 3, 4)));
-extern int ipset_session_outfn(struct ipset_session *session,
- ipset_outfn outfn);
-extern struct ipset_session *ipset_session_init(ipset_outfn outfn);
+extern int ipset_session_print_outfn(struct ipset_session *session,
+ ipset_print_outfn outfn,
+ void *p);
+
+enum ipset_io_type {
+ IPSET_IO_INPUT,
+ IPSET_IO_OUTPUT,
+};
+
+extern int ipset_session_io_full(struct ipset_session *session,
+ const char *filename, enum ipset_io_type what);
+extern int ipset_session_io_normal(struct ipset_session *session,
+ const char *filename, enum ipset_io_type what);
+extern FILE * ipset_session_io_stream(struct ipset_session *session,
+ enum ipset_io_type what);
+extern int ipset_session_io_close(struct ipset_session *session,
+ enum ipset_io_type what);
+
+extern struct ipset_session *ipset_session_init(ipset_print_outfn outfn,
+ void *p);
extern int ipset_session_fini(struct ipset_session *session);
extern void ipset_debug_msg(const char *dir, void *buffer, int len);
diff --git a/include/libipset/ui.h b/include/libipset/ui.h
deleted file mode 100644
index 4846dc1..0000000
--- a/include/libipset/ui.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/* 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_UI_H
-#define LIBIPSET_UI_H
-
-#include <stdbool.h> /* bool */
-#include <libipset/linux_ip_set.h> /* enum ipset_cmd */
-
-#define IPSET_CMD_ALIASES 3
-
-/* Commands in userspace */
-struct ipset_commands {
- enum ipset_cmd cmd;
- int has_arg;
- const char *name[IPSET_CMD_ALIASES];
- const char *help;
-};
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-extern const struct ipset_commands ipset_commands[];
-
-struct ipset_session;
-struct ipset_data;
-
-/* Environment options */
-struct ipset_envopts {
- int flag;
- int has_arg;
- const char *name[2];
- const char *help;
- int (*parse)(struct ipset_session *s, int flag, const char *str);
- int (*print)(char *buf, unsigned int len,
- const struct ipset_data *data, int flag, uint8_t env);
-};
-
-extern const struct ipset_envopts ipset_envopts[];
-
-extern bool ipset_match_cmd(const char *arg, const char * const name[]);
-extern bool ipset_match_option(const char *arg, const char * const name[]);
-extern bool ipset_match_envopt(const char *arg, const char * const name[]);
-extern void ipset_shift_argv(int *argc, char *argv[], int from);
-extern void ipset_port_usage(void);
-extern int ipset_parse_file(struct ipset_session *s, int opt, const char *str);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* LIBIPSET_UI_H */