1 parent
5da4e2e498
commit
7fbad60945
5 files changed
+598
No files matched your search
@@ -0,0 +1,31 @@
|
||||
#include <linux/bpf.h>
|
||||
#include <bpf/bpf_helpers.h>
|
||||
#include "bridge_xdp.h"
|
||||
|
||||
SEC("xdp")
|
||||
int bridge_filter(struct xdp_md *ctx)
|
||||
{
|
||||
void *data_end = (void *)(long)ctx->data_end;
|
||||
void *data = (void *)(long)ctx->data;
|
||||
struct ethhdr *eth = data;
|
||||
|
||||
// Verificação básica do header ethernet
|
||||
if ((void*)(eth + 1) > data_end)
|
||||
return XDP_ABORTED;
|
||||
|
||||
// Atualizar estatísticas
|
||||
__u32 key = 0;
|
||||
struct packet_stats *stats = bpf_map_lookup_elem(&stats_map, &key);
|
||||
if (stats) {
|
||||
stats->packets++;
|
||||
stats->bytes += (data_end - data);
|
||||
}
|
||||
|
||||
// Verificar se é broadcast/multicast
|
||||
if (eth->h_dest[0] & 1)
|
||||
return XDP_PASS; // Deixar o kernel processar
|
||||
|
||||
return XDP_TX; // Enviar pacote diretamente
|
||||
}
|
||||
|
||||
char _license[] SEC("license") = "GPL";
|
||||
Reference in new issue
Block a user