#include #include #include #define PACKET_ID_MASK 0x0FFFFFFF #define VERDICT_MASK 0xF0000000 struct { __uint(type, BPF_MAP_TYPE_ARRAY); __uint(max_entries, 1); __type(key, __u32); __type(value, __u32); } packet_counter SEC(".maps"); SEC("classifier") int classifier(struct __sk_buff *skb) { __u32 key = 0; __u32 *counter = bpf_map_lookup_elem(&packet_counter, &key); __u32 next = 1; if (counter) { next = __sync_add_and_fetch(counter, 1); } skb->mark = (skb->mark & VERDICT_MASK) | (next & PACKET_ID_MASK); return TC_ACT_OK; } char LICENSE[] SEC("license") = "GPL";