如何在MultipathTCP中使用快速开放机制



我想在MultipathTCP中使用快速打开机制。

有什么选择吗?

我试过这个:

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;

}

这似乎是正确的,但不起作用。你能帮我找到解决办法吗?非常感谢。

现有的方法可以做到这一点:

您需要应用补丁或使用内核功能(如果存在(。我在linux内核中应用了mptcp-fastopen的补丁。

这里发布了另一个解决方案:linux内核中的mptcp-fastopen,而不是使用msghdr。它是关于使用";sendto";与MSG_FASTOPEN:的功能

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

此外,在linux内核中的mptcp-fastopen中描述了另一个选项(替代方案(:

setsockopt(sock_fd, SOL_TCP, TCP_FASTOPEN_CONNECT, &enable, sizeof(enable)); 

最新更新