Skip to contentSkip to conversation

ulogd2 supports nfacct infrastructure

PATCH New [email protected] 1 participant 4 messages Feb 22, 2012 netfilter

lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

cover ulogd2 supports nfacct infrastructure

From: Pablo Neira Ayuso <[email protected]>

Hi,

The upcoming kernel will contain the nfacct infrastructure:

http://lwn.net/Articles/473998/

This patchset contains the support for ulogd2. It also contains the GPRINT output plugin, that is a generic output in comma-separated key-value format.

I pushed the patches to git.netfilter.org, if you find any issue, please send me follow-up patches and I'll apply them.

Thanks!

Pablo Neira Ayuso (3):
output: add GPRINT plugin
input: add nfacct plugin
src: add example use of GPRINT to ulogd.conf.in configuration file

 configure.ac                             |    4 +
 include/Makefile.am                      |    2 +-
 include/linux/Makefile.am                |    2 +
 include/linux/netfilter/Makefile.am      |    2 +
 include/linux/netfilter/nfnetlink_acct.h |   36 ++++
 input/Makefile.am                        |    2 +-
 input/sum/Makefile.am                    |    8 +
 input/sum/ulogd_inpflow_NFACCT.c         |  265 +++++++++++++++++++++++++++++
 output/Makefile.am                       |    5 +-
 output/ulogd_output_GPRINT.c             |  270 ++++++++++++++++++++++++++++++
 ulogd.conf.in                            |   21 ++-
 11 files changed, 611 insertions(+), 6 deletions(-)
 create mode 100644 include/linux/Makefile.am
 create mode 100644 include/linux/netfilter/Makefile.am
 create mode 100644 include/linux/netfilter/nfnetlink_acct.h
 create mode 100644 input/sum/Makefile.am
 create mode 100644 input/sum/ulogd_inpflow_NFACCT.c
 create mode 100644 output/ulogd_output_GPRINT.c
Signature · 1 line
1.7.7.3
author maintainer
#1 lore raw

PATCH 1/3 output: add GPRINT plugin

From: Pablo Neira Ayuso <[email protected]>

This patch adds GPRINT which is a generalization of OPRINT.

It display the set of key-values separated by commas. This is the generic print that you can attach to whatever kind of input plugin.

---
 output/Makefile.am           |    5 +-
 output/ulogd_output_GPRINT.c |  270 ++++++++++++++++++++++++++++++++++++++++++
 ulogd.conf.in                |    6 +
 3 files changed, 280 insertions(+), 1 deletions(-)
 create mode 100644 output/ulogd_output_GPRINT.c
output/Makefile.am +4 -1
index 2ec6e8d..bb93b28 100644
@@ -5,9 +5,12 @@ AM_CFLAGS = ${regular_CFLAGS} ${LIBNETFILTER_LOG_CFLAGS} \
 SUBDIRS= pcap mysql pgsql sqlite3 dbi
 
 pkglibexec_LTLIBRARIES = ulogd_output_LOGEMU.la ulogd_output_SYSLOG.la \
-			 ulogd_output_OPRINT.la \
+			 ulogd_output_OPRINT.la ulogd_output_GPRINT.la \
 			 ulogd_output_NACCT.la ulogd_output_XML.la
 
+ulogd_output_GPRINT_la_SOURCES = ulogd_output_GPRINT.c
+ulogd_output_GPRINT_la_LDFLAGS = -avoid-version -module
+
 ulogd_output_LOGEMU_la_SOURCES = ulogd_output_LOGEMU.c
 ulogd_output_LOGEMU_la_LDFLAGS = -avoid-version -module
 
output/ulogd_output_GPRINT.c new file +270 -0

270 lines not on this page · raw message

