Add filter logging.

This commit is contained in:
Christian Deacon
2025-02-26 11:13:59 -05:00
parent 3878bacb71
commit 8596997b98
10 changed files with 285 additions and 152 deletions

View File

@@ -93,4 +93,38 @@ void LogMsg(config__t* cfg, int req_lvl, int error, const char* msg, ...)
LogMsgRaw(req_lvl, cfg->verbose, error, (const char*)cfg->log_file, msg, args);
va_end(args);
}
int HandleRbEvent(void* ctx, void* data, size_t sz)
{
config__t* cfg = (config__t*)ctx;
filter_log_event_t* e = (filter_log_event_t*)data;
filter_t* filter = &cfg->filters[e->filter_id];
if (filter == NULL)
{
return 1;
}
char ip_str[INET6_ADDRSTRLEN];
if (memcmp(e->src_ip6, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 16) != 0)
{
inet_ntop(AF_INET6, e->src_ip6, ip_str, sizeof(ip_str));
} else
{
inet_ntop(AF_INET, &e->src_ip, ip_str, sizeof(ip_str));
}
char* action = "Dropped";
if (filter->action == 1)
{
action = "Passed";
}
LogMsg(cfg, 0, 0, "[FILTER %d] %s packet from '%s:%d' (PPS => %llu, BPS => %llu, Filter Block Time => %llu)...", e->filter_id, action, ip_str, e->src_port, e->pps, e->bps, filter->blocktime);
return 0;
}