* TCP fast open question
@ 2014-03-08 11:58 Zheng Liu
2014-03-08 12:56 ` Zhi Yong Wu
2014-03-10 17:09 ` Yuchung Cheng
0 siblings, 2 replies; 5+ messages in thread
From: Zheng Liu @ 2014-03-08 11:58 UTC (permalink / raw)
To: netdev
Cc: Eric Dumazet, David S. Miller, Yuchung Cheng, Jerry Chu,
Xiaochen Wang, Zheng Liu
Hi all,
Now we are trying to use TCP fast open in our nginx server, and we
encounter a problem under non-blocking socket. I appreciate if some one
can reply this question. Thanks in advance.
I describe our question here. we have two machines, one is as server and
another is as client. 'net.ipv4.tcp_fastopen' on both of them are set to
3. The server program looks like below:
...
listenfd = socket(AF_INET, SOCK_STREAM, 0);
bind(listenfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
int tfo_opt = 1;
setsockopt(listenfd, SOL_TCP, TCP_LISTEN_INFO, &tfo_opt, sizeof(tfo_opt));
listen(listenfd, 5);
connfd = accept(listenfd, (struct sockaddr *)NULL, NULL);
recv(connfd, &buf, 4096)
...
The client program:
...
sockfd = socket(AF_INET, SOCK_STREAM, 0);
fcntl(sockfd, F_SETFL, fcntl(sockfd, F_GETFL, 0)|O_NONBLOCK);
sendto(sockfd, msg, strlen(msg), MSG_FASTOPEN,
(struct sockaddr *)&servaddr, sizeof(servaddr);
recv(sockfd, buf, 4096, 0);
...
We use a non-blocking socket to connect the server and send some
messages. After calling sendto(2) we always get an EINPROGRESS error.
We think it is reasonable because connect(2) could also return this
error with a non-blocking socket and the connection will be established
later. The question is *whether or not the data will be sent* after the
connection is established. If I understand correctly, sendto(2) will
return the number of bytes of data queued up in the kernel or sent in
the SYN packet. Even though the EINPROGRESS is returned. If sendto(2)
returns -1, that means that no data is queued up in kernel or sent in
the packet. Please correct me if I miss-understand something.
We run the program in our testing environment, and we use tcpdump(1) to
capture the packets. From the result we can see there is no any data
that is sent. Then we do another testing that after calling sendto(2)
the client program will sleep for 5 seconds and then call send(2) to
transfer some data.
$ ./client xx.xx.xx.xx
ret -1 errno 115
The program works well. So that means that after getting a EINPROGRESS
error, the program must call send(2) manually. Is it correct? If we
want to avoid this problem, we need to set 'net.ipv4.tcp_fastopen' to
0x707 ?
Regards,
- Zheng
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: TCP fast open question
2014-03-08 11:58 TCP fast open question Zheng Liu
@ 2014-03-08 12:56 ` Zhi Yong Wu
2014-03-08 14:47 ` gnehzuil.liu
2014-03-10 17:09 ` Yuchung Cheng
1 sibling, 1 reply; 5+ messages in thread
From: Zhi Yong Wu @ 2014-03-08 12:56 UTC (permalink / raw)
To: Zheng Liu
Cc: Linux Netdev List, Eric Dumazet, David S. Miller, Yuchung Cheng,
Jerry Chu, Xiaochen Wang, Zheng Liu
On Sat, Mar 8, 2014 at 7:58 PM, Zheng Liu <gnehzuil.liu@gmail.com> wrote:
> Hi all,
>
> Now we are trying to use TCP fast open in our nginx server, and we
> encounter a problem under non-blocking socket. I appreciate if some one
> can reply this question. Thanks in advance.
>
> I describe our question here. we have two machines, one is as server and
> another is as client. 'net.ipv4.tcp_fastopen' on both of them are set to
> 3. The server program looks like below:
>
> ...
> listenfd = socket(AF_INET, SOCK_STREAM, 0);
> bind(listenfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
> int tfo_opt = 1;
> setsockopt(listenfd, SOL_TCP, TCP_LISTEN_INFO, &tfo_opt, sizeof(tfo_opt));
s/TCP_LISTEN_INFO/TCP_FASTOPEN/??
> listen(listenfd, 5);
> connfd = accept(listenfd, (struct sockaddr *)NULL, NULL);
> recv(connfd, &buf, 4096)
> ...
>
> The client program:
>
> ...
> sockfd = socket(AF_INET, SOCK_STREAM, 0);
> fcntl(sockfd, F_SETFL, fcntl(sockfd, F_GETFL, 0)|O_NONBLOCK);
> sendto(sockfd, msg, strlen(msg), MSG_FASTOPEN,
> (struct sockaddr *)&servaddr, sizeof(servaddr);
> recv(sockfd, buf, 4096, 0);
> ...
>
> We use a non-blocking socket to connect the server and send some
> messages. After calling sendto(2) we always get an EINPROGRESS error.
> We think it is reasonable because connect(2) could also return this
> error with a non-blocking socket and the connection will be established
> later. The question is *whether or not the data will be sent* after the
> connection is established. If I understand correctly, sendto(2) will
> return the number of bytes of data queued up in the kernel or sent in
> the SYN packet. Even though the EINPROGRESS is returned. If sendto(2)
> returns -1, that means that no data is queued up in kernel or sent in
> the packet. Please correct me if I miss-understand something.
>
> We run the program in our testing environment, and we use tcpdump(1) to
> capture the packets. From the result we can see there is no any data
> that is sent. Then we do another testing that after calling sendto(2)
> the client program will sleep for 5 seconds and then call send(2) to
> transfer some data.
>
> $ ./client xx.xx.xx.xx
> ret -1 errno 115
>
> The program works well. So that means that after getting a EINPROGRESS
> error, the program must call send(2) manually. Is it correct? If we
> want to avoid this problem, we need to set 'net.ipv4.tcp_fastopen' to
> 0x707 ?
>
> Regards,
> - Zheng
> --
> To unsubscribe from this list: send the line "unsubscribe netdev" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
--
Regards,
Zhi Yong Wu
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: TCP fast open question
2014-03-08 12:56 ` Zhi Yong Wu
@ 2014-03-08 14:47 ` gnehzuil.liu
0 siblings, 0 replies; 5+ messages in thread
From: gnehzuil.liu @ 2014-03-08 14:47 UTC (permalink / raw)
To: Zhi Yong Wu
Cc: Linux Netdev List, Eric Dumazet, David S. Miller, Yuchung Cheng,
Jerry Chu, Xiaochen Wang, Zheng Liu
> 在 2014年3月8日,下午8:56,Zhi Yong Wu <zwu.kernel@gmail.com> 写道:
>
>> On Sat, Mar 8, 2014 at 7:58 PM, Zheng Liu <gnehzuil.liu@gmail.com> wrote:
>> Hi all,
>>
>> Now we are trying to use TCP fast open in our nginx server, and we
>> encounter a problem under non-blocking socket. I appreciate if some one
>> can reply this question. Thanks in advance.
>>
>> I describe our question here. we have two machines, one is as server and
>> another is as client. 'net.ipv4.tcp_fastopen' on both of them are set to
>> 3. The server program looks like below:
>>
>> ...
>> listenfd = socket(AF_INET, SOCK_STREAM, 0);
>> bind(listenfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
>> int tfo_opt = 1;
>> setsockopt(listenfd, SOL_TCP, TCP_LISTEN_INFO, &tfo_opt, sizeof(tfo_opt));
> s/TCP_LISTEN_INFO/TCP_FASTOPEN/??
Sigh! Yes, it's a typo. Thanks for pointing it out.
Regards,
- Zheng
>> listen(listenfd, 5);
>> connfd = accept(listenfd, (struct sockaddr *)NULL, NULL);
>> recv(connfd, &buf, 4096)
>> ...
>>
>> The client program:
>>
>> ...
>> sockfd = socket(AF_INET, SOCK_STREAM, 0);
>> fcntl(sockfd, F_SETFL, fcntl(sockfd, F_GETFL, 0)|O_NONBLOCK);
>> sendto(sockfd, msg, strlen(msg), MSG_FASTOPEN,
>> (struct sockaddr *)&servaddr, sizeof(servaddr);
>> recv(sockfd, buf, 4096, 0);
>> ...
>>
>> We use a non-blocking socket to connect the server and send some
>> messages. After calling sendto(2) we always get an EINPROGRESS error.
>> We think it is reasonable because connect(2) could also return this
>> error with a non-blocking socket and the connection will be established
>> later. The question is *whether or not the data will be sent* after the
>> connection is established. If I understand correctly, sendto(2) will
>> return the number of bytes of data queued up in the kernel or sent in
>> the SYN packet. Even though the EINPROGRESS is returned. If sendto(2)
>> returns -1, that means that no data is queued up in kernel or sent in
>> the packet. Please correct me if I miss-understand something.
>>
>> We run the program in our testing environment, and we use tcpdump(1) to
>> capture the packets. From the result we can see there is no any data
>> that is sent. Then we do another testing that after calling sendto(2)
>> the client program will sleep for 5 seconds and then call send(2) to
>> transfer some data.
>>
>> $ ./client xx.xx.xx.xx
>> ret -1 errno 115
>>
>> The program works well. So that means that after getting a EINPROGRESS
>> error, the program must call send(2) manually. Is it correct? If we
>> want to avoid this problem, we need to set 'net.ipv4.tcp_fastopen' to
>> 0x707 ?
>>
>> Regards,
>> - Zheng
>> --
>> To unsubscribe from this list: send the line "unsubscribe netdev" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
>
>
> --
> Regards,
>
> Zhi Yong Wu
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: TCP fast open question
2014-03-08 11:58 TCP fast open question Zheng Liu
2014-03-08 12:56 ` Zhi Yong Wu
@ 2014-03-10 17:09 ` Yuchung Cheng
2014-03-16 5:57 ` Zheng Liu
1 sibling, 1 reply; 5+ messages in thread
From: Yuchung Cheng @ 2014-03-10 17:09 UTC (permalink / raw)
To: Zheng Liu
Cc: netdev, Eric Dumazet, David S. Miller, Jerry Chu, Xiaochen Wang,
Zheng Liu
On Sat, Mar 8, 2014 at 3:58 AM, Zheng Liu <gnehzuil.liu@gmail.com> wrote:
> Hi all,
>
> Now we are trying to use TCP fast open in our nginx server, and we
> encounter a problem under non-blocking socket. I appreciate if some one
> can reply this question. Thanks in advance.
>
> I describe our question here. we have two machines, one is as server and
> another is as client. 'net.ipv4.tcp_fastopen' on both of them are set to
> 3. The server program looks like below:
>
> ...
> listenfd = socket(AF_INET, SOCK_STREAM, 0);
> bind(listenfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
> int tfo_opt = 1;
> setsockopt(listenfd, SOL_TCP, TCP_LISTEN_INFO, &tfo_opt, sizeof(tfo_opt));
> listen(listenfd, 5);
> connfd = accept(listenfd, (struct sockaddr *)NULL, NULL);
> recv(connfd, &buf, 4096)
> ...
>
> The client program:
>
> ...
> sockfd = socket(AF_INET, SOCK_STREAM, 0);
> fcntl(sockfd, F_SETFL, fcntl(sockfd, F_GETFL, 0)|O_NONBLOCK);
> sendto(sockfd, msg, strlen(msg), MSG_FASTOPEN,
> (struct sockaddr *)&servaddr, sizeof(servaddr);
> recv(sockfd, buf, 4096, 0);
> ...
>
> We use a non-blocking socket to connect the server and send some
> messages. After calling sendto(2) we always get an EINPROGRESS error.
> We think it is reasonable because connect(2) could also return this
> error with a non-blocking socket and the connection will be established
> later. The question is *whether or not the data will be sent* after the
> connection is established. If I understand correctly, sendto(2) will
> return the number of bytes of data queued up in the kernel or sent in
> the SYN packet. Even though the EINPROGRESS is returned. If sendto(2)
> returns -1, that means that no data is queued up in kernel or sent in
> the packet. Please correct me if I miss-understand something.
Correct.
http://tools.ietf.org/html/draft-ietf-tcpm-fastopen-07#appendix-A.1
>
> We run the program in our testing environment, and we use tcpdump(1) to
> capture the packets. From the result we can see there is no any data
> that is sent. Then we do another testing that after calling sendto(2)
The first handshake is used to get the Fast Open cookie for future
connections. I suspect you didn't enable Fast Open on the server side.
What're the output of 'sysctl net.ipv4.tcp_fastopen' on your client
and server? pls send the tcpdump traces on both sides as well.
> the client program will sleep for 5 seconds and then call send(2) to
> transfer some data.
>
> $ ./client xx.xx.xx.xx
> ret -1 errno 115
>
> The program works well. So that means that after getting a EINPROGRESS
> error, the program must call send(2) manually. Is it correct? If we
> want to avoid this problem, we need to set 'net.ipv4.tcp_fastopen' to
> 0x707 ?
>
> Regards,
> - Zheng
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: TCP fast open question
2014-03-10 17:09 ` Yuchung Cheng
@ 2014-03-16 5:57 ` Zheng Liu
0 siblings, 0 replies; 5+ messages in thread
From: Zheng Liu @ 2014-03-16 5:57 UTC (permalink / raw)
To: Yuchung Cheng
Cc: netdev, Eric Dumazet, David S. Miller, Jerry Chu, Xiaochen Wang,
Zheng Liu
Hi Yuchung,
Sorry for the late reply because of an urgent issue.
On Mon, Mar 10, 2014 at 10:09:06AM -0700, Yuchung Cheng wrote:
> On Sat, Mar 8, 2014 at 3:58 AM, Zheng Liu <gnehzuil.liu@gmail.com> wrote:
> > Hi all,
> >
> > Now we are trying to use TCP fast open in our nginx server, and we
> > encounter a problem under non-blocking socket. I appreciate if some one
> > can reply this question. Thanks in advance.
> >
> > I describe our question here. we have two machines, one is as server and
> > another is as client. 'net.ipv4.tcp_fastopen' on both of them are set to
> > 3. The server program looks like below:
> >
> > ...
> > listenfd = socket(AF_INET, SOCK_STREAM, 0);
> > bind(listenfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
> > int tfo_opt = 1;
> > setsockopt(listenfd, SOL_TCP, TCP_LISTEN_INFO, &tfo_opt, sizeof(tfo_opt));
> > listen(listenfd, 5);
> > connfd = accept(listenfd, (struct sockaddr *)NULL, NULL);
> > recv(connfd, &buf, 4096)
> > ...
> >
> > The client program:
> >
> > ...
> > sockfd = socket(AF_INET, SOCK_STREAM, 0);
> > fcntl(sockfd, F_SETFL, fcntl(sockfd, F_GETFL, 0)|O_NONBLOCK);
> > sendto(sockfd, msg, strlen(msg), MSG_FASTOPEN,
> > (struct sockaddr *)&servaddr, sizeof(servaddr);
> > recv(sockfd, buf, 4096, 0);
> > ...
> >
> > We use a non-blocking socket to connect the server and send some
> > messages. After calling sendto(2) we always get an EINPROGRESS error.
> > We think it is reasonable because connect(2) could also return this
> > error with a non-blocking socket and the connection will be established
> > later. The question is *whether or not the data will be sent* after the
> > connection is established. If I understand correctly, sendto(2) will
> > return the number of bytes of data queued up in the kernel or sent in
> > the SYN packet. Even though the EINPROGRESS is returned. If sendto(2)
> > returns -1, that means that no data is queued up in kernel or sent in
> > the packet. Please correct me if I miss-understand something.
> Correct.
> http://tools.ietf.org/html/draft-ietf-tcpm-fastopen-07#appendix-A.1
>
> >
> > We run the program in our testing environment, and we use tcpdump(1) to
> > capture the packets. From the result we can see there is no any data
> > that is sent. Then we do another testing that after calling sendto(2)
> The first handshake is used to get the Fast Open cookie for future
> connections. I suspect you didn't enable Fast Open on the server side.
> What're the output of 'sysctl net.ipv4.tcp_fastopen' on your client
> and server? pls send the tcpdump traces on both sides as well.
Sorry, let me clarify the description please. We can capture the syn
packet without data. So that means that client has issued a cookie
request. My question is when the data could be sent out.
Here I miss understand the behaviour when the program is the first time
to call sendto(2). As RFC draft of TFO described, sendto(2) will return
-1 with EINPROGRESS error if the cookie is not available locallly. That
means that we need to call write(2) to send the data after the connection
is established. Namely, after getting -1 with EINPROGRESS, the caller
must call write(2) again later. Now this problem has been solved.
Thanks for your help,
- Zheng
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-03-16 5:51 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-08 11:58 TCP fast open question Zheng Liu
2014-03-08 12:56 ` Zhi Yong Wu
2014-03-08 14:47 ` gnehzuil.liu
2014-03-10 17:09 ` Yuchung Cheng
2014-03-16 5:57 ` Zheng Liu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).