aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYunchih Chen <yunchih.cat@gmail.com>2018-03-18 21:10:49 +0800
committerYunchih Chen <yunchih.cat@gmail.com>2018-03-18 21:10:49 +0800
commitd6fe4152d0a213cc64336853271188371c9d3563 (patch)
tree9a69e6900bb96a9e2906c14840968a92c9eab159
parent597453d4b147cb0e07704e1dec455cfc7cebe382 (diff)
downloadnfcollect-d6fe4152d0a213cc64336853271188371c9d3563.tar
nfcollect-d6fe4152d0a213cc64336853271188371c9d3563.tar.gz
nfcollect-d6fe4152d0a213cc64336853271188371c9d3563.tar.bz2
nfcollect-d6fe4152d0a213cc64336853271188371c9d3563.tar.lz
nfcollect-d6fe4152d0a213cc64336853271188371c9d3563.tar.xz
nfcollect-d6fe4152d0a213cc64336853271188371c9d3563.tar.zst
nfcollect-d6fe4152d0a213cc64336853271188371c9d3563.zip
Format with clang-format
-rw-r--r--bin/nfcollect.c6
-rw-r--r--include/main.h18
-rw-r--r--lib/commit.c35
-rw-r--r--lib/extract.c58
4 files changed, 63 insertions, 54 deletions
diff --git a/bin/nfcollect.c b/bin/nfcollect.c
index d4cf994..527ac24 100644
--- a/bin/nfcollect.c
+++ b/bin/nfcollect.c
@@ -39,7 +39,8 @@ const char *help_text =
"Usage: " PACKAGE " [OPTION]\n"
"\n"
"Options:\n"
- " -c --compression=<algo> compression algorithm to use (default: no compression)\n"
+ " -c --compression=<algo> compression algorithm to use (default: no "
+ "compression)\n"
" -d --storage_dir=<dirname> log files storage directory\n"
" -h --help print this help\n"
" -g --nflog-group=<id> the group id to collect\n"
@@ -137,8 +138,7 @@ int main(int argc, char *argv[]) {
sem_init(g.nfl_commit_queue, 0, max_commit_worker);
// Set up nflog receiver worker
- nfl_state_t **trunks =
- (nfl_state_t **)calloc(trunk_cnt, sizeof(void *));
+ nfl_state_t **trunks = (nfl_state_t **)calloc(trunk_cnt, sizeof(void *));
nfl_commit_init(trunk_cnt);
debug("Worker started, entries_max = %d, trunk_cnt = %d", entries_max,
diff --git a/include/main.h b/include/main.h
index 44ed766..ad62417 100644
--- a/include/main.h
+++ b/include/main.h
@@ -89,7 +89,7 @@ typedef struct __attribute__((packed)) _nfl_header_t {
uint32_t n_entries; /* 4 4 */
uint32_t max_n_entries; /* 8 4 */
uint32_t cksum; /* 12 4 */
- enum nfl_compression_t compression_opt; /* 16 4 */
+ enum nfl_compression_t compression_opt; /* 16 4 */
time_t start_time; /* 20 8 */
time_t end_time; /* 28 8 */
@@ -99,28 +99,28 @@ typedef struct __attribute__((packed)) _nfl_header_t {
typedef struct __attribute__((packed)) _nfl_entry_t {
// current timestamp since UNIX epoch
- time_t timestamp; /* 0 8 */
+ time_t timestamp; /* 0 8 */
// dest address
- struct in_addr daddr; /* 8 4 */
+ struct in_addr daddr; /* 8 4 */
// uid
- uint32_t uid; /* 12 4 */
+ uint32_t uid; /* 12 4 */
// unused space, just for padding
- uint8_t __unused1; /* 16 1 */
+ uint8_t __unused1; /* 16 1 */
// IP protocol (UDP or TCP)
- uint8_t protocol; /* 17 1 */
+ uint8_t protocol; /* 17 1 */
// unused space, just for padding
- uint16_t __unused2; /* 18 2 */
+ uint16_t __unused2; /* 18 2 */
// source port
- uint16_t sport; /* 20 2 */
+ uint16_t sport; /* 20 2 */
// destination port
- uint16_t dport; /* 22 2 */
+ uint16_t dport; /* 22 2 */
/* size: 24, cachelines: 1, members: 8 */
} nfl_entry_t;
diff --git a/lib/commit.c b/lib/commit.c
index ca90598..f2fbc06 100644
--- a/lib/commit.c
+++ b/lib/commit.c
@@ -8,7 +8,8 @@ static void nfl_commit_default(FILE *f, nfl_entry_t *store,
static void nfl_commit_lz4(FILE *f, nfl_entry_t *store, uint32_t store_size);
static void nfl_commit_zstd(FILE *f, nfl_entry_t *store, uint32_t store_size);
-void nfl_commit_init() { /* TODO */ }
+void nfl_commit_init() { /* TODO */
+}
static void nfl_commit_default(FILE *f, nfl_entry_t *store,
uint32_t store_size) {
@@ -21,8 +22,7 @@ static void nfl_commit_lz4(FILE *f, nfl_entry_t *store, uint32_t store_size) {
/* TODO */
}
-static void nfl_commit_zstd(FILE *f, nfl_entry_t *store,
- uint32_t store_size) {
+static void nfl_commit_zstd(FILE *f, nfl_entry_t *store, uint32_t store_size) {
size_t const bufsize = ZSTD_compressBound(store_size);
void *buf;
@@ -50,21 +50,22 @@ void nfl_commit_worker(nfl_header_t *header, nfl_entry_t *store,
// commit store
uint32_t store_size = sizeof(nfl_entry_t) * header->max_n_entries;
- switch(compression_opt) {
- case COMPRESS_NONE:
- debug("Comm worker #%u: commit without compression\n", header->id)
+ switch (compression_opt) {
+ case COMPRESS_NONE:
+ debug("Comm worker #%u: commit without compression\n", header->id)
nfl_commit_default(f, store, store_size);
- break;
- case COMPRESS_LZ4:
- debug("Comm worker #%u: commit with compression algorithm: lz4", header->id)
- nfl_commit_lz4(f, store, store_size);
- break;
- case COMPRESS_ZSTD:
- debug("Comm worker #%u: commit with compression algorithm: zstd", header->id)
- nfl_commit_zstd(f, store, store_size);
- break;
- // Must not reach here ...
- default: FATAL("Unknown compression option detected");
+ break;
+ case COMPRESS_LZ4:
+ debug("Comm worker #%u: commit with compression algorithm: lz4",
+ header->id) nfl_commit_lz4(f, store, store_size);
+ break;
+ case COMPRESS_ZSTD:
+ debug("Comm worker #%u: commit with compression algorithm: zstd",
+ header->id) nfl_commit_zstd(f, store, store_size);
+ break;
+ // Must not reach here ...
+ default:
+ FATAL("Unknown compression option detected");
}
// Do fsync ?
diff --git a/lib/extract.c b/lib/extract.c
index 61bf340..822c216 100644
--- a/lib/extract.c
+++ b/lib/extract.c
@@ -11,7 +11,7 @@ static int nfl_extract_zstd(FILE *f, nfl_state_t *state);
static int nfl_extract_lz4(FILE *f, nfl_state_t *state);
static int nfl_verify_header(nfl_header_t *header) {
- if(header->cksum != nfl_header_cksum(header))
+ if (header->cksum != nfl_header_cksum(header))
return -1;
if (header->id > MAX_TRUNK_ID)
@@ -37,24 +37,28 @@ static int nfl_extract_default(FILE *f, nfl_state_t *state) {
static int nfl_extract_zstd(FILE *f, nfl_state_t *state) {
char *buf;
size_t const compressed_size = nfl_get_filesize(f) - sizeof(nfl_header_t),
- expected_decom_size = state->header->n_entries * sizeof(nfl_entry_t);
+ expected_decom_size =
+ state->header->n_entries * sizeof(nfl_entry_t);
ERR(!(buf = malloc(compressed_size)), "zstd: cannot malloc");
fread(buf, compressed_size, 1, f);
WARN_RETURN(ferror(f), "%s", strerror(errno));
- size_t const estimate_decom_size = ZSTD_findDecompressedSize(buf, compressed_size);
+ size_t const estimate_decom_size =
+ ZSTD_findDecompressedSize(buf, compressed_size);
if (estimate_decom_size == ZSTD_CONTENTSIZE_ERROR)
FATAL("zstd: file was not compressed by zstd.\n");
else if (estimate_decom_size == ZSTD_CONTENTSIZE_UNKNOWN)
- FATAL("zstd: original size unknown. Use streaming decompression instead");
+ FATAL(
+ "zstd: original size unknown. Use streaming decompression instead");
- size_t const actual_decom_size =
- ZSTD_decompress(state->store, expected_decom_size, buf, compressed_size);
+ size_t const actual_decom_size = ZSTD_decompress(
+ state->store, expected_decom_size, buf, compressed_size);
if (actual_decom_size != expected_decom_size) {
- FATAL("zstd: error decoding current file: %s \n", ZSTD_getErrorName(actual_decom_size));
- }
+ FATAL("zstd: error decoding current file: %s \n",
+ ZSTD_getErrorName(actual_decom_size));
+ }
free(buf);
return 0;
@@ -75,31 +79,35 @@ int nfl_extract_worker(const char *filename, nfl_state_t *state) {
/* ERR(nfl_check_file(f) < 0, "extract worker"); */
// Read header
- ERR(!(state->header = malloc(sizeof(nfl_header_t))), "extract malloc header");
+ ERR(!(state->header = malloc(sizeof(nfl_header_t))),
+ "extract malloc header");
got = fread(state->header, sizeof(nfl_header_t), 1, f);
h = state->header;
// Check header validity
WARN_RETURN(ferror(f), "%s", strerror(errno));
- WARN_RETURN(!got || nfl_verify_header(h) < 0, "File %s has corrupted header.", filename);
+ WARN_RETURN(!got || nfl_verify_header(h) < 0,
+ "File %s has corrupted header.", filename);
// Read body
- ERR(!(state->store = malloc(sizeof(nfl_entry_t) * h->n_entries)), "extract malloc store");
- switch(h->compression_opt) {
- case COMPRESS_NONE:
- debug("Extract worker #%u: extract without compression\n", h->id)
+ ERR(!(state->store = malloc(sizeof(nfl_entry_t) * h->n_entries)),
+ "extract malloc store");
+ switch (h->compression_opt) {
+ case COMPRESS_NONE:
+ debug("Extract worker #%u: extract without compression\n", h->id)
nfl_extract_default(f, state);
- break;
- case COMPRESS_LZ4:
- debug("Extract worker #%u: extract with compression algorithm: lz4", h->id)
- nfl_extract_lz4(f, state);
- break;
- case COMPRESS_ZSTD:
- debug("Extract worker #%u: extract with compression algorithm: zstd", h->id)
- nfl_extract_zstd(f, state);
- break;
- // Must not reach here ...
- default: FATAL("Unknown compression option detected");
+ break;
+ case COMPRESS_LZ4:
+ debug("Extract worker #%u: extract with compression algorithm: lz4",
+ h->id) nfl_extract_lz4(f, state);
+ break;
+ case COMPRESS_ZSTD:
+ debug("Extract worker #%u: extract with compression algorithm: zstd",
+ h->id) nfl_extract_zstd(f, state);
+ break;
+ // Must not reach here ...
+ default:
+ FATAL("Unknown compression option detected");
}
fclose(f);