Skip to content

Commit eb25282

Browse files
committed
- Skip all '.' files in file listing process. Skip 1.8.x bookkeeping file
- Improve robustness of netflow v9 time overflow handling
1 parent a9312e2 commit eb25282

3 files changed

Lines changed: 22 additions & 19 deletions

File tree

src/include/exporter.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,14 +210,15 @@ typedef struct exporter_v5_s {
210210
typedef struct templateList_s templateList_t;
211211
typedef struct exporter_v9_s {
212212
// exporter parameters
213-
uint64_t boot_time;
213+
uint32_t SysUptime;
214+
uint32_t unix_secs;
214215

215216
// statistics
216217
uint64_t TemplateRecords; // stat counter
217218
uint64_t DataRecords; // stat counter
218219

219220
// SysUptime if sent with #160
220-
uint64_t SysUpTime; // in msec
221+
uint64_t msecSysUpTime; // in msec
221222

222223
// in order to prevent search through all lists keep
223224
// the last template we processed as a cache

src/libnffile/flist.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -799,11 +799,9 @@ static int GetFileList(stringlist_t *source_dirs, flist_t *flist) {
799799
case FTS_F:
800800
// file entry
801801

802-
// skip stat file
803-
if (strcmp(ftsent->fts_name, ".nfstat") == 0 || strncmp(ftsent->fts_name, NF_TMPFILE, strlen(NF_TMPFILE)) == 0) continue;
804-
if (strstr(ftsent->fts_name, ".stat") != NULL) continue;
805-
// skip OSX DS_Store files
806-
if (strstr(ftsent->fts_name, ".DS_Store") != NULL) continue;
802+
// skip all . files
803+
if (ftsent->fts_name[0] == '.') continue;
804+
if (strncmp(ftsent->fts_name, NF_TMPFILE, strlen(NF_TMPFILE)) == 0) continue;
807805
// skip pcap file
808806
if (strstr(ftsent->fts_name, "pcap") != NULL) continue;
809807

src/netflow/netflow_v9.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,13 +1173,18 @@ static inline void Process_v9_data(exporter_entry_t *exporter_entry, void *data_
11731173
uint64_t First = stack[STACK_MSECFIRST];
11741174
uint64_t Last = stack[STACK_MSECLAST];
11751175

1176-
if (First > Last) /* First in msec, in case of msec overflow, between start and end */
1177-
genericFlow->msecFirst = exporter_v9->boot_time - 0x100000000LL + First;
1178-
else
1179-
genericFlow->msecFirst = First + exporter_v9->boot_time;
1176+
uint64_t export_time_ms = (uint64_t)exporter_v9->unix_secs * 1000;
1177+
dbg_printf("SysupTime: %u, Unix_sec: %u\n", exporter_v9->SysUptime, exporter_v9->unix_secs);
1178+
dbg_printf("First: %llu, Last: %llu, exportTimeMS: %llu\n", First, Last, export_time_ms);
1179+
1180+
uint32_t offset = (uint32_t)exporter_v9->SysUptime - (uint32_t)First;
1181+
dbg_printf("Offset first: %u\n", offset);
1182+
genericFlow->msecFirst = export_time_ms - (uint64_t)offset;
1183+
1184+
offset = (uint32_t)exporter_v9->SysUptime - (uint32_t)Last;
1185+
dbg_printf("Offset last: %u\n", offset);
1186+
genericFlow->msecLast = export_time_ms - (uint64_t)offset;
11801187

1181-
// end time in msecs
1182-
genericFlow->msecLast = (uint64_t)Last + exporter_v9->boot_time;
11831188
} else if (stack[STACK_SECFIRST]) {
11841189
genericFlow->msecFirst = stack[STACK_SECFIRST] * (uint64_t)1000;
11851190
genericFlow->msecLast = stack[STACK_SECLAST] * (uint64_t)1000;
@@ -1652,8 +1657,8 @@ static void Process_v9_SysUpTime_option_data(exporter_entry_t *exporter_entry, t
16521657
// map input buffer as a byte array
16531658
uint8_t *in = (uint8_t *)(data_flowset + 4); // skip flowset header
16541659
if (CHECK_OPTION_DATA(size_left, optionTemplate->SysUpOption)) {
1655-
exporter_v9->SysUpTime = Get_val(in, optionTemplate->SysUpOption.offset, optionTemplate->SysUpOption.length);
1656-
dbg_printf("Extracted SysUpTime : %" PRIu64 "\n", exporter_v9->SysUpTime);
1660+
exporter_v9->msecSysUpTime = Get_val(in, optionTemplate->SysUpOption.offset, optionTemplate->SysUpOption.length);
1661+
dbg_printf("Extracted SysUpTime : %" PRIu64 "\n", exporter_v9->msecSysUpTime);
16571662
} else {
16581663
LogError("Process_v9_option: %s line %d: Not enough data for option data", __FILE__, __LINE__);
16591664
return;
@@ -1712,17 +1717,16 @@ void Process_v9(void *in_buff, ssize_t in_buff_cnt, FlowSource_t *fs) {
17121717
exporter_v9_t *exporter_v9 = &exporter_entry->version.v9;
17131718

17141719
/* calculate boot time in msec */
1715-
v9_header->SysUptime = ntohl(v9_header->SysUptime);
1716-
v9_header->unix_secs = ntohl(v9_header->unix_secs);
1717-
exporter_v9->boot_time = (uint64_t)1000 * (uint64_t)(v9_header->unix_secs) - (uint64_t)v9_header->SysUptime;
1720+
exporter_v9->SysUptime = ntohl(v9_header->SysUptime);
1721+
exporter_v9->unix_secs = ntohl(v9_header->unix_secs);
17181722

17191723
void *flowset_header = (void *)v9_header + V9_HEADER_LENGTH;
17201724
size_left -= V9_HEADER_LENGTH;
17211725

17221726
#ifdef DEVEL
17231727
uint32_t expected_records = ntohs(v9_header->count);
17241728
printf("[%u] records: %u, buffer: %zd \n", exporter_id, expected_records, size_left);
1725-
printf("SourceID: %u, Sysuptime: %u.%u\n", v9_header->source_id, v9_header->SysUptime, v9_header->unix_secs);
1729+
printf("SourceID: %u, Sysuptime: %u.%u\n", exporter_id, exporter_v9->SysUptime, exporter_v9->unix_secs);
17261730
#endif
17271731

17281732
// sequence check

0 commit comments

Comments
 (0)