SEC("xdp_bench01") int xdp_prog(struct xdp_md *ctx) { void *data_end = (void *)(long)ctx->data_end; void *data = (void *)(long)ctx->data; struct ethhdr *eth = data; volatile u16 eth_type; long *value; u64 offset; u32 key = 0; int *action; u64 *touch_mem; /* Validate packet length is minimum Eth header size */ offset = sizeof(*eth); if (data + offset > data_end) return XDP_DROP; /* Allow userspace to choose XDP_DROP or XDP_PASS */ action = bpf_map_lookup_elem(&xdp_action, &key); if (!action) return XDP_DROP; /* Default: Don't touch packet data, only count packets */ touch_mem = bpf_map_lookup_elem(&touch_memory, &key); if (touch_mem && (*touch_mem == 1)) { /* ... code removed for brevity */ eth_type = eth->h_proto; } value = bpf_map_lookup_elem(&rx_cnt, &key); if (value) *value += 1; return *action; }