From nobody Mon Jul 04 19:41:14 2022 X-Original-To: dev-commits-src-main@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 303FD1CCD7F6; Mon, 4 Jul 2022 19:41:15 +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 4LcGQ30nByz3Grp; Mon, 4 Jul 2022 19:41:15 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1656963675; 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=x7bTlJF3tI5TO+yWAvOfRGQDafvmYhq640AoLP4Foog=; b=BmF3wzJ0yfnfCgaNTARUutf+P23btutHash/1vPdsuWsDsBvfvPDBFxSggMGXiCMk0l6bH 8VhcDx//iyOz2nAlEukXYgYidZLEAi3vlMip7WWjbUK6M3ZW42F8+cyWm8fl47g/l2xP48 mhbovRzafhm8osKXjxhAQNTf0Yn1ryaerILlThOhFt3kNZmk4D2HZp8WB796IZdwEfeIDE 23vh6sqQ5bNsugPVZPbthqej8DN1asQK7P8eb0+Xm8zHdfNi8X3b60Y7z3mo0KBDp+iSQh GvzumfBHaxMpyvJqIlxCu6+D/nRFH+lzOksaHMpQcW2bNoOcah27IcwkSLIAAA== 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 EFCB01763C; Mon, 4 Jul 2022 19:41:14 +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 264JfEs0096242; Mon, 4 Jul 2022 19:41:14 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 264JfEmP096241; Mon, 4 Jul 2022 19:41:14 GMT (envelope-from git) Date: Mon, 4 Jul 2022 19:41:14 GMT Message-Id: <202207041941.264JfEmP096241@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: 74703901d8bb - main - tcp: use a TCP flag to check if connection has been close(2)d List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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: 74703901d8bbc3bc7a29df648bc3c131c87393c2 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1656963675; 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=x7bTlJF3tI5TO+yWAvOfRGQDafvmYhq640AoLP4Foog=; b=Nrqi1boFAm5X8ayyGtdPosEBUj491fmuUR4Q5pCQQf8OMfxYJRrvx1XyqhJtdcETtLeSgL /vbOBmU8HwAnkwL3xswyNsT/VRhZSq7OIBY8p/ASrIzGNb9FsWq/HAtCsF0x0QQcFG29Bp RMGXQOhWNuSHfVi+fh2pxiISI1XTpSp+yPp+Xhe2AJkz0jdwVKgzA6fUEedu0gj8u3ehaP OddW9G/cYmmT1xach6uqsunpKaKtv8DagjQS0QVEG2fbMzTwWroRHIx67zZZ2X4PSYgOgQ uMVh31LmThttM+MNbOa3K6+vTWHl7hs3DudEpdrJRs/m0QKZpbDxTx0PwxB/7w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1656963675; a=rsa-sha256; cv=none; b=Vus5+PrqYlJNBEEMl137dXCG4Ixj+mfQ/ysys7kwkXQjt3vULJKrf4pTVnJ2260XoY1deh 643vQdhTXWUpHd6CxI3c75t14h2+uwuQZz1EYt6nsznACx8LKp17p8gEaH+r+++1ocHR10 2QkfUko2VKljeTpdHXX+L5LDN/P01Pmss3Idf/ow8Y0JNfYi6x0A1cF8ogqOjB6u2qQjRz MBiKPnOX+00q1J0FzQwoHWImA92yUvxLdeuklc6BOdpCIPAbys7T2Xoozwd9VoP42BXRXu 7Da0C/aXoB3iAjCYNY6G5VTDFpE0XudFHSz7FKW3Y9kDmeI5uFYryxqrG88rTQ== 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=74703901d8bbc3bc7a29df648bc3c131c87393c2 commit 74703901d8bbc3bc7a29df648bc3c131c87393c2 Author: Gleb Smirnoff AuthorDate: 2022-07-04 19:40:51 +0000 Commit: Gleb Smirnoff CommitDate: 2022-07-04 19:40:51 +0000 tcp: use a TCP flag to check if connection has been close(2)d The flag SS_NOFDREF is a private flag of the socket layer. It also is supposed to be read with SOCK_LOCK(), which we don't own here. Reviewed by: rrs, tuexen Differential revision: https://reviews.freebsd.org/D35663 --- sys/netinet/tcp_input.c | 3 +-- sys/netinet/tcp_stacks/bbr.c | 54 ++++++++++++++++--------------------------- sys/netinet/tcp_stacks/rack.c | 29 ++++++++++------------- sys/netinet/tcp_usrreq.c | 1 + sys/netinet/tcp_var.h | 2 +- 5 files changed, 35 insertions(+), 54 deletions(-) diff --git a/sys/netinet/tcp_input.c b/sys/netinet/tcp_input.c index a51e62616bea..f2d4f56ac582 100644 --- a/sys/netinet/tcp_input.c +++ b/sys/netinet/tcp_input.c @@ -2315,8 +2315,7 @@ tcp_do_segment(struct mbuf *m, struct tcphdr *th, struct socket *so, * If new data are received on a connection after the * user processes are gone, then RST the other end. */ - if ((so->so_state & SS_NOFDREF) && - tp->t_state > TCPS_CLOSE_WAIT && tlen) { + if ((tp->t_flags & TF_CLOSED) && tlen) { if ((s = tcp_log_addrs(inc, th, NULL, NULL))) { log(LOG_DEBUG, "%s; %s: %s: Received %d bytes of data " "after socket was closed, " diff --git a/sys/netinet/tcp_stacks/bbr.c b/sys/netinet/tcp_stacks/bbr.c index 67d0b7a5c64c..6278bb228c4f 100644 --- a/sys/netinet/tcp_stacks/bbr.c +++ b/sys/netinet/tcp_stacks/bbr.c @@ -9493,15 +9493,12 @@ bbr_do_fin_wait_1(struct mbuf *m, struct tcphdr *th, struct socket *so, /* * If new data are received on a connection after the user processes * are gone, then RST the other end. + * We call a new function now so we might continue and setup + * to reset at all data being ack'd. */ - if ((so->so_state & SS_NOFDREF) && tlen) { - /* - * We call a new function now so we might continue and setup - * to reset at all data being ack'd. - */ - if (bbr_check_data_after_close(m, bbr, tp, &tlen, th, so)) - return (1); - } + if ((tp->t_flags & TF_CLOSED) && tlen && + bbr_check_data_after_close(m, bbr, tp, &tlen, th, so)) + return (1); /* * If last ACK falls within this segment's sequence numbers, record * its timestamp. NOTE: 1) That the test incorporates suggestions @@ -9620,15 +9617,12 @@ bbr_do_closing(struct mbuf *m, struct tcphdr *th, struct socket *so, /* * If new data are received on a connection after the user processes * are gone, then RST the other end. + * We call a new function now so we might continue and setup + * to reset at all data being ack'd. */ - if ((so->so_state & SS_NOFDREF) && tlen) { - /* - * We call a new function now so we might continue and setup - * to reset at all data being ack'd. - */ - if (bbr_check_data_after_close(m, bbr, tp, &tlen, th, so)) - return (1); - } + if ((tp->t_flags & TF_CLOSED) && tlen && + bbr_check_data_after_close(m, bbr, tp, &tlen, th, so)) + return (1); /* * If last ACK falls within this segment's sequence numbers, record * its timestamp. NOTE: 1) That the test incorporates suggestions @@ -9733,15 +9727,12 @@ bbr_do_lastack(struct mbuf *m, struct tcphdr *th, struct socket *so, /* * If new data are received on a connection after the user processes * are gone, then RST the other end. + * We call a new function now so we might continue and setup + * to reset at all data being ack'd. */ - if ((so->so_state & SS_NOFDREF) && tlen) { - /* - * We call a new function now so we might continue and setup - * to reset at all data being ack'd. - */ - if (bbr_check_data_after_close(m, bbr, tp, &tlen, th, so)) - return (1); - } + if ((tp->t_flags & TF_CLOSED) && tlen && + bbr_check_data_after_close(m, bbr, tp, &tlen, th, so)) + return (1); /* * If last ACK falls within this segment's sequence numbers, record * its timestamp. NOTE: 1) That the test incorporates suggestions @@ -9850,17 +9841,12 @@ bbr_do_fin_wait_2(struct mbuf *m, struct tcphdr *th, struct socket *so, * If new data are received on a connection after the user processes * are gone, then we may RST the other end depending on the outcome * of bbr_check_data_after_close. + * We call a new function now so we might continue and setup + * to reset at all data being ack'd. */ - if ((so->so_state & SS_NOFDREF) && - tlen) { - /* - * We call a new function now so we might continue and setup - * to reset at all data being ack'd. - */ - if (bbr_check_data_after_close(m, bbr, tp, &tlen, th, so)) - return (1); - } - INP_WLOCK_ASSERT(tp->t_inpcb); + if (tp->t_state > TCPS_CLOSE_WAIT && tlen && + bbr_check_data_after_close(m, bbr, tp, &tlen, th, so)) + return (1); /* * If last ACK falls within this segment's sequence numbers, record * its timestamp. NOTE: 1) That the test incorporates suggestions diff --git a/sys/netinet/tcp_stacks/rack.c b/sys/netinet/tcp_stacks/rack.c index 3b40138d0fd5..ff43fbd02de2 100644 --- a/sys/netinet/tcp_stacks/rack.c +++ b/sys/netinet/tcp_stacks/rack.c @@ -11855,10 +11855,9 @@ rack_do_fin_wait_1(struct mbuf *m, struct tcphdr *th, struct socket *so, * If new data are received on a connection after the user processes * are gone, then RST the other end. */ - if ((so->so_state & SS_NOFDREF) && tlen) { - if (rack_check_data_after_close(m, tp, &tlen, th, so)) - return (1); - } + if ((tp->t_flags & TF_CLOSED) && tlen && + rack_check_data_after_close(m, tp, &tlen, th, so)) + return (1); /* * If last ACK falls within this segment's sequence numbers, record * its timestamp. NOTE: 1) That the test incorporates suggestions @@ -11983,10 +11982,9 @@ rack_do_closing(struct mbuf *m, struct tcphdr *th, struct socket *so, * If new data are received on a connection after the user processes * are gone, then RST the other end. */ - if ((so->so_state & SS_NOFDREF) && tlen) { - if (rack_check_data_after_close(m, tp, &tlen, th, so)) - return (1); - } + if ((tp->t_flags & TF_CLOSED) && tlen && + rack_check_data_after_close(m, tp, &tlen, th, so)) + return (1); /* * If last ACK falls within this segment's sequence numbers, record * its timestamp. NOTE: 1) That the test incorporates suggestions @@ -12097,10 +12095,9 @@ rack_do_lastack(struct mbuf *m, struct tcphdr *th, struct socket *so, * If new data are received on a connection after the user processes * are gone, then RST the other end. */ - if ((so->so_state & SS_NOFDREF) && tlen) { - if (rack_check_data_after_close(m, tp, &tlen, th, so)) - return (1); - } + if ((tp->t_flags & TF_CLOSED) && tlen && + rack_check_data_after_close(m, tp, &tlen, th, so)) + return (1); /* * If last ACK falls within this segment's sequence numbers, record * its timestamp. NOTE: 1) That the test incorporates suggestions @@ -12212,11 +12209,9 @@ rack_do_fin_wait_2(struct mbuf *m, struct tcphdr *th, struct socket *so, * If new data are received on a connection after the user processes * are gone, then RST the other end. */ - if ((so->so_state & SS_NOFDREF) && - tlen) { - if (rack_check_data_after_close(m, tp, &tlen, th, so)) - return (1); - } + if ((tp->t_flags & TF_CLOSED) && tlen && + rack_check_data_after_close(m, tp, &tlen, th, so)) + return (1); /* * If last ACK falls within this segment's sequence numbers, record * its timestamp. NOTE: 1) That the test incorporates suggestions diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c index e05ef963375c..6e4171bd1264 100644 --- a/sys/netinet/tcp_usrreq.c +++ b/sys/netinet/tcp_usrreq.c @@ -1406,6 +1406,7 @@ tcp_usr_close(struct socket *so) if (!(inp->inp_flags & INP_TIMEWAIT) && !(inp->inp_flags & INP_DROPPED)) { tp = intotcpcb(inp); + tp->t_flags |= TF_CLOSED; TCPDEBUG1(); tcp_disconnect(tp); TCPDEBUG2(PRU_CLOSE); diff --git a/sys/netinet/tcp_var.h b/sys/netinet/tcp_var.h index be9ff06f3a85..6d6c711f25b7 100644 --- a/sys/netinet/tcp_var.h +++ b/sys/netinet/tcp_var.h @@ -524,7 +524,7 @@ tcp_unlock_or_drop(struct tcpcb *tp, int tcp_output_retval) #define TF_FORCEDATA 0x00800000 /* force out a byte */ #define TF_TSO 0x01000000 /* TSO enabled on this connection */ #define TF_TOE 0x02000000 /* this connection is offloaded */ -#define TF_UNUSED0 0x04000000 /* unused */ +#define TF_CLOSED 0x04000000 /* close(2) called on socket */ #define TF_UNUSED1 0x08000000 /* unused */ #define TF_LRD 0x10000000 /* Lost Retransmission Detection */ #define TF_CONGRECOVERY 0x20000000 /* congestion recovery mode */