Fix issue with updating IPv6 client stats and rename map names.
This commit is contained in:
@@ -155,49 +155,49 @@ int main(int argc, char *argv[])
|
||||
LogMsg(&cfg, 2, 0, "Retrieving BPF map FDs...");
|
||||
|
||||
// Retrieve BPF maps.
|
||||
int filters_map = FindMapFd(prog, "filters_map");
|
||||
int map_filters = FindMapFd(prog, "map_filters");
|
||||
|
||||
// Check for valid maps.
|
||||
if (filters_map < 0)
|
||||
if (map_filters < 0)
|
||||
{
|
||||
LogMsg(&cfg, 0, 1, "[ERROR] Failed to find 'filters_map' BPF map.\n");
|
||||
LogMsg(&cfg, 0, 1, "[ERROR] Failed to find 'map_filters' BPF map.\n");
|
||||
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
LogMsg(&cfg, 3, 0, "filters_map FD => %d.", filters_map);
|
||||
LogMsg(&cfg, 3, 0, "map_filters FD => %d.", map_filters);
|
||||
|
||||
int stats_map = FindMapFd(prog, "stats_map");
|
||||
int map_stats = FindMapFd(prog, "map_stats");
|
||||
|
||||
if (stats_map < 0)
|
||||
if (map_stats < 0)
|
||||
{
|
||||
LogMsg(&cfg, 0, 1, "[ERROR] Failed to find 'stats_map' BPF map.\n");
|
||||
LogMsg(&cfg, 0, 1, "[ERROR] Failed to find 'map_stats' BPF map.\n");
|
||||
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_FILTER_LOGGING
|
||||
int filter_log_map = FindMapFd(prog, "filter_log_map");
|
||||
int map_filter_log = FindMapFd(prog, "map_filter_log");
|
||||
struct ring_buffer* rb = NULL;
|
||||
|
||||
if (filter_log_map < 0)
|
||||
if (map_filter_log < 0)
|
||||
{
|
||||
LogMsg(&cfg, 1, 0, "[WARNING] Failed to find 'filter_log_map' BPF map. Filter logging will be disabled...");
|
||||
LogMsg(&cfg, 1, 0, "[WARNING] Failed to find 'map_filter_log' BPF map. Filter logging will be disabled...");
|
||||
}
|
||||
else
|
||||
{
|
||||
LogMsg(&cfg, 3, 0, "filter_log_map FD => %d.", filter_log_map);
|
||||
LogMsg(&cfg, 3, 0, "map_filter_log FD => %d.", map_filter_log);
|
||||
|
||||
rb = ring_buffer__new(filter_log_map, HandleRbEvent, &cfg, NULL);
|
||||
rb = ring_buffer__new(map_filter_log, HandleRbEvent, &cfg, NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
LogMsg(&cfg, 3, 0, "stats_map FD => %d.", stats_map);
|
||||
LogMsg(&cfg, 3, 0, "map_stats FD => %d.", map_stats);
|
||||
|
||||
LogMsg(&cfg, 2, 0, "Updating filters...");
|
||||
|
||||
// Update BPF maps.
|
||||
UpdateFilters(filters_map, &cfg);
|
||||
UpdateFilters(map_filters, &cfg);
|
||||
|
||||
// Signal.
|
||||
signal(SIGINT, SignalHndl);
|
||||
@@ -247,7 +247,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
// Update BPF maps.
|
||||
UpdateFilters(filters_map, &cfg);
|
||||
UpdateFilters(map_filters, &cfg);
|
||||
|
||||
// Update timer
|
||||
last_config_check = time(NULL);
|
||||
@@ -266,9 +266,9 @@ int main(int argc, char *argv[])
|
||||
// Calculate and display stats if enabled.
|
||||
if (!cfg.no_stats)
|
||||
{
|
||||
if (CalculateStats(stats_map, cpus, cfg.stats_per_second))
|
||||
if (CalculateStats(map_stats, cpus, cfg.stats_per_second))
|
||||
{
|
||||
LogMsg(&cfg, 1, 0, "[WARNING] Failed to calculate packet stats. Stats map FD => %d...\n", stats_map);
|
||||
LogMsg(&cfg, 1, 0, "[WARNING] Failed to calculate packet stats. Stats map FD => %d...\n", map_stats);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -305,7 +305,7 @@ int ReadCfg(config__t *cfg, config_overrides_t* overrides)
|
||||
}
|
||||
}
|
||||
|
||||
// Read filters in filters_map structure.
|
||||
// Read filters in map_filters structure.
|
||||
setting = config_lookup(&conf, "filters");
|
||||
|
||||
// Check if filters map is valid. If not, not a biggie since they aren't required.
|
||||
|
||||
@@ -9,13 +9,13 @@ u64 last_passed = 0;
|
||||
/**
|
||||
* Calculates and displays packet counters/stats.
|
||||
*
|
||||
* @param stats_map The stats map BPF FD.
|
||||
* @param map_stats The stats map BPF FD.
|
||||
* @param cpus The amount of CPUs the host has.
|
||||
* @param per_second Calculate packet counters per second (PPS).
|
||||
*
|
||||
* @return 0 on success or 1 on failure.
|
||||
*/
|
||||
int CalculateStats(int stats_map, int cpus, int per_second)
|
||||
int CalculateStats(int map_stats, int cpus, int per_second)
|
||||
{
|
||||
u32 key = 0;
|
||||
|
||||
@@ -26,7 +26,7 @@ int CalculateStats(int stats_map, int cpus, int per_second)
|
||||
u64 dropped = 0;
|
||||
u64 passed = 0;
|
||||
|
||||
if (bpf_map_lookup_elem(stats_map, &key, stats) != 0)
|
||||
if (bpf_map_lookup_elem(map_stats, &key, stats) != 0)
|
||||
{
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
@@ -10,4 +10,4 @@
|
||||
|
||||
#include <time.h>
|
||||
|
||||
int CalculateStats(int stats_map, int cpus, int per_second);
|
||||
int CalculateStats(int map_stats, int cpus, int per_second);
|
||||
@@ -179,12 +179,12 @@ int AttachXdp(struct xdp_program *prog, char** mode, int ifidx, u8 detach, cmdli
|
||||
/**
|
||||
* Updates the filter's BPF map with current config settings.
|
||||
*
|
||||
* @param filters_map The filter's BPF map FD.
|
||||
* @param map_filters The filter's BPF map FD.
|
||||
* @param cfg A pointer to the config structure.
|
||||
*
|
||||
* @return Void
|
||||
*/
|
||||
void UpdateFilters(int filters_map, config__t *cfg)
|
||||
void UpdateFilters(int map_filters, config__t *cfg)
|
||||
{
|
||||
int ret;
|
||||
int cur_idx = 0;
|
||||
@@ -198,7 +198,7 @@ void UpdateFilters(int filters_map, config__t *cfg)
|
||||
// We do this in the case rules were edited and were put out of order since the key doesn't uniquely map to a specific rule.
|
||||
u32 key = i;
|
||||
|
||||
bpf_map_delete_elem(filters_map, &key);
|
||||
bpf_map_delete_elem(map_filters, &key);
|
||||
|
||||
// Only insert set and enabled filters.
|
||||
if (!filter->set || !filter->enabled)
|
||||
@@ -216,7 +216,7 @@ void UpdateFilters(int filters_map, config__t *cfg)
|
||||
}
|
||||
|
||||
// Attempt to update BPF map.
|
||||
if ((ret = bpf_map_update_elem(filters_map, &cur_idx, &filter_cpus, BPF_ANY)) != 0)
|
||||
if ((ret = bpf_map_update_elem(map_filters, &cur_idx, &filter_cpus, BPF_ANY)) != 0)
|
||||
{
|
||||
fprintf(stderr, "[WARNING] Failed to update filter #%d due to BPF update error (%d)...\n", i, ret);
|
||||
}
|
||||
|
||||
@@ -14,4 +14,4 @@ int FindMapFd(struct xdp_program *prog, const char *map_name);
|
||||
void SetLibBPFLogMode(int silent);
|
||||
struct xdp_program *LoadBpfObj(const char *file_name);
|
||||
int AttachXdp(struct xdp_program *prog, char** mode, int ifidx, u8 detach, cmdline_t *cmd);
|
||||
void UpdateFilters(int filters_map, config__t *cfg);
|
||||
void UpdateFilters(int map_filters, config__t *cfg);
|
||||
Reference in New Issue
Block a user