Files
mitm-webserver/tools/ebpf/mark_packet_id.c
malmert 6ad2dd2435
All checks were successful
Build and Deploy MITM Webserver / build (push) Successful in 9s
ebpf fix
2026-03-07 15:43:07 +01:00

38 lines
818 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 counter_state {
struct bpf_spin_lock lock;
__u32 value;
};
struct {
__uint(type, BPF_MAP_TYPE_ARRAY);
__uint(max_entries, 1);
__type(key, __u32);
__type(value, struct counter_state);
} packet_counter SEC(".maps");
SEC("classifier")
int classifier(struct __sk_buff *skb) {
__u32 key = 0;
struct counter_state *state = bpf_map_lookup_elem(&packet_counter, &key);
__u32 next = 1;
if (state) {
bpf_spin_lock(&state->lock);
state->value += 1;
next = state->value;
bpf_spin_unlock(&state->lock);
}
skb->mark = (skb->mark & VERDICT_MASK) | (next & PACKET_ID_MASK);
return TC_ACT_OK;
}
char LICENSE[] SEC("license") = "GPL";