Add pass counter for packets that don't match any rules and are passed to user-space.

This commit is contained in:
Christian Deacon
2024-06-13 19:54:50 -04:00
parent 648dbff479
commit bbacda45b3
3 changed files with 45 additions and 37 deletions

View File

@@ -316,11 +316,6 @@ int main(int argc, char *argv[])
setcfgdefaults(&cfg);
// Create last updated variable.
time_t lastupdatecheck = time(NULL);
time_t statslastupdated = time(NULL);
time_t lastupdated = time(NULL);
// Update config.
updateconfig(&cfg, cmd.cfgfile);
@@ -474,6 +469,11 @@ int main(int argc, char *argv[])
unsigned int endTime = (cmd.time > 0) ? time(NULL) + cmd.time : 0;
// Create last updated variable.
time_t lastupdatecheck = time(NULL);
time_t statslastupdated = time(NULL);
time_t lastupdated = time(NULL);
while (cont)
{
// Get current time.
@@ -517,6 +517,7 @@ int main(int argc, char *argv[])
__u64 allowed = 0;
__u64 dropped = 0;
__u64 passed = 0;
if (bpf_map_lookup_elem(statsmap, &key, stats) != 0)
{
@@ -539,15 +540,16 @@ int main(int argc, char *argv[])
allowed += stats[i].allowed;
dropped += stats[i].dropped;
passed += stats[i].passed;
}
fflush(stdout);
fprintf(stdout, "\rPackets Allowed: %llu | Packets Dropped: %llu", allowed, dropped);
fprintf(stdout, "\rAllowed: %llu | Dropped: %llu | Passed: %llu", allowed, dropped, passed);
statslastupdated = time(NULL);
}
sleep(1);
usleep(500);
}
// Detach XDP program.

View File

@@ -135,6 +135,7 @@ struct stats
{
__u64 allowed;
__u64 dropped;
__u64 passed;
};
struct ip_stats

View File

@@ -594,6 +594,11 @@ int xdp_prog_main(struct xdp_md *ctx)
goto matched;
}
if (stats)
{
stats->passed++;
}
return XDP_PASS;
matched: