commit
This commit is contained in:
1 parent
c4cea8c3b3
commit
9ed03e108d
4 files changed
+242
-237
No files matched your search
@@ -0,0 +1,68 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Script simplificado para compilar e carregar programas XDP
|
||||
|
||||
# Interface a ser utilizada
|
||||
IFACE=${1:-"enp0s6"}
|
||||
MODE=${2:-"generic"} # generic é mais compatível; native é mais rápido
|
||||
TYPE=${3:-"simple"} # simple ou accelerated
|
||||
|
||||
echo "Compilando e carregando programa XDP"
|
||||
echo "Interface: $IFACE"
|
||||
echo "Modo: $MODE"
|
||||
echo "Tipo: $TYPE"
|
||||
|
||||
# Compilar o programa correto
|
||||
if [ "$TYPE" == "simple" ]; then
|
||||
echo "=== Compilando programa simple_xdp_filter ==="
|
||||
clang -O2 -Wall -target bpf -g -D__TARGET_ARCH_arm64 -c simple_xdp_filter.c -o simple_xdp_filter.o -I/usr/include/bpf -I/usr/include/
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Erro na compilação!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
PROG_FILE="simple_xdp_filter.o"
|
||||
else
|
||||
echo "=== Compilando programa xdp_accelerated_nat ==="
|
||||
clang -O2 -Wall -target bpf -g -D__TARGET_ARCH_arm64 -c xdp_accelerated_nat.c -o xdp_accelerated_nat.o -I/usr/include/bpf -I/usr/include/
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Erro na compilação!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
PROG_FILE="xdp_accelerated_nat.o"
|
||||
fi
|
||||
|
||||
# Remover qualquer programa XDP existente
|
||||
echo "Removendo programas XDP existentes da interface $IFACE"
|
||||
ip link set dev $IFACE xdp off
|
||||
|
||||
# Carregar o programa
|
||||
echo "Carregando programa $PROG_FILE na interface $IFACE (modo $MODE)..."
|
||||
ip link set dev $IFACE xdp obj $PROG_FILE section xdp mode $MODE
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Erro ao carregar programa XDP."
|
||||
echo "Tentando modo alternativo (skb)..."
|
||||
ip link set dev $IFACE xdp obj $PROG_FILE section xdp mode skb
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Falha também no modo skb."
|
||||
echo "Verifique se seu kernel suporta XDP."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Programa XDP carregado com sucesso!"
|
||||
echo "Verificando status:"
|
||||
ip link show dev $IFACE | grep xdp
|
||||
|
||||
echo "Use 'bpftool map dump' para ver os mapas"
|
||||
|
||||
if [ "$TYPE" == "simple" ]; then
|
||||
# Mostrar estatísticas iniciais
|
||||
echo "Estatísticas iniciais:"
|
||||
bpftool map dump name stats_map
|
||||
fi
|
||||
Reference in new issue
Block a user