KindlingProject / kindling

eBPF-based Cloud Native Monitoring Tool
http://kindling.harmonycloud.cn
Apache License 2.0
1.12k stars 181 forks source link

tcp_retransmit statistics Error In higher than 4.7 of kernel version #214

Closed jundizhou closed 1 year ago

jundizhou commented 2 years ago

Describe the bug tcp_retransmit statistics Error In higher than 4.7 of kernel version

Higher than 4.7 source code

int tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb, int segs)
{
    struct tcp_sock *tp = tcp_sk(sk);
    int err = __tcp_retransmit_skb(sk, skb, segs);

    if (err == 0) {
#if FASTRETRANS_DEBUG > 0
        if (TCP_SKB_CB(skb)->sacked & TCPCB_SACKED_RETRANS) {
            net_dbg_ratelimited("retrans_out leaked\n");
        }
#endif
        TCP_SKB_CB(skb)->sacked |= TCPCB_RETRANS;
        tp->retrans_out += tcp_skb_pcount(skb);

        /* Save stamp of the first retransmit. */
        if (!tp->retrans_stamp)
            tp->retrans_stamp = tcp_skb_timestamp(skb);

    }

    if (tp->undo_retrans < 0)
        tp->undo_retrans = 0;
    tp->undo_retrans += tcp_skb_pcount(skb);
    return err;
}

Lower than 4.7 source code

int tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb)
{
    struct tcp_sock *tp = tcp_sk(sk);
    int err = __tcp_retransmit_skb(sk, skb);

    if (err == 0) {
        /* Update global TCP statistics. */
        TCP_INC_STATS(sock_net(sk), TCP_MIB_RETRANSSEGS);

        tp->total_retrans++;

#if FASTRETRANS_DEBUG > 0
        if (TCP_SKB_CB(skb)->sacked & TCPCB_SACKED_RETRANS) {
            net_dbg_ratelimited("retrans_out leaked\n");
        }
#endif
        if (!tp->retrans_out)
            tp->lost_retrans_low = tp->snd_nxt;
        TCP_SKB_CB(skb)->sacked |= TCPCB_RETRANS;
        tp->retrans_out += tcp_skb_pcount(skb);

        /* Save stamp of the first retransmit. */
        if (!tp->retrans_stamp)
            tp->retrans_stamp = TCP_SKB_CB(skb)->when;

        tp->undo_retrans += tcp_skb_pcount(skb);

        /* snd_nxt is stored to detect loss of retransmitted segment,
         * see tcp_input.c tcp_sacktag_write_queue().
         */
        TCP_SKB_CB(skb)->ack_seq = tp->snd_nxt;
    }
    return err;
}

Why the bug In higher than 4.7, SEGS parameter represents the number of packet losses, which should be counted instead of 1

dxsup commented 1 year ago

Closed via #450