commit
This commit is contained in:
1 parent
824fffb2cf
commit
b02be8d620
2 files changed
+54
-5
No files matched your search
@@ -0,0 +1,53 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# 1. Limpar qualquer programa XDP anterior para garantir carregamento limpo
|
||||||
|
echo "Removendo programas XDP anteriores..."
|
||||||
|
ip link set dev enp0s6 xdp off 2>/dev/null
|
||||||
|
|
||||||
|
# Compilar o programa XDP com flags otimizadas e suprimir avisos de funções não utilizadas
|
||||||
|
echo "Compilando programa XDP..."
|
||||||
|
clang -O2 -target bpf -c xdp_ddos_filter.c -o xdp_ddos_filter.o \
|
||||||
|
-I/usr/include/bpf -I/usr/include/ \
|
||||||
|
-Wno-unused-function -D__TARGET_ARCH_arm64
|
||||||
|
|
||||||
|
# Verificar se a compilação foi bem-sucedida
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "ERRO: Falha na compilação do programa XDP"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Implantar o programa XDP na interface
|
||||||
|
echo "Implantando programa XDP na interface enp0s6..."
|
||||||
|
ip link set dev enp0s6 xdp object xdp_ddos_filter.o verbose
|
||||||
|
|
||||||
|
# Verificar se carregou corretamente
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo "Programa XDP carregado com sucesso"
|
||||||
|
else
|
||||||
|
echo "ERRO: Falha ao carregar programa XDP"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 2. Aplicar regras iptables existentes
|
||||||
|
echo "Aplicando regras iptables..."
|
||||||
|
sh /root/test.sh # Seu script de regras iptables existente
|
||||||
|
|
||||||
|
# 3. Configurar QoS
|
||||||
|
echo "Configurando QoS..."
|
||||||
|
sh /root/qos.sh # Seu script QoS existente
|
||||||
|
|
||||||
|
echo "Implantação completa de proteção em três camadas (XDP, iptables, QoS)"
|
||||||
|
|
||||||
|
# 4. Testar conectividade WireGuard
|
||||||
|
echo "Verificando conectividade WireGuard..."
|
||||||
|
if systemctl is-active --quiet wg-quick@wg0; then
|
||||||
|
echo "Serviço WireGuard está rodando"
|
||||||
|
else
|
||||||
|
echo "AVISO: Serviço WireGuard parece estar parado, reiniciando..."
|
||||||
|
systemctl restart wg-quick@wg0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Informações adicionais
|
||||||
|
echo ""
|
||||||
|
echo "=== Informações do Programa XDP ==="
|
||||||
|
ip link show dev enp0s6 | grep xdp
|
||||||
+1
-5
@@ -165,11 +165,6 @@ static __always_inline int is_filtered_port(__u16 port) {
|
|||||||
return (port <= 1024);
|
return (port <= 1024);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Função otimizada para verificar se é porta WireGuard
|
|
||||||
static __always_inline int is_wireguard_traffic(__u8 protocol, __u16 port) {
|
|
||||||
return (protocol == IPPROTO_UDP && port == 32100);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Função para atualizar estatísticas de tráfego
|
// Função para atualizar estatísticas de tráfego
|
||||||
static __always_inline void update_stats(__u32 action, __u8 flags) {
|
static __always_inline void update_stats(__u32 action, __u8 flags) {
|
||||||
__u32 key = 0;
|
__u32 key = 0;
|
||||||
@@ -229,6 +224,7 @@ int xdp_ddos_filter(struct xdp_md *ctx) {
|
|||||||
struct udphdr *udp = (void *)(ip + 1);
|
struct udphdr *udp = (void *)(ip + 1);
|
||||||
if ((void *)(udp + 1) <= data_end) {
|
if ((void *)(udp + 1) <= data_end) {
|
||||||
__u16 dest_port = __constant_ntohs(udp->dest);
|
__u16 dest_port = __constant_ntohs(udp->dest);
|
||||||
|
|
||||||
if (dest_port == 32100) { // WireGuard port
|
if (dest_port == 32100) { // WireGuard port
|
||||||
// Permitir todo tráfego WireGuard sem verificação adicional
|
// Permitir todo tráfego WireGuard sem verificação adicional
|
||||||
update_stats(XDP_PASS, 0);
|
update_stats(XDP_PASS, 0);
|
||||||
|
|||||||
Reference in new issue
Block a user