Skip to content

Commit

Permalink
Add BlockReports
Browse files Browse the repository at this point in the history
  • Loading branch information
phaag committed May 6, 2023
1 parent 18a34c1 commit 2c5678f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
16 changes: 15 additions & 1 deletion src/lib/nffile.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ static queue_t *fileQueue = NULL;

#define QueueSize 4

static _Atomic unsigned numBlocks;

int Init_nffile(queue_t *fileList) {
fileQueue = fileList;
if (!LZO_initialize()) {
Expand All @@ -135,10 +137,18 @@ int Init_nffile(queue_t *fileList) {
LogError("Failed to initialize BZ2");
return 0;
}
numBlocks = 0;
atomic_init(&numBlocks, 0);

return 1;

} // End of Init_nffile

unsigned ReportBlocks(void) {
unsigned inUse = atomic_load(&numBlocks);
return inUse;
}

static int LZO_initialize(void) {
if (lzo_init() != LZO_E_OK) {
// this usually indicates a compiler bug - try recompiling
Expand Down Expand Up @@ -341,13 +351,17 @@ static dataBlock_t *NewDataBlock(void) {
return NULL;
}
InitDataBlock(dataBlock);
atomic_fetch_add(&numBlocks, 1);
return dataBlock;

} // End of NewDataBlock

static void FreeDataBlock(dataBlock_t *dataBlock) {
// Release block
if (dataBlock) free((void *)dataBlock);
if (dataBlock) {
free((void *)dataBlock);
atomic_fetch_sub(&numBlocks, 1);
}
} // End of FreeDataBlock

static int ReadAppendix(nffile_t *nffile) {
Expand Down
5 changes: 3 additions & 2 deletions src/lib/nffile.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,7 @@ typedef struct nffile_s {
dataBlock_t *block_header; // buffer ptr
void *buff_ptr; // pointer into buffer for read/write blocks/records

queue_t *processQueue; // blocks ready to be processed
// queue_t *blockQueue; // empty blocks
queue_t *processQueue; // blocks ready to be processed. Connects consumer/producer threads

stat_record_t *stat_record; // flow stat record
char *ident; // source identifier
Expand Down Expand Up @@ -243,6 +242,8 @@ typedef struct record_header_s {

int Init_nffile(queue_t *fileList);

unsigned ReportBlocks(void);

void SumStatRecords(stat_record_t *s1, stat_record_t *s2);

nffile_t *OpenFile(char *filename, nffile_t *nffile);
Expand Down
8 changes: 3 additions & 5 deletions src/nfcapd/nfcapd.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,11 +431,9 @@ static void run(packet_function_t receive_packet, int socket, int pfd, int rfd,
}

// log stats
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);
LogInfo("Ident: '%s' Flows: %llu, Packets: %llu, Bytes: %llu, Sequence Errors: %u, Bad Packets: %u, Blocks: %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, ReportBlocks());

// reset stats
fs->bad_packets = 0;
Expand Down

0 comments on commit 2c5678f

Please sign in to comment.