diff --git a/contrib/netbsd-tests/lib/libc/net/getaddrinfo/t_getaddrinfo.sh b/contrib/netbsd-tests/lib/libc/net/getaddrinfo/t_getaddrinfo.sh index 94a3c0b2e52c..e299702c790d 100755 --- a/contrib/netbsd-tests/lib/libc/net/getaddrinfo/t_getaddrinfo.sh +++ b/contrib/netbsd-tests/lib/libc/net/getaddrinfo/t_getaddrinfo.sh @@ -1,198 +1,216 @@ # $NetBSD: t_getaddrinfo.sh,v 1.2 2011/06/15 07:54:32 jmmv Exp $ # # Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, and 2002 WIDE Project. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # 3. Neither the name of the project nor the names of its contributors # may be used to endorse or promote products derived from this software # without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # check_output() { if [ "$2" = "none" ] ; then exp="${1}.exp" elif [ "$2" = "hosts" ] ; then # Determine if localhost has an IPv6 address or not lcl=$( cat /etc/hosts | \ sed -e 's/#.*$//' -e 's/[ ][ ]*/ /g' | \ awk '/ localhost($| )/ {printf "%s ", $1}' ) if [ "${lcl%*::*}" = "${lcl}" ] ; then exp="${1}_v4.exp" else exp="${1}_v4v6.exp" fi elif [ "$2" = "ifconfig" ] ; then lcl=$( ifconfig lo0 | grep inet6 ) if [ -n "${lcl}" ] ; then exp="${1}_v4v6.exp" else exp="${1}_v4.exp" fi else atf_fail "Invalid family_match_type $2 requested." fi cmp -s $(atf_get_srcdir)/data/${exp} out && return diff -u $(atf_get_srcdir)/data/${exp} out && \ atf_fail "Actual output does not match expected output" } atf_test_case basic basic_head() { atf_set "descr" "Testing basic ones" } basic_body() { TEST=$(atf_get_srcdir)/h_gai + # Begin FreeBSD + if [ "$(atf_config_get ci false)" = "true" ]; then + atf_expect_fail "https://bugs.freebsd.org/285826" + fi + # End FreeBSD + ( $TEST ::1 http $TEST 127.0.0.1 http $TEST localhost http $TEST ::1 tftp $TEST 127.0.0.1 tftp $TEST localhost tftp $TEST ::1 echo $TEST 127.0.0.1 echo $TEST localhost echo ) > out 2>&1 check_output basics hosts } atf_test_case specific specific_head() { atf_set "descr" "Testing specific address family" } specific_body() { TEST=$(atf_get_srcdir)/h_gai ( $TEST -4 localhost http $TEST -6 localhost http ) > out 2>&1 check_output spec_fam hosts } atf_test_case empty_hostname empty_hostname_head() { atf_set "descr" "Testing empty hostname" } empty_hostname_body() { TEST=$(atf_get_srcdir)/h_gai ( $TEST '' http $TEST '' echo $TEST '' tftp $TEST '' 80 $TEST -P '' http $TEST -P '' echo $TEST -P '' tftp $TEST -P '' 80 $TEST -S '' 80 $TEST -D '' 80 ) > out 2>&1 check_output no_host ifconfig } atf_test_case empty_servname empty_servname_head() { atf_set "descr" "Testing empty service name" } empty_servname_body() { TEST=$(atf_get_srcdir)/h_gai + # Begin FreeBSD + if [ "$(atf_config_get ci false)" = "true" ]; then + atf_expect_fail "https://bugs.freebsd.org/285826" + fi + # End FreeBSD + ( $TEST ::1 '' $TEST 127.0.0.1 '' $TEST localhost '' $TEST '' '' ) > out 2>&1 check_output no_serv hosts } atf_test_case sock_raw sock_raw_head() { atf_set "descr" "Testing raw socket" } sock_raw_body() { TEST=$(atf_get_srcdir)/h_gai + # Begin FreeBSD + if [ "$(atf_config_get ci false)" = "true" ]; then + atf_expect_fail "https://bugs.freebsd.org/285826" + fi + # End FreeBSD + ( $TEST -R -p 0 localhost '' $TEST -R -p 59 localhost '' $TEST -R -p 59 localhost 80 $TEST -R -p 59 localhost www $TEST -R -p 59 ::1 '' ) > out 2>&1 check_output sock_raw hosts } atf_test_case unsupported_family unsupported_family_head() { atf_set "descr" "Testing unsupported family" } unsupported_family_body() { TEST=$(atf_get_srcdir)/h_gai ( $TEST -f 99 localhost '' ) > out 2>&1 check_output unsup_fam none } atf_test_case scopeaddr scopeaddr_head() { atf_set "descr" "Testing scoped address format" } scopeaddr_body() { TEST=$(atf_get_srcdir)/h_gai ( $TEST fe80::1%lo0 http # IF=`ifconfig -a | grep -v '^ ' | \ # sed -e 's/:.*//' | head -1 | awk '{print $1}'` # $TEST fe80::1%$IF http ) > out 2>&1 check_output scoped none } atf_init_test_cases() { atf_add_test_case basic atf_add_test_case specific atf_add_test_case empty_hostname atf_add_test_case empty_servname atf_add_test_case sock_raw atf_add_test_case unsupported_family atf_add_test_case scopeaddr } diff --git a/lib/libc/tests/net/getaddrinfo/getaddrinfo.c b/lib/libc/tests/net/getaddrinfo/getaddrinfo.c index 1e066add3119..72e3c66c92ba 100644 --- a/lib/libc/tests/net/getaddrinfo/getaddrinfo.c +++ b/lib/libc/tests/net/getaddrinfo/getaddrinfo.c @@ -1,271 +1,277 @@ /*- * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2025 Gleb Smirnoff * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include #include #include #include #include #include #include static const char goodname[] = "www.freebsd.org"; static const char goodname_dot[] = "www.freebsd.org."; static const char badname[] = "does-not-exist.freebsd.org"; static const char badname_dot[] = "does-not-exist.freebsd.org."; static const char ipv6onlyname[] = "beefy15.nyi.freebsd.org"; static const char ipv6onlyname_dot[] = "beefy15.nyi.freebsd.org."; static const char ipv4onlyname[] = "ipv4only.arpa"; static const char ipv4onlyname_dot[] = "ipv4only.arpa."; /* * We need an IP address that doesn't exist, but not reported with ICMP * unreachable by the nearest router. Let's try TEST-NET-3. */ static char badresolvconf[] = "nameserver 203.0.113.1"; static char badresolvconf2[] = "nameserver 203.0.113.1\n" "nameserver 203.0.113.2"; static char *resconf = NULL; FILE * fopen(const char * restrict path, const char * restrict mode) { static FILE *(*orig)(const char *, const char *); if (orig == NULL && (orig = dlsym(RTLD_NEXT, "fopen")) == NULL) atf_libc_error(ENOENT, "dlsym(fopen): %s", dlerror()); if (resconf != NULL && strcmp(path, _PATH_RESCONF) == 0) return (fmemopen(resconf, strlen(resconf), mode)); else return (orig(path, mode)); } static int send_error = 0; ssize_t send(int s, const void *msg, size_t len, int flags) { static ssize_t (*orig)(int, const void *, size_t, int); if (orig == NULL && (orig = dlsym(RTLD_NEXT, "send")) == NULL) atf_libc_error(ENOENT, "dlsym(send): %s", dlerror()); if (send_error != 0) { errno = send_error; return (-1); } else { return (orig(s, msg, len, flags)); } } ATF_TC(basic); ATF_TC_HEAD(basic, tc) { atf_tc_set_md_var(tc, "require.config", "allow_network_access"); } ATF_TC_BODY(basic, tc) { static const struct addrinfo hints = { .ai_family = AF_UNSPEC, .ai_flags = AI_CANONNAME, }; struct addrinfo *res; int rv; + if (atf_tc_get_config_var_as_bool_wd(tc, "ci", false)) + atf_tc_expect_fail("https://bugs.freebsd.org/285826"); + rv = getaddrinfo(goodname, NULL, &hints, &res); ATF_REQUIRE_MSG(rv == 0, "Expected 0, got %d (%s)", rv, gai_strerror(rv)); freeaddrinfo(res); rv = getaddrinfo(goodname_dot, NULL, &hints, &res); ATF_REQUIRE_MSG(rv == 0, "Expected 0, got %d (%s)", rv, gai_strerror(rv)); freeaddrinfo(res); rv = getaddrinfo(badname, NULL, &hints, &res); ATF_REQUIRE_MSG(rv == EAI_NONAME, "Expected %d (EAI_NONAME), got %d (%s)", EAI_NONAME, rv, gai_strerror(rv)); rv = getaddrinfo(badname_dot, NULL, &hints, &res); ATF_REQUIRE_MSG(rv == EAI_NONAME, "Expected %d (EAI_NONAME), got %d (%s)", EAI_NONAME, rv, gai_strerror(rv)); } ATF_TC_WITHOUT_HEAD(timeout); ATF_TC_BODY(timeout, tc) { static const struct addrinfo hints = { .ai_family = AF_UNSPEC, .ai_flags = AI_CANONNAME, }; struct addrinfo *res; int rv; resconf = badresolvconf; rv = getaddrinfo(goodname, NULL, &hints, &res); ATF_REQUIRE_MSG(rv == EAI_AGAIN, "Expected %d (EAI_AGAIN), got %d (%s)", EAI_AGAIN, rv, gai_strerror(rv)); rv = getaddrinfo(goodname_dot, NULL, &hints, &res); ATF_REQUIRE_MSG(rv == EAI_AGAIN, "Expected %d (EAI_AGAIN), got %d (%s)", EAI_AGAIN, rv, gai_strerror(rv)); } ATF_TC_WITHOUT_HEAD(timeout_specific); ATF_TC_BODY(timeout_specific, tc) { static const struct addrinfo hints = { .ai_family = AF_INET, .ai_socktype = SOCK_STREAM, .ai_flags = AI_CANONNAME, }; struct addrinfo *res; int rv; resconf = badresolvconf; rv = getaddrinfo(goodname, "666", &hints, &res); ATF_REQUIRE_MSG(rv == EAI_AGAIN, "Expected %d (EAI_AGAIN), got %d (%s)", EAI_AGAIN, rv, gai_strerror(rv)); rv = getaddrinfo(goodname_dot, "666", &hints, &res); ATF_REQUIRE_MSG(rv == EAI_AGAIN, "Expected %d (EAI_AGAIN), got %d (%s)", EAI_AGAIN, rv, gai_strerror(rv)); } ATF_TC_WITHOUT_HEAD(timeout2); ATF_TC_BODY(timeout2, tc) { static const struct addrinfo hints = { .ai_family = AF_UNSPEC, .ai_flags = AI_CANONNAME, }; struct addrinfo *res; int rv; resconf = badresolvconf2; rv = getaddrinfo(goodname, NULL, &hints, &res); ATF_REQUIRE_MSG(rv == EAI_AGAIN, "Expected %d (EAI_AGAIN), got %d (%s)", EAI_AGAIN, rv, gai_strerror(rv)); rv = getaddrinfo(goodname_dot, NULL, &hints, &res); ATF_REQUIRE_MSG(rv == EAI_AGAIN, "Expected %d (EAI_AGAIN), got %d (%s)", EAI_AGAIN, rv, gai_strerror(rv)); } /* * Emulate interface/network down. */ ATF_TC_WITHOUT_HEAD(netdown); ATF_TC_BODY(netdown, tc) { static const struct addrinfo hints = { .ai_family = AF_UNSPEC, .ai_flags = AI_CANONNAME, }; struct addrinfo *res; int rv; send_error = ENETDOWN; rv = getaddrinfo(goodname, NULL, &hints, &res); ATF_REQUIRE_MSG(rv == EAI_AGAIN, "Expected %d (EAI_AGAIN), got %d (%s)", EAI_AGAIN, rv, gai_strerror(rv)); rv = getaddrinfo(goodname_dot, NULL, &hints, &res); ATF_REQUIRE_MSG(rv == EAI_AGAIN, "Expected %d (EAI_AGAIN), got %d (%s)", EAI_AGAIN, rv, gai_strerror(rv)); } /* * See https://reviews.freebsd.org/D37139. */ ATF_TC(nofamily); ATF_TC_HEAD(nofamily, tc) { atf_tc_set_md_var(tc, "require.config", "allow_network_access"); } ATF_TC_BODY(nofamily, tc) { static const struct addrinfo hints4 = { .ai_family = AF_INET, .ai_flags = AI_CANONNAME, }, hints6 = { .ai_family = AF_INET6, .ai_flags = AI_CANONNAME, }; struct addrinfo *res; int rv; + if (atf_tc_get_config_var_as_bool_wd(tc, "ci", false)) + atf_tc_expect_fail("https://bugs.freebsd.org/285826"); + rv = getaddrinfo(ipv6onlyname, NULL, &hints4, &res); ATF_REQUIRE_MSG(rv == EAI_ADDRFAMILY, "Expected %d (EAI_ADDRFAMILY), got %d (%s)", EAI_ADDRFAMILY, rv, gai_strerror(rv)); rv = getaddrinfo(ipv6onlyname_dot, NULL, &hints4, &res); ATF_REQUIRE_MSG(rv == EAI_ADDRFAMILY, "Expected %d (EAI_ADDRFAMILY), got %d (%s)", EAI_ADDRFAMILY, rv, gai_strerror(rv)); rv = getaddrinfo(ipv4onlyname, NULL, &hints6, &res); ATF_REQUIRE_MSG(rv == EAI_ADDRFAMILY, "Expected %d (EAI_ADDRFAMILY), got %d (%s)", EAI_ADDRFAMILY, rv, gai_strerror(rv)); rv = getaddrinfo(ipv4onlyname_dot, NULL, &hints6, &res); ATF_REQUIRE_MSG(rv == EAI_ADDRFAMILY, "Expected %d (EAI_ADDRFAMILY), got %d (%s)", EAI_ADDRFAMILY, rv, gai_strerror(rv)); rv = getaddrinfo(badname, NULL, &hints4, &res); ATF_REQUIRE_MSG(rv == EAI_NONAME, "Expected %d (EAI_NONAME), got %d (%s)", EAI_NONAME, rv, gai_strerror(rv)); rv = getaddrinfo(badname_dot, NULL, &hints6, &res); ATF_REQUIRE_MSG(rv == EAI_NONAME, "Expected %d (EAI_NONAME), got %d (%s)", EAI_NONAME, rv, gai_strerror(rv)); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, basic); ATF_TP_ADD_TC(tp, timeout); ATF_TP_ADD_TC(tp, timeout_specific); ATF_TP_ADD_TC(tp, timeout2); ATF_TP_ADD_TC(tp, netdown); ATF_TP_ADD_TC(tp, nofamily); return (atf_no_error()); }