【LWIP】tcp

xiaoxiao2021-02-28  133

收录于:

【LWIP】LWIP协议|相关知识汇总|LWIP学习笔记


相关链接:

【LWIP】Ip4_input函数分析

——|【LWIP】pbuf_realloc函数分析

【LWIP】tcp_input()函数分析

——|【LWIP】tcp_timewait_input函数解析

——|【LWIP】tcp_listen_input函数分析

【LWIP】tcp_receive函数分析

【LWIP】udp_input函数分析


1.调用流程: 

    tcp_input接收IP层递交上来的数据包,获取TCP首部长度(包括选项部分),将p指针移向pbuf的有效数据部分,    根据TCP报头,遍历tcp_active_pcbs链表,tcp_tw_pcbs链表,tcp_listen_pcbs链表,查找相应TCP控制块,    若在tcp_tw_pcbs链表中匹配,调用tcp_timewait_input()


2.函数简析:

    tcp_timewait_input函数是处于TIMEWAIT状态的控制块处理输入报文的函数。


3.具体分析: 

    (在源码中有详细注释)    1.带有RST标志的报文直接返回;    2.带有SYN标志的报文,如果序号在接收窗口内,发送RST标志并返回;。    3.如果无SYN标志,有FIN标志的报文,记录tmr(其它各计数器都基于tmr的值来实现)( 重新启动两个MSL时间等待超时)。    4.如果报文中有数据,将当前控制块设为TF_ACK_NOW状态,调用tcp_output函数。


4.源码:

static void tcp_timewait_input(struct tcp_pcb *pcb) { /* RFC 1337: in TIME_WAIT, ignore RST and ACK FINs + any 'acceptable' segments */ /* RFC 793 3.9 Event Processing - Segment Arrives: * - first check sequence number - we skip that one in TIME_WAIT (always * acceptable since we only send ACKs) * - second check the RST bit (... return) */ /* 带有RST标志的报文直接返回 */ if (flags & TCP_RST) { return; } /* - 如果报文包含SYN标志,如果序号在接收窗口内,返回一个RST标志 */ if (flags & TCP_SYN) { /* If an incoming segment is not acceptable, an acknowledgment should be sent in reply */ if (TCP_SEQ_BETWEEN(seqno, pcb->rcv_nxt, pcb->rcv_nxt + pcb->rcv_wnd)) { /* If the SYN is in the window it is an error, send a reset */ tcp_rst(ackno, seqno + tcplen, ip_current_dest_addr(), ip_current_src_addr(), tcphdr->dest, tcphdr->src); return; } /* 如果报文包含FIN标志(无SYN标志) */ } else if (flags & TCP_FIN) { /* - eighth, check the FIN bit: Remain in the TIME-WAIT state. Restart the 2 MSL time-wait timeout.*/ pcb->tmr = tcp_ticks; } /* 如果报文中有数据 */ if ((tcplen > 0)) { /* Acknowledge data, FIN or out-of-window SYN */ pcb->flags |= TF_ACK_NOW; // 将当前控制块设为TF_ACK_NOW状态 /* TCP层的总输出函数,详见《tcp_output函数解析》 */ tcp_output(pcb); } return; }

 

转载请注明原文地址: https://www.6miu.com/read-45495.html

最新回复(0)