IPFIX: Add IPFIX output plugin
PATCH v2 1/2 IPFIX: Add IPFIX output plugin
From: Ander Juaristi <[email protected]>
This patch adds an IPFIX output plugin to ulogd2. It generates NetFlow/IPFIX traces and sends them to a remote server (collector) via TCP or UDP.
Based on original work by Holger Eitzenberger <[email protected]>.
How to test this
----------------
I am currently testing this with the NFCT input and Wireshark.
Place the following in ulogd.conf:
# this will print all flows on screen
loglevel=1 # load NFCT and IPFIX plugins
plugin="/lib/ulogd/ulogd_inpflow_NFCT.so"
plugin="/lib/ulogd/ulogd_output_IPFIX.so" stack=ct1:NFCT,ipfix1:IPFIX
[ct1]
netlink_socket_buffer_size=217088
netlink_socket_buffer_maxsize=1085440
accept_proto_filter=tcp,sctp
[ipfix1]
oid=1
host="127.0.0.1"
#port=4739
#send_template="once"I am currently testing it by launching a plain NetCat listener on port 4739 (the default for IPFIX) and then running Wireshark and see that it dissects the IPFIX/NetFlow traffic correctly (obviously this relies on the Wireshark NetFlow dissector being correct).
First:
nc -vvvv -l 127.0.0.1 4739
Then:
sudo ulogd -vc ulogd.conf
--- configure.ac | 2 +- include/ulogd/ulogd.h | 5 + input/flow/ulogd_inpflow_IPFIX.c | 2 - output/Makefile.am | 2 +- output/ipfix/Makefile.am | 7 + output/ipfix/ipfix.c | 141 ++++++++ output/ipfix/ipfix.h | 89 +++++ output/ipfix/ulogd_output_IPFIX.c | 503 +++++++++++++++++++++++++++ output/ulogd_output_IPFIX.c | 546 ------------------------------ 9 files changed, 747 insertions(+), 550 deletions(-) delete mode 100644 input/flow/ulogd_inpflow_IPFIX.c create mode 100644 output/ipfix/Makefile.am create mode 100644 output/ipfix/ipfix.c create mode 100644 output/ipfix/ipfix.h create mode 100644 output/ipfix/ulogd_output_IPFIX.c delete mode 100644 output/ulogd_output_IPFIX.c
configure.ac +1 -1
@@ -179,7 +179,7 @@ AC_CONFIG_FILES(include/Makefile include/ulogd/Makefile include/libipulog/Makefi 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 \ + output/dbi/Makefile output/ipfix/Makefile \ src/Makefile Makefile Rules.make) AC_OUTPUT
include/ulogd/ulogd.h +5 -0
@@ -28,6 +28,11 @@/* types without length */ #define ULOGD_RET_NONE 0x0000 +#define __packed __attribute__((packed)) +#define __noreturn __attribute__((noreturn)) +#define __cold __attribute__((cold)) + +#define __packed __attribute__((packed))#define ULOGD_RET_INT8 0x0001#define ULOGD_RET_INT16 0x0002
input/flow/ulogd_inpflow_IPFIX.c deleted +0 -2
@@ -1,2 +0,0 @@ -/* */ -
output/Makefile.am +1 -1
@@ -2,7 +2,7 @@ AM_CPPFLAGS = -I$(top_srcdir)/include ${LIBNETFILTER_ACCT_CFLAGS} \ ${LIBNETFILTER_CONNTRACK_CFLAGS} ${LIBNETFILTER_LOG_CFLAGS} AM_CFLAGS = ${regular_CFLAGS} -SUBDIRS= pcap mysql pgsql sqlite3 dbi +SUBDIRS= pcap mysql pgsql sqlite3 dbi ipfix pkglib_LTLIBRARIES = ulogd_output_LOGEMU.la ulogd_output_SYSLOG.la \ ulogd_output_OPRINT.la ulogd_output_GPRINT.la \
output/ipfix/Makefile.am new file +7 -0
@@ -0,0 +1,7 @@ +AM_CPPFLAGS = -I$(top_srcdir)/include +AM_CFLAGS = $(regular_CFLAGS) + +pkglib_LTLIBRARIES = ulogd_output_IPFIX.la + +ulogd_output_IPFIX_la_SOURCES = ulogd_output_IPFIX.c ipfix.c +ulogd_output_IPFIX_la_LDFLAGS = -avoid-version -module
output/ipfix/ipfix.c new file +141 -0
141 lines not on this page · raw message
output/ipfix/ipfix.h new file +89 -0
89 lines not on this page · raw message
output/ipfix/ulogd_output_IPFIX.c new file +503 -0
503 lines not on this page · raw message
output/ulogd_output_IPFIX.c deleted +0 -546
546 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v2 2/2 IPFIX: Introduce template record support
From: Ander Juaristi <[email protected]>
This commit adds the ability to send template records to the remote collector.
In addition, it also introduces a new
configuration parameter 'send_template', which tells when template records should be sent. It accepts the following string values:
- "once": Send the template record only the first time (might be coalesced with data records).
- "always": Send the template record always, with every data record that is sent to the collector (multiple data records might be sent together).
- "never": Assume the collector knows the schema already. Do not send template records.
If omitted, the default value for 'send_template' is "once".
--- include/ulogd/ipfix_protocol.h | 1 + output/ipfix/ipfix.c | 97 ++++++++++++++++++++++++++++++- output/ipfix/ipfix.h | 22 +++---- output/ipfix/ulogd_output_IPFIX.c | 56 ++++++++++-------- 4 files changed, 139 insertions(+), 37 deletions(-)
include/ulogd/ipfix_protocol.h +1 -0
@@ -129,6 +129,7 @@ enum {/* reserved */ IPFIX_fragmentOffsetIPv4 =88 ,/* reserved */ + IPFIX_applicationId =95 , IPFIX_bgpNextAdjacentAsNumber =128 , IPFIX_bgpPrevAdjacentAsNumber =129 , IPFIX_exporterIPv4Address = 130,
output/ipfix/ipfix.c +94 -3
131 lines not on this page · raw message
output/ipfix/ipfix.h +11 -11
@@ -2,6 +2,7 @@* ipfix.h * * Holger Eitzenberger <[email protected]>, 2009. +* Ander Juaristi <[email protected]>, 2019 */ #ifndef IPFIX_H #define IPFIX_H
@@ -20,17 +21,21 @@ struct ipfix_hdr {uint8_t data[]; } __packed; -#define IPFIX_HDRLEN sizeof(struct ipfix_hdr) +#define IPFIX_HDRLEN sizeof(struct ipfix_hdr)/* * IDs 0-255 are reserved for Template Sets. IDs of Data Sets are > 255. */ struct ipfix_templ_hdr { -uint16_t id; +uint16_t sid; +uint16_t len; +uint16_t tid;uint16_t cnt;uint8_t data[]; } __packed; +#define IPFIX_TEMPL_HDRLEN (nfields) sizeof(struct ipfix_templ_hdr) + (sizeof(uint16_t) * 2 * nfields) +struct ipfix_set_hdr {#define IPFIX_SET_TEMPL 2#define IPFIX_SET_OPT_TEMPL 3
@@ -46,6 +51,7 @@ struct ipfix_msg {uint8_t *tail;uint8_t *end;unsigned nrecs; +int tid;struct ipfix_set_hdr *last_set;uint8_t data[]; };
@@ -53,18 +59,14 @@ struct ipfix_msg {struct vy_ipfix_data {struct in_addr saddr;struct in_addr daddr; -uint16_t ifi_in; -uint16_t ifi_out;uint32_t packets;uint32_t bytes;uint32_t start;/* Unix time */ uint32_t end;/* Unix time */ uint16_t sport;uint16_t dport; -uint32_t aid;/* Application ID */ uint8_t l4_proto; -uint8_t dscp; -uint16_t __padding; +uint32_t aid;/* Application ID */ } __packed;#define VY_IPFIX_SID 256
@@ -73,13 +75,11 @@ struct vy_ipfix_data {#define VY_IPFIX_PKT_LEN (IPFIX_HDRLEN + IPFIX_SET_HDRLEN \ + VY_IPFIX_FLOWS * sizeof(struct vy_ipfix_data)) -/* template management */ -size_t ipfix_rec_len (uint16_t ); -/* message handling */ -struct ipfix_msg *ipfix_msg_alloc (size_t ,uint32_t ); +struct ipfix_msg *ipfix_msg_alloc (size_t ,uint32_t ,int );void ipfix_msg_free (struct ipfix_msg *);struct ipfix_hdr *ipfix_msg_hdr (const struct ipfix_msg *); +struct ipfix_templ_hdr *ipfix_msg_templ_hdr (const struct ipfix_msg *);size_t ipfix_msg_len (const struct ipfix_msg *);void *ipfix_msg_data (struct ipfix_msg *);struct ipfix_set_hdr *ipfix_msg_add_set (struct ipfix_msg *,uint16_t );
output/ipfix/ulogd_output_IPFIX.c +33 -23
155 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH ulogd2,v2 2/2] IPFIX: Introduce template record support
Quoted 9 lines · On Fri, Apr 26, 2019 at 09:58:07AM +0200, [email protected] wrote:
From: Ander Juaristi <[email protected]>
This commit adds the ability to send template records to the remote collector.
In addition, it also introduces a new
configuration parameter 'send_template', which tells when template records should be sent. It accepts the following string values:
Quoted 7 lines
- "once": Send the template record only the first time (might be coalesced with data records).
- "always": Send the template record always, with every data record that is sent to the collector (multiple data records might be sent together).
- "never": Assume the collector knows the schema already. Do not send template records.If omitted, the default value for '
send_template' is "once".
Applied, thanks.
Quoted 39 lines · On Fri, Apr 26, 2019 at 09:58:06AM +0200, [email protected] wrote:
From: Ander Juaristi <[email protected]>
This patch adds an IPFIX output plugin to ulogd2. It generates NetFlow/IPFIX traces and sends them to a remote server (collector) via TCP or UDP.
Based on original work by Holger Eitzenberger <[email protected]>.
How to test this
----------------I am currently testing this with the NFCT input and Wireshark.
Place the following in ulogd.conf:
# this will print all flows on screen loglevel=1# load NFCT and IPFIX plugins plugin="/lib/ulogd/ulogd_inpflow_NFCT.so" plugin="/lib/ulogd/ulogd_output_IPFIX.so"stack=ct1:NFCT,ipfix1:IPFIX [ct1] netlink_socket_buffer_size=217088 netlink_socket_buffer_maxsize=1085440 accept_proto_filter=tcp,sctp [ipfix1] oid=1 host="127.0.0.1" #port=4739 #send_template="once"I am currently testing it by launching a plain NetCat listener on port 4739 (the default for IPFIX) and then running Wireshark and see that it dissects the IPFIX/NetFlow traffic correctly (obviously this relies on the Wireshark NetFlow dissector being correct).
Quoted 7 lines
First:
nc -vvvv -l 127.0.0.1 4739Then:
sudo ulogd -vc ulogd.conf
Applied, thanks.