From nobody Tue Oct 17 15:55:32 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 4S8z8j1p1pz4xgZ9; Tue, 17 Oct 2023 15:55:33 +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 4S8z8j0VTHz4Dx2; Tue, 17 Oct 2023 15:55:33 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1697558133; 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=+UYGq7E/q38eJ/MFdKz1sWmzpgvA8PkAcWEbOtsp5GQ=; b=KusWq/Iy2OpVO0hlBnZ6lXRwRkL4ZlLRSdcpG6qg9s2x8/pXYYXSjyJza7yyvDAHx6Pq5R aOwJlWI8ciOPk87mdoQmlDSVRQrd7ELHh59LByBf0XUpHpI2Jh9bJdo8xRPhcH6UslMTrF q/gqVB05WUVvK8D+zJTnu4uH3biny+lsFAWZ/ep7jtDxyyL29zlGr0nwHXuSZL5YtkRnyp J08zVS1iRx8Z8rkvFcGvJMkic/qF6MiZT6UhPrJ8zfOkpISpFQsy++beMzJt+TPYoM05dJ hwLO7m4X9WnfYR2+XZsVvxHEQu7g1miuGdyeJBWhNYwBXAvYdWTVxyQJquqa0g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1697558133; a=rsa-sha256; cv=none; b=jEtIoA1Wo4IlidceExyUMeEvRBoLfptoV7w2MYJv9nJsNVfL+4j5hwBAMaDuPF7lGm/uHj ZmV1fiEq44hnweHGatD67hIifzPiOK2/AJ8SS7zH+M++nTbLHb7bu/mst7IGXdABPnyPRX vwzMfBowO8L9IHQmO9SAjc6JwcCtNo30XtDX2RSPKnCfGZ2XrNAABHxK2dTWYg2zjL5ooc b2VuqWDDYx8TXKtPOjZUze0z5HwxWB7Trkr4tWkOt3g5SwtiuVLXgCWgOzTbP9aS98MDk+ v3RCYW2JuHglDhRaHDyPvVIpH7iJ8GDjSyW923oIvaysiGOeRKRaCUQW8q3hag== 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=1697558133; 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=+UYGq7E/q38eJ/MFdKz1sWmzpgvA8PkAcWEbOtsp5GQ=; b=szo1mLyznySw1Ky0ykJxxGkP5pJD3daKeqieBCrxQPIiAAXKwPRXZf96J4XPVZtOsHP5yr nRwyb/dFj8Y/gowU56uxlaFnvNxaWy/uJ8Wfoq4qpCnO4EKeoNvICwRdt/PeFgVuN9JB2u W6LHHB2XNySJii3h32jSxI+xPRksYfcSz30pDplNtwHSTWLmmicAIxk5gUdKCewzcio6AP m5KgwpJ2omuFlyooPCku9O+CkBiXFMmNI+s0absPnnV0cbfoiIUfdzcQV13BL01fVOf3IQ xVqGF7FsbwnKLDQgKv61ixu2Z+QEmzbZG3vmGOsAbJ0ed6qabYkJs4tnofffLQ== 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 4S8z8h6LvkzVhJ; Tue, 17 Oct 2023 15:55:32 +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 39HFtW47029082; Tue, 17 Oct 2023 15:55:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 39HFtWoA029079; Tue, 17 Oct 2023 15:55:32 GMT (envelope-from git) Date: Tue, 17 Oct 2023 15:55:32 GMT Message-Id: <202310171555.39HFtWoA029079@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: ae5c3dfd3e75 - main - netinet tests: Add error handling tests for UDP with v4-mapped sockets 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/main X-Git-Reftype: branch X-Git-Commit: ae5c3dfd3e75bb287984947359d4f958aea505ec Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=ae5c3dfd3e75bb287984947359d4f958aea505ec commit ae5c3dfd3e75bb287984947359d4f958aea505ec Author: Mark Johnston AuthorDate: 2023-10-17 14:29:42 +0000 Commit: Mark Johnston CommitDate: 2023-10-17 15:19:06 +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 --- 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 c3cc72351963..9e4be6b69312 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 + # 20231005: Remove man page link for now gone net80211 function. OLD_FILES+=usr/share/man/man9/ieee80211_unref_node.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()); } -