#ifndef OPENSNITCH_EVENT_STATS_H #define OPENSNITCH_EVENT_STATS_H /* Include after the module's events map. Fixed cardinality, no payloads. * Keep this value ABI in sync with daemon/core/event_stats.go. */ struct event_emission_counts { u64 attempted; u64 failed; }; struct { __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY); __type(key, u32); __type(value, struct event_emission_counts); __uint(max_entries, 1); } event_stats SEC(".maps"); static __always_inline long emit_counted_event(void *data, u64 size) { long ret = bpf_ringbuf_output(&events, data, size, 0); u32 key = 0; struct event_emission_counts *counts = bpf_map_lookup_elem(&event_stats, &key); if (counts) { __sync_fetch_and_add(&counts->attempted, 1); if (ret != 0) __sync_fetch_and_add(&counts->failed, 1); } /* Diagnostic accounting cannot replace or retry an emission. */ return ret; } #endif