From nobody Wed Sep 21 21:04:51 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4MXrX36Q0hz4cK1d; Wed, 21 Sep 2022 21:04:51 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4MXrX35Ddkz3nRV; Wed, 21 Sep 2022 21:04:51 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1663794291; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=/SNOp/PsEhKKV7Dtuf1bcW8h8Y+szqaUGNBJav6crew=; b=OGJmd5Mq+z1Ir6Zy4vIl90Lp1/1vCDDnuyLN6eIB0RCStif6/PXPAqgYAq0X+CGFTa56mM aa6Ch8fFzGLQdKX9UxU3HtsorHzFcuY10zN3Og828uBOV4GAJzq/ZFgFMoGYIhqZ600AKF A1S34hmjbK15fPSiMgh0qSLRUV1j/3dtHGyxq3KPGQrYSbhX2IRCOUmrpgKyWcPUdyLWsA XLU4dY20d4DUb1WhFNlkx+vxtdgygW/dtKBP2IJIWpAKFx+iPLAt/K6v1+sBaDI5mwM4iy X1a8pjJ5wVsR4T8HlXjzf2gFaKDNeyq9rJbyUnTeQorjneVjRUEogp3+P8xhBg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4MXrX34Ff2z1B9c; Wed, 21 Sep 2022 21:04:51 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 28LL4p4u023810; Wed, 21 Sep 2022 21:04:51 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 28LL4pkj023809; Wed, 21 Sep 2022 21:04:51 GMT (envelope-from git) Date: Wed, 21 Sep 2022 21:04:51 GMT Message-Id: <202209212104.28LL4pkj023809@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: 493105c2a8f9 - main - tcp: fix simultaneous open and refine e80062a2d43 List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 493105c2a8f95be99b5299af650fcf8b59b91f55 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1663794291; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=/SNOp/PsEhKKV7Dtuf1bcW8h8Y+szqaUGNBJav6crew=; b=Nd9ROJF8UdYBVYYTHopIc7INF5JFpAC4ssFgruyjdDZSuCN9TS9CaF4uE9Xsqq2hOyK31h 6Aqr9xuBvR6ghJcgnCFVa5K7jfoNaIXZM15iGUOCsGbUlqd67WWiG4YfMmtrb2nus8ApAf 2vWHJyQbFhIIKzgdTLienhEh6cZpIC7vZ8N75f2hVfAa/1weq/4L0YUshWdiGAtx/QgnPf WmornWzs0Nr7F7B9khY1AHniS80NKHUytS1Ogni8IfjQ7ZRdCZQlOZIGQ7dE5r3+b/5u98 WOAlEEvnIqJBokQDmInTJ3Dedeftshr4NKtZsU+OaRbuBwbqeC0h04ENIzf8BQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1663794291; a=rsa-sha256; cv=none; b=o1Ez/Jp4kQge5a+e5yBzYWNdwwztU3NbANLN3z9hWqMtLfbmO96qH34dR0yZMwD2Lqfb9p 8jeXrsfMScatZtHLoKoOQJTic+4rGtZoKziN2nOvRcyMxQXUR6CJ58hA+lHX0BT1zignkv yga7uKW7yU6pIiaR4mGlsrwK+C/AG925gGyOfhnAebCIhIlhj7u28c3+HldjVQ0T0pC01p SUmYNDYaTgnJzdoX4RpBhaVEd5MWvzIWrClnziNxRDc5UNRAobrRA9U+sniC/QPJabPwTu nMEiO+D+sSYn3SOfNU3kh3a22OXsF3gpzpQ9luwhrif2gy/yXKvnba7A3+p2Fg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=493105c2a8f95be99b5299af650fcf8b59b91f55 commit 493105c2a8f95be99b5299af650fcf8b59b91f55 Author: Gleb Smirnoff AuthorDate: 2022-09-21 21:02:49 +0000 Commit: Gleb Smirnoff CommitDate: 2022-09-21 21:02:49 +0000 tcp: fix simultaneous open and refine e80062a2d43 - The soisconnected() call on transition from SYN_RCVD to ESTABLISHED is also necessary for a half-synchronized connection. Fix that just setting the flag, when we transfer SYN-SENT -> SYN-RECEIVED. - Provide a comment that explains at what conditions the call to soisconnected() is necessary. - Hence mechanically rename the TF_INCQUEUE flag to TF_SONOTCONN. - Extend the change to the BBR and RACK stacks. Note: the interaction between the accept_filter(9) and the socket layer is not fully consistent, yet. For most accept filters this call to soisconnected() will not move the connection from the incomplete queue to the complete. The move would happen only when the filter has received the desired data, and soisconnected() would be called once again from sorwakeup(). Ideally, we should mark socket as connected only there, and leave the soisconnected() from SYN_RCVD->ESTABLISHED only for the simultaneous open case. However, this doesn't yet work. Reviewed by: rscheff, tuexen, rrs Differential revision: https://reviews.freebsd.org/D36641 --- sys/netinet/tcp_input.c | 15 ++++++++++++--- sys/netinet/tcp_stacks/bbr.c | 7 +++++-- sys/netinet/tcp_stacks/rack.c | 7 +++++-- sys/netinet/tcp_syncache.c | 2 +- sys/netinet/tcp_usrreq.c | 4 ++-- sys/netinet/tcp_var.h | 2 +- 6 files changed, 26 insertions(+), 11 deletions(-) diff --git a/sys/netinet/tcp_input.c b/sys/netinet/tcp_input.c index 86071141b174..e79cf48b9e55 100644 --- a/sys/netinet/tcp_input.c +++ b/sys/netinet/tcp_input.c @@ -2105,7 +2105,7 @@ tcp_do_segment(struct mbuf *m, struct tcphdr *th, struct socket *so, * SYN-SENT -> SYN-RECEIVED * SYN-SENT* -> SYN-RECEIVED* */ - tp->t_flags |= (TF_ACKNOW | TF_NEEDSYN); + tp->t_flags |= (TF_ACKNOW | TF_NEEDSYN | TF_SONOTCONN); tcp_timer_activate(tp, TT_REXMT, 0); tcp_state_change(tp, TCPS_SYN_RECEIVED); } @@ -2433,8 +2433,17 @@ tcp_do_segment(struct mbuf *m, struct tcphdr *th, struct socket *so, case TCPS_SYN_RECEIVED: TCPSTAT_INC(tcps_connects); - if (tp->t_flags & TF_INCQUEUE) { - tp->t_flags &= ~TF_INCQUEUE; + if (tp->t_flags & TF_SONOTCONN) { + /* + * Usually SYN_RECEIVED had been created from a LISTEN, + * and solisten_enqueue() has already marked the socket + * layer as connected. If it didn't, which can happen + * only with an accept_filter(9), then the tp is marked + * with TF_SONOTCONN. The other reason for this mark + * to be set is a simultaneous open, a SYN_RECEIVED + * that had been created from SYN_SENT. + */ + tp->t_flags &= ~TF_SONOTCONN; soisconnected(so); } /* Do window scaling? */ diff --git a/sys/netinet/tcp_stacks/bbr.c b/sys/netinet/tcp_stacks/bbr.c index 47c7f1ee0eee..dd6b823c6142 100644 --- a/sys/netinet/tcp_stacks/bbr.c +++ b/sys/netinet/tcp_stacks/bbr.c @@ -8902,7 +8902,7 @@ bbr_do_syn_sent(struct mbuf *m, struct tcphdr *th, struct socket *so, * SYN-SENT -> SYN-RECEIVED SYN-SENT* -> SYN-RECEIVED* If * there was no CC option, clear cached CC value. */ - tp->t_flags |= (TF_ACKNOW | TF_NEEDSYN); + tp->t_flags |= (TF_ACKNOW | TF_NEEDSYN | TF_SONOTCONN); tcp_state_change(tp, TCPS_SYN_RECEIVED); } INP_WLOCK_ASSERT(tp->t_inpcb); @@ -9088,7 +9088,10 @@ bbr_do_syn_recv(struct mbuf *m, struct tcphdr *th, struct socket *so, tiwin, thflags, nxt_pkt)); } KMOD_TCPSTAT_INC(tcps_connects); - soisconnected(so); + if (tp->t_flags & TF_SONOTCONN) { + tp->t_flags &= ~TF_SONOTCONN; + soisconnected(so); + } /* Do window scaling? */ if ((tp->t_flags & (TF_RCVD_SCALE | TF_REQ_SCALE)) == (TF_RCVD_SCALE | TF_REQ_SCALE)) { diff --git a/sys/netinet/tcp_stacks/rack.c b/sys/netinet/tcp_stacks/rack.c index 3ab4494865a5..6e323350100a 100644 --- a/sys/netinet/tcp_stacks/rack.c +++ b/sys/netinet/tcp_stacks/rack.c @@ -11318,7 +11318,7 @@ rack_do_syn_sent(struct mbuf *m, struct tcphdr *th, struct socket *so, * SYN-SENT -> SYN-RECEIVED SYN-SENT* -> SYN-RECEIVED* If * there was no CC option, clear cached CC value. */ - tp->t_flags |= (TF_ACKNOW | TF_NEEDSYN); + tp->t_flags |= (TF_ACKNOW | TF_NEEDSYN | TF_SONOTCONN); tcp_state_change(tp, TCPS_SYN_RECEIVED); } INP_WLOCK_ASSERT(tp->t_inpcb); @@ -11507,7 +11507,10 @@ rack_do_syn_recv(struct mbuf *m, struct tcphdr *th, struct socket *so, tiwin, thflags, nxt_pkt)); } KMOD_TCPSTAT_INC(tcps_connects); - soisconnected(so); + if (tp->t_flags & TF_SONOTCONN) { + tp->t_flags &= ~TF_SONOTCONN; + soisconnected(so); + } /* Do window scaling? */ if ((tp->t_flags & (TF_RCVD_SCALE | TF_REQ_SCALE)) == (TF_RCVD_SCALE | TF_REQ_SCALE)) { diff --git a/sys/netinet/tcp_syncache.c b/sys/netinet/tcp_syncache.c index f0ee539fa1ec..4fe5422b96ed 100644 --- a/sys/netinet/tcp_syncache.c +++ b/sys/netinet/tcp_syncache.c @@ -1040,7 +1040,7 @@ syncache_socket(struct syncache *sc, struct socket *lso, struct mbuf *m) TCP_PROBE6(state__change, NULL, tp, NULL, tp, NULL, TCPS_LISTEN); if (!solisten_enqueue(so, SS_ISCONNECTED)) - tp->t_flags |= TF_INCQUEUE; + tp->t_flags |= TF_SONOTCONN; return (so); diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c index 474cdb4d7787..ba7ed388c6b9 100644 --- a/sys/netinet/tcp_usrreq.c +++ b/sys/netinet/tcp_usrreq.c @@ -2978,8 +2978,8 @@ db_print_tflags(u_int t_flags) db_printf("%sTF_MORETOCOME", comma ? ", " : ""); comma = 1; } - if (t_flags & TF_INCQUEUE) { - db_printf("%sTF_INCQUEUE", comma ? ", " : ""); + if (t_flags & TF_SONOTCONN) { + db_printf("%sTF_SONOTCONN", comma ? ", " : ""); comma = 1; } if (t_flags & TF_LASTIDLE) { diff --git a/sys/netinet/tcp_var.h b/sys/netinet/tcp_var.h index d6146841a1ab..1b7e25099ced 100644 --- a/sys/netinet/tcp_var.h +++ b/sys/netinet/tcp_var.h @@ -515,7 +515,7 @@ tcp_unlock_or_drop(struct tcpcb *tp, int tcp_output_retval) #define TF_WAKESOR 0x00004000 /* wake up receive socket */ #define TF_GPUTINPROG 0x00008000 /* Goodput measurement in progress */ #define TF_MORETOCOME 0x00010000 /* More data to be appended to sock */ -#define TF_INCQUEUE 0x00020000 /* on incomplete queue of listener */ +#define TF_SONOTCONN 0x00020000 /* needs soisconnected() on ESTAB */ #define TF_LASTIDLE 0x00040000 /* connection was previously idle */ #define TF_RXWIN0SENT 0x00080000 /* sent a receiver win 0 in response */ #define TF_FASTRECOVERY 0x00100000 /* in NewReno Fast Recovery */