From nobody Fri Jul 07 18:52:21 2023 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 4QyMvn6YMBz4lM25; Fri, 7 Jul 2023 18:52:21 +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 4QyMvn60kmz3P7H; Fri, 7 Jul 2023 18:52:21 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1688755941; 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=c88FeeHWh3esI8OcVYHR1X9VqZRjvYmNMiHhe0uCXyo=; b=J9ttqgeRAB5e9NMnpzAZAEgvcBOICcFjJGXvM9M63yaHWmKy19n+K2Z64p/IcfQlIqLvFx yXM/d5xPhxPT965LLv4NLYfO4bYkh6MZ1cZtuB++YoJZ1KoVqVWUDzFIqflsLZykQtsRpZ iq0Y/XmWfpXZTUjZAf4yEjC9A0K4o57aR/CLBkfgBgvFfVQOOq/Z4Ruo3yJVmjFhrnOPhW Y0FDeAnHWhGD0U2Ry8YZm4KgjLSs61egl3g1lxzDH+13fyM9oHE7ok5ddsEAS9vmtIvVwF kAhSOdKemFip70ooYEptVjynkSItL2rN/jChqJMwavDXbufftY1LDl5sxSETIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1688755941; 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=c88FeeHWh3esI8OcVYHR1X9VqZRjvYmNMiHhe0uCXyo=; b=KYDCfGCosD+r3VHlxOCcXbXRYA6EPbrJM8l41QOrtQNW2b/9roGBagifk7Bns0t0vVxnCp JSMHOyE8eE42wv61PLjPPWRTmpE2PoY8SJ+qjeSr221t/cpVTesgnZWrhr64TMicHWUsj/ MI7BF0/If3aEUt3Zw5o6XJ4Toa+j+7UqnSLeIVZGSMPY19zUMjeMmFFg0IKpJldVfjeVBK tG0ibjyrThsC5LOBMj9OA+/Tbm0K6ID9tX3WvldSFqxp1F2AuT+MaGEXPh9J8z+hNEPfBP v8t8390oRxJC9ROF++ysUdkYXRw3wVty+EOj2q3w07fiE/tDiGYoMgEienwEsw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1688755941; a=rsa-sha256; cv=none; b=ShYYcyFSrOCRBLhRGmDKpcstBg6IBtPpzM7TYaSWPi6B4MOUiTQhvP9+6G1ym/vqpwtG2Q /Fsgt7BG7LI0DPfbRsIk4FYDHDbaAuqhct2ukDWm70kx/Db0d1W+B+S/HJnoshOGsK3JkQ l6FY1pIyBLu9VnwVhiaSvdHZCnxFuzY7XHXa08ye8Ky7dJI/PODYKPzc3sHnrwX5GMc3wt fk0aLp0GvM2c8b5Wd8R66xQh+ngz1GrSxjZO/2RiDqyIZApJYsEgwf/1S1KjagY7B+GQKm 3GhbrroGqLcQaTVPZXFUlvcAUqCNoxPYDTXxn8F5eobjEh0oGp+ujobip/ODkQ== 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 4QyMvn4qXFzq07; Fri, 7 Jul 2023 18:52:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 367IqLDk009080; Fri, 7 Jul 2023 18:52:21 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 367IqLfY009079; Fri, 7 Jul 2023 18:52:21 GMT (envelope-from git) Date: Fri, 7 Jul 2023 18:52:21 GMT Message-Id: <202307071852.367IqLfY009079@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: d2681db6434d - stable/13 - netinet tests: Add a test which connects a disconnected socket 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: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: d2681db6434d1d0eb5e6d1e3af07c7b1ff9cb723 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=d2681db6434d1d0eb5e6d1e3af07c7b1ff9cb723 commit d2681db6434d1d0eb5e6d1e3af07c7b1ff9cb723 Author: Mark Johnston AuthorDate: 2023-06-23 14:06:13 +0000 Commit: Mark Johnston CommitDate: 2023-07-07 18:46:23 +0000 netinet tests: Add a test which connects a disconnected socket MFC after: 2 weeks Sponsored by: The FreeBSD Foundation (cherry picked from commit b1c66bc44af099174afb9840c7db011a5bd0225d) --- 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 985d67d83c99..07fe90704206 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(); }