Use built-in Atomic functions to increment values on maps.

This commit is contained in:
Christian Deacon
2020-06-04 17:57:30 +00:00
parent 8faf701446
commit af26940018

View File

@@ -154,8 +154,9 @@ int xdp_prog_main(struct xdp_md *ctx)
ip_stats->tracking = now; ip_stats->tracking = now;
} }
ip_stats->pps++; // Increment PPS and BPS using built-in functions.
ip_stats->bps += ctx->data_end - ctx->data; __sync_fetch_and_add(&ip_stats->pps, 1);
__sync_fetch_and_add(&ip_stats->bps, ctx->data_end - ctx->data);
pps = ip_stats->pps; pps = ip_stats->pps;
bps = ip_stats->bps; bps = ip_stats->bps;
@@ -470,16 +471,12 @@ int xdp_prog_main(struct xdp_md *ctx)
// Update stats map. // Update stats map.
if (action == 0) if (action == 0)
{ {
stats->blocked++; __sync_fetch_and_add(&stats->blocked, 1);
} }
else else
{ {
stats->allowed++; __sync_fetch_and_add(&stats->allowed, 1);
} }
key = 0;
bpf_map_update_elem(&stats_map, &key, stats, BPF_ANY);
} }
#ifdef DEBUG #ifdef DEBUG