This commit is contained in:
rodrigo committed 2025-02-26 22:39:27 -03:00
1 parent 6d94766293
commit 824fffb2cf
3 files changed
+20 -2

No files matched your search

View File
Whitespace-only changes.
View File
Whitespace-only changes.
+20 -2
View File
@@ -165,6 +165,11 @@ 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;
@@ -219,13 +224,26 @@ int xdp_ddos_filter(struct xdp_md *ctx) {
return XDP_PASS; return XDP_PASS;
} }
// Fast path 3: Verificar IPs já confiáveis (hosts que já passaram por verificação) // Fast path 3: WireGuard - verificação prioritária para UDP porta 32100
if (ip->protocol == IPPROTO_UDP) {
struct udphdr *udp = (void *)(ip + 1);
if ((void *)(udp + 1) <= data_end) {
__u16 dest_port = __constant_ntohs(udp->dest);
if (dest_port == 32100) { // WireGuard port
// Permitir todo tráfego WireGuard sem verificação adicional
update_stats(XDP_PASS, 0);
return XDP_PASS;
}
}
}
// Fast path 4: Verificar IPs já confiáveis (hosts que já passaram por verificação)
__u8 *trusted = bpf_map_lookup_elem(&trusted_hosts_map, &src_ip); __u8 *trusted = bpf_map_lookup_elem(&trusted_hosts_map, &src_ip);
if (__builtin_expect(trusted != NULL && *trusted == 1, 0)) { if (__builtin_expect(trusted != NULL && *trusted == 1, 0)) {
return XDP_PASS; return XDP_PASS;
} }
// Fast path 4: Rejeitar IPs na blacklist // Fast path 5: Rejeitar IPs na blacklist
if (__builtin_expect(is_blacklisted(src_ip), 0)) { if (__builtin_expect(is_blacklisted(src_ip), 0)) {
update_stats(XDP_DROP, FLAG_MARKED_SUSPICIOUS); update_stats(XDP_DROP, FLAG_MARKED_SUSPICIOUS);
return XDP_DROP; return XDP_DROP;