Skip to content

Commit

Permalink
Implement maxmind and tor lookup filter in nfprofile. See #557
Browse files Browse the repository at this point in the history
  • Loading branch information
phaag committed Aug 20, 2024
1 parent 925dd28 commit 813da06
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/nfsen/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

AM_CPPFLAGS = -I.. -I../include -I../libnffile -I../libnfdump -I../inline -I../collector $(DEPS_CFLAGS)
AM_CPPFLAGS = -I.. -I../include -I../libnffile -I../libnfdump -I../inline -I../collector
AM_CPPFLAGS += -I../libnffile/conf -I../libnfdump/maxmind -I../libnfdump/tor $(DEPS_CFLAGS)

bin_PROGRAMS =

Expand Down
39 changes: 35 additions & 4 deletions src/nfsen/nfprofile.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@
#include "conf/nfconf.h"
#include "filter/filter.h"
#include "flist.h"
#include "maxmind.h"
#include "nbar.h"
#include "nfdump.h"
#include "nffile.h"
#include "nfstatfile.h"
#include "nfxV3.h"
#include "profile.h"
#include "tor.h"
#include "util.h"
#include "version.h"

Expand Down Expand Up @@ -82,7 +84,7 @@ static void usage(char *name);
static profile_param_info_t *ParseParams(char *profile_datadir);

static void process_data(profile_channel_info_t *channels, unsigned int numChannels, time_t tslot, worker_param_t **workerList, int numWorkers,
pthread_control_barrier_t *barrie);
pthread_control_barrier_t *barrier, int hasGeoDB);

/* Functions */

Expand Down Expand Up @@ -260,7 +262,7 @@ static worker_param_t **LauchWorkers(pthread_t *tid, int numWorkers, pthread_con
} // End of LaunchWorkers

static void process_data(profile_channel_info_t *channels, unsigned int numChannels, time_t tslot, worker_param_t **workerList, int numWorkers,
pthread_control_barrier_t *barrier) {
pthread_control_barrier_t *barrier, int hasGeoDB) {
dataBlock_t *nextBlock = NULL;
dataBlock_t *dataBlock = NULL;
// map datablock for workers - all workers
Expand All @@ -287,7 +289,7 @@ static void process_data(profile_channel_info_t *channels, unsigned int numChann
for (int j = 0; j < numChannels; j++) {
// set ident to file engines
void *engine = channels[j].engine;
FilterSetParam(engine, nffile->ident, NOGEODB);
FilterSetParam(engine, nffile->ident, hasGeoDB);
}
// read first block and continue
nextBlock = ReadBlock(nffile, NULL);
Expand Down Expand Up @@ -662,6 +664,9 @@ int main(int argc, char **argv) {
}
}

// read default config
if (ConfOpen(NULL, "nfdump") < 0) exit(EXIT_FAILURE);

if (syntax_only) {
filename = NULL;
flist.single_file = NULL;
Expand All @@ -679,6 +684,32 @@ int main(int argc, char **argv) {
}
}

int __attribute__((unused)) hasGeoDB = false;
char *geoDBfile = ConfGetString("geodb.path");
if (geoDBfile && strcmp(geoDBfile, "none") == 0) {
geoDBfile = NULL;
}
if (geoDBfile) {
if (!CheckPath(geoDBfile, S_IFREG) || !LoadMaxMind(geoDBfile)) {
LogError("Error reading geo location DB file %s", geoDBfile);
exit(EXIT_FAILURE);
}
hasGeoDB = true;
}

__attribute__((unused)) int hasTorDB = false;
char *torDBfile = ConfGetString("tordb.path");
if (torDBfile && strcmp(torDBfile, "none") == 0) {
torDBfile = NULL;
}
if (torDBfile) {
if (!CheckPath(torDBfile, S_IFREG) || !LoadTorTree(torDBfile)) {
LogError("Error reading tor info DB file %s", torDBfile);
exit(EXIT_FAILURE);
}
hasTorDB = true;
}

if (chdir(profile_datadir)) {
LogError("Error can't chdir to '%s': %s", profile_datadir, strerror(errno));
exit(255);
Expand Down Expand Up @@ -721,7 +752,7 @@ int main(int argc, char **argv) {
exit(255);
}

process_data(channels, numChannels, tslot, workerList, numWorkers, barrier);
process_data(channels, numChannels, tslot, workerList, numWorkers, barrier, hasGeoDB);

WaitWorkersDone(tid, numWorkers);
pthread_control_barrier_destroy(barrier);
Expand Down

0 comments on commit 813da06

Please sign in to comment.