tcp: fastopen: accept data/FIN present in SYNACK
Subsystems (3)
cover tcp: fastopen: accept data/FIN present in SYNACK
Implements RFC 7413 (TCP Fast Open) 4.2.2, accepting payload and/or FIN in SYNACK messages, and prepare removal of SYN flag in tcp_recvmsg()
Eric Dumazet (2):
tcp: fastopen: accept data/FIN present in SYNACK message
tcp: do not enqueue skb with SYN flag
include/net/tcp.h | 1 + net/ipv4/tcp.c | 8 ++++-- net/ipv4/tcp_fastopen.c | 67 +++++++++++++++++++++++++++---------------------- net/ipv4/tcp_input.c | 3 +++ 4 files changed, 47 insertions(+), 32 deletions(-)
Signature · 1 line
2.7.0.rc3.207.g0ac5344
PATCH 1/2 tcp: fastopen: accept data/FIN present in SYNACK message
RFC 7413 (TCP Fast Open) 4.2.2 states that the SYNACK message MAY include data and/or FIN
This patch adds support for the client side :
If we receive a SYNACK with payload or FIN, queue the skb instead of ignoring it.
Since we already support the same for SYN, we refactor the existing code and reuse it. Note we need to clone the skb, so this operation might fail under memory pressure.
Sara Dickinson pointed out FreeBSD server Fast Open implementation was planned to generate such SYNACK in the future.
The server side might be implemented on linux later.
--- include/net/tcp.h | 1 + net/ipv4/tcp_fastopen.c | 64 ++++++++++++++++++++++++++----------------------- net/ipv4/tcp_input.c | 3 +++ 3 files changed, 38 insertions(+), 30 deletions(-)
include/net/tcp.h +1 -0
@@ -1437,6 +1437,7 @@ void tcp_free_fastopen_req(struct tcp_sock *tp);extern struct tcp_fastopen_context __rcu *tcp_fastopen_ctx;int tcp_fastopen_reset_cipher (void *key,unsigned int len); +void tcp_fastopen_add_skb (struct sock *sk,struct sk_buff *skb); struct sock *tcp_try_fastopen(struct sock *sk, struct sk_buff *skb, struct request_sock *req, struct tcp_fastopen_cookie *foc,
net/ipv4/tcp_fastopen.c +34 -30
82 lines not on this page · raw message
net/ipv4/tcp_input.c +3 -0
@@ -5509,6 +5509,9 @@ static bool tcp_rcv_fastopen_synack(struct sock *sk, struct sk_buff *synack, tp->syn_data_acked = tp->syn_data;if (tp->syn_data_acked)NET_INC_STATS_BH (sock_net (sk),LINUX_MIB_TCPFASTOPENACTIVE ); + +tcp_fastopen_add_skb (sk, synack); +return false; }
Signature · 1 line
2.7.0.rc3.207.g0ac5344
PATCH 2/2 tcp: do not enqueue skb with SYN flag
In reply to Eric DumazetIf we remove the SYN flag from the skbs that tcp_fastopen_add_skb() places in socket receive queue, then we can remove the test that tcp_recvmsg() has to perform in fast path.
All we have to do is to adjust SEQ in the slow path.
For the moment, we place an unlikely() and output a message if we find an skb having SYN flag set.
Goal would be to get rid of the test completely.
--- net/ipv4/tcp.c | 8 ++++++-- net/ipv4/tcp_fastopen.c | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-)
net/ipv4/tcp.c +6 -2
@@ -1466,8 +1466,10 @@ static struct sk_buff *tcp_recv_skb(struct sock *sk, u32 seq, u32 *off)while ((skb =skb_peek (&sk->sk_receive_queue)) !=NULL ) { offset = seq -TCP_SKB_CB (skb)->seq; -if (TCP_SKB_CB (skb)->tcp_flags &TCPHDR_SYN ) +if (unlikely (TCP_SKB_CB (skb)->tcp_flags &TCPHDR_SYN )) { +pr_err_once ("%s: found a SYN, please report !\n" , __func__); offset--; + }if (offset < skb->len || (TCP_SKB_CB (skb)->tcp_flags &TCPHDR_FIN )) { *off = offset;return skb;
@@ -1657,8 +1659,10 @@ int tcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, int nonblock,break ; offset = *seq -TCP_SKB_CB (skb)->seq; -if (TCP_SKB_CB (skb)->tcp_flags &TCPHDR_SYN ) +if (unlikely (TCP_SKB_CB (skb)->tcp_flags &TCPHDR_SYN )) { +pr_err_once ("%s: found a SYN, please report !\n" , __func__); offset--; + }if (offset < skb->len) goto found_ok_skb;if (TCP_SKB_CB (skb)->tcp_flags &TCPHDR_FIN )
net/ipv4/tcp_fastopen.c +3 -0
@@ -143,6 +143,9 @@ void tcp_fastopen_add_skb(struct sock *sk, struct sk_buff *skb)__skb_pull (skb,tcp_hdrlen (skb));skb_set_owner_r (skb, sk); +TCP_SKB_CB (skb)->seq++; +TCP_SKB_CB (skb)->tcp_flags &= ~TCPHDR_SYN ; + tp->rcv_nxt =TCP_SKB_CB (skb)->end_seq;__skb_queue_tail (&sk->sk_receive_queue, skb); tp->syn_data_acked =1 ;
Signature · 1 line
2.7.0.rc3.207.g0ac5344
David Miller
maintainerFrom: Eric Dumazet <[email protected]>
Date: Mon, 1 Feb 2016 21:03:06 -0800
Quoted 2 lines
Implements RFC 7413 (TCP Fast Open) 4.2.2, accepting payload and/or FIN in SYNACK messages, and prepare removal of SYN flag in
tcp_recvmsg()
Series applied, thanks Eric.
Quoted 7 lines · David Miller
From: Eric Dumazet <[email protected]>
Date: Mon, 1 Feb 2016 21:03:06 -0800Quoted 2 lines
Implements RFC 7413 (TCP Fast Open) 4.2.2, accepting payload and/or FIN in SYNACK messages, and prepare removal of SYN flag in
tcp_recvmsg()Series applied, thanks Eric.
It seems I missed to call tcp_fin() if a FIN flag was present.
(But then we had this issue before my patches, Yuchung, for a SYN packet
+ FIN ?)
I will send a followup.
Thanks David.
PATCH 1/1 tcp: fastopen: call tcp_fin() if FIN present in SYNACK
From: Eric Dumazet <[email protected]>
When we acknowledge a FIN, it is not enough to ack the sequence number and queue the skb into receive queue. We also have to call tcp_fin() to properly update socket state and send proper poll() notifications.
It seems we also had the problem if we received a SYN packet with the FIN flag set, but it does not seem an urgent issue, as no known implementation can do that.
--- include/net/tcp.h | 1 + net/ipv4/tcp_fastopen.c | 3 +++ net/ipv4/tcp_input.c | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-)
include/net/tcp.h +1 -0
@@ -568,6 +568,7 @@ void tcp_rearm_rto(struct sock *sk);void tcp_synack_rtt_meas (struct sock *sk,struct request_sock *req);void tcp_reset (struct sock *sk);void tcp_skb_mark_lost_uncond_verify (struct tcp_sock *tp,struct sk_buff *skb); +void tcp_fin (struct sock *sk);/* tcp_timer.c */ void tcp_init_xmit_timers (struct sock *);
net/ipv4/tcp_fastopen.c +3 -0
@@ -154,6 +154,9 @@ void tcp_fastopen_add_skb(struct sock *sk, struct sk_buff *skb)* as we certainly are not changing upper 32bit value (0) */ tp->bytes_received = skb->len; + +if (TCP_SKB_CB (skb)->tcp_flags &TCPHDR_FIN ) +tcp_fin (sk); } static struct sock *tcp_fastopen_create_child(struct sock *sk,
net/ipv4/tcp_input.c +1 -1
@@ -3995,7 +3995,7 @@ void tcp_reset(struct sock *sk)* * If we are in FINWAIT-2, a received FIN moves us to TIME-WAIT. */ -static void tcp_fin (struct sock *sk) +void tcp_fin (struct sock *sk) {struct tcp_sock *tp =tcp_sk (sk);
Re: [PATCH net-next] tcp: fastopen: call tcp_fin() if FIN present in SYNACK
From: Eric Dumazet <[email protected]>
Date: Sat, 06 Feb 2016 11:16:28 -0800
Quoted 6 lines
From: Eric Dumazet <[email protected]>
When we acknowledge a FIN, it is not enough to ack the sequence number and queue the skb into receive queue. We also have to call
tcp_fin()to properly update socket state and send properpoll()notifications.
Quoted 6 lines
It seems we also had the problem if we received a SYN packet with the FIN flag set, but it does not seem an urgent issue, as no known implementation can do that.
Fixes 61d2bcae99f6 ("tcp: fastopen: accept data/FIN present in SYNACK message")Signed-off-by Eric Dumazet <[email protected]>
Applied, thanks.