From patchwork Wed Jun 21 10:54:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 778772 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wt1mr3N86z9s2s for ; Wed, 21 Jun 2017 20:54:20 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="pSAaVxzv"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:to:subject:mime-version:content-type :content-transfer-encoding:message-id:from; q=dns; s=default; b= rBmb1sgz/io3YM7gUDsZLGsI7BK2oCA9KEAaEBvWC5Ayxt+TqKwEtd1y+vEfiBm3 Bn3kivoM2uKfImI8Z2toPRyxfniaTftfIZ2tUA0RXOB6JMB90hcemdvk3szlKKQq zqM9Q9p4ySVmMq1MJqiXi4ErfhaIkPKJ6qw56yHvKmQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:to:subject:mime-version:content-type :content-transfer-encoding:message-id:from; s=default; bh=zqEuLm rf0wtPJwEphgqtjpmyJrg=; b=pSAaVxzv24yrO1bJchxXV9IDg3nlKWZh7S5Y1Q s0xjLiQld8nVrVnhEWAqfg/YI6vDd+C+zmIq2TF28lwqch9INObw2wt1DAVL2Cls BwZLHU0KzpzBQPTwsBedHgTu4BNAq96/LEwJOY22xpgPCaKumgxoczq7HvAkLYfq Q8JsE= Received: (qmail 99262 invoked by alias); 21 Jun 2017 10:54:11 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 95912 invoked by uid 89); 21 Jun 2017 10:54:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=ifh, getaddrinfo X-HELO: mx1.redhat.com DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6AA684E4D0 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=fweimer@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 6AA684E4D0 Date: Wed, 21 Jun 2017 12:54:06 +0200 To: libc-alpha@sourceware.org Subject: [PATCH COMMITTED] inet: Add IPv6 getaddrinfo coverage to tst-inet6_scopeid_pton.c User-Agent: Heirloom mailx 12.5 7/5/10 MIME-Version: 1.0 Message-Id: <20170621105406.2D828439942F0@oldenburg.str.redhat.com> From: fweimer@redhat.com (Florian Weimer) 2017-06-21 Florian Weimer Add IPv6 getaddrinfo coverage to tst-inet6_scopeid_pton.c. * inet/tst-inet6_scopeid_pton.c: Switch to . (call_gai, check_ai): New functions. (expect_failure, expect_success): Use them. Add logging. diff --git a/inet/tst-inet6_scopeid_pton.c b/inet/tst-inet6_scopeid_pton.c index 2178c5b..a1bafa9 100644 --- a/inet/tst-inet6_scopeid_pton.c +++ b/inet/tst-inet6_scopeid_pton.c @@ -1,4 +1,4 @@ -/* Tests for __inet6_scopeid_pton. +/* Tests for __inet6_scopeid_pton and IPv6 scopes in getaddrinfo. Copyright (C) 2016-2017 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -20,8 +20,13 @@ #include #include #include +#include #include #include +#include +#include +#include +#include /* An interface which is known to the system. */ static const char *interface_name; @@ -45,30 +50,103 @@ from_string (const char *address) { struct in6_addr addr; if (inet_pton (AF_INET6, address, &addr) != 1) - { - printf ("error: inet_pton (\"%s\") failed\n", address); - exit (1); - } + FAIL_EXIT1 ("inet_pton (\"%s\")", address); return addr; } +/* Invoke getaddrinfo to parse ADDRESS%SCOPE. Return true if + getaddrinfo was successful. */ +static bool +call_gai (int family, const char *address, const char *scope, + struct sockaddr_in6 *result) +{ + struct addrinfo hints = + { + .ai_family = family, + .ai_flags = AI_NUMERICHOST, + .ai_socktype = SOCK_DGRAM, + .ai_protocol = IPPROTO_UDP, + }; + char *fulladdr = xasprintf ("%s%%%s", address, scope); + struct addrinfo *ai = NULL; + int ret = getaddrinfo (fulladdr, NULL, &hints, &ai); + if (ret == EAI_ADDRFAMILY || ret == EAI_NONAME) + { + if (test_verbose > 0) + printf ("info: getaddrinfo (\"%s\"): %s (%d)\n", + fulladdr, gai_strerror (ret), ret); + free (fulladdr); + return false; + } + if (ret != 0) + FAIL_EXIT1 ("getaddrinfo (\"%s\"): %s (%d)\n", + fulladdr, gai_strerror (ret), ret); + TEST_VERIFY_EXIT (ai != NULL); + TEST_VERIFY_EXIT (ai->ai_addrlen == sizeof (*result)); + TEST_VERIFY (ai->ai_family == AF_INET6); + TEST_VERIFY (ai->ai_next == NULL); + memcpy (result, ai->ai_addr, sizeof (*result)); + free (fulladdr); + freeaddrinfo (ai); + return true; +} + +/* Verify that a successful call to getaddrinfo returned the expected + scope data. */ +static void +check_ai (const char *what, const char *addr_string, const char *scope_string, + const struct sockaddr_in6 *sa, + const struct in6_addr *addr, uint32_t scope) +{ + if (memcmp (addr, &sa->sin6_addr, sizeof (*addr)) != 0) + { + support_record_failure (); + printf ("error: getaddrinfo %s address mismatch for %s%%%s\n", + what, addr_string, scope_string); + } + if (sa->sin6_scope_id != scope) + { + support_record_failure (); + printf ("error: getaddrinfo %s scope mismatch for %s%%%s\n" + " expected: %" PRIu32 "\n" + " actual: %" PRIu32 "\n", + what, addr_string, scope_string, scope, sa->sin6_scope_id); + } +} + /* Check a single address were we expected a failure. */ static void expect_failure (const char *address, const char *scope) { + if (test_verbose > 0) + printf ("info: expecting failure for %s%%%s\n", address, scope); struct in6_addr addr = from_string (address); uint32_t result = 1234; if (__inet6_scopeid_pton (&addr, scope, &result) == 0) { + support_record_failure (); printf ("error: unexpected success for %s%%%s\n", address, scope); - exit (1); } if (result != 1234) { + support_record_failure (); printf ("error: unexpected result update for %s%%%s\n", address, scope); - exit (1); + } + + struct sockaddr_in6 sa; + if (call_gai (AF_UNSPEC, address, scope, &sa)) + { + support_record_failure (); + printf ("error: unexpected getaddrinfo success for %s%%%s (AF_UNSPEC)\n", + address, scope); + } + if (call_gai (AF_INET6, address, scope, &sa)) + { + support_record_failure (); + printf ("error: unexpected getaddrinfo success for %s%%%s (AF_INET6)\n", + address, scope); } } @@ -76,21 +154,43 @@ expect_failure (const char *address, const char *scope) static void expect_success (const char *address, const char *scope, uint32_t expected) { + if (test_verbose > 0) + printf ("info: expecting success for %s%%%s\n", address, scope); struct in6_addr addr = from_string (address); uint32_t actual = expected + 1; if (__inet6_scopeid_pton (&addr, scope, &actual) != 0) { + support_record_failure (); printf ("error: unexpected failure for %s%%%s\n", address, scope); - exit (1); } if (actual != expected) { + support_record_failure (); printf ("error: unexpected result for for %s%%%s\n", address, scope); printf (" expected: %" PRIu32 "\n", expected); printf (" actual: %" PRIu32 "\n", actual); - exit (1); + } + + struct sockaddr_in6 sa; + memset (&sa, 0xc0, sizeof (sa)); + if (call_gai (AF_UNSPEC, address, scope, &sa)) + check_ai ("AF_UNSPEC", address, scope, &sa, &addr, expected); + else + { + support_record_failure (); + printf ("error: unexpected getaddrinfo failure for %s%%%s (AF_UNSPEC)\n", + address, scope); + } + memset (&sa, 0xc0, sizeof (sa)); + if (call_gai (AF_INET6, address, scope, &sa)) + check_ai ("AF_INET6", address, scope, &sa, &addr, expected); + else + { + support_record_failure (); + printf ("error: unexpected getaddrinfo failure for %s%%%s (AF_INET6)\n", + address, scope); } } @@ -127,5 +227,4 @@ do_test (void) return 0; } -#define TEST_FUNCTION do_test () -#include "../test-skeleton.c" +#include