제목 : TCP Input. 2005. 6. 13( 월 ) 한 민 규 [email protected] Introduction Preliminary Processing Header Prediction ACK Processing. Content. Introduction. The tcp_input function is called by ipintr when a datagram is received with a protocol field of TCP. Introduction (Con’t).
If the number of bytes in the first mbuf in the chain is less than the size of the combined IP/TCP header(40bytes), m_pullup moves the first 40 bytes into thefirst mbuf.
Convert data pointer of tcpiphdr *
tcp statistic value
tlen is the TCP length, the number of bytes following the IP header
Dataoffset : 4bit로 구성된 dataoffset 항목은 32bit word.
즉 한 bit가 4byte를 나타내어 TCP 헤더의 전체 길이를 표시한다.
The benefit in recognizing the timestamp optionthis way is to avoid calling the general option processing function
tcp_dooptions later in the code
If all three conditions are true,
ts_present is set to 1
The two 16-bit port numbers are left in network byte order
TCP maintains a one-behind cache(tcp_last_inpcb) conaining the address of the PCB for the last recevied TCP segment
If the PCB was not found, the input segment is dropped and an RST is sent as a reply
IF the PCB exists but a corresponding TCP control block does not exist, the socket is probably being closed, so the input segment is dropped and an RST is sent as a reply
tcp_saveti : These become arguments to tcp_trace when it is called at the end of the function
Socket has had listen()
When a segment arrives for a listening socket , a new socket is created by sonewconn
Compute window scale factor
RFC793 window size 16bit : 64k extend
(scale option with SYN)
t_idle is set to 0 since a segment has been received on the connection. The keep-alive timer is also reset to 2hours
If options are present in the TCP header, and if the connection state is not LISTEN, tcp_dooptions processes the options
If the length is not 4(TCPOLEN_MAXSEG), or the segment does not have the SYN flag set, the option is ignored
Window scale Option
1. Check if segment is the next expected
The connection state musth be ESTABLISHED
SYN,FIN,RST, or URG control flags must not be on
ts_val > ts_recent
tiwin(adv window) must be nonzero
snd_nxt must equal the highest sequence number
2. If a timestamp option is present,
Update ts_recent from received timestamp
Update RTT estimators
Delete acknowledged bytes from send buffer
Stop retransmit timer ???
Awaken waiting process :
If a process must be awakened when the send buffer is modified
We continue with the code that’s executed if header prediction fails, the slow path through tcp_input.
win is set to he number of bytes available in the socket’s receive buffer
Receive window setting
If the state is LISTEN or SYN_SENT, expected segment in these two states is a SYN, and we’ll see that any other received segment is dropped
Drop if RST, ACK, or no SYN
TCP is defined only for unicast applications. Recall that the M_BCAST and M_MCAST flags wre set by ether_input, based on the destination hardware address of the frame
Initialize sequence number variables in control block
TCP is expecting to receive a SYN
Acceptable ACK and RST
This normally ocuurs when the other end did not receive our ACK, causing the other end to retransmit the segment.
Set congestion window
Number of consecutive duplicate ACKS exceeds threshold of 3
Congestion window reset
Check for out-of-range ACK (Acceptable ACK)
Base on Delayed-ACK
ts_ecr : timestamp echo reply
needoutput : 1
This flag forces a call to tcp_output at the end of this function
/* actual chars in buffer */
Reomve from the send buffer
한쪽 호스트에서 연결 종료과정 초기의 FIN-ACK 세그먼트가 전송된 상태
FIN-ACK가 수신되었지만 이에 대한 ACK는 전송되지 않은상태. Simultaneous close 상태
수신된 FIN-ACK에 대한 ACK의 전송
양 호스트의 TCP가 FIN-ACK와 이에 대한 응답을 교환하고 TCP 연결종료 과정을 마무리한 상태. 이 상태가 되면 Maximum segment lifetime(Default 120초)의 두배의 시간동안 기다렸다가 해당 연결의 포트번호를 다시 사용할 수 있다.
Needoutput is set to 1 since the new value of snd_wnd
might enable a segment to be sent
A new urgent pointer has been received
/* can't receive more data from peer */