linux TCP超时重传

阅读: 评论:0

linux TCP超时重传

linux TCP超时重传

TCP超时重传是保证TCP可靠性传输的机制之一,当超时后仍没有收到应答报文,就重传数据包并设置超时时钟(超时时间一般增大到原超时时间2倍);直到收到应答报文或超过最大重试次数。


linux TCP超时重传是通过设置重传超时时钟icsk_retransmit_timer来实现的。
零窗探测超时时钟与重传超时时钟共用icsk_retransmit_timer,根据icsk_pending是ICSK_TIME_RETRANS、ICSK_TIME_PROBE0来判断是重传超时还是零窗探测超时。
只有当发送方被通告零窗,连接双方没有数据来往而使接收方无法通过ACK报文通告新窗口时,才使用零窗探测机制;所以重传队列中有重传包时,不会出现零窗探测,出现零窗时不能再发送新数据也就没有重传;所以零窗探测超时时钟与重传超时时钟可以共用icsk_retransmit_timer


I.超时处理函数

281 /*
282  *      The TCP retransmit timer.
283  */
284 
285 void tcp_retransmit_timer(struct sock *sk)
286 {
287         struct tcp_sock *tp = tcp_sk(sk);
288         struct inet_connection_sock *icsk = inet_csk(sk);
289 
290         if (!tp->packets_out)
291                 goto out;
292 
293         WARN_ON(tcp_write_queue_empty(sk));
294 
295         if (!tp->snd_wnd && !sock_flag(sk, SOCK_DEAD) &&
296             !((1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV))) {
297                 /* Receiver dastardly shrinks window. Our retransmits
298                  * become zero probes, but we should not timeout this
299                  * connection. If the socket is an orphan, time it out,
300                  * we cannot allow such beasts to hang infinitely.
301                  */
302 #ifdef TCP_DEBUG
303                 struct inet_sock *inet = inet_sk(sk);
304                 if (sk->sk_family == AF_INET) {
305                         LIMIT_NETDEBUG(KERN_DEBUG "TCP: Peer %pI4:%u/%u unexpectedly shrunk window %u:%u (repaired)n",
306                                &inet->daddr, ntohs(inet->dport),
307                                inet->num, tp->snd_una, tp->snd_nxt);
308                 }
309 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
310                 else if (sk->sk_family == AF_INET6) {
311                         struct ipv6_pinfo *np = inet6_sk(sk);
312                         LIMIT_NETDEBUG(KERN_DEBUG "TCP: Peer %pI6:%u/%u unexpectedly shrunk window %u:%u (repaired)n",
313                                &np->daddr, ntohs(inet->dport),
314                                inet->num, tp->snd_una, tp->snd_nxt);
315                 }
316 #endif
317 #endif
318                 if (tcp_time_stamp - tp->r

本文发布于:2024-02-02 20:25:11,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170687670946234.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:linux   TCP
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23