From nobody Fri Jun 23 15:09:57 2023 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 4Qngdf2f25z4gjjc; Fri, 23 Jun 2023 15:09:58 +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 4Qngdf0mpGz3PSv; Fri, 23 Jun 2023 15:09:58 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1687532998; 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=++XdEPWaEVifEXInwWc/VASPFl97314laiNJvX4h1YM=; b=Km+vN5Y1lkTSv17h0AMPqWYSqf2V2MulICFN3w4TCea7kBVlYnsSgQL+PLu5eeAJKnO+6X DUI9Ftmet0D9rBMK1ek+4utOyKoXnhK8CG0FERXbF9IulNhPyU7KSuEszG5S5h1+7v39Fy WWYfmW+vXhp3qCxO4Jxx+xjojZHMWiiHoRhalwiCGI9oz4/b7w44CURswReJ2Iwf540DzG cWWoBvhWqgCMIPd6Xn7I6/PgKVmhEGFSh2VSpsfqczDha0y5qa9/GIdmzzM+nFpif5YVUI Nneb6AayVuZj8bkWzn6uvCueHWrasZ6TkWucZuaejqRUDKfTfTIn2FZUZd70mQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1687532998; 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=++XdEPWaEVifEXInwWc/VASPFl97314laiNJvX4h1YM=; b=nmLHBrgKFYKpC2PRcHpLBO+BXDUyoHkH5vvO+1P+huJ90UWj23zv+IE47TJ1ZUJVFY9FDL nFgFLbHBtD4Ec6ALyM4QWOzjON9P3INYMX2Rp9rJCbSR29+WVSNw4ZHtIKhsg0MJ/j685R xCp5Of6q2ghw7SlG1mWSVJYfKtZQZ/hUU0I1LeLGLxFNuCYCVMtwQbSKw5EXYox68+mn8y J+Bhzqq5hRqVSLqKZVnjko1UP17l4ymI968f8tBzhcCLCWe8BAYSa6QzmQP3gzQFFTiUrg NO5r5DPYMDRP1exqfeG0Hby9IGEQ+U+iNOeSaQB+QM/NSLPvoEWQP8PS4DL16w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1687532998; a=rsa-sha256; cv=none; b=h264MN2P3xTslmXRZlfHSTBQm2ji7T1wnR0JH/vS0pr6hjr5O7fLOSCFYBdbWDuKmzuclH 9zgGn1s5ysMOctVA77moyo9BpCJ4gq6uS6+0uFp1NxMJSVe55geOPK12jIynGDMTLeIJdg joHYj0np6wPr3jv/39Yvp6h0rAIy9a9u3+yEyBopXWnZ5TWRO8uyavxfYzoOCgZwsgtwQY q6n9E+oekGahuqo1n5rvw5WoF1NgB/rccEId3zCOnmkaoB9wxHoZpgQP/RAUEV9Q+UZKjQ yJPSSiGB11Hh5eM1qGOK3ULUQOj+EHqpp+8iwf1726puczt8sAMWlVVsYnFcmA== 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 4Qngdd70Kkz18QZ; Fri, 23 Jun 2023 15:09:57 +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 35NF9vaZ037791; Fri, 23 Jun 2023 15:09:57 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 35NF9vmI037790; Fri, 23 Jun 2023 15:09:57 GMT (envelope-from git) Date: Fri, 23 Jun 2023 15:09:57 GMT Message-Id: <202306231509.35NF9vmI037790@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: b1c66bc44af0 - main - netinet tests: Add a test which connects a disconnected socket 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: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: b1c66bc44af099174afb9840c7db011a5bd0225d Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=b1c66bc44af099174afb9840c7db011a5bd0225d commit b1c66bc44af099174afb9840c7db011a5bd0225d Author: Mark Johnston AuthorDate: 2023-06-23 14:06:13 +0000 Commit: Mark Johnston CommitDate: 2023-06-23 14:06:13 +0000 netinet tests: Add a test which connects a disconnected socket MFC after: 2 weeks Sponsored by: The FreeBSD Foundation --- tests/sys/netinet/socket_afinet.c | 47 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/tests/sys/netinet/socket_afinet.c b/tests/sys/netinet/socket_afinet.c index c3b672a18602..482f767dd094 100644 --- a/tests/sys/netinet/socket_afinet.c +++ b/tests/sys/netinet/socket_afinet.c @@ -28,9 +28,9 @@ #include __FBSDID("$FreeBSD$"); -#include #include #include +#include #include #include @@ -228,14 +228,57 @@ ATF_TC_BODY(socket_afinet_poll_rdhup, tc) close(ss); } -ATF_TP_ADD_TCS(tp) +ATF_TC_WITHOUT_HEAD(socket_afinet_stream_reconnect); +ATF_TC_BODY(socket_afinet_stream_reconnect, tc) { + struct sockaddr_in sin; + int ss, cs, rc; + + /* + * Make sure that an attempt to connect(2) a connected or disconnected + * stream socket fails with EISCONN. + */ + /* Server setup. */ + ss = socket(PF_INET, SOCK_STREAM, 0); + ATF_CHECK(ss >= 0); + bzero(&sin, sizeof(sin)); + sin.sin_family = AF_INET; + sin.sin_len = sizeof(sin); + sin.sin_port = htons(6666); + sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + rc = bind(ss, (struct sockaddr *)&sin, sizeof(sin)); + ATF_CHECK_EQ(0, rc); + rc = listen(ss, 1); + ATF_CHECK_EQ(0, rc); + + /* Client connects, shuts down. */ + cs = socket(PF_INET, SOCK_STREAM, 0); + ATF_CHECK(cs >= 0); + rc = connect(cs, (struct sockaddr *)&sin, sizeof(sin)); + ATF_CHECK_EQ(0, rc); + rc = shutdown(cs, SHUT_RDWR); + ATF_CHECK_EQ(0, rc); + + /* A subsequent connect(2) fails with EISCONN. */ + rc = connect(cs, (struct sockaddr *)&sin, sizeof(sin)); + ATF_CHECK_EQ(-1, rc); + ATF_CHECK_EQ(errno, EISCONN); + + rc = close(cs); + ATF_CHECK_EQ(0, rc); + rc = close(ss); + ATF_CHECK_EQ(0, rc); +} + +ATF_TP_ADD_TCS(tp) +{ ATF_TP_ADD_TC(tp, socket_afinet); ATF_TP_ADD_TC(tp, socket_afinet_bind_zero); ATF_TP_ADD_TC(tp, socket_afinet_bind_ok); ATF_TP_ADD_TC(tp, socket_afinet_poll_no_rdhup); ATF_TP_ADD_TC(tp, socket_afinet_poll_rdhup); + ATF_TP_ADD_TC(tp, socket_afinet_stream_reconnect); return atf_no_error(); }