Optimize looping through filters when updating them.

This commit is contained in:
Christian Deacon
2025-02-24 14:58:11 -05:00
parent c6db811db1
commit 42738c7670

View File

@@ -165,24 +165,21 @@ int AttachXdp(struct xdp_program *prog, int ifidx, u8 detach, cmdline_t *cmd)
*/
void UpdateFilters(int filters_map, config__t *cfg)
{
int i;
int ret;
// Loop through all filters and delete the map. 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.
for (i = 0; i < MAX_FILTERS; i++)
// Add a filter to the filter maps.
for (int i = 0; i < MAX_FILTERS; i++)
{
// Delete previous rule from BPF map.
// 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);
}
// Add a filter to the filter maps.
for (i = 0; i < MAX_FILTERS; i++)
{
// Check if we have a valid ID.
// Check if we have a valid filter.
if (cfg->filters[i].id < 1)
{
break;
continue;
}
// Create value array (max CPUs in size) since we're using a per CPU map.