please show the code of fast retransmit of linux kernel
时间: 2023-12-30 08:02:56 浏览: 119
The fast retransmit algorithm in the Linux kernel TCP implementation can be found in the function `tcp_fastretrans_alert()` in the file `net/ipv4/tcp_input.c`:
```
static void tcp_fastretrans_alert(struct sock *sk, struct sk_buff *skb, int pkts_acked)
{
struct tcp_sock *tp = tcp_sk(sk);
struct tcp_sacktag_state sack_state;
u32 prior_snd_una = tp->snd_una;
int rexmit = 0;
if (tp->frto <= tcp_jiffies32 &&
!tcp_time_to_recover(sk, 0) &&
!tp->tlp_high_seq &&
tp->packets_out &&
tcp_packets_in_flight(tp) <= tp->ssthresh &&
!after(tp->snd_una, tp->high_seq)) {
/* F-RTO RFC5682 */
if (tcp_try_undo_recovery(sk)) {
/* F-RTO undo recovery successful */
tp->frto = 0;
return;
}
/* F-RTO undo recovery unsuccessful */
tcp_enter_frto(sk, skb);
goto out;
}
...
}
```
This function implements the Fast Retransmit algorithm, which is a mechanism used in TCP to detect packet loss and retransmit lost packets without waiting for a retransmission timeout. The algorithm works by detecting the receipt of three duplicate ACKs (i.e., three ACKs that acknowledge the same sequence number) and assuming that the missing packet is the one that was last transmitted before the three duplicates were received.
The `tcp_fastretrans_alert()` function checks whether the conditions for Fast Retransmit are met, and if so, it calls the `tcp_enter_frto()` function to initiate the retransmission. Otherwise, it continues with normal processing of the received ACK.
阅读全文