*** ./apps/cflowd/cflowd.cc_djp Tue Feb 9 13:46:46 1999 --- ./apps/cflowd/cflowd.cc Fri Sep 10 11:26:34 1999 *************** *** 40,50 **** //=========================================================================== extern "C" { #include "aclocal.h" #include - #include #include - #include - #include #ifdef HAVE_SYS_FILIO_H #define BSD_COMP 1 --- 40,58 ---- //=========================================================================== extern "C" { + #include /* errno, EINTR */ + #include /* open, O_CREAT, O_WRONLY, O_TRUNC, O_RDWR */ + #include /* log */ + #include /* SIGCHLD, SIGTERM, SIGPIPE, signal, SIGTTOU, SIG_IGN */ + #include /* NULL */ + #include /* rename, EOF, fprintf, stderr */ + #include /* exit, strtoul */ + #include /* memset, strcpy, strlen, memcpy */ + #include /* wait */ + #include /* time_t, time, difftime, strftime, localtime */ + #include /* unlink, close, fork, write, read, setpgid, getpid */ #include #include #include "aclocal.h" #ifdef HAVE_SYS_FILIO_H #define BSD_COMP 1 *************** *** 56,61 **** --- 64,72 ---- #include "caida_t.h" } + #include + #include + #include "CflowdConfig.hh" #include "CflowdConfigLex.hh" #include "CflowdTableRequest.hh" *************** *** 73,78 **** --- 84,95 ---- static int g_tableSockFd = -1; static CflowdPacketQueue g_packetQueue; bool g_cflowdDebug = false; + static time_t g_logtimeout = (time_t) -1; + static int g_logfd = -1; + static int g_skip_output_if = -1; + static int g_retain_multicast = 0; // boolean + static unsigned long g_multimask = inet_addr("240.0.0.0"); + static unsigned long g_multinet = inet_addr("224.0.0.0"); Signal g_sigChld(SIGCHLD); Signal g_sigTerm(SIGTERM); *************** *** 529,534 **** --- 546,553 ---- int numPackets, numFlows; CflowdRawFlow flow; CflowdCiscoMap::iterator ciscoMapIter; + time_t now; + static time_t then; uint16_t exportVersion; ipv4addr_t ciscoAddr; *************** *** 624,633 **** --- 643,702 ---- numFlows = flowArrNum; + + if ((time_t)-1 != g_logtimeout) { + time(&now); + if (-1 == g_logfd || difftime(now, then) > g_logtimeout) { + string current, previous; + + // remember when we rename(2)d the previous log file: + then = now; + + // generate the current timestamp: + static char date[sizeof "YYYYMMDD_HH:MI:SS"]; + strftime(date, sizeof date, "%Y%m%d_%H:%M:%S", localtime(&now)); + + current = g_cflowdConfig.FlowDirectory(); + current += "/flows.current"; + + previous = g_cflowdConfig.FlowDirectory(); + previous += "/flows."; + previous += date; + + if (-1 != g_logfd) { // rename current log file to previous: + close(g_logfd); + if (-1 == rename(current.c_str(), previous.c_str())) { + syslog(LOG_ERR,"[E] rename(\"%s\", \"%s\"): %m {%s:%d}", + current.c_str(), previous.c_str(), + __FILE__, __LINE__); + } + } + + // open a new current log file: + g_logfd = open(current.c_str(), O_CREAT | O_WRONLY | O_TRUNC, 0644); + if (-1 == g_logfd) { + syslog(LOG_ERR, + "[E] open(\"%s\", O_CREAT | O_WRONLY | O_TRUNC): %m {%s:%d}", + current.c_str(), __FILE__, __LINE__); + } + } + } + for (flowNum = 0; flowNum < numFlows; flowNum++) { ciscoMapIter = g_cflowdConfig.CiscoMap().find(flows[flowNum].Router()); if (ciscoMapIter != g_cflowdConfig.CiscoMap().end()) { ((*ciscoMapIter).second)->AddFlow(flows[flowNum]); + + // if (the output interface is the one we were asked to skip && + // (we weren't asked to retain multicast flows || + // this isn't a multicast flow)) + if (g_skip_output_if == flows[flowNum].OutputIfIndex() && + (!g_retain_multicast || + (g_multimask & flows[flowNum].DstIpAddr()) != g_multinet)) { + continue; + } + + if (-1 != g_logfd) flows[flowNum].Write(g_logfd); } } *************** *** 814,824 **** int optChar; char *configFilename = NULL; ! while ((optChar = getopt(argc,argv,"D")) != EOF) { switch (optChar) { case 'D': g_cflowdDebug = true; break; default: break; } --- 883,921 ---- int optChar; char *configFilename = NULL; ! while ((optChar = getopt(argc,argv,"Ds:O:m")) != EOF) { switch (optChar) { case 'D': g_cflowdDebug = true; break; + case 's': + { + char *unconv; + g_logtimeout = strtoul(optarg, &unconv, 10); + if ('\0' != *unconv) { + fprintf(stderr, "usage cflowd [ -s logtimeout_seconds [ -O skip_output_if [-m] ] ]\n"); + exit(2); + } + } + break; + case 'O': + { + char *unconv; + g_skip_output_if = strtoul(optarg, &unconv, 10); + if ('\0' != *unconv) { + fprintf(stderr, "usage cflowd [ -s logtimeout_seconds [ -O skip_output_if [-m] ] ]\n"); + exit(2); + } + } + break; + case 'm': // retain multicast traffic even if we're skipping output_if 0 + // (Multicast flows always show the output_if as 0.) + if (-1 == g_skip_output_if) { + fprintf(stderr, "usage cflowd [ -s logtimeout_seconds [ -O skip_output_if [-m] ] ]\n"); + exit(2); + } + g_retain_multicast = 1; + break; default: break; } *** ./configure.in_djp Tue Feb 9 13:46:39 1999 --- ./configure.in Wed Feb 10 10:11:04 1999 *************** *** 55,61 **** builtin(include, ./dwm.m4) dnl ! DWM_PREREQ_PATH(artspp,/usr/local/arts,[arts++ installation directory]) DWM_PREREQ_PATH(cflowdtop,`pwd`,[cflowd top-level source directory]) DWM_PREREQ_PATH(docurl,/caida/powertools/cflowd,[top-level documentation URL]) AC_CHECK_LIB(fl,yywrap, --- 55,61 ---- builtin(include, ./dwm.m4) dnl ! DWM_PREREQ_PATH(artspp,$prefix,[arts++ installation directory]) DWM_PREREQ_PATH(cflowdtop,`pwd`,[cflowd top-level source directory]) DWM_PREREQ_PATH(docurl,/caida/powertools/cflowd,[top-level documentation URL]) AC_CHECK_LIB(fl,yywrap,