How do I know if sendto () with TCP Fast Open uses Fast Open?

I am writing a TCP client on a Linux 3.15 machine that can use TCP Fast Open:

status = sendto(sd, (const void *) data, data_len, MSG_FASTOPEN, (const struct sockaddr *) hostref->ai_addr, sizeof(struct sockaddr_in)); if (status < 0) { fprintf(stderr, "sendto: %s\n", strerror(errno)); exit(EXIT_FAILURE); } fprintf(stdout, "TFO connection successful to %s\n", text_of(hostref->ai_addr)); 

Using tcpdump, I can check the sending of the TCP Fast Open option and bypass the three-way handshake (tested with Google servers).

However, with servers that do not support TCP quick open, sendto still succeeds and the message "TFO connection successful" is displayed. Linux kernel code seems to revert to normal TCP if the server does not support TCP Fast Open (again, checked with tcpdump).

How do I know if my TCP Fast Open connection is used or not?

+5
source share
1 answer

Looking at the patch set that TCP added to quickly open in the Linux kernel, you noticed that no external indications were added that the quick scan was used.

You may indirectly notice certain cases when the quick opening was not used, and in some cases when the quick opening was definitely used.

A case in which you are sure that quick access has not been used is when the value of the TCPFastOpenActive counter has not increased in / proc / net / netstat after a successful sendto () connection:

 + if (tcp_transmit_skb(sk, syn_data, 0, sk->sk_allocation) == 0) { + NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPFASTOPENACTIVE); + goto done; + } 

The case that you are sure of a quick open was used when you have a non-blocking socket, you already have a fast open cookie, and sendto () does not return EINPROGRESS:

For a non-blocking socket, it returns the number of bytes in the queue (and is transmitted in the SYN data packet) if a cookie is available. If the cookie is not available, it passes a SYN packet without data with a Fast Open cookie request and returns -EINPROGRESS as connect ().

For the remaining case, i.e. you don’t have a cookie, but you were able to connect, and TCPFastOpenActive was increased, you cannot tell whether the quick open was used (the TCPFastOpenActive step was caused by the quick open) or if the fast open was not used (the TCPFastOpenActive value was not caused by the fast open).

http://kernelnewbies.org/Linux_3.6#head-ac78950a7b57d92d5835642926f0e147c680b99c

http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=cf60af03ca4e71134206809ea892e49b92a88896

http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/diff/net/ipv4/tcp_output.c?id=783237e8daf13481ee234997cbbbb823872ac388

+5
source

Source: https://habr.com/ru/post/1204206/


All Articles