Skip to content

Commit 0a672f7

Browse files
yuchungchengdavem330
authored andcommitted
tcp: improve fastopen icmp handling
If a fast open socket is already accepted by the user, it should be treated like a connected socket to record the ICMP error in sk_softerr, so the user can fetch it. Do that in both tcp_v4_err and tcp_v6_err. Also refactor the sequence window check to improve readability (e.g., there were two local variables named 'req'). Signed-off-by: Yuchung Cheng <[email protected]> Signed-off-by: Daniel Lee <[email protected]> Signed-off-by: Jerry Chu <[email protected]> Acked-by: Neal Cardwell <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 843f4a5 commit 0a672f7

File tree

2 files changed

+31
-26
lines changed

2 files changed

+31
-26
lines changed

net/ipv4/tcp_ipv4.c

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,8 @@ void tcp_v4_err(struct sk_buff *icmp_skb, u32 info)
336336
const int code = icmp_hdr(icmp_skb)->code;
337337
struct sock *sk;
338338
struct sk_buff *skb;
339-
struct request_sock *req;
340-
__u32 seq;
339+
struct request_sock *fastopen;
340+
__u32 seq, snd_una;
341341
__u32 remaining;
342342
int err;
343343
struct net *net = dev_net(icmp_skb->dev);
@@ -378,12 +378,12 @@ void tcp_v4_err(struct sk_buff *icmp_skb, u32 info)
378378

379379
icsk = inet_csk(sk);
380380
tp = tcp_sk(sk);
381-
req = tp->fastopen_rsk;
382381
seq = ntohl(th->seq);
382+
/* XXX (TFO) - tp->snd_una should be ISN (tcp_create_openreq_child() */
383+
fastopen = tp->fastopen_rsk;
384+
snd_una = fastopen ? tcp_rsk(fastopen)->snt_isn : tp->snd_una;
383385
if (sk->sk_state != TCP_LISTEN &&
384-
!between(seq, tp->snd_una, tp->snd_nxt) &&
385-
(req == NULL || seq != tcp_rsk(req)->snt_isn)) {
386-
/* For a Fast Open socket, allow seq to be snt_isn. */
386+
!between(seq, snd_una, tp->snd_nxt)) {
387387
NET_INC_STATS_BH(net, LINUX_MIB_OUTOFWINDOWICMPS);
388388
goto out;
389389
}
@@ -426,11 +426,9 @@ void tcp_v4_err(struct sk_buff *icmp_skb, u32 info)
426426
if (code != ICMP_NET_UNREACH && code != ICMP_HOST_UNREACH)
427427
break;
428428
if (seq != tp->snd_una || !icsk->icsk_retransmits ||
429-
!icsk->icsk_backoff)
429+
!icsk->icsk_backoff || fastopen)
430430
break;
431431

432-
/* XXX (TFO) - revisit the following logic for TFO */
433-
434432
if (sock_owned_by_user(sk))
435433
break;
436434

@@ -462,14 +460,6 @@ void tcp_v4_err(struct sk_buff *icmp_skb, u32 info)
462460
goto out;
463461
}
464462

465-
/* XXX (TFO) - if it's a TFO socket and has been accepted, rather
466-
* than following the TCP_SYN_RECV case and closing the socket,
467-
* we ignore the ICMP error and keep trying like a fully established
468-
* socket. Is this the right thing to do?
469-
*/
470-
if (req && req->sk == NULL)
471-
goto out;
472-
473463
switch (sk->sk_state) {
474464
struct request_sock *req, **prev;
475465
case TCP_LISTEN:
@@ -502,10 +492,13 @@ void tcp_v4_err(struct sk_buff *icmp_skb, u32 info)
502492
goto out;
503493

504494
case TCP_SYN_SENT:
505-
case TCP_SYN_RECV: /* Cannot happen.
506-
It can f.e. if SYNs crossed,
507-
or Fast Open.
508-
*/
495+
case TCP_SYN_RECV:
496+
/* Only in fast or simultaneous open. If a fast open socket is
497+
* is already accepted it is treated as a connected one below.
498+
*/
499+
if (fastopen && fastopen->sk == NULL)
500+
break;
501+
509502
if (!sock_owned_by_user(sk)) {
510503
sk->sk_err = err;
511504

net/ipv6/tcp_ipv6.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,8 @@ static void tcp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
340340
struct sock *sk;
341341
int err;
342342
struct tcp_sock *tp;
343-
__u32 seq;
343+
struct request_sock *fastopen;
344+
__u32 seq, snd_una;
344345
struct net *net = dev_net(skb->dev);
345346

346347
sk = inet6_lookup(net, &tcp_hashinfo, &hdr->daddr,
@@ -371,8 +372,11 @@ static void tcp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
371372

372373
tp = tcp_sk(sk);
373374
seq = ntohl(th->seq);
375+
/* XXX (TFO) - tp->snd_una should be ISN (tcp_create_openreq_child() */
376+
fastopen = tp->fastopen_rsk;
377+
snd_una = fastopen ? tcp_rsk(fastopen)->snt_isn : tp->snd_una;
374378
if (sk->sk_state != TCP_LISTEN &&
375-
!between(seq, tp->snd_una, tp->snd_nxt)) {
379+
!between(seq, snd_una, tp->snd_nxt)) {
376380
NET_INC_STATS_BH(net, LINUX_MIB_OUTOFWINDOWICMPS);
377381
goto out;
378382
}
@@ -436,8 +440,13 @@ static void tcp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
436440
goto out;
437441

438442
case TCP_SYN_SENT:
439-
case TCP_SYN_RECV: /* Cannot happen.
440-
It can, it SYNs are crossed. --ANK */
443+
case TCP_SYN_RECV:
444+
/* Only in fast or simultaneous open. If a fast open socket is
445+
* is already accepted it is treated as a connected one below.
446+
*/
447+
if (fastopen && fastopen->sk == NULL)
448+
break;
449+
441450
if (!sock_owned_by_user(sk)) {
442451
sk->sk_err = err;
443452
sk->sk_error_report(sk); /* Wake people up to see the error (see connect in sock.c) */
@@ -1760,6 +1769,7 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
17601769
const struct inet_sock *inet = inet_sk(sp);
17611770
const struct tcp_sock *tp = tcp_sk(sp);
17621771
const struct inet_connection_sock *icsk = inet_csk(sp);
1772+
struct fastopen_queue *fastopenq = icsk->icsk_accept_queue.fastopenq;
17631773

17641774
dest = &sp->sk_v6_daddr;
17651775
src = &sp->sk_v6_rcv_saddr;
@@ -1802,7 +1812,9 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
18021812
jiffies_to_clock_t(icsk->icsk_ack.ato),
18031813
(icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
18041814
tp->snd_cwnd,
1805-
tcp_in_initial_slowstart(tp) ? -1 : tp->snd_ssthresh
1815+
sp->sk_state == TCP_LISTEN ?
1816+
(fastopenq ? fastopenq->max_qlen : 0) :
1817+
(tcp_in_initial_slowstart(tp) ? -1 : tp->snd_ssthresh)
18061818
);
18071819
}
18081820

0 commit comments

Comments
 (0)