ulogd.conf.in +6 -0
index ac7bcae..c0c8559 100644
@@ -42,6 +42,7 @@ plugin="@pkglibexecdir@/ulogd_output_SYSLOG.so"
 plugin="@pkglibexecdir@/ulogd_output_XML.so"
 #plugin="@pkglibexecdir@/ulogd_output_SQLITE3.so"
 #plugin="@pkglibexecdir@/ulogd_output_OPRINT.so"
+plugin="@pkglibexecdir@/ulogd_output_GPRINT.so"
 #plugin="@pkglibexecdir@/ulogd_output_NACCT.so"
 #plugin="@pkglibexecdir@/ulogd_output_PCAP.so"
 #plugin="@pkglibexecdir@/ulogd_output_PGSQL.so"
@@ -167,6 +168,11 @@ sync=1
 file="/var/log/ulogd_oprint.log"
 sync=1
 
+[gp1]
+file="/var/log/ulogd_gprint.log"
+sync=1
+timestamp=1
+
 [xml1]
 directory="/var/log/"
 sync=1
Signature · 1 line
1.7.7.3
author maintainer
#2 lore raw

PATCH 2/3 input: add nfacct plugin

In reply to [email protected]

From: Pablo Neira Ayuso <[email protected]>

This patch adds the nfacct plugin.

---
 configure.ac                             |    4 +
 include/Makefile.am                      |    2 +-
 include/linux/Makefile.am                |    2 +
 include/linux/netfilter/Makefile.am      |    2 +
 include/linux/netfilter/nfnetlink_acct.h |   36 ++++
 input/Makefile.am                        |    2 +-
 input/sum/Makefile.am                    |    8 +
 input/sum/ulogd_inpflow_NFACCT.c         |  265 ++++++++++++++++++++++++++++++
 ulogd.conf.in                            |    7 +
 9 files changed, 326 insertions(+), 2 deletions(-)
 create mode 100644 include/linux/Makefile.am
 create mode 100644 include/linux/netfilter/Makefile.am
 create mode 100644 include/linux/netfilter/nfnetlink_acct.h
 create mode 100644 input/sum/Makefile.am
 create mode 100644 input/sum/ulogd_inpflow_NFACCT.c
configure.ac +4 -0
index 132cdbf..89fc338 100644
@@ -41,6 +41,8 @@ AC_SUBST([regular_CFLAGS])
 
 dnl Check for the right nfnetlink version
 PKG_CHECK_MODULES([LIBNFNETLINK], [libnfnetlink >= 0.0.39])
+PKG_CHECK_MODULES([LIBMNL], [libmnl >= 1.0.0])
+PKG_CHECK_MODULES([LIBNETFILTER_ACCT], [libnetfilter_acct >= 1.0.0])
 PKG_CHECK_MODULES([LIBNETFILTER_CONNTRACK], [libnetfilter_conntrack >= 0.0.95])
 PKG_CHECK_MODULES([LIBNETFILTER_LOG], [libnetfilter_log >= 1.0.0])
 
