commit
This commit is contained in:
1 parent
0a94f772da
commit
296aec1afa
1 file changed
-35
@@ -43,16 +43,6 @@ struct {
|
|||||||
__type(value, __u16); // MTU conhecido
|
__type(value, __u16); // MTU conhecido
|
||||||
} path_mtu_map SEC(".maps");
|
} path_mtu_map SEC(".maps");
|
||||||
|
|
||||||
// Função para atualizar estatísticas
|
|
||||||
static __always_inline void update_stats(__u64 *stat_counter) {
|
|
||||||
__u32 key = 0;
|
|
||||||
struct mtu_stats *stats = bpf_map_lookup_elem(&mtu_stats_map, &key);
|
|
||||||
if (stats) {
|
|
||||||
stats->total_packets++;
|
|
||||||
(*stat_counter)++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Função para ajustar TCP MSS - totalmente reescrita para maior simplicidade
|
// Função para ajustar TCP MSS - totalmente reescrita para maior simplicidade
|
||||||
static __always_inline int adjust_tcp_mss(struct tcphdr *tcp, void *data_end, __u16 max_mss) {
|
static __always_inline int adjust_tcp_mss(struct tcphdr *tcp, void *data_end, __u16 max_mss) {
|
||||||
// Verificação básica do cabeçalho TCP
|
// Verificação básica do cabeçalho TCP
|
||||||
@@ -129,31 +119,6 @@ static __always_inline int adjust_tcp_mss(struct tcphdr *tcp, void *data_end, __
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Função para enviar ICMP "Fragmentation needed" para indicar Path MTU Discovery
|
|
||||||
static __always_inline int send_icmp_frag_needed(struct iphdr *iph, __u16 mtu) {
|
|
||||||
// Simplificado para evitar problemas de compilação
|
|
||||||
|
|
||||||
// Verificar se o pacote tem DF (Don't Fragment) ativo
|
|
||||||
__u16 frag_off = bpf_ntohs(iph->frag_off);
|
|
||||||
if ((frag_off & 0x4000) == 0) // Sem bit DF, pode fragmentar
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
// Registrar MTU conhecido para este destino
|
|
||||||
__u32 dest_ip = iph->daddr;
|
|
||||||
__u16 recommended_mtu = MAX_WG_MTU;
|
|
||||||
bpf_map_update_elem(&path_mtu_map, &dest_ip, &recommended_mtu, BPF_ANY);
|
|
||||||
|
|
||||||
// Incrementar contador de PMTU
|
|
||||||
__u32 zero = 0;
|
|
||||||
struct mtu_stats *stats = bpf_map_lookup_elem(&mtu_stats_map, &zero);
|
|
||||||
if (stats) {
|
|
||||||
stats->pmtu_triggered++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sinalizar ao kernel para dropar e enviar ICMP
|
|
||||||
return XDP_ABORTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Programa XDP principal - simplificado
|
// Programa XDP principal - simplificado
|
||||||
SEC("xdp")
|
SEC("xdp")
|
||||||
int xdp_wg_optimizer(struct xdp_md *ctx) {
|
int xdp_wg_optimizer(struct xdp_md *ctx) {
|
||||||
|
|||||||
Reference in new issue
Block a user