Skip to content

Commit

Permalink
NetFlow converters: added NetFlow v5/v9 to IPFIX converters, NetFlow …
Browse files Browse the repository at this point in the history
…v9 iterators, etc. (not tested, unit tests will follow)
  • Loading branch information
Lukas955 committed Nov 27, 2018
1 parent 3cca977 commit d1fa93b
Show file tree
Hide file tree
Showing 10 changed files with 3,401 additions and 1 deletion.
2 changes: 2 additions & 0 deletions include/ipfixcol2/api.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ extern "C" {
// Note: Following codes preservers the same numbering as libfds
/** Status code for success */
#define IPX_OK (0)
/** Status code for the end of a context */
#define IPX_EOC (-1)
/** Status code for ready operation */
#define IPX_READY (-11)
/** Status code for memory allocation error */
Expand Down
10 changes: 9 additions & 1 deletion src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ set(CORE_SOURCE
configurator/plugin_mgr.hpp
configurator/model.cpp
configurator/model.hpp
netflow2ipfix/netflow2ipfix.h
netflow2ipfix/netflow5.c
netflow2ipfix/netflow9.c
netflow2ipfix/netflow9_templates.c
netflow2ipfix/netflow9_templates.h
netflow2ipfix/netflow_parsers.c
netflow2ipfix/netflow_parsers.h
netflow2ipfix/netflow_structs.h
api.c
context.c
context.h
Expand Down Expand Up @@ -76,4 +84,4 @@ set_target_properties(ipfixcol2 PROPERTIES # by default, hide all symbols
install(
TARGETS ipfixcol2
DESTINATION bin
)
)
180 changes: 180 additions & 0 deletions src/core/netflow2ipfix/netflow2ipfix.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
/**
* \file src/core/netflow2ipfix/netflow2ipfix.h
* \author Lukas Hutak <[email protected]>
* \brief Main NetFlow v5/v9 to IPFIX converter functions (header file)
* \date 2018
*/

/*
* Copyright (C) 2018 CESNET, z.s.p.o.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name of the Company nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* ALTERNATIVELY, provided that this notice is retained in full, this
* product may be distributed under the terms of the GNU General Public
* License (GPL) version 2 or later, in which case the provisions
* of the GPL apply INSTEAD OF those given above.
*
* This software is provided ``as is``, and any express or implied
* warranties, including, but not limited to, the implied warranties of
* merchantability and fitness for a particular purpose are disclaimed.
* In no event shall the company or contributors be liable for any
* direct, indirect, incidental, special, exemplary, or consequential
* damages (including, but not limited to, procurement of substitute
* goods or services; loss of use, data, or profits; or business
* interruption) however caused and on any theory of liability, whether
* in contract, strict liability, or tort (including negligence or
* otherwise) arising in any way out of the use of this software, even
* if advised of the possibility of such damage.
*
*/

#ifndef IPFIXCOL2_NETFLOW2IPFIX_H
#define IPFIXCOL2_NETFLOW2IPFIX_H

#include <stdint.h>
#include <stddef.h>
#include <ipfixcol2.h>

/**
* \defgroup nf5_to_ipfix NetFlow v5 to IPFIX
* \brief Conversion from NetFlow v5 Messages to IPFIX Messages
*
* The converter helps to convert a stream of NetFlow Messages from a NetFlow exporter to stream
* of IPFIX Messages. Messages are processed individually and should be passed to the
* converter in the order send by the exporter. If it is necessary to convert streams from
* multiple exporters at time, you MUST create an independent instance for each stream.
*
* @{
*/

/** Auxiliary definition of NetFlow v5 to IPFIX converter internals */
typedef struct ipx_nf5_conv ipx_nf5_conv_t;

/**
* \brief Initialize NetFlow v5 to IPFIX converter
*
* \note
* Template refresh interval (\p tmplt_refresh) refers to exporter timestamps in NetFlow
* Messages to convert, not to wall-clock time.
* \param[in] ident Instance identification (only for log messages!)
* \param[in] vlevel Verbosity level of the converter (i.e. amount of log messages)
* \param[in] tmplt_refresh Template refresh interval (seconds, 0 == disabled)
* \param[in] odid Observation Domain ID of IPFIX Messages (e.g. 0)
* \return Pointer to the converter or NULL (memory allocation error)
*/
ipx_nf5_conv_t *
ipx_nf5_conv_init(const char *ident, enum ipx_verb_level vlevel, uint32_t tmplt_refresh,
uint32_t odid);

/**
* \brief Destroy NetFlow v5 to IPFIX converter
* \param[in] conv Converter to destroy
*/
void
ipx_nf5_conv_destroy(ipx_nf5_conv_t *conv);

/**
* \brief Convert NetFlow v5 message to IPFIX message
*
* The function accepts a message wrapper \p wrapper that should hold a NetFlow v5 Message.
* If the NetFlow Message is successfully converted, a content of the wrapper is replaced
* with the IPFIX Message and the original NetFlow Message is not accessible anymore and it is
* freed.
*
* \note
* In case of an error (i.e. return code different from #IPX_OK) the original NetFlow Message
* in the wrapper is untouched.
* \param[in] conv Message converter
* \param[in] wrapper Message wrapper
* \return #IPX_OK on success
* \return #IPX_ERR_FORMAT in case of invalid NetFlow Message format
* \return #IPX_ERR_NOMEM in case of a memory allocation error
*/
int
ipx_nf5_conv_process(ipx_nf5_conv_t *conv, ipx_msg_ipfix_t *wrapper);

/**
* @}
*/

/**
* \defgroup nf9_to_ipfix NetFlow v9 to IPFIX
* \brief Conversion from NetFlow v9 Messages to IPFIX Messages
*
* The converter helps to convert a stream of NetFlow Messages from combination of a NetFlow
* exporter and a Source ID (a.k.a. Observation Domain ID) to stream of IPFIX Messages. Messages
* are processed individually and should be passed to the converter in the order send by the
* exporter. If it is necessary to convert streams from the same exporter with different Source
* IDs or from multiple exporters at time, you MUST create an independent instance for each
* stream (i.e. combination of an Exporter and Source ID).
*
* \note
* In the context of IPFIX protocol, the Source ID is referred as Observation Domain ID (ODID)
*
* @{
*/

/** Auxiliary definition of NetFlow v9 to IPFIX converter internals */
typedef struct ipx_nf9_conv ipx_nf9_conv_t;

/**
* \brief Initialize NetFlow v9 to IPFIX converter
*
* \param[in] ident Instance identification (only for log messages!)
* \param[in] vlevel Verbosity level of the converter (i.e. amount of log messages)
* \return Pointer to the converter or NULL (memory allocation error)
*/
ipx_nf9_conv_t *
ipx_nf9_conv_init(const char *ident, enum ipx_verb_level vlevel);

/**
* \brief Destroy NetFlow v9 to IPFIX converter
* \param[in] conv Converter to destroy
*/
void
ipx_nf9_conv_destroy(ipx_nf9_conv_t *conv);

/**
* \brief Convert NetFlow v9 Message to IPFIX Message
*
* The function accepts a message wrapper \p wrapper that should hold a NetFlow v9 Message.
* If the NetFlow Message is successfully converted, a content of the wrapper is replaced
* with the IPFIX Message and the original NetFlow Message is not accessible anymore and it is
* freed.
*
* \note
* In case of an error (i.e. return code different from #IPX_OK) the original NetFlow Message
* in the wrapper is untouched.
* \note
* After conversion the IPFIX Message is not ready to be used for accessing flow records,
* it MUST be processed by the IPFIX Parser first.
* \param[in] conv Message converter
* \param[in] wrapper Message wrapper
* \return #IPX_OK on success
* \return #IPX_ERR_FORMAT in case of invalid NetFlow Message format
* \return #IPX_ERR_NOMEM in case of a memory allocation error
*/
int
ipx_nf9_conv_process(ipx_nf9_conv_t *conv, ipx_msg_ipfix_t *wrapper);

/**
* @}
*/

#ifdef __cplusplus
}
#endif

#endif // IPFIXCOL2_NETFLOW2IPFIX_H
Loading

0 comments on commit d1fa93b

Please sign in to comment.