@@ -74,8 +76,10 @@ dnl AM_CONDITIONAL(HAVE_MYSQL, test x$mysqldir != x)
 dnl AM_CONDITIONAL(HAVE_PGSQL, test x$pgsqldir != x)
 
 AC_CONFIG_FILES(include/Makefile include/ulogd/Makefile include/libipulog/Makefile \
+	  include/linux/Makefile include/linux/netfilter/Makefile \
 	  libipulog/Makefile \
 	  input/Makefile input/packet/Makefile input/flow/Makefile \
+	  input/sum/Makefile \
 	  filter/Makefile filter/raw2packet/Makefile filter/packet2flow/Makefile \
 	  output/Makefile output/pcap/Makefile output/mysql/Makefile output/pgsql/Makefile output/sqlite3/Makefile \
 	  output/dbi/Makefile \
include/Makefile.am +1 -1
index fa34473..c62b497 100644
@@ -1 +1 @@
-SUBDIRS = ulogd libipulog
+SUBDIRS = ulogd libipulog linux
include/linux/Makefile.am new file +2 -0
new file mode 100644
index 0000000..ca80d0d
@@ -0,0 +1,2 @@
+
+SUBDIRS = netfilter
include/linux/netfilter/Makefile.am new file +2 -0
new file mode 100644
index 0000000..fc05a9c
@@ -0,0 +1,2 @@
+
+noinst_HEADERS = nfnetlink_acct.h
include/linux/netfilter/nfnetlink_acct.h new file +36 -0
new file mode 100644
index 0000000..7c4279b
@@ -0,0 +1,36 @@
+#ifndef _NFNL_ACCT_H_
+#define _NFNL_ACCT_H_
+
+#ifndef NFACCT_NAME_MAX
+#define NFACCT_NAME_MAX		32
+#endif
+
+enum nfnl_acct_msg_types {
+	NFNL_MSG_ACCT_NEW,
+	NFNL_MSG_ACCT_GET,
+	NFNL_MSG_ACCT_GET_CTRZERO,
+	NFNL_MSG_ACCT_DEL,
+	NFNL_MSG_ACCT_MAX
+};
+
+enum nfnl_acct_type {
+	NFACCT_UNSPEC,
+	NFACCT_NAME,
+	NFACCT_PKTS,
+	NFACCT_BYTES,
+	NFACCT_USE,
+	__NFACCT_MAX
+};
+#define NFACCT_MAX (__NFACCT_MAX - 1)
+
+#ifdef __KERNEL__
+
+struct nf_acct;
+
+extern struct nf_acct *nfnl_acct_find_get(const char *filter_name);
+extern void nfnl_acct_put(struct nf_acct *acct);
+extern void nfnl_acct_update(const struct sk_buff *skb, struct nf_acct *nfacct);
+
+#endif /* __KERNEL__ */
+
+#endif /* _NFNL_ACCT_H */
input/Makefile.am +1 -1
index 77f2838..5ffef1b 100644
@@ -1,2 +1,2 @@
 
-SUBDIRS = packet flow
+SUBDIRS = packet flow sum
input/sum/Makefile.am new file +8 -0
new file mode 100644
index 0000000..04051b4
@@ -0,0 +1,8 @@
+AM_CPPFLAGS = -I$(top_srcdir)/include
+AM_CFLAGS = ${regular_CFLAGS}
+
+pkglibexec_LTLIBRARIES = ulogd_inpflow_NFACCT.la
+
+ulogd_inpflow_NFACCT_la_SOURCES = ulogd_inpflow_NFACCT.c
+ulogd_inpflow_NFACCT_la_LDFLAGS = -avoid-version -module $(LIBMNL_LIBS) $(LIBNETFILTER_ACCT_LIBS)
+ulogd_inpflow_NFACCT_la_CFLAGS = $(AM_CFLAGS) $(LIBMNL_LIBS) $(LIBNETFILTER_ACCT_CFLAGS)
input/sum/ulogd_inpflow_NFACCT.c new file +265 -0

265 lines not on this page · raw message

ulogd.conf.in +7 -0
index c0c8559..71e8255 100644
@@ -49,6 +49,7 @@ plugin="@pkglibexecdir@/ulogd_output_GPRINT.so"
 #plugin="@pkglibexecdir@/ulogd_output_MYSQL.so"
 #plugin="@pkglibexecdir@/ulogd_output_DBI.so"
 plugin="@pkglibexecdir@/ulogd_raw2packet_BASE.so"
+plugin="@pkglibexecdir@/ulogd_inpflow_NFACCT.so"
 
 # this is a stack for logging packet send by system via LOGEMU
 #stack=log1:NFLOG,base1:BASE,ifi1:IFINDEX,ip2str1:IP2STR,print1:PRINTPKT,emu1:LOGEMU
@@ -107,6 +108,9 @@ plugin="@pkglibexecdir@/ulogd_raw2packet_BASE.so"
 # this is a stack for flow-based logging in NACCT compatible format
 #stack=ct1:NFCT,ip2str1:IP2STR,nacct1:NACCT
 
+# this is a stack for accounting-based logging via GPRINT
+#stack=acct1:NFACCT,gp1:GPRINT
+
 [ct1]
 #netlink_socket_buffer_size=217088
 #netlink_socket_buffer_maxsize=1085440
@@ -250,3 +254,6 @@ sync = 1
 
 [mark1]
 mark = 1
+
+[acct1]
+pollinterval = 2
Signature · 1 line
1.7.7.3
author maintainer
#3 lore raw

PATCH 3/3 src: add example use of GPRINT to ulogd.conf.in configuration file

In reply to [email protected]

From: Pablo Neira Ayuso <[email protected]>

Example on how this display one conntrack:

timestamp=2012/02/22-13:16:54,orig.ip.saddr=192.168.1.129,orig.ip.daddr=173.194.34.235,orig.ip.protocol=6,orig.l4.sport=58221,orig.l4.dport=80,orig.raw.pktlen=1206,orig.raw.pktcount=4,reply.ip.saddr=173.194.34.235,reply.ip.daddr=192.168.1.129,reply.ip.protocol=6,reply.l4.sport=80,reply.l4.dport=58221,reply.raw.pktlen=1104,reply.raw.pktcount=3,ct.mark=0,ct.id=846180008,ct.event=4,flow.end.sec=1329913014,flow.end.usec=413771,oob.family=2,oob.protocol=0

and one NFLOG line look like this

timestamp=2012/02/22-13:21:24,raw.pktlen=40,raw.pktcount=1,oob.prefix=test,oob.time.sec=1329913284,oob.time.usec=226795,oob.mark=0,oob.ifindex_in=3,oob.hook=1,raw.mac_len=14,oob.family=2,oob.protocol=2048,raw.label=0,raw.type=1,raw.mac.addrlen=6

People that like parsing comma-separated key-value files will like this.

---
 ulogd.conf.in |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)
