doubt about the 3-way handshake

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



HI, guys :

The implement of the 3 way handshaking confuse me:

      This is what the tcp_v4_do_rcv() mainly do:

  1.     if (sk->sk_state == TCP_LISTEN) {
  2.         struct sock *nsk = tcp_v4_hnd_req(sk, skb);
  3.           ...
  4.         if (nsk != sk) {
  5.             if (tcp_child_process(sk, nsk, skb)) {
  6.               ...
  7.             }
  8.             return 0;
  9.         }
  10.     }
  11.    ...
  12.     if (tcp_rcv_state_process(sk, skb, skb-> h.th, skb->len)) {
  13.         ...
  14.     }
It seems that, if the server is in the LISTEN state, it execs the line 2, which is tcp_v4_hnd_req(sk, skb); , That is the function really confuse me:

  1. static struct sock *tcp_v4_hnd_req(struct sock *sk, struct sk_buff *skb)
  2. {
  3.     struct tcphdr *th = skb-> h.th;
  4.     struct iphdr *iph = skb->nh.iph;
  5.     struct sock *nsk;
  6.     struct request_sock **prev;
  7.     /* Find possible connection requests. */
  8.     struct request_sock *req = inet_csk_search_req(sk, &prev, th->source,
  9.                                iph->saddr, iph->daddr);
  10.     if (req)
  11.         return tcp_check_req(sk, skb, req, prev);
  12.     nsk = inet_lookup_established(&tcp_hashinfo, skb->nh.iph->saddr,
  13.                       th->source, skb-> nh.iph->daddr,
  14.                       th->dest, inet_iif(skb));
  15.     if (nsk) {
  16.         if (nsk->sk_state != TCP_TIME_WAIT) {
  17.             bh_lock_sock(nsk);
  18.             return nsk;
  19.         }
  20.         inet_twsk_put(inet_twsk(nsk));
  21.         return NULL;
  22.     }
  23. #ifdef CONFIG_SYN_COOKIES
  24.     if (!th->rst && !th->syn && th->ack)
  25.         sk = cookie_v4_check(sk, skb, &(IPCB(skb)->opt));
  26. #endif
  27.     return sk;
  28. }
Because the server  is running just now and at the LISTEN state, so  there is nothing in the listen queue's request_sock array. So the return value of the Line 8 -- inet_csk_search_req() should be NULL,  and then  the " return tcp_check_req(sk, skb, req, prev);" at Line 11 should NOT be executed. 
IS that Right?  Could you please explain this function for me? I am very grateful.

     R.wen

[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux