Skip to content

Commit

Permalink
Use per CPU array map for filter rules to increase performance.
Browse files Browse the repository at this point in the history
  • Loading branch information
gamemann committed Nov 12, 2023
1 parent 03d38b5 commit b3530e3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/xdpfw.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void signalHndl(int tmp)
*/
void updatefilters(struct config *cfg)
{
// Loop through all filters and delete the map.
// 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 (__u8 i = 0; i < MAX_FILTERS; i++)
{
__u32 key = i;
Expand All @@ -60,8 +60,16 @@ void updatefilters(struct config *cfg)
break;
}

// Create value array (max CPUs in size) since we're using a per CPU map.
struct filter filter[MAX_CPUS];

for (int j = 0; j < MAX_CPUS; j++)
{
filter[j] = cfg->filters[i];
}

// Attempt to update BPF map.
if (bpf_map_update_elem(filtersmap, &i, &cfg->filters[i], BPF_ANY) == -1)
if (bpf_map_update_elem(filtersmap, &i, &filter, BPF_ANY) == -1)
{
fprintf(stderr, "Error updating BPF item #%d\n", i);
}
Expand Down
2 changes: 1 addition & 1 deletion src/xdpfw_kern.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct

struct
{
__uint(type, BPF_MAP_TYPE_ARRAY);
__uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
__uint(max_entries, MAX_FILTERS);
__type(key, __u32);
__type(value, struct filter);
Expand Down

0 comments on commit b3530e3

Please sign in to comment.