Files
mitm-webserver/tools/ebpf/mark_packet_id.c
malmert a282b89d45
All checks were successful
Build and Deploy MITM Webserver / build (push) Successful in 10s
tc full packet test
2026-03-07 15:13:08 +01:00

30 lines
650 B
C

#include <linux/bpf.h>
#include <linux/pkt_cls.h>
#include <bpf/bpf_helpers.h>
#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";