From 2278480dc39886e667300866b9d4490149db6f99 Mon Sep 17 00:00:00 2001 From: MuriloChianfa Date: Fri, 30 Jan 2026 21:49:50 -0300 Subject: [PATCH] reduce minimum nfcapd time to 1 second --- man/nfcapd.1 | 2 +- man/nfpcapd.1 | 2 +- man/sfcapd.1 | 2 +- src/nfcapd/nfcapd.c | 11 +++++------ src/nfpcapd/nfpcapd.c | 4 ++-- src/sflow/sfcapd.c | 11 +++++------ 6 files changed, 15 insertions(+), 17 deletions(-) diff --git a/man/nfcapd.1 b/man/nfcapd.1 index 79996292..59a0b9de 100755 --- a/man/nfcapd.1 +++ b/man/nfcapd.1 @@ -263,7 +263,7 @@ The following hierarchies are defined: .El .It Fl t Ar interval Sets the time interval in seconds to rotate files. The default value is 300s ( 5min ). -The smallest available interval is 2s. +The smallest available interval is 1s. .It Fl s Ar rate Apply sampling rate .Ar rate diff --git a/man/nfpcapd.1 b/man/nfpcapd.1 index f1dd9435..7688b99e 100644 --- a/man/nfpcapd.1 +++ b/man/nfpcapd.1 @@ -124,7 +124,7 @@ The base directory ( .Fl l ) is concatenated with the specified sub hierarchy format to form the final data directory. For a full list of hierarchies see nfcapd(1). .It Fl t Ar interval -Specifies the time interval in seconds to rotate files. The default value is 300s ( 5min ). The smallest interval can be set to 2s. The intervals are in sync with wall clock. +Specifies the time interval in seconds to rotate files. The default value is 300s ( 5min ). The smallest interval can be set to 1s. The intervals are in sync with wall clock. .It Fl P Ar pidfile Specify name of pidfile. Default is no pidfile. .It Fl D diff --git a/man/sfcapd.1 b/man/sfcapd.1 index 57d46869..18718774 100755 --- a/man/sfcapd.1 +++ b/man/sfcapd.1 @@ -227,7 +227,7 @@ The following hierarchies are defined: .El .It Fl t Ar interval Sets the time interval in seconds to rotate files. The default value is 300s ( 5min ). -The smallest available interval is 2s. +The smallest available interval is 1s. .It Fl z=lzo Compress flow files with LZO1X-1 compression. Fastest compression. .It Fl z=bz2 diff --git a/src/nfcapd/nfcapd.c b/src/nfcapd/nfcapd.c index 6b4576d8..4b955f49 100644 --- a/src/nfcapd/nfcapd.c +++ b/src/nfcapd/nfcapd.c @@ -295,8 +295,8 @@ static void run(collector_ctx_t *ctx, packet_function_t receive_packet, int sock uint32_t ignored_packets = 0; uint64_t packets = 0; - // wake up at least at next time slot (twin) + 1s - alarm(t_start + twin + 1 - time(NULL)); + // wake up at next time slot (twin) for precise rotation + alarm(t_start + twin - time(NULL)); /* * Main processing loop: * this loop, continues until = 1, set by the signal handler @@ -374,11 +374,10 @@ static void run(collector_ctx_t *ctx, packet_function_t receive_packet, int sock * update alarm for next cycle * t_start = filename time stamp: begin of slot * + twin = end of next time interval - * + 1 = act at least 1s after time window expired * - t_now = difference value to now */ t_start += twin; - alarm(t_start + twin + 1 - t_now); + alarm(t_start + twin - t_now); } /* check for EINTR and continue */ @@ -694,8 +693,8 @@ int main(int argc, char **argv) { break; case 't': twin = atoi(optarg); - if (twin < 2) { - LogError("time interval <= 2s not allowed"); + if (twin < 1) { + LogError("time interval < 1s not allowed"); exit(EXIT_FAILURE); } if (twin < 60) { diff --git a/src/nfpcapd/nfpcapd.c b/src/nfpcapd/nfpcapd.c index 1a87ffc0..be98681e 100755 --- a/src/nfpcapd/nfpcapd.c +++ b/src/nfpcapd/nfpcapd.c @@ -443,8 +443,8 @@ int main(int argc, char *argv[]) { } break; case 't': t_win = atoi(optarg); - if (t_win < 2) { - LogError("time interval <= 2s not allowed"); + if (t_win < 1) { + LogError("time interval < 1s not allowed"); exit(EXIT_FAILURE); } if (t_win < 60) { diff --git a/src/sflow/sfcapd.c b/src/sflow/sfcapd.c index 8aaed0eb..4d9e82fd 100644 --- a/src/sflow/sfcapd.c +++ b/src/sflow/sfcapd.c @@ -292,8 +292,8 @@ static void run(collector_ctx_t *ctx, packet_function_t receive_packet, int sock uint32_t ignored_packets = 0; uint64_t packets = 0; - // wake up at least at next time slot (twin) + 1s - alarm(t_start + twin + 1 - time(NULL)); + // wake up at next time slot (twin) for precise rotation + alarm(t_start + twin - time(NULL)); /* * Main processing loop: * this loop, continues until = 1, set by the signal handler @@ -352,11 +352,10 @@ static void run(collector_ctx_t *ctx, packet_function_t receive_packet, int sock * update alarm for next cycle * t_start = filename time stamp: begin of slot * + twin = end of next time interval - * + 1 = act at least 1s after time window expired * - t_now = difference value to now */ t_start += twin; - alarm(t_start + twin + 1 - t_now); + alarm(t_start + twin - t_now); } /* check for EINTR and continue */ @@ -643,8 +642,8 @@ int main(int argc, char **argv) { break; case 't': twin = atoi(optarg); - if (twin < 2) { - LogError("time interval <= 2s not allowed"); + if (twin < 1) { + LogError("time interval < 1s not allowed"); exit(EXIT_FAILURE); } if (twin < 60) {