MPTCP Source Code Analysis (ii) establishing sub-paths

Source: Internet
Author: User
Tags hmac

Brief IntroductionMptcp after three handshake, the client and the server will exchange the address information, let the other side know each other's unused address information. Additional sub-paths can be established when the client knows the address of the server. The three-time handshake and the process of establishing a Subpath 1: Figure 1 for a detailed explanation of token, random number R, and HMAC (hash-based Message authentication Code) can be Read the bibliography [1]. kernel implementations of the MPTCP:Here we focus mainly on the effect of master sock on slave sock in the process of establishing a sub-path. When the client sends the first SYN to make a subpath, it calls Mptcp_init4_subsockets to create a new socket and the corresponding sock.
 "net/mptcp/mptcp_ipv4.c"Line328Of488328 intMptcp_init4_subsockets (structSock *meta_sk,Const structMPTCP_LOC4 *Loc,329                structMPTCP_REM4 *rem) the {331     structTcp_sock *TP;332     structSock *SK;333     structsockaddr_in loc_in, rem_in;334     structsocket sock;335     intUlid_size =0, ret;336337     /** First, create and prepare the new socket*/338339Sock.type = meta_sk->sk_socket->type;340Sock.state =ss_unconnected;341SOCK.WQ = meta_sk->sk_socket->Wq;342Sock.file = meta_sk->sk_socket->file;343Sock.ops =NULL;344345ret = Inet_create (sock_net (Meta_sk), &sock, Ipproto_tcp,1);346     if(Unlikely (Ret <0)) {347Mptcp_debug ("%s inet_create failed ret:%d\n", __func__, ret);348         returnret;349     } -351SK =sock.sk;352TP = Tcp_sk (SK);
View CodeThe No. 345 line of the function inet_create creates the socket and sock of the sub-path.
354     /*All subsockets need the Mptcp-lock-class*/355Lockdep_set_class_and_name (& SK)->sk_lock.slock, &meta_slock_key,"slock-af_inet-mptcp");356Lockdep_init_map (& SK)->sk_lock.dep_map,"sk_lock-af_inet-mptcp", &meta_key,0);357358     if(Mptcp_add_sock (Meta_sk, SK, loc->loc4_id, rem->rem4_id, Gfp_kernel))359         Gotoerror; the361Tp->mptcp->slave_sk =1;362Tp->mptcp->low_prio = loc->Low_prio;363 364     /*Initializing the timer for an MPTCP subflow*/365Setup_timer (&tp->mptcp->mptcp_ack_timer, Mptcp_ack_handler, unsignedLong) SK);
The Mptcp_add_sock of line No. 358 links the master sock with the sock of the subpath. The No. 361 line of the surface of this sock is slave subsock. Line No. 362 Sets whether this sub-path is an alternate path. Data is sent through an alternate subpath only if the path is now unavailable. The timer set in line No. 365 is used to re-send the last ACK to establish the subpath, and this is done to ensure that the hmac-a can be delivered.
368            369Ulid_size =sizeof(structsockaddr_in);370loc_in.sin_family =af_inet;371rem_in.sin_family =af_inet;372Loc_in.sin_port =0;373     if(rem->Port)374Rem_in.sin_port = rem->Port;375     Else376Rem_in.sin_port = Inet_sk (Meta_sk)Inet_dport;377LOC_IN.SIN_ADDR = loc->addr;378REM_IN.SIN_ADDR = rem->addr;379        380ret = Sock.ops->bind (&sock, (structSOCKADDR *) &loc_in, ulid_size);381     if(Ret <0) {382Mptcp_debug ("%s:mptcp Subsocket bind () failed, error%d\n",383__func__, ret);384         Gotoerror;385     }386387Mptcp_debug ("%s:token% #x pi%d src_addr:%pi4:%d dst_addr:%pi4:%d\n",388__func__, Tcp_sk (Meta_sk)->mpcb->Mptcp_loc_token,389Tp->mptcp->path_index, &Loc_in.sin_addr,390Ntohs (Loc_in.sin_port), &Rem_in.sin_addr,391Ntohs (Rem_in.sin_port));392393     if(Tcp_sk (Meta_sk)->mpcb->pm_ops->init_subsocket_v4)394Tcp_sk (Meta_sk)->mpcb->pm_ops->init_subsocket_v4 (SK, rem->addr);395396ret = Sock.ops->connect (&sock, (structSOCKADDR *) &rem_in,397ulid_size, o_nonblock);398     if(Ret <0&& ret! =-einprogress) {399Mptcp_debug ("%s:mptcp Subsocket Connect () failed, error%d\n", -__func__, ret);401         Gotoerror;402}
View CodeThe No. 380 line is to bind the socket of the sub-path to the address. Line NO. 396 This socket will call Tcp_v4_connect for the connection operation.
403404Sk_set_socket (SK, meta_sk->sk_socket);405SK-&GT;SK_WQ = meta_sk->Sk_wq;406407     return 0;408409Error:410     /*May happen if Mptcp_add_sock fails first*/411     if(!MPTCP (TP)) {412Tcp_close (SK,0);413}Else {414local_bh_disable ();415Mptcp_sub_force_close (SK);416local_bh_enable ();417     }418     returnret;419}
The No. 404 and 405 lines will connect the sub-path's SK to the master socket, because only the master socket is visible to the application, and the socket of the slave subsock is not visible. The following scenario is when the server receives a 1 ack/mp_join (hmac-a) packet, and the status is changed from SYN_RECV to established.                         The function's invocation relationship is as follows: TCP_V4_RCV = "TCP_V4_DO_RCV =" MPTCP_V4_DO_RCV = "tcp_v4_hnd_req = "Tcp_check_req =" Mptcp_check_req_child = " Mptcp_add_sock will establish a new sock in the function tcp_check_req. The main code is as follows:
"NET/IPV4/TCP_MINISOCKS.C"Line766Of872760     /*OK, ACK is valid, create big socket and761 * Feeds this segment to it. It'll repeat all762 * the tests. This SEGMENT must MOVE SOCKET TO763 * established state. If It'll be dropped after764 * sockets is created, wait for troubles.765*/766#ifdef CONFIG_MPTCP767     if(Mptcp (Tcp_sk (SK)))768         /*Mptcp:we Call the mptcp-specific syn_recv_sock*/769Child = Tcp_sk (SK)->mpcb->Syn_recv_sock (SK, SKB, req, NULL);770     Else771 #endif772Child = INET_CSK (SK)->icsk_af_ops->Syn_recv_sock (SK, SKB,773req, NULL);774775     if(Child = =NULL)776         GotoListen_overflow;
The No. 769 row will call Mptcp_syn_recv_sock and Tcp_v4_syn_recv_sock and Tcp_create_openreq_child to create a new sock and initialize it.  The functions Mptcp_check_req_child and Mptcp_add_sock associate this sock with the master sock and set the sock property Slave_sk to 1. Conclusion: 1. MPTCP uses token, random number R, and HMAC (hash-based message authentication Code) to exchange this information to ensure that the build subpath is correct.  2.sub Sock is based on Meta sock, only meta is visible to the application layer, and the remaining sub sock are not visible. Reference: [1] https://tools.ietf.org/html/rfc6824#section-3.2 question: 1. The function of the No. 394 line is unknown? 2. function MPTCP_V4_ADD_LSRR function?

MPTCP Source Code Analysis (ii) establishing sub-paths

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.