summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKen-ichirou MATSUZAWA <chamaken@gmail.com>2015-08-21 09:30:33 +0900
committerPablo Neira Ayuso <pablo@netfilter.org>2015-08-24 20:42:29 +0200
commit6b2f3c08adc2c84c0b5f969af6cfb4d44940e560 (patch)
tree3ce6910ba96235b223c0b951af38188ad2b0c292 /src
parent7ceefe50a1690d9b6d0125c9b9f53c959ae7a128 (diff)
nlmsg: add printf function in conjunction with libmnl
To printf nflog netlink message in XML, nflog_snprintf_xml can be used after converting nflog nlattrs to nflog_data, but we should not have any code that mixes both new and old, which handles nflog_data, APIs. The idea is to deprecate libnfnetlink and any client of that library at some point, that will take quite time though since we'll have to mark those old interfaces as deprecated. Signed-off-by: Ken-ichirou MATSUZAWA <chamas@h4.dion.ne.jp>
Diffstat (limited to 'src')
-rw-r--r--src/libnetfilter_log.c6
-rw-r--r--src/nlmsg.c53
2 files changed, 54 insertions, 5 deletions
diff --git a/src/libnetfilter_log.c b/src/libnetfilter_log.c
index e92576b..567049c 100644
--- a/src/libnetfilter_log.c
+++ b/src/libnetfilter_log.c
@@ -26,6 +26,7 @@
#include <errno.h>
#include <netinet/in.h>
#include <sys/socket.h>
+#include "internal.h"
#include <libnetfilter_log/linux_nfnetlink_log.h>
@@ -78,11 +79,6 @@ struct nflog_g_handle
void *data;
};
-struct nflog_data
-{
- struct nfattr **nfa;
-};
-
int nflog_errno;
/***********************************************************************
diff --git a/src/nlmsg.c b/src/nlmsg.c
index 63db96a..0aa21a0 100644
--- a/src/nlmsg.c
+++ b/src/nlmsg.c
@@ -9,6 +9,9 @@
#include <arpa/inet.h>
#include <linux/netfilter/nfnetlink_log.h>
#include <libmnl/libmnl.h>
+#include <libnetfilter_log/libnetfilter_log.h>
+#include <errno.h>
+#include "internal.h"
/**
* \defgroup nlmsg Netlink message helper functions
@@ -157,5 +160,55 @@ int nflog_nlmsg_parse(const struct nlmsghdr *nlh, struct nlattr **attr)
}
/**
+ * nflog_nlmsg_snprintf - print a nflog nlattrs to a buffer
+ * \param buf buffer used to build the printable nflog
+ * \param bufsiz size of the buffer
+ * \param nlh netlink message (to get queue num in the futuer)
+ * \param attr pointer to a nflog attrs
+ * \param type print message type in enum nflog_output_type
+ * \param flags The flag that tell what to print into the buffer
+ *
+ * This function supports the following type - flags:
+ *
+ * type: NFLOG_OUTPUT_XML
+ * - NFLOG_XML_PREFIX: include the string prefix
+ * - NFLOG_XML_HW: include the hardware link layer address
+ * - NFLOG_XML_MARK: include the packet mark
+ * - NFLOG_XML_DEV: include the device information
+ * - NFLOG_XML_PHYSDEV: include the physical device information
+ * - NFLOG_XML_PAYLOAD: include the payload (in hexadecimal)
+ * - NFLOG_XML_TIME: include the timestamp
+ * - NFLOG_XML_ALL: include all the logging information (all flags set)
+ *
+ * You can combine this flags with an binary OR.
+ *
+ * this function returns -1 and errno is explicitly set in case of
+ * failure, otherwise the length of the string that would have been
+ * printed into the buffer (in case that there is enough room in
+ * it). See snprintf() return value for more information.
+ */
+int nflog_nlmsg_snprintf(char *buf, size_t bufsiz, const struct nlmsghdr *nlh,
+ struct nlattr **attr, enum nflog_output_type type,
+ uint32_t flags)
+{
+ /* This is a hack to re-use the existing old API code. */
+ struct nflog_data nfad = {
+ .nfa = (struct nfattr **)&attr[1],
+ };
+ int ret;
+
+ switch (type) {
+ case NFLOG_OUTPUT_XML:
+ ret = nflog_snprintf_xml(buf, bufsiz, &nfad, flags);
+ break;
+ default:
+ ret = -1;
+ errno = EOPNOTSUPP;
+ break;
+ }
+ return ret;
+}
+
+/**
* @}
*/