Clean up logging. User Log* routines everywhere

This commit is contained in:
Peter Haag 2016-11-26 13:32:28 +01:00
parent 4cd1ef119d
commit 4c712ee62a
19 changed files with 173 additions and 292 deletions

View File

@ -1,4 +1,5 @@
/*
* Copyright (c) 2016, Peter Haag
* Copyright (c) 2014, Peter Haag
* Copyright (c) 2009, Peter Haag
* Copyright (c) 2004-2008, SWITCH - Teleinformatikdienste fuer Lehre und Forschung
@ -28,16 +29,11 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* $Author: haag $
*
* $Id: bookkeeper.c 39 2009-11-25 08:11:15Z haag $
*
* $LastChangedRevision: 39 $
*
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <unistd.h>
@ -65,21 +61,13 @@ union semun {
};
#endif
#include "config.h"
#include "util.h"
#include "bookkeeper.h"
static bookkeeper_list_t *bookkeeper_list = NULL;
/* function prototypes */
/*
* bookkeeper.c is needed for daemon code as well as normal stdio code
* therefore a generic LogError is defined, which maps to the
* approriate logging channel - either stderr or syslog
*/
void LogError(char *format, ...);
static uint32_t hash(char *str, int flag);
static void sem_lock(int sem_set_id);

View File

@ -1,4 +1,5 @@
/*
* Copyright (c) 2016, Peter Haag
* Copyright (c) 2014, Peter Haag
* Copyright (c) 2009, Peter Haag
* Copyright (c) 2008, SWITCH - Teleinformatikdienste fuer Lehre und Forschung
@ -28,15 +29,11 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* $Author: haag $
*
* $Id: collector.c 69 2010-09-09 07:17:43Z haag $
*
* $LastChangedRevision: 69 $
*
*/
#include "config.h"
#ifdef HAVE_STDINT_H
#include <stdint.h>
#endif
#include <stdio.h>
#include <stdlib.h>
@ -50,7 +47,6 @@
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <syslog.h>
#include <stdarg.h>
#include <time.h>

View File

@ -1,4 +1,5 @@
/*
* Copyright (c) 2016, Peter Haag
* Copyright (c) 2014, Peter Haag
* Copyright (c) 2009, Peter Haag
* Copyright (c) 2004-2008, SWITCH - Teleinformatikdienste fuer Lehre und Forschung
@ -73,13 +74,6 @@
static uint32_t timeout = 0;
/*
* expire.c is needed for daemon code as well as normal stdio code
* therefore a generic LogError is defined, which maps to the
* approriate logging channel - either stderr or syslog
*/
void LogError(char *format, ...);
static void PrepareDirLists(channel_t *channel);
static int compare(const FTSENT **f1, const FTSENT **f2);

View File

