From nobody Tue Oct 24 13:38:24 2023 X-Original-To: dev-commits-src-branches@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 4SFCnF1dDlz4y3ry; Tue, 24 Oct 2023 13:38:25 +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 4SFCnF0z83z4ZDB; Tue, 24 Oct 2023 13:38:25 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1698154705; 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=b88HxLwJcZljTYyi4Rhs7GAzLlg40PQYukYnP+AU7TM=; b=cS2DD7h96eTnuPjGalNaTLdinACuEnSTDlXVU+LoQwz4sil+/wuMne/MI3Niuhgi5pm3LK W0Qo7R+u3WjsM529FoFQgCaECh4Gp9/T5O9AlTXoimUQgakwj9tu3yfTKLkxJ8vt3Ghsfc kRzocHTuR68GSQwgUzFD9H9hA+QMiIPDnLO7YRtJlX3+4uYSOAHE+pMV59Gs8Nxk4irlpr 2mNrDYeA0kJZUTWT8kc8xJPuJ+SnEqxRMEv+hh8HJsfQ1aGV32psIoJxKo4xILWREjkkt5 lckE79ypbSSGR5gmvmvPZ+0Qf3ga+HcG8sVjJn2cZvD4Bg23kU2foxLQk0rPlg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1698154705; a=rsa-sha256; cv=none; b=lCItAJM6jHxZbS6IWofmwyATtGCoFWN3lVNMBAp1PS+I4x2ceccUR6BBAgj4ugIWjgvJgw Fu/yw6lwJfEHo4LMzRC3d7Cdh+hXrySOwEcpv3LCX3RgD2FOK8Czs9UP6bXBVOYRcbYnfv s2RBhve3VzwNnvGYd3WeWXERGtE12MiRny+L7aQFCifQ7FB6d6coTqtgZT+t1A4Lddk9gQ OCiBTy5x6wxDqw72z/Afa9AP3uxYgtmbLyBDPkHXqXpKzT322l8YXK5ajt6MNViMauT082 M9nS5EmxmGLt/RZzwJ9BIFDGTbGvQq0ymojVINPtiJpmCXkQA4k1hW8AobviZw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1698154705; 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=b88HxLwJcZljTYyi4Rhs7GAzLlg40PQYukYnP+AU7TM=; b=VH70uTxOqPlyuKIl+EkDcwEnYqC5KQ2hcQCeL8tHFA89/GnYTa91BsDQnPrkbni2y5rF8p p7TA4o4z9l1mwjnr0GJq2ZstJaktrJkEWk/SOm3kRCzKDc/bmqBpgX7j08CZ/HtsoV5R+v aJkyeWPQAkj7g5HgbDKmqhVXGWtLHex+cDztAyPq97KI1L4/XYKOY2pWcV71ZPAI03fCcI aMwExPXz+QakUcEjShVMHJFFNDLDBzWCHT6uh0Q2g3YiurHVuFOv6NsUBvawDcaLkVStoD E/H/k2Gqgp6kZXeTRMSdwcBpTdgieSsztLBGZjfCT03ahOxuHFEg+X3IuZfizw== 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 4SFCnF01gJz9Sx; Tue, 24 Oct 2023 13:38:25 +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 39ODcO9m089386; Tue, 24 Oct 2023 13:38:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 39ODcONY089383; Tue, 24 Oct 2023 13:38:24 GMT (envelope-from git) Date: Tue, 24 Oct 2023 13:38:24 GMT Message-Id: <202310241338.39ODcONY089383@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: 4b1770ef487d - stable/14 - netinet tests: Add error handling tests for UDP with v4-mapped sockets List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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/14 X-Git-Reftype: branch X-Git-Commit: 4b1770ef487d543b083ffea614f12edb3fb36a9d Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=4b1770ef487d543b083ffea614f12edb3fb36a9d commit 4b1770ef487d543b083ffea614f12edb3fb36a9d Author: Mark Johnston AuthorDate: 2023-10-17 14:29:42 +0000 Commit: Mark Johnston CommitDate: 2023-10-24 13:19:46 +0000 netinet tests: Add error handling tests for UDP with v4-mapped sockets This provides a regression test for commit abca3ae7734f. Add it to the existing v4-mapped address test file, and rename accordingly. Reviewed by: tuexen, karels, rrs MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D39216 (cherry picked from commit ae5c3dfd3e75bb287984947359d4f958aea505ec) --- ObsoleteFiles.inc | 3 + tests/sys/netinet/Makefile | 2 +- ...p6_v4mapped_bind_test.c => ip6_v4mapped_test.c} | 81 +++++++++++++++++++--- 3 files changed, 76 insertions(+), 10 deletions(-) diff --git a/ObsoleteFiles.inc b/ObsoleteFiles.inc index 6a5e4e39fc1e..dbb4eda24416 100644 --- a/ObsoleteFiles.inc +++ b/ObsoleteFiles.inc @@ -51,6 +51,9 @@ # xargs -n1 | sort | uniq -d; # done +# 20231006: rename tcp6_v4unmapped_bind_test +OLD_FILES+=usr/tests/sys/netinet/tcp6_v4unmapped_bind_test + # 20231013: Man pages renamed to match the actual functions OLD_FILES+=usr/share/man/man9/cr_seeothergids.9.gz OLD_FILES+=usr/share/man/man9/cr_seeotheruids.9.gz diff --git a/tests/sys/netinet/Makefile b/tests/sys/netinet/Makefile index 144754acfbcc..44f76508bf5c 100644 --- a/tests/sys/netinet/Makefile +++ b/tests/sys/netinet/Makefile @@ -7,9 +7,9 @@ BINDIR= ${TESTSDIR} TESTS_SUBDIRS+= libalias ATF_TESTS_C= ip_reass_test \ + ip6_v4mapped_test \ so_reuseport_lb_test \ socket_afinet \ - tcp6_v4mapped_bind_test \ tcp_connect_port_test \ tcp_md5_getsockopt diff --git a/tests/sys/netinet/tcp6_v4mapped_bind_test.c b/tests/sys/netinet/ip6_v4mapped_test.c similarity index 81% rename from tests/sys/netinet/tcp6_v4mapped_bind_test.c rename to tests/sys/netinet/ip6_v4mapped_test.c index c7fc682d7ae7..d4c4ed526ab5 100644 --- a/tests/sys/netinet/tcp6_v4mapped_bind_test.c +++ b/tests/sys/netinet/ip6_v4mapped_test.c @@ -194,17 +194,15 @@ restore_portrange(void) "failed while restoring value"); } -ATF_TC_WITH_CLEANUP(v4mapped); -ATF_TC_HEAD(v4mapped, tc) +ATF_TC_WITH_CLEANUP(tcp_v4mapped_bind); +ATF_TC_HEAD(tcp_v4mapped_bind, tc) { - /* root is only required for sysctls (setup and cleanup). */ atf_tc_set_md_var(tc, "require.user", "root"); atf_tc_set_md_var(tc, "require.config", "allow_sysctl_side_effects"); atf_tc_set_md_var(tc, "descr", "Check local port assignment with bind and mapped V4 addresses"); } - /* * Create a listening IPv4 socket, then connect to it repeatedly using a * bound IPv6 socket using a v4 mapped address. With a small port range, @@ -213,7 +211,7 @@ ATF_TC_HEAD(v4mapped, tc) * and then the connect would fail with EADDRINUSE. Make sure we get * the right error. */ -ATF_TC_BODY(v4mapped, tc) +ATF_TC_BODY(tcp_v4mapped_bind, tc) { union { struct sockaddr saddr; @@ -315,17 +313,82 @@ ATF_TC_BODY(v4mapped, tc) ATF_REQUIRE_MSG(i >= 1, "No successful connections"); ATF_REQUIRE_MSG(got_bind_error == true, "No expected bind error"); } +ATF_TC_CLEANUP(tcp_v4mapped_bind, tc) +{ + restore_portrange(); +} -ATF_TC_CLEANUP(v4mapped, tc) +ATF_TC(udp_v4mapped_sendto); +ATF_TC_HEAD(udp_v4mapped_sendto, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Validate sendto() with a v4-mapped address and a v6-only socket"); +} +ATF_TC_BODY(udp_v4mapped_sendto, tc) { + struct addrinfo ai_hint, *aip; + struct sockaddr_in sin; + struct sockaddr_in6 sin6; + ssize_t n; + socklen_t salen; + int error, ls, s, zero; + short port; + char ch; - restore_portrange(); + ls = socket(PF_INET, SOCK_DGRAM, 0); + ATF_REQUIRE(ls >= 0); + + memset(&ai_hint, 0, sizeof(ai_hint)); + ai_hint.ai_family = AF_INET; + ai_hint.ai_flags = AI_NUMERICHOST; + error = getaddrinfo("127.0.0.1", NULL, &ai_hint, &aip); + ATF_REQUIRE_MSG(error == 0, "getaddrinfo: %s", gai_strerror(error)); + memcpy(&sin, aip->ai_addr, sizeof(sin)); + + error = bind(ls, (struct sockaddr *)&sin, sizeof(sin)); + ATF_REQUIRE_MSG(error == 0, "bind: %s", strerror(errno)); + salen = sizeof(sin); + error = getsockname(ls, (struct sockaddr *)&sin, &salen); + ATF_REQUIRE_MSG(error == 0, + "getsockname() for listen socket failed: %s", strerror(errno)); + ATF_REQUIRE_MSG(salen == sizeof(struct sockaddr_in), + "unexpected sockaddr size"); + port = sin.sin_port; + + s = socket(PF_INET6, SOCK_DGRAM, 0); + ATF_REQUIRE(s >= 0); + + memset(&ai_hint, 0, sizeof(ai_hint)); + ai_hint.ai_family = AF_INET6; + ai_hint.ai_flags = AI_NUMERICHOST | AI_V4MAPPED; + error = getaddrinfo("127.0.0.1", NULL, &ai_hint, &aip); + ATF_REQUIRE_MSG(error == 0, "getaddrinfo: %s", gai_strerror(error)); + memcpy(&sin6, aip->ai_addr, sizeof(sin6)); + sin6.sin6_port = port; + + ch = 0x42; + n = sendto(s, &ch, 1, 0, (struct sockaddr *)&sin6, sizeof(sin6)); + ATF_REQUIRE_ERRNO(EINVAL, n == -1); + + zero = 0; + error = setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &zero, sizeof(zero)); + ATF_REQUIRE_MSG(error == 0, + "setsockopt(IPV6_V6ONLY) failed: %s", strerror(errno)); + + ch = 0x42; + n = sendto(s, &ch, 1, 0, (struct sockaddr *)&sin6, sizeof(sin6)); + ATF_REQUIRE_MSG(n == 1, "sendto() failed: %s", strerror(errno)); + + ch = 0; + n = recv(ls, &ch, 1, 0); + ATF_REQUIRE_MSG(n == 1, "recv() failed: %s", strerror(errno)); + ATF_REQUIRE(ch == 0x42); } ATF_TP_ADD_TCS(tp) { - ATF_TP_ADD_TC(tp, v4mapped); + ATF_TP_ADD_TC(tp, tcp_v4mapped_bind); + ATF_TP_ADD_TC(tp, udp_v4mapped_sendto); return (atf_no_error()); } -