new file mode 100644
@@ -0,0 +1,9 @@
+#ifndef _LIBNETFILTER_LOG_INTERNAL_H
+#define _LIBNETFILTER_LOG_INTERNAL_H
+
+struct nflog_data
+{
+ struct nfattr **nfa;
+};
+
+#endif
@@ -89,4 +89,12 @@ extern int nfnl_attr_put_cfg_mode(struct nlmsghdr *nlh, uint8_t mode, uint32_t r
extern int nfnl_attr_put_cfg_cmd(struct nlmsghdr *nlh, uint8_t cmd);
extern int nfnl_nlmsg_parse(const struct nlmsghdr *nlh, struct nlattr **attr);
+enum nflog_output_type {
+ NFLOG_OUTPUT_XML = 0,
+};
+
+int nflog_nlmsg_snprintf(char *buf, size_t bufsiz, const struct nlmsghdr *nlh,
+ struct nlattr **attr, enum nflog_output_type type,
+ uint32_t flags);
+
#endif /* __LIBNETFILTER_LOG_H */
@@ -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;
/***********************************************************************
@@ -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
@@ -156,6 +159,27 @@ int nfnl_nlmsg_parse(const struct nlmsghdr *nlh, struct nlattr **attr)
nfnl_parse_attr_cb, attr);
}
+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);
+ default:
+ ret = -1;
+ errno = EOPNOTSUPP;
+ break;
+ }
+ return ret;
+}
+
/**
* @}
*/
@@ -14,6 +14,7 @@ static int log_cb(const struct nlmsghdr *nlh, void *data)
struct nfulnl_msg_packet_hdr *ph = NULL;
const char *prefix = NULL;
uint32_t mark = 0;
+ char buf[4096];
int ret;
ret = nfnl_nlmsg_parse(nlh, attrs);
@@ -31,6 +32,10 @@ static int log_cb(const struct nlmsghdr *nlh, void *data)
prefix ? prefix : "", ntohs(ph->hw_protocol), ph->hook,
mark);
+ nflog_nlmsg_snprintf(buf, sizeof(buf), nlh, attrs, NFLOG_OUTPUT_XML,
+ NFLOG_XML_ALL);
+ printf("%s (ret =%d)\n", buf, ret);
+
return MNL_CB_OK;
}