Skip to content

Commit

Permalink
Speedup json output
Browse files Browse the repository at this point in the history
  • Loading branch information
phaag committed Jul 29, 2024
1 parent b6179a6 commit bd93c60
Show file tree
Hide file tree
Showing 4 changed files with 424 additions and 332 deletions.
26 changes: 8 additions & 18 deletions src/netflow/netflow_v1.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,12 @@ static inline exporter_v1_t *getExporter(FlowSource_t *fs, netflow_v1_header_t *
LogError("Process_v1: malloc() error in %s line %d: %s\n", __FILE__, __LINE__, strerror(errno));
return NULL;
}
memset((void *)(*e), 0, sizeof(exporter_v1_t));
(*e)->next = NULL;
(*e)->info.header.type = ExporterInfoRecordType;
(*e)->info.header.size = sizeof(exporter_info_record_t);
(*e)->info.version = version;
(*e)->info.id = 0;
(*e)->info.ip = fs->ip;
(*e)->info.sa_family = fs->sa_family;
(*e)->info.sysid = 0;
(*e)->packets = 0;
(*e)->flows = 0;
(*e)->sequence_failure = 0;

(**e) = (exporter_v1_t){.info = {.header = {.type = ExporterInfoRecordType, .size = sizeof(exporter_info_record_t)},
.version = version,
.id = 0,
.ip = fs->ip,
.sa_family = fs->sa_family,
.sysid = 0}};
char *ipstr = GetExporterIP(fs);
if (fs->sa_family == PF_INET6) {
(*e)->outRecordSize = baseRecordSize + EXipReceivedV6Size;
Expand All @@ -166,13 +159,10 @@ static inline exporter_v1_t *getExporter(FlowSource_t *fs, netflow_v1_header_t *
} // End of getExporter

void Process_v1(void *in_buff, ssize_t in_buff_cnt, FlowSource_t *fs) {
netflow_v1_header_t *v1_header;
exporter_v1_t *exporter;

// map v1 data structure to input buffer
v1_header = (netflow_v1_header_t *)in_buff;
netflow_v1_header_t *v1_header = (netflow_v1_header_t *)in_buff;

exporter = getExporter(fs, v1_header);
exporter_v1_t *exporter = getExporter(fs, v1_header);
if (!exporter) {
LogError("Process_v1: NULL Exporter: Abort v1 record processing");
return;
Expand Down
51 changes: 23 additions & 28 deletions src/netflow/netflow_v1.h
Original file line number Diff line number Diff line change
@@ -1,43 +1,39 @@
/*
* Copyright (c) 2009-2020, Peter Haag
* Copyright (c) 2009-2024, Peter Haag
* Copyright (c) 2004-2008, SWITCH - Teleinformatikdienste fuer Lehre und Forschung
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* * 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.
* * Neither the name of the author nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* * Neither the name of the author nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT OWNER 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
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT OWNER 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 _NETFLOW_V1_H
#define _NETFLOW_V1_H 1

#include "config.h"

#include <sys/types.h>
#ifdef HAVE_STDINT_H
#include <stdint.h>
#endif
#include <sys/types.h>

#include "collector.h"

Expand All @@ -46,5 +42,4 @@ int Init_v1(int verbose);

void Process_v1(void *in_buff, ssize_t in_buff_cnt, FlowSource_t *fs);


#endif //_NETFLOW_V1_H
#endif //_NETFLOW_V1_H
2 changes: 2 additions & 0 deletions src/output/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ liboutput_a_SOURCES = output.c output.h \
output_fmt.c output_fmt.h output_json.c output_json.h \
output_raw.c output_raw.h

EXTRA_DIST = itoa.c

CLEANFILES = *.gch

Loading

0 comments on commit bd93c60

Please sign in to comment.