diff --git a/README.md b/README.md index b69c28e..a334c97 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ As of this time, I am not aware of any NIC manufacturers that will be able to of * `interface` => The interface for the XDP program to attach to. * `updatetime` => How often to update the config and filtering rules. Leaving this at 0 disables auto-updating. * `nostats` => If true, no accepted/blocked packet statistics will be displayed in `stdout`. +* `stdout_update_time` => The amount of time in milliseconds to update `stdout` with counters. Default is set to `1000` (one second). ### Filters Config option `filters` is an array. Each filter includes the following options: diff --git a/src/config.c b/src/config.c index 0546f84..2d85b8c 100644 --- a/src/config.c +++ b/src/config.c @@ -23,6 +23,7 @@ void setcfgdefaults(struct config *cfg) cfg->updatetime = 0; cfg->interface = "eth0"; cfg->nostats = 0; + cfg->stdout_update_time = 1000; for (__u16 i = 0; i < MAX_FILTERS; i++) { @@ -158,16 +159,18 @@ int readcfg(struct config *cfg) // Get auto update time. int updatetime; - if (!config_lookup_int(&conf, "updatetime", &updatetime)) + if (config_lookup_int(&conf, "updatetime", &updatetime) == CONFIG_TRUE) { - fprintf(stderr, "Error from LibConfig when reading 'updatetime' setting - %s\n\n", config_error_text(&conf)); - - config_destroy(&conf); - - return 1; + cfg->updatetime = updatetime; } - cfg->updatetime = updatetime; + // Get stdout update time. + int stdout_update_time; + + if (config_lookup_int(&conf, "stdout_update_time", &stdout_update_time) == CONFIG_TRUE) + { + cfg->stdout_update_time = stdout_update_time; + } // Get no stats. int nostats; diff --git a/src/config.h b/src/config.h index a4711ac..45b775d 100644 --- a/src/config.h +++ b/src/config.h @@ -9,6 +9,7 @@ struct config char *interface; __u16 updatetime; unsigned int nostats : 1; + int stdout_update_time; struct filter filters[MAX_FILTERS]; }; diff --git a/src/xdpfw.c b/src/xdpfw.c index 70cefe7..559d373 100644 --- a/src/xdpfw.c +++ b/src/xdpfw.c @@ -322,9 +322,10 @@ int main(int argc, char *argv[]) // Check for list option. if (cmd.list) { - fprintf(stdout, "Details:\n"); + fprintf(stdout, "Current Settings:\n"); fprintf(stdout, "Interface Name => %s\n", cfg.interface); fprintf(stdout, "Update Time => %d\n", cfg.updatetime); + fprintf(stdout, "Stdout Update Time => %d\n\n", cfg.stdout_update_time); for (uint16_t i = 0; i < MAX_FILTERS; i++) { diff --git a/src/xdpfw_kern.c b/src/xdpfw_kern.c index e83127d..d157847 100644 --- a/src/xdpfw_kern.c +++ b/src/xdpfw_kern.c @@ -611,7 +611,7 @@ int xdp_prog_main(struct xdp_md *ctx) // Before dropping, update the blacklist map. if (blocktime > 0) { - __u64 newTime = now + (blocktime * 1000000000); + __u64 newTime = now + (blocktime * NANO_TO_SEC); if (iph6) {