diff --git a/ebpf-sockmap/bpf/sockmap.bpf.c b/ebpf-sockmap/bpf/sockmap.bpf.c index 211fcdc..7024e8f 100644 --- a/ebpf-sockmap/bpf/sockmap.bpf.c +++ b/ebpf-sockmap/bpf/sockmap.bpf.c @@ -157,8 +157,13 @@ int bpf_sockops_handler(struct bpf_sock_ops *skops) struct sock_key key = {}; extract_key_from_ops(skops, &key); + // DEBUG TEMPORÁRIO — remover depois de confirmar o comportamento. + bpf_printk("REG op=%u sip=%x dip=%x", op, key.sip4, key.dip4); + bpf_printk("REG sport=%u dport=%u", key.sport, key.dport); + // BPF_ANY: atualiza mesmo se já existir (cobre reconexões keepalive) int ret = bpf_sock_hash_update(skops, &sock_hash, &key, BPF_ANY); + bpf_printk("REG update ret=%d", ret); if (ret == 0) { stats_inc(0); @@ -186,6 +191,8 @@ int bpf_sockops_handler(struct bpf_sock_ops *skops) new_state == BPF_TCP_TIME_WAIT) { struct sock_key key = {}; extract_key_from_ops(skops, &key); + // DEBUG TEMPORÁRIO + bpf_printk("DEL state=%u sport=%u dport=%u", new_state, key.sport, key.dport); bpf_map_delete_elem(&sock_hash, &key); } break; @@ -229,8 +236,13 @@ int bpf_msg_redirect(struct sk_msg_md *msg) key.dport = bpf_htonl(msg->local_port) >> 16; key.family = msg->family; + // DEBUG TEMPORÁRIO + bpf_printk("MSG sip=%x dip=%x", key.sip4, key.dip4); + bpf_printk("MSG sport=%u dport=%u size=%u", key.sport, key.dport, msg->size); + // Tenta redirecionar diretamente para o socket par. int ret = bpf_msg_redirect_hash(msg, &sock_hash, &key, BPF_F_INGRESS); + bpf_printk("MSG redirect ret=%d", ret); if (ret == SK_PASS) { stats_inc(1); // Redirecionamento OK — caminho acelerado return SK_PASS;