Skip to content

Commit f9c1b2b

Browse files
committed
Merge remote-tracking branch 'origin/netflow' into devel
2 parents dfa3a02 + a46e45a commit f9c1b2b

File tree

25 files changed

+7586
-32
lines changed

25 files changed

+7586
-32
lines changed

include/ipfixcol2/api.h.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ extern "C" {
105105
// Note: Following codes preservers the same numbering as libfds
106106
/** Status code for success */
107107
#define IPX_OK (0)
108+
/** Status code for the end of a context */
109+
#define IPX_EOC (-1)
108110
/** Status code for ready operation */
109111
#define IPX_READY (-11)
110112
/** Status code for memory allocation error */

include/ipfixcol2/message_ipfix.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,12 @@ struct ipx_ipfix_record {
116116
* \param[in] plugin_ctx Context of the plugin
117117
* \param[in] msg_ctx Message context (info about Transport Session, ODID, etc.)
118118
* \param[in] msg_data Pointer to the IPFIX (or NetFlow) Message header
119+
* \param[in] msg_size Total size of the IPFIX (or NetFlow) Message
119120
* \return Pointer or NULL (memory allocation error)
120121
*/
121122
IPX_API ipx_msg_ipfix_t *
122123
ipx_msg_ipfix_create(const ipx_ctx_t *plugin_ctx, const struct ipx_msg_ctx *msg_ctx,
123-
uint8_t *msg_data);
124+
uint8_t *msg_data, uint16_t msg_size);
124125

125126
/**
126127
* \brief Destroy a message wrapper with a parsed IPFIX packet

src/core/CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ set(CORE_SOURCE
1717
configurator/plugin_mgr.hpp
1818
configurator/model.cpp
1919
configurator/model.hpp
20+
netflow2ipfix/netflow2ipfix.h
21+
netflow2ipfix/netflow5.c
22+
netflow2ipfix/netflow9.c
23+
netflow2ipfix/netflow9_templates.c
24+
netflow2ipfix/netflow9_templates.h
25+
netflow2ipfix/netflow9_parsers.c
26+
netflow2ipfix/netflow9_parsers.h
27+
netflow2ipfix/netflow_structs.h
2028
api.c
2129
context.c
2230
context.h
@@ -76,4 +84,4 @@ set_target_properties(ipfixcol2 PROPERTIES # by default, hide all symbols
7684
install(
7785
TARGETS ipfixcol2
7886
DESTINATION bin
79-
)
87+
)

src/core/message_ipfix.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ ipx_msg_ipfix_size(uint32_t rec_cnt, size_t rec_size)
6060

6161
ipx_msg_ipfix_t *
6262
ipx_msg_ipfix_create(const ipx_ctx_t *plugin_ctx, const struct ipx_msg_ctx *msg_ctx,
63-
uint8_t *msg_data)
63+
uint8_t *msg_data, uint16_t msg_size)
6464
{
6565
const size_t rec_size = ipx_ctx_recsize_get(plugin_ctx);
6666
const size_t new_size = ipx_msg_ipfix_size(REC_DEF_CNT, rec_size);
@@ -72,6 +72,7 @@ ipx_msg_ipfix_create(const ipx_ctx_t *plugin_ctx, const struct ipx_msg_ctx *msg_
7272
ipx_msg_header_init(&wrapper->msg_header, IPX_MSG_IPFIX);
7373
wrapper->ctx = *msg_ctx;
7474
wrapper->raw_pkt = msg_data;
75+
wrapper->raw_size = msg_size;
7576
wrapper->sets.cnt_alloc = SET_DEF_CNT;
7677
wrapper->rec_info.cnt_alloc = REC_DEF_CNT;
7778
wrapper->rec_info.rec_size = rec_size;

src/core/message_ipfix.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ struct ipx_msg_ipfix {
6767
struct ipx_msg_ctx ctx;
6868
/** Raw IPFIX packet from a source (in Network Byte Order) */
6969
uint8_t *raw_pkt;
70+
/** Size of raw message */
71+
uint16_t raw_size;
7072

7173
struct {
7274
/** Array of sets (valid only when #cnt_valid <= SET_DEF_CNT) */
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
/**
2+
* @file src/core/netflow2ipfix/netflow2ipfix.h
3+
* @author Lukas Hutak <[email protected]>
4+
* @brief Main NetFlow v5/v9 to IPFIX converter functions (header file)
5+
* @date 2018-2019
6+
*
7+
* Copyright(c) 2019 CESNET z.s.p.o.
8+
* SPDX-License-Identifier: BSD-3-Clause
9+
*/
10+
11+
#ifndef IPFIXCOL2_NETFLOW2IPFIX_H
12+
#define IPFIXCOL2_NETFLOW2IPFIX_H
13+
14+
#include <stdint.h>
15+
#include <stddef.h>
16+
#include <ipfixcol2.h>
17+
18+
/**
19+
* @defgroup nf5_to_ipfix NetFlow v5 to IPFIX
20+
* @brief Conversion from NetFlow v5 Messages to IPFIX Messages
21+
*
22+
* The converter helps to convert a stream of NetFlow Messages from a NetFlow exporter to stream
23+
* of IPFIX Messages. Messages are processed individually and should be passed to the
24+
* converter in the order send by the exporter. If it is necessary to convert streams from
25+
* multiple exporters at time, you MUST create an independent instance for each stream.
26+
*
27+
* @note
28+
* If stream of NetFlow packets contains a soft error (such as missing one or more packets,
29+
* reordered packets), a warning message is printed on the standard output. Generated stream of
30+
* IPFIX Messages don't contain these error (i.e. independent sequence numbers are generated)
31+
*
32+
* @{
33+
*/
34+
35+
/// Auxiliary definition of NetFlow v5 to IPFIX converter internals
36+
typedef struct ipx_nf5_conv ipx_nf5_conv_t;
37+
38+
/**
39+
* @brief Initialize NetFlow v5 to IPFIX converter
40+
*
41+
* @note
42+
* Template refresh interval (@p tmplt_refresh) refers to exporter timestamps in NetFlow
43+
* Messages to convert, not to wall-clock time.
44+
* @param[in] ident Instance identification (only for log messages!)
45+
* @param[in] vlevel Verbosity level of the converter (i.e. amount of log messages)
46+
* @param[in] tmplt_refresh Template refresh interval (seconds, 0 == disabled)
47+
* @param[in] odid Observation Domain ID of IPFIX Messages (e.g. 0)
48+
* @return Pointer to the converter or NULL (memory allocation error)
49+
*/
50+
ipx_nf5_conv_t *
51+
ipx_nf5_conv_init(const char *ident, enum ipx_verb_level vlevel, uint32_t tmplt_refresh,
52+
uint32_t odid);
53+
54+
/**
55+
* @brief Destroy NetFlow v5 to IPFIX converter
56+
* @param[in] conv Converter to destroy
57+
*/
58+
void
59+
ipx_nf5_conv_destroy(ipx_nf5_conv_t *conv);
60+
61+
/**
62+
* @brief Convert NetFlow v5 message to IPFIX message
63+
*
64+
* The function accepts a message wrapper @p wrapper that should hold a NetFlow v5 Message.
65+
* If the NetFlow Message is successfully converted, a content of the wrapper is replaced
66+
* with the IPFIX Message and the original NetFlow Message is not accessible anymore and it is
67+
* freed.
68+
*
69+
* @note
70+
* In case of an error (i.e. return code different from #IPX_OK) the original NetFlow Message
71+
* in the wrapper is untouched.
72+
* @note
73+
* Sequence number of the first IPFIX Message is deduced from the first NetFlow message to
74+
* convert. Sequence numbers of following converted messages is incremented independently
75+
* on the original NetFlow sequence number to avoid creation of invalid messages. In other words,
76+
* missing or reordered NetFlow messages don't affect correctness of the IPFIX stream.
77+
*
78+
* @param[in] conv Message converter
79+
* @param[in] wrapper Message wrapper
80+
* @return #IPX_OK on success
81+
* @return #IPX_ERR_FORMAT in case of invalid NetFlow Message format
82+
* @return #IPX_ERR_NOMEM in case of a memory allocation error
83+
*/
84+
int
85+
ipx_nf5_conv_process(ipx_nf5_conv_t *conv, ipx_msg_ipfix_t *wrapper);
86+
87+
/**
88+
* @brief Change verbosity level
89+
*
90+
* @param[in] conv Message converter
91+
* @param[in] v_new New verbosity level
92+
*/
93+
void
94+
ipx_nf5_conv_verb(ipx_nf5_conv_t *conv, enum ipx_verb_level v_new);
95+
96+
/**
97+
* @}
98+
*/
99+
100+
/**
101+
* @defgroup nf9_to_ipfix NetFlow v9 to IPFIX
102+
* @brief Conversion from NetFlow v9 Messages to IPFIX Messages
103+
*
104+
* The converter helps to convert a stream of NetFlow Messages from combination of a NetFlow
105+
* exporter and a Source ID (a.k.a. Observation Domain ID) to stream of IPFIX Messages. Messages
106+
* are processed individually and should be passed to the converter in the order send by the
107+
* exporter. If it is necessary to convert streams from the same exporter with different Source
108+
* IDs or from multiple exporters at time, you MUST create an independent instance for each
109+
* stream (i.e. combination of an Exporter and Source ID).
110+
*
111+
* @note
112+
* NetFlow Field Specifiers with ID > 127 are not backwards compatible with IPFIX Information
113+
* Elements, therefore, after conversion these specifiers are defined as Enterprise Specific
114+
* fields with Enterprise Number 4294967294 (128 <= ID <= 32767) or Enterprise Number 4294967295
115+
* (32768 <= ID <= 65535). In the latter case, the ID of the field is changed to fit into
116+
* range 0..32767: newID = oldID - 32768.
117+
*
118+
* @note
119+
* In the context of IPFIX protocol, the Source ID is referred as Observation Domain ID (ODID)
120+
*
121+
* @{
122+
*/
123+
124+
/// Auxiliary definition of NetFlow v9 to IPFIX converter internals
125+
typedef struct ipx_nf9_conv ipx_nf9_conv_t;
126+
127+
/**
128+
* @brief Initialize NetFlow v9 to IPFIX converter
129+
*
130+
* @param[in] ident Instance identification (only for log messages!)
131+
* @param[in] vlevel Verbosity level of the converter (i.e. amount of log messages)
132+
* @return Pointer to the converter or NULL (memory allocation error)
133+
*/
134+
ipx_nf9_conv_t *
135+
ipx_nf9_conv_init(const char *ident, enum ipx_verb_level vlevel);
136+
137+
/**
138+
* @brief Destroy NetFlow v9 to IPFIX converter
139+
* @param[in] conv Converter to destroy
140+
*/
141+
void
142+
ipx_nf9_conv_destroy(ipx_nf9_conv_t *conv);
143+
144+
/**
145+
* @brief Convert NetFlow v9 Message to IPFIX Message
146+
*
147+
* The function accepts a message wrapper @p wrapper that should hold a NetFlow v9 Message.
148+
* If the NetFlow Message is successfully converted, a content of the wrapper is replaced
149+
* with the IPFIX Message and the original NetFlow Message is not accessible anymore and it is
150+
* freed.
151+
*
152+
* @note
153+
* In case of an error (i.e. return code different from #IPX_OK) the original NetFlow Message
154+
* in the wrapper is untouched.
155+
* @note
156+
* After conversion the IPFIX Message is not ready to be used for accessing flow records,
157+
* it MUST be processed by the IPFIX Parser first.
158+
* @note
159+
* Sequence numbers of IPFIX Messages are incremented independently on NetFlow messages to
160+
* convert and starts from 0. In other words, missing or reordered NetFlow messages don't
161+
* affect correctness of the IPFIX stream.
162+
*
163+
* @param[in] conv Message converter
164+
* @param[in] wrapper Message wrapper
165+
* @return #IPX_OK on success
166+
* @return #IPX_ERR_FORMAT in case of invalid NetFlow Message format
167+
* @return #IPX_ERR_NOMEM in case of a memory allocation error
168+
*/
169+
int
170+
ipx_nf9_conv_process(ipx_nf9_conv_t *conv, ipx_msg_ipfix_t *wrapper);
171+
172+
/**
173+
* @brief Change verbosity level
174+
*
175+
* @param[in] conv Message converter
176+
* @param[in] v_new New verbosity level
177+
*/
178+
void
179+
ipx_nf9_conv_verb(ipx_nf9_conv_t *conv, enum ipx_verb_level v_new);
180+
181+
/**
182+
* @}
183+
*/
184+
185+
#endif // IPFIXCOL2_NETFLOW2IPFIX_H

0 commit comments

Comments
 (0)