ulogd.conf.in +5 -3
index 71e8255..b33e69c 100644
@@ -41,7 +41,6 @@ plugin="@pkglibexecdir@/ulogd_output_LOGEMU.so"
 plugin="@pkglibexecdir@/ulogd_output_SYSLOG.so"
 plugin="@pkglibexecdir@/ulogd_output_XML.so"
 #plugin="@pkglibexecdir@/ulogd_output_SQLITE3.so"
-#plugin="@pkglibexecdir@/ulogd_output_OPRINT.so"
 plugin="@pkglibexecdir@/ulogd_output_GPRINT.so"
 #plugin="@pkglibexecdir@/ulogd_output_NACCT.so"
 #plugin="@pkglibexecdir@/ulogd_output_PCAP.so"
@@ -63,11 +62,14 @@ plugin="@pkglibexecdir@/ulogd_inpflow_NFACCT.so"
 # this is a stack for packet-based logging via LOGEMU with filtering on MARK
 #stack=log2:NFLOG,mark1:MARK,base1:BASE,ifi1:IFINDEX,ip2str1:IP2STR,print1:PRINTPKT,emu1:LOGEMU
 
+# this is a stack for packet-based logging via GPRINT
+#stack=log1:NFLOG,gp1:GPRINT
+
 # this is a stack for flow-based logging via LOGEMU
 #stack=ct1:NFCT,ip2str1:IP2STR,print1:PRINTFLOW,emu1:LOGEMU
 
-# this is a stack for flow-based logging via OPRINT
-#stack=ct1:NFCT,op1:OPRINT
+# this is a stack for flow-based logging via GPRINT
+#stack=ct1:NFCT,gp1:GPRINT
 
 # this is a stack for flow-based logging via XML
 #stack=ct1:NFCT,xml1:XML
Signature · 1 line
1.7.7.3