1 /* Copyright 2007-2010 Jozsef Kadlecsik (kadlec@blackhole.kfki.hu)
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 as
5 * published by the Free Software Foundation.
7 #ifndef LIBIPSET_SESSION_H
8 #define LIBIPSET_SESSION_H
10 #include <stdbool.h> /* bool */
11 #include <stdint.h> /* uintxx_t */
12 #include <stdio.h> /* printf */
14 #include <libipset/linux_ip_set.h> /* enum ipset_cmd */
16 /* Report and output buffer sizes */
17 #define IPSET_ERRORBUFLEN 1024
18 #define IPSET_OUTBUFLEN 8192
28 extern struct ipset_data *
29 ipset_session_data(const struct ipset_session *session);
30 extern struct ipset_handle *
31 ipset_session_handle(const struct ipset_session *session);
32 extern const struct ipset_type *
33 ipset_saved_type(const struct ipset_session *session);
34 extern void ipset_session_lineno(struct ipset_session *session,
42 extern int ipset_session_report(struct ipset_session *session,
43 enum ipset_err_type type,
44 const char *fmt, ...);
45 extern int ipset_session_warning_as_error(struct ipset_session *session);
47 #define ipset_err(session, fmt, args...) \
48 ipset_session_report(session, IPSET_ERROR, fmt , ## args)
50 #define ipset_warn(session, fmt, args...) \
51 ipset_session_report(session, IPSET_WARNING, fmt , ## args)
53 #define ipset_errptr(session, fmt, args...) ({ \
54 ipset_session_report(session, IPSET_ERROR, fmt , ## args); \
58 extern void ipset_session_report_reset(struct ipset_session *session);
59 extern const char *ipset_session_error(const struct ipset_session *session);
60 extern const char *ipset_session_warning(const struct ipset_session *session);
62 #define ipset_session_data_set(session, opt, value) \
63 ipset_data_set(ipset_session_data(session), opt, value)
64 #define ipset_session_data_get(session, opt) \
65 ipset_data_get(ipset_session_data(session), opt)
67 /* Environment option flags */
69 IPSET_ENV_BIT_SORTED = 0,
70 IPSET_ENV_SORTED = (1 << IPSET_ENV_BIT_SORTED),
71 IPSET_ENV_BIT_QUIET = 1,
72 IPSET_ENV_QUIET = (1 << IPSET_ENV_BIT_QUIET),
73 IPSET_ENV_BIT_RESOLVE = 2,
74 IPSET_ENV_RESOLVE = (1 << IPSET_ENV_BIT_RESOLVE),
75 IPSET_ENV_BIT_EXIST = 3,
76 IPSET_ENV_EXIST = (1 << IPSET_ENV_BIT_EXIST),
77 IPSET_ENV_BIT_LIST_SETNAME = 4,
78 IPSET_ENV_LIST_SETNAME = (1 << IPSET_ENV_BIT_LIST_SETNAME),
79 IPSET_ENV_BIT_LIST_HEADER = 5,
80 IPSET_ENV_LIST_HEADER = (1 << IPSET_ENV_BIT_LIST_HEADER),
83 extern int ipset_envopt_parse(struct ipset_session *session,
84 int env, const char *str);
85 extern bool ipset_envopt_test(struct ipset_session *session,
86 enum ipset_envopt env);
88 enum ipset_output_mode {
95 extern int ipset_session_output(struct ipset_session *session,
96 enum ipset_output_mode mode);
98 extern int ipset_commit(struct ipset_session *session);
99 extern int ipset_cmd(struct ipset_session *session, enum ipset_cmd cmd,
102 typedef int (*ipset_outfn)(const char *fmt, ...)
103 __attribute__ ((format (printf, 1, 2)));
105 extern int ipset_session_outfn(struct ipset_session *session,
107 extern struct ipset_session *ipset_session_init(ipset_outfn outfn);
108 extern int ipset_session_fini(struct ipset_session *session);
110 extern void ipset_debug_msg(const char *dir, void *buffer, int len);
116 #endif /* LIBIPSET_SESSION_H */