@ -1,4 +1,5 @@
/*
* Copyright (c) 2016, Peter Haag
* Copyright (c) 2014, Peter Haag
* Copyright (c) 2012, Peter Haag
*
@ -26,15 +27,11 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* $Author: peter $
*
* $Id: exporter.c 224 2014-02-16 12:59:29Z peter $
*
* $LastChangedRevision: 224 $
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <sys/types.h>
#include <sys/socket.h>
@ -47,7 +44,6 @@
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <syslog.h>
#include <stdarg.h>
#ifdef HAVE_STDINT_H

View File

@ -30,7 +30,9 @@
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
@ -54,14 +56,6 @@
#include "flowtree.h"
#include "netflow_pcap.h"
#ifdef DEVEL
# define dbg_printf(...) printf(__VA_ARGS__)
# define dbg_assert(a) assert(a)
#else
# define dbg_printf(...) /* printf(__VA_ARGS__) */
# define dbg_assert(a) /* assert(a) */
#endif
static int FlowNodeCMP(struct FlowNode *e1, struct FlowNode *e2);
// Insert the IP RB tree code here
@ -365,34 +359,6 @@ if ( node->left || node->right ) {
} // End of Flush_FlowTree
static void DisconnectFlowNode(Linked_list_t *LinkedList, struct FlowNode *node) {
if ( node == NULL )
return;
else {
// disconnect node
struct FlowNode *prev = node->left;
struct FlowNode *next = node->right;
if ( prev )
prev->right = next;
else
LinkedList->list = next;
if ( next )
next->left = prev;
if ( LinkedList->tail == node )
LinkedList->tail = node->left;
node->left = NULL;
node->right = NULL;
LinkedList->size--;
}
} // End of DisconnectFlowNode
int AddNodeData(struct FlowNode *node, uint32_t seq, void *payload, uint32_t size) {
return 0;

View File

@ -1,5 +1,6 @@
/*
* All rights reserved.
* Copyright (c) 2016, Peter Haag
* Copyright (c) 2014, Peter Haag
* Copyright (c) 2009, Peter Haag
* Copyright (c) 2004-2008, SWITCH - Teleinformatikdienste fuer Lehre und Forschung
@ -32,16 +33,11 @@
*
* Flow-Tools related code taken from flow-tools-0.67 cretated by Mark Fullmer
*
* $Author: haag $
*
* $Id: ft2nfdump.c 69 2010-09-09 07:17:43Z haag $
*
* $LastChangedRevision: 69 $
*
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
@ -66,6 +62,7 @@
#include "nffile.h"
#include "nfx.h"
#include "launch.h"
#include "util.h"
/* Global defines */
#define MAXRECORDS 30

View File

@ -1,6 +1,5 @@
/*
* This file is part of the nfdump project.
*
* Copyright (c) 2016
* Copyright (c) 2004-2008, SWITCH - Teleinformatikdienste fuer Lehre und Forschung
* All rights reserved.
*
@ -12,7 +11,7 @@
* * 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 SWITCH nor the names of its contributors may be
* * 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.
*
@ -28,19 +27,13 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* $Author: peter $
*
* $Id: grammar.y 100 2008-08-15 11:36:21Z peter $
*
* $LastChangedRevision: 100 $
*
*
*
*/
%{
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <sys/types.h>

View File

@ -1665,8 +1665,8 @@ static uint32_t packet_cntr = 0;
exporter->sequence_failure++;
dbg_printf("[%u] Sequence check failed: last seq: %u, seq %u\n",
exporter->info.id, Sequence, exporter->PacketSequence);
/* maybee to noise onbuggy exporters
syslog(LOG_ERR, "Process_ipfix [%u] Sequence error: last seq: %u, seq %u\n",
/* maybee to noise on buggy exporters
LogError("Process_ipfix [%u] Sequence error: last seq: %u, seq %u\n",
info.id, exporter->LastSequence, Sequence);
*/
} else {

View File

@ -1,4 +1,5 @@
/*
* Copyright (c) 2016, Peter Haag
* Copyright (c) 2014, Peter Haag
* Copyright (c) 2009, Peter Haag
* Copyright (c) 2004-2008, SWITCH - Teleinformatikdienste fuer Lehre und Forschung
@ -28,16 +29,11 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* $Author: haag $
*
* $Id: launch.c 69 2010-09-09 07:17:43Z haag $
*
* $LastChangedRevision: 69 $
*
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <signal.h>
#include <sys/types.h>
@ -48,7 +44,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <stdarg.h>
#include <errno.h>
#include <unistd.h>
@ -75,6 +70,7 @@
#include "nffile.h"
#include "nfxstat.h"
#include "collector.h"
#include "util.h"
static int done, launch, child_exit;
@ -153,7 +149,7 @@ int i;
s = ident;
break;
default:
syslog(LOG_ERR, "Unknown format token '%%%c'\n", q[i+1]);
LogError("Unknown format token '%%%c'", q[i+1]);
s = NULL;
}
if ( s ) {
@ -165,7 +161,7 @@ int i;
// be a bit paranoid and prevent endless expansion
if ( strlen(q) > MAXCMDLEN ) {
// this is fishy
syslog(LOG_ERR, "Error: cmdline too long!\n");
LogError("Error: cmdline too long!");
return NULL;
}
memmove(&q[i] + strlen(s), &q[i+2], strlen(&q[i+2]) + 1); // include trailing '0' in memmove
@ -215,7 +211,7 @@ int i, argnum;
if ( (i >= MAXCMDLEN) || (argnum >= MAXARGS) ) {
// for safety reason, disable the command
args[0] = NULL;
syslog(LOG_ERR, "Launcher: Unable to parse command: '%s'", buf);
LogError("Launcher: Unable to parse command: '%s'", buf);
}
} // End of cmd_parse
@ -228,20 +224,20 @@ static void cmd_execute(char **args) {
int pid;
// Get a child process.
syslog(LOG_DEBUG, "Launcher: fork child.");
LogInfo("Launcher: fork child.");
if ((pid = fork()) < 0) {
syslog(LOG_ERR, "Can't fork: %s", strerror(errno));
LogError("Can't fork: %s", strerror(errno));
return;
}
if (pid == 0) { // we are the child
execvp(*args, args);
syslog(LOG_ERR, "Can't execvp: %s: %s", args[0], strerror(errno));
LogError("Can't execvp: %s: %s", args[0], strerror(errno));
_exit(1);
}
// we are the parent
syslog(LOG_DEBUG, "Launcher: child exec done.");
LogInfo("Launcher: child exec done.");
/* empty */
} // End of cmd_execute
@ -251,7 +247,7 @@ bookkeeper_t *books;
dirstat_t *dirstat, oldstat;
int ret, bookkeeper_stat, do_rescan;
syslog(LOG_INFO, "Run expire on '%s'", datadir);
LogInfo("Run expire on '%s'", datadir);
do_rescan = 0;
ret = ReadStatInfo(datadir, &dirstat, CREATE_AND_LOCK);
@ -261,16 +257,16 @@ int ret, bookkeeper_stat, do_rescan;
case ERR_NOSTATFILE:
dirstat->low_water = 95;
case FORCE_REBUILD:
syslog(LOG_INFO, "Force rebuild stat record");
LogInfo("Force rebuild stat record");
do_rescan = 1;
break;
case ERR_FAIL:
syslog(LOG_ERR, "expire failed: can't read stat record");
LogError("expire failed: can't read stat record");
return;
/* not reached */
break;
default:
syslog(LOG_ERR, "expire failed: unexpected return code %i reading stat record", ret);
LogError("expire failed: unexpected return code %i reading stat record", ret);
return;
/* not reached */
}
@ -290,15 +286,15 @@ int ret, bookkeeper_stat, do_rescan;
UpdateBookStat(dirstat, &tmp_books);
ReleaseBookkeeper(books, DETACH_ONLY);
} else {
syslog(LOG_ERR, "Error %i: can't access book keeping records", ret);
LogError("Error %i: can't access book keeping records", ret);
}
syslog(LOG_INFO, "Limits: Filesize %s, Lifetime %s, Watermark: %llu%%\n",
LogInfo("Limits: Filesize %s, Lifetime %s, Watermark: %llu%%\n",
dirstat->max_size ? ScaleValue(dirstat->max_size) : "<none>",
dirstat->max_lifetime ? ScaleTime(dirstat->max_lifetime) : "<none>",
(unsigned long long)dirstat->low_water);
syslog(LOG_INFO, "Current size: %s, Current lifetime: %s, Number of files: %llu",
LogInfo("Current size: %s, Current lifetime: %s, Number of files: %llu",
ScaleValue(dirstat->filesize),
ScaleTime(dirstat->last - dirstat->first),
(unsigned long long)dirstat->numfiles);
@ -309,16 +305,16 @@ int ret, bookkeeper_stat, do_rescan;
WriteStatInfo(dirstat);
if ( (oldstat.numfiles - dirstat->numfiles) > 0 ) {
syslog(LOG_INFO, "expire completed");
syslog(LOG_INFO, " expired files: %llu", (unsigned long long)(oldstat.numfiles - dirstat->numfiles));
syslog(LOG_INFO, " expired time slot: %s", ScaleTime(dirstat->first - oldstat.first));
syslog(LOG_INFO, " expired file size: %s", ScaleValue(oldstat.filesize - dirstat->filesize));
syslog(LOG_INFO, "New size: %s, New lifetime: %s, Number of files: %llu",
LogInfo("expire completed");
LogInfo(" expired files: %llu", (unsigned long long)(oldstat.numfiles - dirstat->numfiles));
LogInfo(" expired time slot: %s", ScaleTime(dirstat->first - oldstat.first));
LogInfo(" expired file size: %s", ScaleValue(oldstat.filesize - dirstat->filesize));
LogInfo("New size: %s, New lifetime: %s, Number of files: %llu",
ScaleValue(dirstat->filesize),
ScaleTime(dirstat->last - dirstat->first),
(unsigned long long)dirstat->numfiles);
} else {
syslog(LOG_INFO, "expire completed - nothing to expire.");
LogInfo("expire completed - nothing to expire.");
}
ReleaseStatInfo(dirstat);
@ -333,7 +329,7 @@ srecord_t *InfoRecord;
InfoRecord = (srecord_t *)commbuff;
syslog(LOG_INFO, "Launcher: Startup. auto-expire %s", expire ? "enabled" : "off" );
LogInfo("Launcher: Startup. auto-expire %s", expire ? "enabled" : "off" );
done = launch = child_exit = 0;
// process may be NULL, if we only expire data files
@ -351,7 +347,7 @@ srecord_t *InfoRecord;
while ( fs ) {
cmd = cmd_expand(&TestRecord, fs->Ident, fs->datadir, process);
if ( cmd == NULL ) {
syslog(LOG_ERR, "Launcher: ident: %s, Unable to expand command: '%s'", fs->Ident, process);
LogError("Launcher: ident: %s, Unable to expand command: '%s'", fs->Ident, process);
exit(255);
}
@ -371,9 +367,9 @@ srecord_t *InfoRecord;
while ( !done ) {
// sleep until we get signaled
syslog(LOG_DEBUG, "Launcher: Sleeping");
dbg_printf("Launcher: Sleeping");
select(0, NULL, NULL, NULL, NULL);
syslog(LOG_DEBUG, "Launcher: Wakeup");
dbg_printf("Launcher: Wakeup");
if ( launch ) { // SIGHUP
launch = 0;
@ -385,11 +381,10 @@ srecord_t *InfoRecord;
// Expand % placeholders
cmd = cmd_expand(InfoRecord, fs->Ident, fs->datadir, process);
if ( cmd == NULL ) {
syslog(LOG_ERR, "Launcher: ident: %s, Unable to expand command: '%s'", fs->Ident, process);
LogError("Launcher: ident: %s, Unable to expand command: '%s'", fs->Ident, process);
continue;
}
// printf("Launcher: run command: '%s'\n", cmd);
syslog(LOG_DEBUG, "Launcher: ident: %s run command: '%s'", fs->Ident, cmd);
dbg_printf("Launcher: ident: %s run command: '%s'", fs->Ident, cmd);
// prepare args array
cmd_parse(cmd, args);
@ -412,29 +407,29 @@ srecord_t *InfoRecord;
}
}
if ( child_exit ) {
syslog(LOG_INFO, "launcher child exit %d children.", child_exit);
LogInfo("launcher child exit %d children.", child_exit);
while ( (pid = waitpid (-1, &stat, WNOHANG)) > 0 ) {
if ( WIFEXITED(stat) ) {
syslog(LOG_DEBUG, "launcher child %i exit status: %i", pid, WEXITSTATUS(stat));
LogInfo("launcher child %i exit status: %i", pid, WEXITSTATUS(stat));
}
if ( WIFSIGNALED(stat) ) {
syslog(LOG_WARNING, "launcher child %i died due to signal %i", pid, WTERMSIG(stat));
LogError("launcher child %i died due to signal %i", pid, WTERMSIG(stat));
}
child_exit--;
}
syslog(LOG_INFO, "launcher waiting children done. %d children", child_exit);
LogInfo("launcher waiting children done. %d children", child_exit);
child_exit = 0;
}
if ( done ) {
syslog(LOG_INFO, "Launcher: Terminating.");
LogInfo("Launcher: Terminating.");
}
}
waitpid (-1, &stat, 0);
// we are done
syslog(LOG_INFO, "Launcher: exit.");
LogInfo("Launcher: exit.");
} // End of launcher

View File

@ -1,4 +1,5 @@
/*
* Copyright (c) 2016, Peter Haag
* Copyright (c) 2014, Peter Haag
* Copyright (c) 2009, Peter Haag
* Copyright (c) 2004-2008, SWITCH - Teleinformatikdienste fuer Lehre und Forschung
@ -28,22 +29,17 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* $Author: peter $
*
* $Id: netflow_v1.c 30 2011-07-18 11:19:46Z peter $
*
* $LastChangedRevision: 30 $
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <stdlib.h>
#include <syslog.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>
@ -64,12 +60,6 @@
#include "exporter.h"
#include "netflow_v1.h"
#ifndef DEVEL
# define dbg_printf(...) /* printf(__VA_ARGS__) */
#else
# define dbg_printf(...) printf(__VA_ARGS__)
#endif
extern int verbose;
extern extension_descriptor_t extension_descriptor[];
@ -151,7 +141,7 @@ uint16_t map_size;
// Create a generic netflow v1 extension map
v1_extension_info.map = (extension_map_t *)malloc((size_t)map_size);
if ( !v1_extension_info.map ) {
syslog(LOG_ERR, "Process_v1: malloc() error in %s line %d: %s\n", __FILE__, __LINE__, strerror (errno));
LogError("Process_v1: malloc() error in %s line %d: %s\n", __FILE__, __LINE__, strerror (errno));
return 0;
}
@ -195,7 +185,7 @@ char ipstr[IP_STRING_LEN];
// nothing found
*e = (exporter_v1_t *)malloc(sizeof(exporter_v1_t));
if ( !(*e)) {
syslog(LOG_ERR, "Process_v1: malloc() error in %s line %d: %s\n", __FILE__, __LINE__, strerror (errno));
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));
@ -214,7 +204,7 @@ char ipstr[IP_STRING_LEN];
// copy the v1 generic extension map
(*e)->extension_map = (extension_map_t *)malloc(v1_extension_info.map->size);
if ( !(*e)->extension_map ) {
syslog(LOG_ERR, "Process_v1: malloc() error in %s line %d: %s\n", __FILE__, __LINE__, strerror (errno));
LogError("Process_v1: malloc() error in %s line %d: %s\n", __FILE__, __LINE__, strerror (errno));
free(*e);
*e = NULL;
return NULL;
@ -246,7 +236,7 @@ char ipstr[IP_STRING_LEN];
dbg_printf("New Exporter: v1 SysID: %u, Extension ID: %i, IP: %s, \n",
(*e)->info.sysid, (*e)->extension_map->map_id, ipstr);
syslog(LOG_INFO, "Process_v1: SysID: %u, New exporter: IP: %s\n", (*e)->info.sysid, ipstr);
LogError("Process_v1: SysID: %u, New exporter: IP: %s\n", (*e)->info.sysid, ipstr);
return (*e);
@ -271,7 +261,7 @@ char *string;
exporter = GetExporter(fs, v1_header);
if ( !exporter ) {
syslog(LOG_ERR,"Process_v1: Exporter NULL: Abort v1 record processing");
LogError("Process_v1: Exporter NULL: Abort v1 record processing");
return;
}
flags = 0;
@ -294,14 +284,14 @@ char *string;
// count check
count = ntohs(v1_header->count);
if ( count > NETFLOW_V1_MAX_RECORDS ) {
syslog(LOG_ERR,"Process_v1: Unexpected record count in header: %i. Abort v1 record processing", count);
LogError("Process_v1: Unexpected record count in header: %i. Abort v1 record processing", count);
fs->nffile->buff_ptr = (void *)common_record;
return;
}
// input buffer size check for all expected records
if ( size_left < ( NETFLOW_V1_HEADER_LENGTH + count * flow_record_length) ) {
syslog(LOG_ERR,"Process_v1: Not enough data to process v1 record. Abort v1 record processing");
LogError("Process_v1: Not enough data to process v1 record. Abort v1 record processing");
fs->nffile->buff_ptr = (void *)common_record;
return;
}
@ -309,7 +299,7 @@ char *string;
// output buffer size check for all expected records
if ( !CheckBufferSpace(fs->nffile, count * v1_output_record_size) ) {
// fishy! - should never happen. maybe disk full?
syslog(LOG_ERR,"Process_v1: output buffer size error. Abort v1 record processing");
LogError("Process_v1: output buffer size error. Abort v1 record processing");
return;
}
@ -386,7 +376,7 @@ char *string;
default:
// this should never happen, as v1 has no other extensions
syslog(LOG_ERR,"Process_v1: Unexpected extension %i for v1 record. Skip extension", id);
LogError("Process_v1: Unexpected extension %i for v1 record. Skip extension", id);
}
j++;
}
@ -504,9 +494,9 @@ char *string;
// buffer size sanity check - should never happen, but check it anyway
bsize = (pointer_addr_t)common_record - (pointer_addr_t)fs->nffile->block_header - sizeof(data_block_header_t);
if ( bsize > BUFFSIZE ) {
syslog(LOG_ERR,"### Software error ###: %s line %d", __FILE__, __LINE__);
syslog(LOG_ERR,"Process_v1: Output buffer overflow! Flush buffer and skip records.");
syslog(LOG_ERR,"Buffer size: size: %u, bsize: %llu > %u", fs->nffile->block_header->size, (unsigned long long)bsize, BUFFSIZE);
LogError("### Software error ###: %s line %d", __FILE__, __LINE__);
LogError("Process_v1: Output buffer overflow! Flush buffer and skip records.");
LogError("Buffer size: size: %u, bsize: %llu > %u", fs->nffile->block_header->size, (unsigned long long)bsize, BUFFSIZE);
// reset buffer
fs->nffile->block_header->size = 0;
fs->nffile->block_header->NumRecords = 0;

View File

@ -1,4 +1,5 @@
/*
* Copyright (c) 2016, Peter Haag
* Copyright (c) 2014, Peter Haag
* Copyright (c) 2009, Peter Haag
* Copyright (c) 2004-2008, SWITCH - Teleinformatikdienste fuer Lehre und Forschung
@ -28,12 +29,6 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* $Author: peter $
*
* $Id: netflow_v1.h 26 2011-07-05 18:51:25Z peter $
*
* $LastChangedRevision: 26 $
*
*/
#ifndef _NETFLOW_V1_H

View File

@ -1,4 +1,5 @@
/*
* Copyright (c) 2016, Peter Haag
* Copyright (c) 2014, Peter Haag
* Copyright (c) 2009, Peter Haag
* Copyright (c) 2004-2008, SWITCH - Teleinformatikdienste fuer Lehre und Forschung
@ -28,22 +29,17 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* $Author: haag $
*
* $Id: netflow_v5_v7.c 69 2010-09-09 07:17:43Z haag $
*
* $LastChangedRevision: 69 $
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <stdlib.h>
#include <syslog.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>
@ -159,7 +155,7 @@ uint16_t map_size;
// Create a generic v5 extension map
v5_extension_info.map = (extension_map_t *)malloc((size_t)map_size);
if ( !v5_extension_info.map ) {
syslog(LOG_ERR, "Process_v5: malloc() error in %s line %d: %s\n", __FILE__, __LINE__, strerror (errno));
LogError("Process_v5: malloc() error in %s line %d: %s\n", __FILE__, __LINE__, strerror (errno));
return 0;
}
v5_extension_info.map->type = ExtensionMapType;
@ -204,7 +200,7 @@ char ipstr[IP_STRING_LEN];
// nothing found
*e = (exporter_v5_t *)malloc(sizeof(exporter_v5_t));
if ( !(*e)) {
syslog(LOG_ERR, "Process_v5: malloc() error in %s line %d: %s\n", __FILE__, __LINE__, strerror (errno));
LogError("Process_v5: malloc() error in %s line %d: %s\n", __FILE__, __LINE__, strerror (errno));
return NULL;
}
memset((void *)(*e), 0, sizeof(exporter_v5_t));
@ -222,7 +218,7 @@ char ipstr[IP_STRING_LEN];
sampler = (generic_sampler_t *)malloc(sizeof(generic_sampler_t));
if ( !sampler ) {
syslog(LOG_ERR, "Process_v5: malloc() error in %s line %d: %s\n", __FILE__, __LINE__, strerror (errno));
LogError("Process_v5: malloc() error in %s line %d: %s\n", __FILE__, __LINE__, strerror (errno));
return NULL;
}
(*e)->sampler = sampler;
@ -241,7 +237,7 @@ char ipstr[IP_STRING_LEN];
// copy the v5 generic extension map
(*e)->extension_map = (extension_map_t *)malloc(v5_extension_info.map->size);
if ( !(*e)->extension_map ) {
syslog(LOG_ERR, "Process_v5: malloc() error in %s line %d: %s\n", __FILE__, __LINE__, strerror (errno));
LogError("Process_v5: malloc() error in %s line %d: %s\n", __FILE__, __LINE__, strerror (errno));
free(*e);
*e = NULL;
return NULL;
@ -277,12 +273,12 @@ char ipstr[IP_STRING_LEN];
dbg_printf("New Exporter: v5 SysID: %u, Extension ID: %i, IP: %s, Sampling Mode: %i, Sampling Interval: %u\n",
(*e)->info.sysid, (*e)->extension_map->map_id, ipstr, sampler->info.mode ,sampler->info.interval);
syslog(LOG_INFO, "Process_v5: New exporter: SysID: %u, engine id %u, type %u, IP: %s, Sampling Mode: %i, Sampling Interval: %u\n",
LogInfo("Process_v5: New exporter: SysID: %u, engine id %u, type %u, IP: %s, Sampling Mode: %i, Sampling Interval: %u\n",
(*e)->info.sysid, ( engine_tag & 0xFF ),( (engine_tag >> 8) & 0xFF ), ipstr, sampler->info.mode ,sampler->info.interval );
if ( overwrite_sampling > 0 ) {
sampler->info.interval = overwrite_sampling;
syslog(LOG_INFO, "Process_v5: Hard overwrite sampling rate: %u\n", sampler->info.interval);
LogInfo("Process_v5: Hard overwrite sampling rate: %u\n", sampler->info.interval);
}
return (*e);
@ -312,7 +308,7 @@ char *string;
exporter = GetExporter(fs, v5_header);
if ( !exporter ) {
syslog(LOG_ERR,"Process_v5: Exporter NULL: Abort v5/v7 record processing");
LogError("Process_v5: Exporter NULL: Abort v5/v7 record processing");
return;
}
exporter->packets++;
@ -348,14 +344,14 @@ char *string;
// count check
count = ntohs(v5_header->count);
if ( count > NETFLOW_V5_MAX_RECORDS ) {
syslog(LOG_ERR,"Process_v5: Unexpected record count in header: %i. Abort v5/v7 record processing", count);
LogError("Process_v5: Unexpected record count in header: %i. Abort v5/v7 record processing", count);
fs->nffile->buff_ptr = (void *)common_record;
return;
}
// input buffer size check for all expected records
if ( size_left < ( NETFLOW_V5_HEADER_LENGTH + count * flow_record_length) ) {
syslog(LOG_ERR,"Process_v5: Not enough data to process v5 record. Abort v5/v7 record processing");
LogError("Process_v5: Not enough data to process v5 record. Abort v5/v7 record processing");
fs->nffile->buff_ptr = (void *)common_record;
return;
}
@ -363,7 +359,7 @@ char *string;
// output buffer size check for all expected records
if ( !CheckBufferSpace(fs->nffile, count * v5_output_record_size) ) {
// fishy! - should never happen. maybe disk full?
syslog(LOG_ERR,"Process_v5: output buffer size error. Abort v5/v7 record processing");
LogError("Process_v5: output buffer size error. Abort v5/v7 record processing");
return;
}
@ -389,7 +385,7 @@ char *string;
fs->nffile->stat_record->sequence_failure++;
exporter->sequence_failure++;
/*
syslog(LOG_ERR,"Flow v%d sequence last:%llu now:%llu mismatch. Missing: dist:%lu flows",
LogError("Flow v%d sequence last:%llu now:%llu mismatch. Missing: dist:%lu flows",
version, exporter->last_sequence, exporter->sequence, exporter->distance);
*/
@ -516,7 +512,7 @@ char *string;
default:
// this should never happen, as v5 has no other extensions
syslog(LOG_ERR,"Process_v5: Unexpected extension %i for v5 record. Skip extension", id);
LogError("Process_v5: Unexpected extension %i for v5 record. Skip extension", id);
}
j++;
}
@ -534,7 +530,7 @@ char *string;
*/
if ( First > Last && ( (First - Last) < 20000) ) {
uint32_t _t;
syslog(LOG_ERR,"Process_v5: Unexpected time swap: First 0x%llx smaller than boot time: 0x%llx", start_time, boot_time);
LogError("Process_v5: Unexpected time swap: First 0x%llx smaller than boot time: 0x%llx", start_time, boot_time);
_t= First;
First = Last;
Last = _t;
@ -652,9 +648,9 @@ char *string;
// buffer size sanity check - should never happen, but check it anyway
bsize = (pointer_addr_t)common_record - (pointer_addr_t)fs->nffile->block_header - sizeof(data_block_header_t);
if ( bsize >= BUFFSIZE ) {
syslog(LOG_ERR,"### Software error ###: %s line %d", __FILE__, __LINE__);
syslog(LOG_ERR,"Process_v5: Output buffer overflow! Flush buffer and skip records.");
syslog(LOG_ERR,"Buffer size: size: %u, bsize: %llu > %u", fs->nffile->block_header->size, (unsigned long long)bsize, BUFFSIZE);
LogError("### Software error ###: %s line %d", __FILE__, __LINE__);
LogError("Process_v5: Output buffer overflow! Flush buffer and skip records.");
LogError("Buffer size: size: %u, bsize: %llu > %u", fs->nffile->block_header->size, (unsigned long long)bsize, BUFFSIZE);
// reset buffer
fs->nffile->block_header->size = 0;
fs->nffile->block_header->NumRecords = 0;

View File

@ -1,4 +1,5 @@
/*
* Copyright (c) 2016, Peter Haag
* Copyright (c) 2014, Peter Haag
* Copyright (c) 2009, Peter Haag
* Copyright (c) 2004-2008, SWITCH - Teleinformatikdienste fuer Lehre und Forschung
@ -28,21 +29,8 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* $Author: haag $
*
* $Id: nffile_inline.c 40 2009-12-16 10:41:44Z haag $
*
* $LastChangedRevision: 40 $
*
*/
/*
* nffile_inline.c is needed for daemon code as well as normal stdio code
* therefore a generic LogError is defined, which maps to the
* approriate logging channel - either stderr or syslog
*/
void LogError(char *format, ...);
static inline int CheckBufferSpace(nffile_t *nffile, size_t required);
static inline void AppendToBuffer(nffile_t *nffile, void *record, size_t required);
@ -59,9 +47,7 @@ static void PackRecord(master_record_t *master_record, nffile_t *nffile);
static inline int CheckBufferSpace(nffile_t *nffile, size_t required) {
#ifdef DEVEL
// printf("Buffer Size %u\n", nffile->block_header->size);
#endif
dbg_printf("Buffer Size %u\n", nffile->block_header->size);
// flush current buffer to disc
if ( (nffile->block_header->size + required ) > WRITE_BUFFSIZE ) {

View File

@ -1,4 +1,5 @@
/*
* Copyright (c) 2016, Peter Haag
* Copyright (c) 2014, Peter Haag
* Copyright (c) 2009, Peter Haag
* Copyright (c) 2004-2008, SWITCH - Teleinformatikdienste fuer Lehre und Forschung
@ -28,12 +29,6 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* $Author: haag $
*
* $Id: nfreplay.c 39 2009-11-25 08:11:15Z haag $
*
* $LastChangedRevision: 39 $
*
*/
#include "config.h"

View File

@ -1,4 +1,5 @@
/*
* Copyright (c) 2016, Peter Haag
* Copyright (c) 2014, Peter Haag
* Copyright (c) 2009, Peter Haag
* Copyright (c) 2004-2008, SWITCH - Teleinformatikdienste fuer Lehre und Forschung
@ -28,15 +29,11 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* $Author: haag $
*
* $Id: nfstatfile.c 39 2009-11-25 08:11:15Z haag $
*
* $LastChangedRevision: 39 $
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
@ -55,6 +52,7 @@
#include <stdint.h>
#endif
#include "util.h"
#include "nfstatfile.h"
#define stat_filename ".nfstat"
@ -95,13 +93,6 @@ static const double _1hour = 3600.0;
static const double _1day = 86400.0;
static const double _1week = 604800.0;
/*
* expire.c is needed for daemon code as well as normal stdio code
* therefore a generic LogError is defined, which maps to the
* approriate logging channel - either stderr or syslog
*/
void LogError(char *format, ...);
static inline uint64_t string2uint64(char *s);
static int ParseString(char *str, char **key, char **value);

View File

@ -29,11 +29,11 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* Author: peter
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
@ -55,7 +55,6 @@
#include <time.h>
#include <fcntl.h>
#include <signal.h>
#include <syslog.h>
#include <sys/mman.h>
#include <string.h>
#include <dirent.h>
@ -168,7 +167,7 @@ pid_t ret;
return;
if ( launcher_alive ) {
syslog(LOG_INFO, "Signal launcher[%i] to terminate.", pid);
LogInfo("Signal launcher[%i] to terminate.", pid);
kill(pid, SIGTERM);
// wait for launcher to teminate
@ -178,22 +177,22 @@ pid_t ret;
sleep(1);
}
if ( i >= LAUNCHER_TIMEOUT ) {
syslog(LOG_WARNING, "Launcher does not want to terminate - signal again");
LogError("Launcher does not want to terminate - signal again");
kill(pid, SIGTERM);
sleep(1);
}
} else {
syslog(LOG_ERR, "launcher[%i] already dead.", pid);
LogError("launcher[%i] already dead.", pid);
}
if ( (ret = waitpid (pid, &stat, 0)) == -1 ) {
syslog(LOG_ERR, "wait for launcher failed: %s %i", strerror(errno), ret);
LogError("wait for launcher failed: %s %i", strerror(errno), ret);
} else {
if ( WIFEXITED(stat) ) {
syslog(LOG_INFO, "launcher exit status: %i", WEXITSTATUS(stat));
LogInfo("launcher exit status: %i", WEXITSTATUS(stat));
}
if ( WIFSIGNALED(stat) ) {
syslog(LOG_WARNING, "launcher terminated due to signal %i", WTERMSIG(stat));
LogError("launcher terminated due to signal %i", WTERMSIG(stat));
}
}
@ -285,7 +284,7 @@ int err;
newuid = newgid = 0;
myuid = getuid();
if ( myuid != 0 ) {
syslog(LOG_ERR, "Only root wants to change uid/gid");
LogError("Only root wants to change uid/gid");
fprintf(stderr, "ERROR: Only root wants to change uid/gid\n");
exit(255);
}
@ -311,7 +310,7 @@ int err;
err = setgid(newgid);
if ( err ) {
syslog(LOG_ERR, "Can't set group id %ld for group '%s': %s", (long)newgid, groupid, strerror(errno));
LogError("Can't set group id %ld for group '%s': %s", (long)newgid, groupid, strerror(errno));
fprintf (stderr,"Can't set group id %ld for group '%s': %s\n", (long)newgid, groupid, strerror(errno));
exit(255);
}
@ -321,7 +320,7 @@ int err;
if ( newuid ) {
err = setuid(newuid);
if ( err ) {
syslog(LOG_ERR, "Can't set user id %ld for user '%s': %s", (long)newuid, userid, strerror(errno));
LogError("Can't set user id %ld for user '%s': %s", (long)newuid, userid, strerror(errno));
fprintf (stderr,"Can't set user id %ld for user '%s': %s\n", (long)newuid, userid, strerror(errno));
exit(255);
}
@ -350,7 +349,7 @@ srecord_t *commbuff;
in_buff = malloc(NETWORK_INPUT_BUFF_SIZE);
if ( !in_buff ) {
syslog(LOG_ERR, "malloc() buffer allocation error: %s", strerror(errno));
LogError("malloc() buffer allocation error: %s", strerror(errno));
return;
}
@ -416,7 +415,7 @@ srecord_t *commbuff;
(struct sockaddr *)&sf_sender, &sf_sender_size);
#endif
if ( cnt == -1 && errno != EINTR ) {
syslog(LOG_ERR, "ERROR: recvfrom: %s", strerror(errno));
LogError("ERROR: recvfrom: %s", strerror(errno));
continue;
}
@ -424,7 +423,7 @@ srecord_t *commbuff;
ssize_t len;
len = sendto(peer.sockfd, in_buff, cnt, 0, (struct sockaddr *)&(peer.addr), peer.addrlen);
if ( len < 0 ) {
syslog(LOG_ERR, "ERROR: sendto(): %s", strerror(errno));
LogError("ERROR: sendto(): %s", strerror(errno));
}
}
}
@ -446,7 +445,7 @@ srecord_t *commbuff;
subdir = GetSubDir(now);
if ( !subdir ) {
// failed to generate subdir path - put flows into base directory
syslog(LOG_ERR, "Failed to create subdir path!");
LogError("Failed to create subdir path!");
// failed to generate subdir path - put flows into base directory
subdir = NULL;
@ -476,7 +475,7 @@ srecord_t *commbuff;
if ( nffile->block_header->NumRecords ) {
// flush current buffer to disc
if ( WriteBlock(nffile) <= 0 )
syslog(LOG_ERR, "Ident: %s, failed to write output buffer to disk: '%s'" , fs->Ident, strerror(errno));
LogError("Ident: %s, failed to write output buffer to disk: '%s'" , fs->Ident, strerror(errno));
} // else - no new records in current block
@ -492,7 +491,7 @@ srecord_t *commbuff;
if ( fs->xstat ) {
if ( WriteExtraBlock(nffile, fs->xstat->block_header ) <= 0 )
syslog(LOG_ERR, "Ident: %s, failed to write xstat buffer to disk: '%s'" , fs->Ident, strerror(errno));
LogError("Ident: %s, failed to write xstat buffer to disk: '%s'" , fs->Ident, strerror(errno));
ResetPortHistogram(fs->xstat->port_histogram);
ResetBppHistogram(fs->xstat->bpp_histogram);
@ -506,15 +505,15 @@ srecord_t *commbuff;
if ( subdir && !SetupSubDir(fs->datadir, subdir, error, 255) ) {
// in this case the flows get lost! - the rename will fail
// but this should not happen anyway, unless i/o problems, inode problems etc.
syslog(LOG_ERR, "Ident: %s, Failed to create sub hier directories: %s", fs->Ident, error );
LogError("Ident: %s, Failed to create sub hier directories: %s", fs->Ident, error );
}
// if rename fails, we are in big trouble, as we need to get rid of the old .current file
// otherwise, we will loose flows and can not continue collecting new flows
err = rename(fs->current, nfcapd_filename);
if ( err ) {
syslog(LOG_ERR, "Ident: %s, Can't rename dump file: %s", fs->Ident, strerror(errno));
syslog(LOG_ERR, "Ident: %s, Serious Problem! Fix manually", fs->Ident);
LogError("Ident: %s, Can't rename dump file: %s", fs->Ident, strerror(errno));
LogError("Ident: %s, Serious Problem! Fix manually", fs->Ident);
if ( launcher_pid )
commbuff->failed = 1;
@ -531,7 +530,7 @@ srecord_t *commbuff;
}
// log stats
syslog(LOG_INFO,"Ident: '%s' Flows: %llu, Packets: %llu, Bytes: %llu, Sequence Errors: %u, Bad Packets: %u",
LogInfo("Ident: '%s' Flows: %llu, Packets: %llu, Bytes: %llu, Sequence Errors: %u, Bad Packets: %u",
fs->Ident, (unsigned long long)nffile->stat_record->numflows, (unsigned long long)nffile->stat_record->numpackets,
(unsigned long long)nffile->stat_record->numbytes, nffile->stat_record->sequence_failure, fs->bad_packets);
@ -576,14 +575,14 @@ srecord_t *commbuff;
commbuff->subdir[0] = '\0';
if ( launcher_alive ) {
syslog(LOG_DEBUG, "Signal launcher");
LogInfo("Signal launcher");
kill(launcher_pid, SIGHUP);
} else
syslog(LOG_ERR, "ERROR: Launcher died unexpectedly!");
LogError("ERROR: Launcher died unexpectedly!");
}
syslog(LOG_INFO, "Total ignored packets: %u", ignored_packets);
LogInfo("Total ignored packets: %u", ignored_packets);
ignored_packets = 0;
if ( done )
@ -611,7 +610,7 @@ srecord_t *commbuff;
break;
else {
/* this should never be executed as it should be caught in other places */
syslog(LOG_ERR, "error condition in '%s', line '%d', cnt: %i", __FILE__, __LINE__ ,(int)cnt);
LogError("error condition in '%s', line '%d', cnt: %i", __FILE__, __LINE__ ,(int)cnt);
continue;
}
}
@ -624,7 +623,7 @@ srecord_t *commbuff;
fs = GetFlowSource(&sf_sender);
if ( fs == NULL ) {
syslog(LOG_WARNING, "Skip UDP packet. Ignored packets so far %u packets", ignored_packets);
LogError("Skip UDP packet. Ignored packets so far %u packets", ignored_packets);
ignored_packets++;
continue;
}
@ -632,7 +631,7 @@ srecord_t *commbuff;
/* check for too little data - cnt must be > 0 at this point */
if ( cnt < sizeof(common_flow_header_t) ) {
syslog(LOG_WARNING, "Ident: %s, Data length error: too little data for common netflow header. cnt: %i",fs->Ident, (int)cnt);
LogError("Ident: %s, Data length error: too little data for common netflow header. cnt: %i",fs->Ident, (int)cnt);
fs->bad_packets++;
continue;
}
@ -651,7 +650,7 @@ srecord_t *commbuff;
fs->nffile->block_header->size = 0;
fs->nffile->block_header->NumRecords = 0;
fs->nffile->buff_ptr = (void *)((pointer_addr_t)fs->nffile->block_header + sizeof(data_block_header_t) );
syslog(LOG_ERR, "### Software bug ### Ident: %s, output buffer overflow: expect memory inconsitency", fs->Ident);
LogError("### Software bug ### Ident: %s, output buffer overflow: expect memory inconsitency", fs->Ident);
}
}
@ -1003,7 +1002,7 @@ int c;
pid_t pid = getpid();
int pidf = open(pidfile, O_RDWR|O_TRUNC|O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if ( pidf == -1 ) {
syslog(LOG_ERR, "Error opening pid file: '%s' %s", pidfile, strerror(errno));
LogError("Error opening pid file: '%s' %s", pidfile, strerror(errno));
close(sock);
exit(255);
}
@ -1021,7 +1020,7 @@ int c;
// prepare shared memory
shmem = mmap(0, sizeof(srecord_t), PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, -1, 0);
if ( shmem == (caddr_t)-1 ) {
syslog(LOG_ERR, "mmap() error: %s", strerror(errno));
LogError("mmap() error: %s", strerror(errno));
close(sock);
exit(255);
}
@ -1037,7 +1036,7 @@ int c;
exit(0);
break;
case -1:
syslog(LOG_ERR, "fork() error: %s", strerror(errno));
LogError("fork() error: %s", strerror(errno));
if ( strlen(pidfile) )
unlink(pidfile);
exit(255);
@ -1045,14 +1044,14 @@ int c;
default:
// parent
launcher_alive = 1;
syslog(LOG_DEBUG, "Launcher[%i] forked", launcher_pid);
LogInfo("Launcher[%i] forked", launcher_pid);
}
}
fs = FlowSource;
while ( fs ) {
if ( InitBookkeeper(&fs->bookkeeper, fs->datadir, getpid(), launcher_pid) != BOOKKEEPER_OK ) {
syslog(LOG_ERR, "initialize bookkeeper failed.");
LogError("initialize bookkeeper failed.");
// release all already allocated bookkeepers
fs = FlowSource;
@ -1070,7 +1069,6 @@ int c;
// Init the extension map list
if ( !InitExtensionMapList(fs) ) {
// error message goes to syslog
exit(255);
}
@ -1088,7 +1086,7 @@ int c;
sigaction(SIGALRM, &act, NULL);
sigaction(SIGCHLD, &act, NULL);
syslog(LOG_INFO, "Startup.");
LogInfo("Startup.");
run(receive_packet, sock, peer, twin, t_start, report_sequence, subdir_index,
time_extension, compress, do_xstat);
close(sock);
@ -1101,15 +1099,15 @@ int c;
if ( expire == 0 && ReadStatInfo(fs->datadir, &dirstat, LOCK_IF_EXISTS) == STATFILE_OK ) {
UpdateBookStat(dirstat, fs->bookkeeper);
WriteStatInfo(dirstat);
syslog(LOG_INFO, "Updating statinfo in directory '%s'", datadir);
LogInfo("Updating statinfo in directory '%s'", datadir);
}
ReleaseBookkeeper(fs->bookkeeper, DESTROY_BOOKKEEPER);
fs = fs->next;
}
syslog(LOG_INFO, "Terminating sfcapd.");
closelog();
LogInfo("Terminating sfcapd.");
EndLog();
if ( strlen(pidfile) )
unlink(pidfile);

View File

@ -487,12 +487,7 @@ static inline uint64_t getData64(SFSample *sample);
static void writeCountersLine(SFSample *sample);
#ifdef __SUNPRO_C
static void receiveError(SFSample *sample, char *errm, int hexdump);
#pragma does_not_return (receiveError)
#else
static void receiveError(SFSample *sample, char *errm, int hexdump) __attribute__ ((noreturn));
#endif
static inline void skipBytes(SFSample *sample, int skip);
@ -506,8 +501,6 @@ static inline uint32_t getString(SFSample *sample, char *buf, int bufLen);
static inline uint32_t getAddress(SFSample *sample, SFLAddress *address);
static inline char *printTag(uint32_t tag, char *buf, int bufLen);
static inline void skipTLVRecord(SFSample *sample, uint32_t tag, uint32_t len, char *description);
static inline void readSFlowDatagram(SFSample *sample, FlowSource_t *fs);
@ -522,6 +515,10 @@ static inline void readCountersSample_v2v4(SFSample *sample, FlowSource_t *fs);
static inline void StoreSflowRecord(SFSample *sample, FlowSource_t *fs);
#ifdef DEVEL
static inline char *printTag(uint32_t tag, char *buf, int bufLen);
#endif
extern int verbose;
@ -1410,13 +1407,14 @@ static inline uint32_t getAddress(SFSample *sample, SFLAddress *address) {
return address->type;
} // End of getAddress
static inline void skipTLVRecord(SFSample *sample, uint32_t tag, uint32_t len, char *description) {
#ifdef DEVEL
static inline char *printTag(uint32_t tag, char *buf, int bufLen) {
snprintf(buf, bufLen, "%u:%u", (tag >> 12), (tag & 0x00000FFF));
return buf;
} // End of printTag
static inline void skipTLVRecord(SFSample *sample, uint32_t tag, uint32_t len, char *description) {
#ifdef DEVEL
char buf[51];
#endif

View File

@ -1,4 +1,5 @@
/*
* Copyright (c) 2016, Peter Haag
* Copyright (c) 2014, Peter Haag
* Copyright (c) 2009, Peter Haag
* Copyright (c) 2004-2008, SWITCH - Teleinformatikdienste fuer Lehre und Forschung
@ -28,15 +29,11 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* $Author: haag $
*
* $Id: util.c 39 2009-11-25 08:11:15Z haag $
*
* $LastChangedRevision: 39 $
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <unistd.h>
@ -45,10 +42,12 @@
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/select.h>
#ifndef SYSLOG_NAMES
#define SYSLOG_NAMES 1
# define SYSLOG_NAMES 1
#endif
#include <syslog.h>
#include <stdarg.h>
@ -64,12 +63,6 @@ extern char *CurrentIdent;
enum { NONE, LESS, MORE };
#ifndef DEVEL
# define dbg_printf(...) /* printf(__VA_ARGS__) */
#else
# define dbg_printf(...) printf(__VA_ARGS__)
#endif
/* Function prototypes */
static int check_number(char *s, int len);

View File

@ -1,4 +1,5 @@
/*
* Copyright (c) 2016, Peter Haag
* Copyright (c) 2014, Peter Haag
* Copyright (c) 2009, Peter Haag
* Copyright (c) 2004-2008, SWITCH - Teleinformatikdienste fuer Lehre und Forschung
@ -28,17 +29,31 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* $Author: haag $
*
* $Id: util.h 39 2009-11-25 08:11:15Z haag $
*
* $LastChangedRevision: 39 $
*
*/
#ifndef _UTIL_H
#define _UTIL_H 1
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef HAVE_STDINT_H
#include <stdint.h>
#endif
#include <time.h>
#ifdef DEVEL
# include <stdio.h>
# include <assert.h>
# define dbg_printf(...) printf(__VA_ARGS__)
# define dbg_assert(a) assert(a)
#else
# define dbg_printf(...) /* printf(__VA_ARGS__) */
# define dbg_assert(a) /* assert(a) */
#endif
#define EBUFF_SIZE 256
#ifndef HAVE_HTONLL
@ -56,7 +71,6 @@
#define _1GB (double)(1000.0 * 1000.0 * 1000.0)
#define _1TB (double)(1000.0 * 1000.0 * 1000.0 * 1000.0)
typedef struct stringlist_s {
uint32_t block_size;
uint32_t max_index;