Signed-off-by: Rodrigo Martins <rodrigo.sousa.577@gmail.com>
This commit is contained in:
rodrigo committed 2025-03-23 22:11:10 -03:00
1 parent 5da4e2e498
commit 06864531fd
6 files changed
+630

No files matched your search

+37
View File
@@ -0,0 +1,37 @@
#define _GNU_SOURCE
#include <stdio.h>
#include <net/if.h>
#include <bpf/libbpf.h>
#include <linux/if_link.h>
#include "bridge_xdp.h"
int main(int argc, char **argv)
{
if (argc != 2) {
printf("Uso: %s <interface>\n", argv[0]);
return 1;
}
// Carregar programa XDP
struct bpf_object *obj = bpf_object__open("bridge_xdp.o");
if (!obj) {
printf("Erro ao abrir objeto BPF\n");
return 1;
}
if (bpf_object__load(obj)) {
printf("Erro ao carregar objeto BPF\n");
return 1;
}
// Anexar à interface
int prog_fd = bpf_program__fd(bpf_object__find_program_by_name(obj, "bridge_filter"));
unsigned int flags = XDP_FLAGS_UPDATE_IF_NOEXIST | XDP_FLAGS_DRV_MODE;
if (bpf_xdp_attach(if_nametoindex(argv[1]), prog_fd, flags, NULL) != 0) {
printf("Erro ao anexar XDP\n");
return 1;
}
printf("XDP anexado com sucesso à interface %s\n", argv[1]);
return 0;
}