Optimize looping through filters when updating them.
This commit is contained in:
@@ -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)
|
void UpdateFilters(int filters_map, config__t *cfg)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
int ret;
|
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.
|
// Add a filter to the filter maps.
|
||||||
for (i = 0; i < MAX_FILTERS; i++)
|
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;
|
u32 key = i;
|
||||||
|
|
||||||
bpf_map_delete_elem(filters_map, &key);
|
bpf_map_delete_elem(filters_map, &key);
|
||||||
}
|
|
||||||
|
|
||||||
// Add a filter to the filter maps.
|
// Check if we have a valid filter.
|
||||||
for (i = 0; i < MAX_FILTERS; i++)
|
|
||||||
{
|
|
||||||
// Check if we have a valid ID.
|
|
||||||
if (cfg->filters[i].id < 1)
|
if (cfg->filters[i].id < 1)
|
||||||
{
|
{
|
||||||
break;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create value array (max CPUs in size) since we're using a per CPU map.
|
// Create value array (max CPUs in size) since we're using a per CPU map.
|
||||||
|
|||||||
Reference in New Issue
Block a user