tcp_timewait_input函数解析
来源:互联网 发布:js代码生成器 编辑:程序博客网 时间:2024/05/01 02:52
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函数。
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 voidtcp_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;}
阅读全文
0 0
- tcp_timewait_input函数解析
- 函数调用约定解析
- 函数解析字符串(ZT)
- setsockopt函数解析(转)
- ARX函数解析
- 成员函数重载解析
- js 函数深入解析
- Linux wait函数解析
- 函数调用约定解析
- 钩子函数解析
- 虚函数解析
- 函数表达式解析器
- PartitionMotionSearch()函数解析
- fcntl函数解析
- main函数参数解析
- json解析函数。
- 虚函数详细解析
- 虚析构函数解析
- 常见C++面试题及基本知识点总结(一)
- java跳出多重嵌套循环
- Linux搭建electron环境
- linux常用操作-2.用户管理
- 谈谈 DNS 原理及“域名劫持”和“域名欺骗/域名污染”
- tcp_timewait_input函数解析
- 匠人精神:默默修伞40年,留下了10000份温暖记忆
- 【codeforces 747C】Servers
- iOS资源大全中文版
- 开课十二天
- 洛朗级数与泰勒展开的区别
- 1013. Battle Over Cities (25)
- ffmpeg设置视频帧率
- POJ 2100 Graveyard Design 尺取法(滑动窗口)