Skip to content

Commit

Permalink
Adapt -J option in nfdump to new compression spec, being still compat…
Browse files Browse the repository at this point in the history
…ible with old one.
  • Loading branch information
phaag committed May 21, 2023
1 parent a1f4f19 commit 12a90b4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
8 changes: 5 additions & 3 deletions man/nfdump.1
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
.Op Fl E Ar flowfile
.Op Fl x Ar flowfile
.Op Fl z=<compress>
.Op Fl J Ar num
.Op Fl J Ar compress
.Op Fl X
.Op Fl Z
.Op Fl T
Expand Down Expand Up @@ -672,10 +672,12 @@ Compress flow files with LZ4 compression. Fast and efficient.
.It Fl z=bz2
Compress flow files with bz2 compression. Slow but most efficient. May be used
for archiving files or if you are really short of spce.
.It Fl J Ar num
.It Fl J Ar compress
Change compression for any number of files given by option
.Fl r Ar flowpath
num: 0 uncompress, 1: LZO1X-1, 2: bz2, 3: LZ4 compression. This option may be used
Set
.Ar compress
to 0 for no compression or to any of: 1 or LZO, 2 or BZ2, 3 or LZ4. This option may be used
for archiving flow files and changing the compression to use less disk space.
.It Fl X
Compiles the
Expand Down
12 changes: 8 additions & 4 deletions src/lib/nffile.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ int Init_nffile(queue_t *fileList) {
} // End of Init_nffile

int ParseCompression(char *arg) {
if (arg == NULL || arg[0] != '=' || strlen(arg) > 16) {
if (arg == NULL) {
return LZO_COMPRESSED;
}
if (arg[0] != '=' || strlen(arg) > 16) {
return -1;
}
arg++;
Expand All @@ -152,9 +155,10 @@ int ParseCompression(char *arg) {
arg[i] = tolower(arg[i]);
}

if (strcmp(arg, "lzo") == 0) return LZO_COMPRESSED;
if (strcmp(arg, "lz4") == 0) return LZ4_COMPRESSED;
if (strcmp(arg, "bz2") == 0 || strcmp(arg, "bzip2") == 0) return BZ2_COMPRESSED;
if (strcmp(arg, "0") == 0) return NOT_COMPRESSED;
if (strcmp(arg, "lzo") == 0 || strcmp(arg, "1") == 0) return LZO_COMPRESSED;
if (strcmp(arg, "lz4") == 0 || strcmp(arg, "3") == 0) return LZ4_COMPRESSED;
if (strcmp(arg, "bz2") == 0 || strcmp(arg, "bzip2") == 0 || strcmp(arg, "2") == 0) return BZ2_COMPRESSED;

// anything else is invalid
return -1;
Expand Down
7 changes: 3 additions & 4 deletions src/nfdump/nfdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -819,10 +819,9 @@ int main(int argc, char **argv) {
}
break;
case 'J':
CheckArgLen(optarg, 8);
ModifyCompress = atoi(optarg);
if ((ModifyCompress < 0) || (ModifyCompress > 3)) {
LogError("Expected -J <num>, 0: uncompressed, 1: LZO, 2: BZ2, 3: LZ4 compressed");
ModifyCompress = ParseCompression(optarg);
if (ModifyCompress < 0) {
LogError("Expected -J <arg>, 0 for uncompressed, 1, LZO, 2, BZ2, 3, LZ4");
exit(EXIT_FAILURE);
}
break;
Expand Down

0 comments on commit 12a90b4

Please sign in to comment.