The implement of the 3 way handshaking confuse me:
This is what the tcp_v4_do_rcv() mainly do:
- if (sk->sk_state == TCP_LISTEN) {
- struct sock *nsk = tcp_v4_hnd_req(sk, skb);
- ...
- if (nsk != sk) {
- if (tcp_child_process(sk, nsk, skb)) {
- ...
- }
- return 0;
- }
- }
- ...
- if (tcp_rcv_state_process(sk, skb, skb-> h.th, skb->len)) {
- ...
-
}
- static struct sock *tcp_v4_hnd_req(struct sock *sk, struct sk_buff *skb)
- {
- struct tcphdr *th = skb-> h.th;
- struct iphdr *iph = skb->nh.iph;
- struct sock *nsk;
- struct request_sock **prev;
- /* Find possible connection requests. */
- struct request_sock *req = inet_csk_search_req(sk, &prev, th->source,
- iph->saddr, iph->daddr);
- if (req)
- return tcp_check_req(sk, skb, req, prev);
- nsk = inet_lookup_established(&tcp_hashinfo, skb->nh.iph->saddr,
- th->source, skb-> nh.iph->daddr,
- th->dest, inet_iif(skb));
- if (nsk) {
- if (nsk->sk_state != TCP_TIME_WAIT) {
- bh_lock_sock(nsk);
- return nsk;
- }
- inet_twsk_put(inet_twsk(nsk));
- return NULL;
- }
- #ifdef CONFIG_SYN_COOKIES
- if (!th->rst && !th->syn && th->ack)
- sk = cookie_v4_check(sk, skb, &(IPCB(skb)->opt));
- #endif
- return sk;
- }
IS that Right? Could you please explain this function for me? I am very grateful.
R.wen