From 42738c76701d405be4fa1f893af92347c2c3e0da Mon Sep 17 00:00:00 2001 From: Christian Deacon Date: Mon, 24 Feb 2025 14:58:11 -0500 Subject: [PATCH] Optimize looping through filters when updating them. --- src/loader/utils/xdp.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/loader/utils/xdp.c b/src/loader/utils/xdp.c index 9f2cd31..f473b02 100644 --- a/src/loader/utils/xdp.c +++ b/src/loader/utils/xdp.c @@ -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.