diff --git a/README.md b/README.md index 886b4f3..4465931 100644 --- a/README.md +++ b/README.md @@ -179,3 +179,4 @@ This XDP project performs basic layer 3/4 forwarding using source port mapping s ## Credits * [Christian Deacon](https://github.com/gamemann) - Creator. +* [Phil](https://github.com/Nasty07) - Contributor. diff --git a/src/xdpfw.c b/src/xdpfw.c index c0b6f8e..3c939a0 100644 --- a/src/xdpfw.c +++ b/src/xdpfw.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -291,6 +292,7 @@ int attachxdp(int ifidx, int progfd, struct cmdline *cmd) return mode; } +struct stat conf_stat; int main(int argc, char *argv[]) { // Parse the command line. @@ -341,8 +343,9 @@ int main(int argc, char *argv[]) setcfgdefaults(&cfg); // Create last updated variable. - time_t lastupdated = time(NULL); + time_t lastupdatecheck = time(NULL); time_t statslastupdated = time(NULL); + time_t lastupdated = time(NULL); // Update config. updateconfig(&cfg, cmd.cfgfile); @@ -510,20 +513,26 @@ int main(int argc, char *argv[]) } // Check for auto-update. - if (cfg.updatetime > 0 && (curTime - lastupdated) > cfg.updatetime) + if (cfg.updatetime > 0 && (curTime - lastupdatecheck) > cfg.updatetime) { - // Memleak fix for strdup() in updateconfig() - // Before updating it again, we need to free the old return value - free(cfg.interface); + // Check if config file have been modified + if (stat(cmd.cfgfile, &conf_stat) == 0 && conf_stat.st_mtime > lastupdated) { + // Memleak fix for strdup() in updateconfig() + // Before updating it again, we need to free the old return value + free(cfg.interface); - // Update config. - updateconfig(&cfg, cmd.cfgfile); + // Update config. + updateconfig(&cfg, cmd.cfgfile); + + // Update BPF maps. + updatefilters(&cfg); + + // Update timer + lastupdated = time(NULL); + } - // Update BPF maps. - updatefilters(&cfg); - // Update last updated variable. - lastupdated = time(NULL); + lastupdatecheck = time(NULL); } // Update stats.