summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2012-05-26 15:06:29 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2012-05-26 15:08:41 +0200
commitf156d51b35485befb6aa9b750ab9fe462e25dd56 (patch)
treeb0d2b7362b15355bc4cd10b892d1b34c7a400349
parentef53066dfaf1b5467c790bfa65a295a6cccd7562 (diff)
src: add new parameter type to nfct_timeout_snprintf
Thus, we can extend this interface to support the timeout policy in XML output in the future. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rw-r--r--Make_global.am2
-rw-r--r--examples/nfct-timeout-get.c2
-rw-r--r--include/libnetfilter_cttimeout/libnetfilter_cttimeout.h6
-rw-r--r--src/libnetfilter_cttimeout.c45
-rw-r--r--src/libnetfilter_cttimeout.map10
5 files changed, 45 insertions, 20 deletions
diff --git a/Make_global.am b/Make_global.am
index 1654f10..986b0fb 100644
--- a/Make_global.am
+++ b/Make_global.am
@@ -18,7 +18,7 @@
# set age to 0.
# </snippet>
#
-LIBVERSION=0:0:0
+LIBVERSION=1:0:0
AM_CPPFLAGS = ${regular_CPPFLAGS} -I${top_srcdir}/include ${LIBMNL_CFLAGS}
AM_CFLAGS = ${regular_CFLAGS} ${GCC_FVISIBILITY_HIDDEN}
diff --git a/examples/nfct-timeout-get.c b/examples/nfct-timeout-get.c
index 211dedb..b2f62d0 100644
--- a/examples/nfct-timeout-get.c
+++ b/examples/nfct-timeout-get.c
@@ -32,7 +32,7 @@ static int timeout_cb(const struct nlmsghdr *nlh, void *data)
goto err_free;
}
- nfct_timeout_snprintf(buf, sizeof(buf), t, 0);
+ nfct_timeout_snprintf(buf, sizeof(buf), t, NFCT_TIMEOUT_O_DEFAULT, 0);
printf("%s\n", buf);
err_free:
diff --git a/include/libnetfilter_cttimeout/libnetfilter_cttimeout.h b/include/libnetfilter_cttimeout/libnetfilter_cttimeout.h
index e8e49ed..00c8b81 100644
--- a/include/libnetfilter_cttimeout/libnetfilter_cttimeout.h
+++ b/include/libnetfilter_cttimeout/libnetfilter_cttimeout.h
@@ -107,7 +107,11 @@ struct nlmsghdr *nfct_timeout_nlmsg_build_hdr(char *buf, uint8_t cmd, uint16_t f
void nfct_timeout_nlmsg_build_payload(struct nlmsghdr *, const struct nfct_timeout *);
int nfct_timeout_nlmsg_parse_payload(const struct nlmsghdr *nlh, struct nfct_timeout *);
-int nfct_timeout_snprintf(char *buf, size_t size, const struct nfct_timeout *, unsigned int flags);
+enum {
+ NFCT_TIMEOUT_O_DEFAULT,
+};
+
+int nfct_timeout_snprintf(char *buf, size_t size, const struct nfct_timeout *, unsigned int type, unsigned int flags);
#ifdef __cplusplus
} /* extern "C" */
diff --git a/src/libnetfilter_cttimeout.c b/src/libnetfilter_cttimeout.c
index b930089..1e6739d 100644
--- a/src/libnetfilter_cttimeout.c
+++ b/src/libnetfilter_cttimeout.c
@@ -356,19 +356,10 @@ const char *nfct_timeout_policy_attr_to_name(uint8_t l4proto, uint32_t state)
}
EXPORT_SYMBOL(nfct_timeout_policy_attr_to_name);
-
-/**
- * nfct_timeout_snprintf - print conntrack timeout object into one buffer
- * \param buf: pointer to buffer that is used to print the object
- * \param size: size of the buffer (or remaining room in it).
- * \param nfct_timeout: pointer to a valid conntrack timeout object.
- * \param flags: output flags (CTA_TIMEOUT_SNPRINTF_F_FULL).
- *
- * This function returns -1 in case that some mandatory attributes are
- * missing. On sucess, it returns 0.
- */
-int nfct_timeout_snprintf(char *buf, size_t size, const struct nfct_timeout *t,
- unsigned int flags)
+static int
+nfct_timeout_snprintf_default(char *buf, size_t size,
+ const struct nfct_timeout *t,
+ unsigned int flags)
{
int ret = 0;
unsigned int offset = 0;
@@ -426,6 +417,34 @@ int nfct_timeout_snprintf(char *buf, size_t size, const struct nfct_timeout *t,
return ret;
}
+
+/**
+ * nfct_timeout_snprintf - print conntrack timeout object into one buffer
+ * \param buf: pointer to buffer that is used to print the object
+ * \param size: size of the buffer (or remaining room in it).
+ * \param t: pointer to a valid conntrack timeout object.
+ * \param type: output type (see NFCT_TIMEOUT_O_*)
+ * \param flags: output flags (always set this to zero).
+ *
+ * This function returns -1 in case that some mandatory attributes are
+ * missing. On sucess, it returns 0.
+ */
+int nfct_timeout_snprintf(char *buf, size_t size, const struct nfct_timeout *t,
+ unsigned int type, unsigned int flags)
+{
+ int ret = 0;
+
+ switch(type) {
+ case NFCT_TIMEOUT_O_DEFAULT:
+ ret = nfct_timeout_snprintf_default(buf, size, t, flags);
+ break;
+ /* add your new output here. */
+ default:
+ break;
+ }
+
+ return ret;
+}
EXPORT_SYMBOL(nfct_timeout_snprintf);
/**
diff --git a/src/libnetfilter_cttimeout.map b/src/libnetfilter_cttimeout.map
index 788b7f2..1c854cc 100644
--- a/src/libnetfilter_cttimeout.map
+++ b/src/libnetfilter_cttimeout.map
@@ -12,11 +12,13 @@ global:
nfct_timeout_nlmsg_build_hdr;
nfct_timeout_nlmsg_build_payload;
nfct_timeout_nlmsg_parse_payload;
- nfct_timeout_snprintf;
+ /* nfct_timeout_snprintf prototype was modified, new version in 1.1.
+ I decided not to keep the old symbol compatibility. See git log
+ for more information. */
local: *;
};
-#LIBNETFILTER_CTTIMEOUT_1.1 {
-# _my_new_func;
-#} LIBNETFILTER_CTTIMEOUT_1.0;
+LIBNETFILTER_CTTIMEOUT_1.1 {
+ nfct_timeout_snprintf;
+} LIBNETFILTER_CTTIMEOUT_1.0;