Add std_update_time option.

This commit is contained in:
Christian Deacon
2024-06-13 20:03:21 -04:00
parent bbacda45b3
commit 525b9465cf
5 changed files with 15 additions and 9 deletions

View File

@@ -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:

View File

@@ -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;

View File

@@ -9,6 +9,7 @@ struct config
char *interface;
__u16 updatetime;
unsigned int nostats : 1;
int stdout_update_time;
struct filter filters[MAX_FILTERS];
};

View File

@@ -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++)
{

View File

@@ -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)
{