TCP Receive
Overview
Detail Flow (with code)
tcp_ipv4.c: Receive (tcp_v4_rcv function)
還記得skb與sock的關係吧?
int tcp_v4_rcv(struct sk_buff *skb)
{
struct sock *sk;
. . .
檢查sockets hash info,分析對應的sokk關係
有三種hash tables:
❑ Sockets that are fully connected.
❑ Sockets that are waiting for a connection (in the listen state).
❑ Sockets that are in the process of establishing a connection (using the three-way handshake discussed below).
sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
. . .
if (!sk)
goto no_tcp_socket;
檢查sock有沒有被一些apps占用
沒有就放到prequeue裡面,然後呼叫tcp_v4_do_rcv()做後續處理
如果有,放到backlog
if (!sock_owned_by_user(sk)) {
if (!tcp_prequeue(sk, skb))
ret = tcp_v4_do_rcv(sk, skb);
} else if (unlikely(sk_add_backlog(sk, skb,
sk->sk_rcvbuf + sk->sk_sndbuf))) {
bh_unlock_sock(sk);
NET_INC_STATS_BH(net, LINUX_MIB_TCPBACKLOGDROP);
goto discard_and_relse;
}
tcp_v4_do_rcv:
tcp_input.c
tcp_event_data_recv() : measuring the MSS and RTT
tcp_ack() : deals with incoming acks
- cleaning the retransmission queue
- marking the SACKed packets
- reacting to duplicate ACKs
- reordering detection
- reordering detection
- advancing congestion window