0

I would like to use Fast Open Mechanism with MultipathTCP.

Are there any options to do that?

I tried this:

int main(int argc, char *argv[])
{

...

struct msghdr        msgh;  
memset(&msgh, 0, sizeof(msgh));
struct cmsghdr *cmsg;

    unsigned char buffer[1] = "X";
    int size = 3;   

    struct sockaddr_in dst;
memset(&dst,0,sizeof(dst));
    inet_pton(AF_INET, "127.0.0.1", &dst.sin_addr);
    dst.sin_family = AF_INET;
dst.sin_port = htons(PORT);
                          


/* Construct control information */
struct iovec msgiov = {};   

struct unp_in_pktinfo {
  struct in_addr  ipi_addr;     /* destination IPv4 address */
  int             ipi_ifindex;  /* received interface index */
};
        


msgh.msg_name = &dst;
msgh.msg_namelen = sizeof(struct sockaddr_in);
msgiov.iov_base = buffer;
msgiov.iov_len = size;
msgh.msg_iov = &msgiov;
msgh.msg_iovlen = 1;
unsigned char control_buf[CMSG_LEN(sizeof(struct unp_in_pktinfo))] = {};
msgh.msg_control = &control_buf;
msgh.msg_controllen = CMSG_LEN(sizeof(struct unp_in_pktinfo));

cmsg = CMSG_FIRSTHDR(&msgh);
cmsg->cmsg_level = IPPROTO_IP;
cmsg->cmsg_type = IP_PKTINFO;
cmsg->cmsg_len =  CMSG_LEN(sizeof(struct in_pktinfo));
memcpy((struct in_addr *)CMSG_DATA(cmsg), &(dst.sin_addr),
        sizeof(dst.sin_addr));
cmsg = (struct cmsghdr *)((caddr_t) cmsg + CMSG_ALIGN(cmsg->cmsg_len));

sock_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_MPTCP);
ret = sendmsg(sock_fd, &msgh, MSG_FASTOPEN);

close(sock_fd);
return EXIT_SUCCESS;

}

It seems to be correct, but It doesn't work. Could you please help me to find a solution? Thank you!

boomer
  • 35
  • 6

1 Answers1

0

There is existing approach to do that:

You need to apply the patch or use the kernel functionality (if exists). I applied patch from mptcp fastopen in linux kernel.

Instead of using msghdr, there is another solution posted here: mptcp fastopen in linux kernel. It is about using "sendto" fucntion with MSG_FASTOPEN:

ret = sendto(sock_fd, sendline, strlen(sendline), MSG_FASTOPEN,(struct sockaddr *) &daddr, sizeof(daddr));

Also the is another option (alternative) described in mptcp fastopen in linux kernel:

setsockopt(sock_fd, SOL_TCP, TCP_FASTOPEN_CONNECT, &enable, sizeof(enable)); 
boomer
  • 35
  • 6